2022-10-15 17:38:01 +02:00
|
|
|
package eu.kanade.presentation.more.settings.screen
|
|
|
|
|
2022-10-15 17:58:24 +02:00
|
|
|
import androidx.annotation.StringRes
|
2022-10-15 17:38:01 +02:00
|
|
|
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.compose.ui.res.pluralStringResource
|
|
|
|
import androidx.compose.ui.res.stringResource
|
|
|
|
import androidx.fragment.app.FragmentActivity
|
|
|
|
import eu.kanade.presentation.more.settings.Preference
|
|
|
|
import eu.kanade.presentation.util.collectAsState
|
|
|
|
import eu.kanade.tachiyomi.R
|
|
|
|
import eu.kanade.tachiyomi.core.security.SecurityPreferences
|
|
|
|
import eu.kanade.tachiyomi.util.system.AuthenticatorUtil.authenticate
|
|
|
|
import eu.kanade.tachiyomi.util.system.AuthenticatorUtil.isAuthenticationSupported
|
|
|
|
import uy.kohesive.injekt.Injekt
|
|
|
|
import uy.kohesive.injekt.api.get
|
|
|
|
|
|
|
|
class SettingsSecurityScreen : SearchableSettings {
|
|
|
|
|
|
|
|
@ReadOnlyComposable
|
|
|
|
@Composable
|
2022-10-15 17:58:24 +02:00
|
|
|
@StringRes
|
|
|
|
override fun getTitleRes() = R.string.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,
|
2022-10-15 17:58:24 +02:00
|
|
|
title = stringResource(R.string.lock_with_biometrics),
|
2022-10-15 17:38:01 +02:00
|
|
|
enabled = authSupported,
|
|
|
|
onValueChanged = {
|
|
|
|
(context as FragmentActivity).authenticate(
|
|
|
|
title = context.getString(R.string.lock_with_biometrics),
|
|
|
|
)
|
|
|
|
},
|
|
|
|
),
|
|
|
|
Preference.PreferenceItem.ListPreference(
|
|
|
|
pref = securityPreferences.lockAppAfter(),
|
2022-10-15 17:58:24 +02:00
|
|
|
title = stringResource(R.string.lock_when_idle),
|
2022-10-15 17:38:01 +02:00
|
|
|
enabled = authSupported && useAuth,
|
|
|
|
entries = LockAfterValues
|
|
|
|
.associateWith {
|
|
|
|
when (it) {
|
2022-10-15 17:58:24 +02:00
|
|
|
-1 -> stringResource(R.string.lock_never)
|
|
|
|
0 -> stringResource(R.string.lock_always)
|
2022-10-15 17:38:01 +02:00
|
|
|
else -> pluralStringResource(id = R.plurals.lock_after_mins, count = it, it)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onValueChanged = {
|
|
|
|
(context as FragmentActivity).authenticate(
|
|
|
|
title = context.getString(R.string.lock_when_idle),
|
|
|
|
)
|
|
|
|
},
|
|
|
|
),
|
|
|
|
Preference.PreferenceItem.SwitchPreference(
|
|
|
|
pref = securityPreferences.hideNotificationContent(),
|
2022-10-15 17:58:24 +02:00
|
|
|
title = stringResource(R.string.hide_notification_content),
|
2022-10-15 17:38:01 +02:00
|
|
|
),
|
|
|
|
Preference.PreferenceItem.ListPreference(
|
|
|
|
pref = securityPreferences.secureScreen(),
|
2022-10-15 17:58:24 +02:00
|
|
|
title = stringResource(R.string.secure_screen),
|
2022-10-15 17:38:01 +02:00
|
|
|
entries = SecurityPreferences.SecureScreenMode.values()
|
2022-10-15 17:58:24 +02:00
|
|
|
.associateWith { stringResource(it.titleResId) },
|
2022-10-15 17:38:01 +02:00
|
|
|
),
|
2022-10-16 21:32:48 +02:00
|
|
|
Preference.PreferenceItem.InfoPreference(stringResource(R.string.secure_screen_summary)),
|
2022-10-15 17:38:01 +02:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private val LockAfterValues = listOf(
|
|
|
|
0, // Always
|
|
|
|
1,
|
|
|
|
2,
|
|
|
|
5,
|
|
|
|
10,
|
|
|
|
-1, // Never
|
|
|
|
)
|