From 7d34ff214cad896abc2a834300d632ddce0a732f Mon Sep 17 00:00:00 2001 From: Ivan Iskandar <12537387+ivaniskandar@users.noreply.github.com> Date: Wed, 23 Nov 2022 21:14:55 +0700 Subject: [PATCH] Change settings screen to object (#8604) --- .../more/settings/screen/AboutScreen.kt | 92 +++++----- .../settings/screen/SettingsAdvancedScreen.kt | 2 +- .../screen/SettingsAppearanceScreen.kt | 2 +- .../settings/screen/SettingsBackupScreen.kt | 2 +- .../settings/screen/SettingsBrowseScreen.kt | 2 +- .../settings/screen/SettingsDownloadScreen.kt | 2 +- .../settings/screen/SettingsGeneralScreen.kt | 2 +- .../settings/screen/SettingsLibraryScreen.kt | 2 +- .../settings/screen/SettingsMainScreen.kt | 160 +++++++++--------- .../settings/screen/SettingsReaderScreen.kt | 2 +- .../settings/screen/SettingsSearchScreen.kt | 20 +-- .../settings/screen/SettingsSecurityScreen.kt | 2 +- .../settings/screen/SettingsTrackingScreen.kt | 2 +- .../ui/setting/SettingsMainController.kt | 10 +- 14 files changed, 150 insertions(+), 152 deletions(-) diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/AboutScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/AboutScreen.kt index 9724b8e65e..ebd386a96c 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/AboutScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/AboutScreen.kt @@ -52,7 +52,7 @@ import java.text.SimpleDateFormat import java.util.Locale import java.util.TimeZone -class AboutScreen : Screen { +object AboutScreen : Screen { @Composable override fun Content() { @@ -199,56 +199,54 @@ class AboutScreen : Screen { } } - companion object { - fun getVersionName(withBuildDate: Boolean): String { - return when { - BuildConfig.DEBUG -> { - "Debug ${BuildConfig.COMMIT_SHA}".let { - if (withBuildDate) { - "$it (${getFormattedBuildTime()})" - } else { - it - } - } - } - BuildConfig.PREVIEW -> { - "Preview r${BuildConfig.COMMIT_COUNT}".let { - if (withBuildDate) { - "$it (${BuildConfig.COMMIT_SHA}, ${getFormattedBuildTime()})" - } else { - "$it (${BuildConfig.COMMIT_SHA})" - } - } - } - else -> { - "Stable ${BuildConfig.VERSION_NAME}".let { - if (withBuildDate) { - "$it (${getFormattedBuildTime()})" - } else { - it - } + fun getVersionName(withBuildDate: Boolean): String { + return when { + BuildConfig.DEBUG -> { + "Debug ${BuildConfig.COMMIT_SHA}".let { + if (withBuildDate) { + "$it (${getFormattedBuildTime()})" + } else { + it } } } - } - - private fun getFormattedBuildTime(): String { - return try { - val inputDf = SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'", Locale.US) - inputDf.timeZone = TimeZone.getTimeZone("UTC") - val buildTime = inputDf.parse(BuildConfig.BUILD_TIME) - - val outputDf = DateFormat.getDateTimeInstance( - DateFormat.MEDIUM, - DateFormat.SHORT, - Locale.getDefault(), - ) - outputDf.timeZone = TimeZone.getDefault() - - buildTime!!.toDateTimestampString(UiPreferences.dateFormat(Injekt.get().dateFormat().get())) - } catch (e: Exception) { - BuildConfig.BUILD_TIME + BuildConfig.PREVIEW -> { + "Preview r${BuildConfig.COMMIT_COUNT}".let { + if (withBuildDate) { + "$it (${BuildConfig.COMMIT_SHA}, ${getFormattedBuildTime()})" + } else { + "$it (${BuildConfig.COMMIT_SHA})" + } + } + } + else -> { + "Stable ${BuildConfig.VERSION_NAME}".let { + if (withBuildDate) { + "$it (${getFormattedBuildTime()})" + } else { + it + } + } } } } + + private fun getFormattedBuildTime(): String { + return try { + val inputDf = SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'", Locale.US) + inputDf.timeZone = TimeZone.getTimeZone("UTC") + val buildTime = inputDf.parse(BuildConfig.BUILD_TIME) + + val outputDf = DateFormat.getDateTimeInstance( + DateFormat.MEDIUM, + DateFormat.SHORT, + Locale.getDefault(), + ) + outputDf.timeZone = TimeZone.getDefault() + + buildTime!!.toDateTimestampString(UiPreferences.dateFormat(Injekt.get().dateFormat().get())) + } catch (e: Exception) { + BuildConfig.BUILD_TIME + } + } } diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsAdvancedScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsAdvancedScreen.kt index 051ad2f83e..d1c8de7a1c 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsAdvancedScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsAdvancedScreen.kt @@ -68,7 +68,7 @@ import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get import java.io.File -class SettingsAdvancedScreen : SearchableSettings { +object SettingsAdvancedScreen : SearchableSettings { @ReadOnlyComposable @Composable @StringRes diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsAppearanceScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsAppearanceScreen.kt index fa384feeb8..2235daed10 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsAppearanceScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsAppearanceScreen.kt @@ -27,7 +27,7 @@ import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get import java.util.Date -class SettingsAppearanceScreen : SearchableSettings { +object SettingsAppearanceScreen : SearchableSettings { @ReadOnlyComposable @Composable diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsBackupScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsBackupScreen.kt index d43db754f9..904a8ec76a 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsBackupScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsBackupScreen.kt @@ -59,7 +59,7 @@ import kotlinx.coroutines.launch import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get -class SettingsBackupScreen : SearchableSettings { +object SettingsBackupScreen : SearchableSettings { @ReadOnlyComposable @Composable diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsBrowseScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsBrowseScreen.kt index 9756675489..2e0c8f9cfc 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsBrowseScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsBrowseScreen.kt @@ -16,7 +16,7 @@ import eu.kanade.tachiyomi.util.system.AuthenticatorUtil.authenticate import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get -class SettingsBrowseScreen : SearchableSettings { +object SettingsBrowseScreen : SearchableSettings { @ReadOnlyComposable @Composable diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsDownloadScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsDownloadScreen.kt index e5e42b0a05..f42b83eef9 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsDownloadScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsDownloadScreen.kt @@ -32,7 +32,7 @@ import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get import java.io.File -class SettingsDownloadScreen : SearchableSettings { +object SettingsDownloadScreen : SearchableSettings { @ReadOnlyComposable @Composable diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsGeneralScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsGeneralScreen.kt index 62fc12a88b..e518636ac9 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsGeneralScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsGeneralScreen.kt @@ -25,7 +25,7 @@ import org.xmlpull.v1.XmlPullParser import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get -class SettingsGeneralScreen : SearchableSettings { +object SettingsGeneralScreen : SearchableSettings { @Composable @ReadOnlyComposable diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsLibraryScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsLibraryScreen.kt index 14091b3a18..5ee9637b9f 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsLibraryScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsLibraryScreen.kt @@ -61,7 +61,7 @@ import kotlinx.coroutines.runBlocking import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get -class SettingsLibraryScreen : SearchableSettings { +object SettingsLibraryScreen : SearchableSettings { @Composable @ReadOnlyComposable diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsMainScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsMainScreen.kt index d066e99e21..d4a7e85b47 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsMainScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsMainScreen.kt @@ -175,84 +175,84 @@ object SettingsMainScreen : Screen { private fun Navigator.navigate(screen: Screen, twoPane: Boolean) { if (twoPane) replaceAll(screen) else push(screen) } + + private data class Item( + @StringRes val titleRes: Int, + @StringRes val subtitleRes: Int, + val formatSubtitle: @Composable () -> String = { stringResource(subtitleRes) }, + val icon: ImageVector, + val screen: Screen, + ) + + private val items = listOf( + Item( + titleRes = R.string.pref_category_general, + subtitleRes = R.string.pref_general_summary, + icon = Icons.Outlined.Tune, + screen = SettingsGeneralScreen, + ), + Item( + titleRes = R.string.pref_category_appearance, + subtitleRes = R.string.pref_appearance_summary, + icon = Icons.Outlined.Palette, + screen = SettingsAppearanceScreen, + ), + Item( + titleRes = R.string.pref_category_library, + subtitleRes = R.string.pref_library_summary, + icon = Icons.Outlined.CollectionsBookmark, + screen = SettingsLibraryScreen, + ), + Item( + titleRes = R.string.pref_category_reader, + subtitleRes = R.string.pref_reader_summary, + icon = Icons.Outlined.ChromeReaderMode, + screen = SettingsReaderScreen, + ), + Item( + titleRes = R.string.pref_category_downloads, + subtitleRes = R.string.pref_downloads_summary, + icon = Icons.Outlined.GetApp, + screen = SettingsDownloadScreen, + ), + Item( + titleRes = R.string.pref_category_tracking, + subtitleRes = R.string.pref_tracking_summary, + icon = Icons.Outlined.Sync, + screen = SettingsTrackingScreen, + ), + Item( + titleRes = R.string.browse, + subtitleRes = R.string.pref_browse_summary, + icon = Icons.Outlined.Explore, + screen = SettingsBrowseScreen, + ), + Item( + titleRes = R.string.label_backup, + subtitleRes = R.string.pref_backup_summary, + icon = Icons.Outlined.SettingsBackupRestore, + screen = SettingsBackupScreen, + ), + Item( + titleRes = R.string.pref_category_security, + subtitleRes = R.string.pref_security_summary, + icon = Icons.Outlined.Security, + screen = SettingsSecurityScreen, + ), + Item( + titleRes = R.string.pref_category_advanced, + subtitleRes = R.string.pref_advanced_summary, + icon = Icons.Outlined.Code, + screen = SettingsAdvancedScreen, + ), + Item( + titleRes = R.string.pref_category_about, + subtitleRes = 0, + formatSubtitle = { + "${stringResource(R.string.app_name)} ${AboutScreen.getVersionName(withBuildDate = false)}" + }, + icon = Icons.Outlined.Info, + screen = AboutScreen, + ), + ) } - -private data class Item( - @StringRes val titleRes: Int, - @StringRes val subtitleRes: Int, - val formatSubtitle: @Composable () -> String = { stringResource(subtitleRes) }, - val icon: ImageVector, - val screen: Screen, -) - -private val items = listOf( - Item( - titleRes = R.string.pref_category_general, - subtitleRes = R.string.pref_general_summary, - icon = Icons.Outlined.Tune, - screen = SettingsGeneralScreen(), - ), - Item( - titleRes = R.string.pref_category_appearance, - subtitleRes = R.string.pref_appearance_summary, - icon = Icons.Outlined.Palette, - screen = SettingsAppearanceScreen(), - ), - Item( - titleRes = R.string.pref_category_library, - subtitleRes = R.string.pref_library_summary, - icon = Icons.Outlined.CollectionsBookmark, - screen = SettingsLibraryScreen(), - ), - Item( - titleRes = R.string.pref_category_reader, - subtitleRes = R.string.pref_reader_summary, - icon = Icons.Outlined.ChromeReaderMode, - screen = SettingsReaderScreen(), - ), - Item( - titleRes = R.string.pref_category_downloads, - subtitleRes = R.string.pref_downloads_summary, - icon = Icons.Outlined.GetApp, - screen = SettingsDownloadScreen(), - ), - Item( - titleRes = R.string.pref_category_tracking, - subtitleRes = R.string.pref_tracking_summary, - icon = Icons.Outlined.Sync, - screen = SettingsTrackingScreen(), - ), - Item( - titleRes = R.string.browse, - subtitleRes = R.string.pref_browse_summary, - icon = Icons.Outlined.Explore, - screen = SettingsBrowseScreen(), - ), - Item( - titleRes = R.string.label_backup, - subtitleRes = R.string.pref_backup_summary, - icon = Icons.Outlined.SettingsBackupRestore, - screen = SettingsBackupScreen(), - ), - Item( - titleRes = R.string.pref_category_security, - subtitleRes = R.string.pref_security_summary, - icon = Icons.Outlined.Security, - screen = SettingsSecurityScreen(), - ), - Item( - titleRes = R.string.pref_category_advanced, - subtitleRes = R.string.pref_advanced_summary, - icon = Icons.Outlined.Code, - screen = SettingsAdvancedScreen(), - ), - Item( - titleRes = R.string.pref_category_about, - subtitleRes = 0, - formatSubtitle = { - "${stringResource(R.string.app_name)} ${AboutScreen.getVersionName(withBuildDate = false)}" - }, - icon = Icons.Outlined.Info, - screen = AboutScreen(), - ), -) diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsReaderScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsReaderScreen.kt index fd835cdb51..cc327de215 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsReaderScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsReaderScreen.kt @@ -21,7 +21,7 @@ import eu.kanade.tachiyomi.util.system.isReleaseBuildType import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get -class SettingsReaderScreen : SearchableSettings { +object SettingsReaderScreen : SearchableSettings { @ReadOnlyComposable @Composable diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsSearchScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsSearchScreen.kt index 2bd64fad7b..846add570e 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsSearchScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsSearchScreen.kt @@ -282,16 +282,16 @@ private fun getLocalizedBreadcrumb(path: String, node: String?): String { } private val settingScreens = listOf( - SettingsGeneralScreen(), - SettingsAppearanceScreen(), - SettingsLibraryScreen(), - SettingsReaderScreen(), - SettingsDownloadScreen(), - SettingsTrackingScreen(), - SettingsBrowseScreen(), - SettingsBackupScreen(), - SettingsSecurityScreen(), - SettingsAdvancedScreen(), + SettingsGeneralScreen, + SettingsAppearanceScreen, + SettingsLibraryScreen, + SettingsReaderScreen, + SettingsDownloadScreen, + SettingsTrackingScreen, + SettingsBrowseScreen, + SettingsBackupScreen, + SettingsSecurityScreen, + SettingsAdvancedScreen, ) private data class SettingsData( diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsSecurityScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsSecurityScreen.kt index 1b7fa736c8..c560dff7f5 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsSecurityScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsSecurityScreen.kt @@ -18,7 +18,7 @@ import eu.kanade.tachiyomi.util.system.AuthenticatorUtil.isAuthenticationSupport import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get -class SettingsSecurityScreen : SearchableSettings { +object SettingsSecurityScreen : SearchableSettings { @ReadOnlyComposable @Composable diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsTrackingScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsTrackingScreen.kt index ba04de027f..a94ce45c4d 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsTrackingScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsTrackingScreen.kt @@ -59,7 +59,7 @@ import eu.kanade.tachiyomi.util.system.toast import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get -class SettingsTrackingScreen : SearchableSettings { +object SettingsTrackingScreen : SearchableSettings { @ReadOnlyComposable @Composable 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 b9ac2e98a1..18fbfbbc75 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 @@ -45,9 +45,9 @@ class SettingsMainController(bundle: Bundle = bundleOf()) : BasicFullComposeCont if (!isTabletUi) { Navigator( screen = if (toBackupScreen) { - SettingsBackupScreen() + SettingsBackupScreen } else if (toAboutScreen) { - AboutScreen() + AboutScreen } else { SettingsMainScreen }, @@ -63,11 +63,11 @@ class SettingsMainController(bundle: Bundle = bundleOf()) : BasicFullComposeCont } else { Navigator( screen = if (toBackupScreen) { - SettingsBackupScreen() + SettingsBackupScreen } else if (toAboutScreen) { - AboutScreen() + AboutScreen } else { - SettingsGeneralScreen() + SettingsGeneralScreen }, ) { TwoPanelBox(