mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-19 03:09:19 +01:00
Require authentication to toggle showing NSFW sources
This commit is contained in:
parent
ea34ba53b9
commit
f343131802
@ -1,5 +1,6 @@
|
|||||||
package eu.kanade.tachiyomi.ui.setting
|
package eu.kanade.tachiyomi.ui.setting
|
||||||
|
|
||||||
|
import androidx.fragment.app.FragmentActivity
|
||||||
import androidx.preference.PreferenceScreen
|
import androidx.preference.PreferenceScreen
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.extension.ExtensionUpdateJob
|
import eu.kanade.tachiyomi.extension.ExtensionUpdateJob
|
||||||
@ -7,6 +8,7 @@ import eu.kanade.tachiyomi.util.preference.defaultValue
|
|||||||
import eu.kanade.tachiyomi.util.preference.infoPreference
|
import eu.kanade.tachiyomi.util.preference.infoPreference
|
||||||
import eu.kanade.tachiyomi.util.preference.onChange
|
import eu.kanade.tachiyomi.util.preference.onChange
|
||||||
import eu.kanade.tachiyomi.util.preference.preferenceCategory
|
import eu.kanade.tachiyomi.util.preference.preferenceCategory
|
||||||
|
import eu.kanade.tachiyomi.util.preference.requireAuthentication
|
||||||
import eu.kanade.tachiyomi.util.preference.summaryRes
|
import eu.kanade.tachiyomi.util.preference.summaryRes
|
||||||
import eu.kanade.tachiyomi.util.preference.switchPreference
|
import eu.kanade.tachiyomi.util.preference.switchPreference
|
||||||
import eu.kanade.tachiyomi.util.preference.titleRes
|
import eu.kanade.tachiyomi.util.preference.titleRes
|
||||||
@ -51,6 +53,12 @@ class SettingsBrowseController : SettingsController() {
|
|||||||
titleRes = R.string.pref_show_nsfw_source
|
titleRes = R.string.pref_show_nsfw_source
|
||||||
summaryRes = R.string.requires_app_restart
|
summaryRes = R.string.requires_app_restart
|
||||||
defaultValue = true
|
defaultValue = true
|
||||||
|
|
||||||
|
requireAuthentication(
|
||||||
|
activity as? FragmentActivity,
|
||||||
|
activity!!.getString(R.string.pref_category_nsfw_content),
|
||||||
|
activity!!.getString(R.string.confirm_lock_change),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
infoPreference(R.string.parental_controls_info)
|
infoPreference(R.string.parental_controls_info)
|
||||||
|
@ -8,6 +8,7 @@ import eu.kanade.tachiyomi.R
|
|||||||
import eu.kanade.tachiyomi.data.preference.asImmediateFlow
|
import eu.kanade.tachiyomi.data.preference.asImmediateFlow
|
||||||
import eu.kanade.tachiyomi.util.preference.defaultValue
|
import eu.kanade.tachiyomi.util.preference.defaultValue
|
||||||
import eu.kanade.tachiyomi.util.preference.intListPreference
|
import eu.kanade.tachiyomi.util.preference.intListPreference
|
||||||
|
import eu.kanade.tachiyomi.util.preference.requireAuthentication
|
||||||
import eu.kanade.tachiyomi.util.preference.summaryRes
|
import eu.kanade.tachiyomi.util.preference.summaryRes
|
||||||
import eu.kanade.tachiyomi.util.preference.switchPreference
|
import eu.kanade.tachiyomi.util.preference.switchPreference
|
||||||
import eu.kanade.tachiyomi.util.preference.titleRes
|
import eu.kanade.tachiyomi.util.preference.titleRes
|
||||||
@ -28,32 +29,14 @@ class SettingsSecurityController : SettingsController() {
|
|||||||
key = Keys.useAuthenticator
|
key = Keys.useAuthenticator
|
||||||
titleRes = R.string.lock_with_biometrics
|
titleRes = R.string.lock_with_biometrics
|
||||||
defaultValue = false
|
defaultValue = false
|
||||||
onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue ->
|
|
||||||
(activity as? FragmentActivity)?.startAuthentication(
|
|
||||||
activity!!.getString(R.string.lock_with_biometrics),
|
|
||||||
activity!!.getString(R.string.confirm_lock_change),
|
|
||||||
callback = object : AuthenticatorUtil.AuthenticationCallback() {
|
|
||||||
override fun onAuthenticationSucceeded(
|
|
||||||
activity: FragmentActivity?,
|
|
||||||
result: BiometricPrompt.AuthenticationResult
|
|
||||||
) {
|
|
||||||
super.onAuthenticationSucceeded(activity, result)
|
|
||||||
isChecked = newValue as Boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onAuthenticationError(
|
requireAuthentication(
|
||||||
activity: FragmentActivity?,
|
activity as? FragmentActivity,
|
||||||
errorCode: Int,
|
activity!!.getString(R.string.lock_with_biometrics),
|
||||||
errString: CharSequence
|
activity!!.getString(R.string.confirm_lock_change),
|
||||||
) {
|
)
|
||||||
super.onAuthenticationError(activity, errorCode, errString)
|
|
||||||
activity?.toast(errString.toString())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
intListPreference {
|
intListPreference {
|
||||||
key = Keys.lockAppAfter
|
key = Keys.lockAppAfter
|
||||||
titleRes = R.string.lock_when_idle
|
titleRes = R.string.lock_when_idle
|
||||||
@ -107,6 +90,7 @@ class SettingsSecurityController : SettingsController() {
|
|||||||
summaryRes = R.string.secure_screen_summary
|
summaryRes = R.string.secure_screen_summary
|
||||||
defaultValue = false
|
defaultValue = false
|
||||||
}
|
}
|
||||||
|
|
||||||
switchPreference {
|
switchPreference {
|
||||||
key = Keys.hideNotificationContent
|
key = Keys.hideNotificationContent
|
||||||
titleRes = R.string.hide_notification_content
|
titleRes = R.string.hide_notification_content
|
||||||
|
@ -2,6 +2,8 @@ package eu.kanade.tachiyomi.util.preference
|
|||||||
|
|
||||||
import androidx.annotation.StringRes
|
import androidx.annotation.StringRes
|
||||||
import androidx.appcompat.content.res.AppCompatResources
|
import androidx.appcompat.content.res.AppCompatResources
|
||||||
|
import androidx.biometric.BiometricPrompt
|
||||||
|
import androidx.fragment.app.FragmentActivity
|
||||||
import androidx.preference.CheckBoxPreference
|
import androidx.preference.CheckBoxPreference
|
||||||
import androidx.preference.DialogPreference
|
import androidx.preference.DialogPreference
|
||||||
import androidx.preference.EditTextPreference
|
import androidx.preference.EditTextPreference
|
||||||
@ -14,7 +16,11 @@ import androidx.preference.PreferenceManager
|
|||||||
import androidx.preference.PreferenceScreen
|
import androidx.preference.PreferenceScreen
|
||||||
import androidx.preference.SwitchPreferenceCompat
|
import androidx.preference.SwitchPreferenceCompat
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
|
import eu.kanade.tachiyomi.util.system.AuthenticatorUtil
|
||||||
|
import eu.kanade.tachiyomi.util.system.AuthenticatorUtil.isAuthenticationSupported
|
||||||
|
import eu.kanade.tachiyomi.util.system.AuthenticatorUtil.startAuthentication
|
||||||
import eu.kanade.tachiyomi.util.system.getResourceColor
|
import eu.kanade.tachiyomi.util.system.getResourceColor
|
||||||
|
import eu.kanade.tachiyomi.util.system.toast
|
||||||
import eu.kanade.tachiyomi.widget.preference.AdaptiveTitlePreferenceCategory
|
import eu.kanade.tachiyomi.widget.preference.AdaptiveTitlePreferenceCategory
|
||||||
import eu.kanade.tachiyomi.widget.preference.IntListPreference
|
import eu.kanade.tachiyomi.widget.preference.IntListPreference
|
||||||
import eu.kanade.tachiyomi.widget.preference.SwitchPreferenceCategory
|
import eu.kanade.tachiyomi.widget.preference.SwitchPreferenceCategory
|
||||||
@ -125,6 +131,37 @@ inline fun Preference.onChange(crossinline block: (Any?) -> Boolean) {
|
|||||||
setOnPreferenceChangeListener { _, newValue -> block(newValue) }
|
setOnPreferenceChangeListener { _, newValue -> block(newValue) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline fun SwitchPreferenceCompat.requireAuthentication(activity: FragmentActivity?, title: String, subtitle: String?) {
|
||||||
|
onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue ->
|
||||||
|
if (context.isAuthenticationSupported()) {
|
||||||
|
activity?.startAuthentication(
|
||||||
|
title,
|
||||||
|
subtitle,
|
||||||
|
callback = object : AuthenticatorUtil.AuthenticationCallback() {
|
||||||
|
override fun onAuthenticationSucceeded(
|
||||||
|
activity: FragmentActivity?,
|
||||||
|
result: BiometricPrompt.AuthenticationResult
|
||||||
|
) {
|
||||||
|
super.onAuthenticationSucceeded(activity, result)
|
||||||
|
isChecked = newValue as Boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onAuthenticationError(
|
||||||
|
activity: FragmentActivity?,
|
||||||
|
errorCode: Int,
|
||||||
|
errString: CharSequence
|
||||||
|
) {
|
||||||
|
super.onAuthenticationError(activity, errorCode, errString)
|
||||||
|
activity?.toast(errString.toString())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var Preference.defaultValue: Any?
|
var Preference.defaultValue: Any?
|
||||||
get() = null // set only
|
get() = null // set only
|
||||||
set(value) {
|
set(value) {
|
||||||
|
Loading…
Reference in New Issue
Block a user