diff --git a/app/src/main/assets/themeConfig.json b/app/src/main/assets/themeConfig.json new file mode 100644 index 000000000..712cff4fb --- /dev/null +++ b/app/src/main/assets/themeConfig.json @@ -0,0 +1,50 @@ +[ + { + "configName": "典雅蓝", + "isNightTheme": false, + "primaryColor": "#03A9F4", + "accentColor": "#AD1457", + "backgroundColor": "#F5F5F5", + "bottomBackground": "#EEEEEE" + }, + { + "configName": "极简", + "isNightTheme": false, + "primaryColor": "#03A9F4", + "accentColor": "#AD1457", + "backgroundColor": "#F5F5F5", + "bottomBackground": "#EEEEEE" + }, + { + "configName": "黑白", + "isNightTheme": false, + "primaryColor": "#03A9F4", + "accentColor": "#AD1457", + "backgroundColor": "#F5F5F5", + "bottomBackground": "#EEEEEE" + }, + { + "configName": "曜夜", + "isNightTheme": false, + "primaryColor": "#03A9F4", + "accentColor": "#AD1457", + "backgroundColor": "#F5F5F5", + "bottomBackground": "#EEEEEE" + }, + { + "configName": "黑白", + "isNightTheme": false, + "primaryColor": "#03A9F4", + "accentColor": "#AD1457", + "backgroundColor": "#F5F5F5", + "bottomBackground": "#EEEEEE" + }, + { + "configName": "A屏黑", + "isNightTheme": false, + "primaryColor": "#03A9F4", + "accentColor": "#AD1457", + "backgroundColor": "#F5F5F5", + "bottomBackground": "#EEEEEE" + } +] \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/help/AppConfig.kt b/app/src/main/java/io/legado/app/help/AppConfig.kt index aebc822b7..e2538e902 100644 --- a/app/src/main/java/io/legado/app/help/AppConfig.kt +++ b/app/src/main/java/io/legado/app/help/AppConfig.kt @@ -21,10 +21,12 @@ object AppConfig { var isNightTheme: Boolean get() = isNightTheme(App.INSTANCE) set(value) { - if (value) { - App.INSTANCE.putPrefString(PreferKey.themeMode, "2") - } else { - App.INSTANCE.putPrefString(PreferKey.themeMode, "1") + if (isNightTheme != value) { + if (value) { + App.INSTANCE.putPrefString(PreferKey.themeMode, "2") + } else { + App.INSTANCE.putPrefString(PreferKey.themeMode, "1") + } } } diff --git a/app/src/main/java/io/legado/app/help/ThemeConfig.kt b/app/src/main/java/io/legado/app/help/ThemeConfig.kt new file mode 100644 index 000000000..cb41e41d6 --- /dev/null +++ b/app/src/main/java/io/legado/app/help/ThemeConfig.kt @@ -0,0 +1,54 @@ +package io.legado.app.help + +import android.content.Context +import android.graphics.Color +import io.legado.app.App +import io.legado.app.R +import io.legado.app.constant.EventBus +import io.legado.app.constant.PreferKey +import io.legado.app.utils.* + +object ThemeConfig { + val configFileName = "themeConfigs.json" + private val configFilePath = FileUtils.getPath(App.INSTANCE.filesDir, configFileName) + val configList = arrayListOf() + private val defaultConfigs by lazy { + val json = String(App.INSTANCE.assets.open(configFileName).readBytes()) + GSON.fromJsonArray(json)!! + } + + + fun applyConfig(context: Context, config: Config) { + val primary = Color.parseColor(config.primaryColor) + val accent = Color.parseColor(config.accentColor) + var background = Color.parseColor(config.backgroundColor) + if (!ColorUtils.isColorLight(background)) { + background = context.getCompatColor(R.color.md_grey_100) + } + val bBackground = Color.parseColor(config.bottomBackground) + if (config.isNightTheme) { + context.putPrefInt(PreferKey.cNPrimary, primary) + context.putPrefInt(PreferKey.cNAccent, accent) + context.putPrefInt(PreferKey.cNBackground, background) + context.putPrefInt(PreferKey.cNBBackground, bBackground) + } else { + context.putPrefInt(PreferKey.cPrimary, primary) + context.putPrefInt(PreferKey.cAccent, accent) + context.putPrefInt(PreferKey.cBackground, background) + context.putPrefInt(PreferKey.cBBackground, bBackground) + } + AppConfig.isNightTheme = config.isNightTheme + App.INSTANCE.applyDayNight() + postEvent(EventBus.RECREATE, "") + } + + class Config( + var configName: String = "典雅蓝", + var isNightTheme: Boolean = false, + var primaryColor: String = "#03A9F4", + var accentColor: String = "#AD1457", + var backgroundColor: String = "#F5F5F5", + var bottomBackground: String = "#EEEEEE" + ) + +} \ No newline at end of file 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 4ac41081f..e43a3019f 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 @@ -16,7 +16,6 @@ import io.legado.app.constant.EventBus import io.legado.app.constant.PreferKey import io.legado.app.help.AppConfig import io.legado.app.help.LauncherIconHelp -import io.legado.app.lib.dialogs.alert import io.legado.app.lib.theme.ATH import io.legado.app.ui.widget.number.NumberPickerDialog import io.legado.app.ui.widget.prefs.ColorPreference @@ -28,8 +27,6 @@ import io.legado.app.utils.* class ThemeConfigFragment : BasePreferenceFragment(), SharedPreferences.OnSharedPreferenceChangeListener { - val items = App.INSTANCE.resources.getStringArray(R.array.default_themes).toList() - override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { addPreferencesFromResource(R.xml.pref_config_theme) if (Build.VERSION.SDK_INT < 26) { @@ -151,7 +148,6 @@ class ThemeConfigFragment : BasePreferenceFragment(), @SuppressLint("PrivateResource") override fun onPreferenceTreeClick(preference: Preference?): Boolean { when (preference?.key) { - "defaultTheme" -> changeTheme() PreferKey.barElevation -> NumberPickerDialog(requireContext()) .setTitle(getString(R.string.bar_elevation)) .setMaxValue(32) @@ -166,6 +162,7 @@ class ThemeConfigFragment : BasePreferenceFragment(), AppConfig.elevation = it recreateActivities() } + "themeList" -> themeListAlert() "saveDayTheme" -> { } "saveNightTheme" -> { @@ -174,50 +171,8 @@ class ThemeConfigFragment : BasePreferenceFragment(), return super.onPreferenceTreeClick(preference) } - private fun changeTheme() { - alert(title = getString(R.string.select_theme)) { - items(items) { _, which -> - when (which) { - 0 -> { - putPrefInt(PreferKey.cPrimary, getCompatColor(R.color.md_grey_100)) - putPrefInt(PreferKey.cAccent, getCompatColor(R.color.md_deep_orange_600)) - putPrefInt(PreferKey.cBackground, getCompatColor(R.color.md_grey_100)) - putPrefInt(PreferKey.cBBackground, getCompatColor(R.color.md_grey_200)) - AppConfig.isNightTheme = false - } - 1 -> { - putPrefInt(PreferKey.cNPrimary, getCompatColor(R.color.md_grey_900)) - putPrefInt(PreferKey.cNAccent, getCompatColor(R.color.md_deep_orange_600)) - putPrefInt(PreferKey.cNBackground, getCompatColor(R.color.md_grey_900)) - putPrefInt(PreferKey.cNBBackground, getCompatColor(R.color.md_grey_900)) - AppConfig.isNightTheme = true - } - 2 -> { - putPrefInt(PreferKey.cPrimary, getCompatColor(R.color.md_light_blue_500)) - putPrefInt(PreferKey.cAccent, getCompatColor(R.color.md_pink_800)) - putPrefInt(PreferKey.cBackground, getCompatColor(R.color.md_grey_100)) - putPrefInt(PreferKey.cBBackground, getCompatColor(R.color.md_grey_200)) - AppConfig.isNightTheme = false - } - 3 -> { - putPrefInt(PreferKey.cPrimary, getCompatColor(R.color.white)) - putPrefInt(PreferKey.cAccent, getCompatColor(R.color.md_deep_orange_600)) - putPrefInt(PreferKey.cBackground, getCompatColor(R.color.white)) - putPrefInt(PreferKey.cBBackground, getCompatColor(R.color.white)) - AppConfig.isNightTheme = false - } - 4 -> { - putPrefInt(PreferKey.cNPrimary, getCompatColor(R.color.black)) - putPrefInt(PreferKey.cNAccent, getCompatColor(R.color.md_deep_orange_600)) - putPrefInt(PreferKey.cNBackground, getCompatColor(R.color.black)) - putPrefInt(PreferKey.cNBBackground, getCompatColor(R.color.black)) - AppConfig.isNightTheme = true - } - } - App.INSTANCE.applyDayNight() - recreateActivities() - } - }.show().applyTint() + private fun themeListAlert() { + } private fun upTheme(isNightTheme: Boolean) { diff --git a/app/src/main/res/values-zh-rHK/arrays.xml b/app/src/main/res/values-zh-rHK/arrays.xml index 346489faf..4e75577e4 100644 --- a/app/src/main/res/values-zh-rHK/arrays.xml +++ b/app/src/main/res/values-zh-rHK/arrays.xml @@ -41,14 +41,6 @@ 細體 - - 极简 - 曜夜 - 经典 - 黑白 - A屏黑 - - 跟随系统 简体中文 diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index e9dc8e01c..c007a530c 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -730,7 +730,6 @@ 默认启用替换净化 新加入书架的书是否启用替换净化 选择恢复文件 - 切换默认主题 白天背景不能太暗 白天底栏不能太暗 夜间背景不能太亮 diff --git a/app/src/main/res/values-zh-rTW/arrays.xml b/app/src/main/res/values-zh-rTW/arrays.xml index bcf021e96..23909ad85 100644 --- a/app/src/main/res/values-zh-rTW/arrays.xml +++ b/app/src/main/res/values-zh-rTW/arrays.xml @@ -97,14 +97,6 @@ 細體 - - 極簡 - 耀夜 - 經典 - 黑白 - A屏黑 - - 跟隨系統 簡體中文 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 549b7ca89..94e5a1760 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -730,7 +730,6 @@ 預設啟用取代淨化 新加入書架的書是否啟用取代淨化 選擇復原文件 - 切換預設主題 白天背景不能太暗 白天底欄不能太暗 夜間背景不能太亮 diff --git a/app/src/main/res/values-zh/arrays.xml b/app/src/main/res/values-zh/arrays.xml index 39f133376..5fdf42b1d 100644 --- a/app/src/main/res/values-zh/arrays.xml +++ b/app/src/main/res/values-zh/arrays.xml @@ -97,14 +97,6 @@ 细体 - - 极简 - 曜夜 - 经典 - 黑白 - A屏黑 - - 跟随系统 简体中文 diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index 592bed1bc..9e10e4ff9 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -731,7 +731,6 @@ 默认启用替换净化 新加入书架的书是否启用替换净化 选择恢复文件 - 切换默认主题 白天背景不能太暗 白天底栏不能太暗 夜间背景不能太亮 diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index db6fcec3c..5847f7765 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -97,14 +97,6 @@ Light - - 极简 - 曜夜 - 经典 - 黑白 - A屏黑 - - 跟随系统 简体中文 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 33091d3c9..5bcf3470f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -732,7 +732,6 @@ 默认启用替换净化 新加入书架的书是否启用替换净化 选择恢复文件 - 切换默认主题 白天背景不能太暗 白天底栏不能太暗 夜间背景不能太亮