From 0493e77cff6e71bcdb8ff679440c4d3df434f326 Mon Sep 17 00:00:00 2001 From: arkon Date: Mon, 23 Aug 2021 12:24:30 -0400 Subject: [PATCH] Split out appearance settings from general section --- .../setting/SettingsAppearanceController.kt | 160 ++++++++++++++++++ .../ui/setting/SettingsGeneralController.kt | 133 --------------- .../ui/setting/SettingsMainController.kt | 6 + .../preference/ThemesPreferenceAdapter.kt | 3 +- app/src/main/res/drawable/ic_palette_24dp.xml | 21 +++ app/src/main/res/values/strings.xml | 18 +- 6 files changed, 200 insertions(+), 141 deletions(-) create mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAppearanceController.kt create mode 100644 app/src/main/res/drawable/ic_palette_24dp.xml diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAppearanceController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAppearanceController.kt new file mode 100644 index 0000000000..3c7d8b50fa --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAppearanceController.kt @@ -0,0 +1,160 @@ +package eu.kanade.tachiyomi.ui.setting + +import android.os.Build +import androidx.preference.PreferenceScreen +import eu.kanade.tachiyomi.R +import eu.kanade.tachiyomi.data.preference.asImmediateFlow +import eu.kanade.tachiyomi.util.preference.defaultValue +import eu.kanade.tachiyomi.util.preference.entriesRes +import eu.kanade.tachiyomi.util.preference.initThenAdd +import eu.kanade.tachiyomi.util.preference.intListPreference +import eu.kanade.tachiyomi.util.preference.listPreference +import eu.kanade.tachiyomi.util.preference.onChange +import eu.kanade.tachiyomi.util.preference.preferenceCategory +import eu.kanade.tachiyomi.util.preference.switchPreference +import eu.kanade.tachiyomi.util.preference.titleRes +import eu.kanade.tachiyomi.util.system.isTablet +import eu.kanade.tachiyomi.widget.preference.ThemesPreference +import kotlinx.coroutines.flow.launchIn +import java.util.Date +import eu.kanade.tachiyomi.data.preference.PreferenceKeys as Keys +import eu.kanade.tachiyomi.data.preference.PreferenceValues as Values + +class SettingsAppearanceController : SettingsController() { + + override fun setupPreferenceScreen(screen: PreferenceScreen) = screen.apply { + titleRes = R.string.pref_category_appearance + + preferenceCategory { + titleRes = R.string.pref_category_theme + + listPreference { + key = Keys.themeMode + titleRes = R.string.pref_theme_mode + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + entriesRes = arrayOf( + R.string.theme_system, + R.string.theme_light, + R.string.theme_dark + ) + entryValues = arrayOf( + Values.ThemeMode.system.name, + Values.ThemeMode.light.name, + Values.ThemeMode.dark.name + ) + defaultValue = Values.ThemeMode.system.name + } else { + entriesRes = arrayOf( + R.string.theme_light, + R.string.theme_dark + ) + entryValues = arrayOf( + Values.ThemeMode.light.name, + Values.ThemeMode.dark.name + ) + defaultValue = Values.ThemeMode.light.name + } + + summary = "%s" + } + initThenAdd(ThemesPreference(context)) { + key = Keys.appTheme + titleRes = R.string.pref_app_theme + + val appThemes = Values.AppTheme.values().filter { + val monetFilter = if (it == Values.AppTheme.MONET) { + Build.VERSION.SDK_INT >= Build.VERSION_CODES.S + } else { + true + } + it.titleResId != null && monetFilter + } + entries = appThemes + defaultValue = appThemes[0].name + + onChange { + activity?.recreate() + true + } + } + switchPreference { + key = Keys.themeDarkAmoled + titleRes = R.string.pref_dark_theme_pure_black + defaultValue = false + + preferences.themeMode().asImmediateFlow { isVisible = it != Values.ThemeMode.light } + .launchIn(viewScope) + + onChange { + activity?.recreate() + true + } + } + } + + preferenceCategory { + titleRes = R.string.pref_category_layout + + if (context.isTablet()) { + intListPreference { + key = Keys.sideNavIconAlignment + titleRes = R.string.pref_side_nav_icon_alignment + entriesRes = arrayOf( + R.string.alignment_top, + R.string.alignment_center, + R.string.alignment_bottom, + ) + entryValues = arrayOf("0", "1", "2") + defaultValue = "0" + summary = "%s" + } + } else { + switchPreference { + key = Keys.hideBottomBarOnScroll + titleRes = R.string.pref_hide_bottom_bar_on_scroll + defaultValue = true + } + } + } + + preferenceCategory { + titleRes = R.string.pref_category_timestamps + + intListPreference { + key = Keys.relativeTime + titleRes = R.string.pref_relative_format + val values = arrayOf("0", "2", "7") + entryValues = values + entries = values.map { + when (it) { + "0" -> context.getString(R.string.off) + "2" -> context.getString(R.string.pref_relative_time_short) + else -> context.getString(R.string.pref_relative_time_long) + } + }.toTypedArray() + defaultValue = "7" + summary = "%s" + } + + listPreference { + key = Keys.dateFormat + titleRes = R.string.pref_date_format + entryValues = arrayOf("", "MM/dd/yy", "dd/MM/yy", "yyyy-MM-dd", "dd MMM yyyy", "MMM dd, yyyy") + + val now = Date().time + entries = entryValues.map { value -> + val formattedDate = preferences.dateFormat(value.toString()).format(now) + if (value == "") { + "${context.getString(R.string.label_default)} ($formattedDate)" + } else { + "$value ($formattedDate)" + } + }.toTypedArray() + + defaultValue = "" + summary = "%s" + } + } + } +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt index a3ad186ab1..f80829c5ac 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt @@ -5,24 +5,14 @@ import android.os.Build import android.provider.Settings import androidx.preference.PreferenceScreen import eu.kanade.tachiyomi.R -import eu.kanade.tachiyomi.data.preference.asImmediateFlow import eu.kanade.tachiyomi.util.preference.defaultValue import eu.kanade.tachiyomi.util.preference.entriesRes -import eu.kanade.tachiyomi.util.preference.initThenAdd import eu.kanade.tachiyomi.util.preference.intListPreference -import eu.kanade.tachiyomi.util.preference.listPreference -import eu.kanade.tachiyomi.util.preference.onChange import eu.kanade.tachiyomi.util.preference.onClick import eu.kanade.tachiyomi.util.preference.preference -import eu.kanade.tachiyomi.util.preference.preferenceCategory import eu.kanade.tachiyomi.util.preference.switchPreference import eu.kanade.tachiyomi.util.preference.titleRes -import eu.kanade.tachiyomi.util.system.isTablet -import eu.kanade.tachiyomi.widget.preference.ThemesPreference -import kotlinx.coroutines.flow.launchIn -import java.util.Date import eu.kanade.tachiyomi.data.preference.PreferenceKeys as Keys -import eu.kanade.tachiyomi.data.preference.PreferenceValues as Values class SettingsGeneralController : SettingsController() { @@ -47,27 +37,6 @@ class SettingsGeneralController : SettingsController() { titleRes = R.string.pref_confirm_exit defaultValue = false } - if (context.isTablet()) { - intListPreference { - key = Keys.sideNavIconAlignment - titleRes = R.string.pref_side_nav_icon_alignment - entriesRes = arrayOf( - R.string.alignment_top, - R.string.alignment_center, - R.string.alignment_bottom, - ) - entryValues = arrayOf("0", "1", "2") - defaultValue = "0" - summary = "%s" - } - } else { - switchPreference { - key = Keys.hideBottomBarOnScroll - titleRes = R.string.pref_hide_bottom_bar_on_scroll - defaultValue = true - } - } - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { preference { key = "pref_manage_notifications" @@ -80,107 +49,5 @@ class SettingsGeneralController : SettingsController() { } } } - intListPreference { - key = Keys.relativeTime - titleRes = R.string.pref_relative_format - val values = arrayOf("0", "2", "7") - entryValues = values - entries = values.map { - when (it) { - "0" -> context.getString(R.string.off) - "2" -> context.getString(R.string.pref_relative_time_short) - else -> context.getString(R.string.pref_relative_time_long) - } - }.toTypedArray() - defaultValue = "7" - summary = "%s" - } - - listPreference { - key = Keys.dateFormat - titleRes = R.string.pref_date_format - entryValues = arrayOf("", "MM/dd/yy", "dd/MM/yy", "yyyy-MM-dd", "dd MMM yyyy", "MMM dd, yyyy") - - val now = Date().time - entries = entryValues.map { value -> - val formattedDate = preferences.dateFormat(value.toString()).format(now) - if (value == "") { - "${context.getString(R.string.label_default)} ($formattedDate)" - } else { - "$value ($formattedDate)" - } - }.toTypedArray() - - defaultValue = "" - summary = "%s" - } - - preferenceCategory { - titleRes = R.string.pref_category_theme - - listPreference { - key = Keys.themeMode - titleRes = R.string.pref_theme_mode - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - entriesRes = arrayOf( - R.string.theme_system, - R.string.theme_light, - R.string.theme_dark - ) - entryValues = arrayOf( - Values.ThemeMode.system.name, - Values.ThemeMode.light.name, - Values.ThemeMode.dark.name - ) - defaultValue = Values.ThemeMode.system.name - } else { - entriesRes = arrayOf( - R.string.theme_light, - R.string.theme_dark - ) - entryValues = arrayOf( - Values.ThemeMode.light.name, - Values.ThemeMode.dark.name - ) - defaultValue = Values.ThemeMode.light.name - } - - summary = "%s" - } - initThenAdd(ThemesPreference(context)) { - key = Keys.appTheme - titleRes = R.string.pref_app_theme - - val appThemes = Values.AppTheme.values().filter { - val monetFilter = if (it == Values.AppTheme.MONET) { - Build.VERSION.SDK_INT >= Build.VERSION_CODES.S - } else { - true - } - it.titleResId != null && monetFilter - } - entries = appThemes - defaultValue = appThemes[0].name - - onChange { - activity?.recreate() - true - } - } - switchPreference { - key = Keys.themeDarkAmoled - titleRes = R.string.pref_dark_theme_pure_black - defaultValue = false - - preferences.themeMode().asImmediateFlow { isVisible = it != Values.ThemeMode.light } - .launchIn(viewScope) - - onChange { - activity?.recreate() - true - } - } - } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsMainController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsMainController.kt index dbf69292b5..c24afb8494 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsMainController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsMainController.kt @@ -28,6 +28,12 @@ class SettingsMainController : SettingsController() { titleRes = R.string.pref_category_general onClick { navigateTo(SettingsGeneralController()) } } + preference { + iconRes = R.drawable.ic_palette_24dp + iconTint = tintColor + titleRes = R.string.pref_category_appearance + onClick { navigateTo(SettingsAppearanceController()) } + } preference { iconRes = R.drawable.ic_library_outline_24dp iconTint = tintColor diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/preference/ThemesPreferenceAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/preference/ThemesPreferenceAdapter.kt index 14f85ff446..5f985325a3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/preference/ThemesPreferenceAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/preference/ThemesPreferenceAdapter.kt @@ -23,7 +23,8 @@ class ThemesPreferenceAdapter(private val clickListener: OnItemClickListener) : override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ThemeViewHolder { val themeResIds = BaseThemedActivity.getThemeResIds(themes[viewType], preferences.themeDarkAmoled().get()) val themedContext = themeResIds.fold(parent.context) { - context, themeResId -> ContextThemeWrapper(context, themeResId) + context, themeResId -> + ContextThemeWrapper(context, themeResId) } binding = PrefThemeItemBinding.inflate(LayoutInflater.from(themedContext), parent, false) diff --git a/app/src/main/res/drawable/ic_palette_24dp.xml b/app/src/main/res/drawable/ic_palette_24dp.xml new file mode 100644 index 0000000000..393dbf26a8 --- /dev/null +++ b/app/src/main/res/drawable/ic_palette_24dp.xml @@ -0,0 +1,21 @@ + + + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b8e032cb8d..7c93530176 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -134,6 +134,7 @@ General + Appearance Library Reader Downloads @@ -158,14 +159,20 @@ Yin & Yang Yotsuba Pure black dark mode - Start screen - Date format - Confirm exit - Hide bottom bar on scroll + Layout Side navigation icon alignment Top Center Bottom + Hide bottom bar on scroll + Timestamps + Relative timestamps + Short (Today, Yesterday) + Long (Short+, n days ago) + Date format + + Start screen + Confirm exit Manage notifications Security @@ -193,9 +200,6 @@ Yesterday %1$d days ago - Relative timestamps - Short (Today, Yesterday) - Long (Short+, n days ago) Display