主题导入导出

pull/363/head
gedoor 4 years ago
parent 4dc7538c12
commit eb09a59142
  1. 50
      app/src/main/assets/themeConfig.json
  2. 10
      app/src/main/java/io/legado/app/help/AppConfig.kt
  3. 54
      app/src/main/java/io/legado/app/help/ThemeConfig.kt
  4. 51
      app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt
  5. 8
      app/src/main/res/values-zh-rHK/arrays.xml
  6. 1
      app/src/main/res/values-zh-rHK/strings.xml
  7. 8
      app/src/main/res/values-zh-rTW/arrays.xml
  8. 1
      app/src/main/res/values-zh-rTW/strings.xml
  9. 8
      app/src/main/res/values-zh/arrays.xml
  10. 1
      app/src/main/res/values-zh/strings.xml
  11. 8
      app/src/main/res/values/arrays.xml
  12. 1
      app/src/main/res/values/strings.xml

@ -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"
}
]

@ -21,10 +21,12 @@ object AppConfig {
var isNightTheme: Boolean var isNightTheme: Boolean
get() = isNightTheme(App.INSTANCE) get() = isNightTheme(App.INSTANCE)
set(value) { set(value) {
if (value) { if (isNightTheme != value) {
App.INSTANCE.putPrefString(PreferKey.themeMode, "2") if (value) {
} else { App.INSTANCE.putPrefString(PreferKey.themeMode, "2")
App.INSTANCE.putPrefString(PreferKey.themeMode, "1") } else {
App.INSTANCE.putPrefString(PreferKey.themeMode, "1")
}
} }
} }

@ -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<Config>()
private val defaultConfigs by lazy {
val json = String(App.INSTANCE.assets.open(configFileName).readBytes())
GSON.fromJsonArray<Config>(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"
)
}

@ -16,7 +16,6 @@ import io.legado.app.constant.EventBus
import io.legado.app.constant.PreferKey import io.legado.app.constant.PreferKey
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
import io.legado.app.help.LauncherIconHelp import io.legado.app.help.LauncherIconHelp
import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.ATH
import io.legado.app.ui.widget.number.NumberPickerDialog import io.legado.app.ui.widget.number.NumberPickerDialog
import io.legado.app.ui.widget.prefs.ColorPreference import io.legado.app.ui.widget.prefs.ColorPreference
@ -28,8 +27,6 @@ import io.legado.app.utils.*
class ThemeConfigFragment : BasePreferenceFragment(), class ThemeConfigFragment : BasePreferenceFragment(),
SharedPreferences.OnSharedPreferenceChangeListener { SharedPreferences.OnSharedPreferenceChangeListener {
val items = App.INSTANCE.resources.getStringArray(R.array.default_themes).toList()
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
addPreferencesFromResource(R.xml.pref_config_theme) addPreferencesFromResource(R.xml.pref_config_theme)
if (Build.VERSION.SDK_INT < 26) { if (Build.VERSION.SDK_INT < 26) {
@ -151,7 +148,6 @@ class ThemeConfigFragment : BasePreferenceFragment(),
@SuppressLint("PrivateResource") @SuppressLint("PrivateResource")
override fun onPreferenceTreeClick(preference: Preference?): Boolean { override fun onPreferenceTreeClick(preference: Preference?): Boolean {
when (preference?.key) { when (preference?.key) {
"defaultTheme" -> changeTheme()
PreferKey.barElevation -> NumberPickerDialog(requireContext()) PreferKey.barElevation -> NumberPickerDialog(requireContext())
.setTitle(getString(R.string.bar_elevation)) .setTitle(getString(R.string.bar_elevation))
.setMaxValue(32) .setMaxValue(32)
@ -166,6 +162,7 @@ class ThemeConfigFragment : BasePreferenceFragment(),
AppConfig.elevation = it AppConfig.elevation = it
recreateActivities() recreateActivities()
} }
"themeList" -> themeListAlert()
"saveDayTheme" -> { "saveDayTheme" -> {
} }
"saveNightTheme" -> { "saveNightTheme" -> {
@ -174,50 +171,8 @@ class ThemeConfigFragment : BasePreferenceFragment(),
return super.onPreferenceTreeClick(preference) return super.onPreferenceTreeClick(preference)
} }
private fun changeTheme() { private fun themeListAlert() {
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 upTheme(isNightTheme: Boolean) { private fun upTheme(isNightTheme: Boolean) {

@ -41,14 +41,6 @@
<item>細體</item> <item>細體</item>
</string-array> </string-array>
<string-array name="default_themes">
<item>极简</item>
<item>曜夜</item>
<item>经典</item>
<item>黑白</item>
<item>A屏黑</item>
</string-array>
<string-array name="language"> <string-array name="language">
<item>跟随系统</item> <item>跟随系统</item>
<item>简体中文</item> <item>简体中文</item>

@ -730,7 +730,6 @@
<string name="replace_enable_default_t">默认启用替换净化</string> <string name="replace_enable_default_t">默认启用替换净化</string>
<string name="replace_enable_default_s">新加入书架的书是否启用替换净化</string> <string name="replace_enable_default_s">新加入书架的书是否启用替换净化</string>
<string name="select_restore_file">选择恢复文件</string> <string name="select_restore_file">选择恢复文件</string>
<string name="select_theme">切换默认主题</string>
<string name="day_background_too_dark">白天背景不能太暗</string> <string name="day_background_too_dark">白天背景不能太暗</string>
<string name="day_bottom_bar_too_dark">白天底栏不能太暗</string> <string name="day_bottom_bar_too_dark">白天底栏不能太暗</string>
<string name="night_background_too_light">夜间背景不能太亮</string> <string name="night_background_too_light">夜间背景不能太亮</string>

@ -97,14 +97,6 @@
<item>細體</item> <item>細體</item>
</string-array> </string-array>
<string-array name="default_themes">
<item>極簡</item>
<item>耀夜</item>
<item>經典</item>
<item>黑白</item>
<item>A屏黑</item>
</string-array>
<string-array name="language"> <string-array name="language">
<item>跟隨系統</item> <item>跟隨系統</item>
<item>簡體中文</item> <item>簡體中文</item>

@ -730,7 +730,6 @@
<string name="replace_enable_default_t">預設啟用取代淨化</string> <string name="replace_enable_default_t">預設啟用取代淨化</string>
<string name="replace_enable_default_s">新加入書架的書是否啟用取代淨化</string> <string name="replace_enable_default_s">新加入書架的書是否啟用取代淨化</string>
<string name="select_restore_file">選擇復原文件</string> <string name="select_restore_file">選擇復原文件</string>
<string name="select_theme">切換預設主題</string>
<string name="day_background_too_dark">白天背景不能太暗</string> <string name="day_background_too_dark">白天背景不能太暗</string>
<string name="day_bottom_bar_too_dark">白天底欄不能太暗</string> <string name="day_bottom_bar_too_dark">白天底欄不能太暗</string>
<string name="night_background_too_light">夜間背景不能太亮</string> <string name="night_background_too_light">夜間背景不能太亮</string>

@ -97,14 +97,6 @@
<item>细体</item> <item>细体</item>
</string-array> </string-array>
<string-array name="default_themes">
<item>极简</item>
<item>曜夜</item>
<item>经典</item>
<item>黑白</item>
<item>A屏黑</item>
</string-array>
<string-array name="language"> <string-array name="language">
<item>跟随系统</item> <item>跟随系统</item>
<item>简体中文</item> <item>简体中文</item>

@ -731,7 +731,6 @@
<string name="replace_enable_default_t">默认启用替换净化</string> <string name="replace_enable_default_t">默认启用替换净化</string>
<string name="replace_enable_default_s">新加入书架的书是否启用替换净化</string> <string name="replace_enable_default_s">新加入书架的书是否启用替换净化</string>
<string name="select_restore_file">选择恢复文件</string> <string name="select_restore_file">选择恢复文件</string>
<string name="select_theme">切换默认主题</string>
<string name="day_background_too_dark">白天背景不能太暗</string> <string name="day_background_too_dark">白天背景不能太暗</string>
<string name="day_bottom_bar_too_dark">白天底栏不能太暗</string> <string name="day_bottom_bar_too_dark">白天底栏不能太暗</string>
<string name="night_background_too_light">夜间背景不能太亮</string> <string name="night_background_too_light">夜间背景不能太亮</string>

@ -97,14 +97,6 @@
<item>Light</item> <item>Light</item>
</string-array> </string-array>
<string-array name="default_themes">
<item>极简</item>
<item>曜夜</item>
<item>经典</item>
<item>黑白</item>
<item>A屏黑</item>
</string-array>
<string-array name="language"> <string-array name="language">
<item>跟随系统</item> <item>跟随系统</item>
<item>简体中文</item> <item>简体中文</item>

@ -732,7 +732,6 @@
<string name="replace_enable_default_t">默认启用替换净化</string> <string name="replace_enable_default_t">默认启用替换净化</string>
<string name="replace_enable_default_s">新加入书架的书是否启用替换净化</string> <string name="replace_enable_default_s">新加入书架的书是否启用替换净化</string>
<string name="select_restore_file">选择恢复文件</string> <string name="select_restore_file">选择恢复文件</string>
<string name="select_theme">切换默认主题</string>
<string name="day_background_too_dark">白天背景不能太暗</string> <string name="day_background_too_dark">白天背景不能太暗</string>
<string name="day_bottom_bar_too_dark">白天底栏不能太暗</string> <string name="day_bottom_bar_too_dark">白天底栏不能太暗</string>
<string name="night_background_too_light">夜间背景不能太亮</string> <string name="night_background_too_light">夜间背景不能太亮</string>

Loading…
Cancel
Save