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>
This commit is contained in:
Jays2Kings 2021-04-10 16:26:59 -04:00
parent 65548c95a2
commit 5ea0dda75e
5 changed files with 82 additions and 57 deletions

View File

@ -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 = ""

View File

@ -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

View File

@ -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
}
}
}
}

View File

@ -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

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FF000000"
android:pathData="M12,1L3,5v6c0,5.55 3.84,10.74 9,12 5.16,-1.26 9,-6.45 9,-12L21,5l-9,-4zM12,11.99h7c-0.53,4.12 -3.28,7.79 -7,8.94L12,12L5,12L5,6.3l7,-3.11v8.8z"/>
</vector>