From 5ea0dda75eec92a1b67c8a6262355d5c2884da28 Mon Sep 17 00:00:00 2001 From: Jays2Kings Date: Sat, 10 Apr 2021 16:26:59 -0400 Subject: [PATCH] Splitting Security into a new section Just like upstream (0 idea what commit its from I just know im late) Also taking the description for secure screen because it was dumb of me to assume people know it blocks screenshots Co-Authored-By: arkon <4098258+arkon@users.noreply.github.com> --- .../ui/setting/SettingsGeneralController.kt | 60 +----------------- .../ui/setting/SettingsMainController.kt | 6 ++ .../ui/setting/SettingsSecurityController.kt | 62 +++++++++++++++++++ .../ui/setting/search/SettingsSearchHelper.kt | 2 + .../main/res/drawable/ic_security_24dp.xml | 9 +++ 5 files changed, 82 insertions(+), 57 deletions(-) create mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsSecurityController.kt create mode 100644 app/src/main/res/drawable/ic_security_24dp.xml 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 2acf0c7497..51e5dc88b2 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 @@ -3,19 +3,16 @@ package eu.kanade.tachiyomi.ui.setting import android.os.Bundle import android.view.View import androidx.appcompat.app.AppCompatDelegate -import androidx.biometric.BiometricManager import androidx.preference.PreferenceScreen import eu.kanade.tachiyomi.BuildConfig import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.preference.asImmediateFlow -import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.data.updater.UpdaterJob -import eu.kanade.tachiyomi.ui.security.SecureActivityDelegate import eu.kanade.tachiyomi.util.system.LocaleHelper import eu.kanade.tachiyomi.util.system.appDelegateNightMode import eu.kanade.tachiyomi.util.system.getPrefTheme -import eu.kanade.tachiyomi.widget.preference.IntListMatPreference import kotlinx.coroutines.flow.launchIn +import java.util.Locale import eu.kanade.tachiyomi.data.preference.PreferenceKeys as Keys class SettingsGeneralController : SettingsController() { @@ -134,57 +131,6 @@ class SettingsGeneralController : SettingsController() { } } - preferenceCategory { - titleRes = R.string.security - - val biometricManager = BiometricManager.from(context) - if (biometricManager.canAuthenticate() == BiometricManager.BIOMETRIC_SUCCESS) { - var preference: IntListMatPreference? = null - switchPreference { - key = Keys.useBiometrics - titleRes = R.string.lock_with_biometrics - defaultValue = false - - onChange { - preference?.isVisible = it as Boolean - true - } - } - preference = intListPreference(activity) { - key = Keys.lockAfter - titleRes = R.string.lock_when_idle - isVisible = preferences.useBiometrics().getOrDefault() - val values = listOf(0, 2, 5, 10, 20, 30, 60, 90, 120, -1) - entries = values.mapNotNull { - when (it) { - 0 -> context.getString(R.string.always) - -1 -> context.getString(R.string.never) - else -> resources?.getQuantityString( - R.plurals.after_minutes, - it.toInt(), - it - ) - } - } - entryValues = values - defaultValue = 0 - } - } - - switchPreference { - key = Keys.secureScreen - titleRes = R.string.secure_screen - summaryRes = R.string.hide_tachi_from_recents - defaultValue = false - - onChange { - it as Boolean - SecureActivityDelegate.setSecure(activity, it) - true - } - } - } - preferenceCategory { titleRes = R.string.locale @@ -197,8 +143,8 @@ class SettingsGeneralController : SettingsController() { "pt-BR", "ro", "ru", "sc", "sr", "sv", "th", "tl", "tr", "uk", "vi", "zh-rCN" ) entries = entryValues.map { value -> - val locale = LocaleHelper.getLocaleFromString(value.toString()) - locale?.getDisplayName(locale)?.capitalize() + val locale = LocaleHelper.getLocaleFromString(value) + locale?.getDisplayName(locale)?.capitalize(Locale.ROOT) ?: context.getString(R.string.system_default) } defaultValue = "" 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 222eebbec9..9c18107e8a 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 @@ -66,6 +66,12 @@ class SettingsMainController : SettingsController() { titleRes = R.string.backup onClick { navigateTo(SettingsBackupController()) } } + preference { + iconRes = R.drawable.ic_security_24dp + iconTint = tintColor + titleRes = R.string.security + onClick { navigateTo(SettingsSecurityController()) } + } preference { iconRes = R.drawable.ic_code_24dp iconTint = tintColor 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 new file mode 100644 index 0000000000..190a77a833 --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsSecurityController.kt @@ -0,0 +1,62 @@ +package eu.kanade.tachiyomi.ui.setting + +import androidx.biometric.BiometricManager +import androidx.preference.PreferenceScreen +import eu.kanade.tachiyomi.R +import eu.kanade.tachiyomi.data.preference.PreferenceKeys +import eu.kanade.tachiyomi.data.preference.getOrDefault +import eu.kanade.tachiyomi.ui.security.SecureActivityDelegate +import eu.kanade.tachiyomi.widget.preference.IntListMatPreference + +class SettingsSecurityController : SettingsController() { + override fun setupPreferenceScreen(screen: PreferenceScreen) = screen.apply { + titleRes = R.string.security + + val biometricManager = BiometricManager.from(context) + if (biometricManager.canAuthenticate() == BiometricManager.BIOMETRIC_SUCCESS) { + var preference: IntListMatPreference? = null + switchPreference { + key = PreferenceKeys.useBiometrics + titleRes = R.string.lock_with_biometrics + defaultValue = false + + onChange { + preference?.isVisible = it as Boolean + true + } + } + preference = intListPreference(activity) { + key = PreferenceKeys.lockAfter + titleRes = R.string.lock_when_idle + isVisible = preferences.useBiometrics().getOrDefault() + val values = listOf(0, 2, 5, 10, 20, 30, 60, 90, 120, -1) + entries = values.mapNotNull { + when (it) { + 0 -> context.getString(R.string.always) + -1 -> context.getString(R.string.never) + else -> resources?.getQuantityString( + R.plurals.after_minutes, + it, + it + ) + } + } + entryValues = values + defaultValue = 0 + } + } + + switchPreference { + key = PreferenceKeys.secureScreen + titleRes = R.string.secure_screen + summaryRes = R.string.hide_app_block_screenshots + defaultValue = false + + onChange { + it as Boolean + SecureActivityDelegate.setSecure(activity, it) + true + } + } + } +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/search/SettingsSearchHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/search/SettingsSearchHelper.kt index 7c8e8f513d..821a135c74 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/search/SettingsSearchHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/search/SettingsSearchHelper.kt @@ -15,6 +15,7 @@ import eu.kanade.tachiyomi.ui.setting.SettingsDownloadController import eu.kanade.tachiyomi.ui.setting.SettingsGeneralController import eu.kanade.tachiyomi.ui.setting.SettingsLibraryController import eu.kanade.tachiyomi.ui.setting.SettingsReaderController +import eu.kanade.tachiyomi.ui.setting.SettingsSecurityController import eu.kanade.tachiyomi.ui.setting.SettingsTrackingController import eu.kanade.tachiyomi.util.system.isLTR import eu.kanade.tachiyomi.util.system.launchNow @@ -33,6 +34,7 @@ object SettingsSearchHelper { SettingsBrowseController::class, SettingsDownloadController::class, SettingsGeneralController::class, + SettingsSecurityController::class, SettingsLibraryController::class, SettingsReaderController::class, SettingsTrackingController::class diff --git a/app/src/main/res/drawable/ic_security_24dp.xml b/app/src/main/res/drawable/ic_security_24dp.xml new file mode 100644 index 0000000000..0cde5e26b7 --- /dev/null +++ b/app/src/main/res/drawable/ic_security_24dp.xml @@ -0,0 +1,9 @@ + + +