pull/32/head
gedoor 6 years ago
parent 5b1f4ad4a2
commit a7c6e1ba62
  1. 23
      app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt

@ -35,7 +35,6 @@ class ThemeConfigFragment : PreferenceFragmentCompat(), SharedPreferences.OnShar
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) { override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {
sharedPreferences ?: return sharedPreferences ?: return
activity ?: return
when (key) { when (key) {
"colorPrimary", "colorAccent", "colorBackground" -> "colorPrimary", "colorAccent", "colorBackground" ->
if (!ColorUtils.isColorLight( if (!ColorUtils.isColorLight(
@ -45,15 +44,20 @@ class ThemeConfigFragment : PreferenceFragmentCompat(), SharedPreferences.OnShar
) )
) )
) { ) {
AlertDialog.Builder(activity!!) activity?.let {
AlertDialog.Builder(it)
.setTitle("白天背景太暗") .setTitle("白天背景太暗")
.setMessage("将会恢复默认背景?") .setMessage("将会恢复默认背景?")
.setPositiveButton(R.string.ok) { _, _ -> .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) { _, _ -> upTheme(false) } .setNegativeButton(R.string.cancel) { _, _ -> upTheme(false) }
.show().upTint .show().upTint
}
} else { } else {
upTheme(false) upTheme(false)
} }
@ -65,7 +69,8 @@ class ThemeConfigFragment : PreferenceFragmentCompat(), SharedPreferences.OnShar
) )
) )
) { ) {
AlertDialog.Builder(activity!!) activity?.let {
AlertDialog.Builder(it)
.setTitle("夜间背景太亮") .setTitle("夜间背景太亮")
.setMessage("将会恢复默认背景?") .setMessage("将会恢复默认背景?")
.setPositiveButton(R.string.ok) { _, _ -> .setPositiveButton(R.string.ok) { _, _ ->
@ -76,7 +81,8 @@ class ThemeConfigFragment : PreferenceFragmentCompat(), SharedPreferences.OnShar
upTheme(true) upTheme(true)
} }
.setNegativeButton(R.string.cancel) { _, _ -> upTheme(true) } .setNegativeButton(R.string.cancel) { _, _ -> upTheme(true) }
.show() .show().upTint
}
} else { } else {
upTheme(true) upTheme(true)
} }
@ -87,7 +93,8 @@ class ThemeConfigFragment : PreferenceFragmentCompat(), SharedPreferences.OnShar
override fun onPreferenceTreeClick(preference: Preference?): Boolean { override fun onPreferenceTreeClick(preference: Preference?): Boolean {
when (preference?.key) { when (preference?.key) {
"defaultTheme" -> { "defaultTheme" -> {
AlertDialog.Builder(activity!!) activity?.let {
AlertDialog.Builder(it)
.setTitle("恢复默认主题") .setTitle("恢复默认主题")
.setMessage("是否确认恢复?") .setMessage("是否确认恢复?")
.setPositiveButton(R.string.ok) { _, _ -> .setPositiveButton(R.string.ok) { _, _ ->
@ -104,8 +111,8 @@ class ThemeConfigFragment : PreferenceFragmentCompat(), SharedPreferences.OnShar
Handler().postDelayed({ activity?.recreate() }, 100) Handler().postDelayed({ activity?.recreate() }, 100)
} }
.setNegativeButton(R.string.cancel, null) .setNegativeButton(R.string.cancel, null)
.show() .show().upTint
.upTint }
} }
} }
return super.onPreferenceTreeClick(preference) return super.onPreferenceTreeClick(preference)

Loading…
Cancel
Save