diff --git a/app/src/main/java/com/huanchengfly/tieba/post/App.kt b/app/src/main/java/com/huanchengfly/tieba/post/App.kt index 00cf4089..cb20a44b 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/App.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/App.kt @@ -38,6 +38,7 @@ import com.huanchengfly.tieba.post.utils.AccountUtil import com.huanchengfly.tieba.post.utils.AppIconUtil import com.huanchengfly.tieba.post.utils.ClientUtils import com.huanchengfly.tieba.post.utils.EmoticonManager +import com.huanchengfly.tieba.post.utils.Icons import com.huanchengfly.tieba.post.utils.SharedPreferencesUtil import com.huanchengfly.tieba.post.utils.ThemeUtil import com.huanchengfly.tieba.post.utils.TiebaUtil @@ -93,6 +94,11 @@ class App : Application(), IApp, IGetter, SketchFactory { return null } + fun refreshIcon(enableNewUi: Boolean = applicationMetaData.getBoolean("enable_new_ui") || appPreferences.enableNewUi) { + if (enableNewUi) AppIconUtil.setIcon() + else AppIconUtil.setIcon(Icons.DISABLE) + } + override fun onCreate() { INSTANCE = this super.onCreate() @@ -103,7 +109,6 @@ class App : Application(), IApp, IGetter, SketchFactory { setWebViewPath(this) } val isSelfBuild = applicationMetaData.getBoolean("is_self_build") - val enableNewUi = applicationMetaData.getBoolean("enable_new_ui") if (!isSelfBuild) { Distribute.setUpdateTrack(if (appPreferences.checkCIUpdate) UpdateTrack.PRIVATE else UpdateTrack.PUBLIC) Distribute.setListener(MyDistributeListener()) @@ -112,9 +117,9 @@ class App : Application(), IApp, IGetter, SketchFactory { Analytics::class.java, Crashes::class.java, Distribute::class.java ) } + refreshIcon() AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM) ThemeUtils.init(ThemeDelegate) - if (enableNewUi) AppIconUtil.setIcon() registerActivityLifecycleCallbacks(ClipBoardLinkDetector) PluginManager.init(this) CoroutineScope(Dispatchers.IO).apply { diff --git a/app/src/main/java/com/huanchengfly/tieba/post/fragments/PreferencesFragment.kt b/app/src/main/java/com/huanchengfly/tieba/post/fragments/PreferencesFragment.kt index e276ef3e..c58dfd6d 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/fragments/PreferencesFragment.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/fragments/PreferencesFragment.kt @@ -17,6 +17,7 @@ import androidx.preference.ListPreference import androidx.preference.Preference import androidx.preference.SwitchPreference import com.google.android.material.snackbar.Snackbar +import com.huanchengfly.tieba.post.App import com.huanchengfly.tieba.post.BuildConfig import com.huanchengfly.tieba.post.DataStorePreference import com.huanchengfly.tieba.post.R @@ -257,6 +258,10 @@ class PreferencesFragment : PreferencesFragment() { aboutPreference!!.summary = getString(R.string.tip_about, BuildConfig.VERSION_NAME) refresh() + findPreference("enableNewUi")?.setOnPreferenceChangeListener { _, newValue -> + App.INSTANCE.refreshIcon(newValue == true) + true + } /* try { val preferenceGroupClazz = PreferenceGroup::class.java diff --git a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/settings/more/MoreSettingsPage.kt b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/settings/more/MoreSettingsPage.kt index 229bed97..9a7b8fb8 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/ui/page/settings/more/MoreSettingsPage.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/ui/page/settings/more/MoreSettingsPage.kt @@ -5,6 +5,7 @@ import androidx.compose.foundation.layout.padding import androidx.compose.material.ExperimentalMaterialApi import androidx.compose.material.icons.Icons import androidx.compose.material.icons.outlined.BugReport +import androidx.compose.material.icons.outlined.FiberNew import androidx.compose.material.icons.outlined.Info import androidx.compose.material.icons.outlined.OfflineBolt import androidx.compose.runtime.* @@ -78,6 +79,23 @@ fun MoreSettingsPage( summary = stringResource(id = R.string.tip_check_ci_update) ) } + prefsItem { + SwitchPref( + leadingIcon = { + LeadingIcon { + AvatarIcon( + icon = Icons.Outlined.FiberNew, + size = Sizes.Small, + contentDescription = null, + ) + } + }, + key = "enableNewUi", + title = stringResource(id = R.string.title_enable_new_ui), + defaultChecked = false, + summary = stringResource(id = R.string.summary_enable_new_ui) + ) + } prefsItem { SwitchPref( leadingIcon = { diff --git a/app/src/main/java/com/huanchengfly/tieba/post/utils/AppIconUtil.kt b/app/src/main/java/com/huanchengfly/tieba/post/utils/AppIconUtil.kt index 283dc8d0..0f13ac4c 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/utils/AppIconUtil.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/utils/AppIconUtil.kt @@ -10,6 +10,7 @@ object Icons { const val NEW_ICON = "com.huanchengfly.tieba.post.MainActivityV2" const val NEW_ICON_INVERT = "com.huanchengfly.tieba.post.MainActivityIconInvert" const val OLD_ICON = "com.huanchengfly.tieba.post.MainActivityIconOld" + const val DISABLE = "com.huanchengfly.tieba.post.MainActivityV2Disabled" const val DEFAULT_ICON = NEW_ICON diff --git a/app/src/main/java/com/huanchengfly/tieba/post/utils/AppPreferencesUtils.kt b/app/src/main/java/com/huanchengfly/tieba/post/utils/AppPreferencesUtils.kt index 46710320..cf2433e1 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/utils/AppPreferencesUtils.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/utils/AppPreferencesUtils.kt @@ -72,6 +72,8 @@ open class AppPreferencesUtils(context: Context) { var darkTheme by DataStoreDelegates.string(key = "dark_theme", defaultValue = "grey_dark") + var enableNewUi by DataStoreDelegates.boolean(defaultValue = false) + var followSystemNight by DataStoreDelegates.boolean( defaultValue = true, key = "follow_system_night" diff --git a/app/src/main/res/drawable/ic_round_fiber_new.xml b/app/src/main/res/drawable/ic_round_fiber_new.xml new file mode 100644 index 00000000..ebcd6ffd --- /dev/null +++ b/app/src/main/res/drawable/ic_round_fiber_new.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index 32b4f860..bc9de403 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -20,6 +20,7 @@ oksign_use_official_oksign checkCIUpdate + enableNewUi diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f04f3e8f..4d75db11 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -635,4 +635,6 @@ 语音 表情 表情 %s + (实验性特性)启用新版 UI。仅少部分页面完成,BUG 可能较多,仅供尝鲜使用! + 启用新版 UI diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index e81f4ee6..b8cad54f 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -259,6 +259,13 @@ android:summary="@string/tip_check_ci_update" android:title="@string/title_check_ci_update" /> + +