From 299e52e877d57cd912ac5dab2fe9c087c95ca350 Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 5 Feb 2022 18:51:08 -0500 Subject: [PATCH] Allow disabling secure screen when incognito mode is on --- app/build.gradle.kts | 2 +- .../java/eu/kanade/tachiyomi/Migrations.kt | 7 ++++++ .../data/preference/PreferenceValues.kt | 6 +++++ .../data/preference/PreferencesHelper.kt | 2 +- .../ui/security/SecureActivityDelegate.kt | 5 ++-- .../ui/setting/SettingsSecurityController.kt | 25 +++++++++++++------ app/src/main/res/values/strings.xml | 4 +-- 7 files changed, 38 insertions(+), 13 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 32bc7e4023..bac499dd1c 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -28,7 +28,7 @@ android { applicationId = "eu.kanade.tachiyomi" minSdk = AndroidConfig.minSdk targetSdk = AndroidConfig.targetSdk - versionCode = 74 + versionCode = 75 versionName = "0.13.1" buildConfigField("String", "COMMIT_COUNT", "\"${getCommitCount()}\"") diff --git a/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt b/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt index b1be977b83..8598b23c18 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt @@ -7,6 +7,7 @@ import eu.kanade.tachiyomi.data.backup.BackupCreatorJob import eu.kanade.tachiyomi.data.library.LibraryUpdateJob import eu.kanade.tachiyomi.data.preference.MANGA_ONGOING import eu.kanade.tachiyomi.data.preference.PreferenceKeys +import eu.kanade.tachiyomi.data.preference.PreferenceValues import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.track.TrackManager import eu.kanade.tachiyomi.data.updater.AppUpdateJob @@ -245,6 +246,12 @@ object Migrations { preferences.libraryUpdateMangaRestriction() -= MANGA_ONGOING } } + if (oldVersion < 75) { + val oldSecureScreen = prefs.getBoolean("secure_screen", false) + if (oldSecureScreen) { + preferences.secureScreen().set(PreferenceValues.SecureScreenMode.ALWAYS) + } + } return true } 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 9dd96b5b72..3e5c8d0f1b 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 @@ -67,4 +67,10 @@ object PreferenceValues { PACKAGEINSTALLER, SHIZUKU, } + + enum class SecureScreenMode { + ALWAYS, + INCOGNITO, + 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 e1861bd103..d457394682 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 @@ -57,7 +57,7 @@ class PreferencesHelper(val context: Context) { fun lastAppUnlock() = flowPrefs.getLong("last_app_unlock", 0) - fun secureScreen() = flowPrefs.getBoolean("secure_screen", false) + fun secureScreen() = flowPrefs.getEnum("secure_screen_v2", Values.SecureScreenMode.INCOGNITO) fun hideNotificationContent() = prefs.getBoolean(Keys.hideNotificationContent, false) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/security/SecureActivityDelegate.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/security/SecureActivityDelegate.kt index 69f8d50046..638de82b89 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/security/SecureActivityDelegate.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/security/SecureActivityDelegate.kt @@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.ui.security import android.content.Intent import androidx.fragment.app.FragmentActivity import androidx.lifecycle.lifecycleScope +import eu.kanade.tachiyomi.data.preference.PreferenceValues import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.util.system.AuthenticatorUtil.isAuthenticationSupported import eu.kanade.tachiyomi.util.view.setSecureScreen @@ -19,8 +20,8 @@ class SecureActivityDelegate(private val activity: FragmentActivity) { fun onCreate() { val secureScreenFlow = preferences.secureScreen().asFlow() val incognitoModeFlow = preferences.incognitoMode().asFlow() - secureScreenFlow.combine(incognitoModeFlow) { secureScreen, incognitoMode -> - secureScreen || incognitoMode + combine(secureScreenFlow, incognitoModeFlow) { secureScreen, incognitoMode -> + secureScreen == PreferenceValues.SecureScreenMode.ALWAYS || secureScreen == PreferenceValues.SecureScreenMode.INCOGNITO && incognitoMode } .onEach { activity.window.setSecureScreen(it) } .launchIn(activity.lifecycleScope) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsSecurityController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsSecurityController.kt index 7a2d7da767..4e74facce3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsSecurityController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsSecurityController.kt @@ -5,11 +5,14 @@ import androidx.fragment.app.FragmentActivity import androidx.preference.Preference import androidx.preference.PreferenceScreen import eu.kanade.tachiyomi.R +import eu.kanade.tachiyomi.data.preference.PreferenceValues import eu.kanade.tachiyomi.util.preference.bindTo import eu.kanade.tachiyomi.util.preference.defaultValue +import eu.kanade.tachiyomi.util.preference.entriesRes +import eu.kanade.tachiyomi.util.preference.infoPreference import eu.kanade.tachiyomi.util.preference.intListPreference +import eu.kanade.tachiyomi.util.preference.listPreference import eu.kanade.tachiyomi.util.preference.requireAuthentication -import eu.kanade.tachiyomi.util.preference.summaryRes import eu.kanade.tachiyomi.util.preference.switchPreference import eu.kanade.tachiyomi.util.preference.titleRes import eu.kanade.tachiyomi.util.system.AuthenticatorUtil @@ -80,16 +83,24 @@ class SettingsSecurityController : SettingsController() { } } - switchPreference { - bindTo(preferences.secureScreen()) - titleRes = R.string.secure_screen - summaryRes = R.string.secure_screen_summary - } - switchPreference { key = Keys.hideNotificationContent titleRes = R.string.hide_notification_content defaultValue = false } + + listPreference { + bindTo(preferences.secureScreen()) + titleRes = R.string.secure_screen + summary = "%s" + entriesRes = arrayOf( + R.string.lock_always, + R.string.pref_incognito_mode, + R.string.lock_never, + ) + entryValues = PreferenceValues.SecureScreenMode.values().map { it.name }.toTypedArray() + } + + infoPreference(R.string.secure_screen_summary) } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 21b622b3e6..4ed26f5425 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -185,9 +185,9 @@ After 1 minute After %1$s minutes - Secure screen - Hide app contents when switching apps and block screenshots Hide notification content + Secure screen + Secure screen hides app contents when switching apps and block screenshots NSFW (18+) sources Show in sources and extensions lists