Updated on 2026-08-14
This commit is contained in:
parent
a10b94fa45
commit
03b555e463
2 changed files with 19 additions and 37 deletions
|
|
@ -2,7 +2,6 @@ package com.tangem.tap
|
|||
|
||||
import androidx.lifecycle.DefaultLifecycleObserver
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.tangem.common.routing.AppRoute
|
||||
import com.tangem.domain.settings.repositories.SettingsRepository
|
||||
import com.tangem.domain.wallets.legacy.UserWalletsListManager
|
||||
|
|
@ -17,6 +16,7 @@ internal class LockUserWalletsTimer(
|
|||
private val settingsRepository: SettingsRepository,
|
||||
private val duration: Duration = with(Duration) { 10.minutes },
|
||||
private val userWalletsListManager: UserWalletsListManager,
|
||||
private val coroutineScope: CoroutineScope,
|
||||
) : LifecycleOwner by owner,
|
||||
DefaultLifecycleObserver {
|
||||
|
||||
|
|
@ -31,7 +31,7 @@ internal class LockUserWalletsTimer(
|
|||
}
|
||||
|
||||
override fun onStart(owner: LifecycleOwner) {
|
||||
owner.lifecycleScope.launch {
|
||||
coroutineScope.launch {
|
||||
val wasApplicationStopped = settingsRepository.wasApplicationStopped()
|
||||
val shouldOpenWelcomeScreenOnResume = settingsRepository.shouldOpenWelcomeScreenOnResume()
|
||||
|
||||
|
|
@ -59,16 +59,11 @@ internal class LockUserWalletsTimer(
|
|||
override fun onStop(owner: LifecycleOwner) {
|
||||
Timber.i("Owner stopped")
|
||||
|
||||
owner.lifecycleScope.launch {
|
||||
coroutineScope.launch {
|
||||
settingsRepository.setWasApplicationStopped(value = true)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroy(owner: LifecycleOwner) {
|
||||
Timber.i("Owner destroyed")
|
||||
stop()
|
||||
}
|
||||
|
||||
fun restart() {
|
||||
if (delayJob == null) return
|
||||
Timber.i(
|
||||
|
|
@ -92,44 +87,30 @@ internal class LockUserWalletsTimer(
|
|||
delayJob = createDelayJob()
|
||||
}
|
||||
|
||||
private fun stop(log: Boolean = true) {
|
||||
if (log) {
|
||||
Timber.i(
|
||||
"""
|
||||
Timer stop
|
||||
|- Was started: ${delayJob?.isActive ?: false}
|
||||
""".trimIndent(),
|
||||
)
|
||||
}
|
||||
delayJob = null
|
||||
}
|
||||
|
||||
private fun createDelayJob(): Job = lifecycleScope.launch(Dispatchers.Default) {
|
||||
private fun createDelayJob(): Job = coroutineScope.launch {
|
||||
val startTime = System.currentTimeMillis()
|
||||
|
||||
delay(duration)
|
||||
|
||||
if (isActive) {
|
||||
val userWalletsListManager = userWalletsListManager.asLockable() ?: return@launch
|
||||
val userWalletsListManager = userWalletsListManager.asLockable() ?: return@launch
|
||||
|
||||
if (userWalletsListManager.hasUserWallets) {
|
||||
val currentTime = System.currentTimeMillis()
|
||||
val wasApplicationStopped = settingsRepository.wasApplicationStopped()
|
||||
if (userWalletsListManager.hasUserWallets) {
|
||||
val currentTime = System.currentTimeMillis()
|
||||
val wasApplicationStopped = settingsRepository.wasApplicationStopped()
|
||||
|
||||
Timber.i(
|
||||
"""
|
||||
Timber.i(
|
||||
"""
|
||||
Finished
|
||||
|- App is stopped: $wasApplicationStopped
|
||||
|- Millis passed: ${currentTime - startTime}
|
||||
""".trimIndent(),
|
||||
)
|
||||
""".trimIndent(),
|
||||
)
|
||||
|
||||
userWalletsListManager.lock()
|
||||
if (wasApplicationStopped) {
|
||||
settingsRepository.setShouldOpenWelcomeScreenOnResume(value = true)
|
||||
} else {
|
||||
store.dispatchNavigationAction { replaceAll(AppRoute.Welcome()) }
|
||||
}
|
||||
userWalletsListManager.lock()
|
||||
if (wasApplicationStopped) {
|
||||
settingsRepository.setShouldOpenWelcomeScreenOnResume(value = true)
|
||||
} else {
|
||||
store.dispatchNavigationAction { replaceAll(AppRoute.Welcome()) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -327,7 +327,7 @@ class MainActivity : AppCompatActivity(), SnackbarHandler, ActivityResultCallbac
|
|||
context = rootComponentContext,
|
||||
)
|
||||
|
||||
appRouterConfig.routerScope = lifecycleScope
|
||||
appRouterConfig.routerScope = mainScope
|
||||
appRouterConfig.componentRouter = routingComponent.router
|
||||
appRouterConfig.snackbarHandler = this
|
||||
|
||||
|
|
@ -368,6 +368,7 @@ class MainActivity : AppCompatActivity(), SnackbarHandler, ActivityResultCallbac
|
|||
owner = this,
|
||||
settingsRepository = settingsRepository,
|
||||
userWalletsListManager = userWalletsListManager,
|
||||
coroutineScope = mainScope,
|
||||
)
|
||||
|
||||
initIntentHandlers()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue