From 9b100ba6a485bd77abef7f9bc83c6ab957cd6d43 Mon Sep 17 00:00:00 2001 From: gedoor Date: Thu, 5 Aug 2021 10:20:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/config/ThemeConfigFragment.kt | 66 ++++++++++--------- app/src/main/res/xml/pref_config_theme.xml | 36 ++++------ 2 files changed, 46 insertions(+), 56 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt index 510819f23..2367cc2cb 100644 --- a/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt @@ -164,37 +164,9 @@ class ThemeConfigFragment : BasePreferenceFragment(), recreateActivities() } "themeList" -> ThemeListDialog().show(childFragmentManager, "themeList") - "saveDayTheme", "saveNightTheme" -> saveThemeAlert(key) - PreferKey.bgImage -> if (getPrefString(PreferKey.bgImage).isNullOrEmpty()) { - selectImage.launch(requestCodeBgLight) - } else { - selector(items = arrayListOf("删除图片", "选择图片")) { _, i -> - if (i == 0) { - removePref(PreferKey.bgImage) - upTheme(false) - } else { - selectImage.launch(requestCodeBgLight) - } - } - } - PreferKey.bgImageN -> if (getPrefString(PreferKey.bgImageN).isNullOrEmpty()) { - selectImage.launch(requestCodeBgDark) - } else { - selector(items = arrayListOf("删除图片", "选择图片")) { _, i -> - if (i == 0) { - removePref(PreferKey.bgImageN) - upTheme(true) - } else { - selectImage.launch(requestCodeBgDark) - } - } - } - PreferKey.bgImageBlurring -> alertImageBlurring(PreferKey.bgImageBlurring) { - upTheme(false) - } - PreferKey.bgImageNBlurring -> alertImageBlurring(PreferKey.bgImageNBlurring) { - upTheme(true) - } + "saveDayTheme", "saveNightTheme" -> alertSaveTheme(key) + PreferKey.bgImage -> selectBgAction(false) + PreferKey.bgImageN -> selectBgAction(true) PreferKey.defaultCover -> if (getPrefString(PreferKey.defaultCover).isNullOrEmpty()) { selectImage.launch(requestCodeCover) } else { @@ -223,7 +195,7 @@ class ThemeConfigFragment : BasePreferenceFragment(), } @SuppressLint("InflateParams") - private fun saveThemeAlert(key: String) { + private fun alertSaveTheme(key: String) { alert(R.string.theme_name) { val alertBinding = DialogEditTextBinding.inflate(layoutInflater).apply { textInputLayout.hint = "name" @@ -245,6 +217,36 @@ class ThemeConfigFragment : BasePreferenceFragment(), }.show() } + private fun selectBgAction(isNight: Boolean) { + val bgKey = if (isNight) PreferKey.bgImageN else PreferKey.bgImage + val blurringKey = if (isNight) PreferKey.bgImageNBlurring else PreferKey.bgImageBlurring + val actions = arrayListOf( + getString(R.string.background_image_blurring), + getString(R.string.select_image) + ) + if (!getPrefString(bgKey).isNullOrEmpty()) { + actions.add(getString(R.string.delete)) + } + selector(items = actions) { _, i -> + when (i) { + 0 -> alertImageBlurring(blurringKey) { + upTheme(isNight) + } + 1 -> { + if (isNight) { + selectImage.launch(requestCodeBgDark) + } else { + selectImage.launch(requestCodeBgLight) + } + } + 2 -> { + removePref(bgKey) + upTheme(isNight) + } + } + } + } + private fun alertImageBlurring(preferKey: String, success: () -> Unit) { alert(R.string.background_image_blurring) { val alertBinding = DialogImageBlurringBinding.inflate(layoutInflater).apply { diff --git a/app/src/main/res/xml/pref_config_theme.xml b/app/src/main/res/xml/pref_config_theme.xml index 564cb9811..a30c3c603 100644 --- a/app/src/main/res/xml/pref_config_theme.xml +++ b/app/src/main/res/xml/pref_config_theme.xml @@ -82,14 +82,6 @@ app:cpv_dialogType="preset" app:iconSpaceReserved="false" /> - - - - + + + android:title="@string/default_cover" /> - - - - + + + android:title="@string/default_cover" />