2022-10-15 17:38:01 +02:00
|
|
|
package eu.kanade.presentation.more.settings.screen
|
|
|
|
|
|
|
|
import androidx.compose.runtime.Composable
|
|
|
|
import androidx.compose.runtime.ReadOnlyComposable
|
|
|
|
import androidx.compose.runtime.getValue
|
|
|
|
import androidx.compose.runtime.remember
|
|
|
|
import androidx.compose.ui.platform.LocalContext
|
|
|
|
import androidx.fragment.app.FragmentActivity
|
|
|
|
import eu.kanade.presentation.more.settings.Preference
|
|
|
|
import eu.kanade.tachiyomi.core.security.SecurityPreferences
|
|
|
|
import eu.kanade.tachiyomi.util.system.AuthenticatorUtil.authenticate
|
|
|
|
import eu.kanade.tachiyomi.util.system.AuthenticatorUtil.isAuthenticationSupported
|
2023-11-18 19:54:56 +01:00
|
|
|
import tachiyomi.core.i18n.localize
|
|
|
|
import tachiyomi.i18n.MR
|
|
|
|
import tachiyomi.presentation.core.i18n.localize
|
|
|
|
import tachiyomi.presentation.core.i18n.localizePlural
|
2023-07-20 03:57:22 +02:00
|
|
|
import tachiyomi.presentation.core.util.collectAsState
|
2022-10-15 17:38:01 +02:00
|
|
|
import uy.kohesive.injekt.Injekt
|
|
|
|
import uy.kohesive.injekt.api.get
|
|
|
|
|
2022-11-23 15:14:55 +01:00
|
|
|
object SettingsSecurityScreen : SearchableSettings {
|
2022-10-15 17:38:01 +02:00
|
|
|
|
|
|
|
@ReadOnlyComposable
|
|
|
|
@Composable
|
2023-11-18 19:54:56 +01:00
|
|
|
override fun getTitleRes() = MR.strings.pref_category_security
|
2022-10-15 17:38:01 +02:00
|
|
|
|
|
|
|
@Composable
|
|
|
|
override fun getPreferences(): List<Preference> {
|
|
|
|
val context = LocalContext.current
|
|
|
|
val securityPreferences = remember { Injekt.get<SecurityPreferences>() }
|
|
|
|
val authSupported = remember { context.isAuthenticationSupported() }
|
|
|
|
|
|
|
|
val useAuthPref = securityPreferences.useAuthenticator()
|
|
|
|
val useAuth by useAuthPref.collectAsState()
|
|
|
|
|
|
|
|
return listOf(
|
|
|
|
Preference.PreferenceItem.SwitchPreference(
|
|
|
|
pref = useAuthPref,
|
2023-11-18 19:54:56 +01:00
|
|
|
title = localize(MR.strings.lock_with_biometrics),
|
2022-10-15 17:38:01 +02:00
|
|
|
enabled = authSupported,
|
|
|
|
onValueChanged = {
|
|
|
|
(context as FragmentActivity).authenticate(
|
2023-11-18 19:54:56 +01:00
|
|
|
title = context.localize(MR.strings.lock_with_biometrics),
|
2022-10-15 17:38:01 +02:00
|
|
|
)
|
|
|
|
},
|
|
|
|
),
|
|
|
|
Preference.PreferenceItem.ListPreference(
|
|
|
|
pref = securityPreferences.lockAppAfter(),
|
2023-11-18 19:54:56 +01:00
|
|
|
title = localize(MR.strings.lock_when_idle),
|
2022-10-15 17:38:01 +02:00
|
|
|
enabled = authSupported && useAuth,
|
|
|
|
entries = LockAfterValues
|
|
|
|
.associateWith {
|
|
|
|
when (it) {
|
2023-11-18 19:54:56 +01:00
|
|
|
-1 -> localize(MR.strings.lock_never)
|
|
|
|
0 -> localize(MR.strings.lock_always)
|
|
|
|
else -> localizePlural(MR.plurals.lock_after_mins, count = it, it)
|
2022-10-15 17:38:01 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
onValueChanged = {
|
|
|
|
(context as FragmentActivity).authenticate(
|
2023-11-18 19:54:56 +01:00
|
|
|
title = context.localize(MR.strings.lock_when_idle),
|
2022-10-15 17:38:01 +02:00
|
|
|
)
|
|
|
|
},
|
|
|
|
),
|
|
|
|
Preference.PreferenceItem.SwitchPreference(
|
|
|
|
pref = securityPreferences.hideNotificationContent(),
|
2023-11-18 19:54:56 +01:00
|
|
|
title = localize(MR.strings.hide_notification_content),
|
2022-10-15 17:38:01 +02:00
|
|
|
),
|
|
|
|
Preference.PreferenceItem.ListPreference(
|
|
|
|
pref = securityPreferences.secureScreen(),
|
2023-11-18 19:54:56 +01:00
|
|
|
title = localize(MR.strings.secure_screen),
|
2023-07-19 01:12:04 +02:00
|
|
|
entries = SecurityPreferences.SecureScreenMode.entries
|
2023-11-18 19:54:56 +01:00
|
|
|
.associateWith { localize(it.titleRes) },
|
2022-10-15 17:38:01 +02:00
|
|
|
),
|
2023-11-18 19:54:56 +01:00
|
|
|
Preference.PreferenceItem.InfoPreference(localize(MR.strings.secure_screen_summary)),
|
2022-10-15 17:38:01 +02:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private val LockAfterValues = listOf(
|
|
|
|
0, // Always
|
|
|
|
1,
|
|
|
|
2,
|
|
|
|
5,
|
|
|
|
10,
|
|
|
|
-1, // Never
|
|
|
|
)
|