mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 02:34:39 +00:00
refactor: Split security preferences from PreferencesHelper
This commit is contained in:
parent
48d542f5a6
commit
b43fccacd7
7 changed files with 26 additions and 15 deletions
|
@ -31,20 +31,19 @@ import eu.kanade.tachiyomi.appwidget.components.LockedWidget
|
|||
import eu.kanade.tachiyomi.appwidget.components.UpdatesWidget
|
||||
import eu.kanade.tachiyomi.appwidget.util.appWidgetBackgroundRadius
|
||||
import eu.kanade.tachiyomi.appwidget.util.calculateRowAndColumnCount
|
||||
import eu.kanade.tachiyomi.core.security.SecurityPreferences
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.ui.recents.RecentsPresenter
|
||||
import eu.kanade.tachiyomi.util.system.dpToPx
|
||||
import eu.kanade.tachiyomi.util.system.launchIO
|
||||
import kotlinx.coroutines.MainScope
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import java.util.Calendar
|
||||
import java.util.Date
|
||||
import java.util.*
|
||||
import kotlin.math.min
|
||||
|
||||
class UpdatesGridGlanceWidget : GlanceAppWidget() {
|
||||
private val app: Application by injectLazy()
|
||||
private val preferences: PreferencesHelper by injectLazy()
|
||||
private val preferences: SecurityPreferences by injectLazy()
|
||||
|
||||
private val coroutineScope = MainScope()
|
||||
|
||||
|
|
|
@ -169,8 +169,6 @@ object PreferenceKeys {
|
|||
|
||||
const val languageBadge = "display_language_badge"
|
||||
|
||||
const val useBiometrics = "use_biometrics"
|
||||
|
||||
const val lockAfter = "lock_after"
|
||||
|
||||
const val lastUnlock = "last_unlock"
|
||||
|
|
|
@ -294,8 +294,6 @@ class PreferencesHelper(val context: Context, val preferenceStore: PreferenceSto
|
|||
|
||||
fun skipDupe() = preferenceStore.getBoolean("skip_dupe", false)
|
||||
|
||||
fun useBiometrics() = preferenceStore.getBoolean(Keys.useBiometrics, false)
|
||||
|
||||
fun lockAfter() = preferenceStore.getInt(Keys.lockAfter, 0)
|
||||
|
||||
fun lastUnlock() = preferenceStore.getLong(Keys.lastUnlock, 0)
|
||||
|
|
|
@ -6,16 +6,18 @@ import android.os.Build
|
|||
import android.view.Window
|
||||
import android.view.WindowManager
|
||||
import androidx.biometric.BiometricManager
|
||||
import eu.kanade.tachiyomi.core.security.SecurityPreferences
|
||||
import eu.kanade.tachiyomi.data.preference.PreferenceValues
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.ui.main.SearchActivity
|
||||
import eu.kanade.tachiyomi.util.system.AuthenticatorUtil
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import java.util.Date
|
||||
import java.util.*
|
||||
|
||||
object SecureActivityDelegate {
|
||||
|
||||
private val preferences by injectLazy<PreferencesHelper>()
|
||||
private val preferences: PreferencesHelper by injectLazy()
|
||||
private val securityPreferences: SecurityPreferences by injectLazy()
|
||||
|
||||
var locked: Boolean = true
|
||||
|
||||
|
@ -40,7 +42,7 @@ object SecureActivityDelegate {
|
|||
@Suppress("DEPRECATION")
|
||||
fun promptLockIfNeeded(activity: Activity?, requireSuccess: Boolean = false) {
|
||||
if (activity == null || AuthenticatorUtil.isAuthenticating) return
|
||||
val lockApp = preferences.useBiometrics().get()
|
||||
val lockApp = securityPreferences.useBiometrics().get()
|
||||
if (lockApp && BiometricManager.from(activity).canAuthenticate(BiometricManager.Authenticators.DEVICE_CREDENTIAL or BiometricManager.Authenticators.BIOMETRIC_WEAK) == BiometricManager.BIOMETRIC_SUCCESS) {
|
||||
if (isAppLocked()) {
|
||||
val intent = Intent(activity, BiometricActivity::class.java)
|
||||
|
@ -53,12 +55,12 @@ object SecureActivityDelegate {
|
|||
}
|
||||
}
|
||||
} else if (lockApp) {
|
||||
preferences.useBiometrics().set(false)
|
||||
securityPreferences.useBiometrics().set(false)
|
||||
}
|
||||
}
|
||||
|
||||
fun shouldBeLocked(): Boolean {
|
||||
val lockApp = preferences.useBiometrics().get()
|
||||
val lockApp = securityPreferences.useBiometrics().get()
|
||||
if (lockApp && isAppLocked()) return true
|
||||
return false
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.ui.setting.controllers
|
|||
import androidx.fragment.app.FragmentActivity
|
||||
import androidx.preference.PreferenceScreen
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.core.security.SecurityPreferences
|
||||
import eu.kanade.tachiyomi.data.preference.PreferenceKeys
|
||||
import eu.kanade.tachiyomi.data.preference.PreferenceValues
|
||||
import eu.kanade.tachiyomi.data.preference.changesIn
|
||||
|
@ -18,14 +19,17 @@ import eu.kanade.tachiyomi.ui.setting.requireAuthentication
|
|||
import eu.kanade.tachiyomi.ui.setting.switchPreference
|
||||
import eu.kanade.tachiyomi.ui.setting.titleRes
|
||||
import eu.kanade.tachiyomi.util.system.AuthenticatorUtil.isAuthenticationSupported
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
|
||||
class SettingsSecurityController : SettingsLegacyController() {
|
||||
private val securityPreferences: SecurityPreferences by injectLazy()
|
||||
|
||||
override fun setupPreferenceScreen(screen: PreferenceScreen) = screen.apply {
|
||||
titleRes = R.string.security
|
||||
|
||||
if (context.isAuthenticationSupported()) {
|
||||
switchPreference {
|
||||
key = PreferenceKeys.useBiometrics
|
||||
bindTo(securityPreferences.useBiometrics())
|
||||
titleRes = R.string.lock_with_biometrics
|
||||
defaultValue = false
|
||||
|
||||
|
@ -53,7 +57,7 @@ class SettingsSecurityController : SettingsLegacyController() {
|
|||
entryValues = values
|
||||
defaultValue = 0
|
||||
|
||||
preferences.useBiometrics().changesIn(viewScope) { isVisible = it }
|
||||
securityPreferences.useBiometrics().changesIn(viewScope) { isVisible = it }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ package yokai.core.di
|
|||
import android.app.Application
|
||||
import eu.kanade.tachiyomi.core.preference.AndroidPreferenceStore
|
||||
import eu.kanade.tachiyomi.core.preference.PreferenceStore
|
||||
import eu.kanade.tachiyomi.core.security.SecurityPreferences
|
||||
import eu.kanade.tachiyomi.core.storage.AndroidStorageFolderProvider
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.data.track.TrackPreferences
|
||||
|
@ -39,6 +40,8 @@ class PreferenceModule(val application: Application) : InjektModule {
|
|||
|
||||
addSingletonFactory { NetworkPreferences(get()) }
|
||||
|
||||
addSingletonFactory { SecurityPreferences(get()) }
|
||||
|
||||
addSingletonFactory {
|
||||
PreferencesHelper(
|
||||
context = application,
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
package eu.kanade.tachiyomi.core.security
|
||||
|
||||
import eu.kanade.tachiyomi.core.preference.PreferenceStore
|
||||
|
||||
class SecurityPreferences(private val preferenceStore: PreferenceStore) {
|
||||
fun useBiometrics() = preferenceStore.getBoolean("use_biometrics", false)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue