From 41952f02156c888c68157ce123f82c1a6f8a323c Mon Sep 17 00:00:00 2001 From: OncePunchedMan <64155117+OncePunchedMan@users.noreply.github.com> Date: Thu, 11 Nov 2021 22:32:28 +0100 Subject: [PATCH] Added tabletUI option: "Automatic" (#6208) * added automatic tablet ui option; useful for foldables * set automatic as default, rename setting * remove redundant checks Co-authored-by: Ivan Iskandar <12537387+ivaniskandar@users.noreply.github.com> * remove redundant checks Co-authored-by: Ivan Iskandar <12537387+ivaniskandar@users.noreply.github.com> * fix defaultValue Co-authored-by: Ivan Iskandar <12537387+ivaniskandar@users.noreply.github.com> --- .../kanade/tachiyomi/data/preference/PreferenceValues.kt | 1 + .../kanade/tachiyomi/data/preference/PreferencesHelper.kt | 5 +---- .../tachiyomi/ui/setting/SettingsAdvancedController.kt | 8 ++------ .../eu/kanade/tachiyomi/util/system/ContextExtensions.kt | 1 + app/src/main/res/values/strings.xml | 2 +- 5 files changed, 6 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceValues.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceValues.kt index f7a6e40f0..d06d5c9b4 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceValues.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceValues.kt @@ -53,6 +53,7 @@ object PreferenceValues { } enum class TabletUiMode { + AUTOMATIC, ALWAYS, LANDSCAPE, NEVER, diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt index 64bd3cfd3..740bebb6e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt @@ -326,10 +326,7 @@ class PreferencesHelper(val context: Context) { fun incognitoMode() = flowPrefs.getBoolean(Keys.incognitoMode, false) - fun tabletUiMode() = flowPrefs.getEnum( - Keys.tabletUiMode, - if (context.applicationContext.isTablet()) Values.TabletUiMode.ALWAYS else Values.TabletUiMode.NEVER - ) + fun tabletUiMode() = flowPrefs.getEnum(Keys.tabletUiMode, Values.TabletUiMode.AUTOMATIC) fun extensionInstaller() = flowPrefs.getEnum( Keys.extensionInstaller, diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAdvancedController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAdvancedController.kt index a397ea827..1030286c2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAdvancedController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAdvancedController.kt @@ -247,13 +247,9 @@ class SettingsAdvancedController : SettingsController() { key = Keys.tabletUiMode titleRes = R.string.pref_tablet_ui_mode summary = "%s" - entriesRes = arrayOf(R.string.lock_always, R.string.landscape, R.string.lock_never) + entriesRes = arrayOf(R.string.automatic_background, R.string.lock_always, R.string.landscape, R.string.lock_never) entryValues = PreferenceValues.TabletUiMode.values().map { it.name }.toTypedArray() - defaultValue = if (context.isTablet()) { - PreferenceValues.TabletUiMode.ALWAYS - } else { - PreferenceValues.TabletUiMode.NEVER - }.name + defaultValue = PreferenceValues.TabletUiMode.AUTOMATIC.name onChange { activity?.toast(R.string.requires_app_restart) diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt index f02bef0e1..870c699c6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/system/ContextExtensions.kt @@ -316,6 +316,7 @@ fun Context.isTablet(): Boolean { fun Context.prepareTabletUiContext(): Context { val configuration = resources.configuration val expected = when (Injekt.get().tabletUiMode().get()) { + PreferenceValues.TabletUiMode.AUTOMATIC -> isTablet() PreferenceValues.TabletUiMode.ALWAYS -> true PreferenceValues.TabletUiMode.LANDSCAPE -> configuration.orientation == Configuration.ORIENTATION_LANDSCAPE PreferenceValues.TabletUiMode.NEVER -> false diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 353b19264..baec15159 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -476,7 +476,7 @@ Battery optimization is already disabled Couldn\'t open device settings Some manufacturers have additional app restrictions that kill background services. This website has more info on how to fix it. - Force tablet UI + Tablet UI Verbose logging Print verbose logs to system log (reduces app performance)