|
|
|
@ -4,6 +4,7 @@ import android.content.SharedPreferences |
|
|
|
|
import android.os.Bundle |
|
|
|
|
import android.os.Handler |
|
|
|
|
import androidx.appcompat.app.AlertDialog |
|
|
|
|
import androidx.preference.Preference |
|
|
|
|
import androidx.preference.PreferenceFragmentCompat |
|
|
|
|
import com.jeremyliao.liveeventbus.LiveEventBus |
|
|
|
|
import io.legado.app.App |
|
|
|
@ -34,6 +35,7 @@ class ThemeConfigFragment : PreferenceFragmentCompat(), SharedPreferences.OnShar |
|
|
|
|
|
|
|
|
|
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) { |
|
|
|
|
sharedPreferences ?: return |
|
|
|
|
activity ?: return |
|
|
|
|
when (key) { |
|
|
|
|
"colorPrimary", "colorAccent", "colorBackground" -> |
|
|
|
|
if (!ColorUtils.isColorLight( |
|
|
|
@ -43,7 +45,7 @@ class ThemeConfigFragment : PreferenceFragmentCompat(), SharedPreferences.OnShar |
|
|
|
|
) |
|
|
|
|
) |
|
|
|
|
) { |
|
|
|
|
AlertDialog.Builder(App.INSTANCE) |
|
|
|
|
AlertDialog.Builder(activity!!) |
|
|
|
|
.setTitle("白天背景太暗") |
|
|
|
|
.setMessage("将会恢复默认背景?") |
|
|
|
|
.setPositiveButton(R.string.ok) { _, _ -> |
|
|
|
@ -63,7 +65,7 @@ class ThemeConfigFragment : PreferenceFragmentCompat(), SharedPreferences.OnShar |
|
|
|
|
) |
|
|
|
|
) |
|
|
|
|
) { |
|
|
|
|
AlertDialog.Builder(App.INSTANCE) |
|
|
|
|
AlertDialog.Builder(activity!!) |
|
|
|
|
.setTitle("夜间背景太亮") |
|
|
|
|
.setMessage("将会恢复默认背景?") |
|
|
|
|
.setPositiveButton(R.string.ok) { _, _ -> |
|
|
|
@ -82,6 +84,33 @@ class ThemeConfigFragment : PreferenceFragmentCompat(), SharedPreferences.OnShar |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun onPreferenceTreeClick(preference: Preference?): Boolean { |
|
|
|
|
when (preference?.key) { |
|
|
|
|
"defaultTheme" -> { |
|
|
|
|
AlertDialog.Builder(activity!!) |
|
|
|
|
.setTitle("恢复默认主题") |
|
|
|
|
.setMessage("是否确认恢复?") |
|
|
|
|
.setPositiveButton(R.string.ok) { _, _ -> |
|
|
|
|
preferenceManager.sharedPreferences.edit() |
|
|
|
|
.putInt("colorPrimary", App.INSTANCE.getCompatColor(R.color.md_grey_100)) |
|
|
|
|
.putInt("colorAccent", App.INSTANCE.getCompatColor(R.color.md_pink_600)) |
|
|
|
|
.putInt("colorBackground", App.INSTANCE.getCompatColor(R.color.md_grey_100)) |
|
|
|
|
.putInt("colorPrimaryNight", App.INSTANCE.getCompatColor(R.color.md_grey_800)) |
|
|
|
|
.putInt("colorAccentNight", App.INSTANCE.getCompatColor(R.color.md_pink_800)) |
|
|
|
|
.putInt("colorBackgroundNight", App.INSTANCE.getCompatColor(R.color.md_grey_800)) |
|
|
|
|
.apply() |
|
|
|
|
App.INSTANCE.upThemeStore() |
|
|
|
|
LiveEventBus.get().with(Bus.recreate).post("") |
|
|
|
|
Handler().postDelayed({ activity?.recreate() }, 100) |
|
|
|
|
} |
|
|
|
|
.setNegativeButton(R.string.cancel, null) |
|
|
|
|
.show() |
|
|
|
|
.upTint |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return super.onPreferenceTreeClick(preference) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun upTheme(isNightTheme: Boolean) { |
|
|
|
|
if (App.INSTANCE.getPrefBoolean("isNightTheme", false) == isNightTheme) { |
|
|
|
|
App.INSTANCE.upThemeStore() |
|
|
|
|