Refactor out lockObserver
This commit is contained in:
1 parent
f84b10f2eb
commit
19295e1d30
3 files changed
+22
-25
No files matched your search
@@ -20,8 +20,6 @@ import android.app.Application
|
||||
import android.content.ComponentCallbacks2
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
import androidx.collection.LruCache
|
||||
import androidx.lifecycle.DefaultLifecycleObserver
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import androidx.lifecycle.ProcessLifecycleOwner
|
||||
import coil.ImageLoaderFactory
|
||||
import coil.decode.ImageDecoderDecoder
|
||||
@@ -42,6 +40,7 @@ import com.hippo.ehviewer.legacy.cleanObsoleteCache
|
||||
import com.hippo.ehviewer.okhttp.cache
|
||||
import com.hippo.ehviewer.okhttp.httpClient
|
||||
import com.hippo.ehviewer.ui.keepNoMediaFileStatus
|
||||
import com.hippo.ehviewer.ui.lockObserver
|
||||
import com.hippo.ehviewer.util.ReadableTime
|
||||
import com.hippo.ehviewer.yorozuya.FileUtils
|
||||
import eu.kanade.tachiyomi.core.preference.AndroidPreferenceStore
|
||||
@@ -53,10 +52,10 @@ import splitties.arch.room.roomDb
|
||||
import splitties.init.appCtx
|
||||
import java.net.Proxy
|
||||
|
||||
class EhApplication : Application(), DefaultLifecycleObserver, ImageLoaderFactory {
|
||||
class EhApplication : Application(), ImageLoaderFactory {
|
||||
@OptIn(DelicateCoroutinesApi::class)
|
||||
override fun onCreate() {
|
||||
ProcessLifecycleOwner.get().lifecycle.addObserver(this)
|
||||
ProcessLifecycleOwner.get().lifecycle.addObserver(lockObserver)
|
||||
val handler = Thread.getDefaultUncaughtExceptionHandler()
|
||||
Thread.setDefaultUncaughtExceptionHandler { t, e ->
|
||||
try {
|
||||
@@ -67,7 +66,7 @@ class EhApplication : Application(), DefaultLifecycleObserver, ImageLoaderFactor
|
||||
}
|
||||
handler?.uncaughtException(t, e)
|
||||
}
|
||||
super<Application>.onCreate()
|
||||
super.onCreate()
|
||||
System.loadLibrary("ehviewer")
|
||||
Settings.initialize()
|
||||
ReadableTime.initialize(this)
|
||||
@@ -126,13 +125,6 @@ class EhApplication : Application(), DefaultLifecycleObserver, ImageLoaderFactor
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPause(owner: LifecycleOwner) {
|
||||
if (!locked) {
|
||||
locked_last_leave_time = System.currentTimeMillis() / 1000
|
||||
}
|
||||
locked = true
|
||||
}
|
||||
|
||||
override fun newImageLoader() = imageLoader {
|
||||
okHttpClient(nonCacheOkHttpClient)
|
||||
components {
|
||||
@@ -146,9 +138,6 @@ class EhApplication : Application(), DefaultLifecycleObserver, ImageLoaderFactor
|
||||
}
|
||||
|
||||
companion object {
|
||||
var locked = true
|
||||
var locked_last_leave_time: Long = 0
|
||||
|
||||
val ehProxySelector by lazy { EhProxySelector() }
|
||||
|
||||
val nonCacheOkHttpClient by lazy {
|
||||
|
||||
@@ -20,7 +20,6 @@ import android.content.res.Resources.Theme
|
||||
import android.os.Bundle
|
||||
import androidx.annotation.StyleRes
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.hippo.ehviewer.EhApplication
|
||||
import com.hippo.ehviewer.R
|
||||
import com.hippo.ehviewer.Settings
|
||||
import eu.kanade.tachiyomi.util.system.isNightMode
|
||||
@@ -44,17 +43,16 @@ abstract class EhActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
layoutInflater.factory2 =
|
||||
LayoutInflaterFactory(delegate).addOnViewCreatedListener(WindowInsetsHelper.LISTENER)
|
||||
layoutInflater.factory2 = LayoutInflaterFactory(delegate).addOnViewCreatedListener(WindowInsetsHelper.LISTENER)
|
||||
super.onCreate(savedInstanceState)
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
val lockedResumeTime = System.currentTimeMillis() / 1000
|
||||
val lockedDelayTime = lockedResumeTime - EhApplication.locked_last_leave_time
|
||||
val lockedDelayTime = lockedResumeTime - locked_last_leave_time
|
||||
if (lockedDelayTime < Settings.securityDelay * 60) {
|
||||
EhApplication.locked = false
|
||||
} else if (Settings.security && isAuthenticationSupported() && EhApplication.locked) {
|
||||
locked = false
|
||||
} else if (Settings.security && isAuthenticationSupported() && locked) {
|
||||
startActivity(Intent(this, SecurityActivity::class.java))
|
||||
}
|
||||
super.onResume()
|
||||
|
||||
@@ -27,7 +27,8 @@ import androidx.biometric.auth.AuthPromptCallback
|
||||
import androidx.biometric.auth.startClass2BiometricOrCredentialAuthentication
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.fragment.app.FragmentActivity
|
||||
import com.hippo.ehviewer.EhApplication
|
||||
import androidx.lifecycle.DefaultLifecycleObserver
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import com.hippo.ehviewer.R
|
||||
|
||||
fun Context.isAuthenticationSupported(): Boolean {
|
||||
@@ -97,7 +98,7 @@ class SecurityActivity : AppCompatActivity() {
|
||||
|
||||
private fun onSuccess() {
|
||||
isAuthenticating = false
|
||||
EhApplication.locked = false
|
||||
locked = false
|
||||
finish()
|
||||
}
|
||||
|
||||
@@ -105,8 +106,17 @@ class SecurityActivity : AppCompatActivity() {
|
||||
moveTaskToBack(true)
|
||||
isAuthenticating = false
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private var isAuthenticating = false
|
||||
private var isAuthenticating = false
|
||||
var locked = true
|
||||
var locked_last_leave_time: Long = 0
|
||||
|
||||
val lockObserver = object : DefaultLifecycleObserver {
|
||||
override fun onPause(owner: LifecycleOwner) {
|
||||
if (!locked) {
|
||||
locked_last_leave_time = System.currentTimeMillis() / 1000
|
||||
}
|
||||
locked = true
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user