From 85f2996ae9bbbfac18fb6a836d9334574812f8c9 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) (cherry picked from commit 8ea05e852efd621ee987c7e45d6db64a083eeffd) --- 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 32a290be7..c14a687a5 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/App.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/App.kt @@ -52,6 +52,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 open class App : Application(), DefaultLifecycleObserver, ImageLoaderFactory { @@ -148,6 +149,7 @@ open 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 92de28c6e..96b0989b2 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 @@ -56,7 +56,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 2c8be2504..151891344 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 a066bf64d..e33760af1 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() } },