pull/32/head
gedoor 6 years ago
parent ec49c73e81
commit 3fb20d551c
  1. 2
      app/src/main/java/io/legado/app/App.kt
  2. 16
      app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt

@ -74,8 +74,8 @@ class App : Application() {
} }
fun applyDayNight(){ fun applyDayNight(){
initNightTheme()
upThemeStore() upThemeStore()
initNightTheme()
} }
/** /**

@ -2,6 +2,8 @@ package io.legado.app.ui.config
import android.content.SharedPreferences import android.content.SharedPreferences
import android.os.Bundle import android.os.Bundle
import android.os.Handler
import android.os.Looper
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceFragmentCompat
import io.legado.app.App import io.legado.app.App
@ -32,7 +34,8 @@ class ThemeConfigFragment : PreferenceFragmentCompat(), SharedPreferences.OnShar
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) { override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {
sharedPreferences ?: return sharedPreferences ?: return
when (key) { when (key) {
"colorPrimary", "colorAccent", "colorBackground" -> if (!ColorUtils.isColorLight( "colorPrimary", "colorAccent", "colorBackground" ->
if (!ColorUtils.isColorLight(
sharedPreferences.getInt( sharedPreferences.getInt(
"colorBackground", "colorBackground",
App.INSTANCE.getCompatColor(R.color.md_grey_100) App.INSTANCE.getCompatColor(R.color.md_grey_100)
@ -42,16 +45,17 @@ class ThemeConfigFragment : PreferenceFragmentCompat(), SharedPreferences.OnShar
AlertDialog.Builder(App.INSTANCE) AlertDialog.Builder(App.INSTANCE)
.setTitle("白天背景太暗") .setTitle("白天背景太暗")
.setMessage("将会恢复默认背景?") .setMessage("将会恢复默认背景?")
.setPositiveButton(R.string.ok) { dialog, which -> .setPositiveButton(R.string.ok) { _, _ ->
App.INSTANCE.putPrefInt("colorBackground", App.INSTANCE.getCompatColor(R.color.md_grey_100)) App.INSTANCE.putPrefInt("colorBackground", App.INSTANCE.getCompatColor(R.color.md_grey_100))
upTheme(false) upTheme(false)
} }
.setNegativeButton(R.string.cancel) { dialogInterface, i -> upTheme(false) } .setNegativeButton(R.string.cancel) { _, _ -> upTheme(false) }
.show().upTint .show().upTint
} else { } else {
upTheme(false) upTheme(false)
} }
"colorPrimaryNight", "colorAccentNight", "colorBackgroundNight" -> if (ColorUtils.isColorLight( "colorPrimaryNight", "colorAccentNight", "colorBackgroundNight" ->
if (ColorUtils.isColorLight(
sharedPreferences.getInt( sharedPreferences.getInt(
"colorBackgroundNight", "colorBackgroundNight",
App.INSTANCE.getCompatColor(R.color.md_grey_800) App.INSTANCE.getCompatColor(R.color.md_grey_800)
@ -61,14 +65,14 @@ class ThemeConfigFragment : PreferenceFragmentCompat(), SharedPreferences.OnShar
AlertDialog.Builder(App.INSTANCE) AlertDialog.Builder(App.INSTANCE)
.setTitle("夜间背景太亮") .setTitle("夜间背景太亮")
.setMessage("将会恢复默认背景?") .setMessage("将会恢复默认背景?")
.setPositiveButton(R.string.ok) { dialog, which -> .setPositiveButton(R.string.ok) { _, _ ->
App.INSTANCE.putPrefInt( App.INSTANCE.putPrefInt(
"colorBackgroundNight", "colorBackgroundNight",
App.INSTANCE.getCompatColor(R.color.md_grey_800) App.INSTANCE.getCompatColor(R.color.md_grey_800)
) )
upTheme(true) upTheme(true)
} }
.setNegativeButton(R.string.cancel) { dialogInterface, i -> upTheme(true) } .setNegativeButton(R.string.cancel) { _, _ -> upTheme(true) }
.show() .show()
} else { } else {
upTheme(true) upTheme(true)

Loading…
Cancel
Save