From 8ae15141f6f8f0c08d8a53de77a610337fe602e6 Mon Sep 17 00:00:00 2001 From: arkon Date: Wed, 4 Mar 2020 22:32:45 -0500 Subject: [PATCH] Move security settings to separate section --- .../ui/setting/SettingsGeneralController.kt | 45 --------------- .../ui/setting/SettingsMainController.kt | 6 ++ .../ui/setting/SettingsSecurityController.kt | 56 +++++++++++++++++++ .../res/drawable/ic_security_black_24dp.xml | 9 +++ 4 files changed, 71 insertions(+), 45 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_black_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 1962ee204..82f11d790 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,7 +3,6 @@ package eu.kanade.tachiyomi.ui.setting import android.content.Intent import android.os.Build import android.provider.Settings -import androidx.biometric.BiometricManager import androidx.preference.PreferenceScreen import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.preference.PreferenceKeys as Keys @@ -17,8 +16,6 @@ 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.summaryRes -import eu.kanade.tachiyomi.util.preference.switchPreference import eu.kanade.tachiyomi.util.preference.titleRes import eu.kanade.tachiyomi.util.system.LocaleHelper @@ -144,47 +141,5 @@ class SettingsGeneralController : SettingsController() { } } } - - preferenceCategory { - titleRes = R.string.pref_category_security - - if (BiometricManager.from(context).canAuthenticate() == BiometricManager.BIOMETRIC_SUCCESS) { - switchPreference { - key = Keys.useBiometricLock - titleRes = R.string.lock_with_biometrics - defaultValue = false - } - intListPreference { - key = Keys.lockAppAfter - titleRes = R.string.lock_when_idle - val values = arrayOf("0", "1", "2", "5", "10", "-1") - entries = values.mapNotNull { - when (it) { - "-1" -> context.getString(R.string.lock_never) - "0" -> context.getString(R.string.lock_always) - else -> resources?.getQuantityString(R.plurals.lock_after_mins, it.toInt(), it) - } - }.toTypedArray() - entryValues = values - defaultValue = "0" - summary = "%s" - - preferences.useBiometricLock().asObservable() - .subscribeUntilDestroy { isVisible = it } - } - } - - switchPreference { - key = Keys.secureScreen - titleRes = R.string.secure_screen - summaryRes = R.string.secure_screen_summary - defaultValue = false - } - switchPreference { - key = Keys.hideNotificationContent - titleRes = R.string.hide_notification_content - defaultValue = false - } - } } } 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 303100214..379e97fb7 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 @@ -53,6 +53,12 @@ class SettingsMainController : SettingsController() { titleRes = R.string.backup onClick { navigateTo(SettingsBackupController()) } } + preference { + iconRes = R.drawable.ic_security_black_24dp + iconTint = tintColor + titleRes = R.string.pref_category_security + onClick { navigateTo(SettingsSecurityController()) } + } preference { iconRes = R.drawable.ic_code_black_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 000000000..45385929a --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsSecurityController.kt @@ -0,0 +1,56 @@ +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 as Keys +import eu.kanade.tachiyomi.util.preference.defaultValue +import eu.kanade.tachiyomi.util.preference.intListPreference +import eu.kanade.tachiyomi.util.preference.summaryRes +import eu.kanade.tachiyomi.util.preference.switchPreference +import eu.kanade.tachiyomi.util.preference.titleRes + +class SettingsSecurityController : SettingsController() { + + override fun setupPreferenceScreen(screen: PreferenceScreen) = with(screen) { + titleRes = R.string.pref_category_security + + if (BiometricManager.from(context).canAuthenticate() == BiometricManager.BIOMETRIC_SUCCESS) { + switchPreference { + key = Keys.useBiometricLock + titleRes = R.string.lock_with_biometrics + defaultValue = false + } + intListPreference { + key = Keys.lockAppAfter + titleRes = R.string.lock_when_idle + val values = arrayOf("0", "1", "2", "5", "10", "-1") + entries = values.mapNotNull { + when (it) { + "-1" -> context.getString(R.string.lock_never) + "0" -> context.getString(R.string.lock_always) + else -> resources?.getQuantityString(R.plurals.lock_after_mins, it.toInt(), it) + } + }.toTypedArray() + entryValues = values + defaultValue = "0" + summary = "%s" + + preferences.useBiometricLock().asObservable() + .subscribeUntilDestroy { isVisible = it } + } + } + + switchPreference { + key = Keys.secureScreen + titleRes = R.string.secure_screen + summaryRes = R.string.secure_screen_summary + defaultValue = false + } + switchPreference { + key = Keys.hideNotificationContent + titleRes = R.string.hide_notification_content + defaultValue = false + } + } +} diff --git a/app/src/main/res/drawable/ic_security_black_24dp.xml b/app/src/main/res/drawable/ic_security_black_24dp.xml new file mode 100644 index 000000000..c2aed7ed0 --- /dev/null +++ b/app/src/main/res/drawable/ic_security_black_24dp.xml @@ -0,0 +1,9 @@ + + +