From 83a831371ee1eddda508e658403f4e1fee7150ce Mon Sep 17 00:00:00 2001 From: Jays2Kings Date: Wed, 14 Jul 2021 19:44:15 -0400 Subject: [PATCH] Fix crash in general settings (again) --- .../tachiyomi/ui/setting/ThemePreference.kt | 36 +++++++++++++------ 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/ThemePreference.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/ThemePreference.kt index a5639d2d4c..43c9f10972 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/ThemePreference.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/ThemePreference.kt @@ -164,7 +164,7 @@ class ThemePreference @JvmOverloads constructor(context: Context, attrs: Attribu } } - inner class ThemeItem(val theme: Themes, val darkTheme: Boolean) : AbstractItem>() { + inner class ThemeItem(val theme: Themes, val isDarkTheme: Boolean) : AbstractItem>() { /** defines the type defining this item. must be unique. preferably an id */ override val type: Int = R.id.theme_card_view @@ -178,15 +178,29 @@ class ThemePreference @JvmOverloads constructor(context: Context, attrs: Attribu return ViewHolder(v) } - val colors = theme.getColors(if (darkTheme) AppCompatDelegate.MODE_NIGHT_YES else AppCompatDelegate.MODE_NIGHT_NO) + val colors = theme.getColors(if (isDarkTheme) AppCompatDelegate.MODE_NIGHT_YES else AppCompatDelegate.MODE_NIGHT_NO) @Suppress("UNUSED_PARAMETER") override var isSelected: Boolean - get() = when (preferences.nightMode().get()) { - AppCompatDelegate.MODE_NIGHT_YES -> preferences.darkTheme().get() == theme && darkTheme - AppCompatDelegate.MODE_NIGHT_NO -> preferences.lightTheme().get() == theme && !darkTheme - else -> (preferences.darkTheme().get() == theme && darkTheme) || - (preferences.lightTheme().get() == theme && !darkTheme) + get() { + val darkTheme = try { + preferences.darkTheme().get() + } catch (_: Exception) { + ThemeUtil.convertNewThemes(preferences.context) + preferences.darkTheme().get() + } + val lightTheme = try { + preferences.lightTheme().get() + } catch (_: Exception) { + ThemeUtil.convertNewThemes(preferences.context) + preferences.lightTheme().get() + } + return when (preferences.nightMode().get()) { + AppCompatDelegate.MODE_NIGHT_YES -> darkTheme == theme && isDarkTheme + AppCompatDelegate.MODE_NIGHT_NO -> lightTheme == theme && !isDarkTheme + else -> (darkTheme == theme && isDarkTheme) || + (lightTheme == theme && !isDarkTheme) + } } set(value) {} @@ -195,7 +209,7 @@ class ThemePreference @JvmOverloads constructor(context: Context, attrs: Attribu val binding = ThemeItemBinding.bind(view) override fun bindView(item: ThemeItem, payloads: List) { binding.themeNameText.setText( - if (item.darkTheme) { + if (item.isDarkTheme) { item.theme.darkNameRes } else { item.theme.nameRes @@ -207,9 +221,9 @@ class ThemePreference @JvmOverloads constructor(context: Context, attrs: Attribu if (binding.checkbox.isVisible) { val themeMatchesApp = if (context.isInNightMode()) { - item.darkTheme + item.isDarkTheme } else { - !item.darkTheme + !item.isDarkTheme } binding.themeSelected.alpha = if (themeMatchesApp) 1f else 0.5f binding.checkbox.alpha = if (themeMatchesApp) 1f else 0.5f @@ -235,7 +249,7 @@ class ThemePreference @JvmOverloads constructor(context: Context, attrs: Attribu binding.themeItem3.imageTintList = ColorStateList.valueOf(item.colors.inactiveTab) binding.themeLayout.setBackgroundColor(item.colors.colorBackground) - if (item.darkTheme && preferences.themeDarkAmoled().get()) { + if (item.isDarkTheme && preferences.themeDarkAmoled().get()) { binding.themeLayout.setBackgroundColor(Color.BLACK) if (!ThemeUtil.isColoredTheme(item.theme)) { binding.themeBottomBar.setBackgroundColor(Color.BLACK)