Skip to content

Commit 44260e0

Browse files
committed
refactor: Nullify inactivityJob always
1 parent 1923664 commit 44260e0

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

app/src/main/java/to/bitkit/ui/components/InactivityTracker.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ fun InactivityTracker(
4545
if (isPinEnabled && isPinOnIdleEnabled && isAuthenticated) {
4646
inactivityJob = scope.launch {
4747
delay(INACTIVITY_DELAY)
48-
Logger.debug("Inactivity timeout reached after ${INACTIVITY_DELAY/1000}s, isAuthenticated=false.")
48+
Logger.debug("Inactivity timeout reached after ${INACTIVITY_DELAY / 1000}s, resetting isAuthenticated.")
4949
app.setIsAuthenticated(false)
5050
resetInactivityTimeout()
5151
}
@@ -66,14 +66,16 @@ fun InactivityTracker(
6666
val observer = LifecycleEventObserver { _, event ->
6767
when (event) {
6868
Lifecycle.Event.ON_RESUME -> resetInactivityTimeout()
69-
Lifecycle.Event.ON_PAUSE -> inactivityJob?.cancel()
69+
Lifecycle.Event.ON_PAUSE -> inactivityJob?.cancel()?.also { inactivityJob = null }
7070
else -> Unit
7171
}
7272
}
7373
lifecycleOwner.lifecycle.addObserver(observer)
7474
onDispose {
7575
lifecycleOwner.lifecycle.removeObserver(observer)
76-
inactivityJob?.cancel()
76+
inactivityJob?.cancel()?.also {
77+
inactivityJob = null
78+
}
7779
}
7880
}
7981

0 commit comments

Comments
 (0)