From 8ea05e852efd621ee987c7e45d6db64a083eeffd Mon Sep 17 00:00:00 2001 From: AntsyLich <59261191+AntsyLich@users.noreply.github.com> Date: Fri, 22 Jul 2022 08:23:59 +0600 Subject: [PATCH] Fix logic of app unlock (#7569) --- app/src/main/java/eu/kanade/tachiyomi/App.kt | 2 ++ .../eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt | 2 +- .../kanade/tachiyomi/ui/base/delegate/SecureActivityDelegate.kt | 2 +- .../main/java/eu/kanade/tachiyomi/ui/security/UnlockActivity.kt | 2 -- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/App.kt b/app/src/main/java/eu/kanade/tachiyomi/App.kt index bd62bc98dd..4715471407 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/App.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/App.kt @@ -55,6 +55,7 @@ import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get import uy.kohesive.injekt.injectLazy import java.security.Security +import java.util.Date class App : Application(), DefaultLifecycleObserver, ImageLoaderFactory { @@ -156,6 +157,7 @@ class App : Application(), DefaultLifecycleObserver, ImageLoaderFactory { } override fun onStop(owner: LifecycleOwner) { + preferences.lastAppClosed().set(Date().time) if (!AuthenticatorUtil.isAuthenticating && preferences.lockAppAfter().get() >= 0) { SecureActivityDelegate.locked = true } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt index 7f958c97cd..09343e2eaf 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt @@ -53,7 +53,7 @@ class PreferencesHelper(val context: Context) { fun lockAppAfter() = flowPrefs.getInt("lock_app_after", 0) - fun lastAppUnlock() = flowPrefs.getLong("last_app_unlock", 0) + fun lastAppClosed() = flowPrefs.getLong("last_app_closed", 0) fun secureScreen() = flowPrefs.getEnum("secure_screen_v2", Values.SecureScreenMode.INCOGNITO) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/delegate/SecureActivityDelegate.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/delegate/SecureActivityDelegate.kt index 2c8be25042..1518913445 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/delegate/SecureActivityDelegate.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/delegate/SecureActivityDelegate.kt @@ -68,6 +68,6 @@ class SecureActivityDelegateImpl : SecureActivityDelegate, DefaultLifecycleObser private fun isAppLocked(): Boolean { if (!SecureActivityDelegate.locked) return false return preferences.lockAppAfter().get() <= 0 || - Date().time >= preferences.lastAppUnlock().get() + 60 * 1000 * preferences.lockAppAfter().get() + Date().time >= preferences.lastAppClosed().get() + 60 * 1000 * preferences.lockAppAfter().get() } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/security/UnlockActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/security/UnlockActivity.kt index a066bf64dd..e33760af1c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/security/UnlockActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/security/UnlockActivity.kt @@ -10,7 +10,6 @@ import eu.kanade.tachiyomi.util.system.AuthenticatorUtil import eu.kanade.tachiyomi.util.system.AuthenticatorUtil.startAuthentication import eu.kanade.tachiyomi.util.system.logcat import logcat.LogPriority -import java.util.Date /** * Blank activity with a BiometricPrompt. @@ -39,7 +38,6 @@ class UnlockActivity : BaseActivity() { ) { super.onAuthenticationSucceeded(activity, result) SecureActivityDelegate.locked = false - preferences.lastAppUnlock().set(Date().time) finish() } },