pull/32/head
gedoor 6 years ago
parent ec49c73e81
commit 3fb20d551c
  1. 2
      app/src/main/java/io/legado/app/App.kt
  2. 78
      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,47 +34,49 @@ 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" ->
sharedPreferences.getInt( if (!ColorUtils.isColorLight(
"colorBackground", sharedPreferences.getInt(
App.INSTANCE.getCompatColor(R.color.md_grey_100) "colorBackground",
) App.INSTANCE.getCompatColor(R.color.md_grey_100)
) )
) {
AlertDialog.Builder(App.INSTANCE)
.setTitle("白天背景太暗")
.setMessage("将会恢复默认背景?")
.setPositiveButton(R.string.ok) { dialog, which ->
App.INSTANCE.putPrefInt("colorBackground", App.INSTANCE.getCompatColor(R.color.md_grey_100))
upTheme(false)
}
.setNegativeButton(R.string.cancel) { dialogInterface, i -> upTheme(false) }
.show().upTint
} else {
upTheme(false)
}
"colorPrimaryNight", "colorAccentNight", "colorBackgroundNight" -> if (ColorUtils.isColorLight(
sharedPreferences.getInt(
"colorBackgroundNight",
App.INSTANCE.getCompatColor(R.color.md_grey_800)
) )
) ) {
) { AlertDialog.Builder(App.INSTANCE)
AlertDialog.Builder(App.INSTANCE) .setTitle("白天背景太暗")
.setTitle("夜间背景太亮") .setMessage("将会恢复默认背景?")
.setMessage("将会恢复默认背景?") .setPositiveButton(R.string.ok) { _, _ ->
.setPositiveButton(R.string.ok) { dialog, which -> App.INSTANCE.putPrefInt("colorBackground", App.INSTANCE.getCompatColor(R.color.md_grey_100))
App.INSTANCE.putPrefInt( upTheme(false)
}
.setNegativeButton(R.string.cancel) { _, _ -> upTheme(false) }
.show().upTint
} else {
upTheme(false)
}
"colorPrimaryNight", "colorAccentNight", "colorBackgroundNight" ->
if (ColorUtils.isColorLight(
sharedPreferences.getInt(
"colorBackgroundNight", "colorBackgroundNight",
App.INSTANCE.getCompatColor(R.color.md_grey_800) App.INSTANCE.getCompatColor(R.color.md_grey_800)
) )
upTheme(true) )
} ) {
.setNegativeButton(R.string.cancel) { dialogInterface, i -> upTheme(true) } AlertDialog.Builder(App.INSTANCE)
.show() .setTitle("夜间背景太亮")
} else { .setMessage("将会恢复默认背景?")
upTheme(true) .setPositiveButton(R.string.ok) { _, _ ->
} App.INSTANCE.putPrefInt(
"colorBackgroundNight",
App.INSTANCE.getCompatColor(R.color.md_grey_800)
)
upTheme(true)
}
.setNegativeButton(R.string.cancel) { _, _ -> upTheme(true) }
.show()
} else {
upTheme(true)
}
} }
} }

Loading…
Cancel
Save