Skip to content

Commit 5bb2a76

Browse files
committed
Make inForeground read only; add kdoc
1 parent db69c07 commit 5bb2a76

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

app/src/main/kotlin/at/bitfire/davdroid/ui/AppTheme.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ fun AppTheme(
5050

5151
// Track if the app is in the foreground
5252
LifecycleResumeEffect(view) {
53-
ForegroundTracker.inForeground.value = true
53+
ForegroundTracker.onResume()
5454
onPauseOrDispose {
55-
ForegroundTracker.inForeground.value = false
55+
ForegroundTracker.onPaused()
5656
}
5757
}
5858
}

app/src/main/kotlin/at/bitfire/davdroid/ui/ForegroundTracker.kt

+22-1
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,31 @@
55
package at.bitfire.davdroid.ui
66

77
import kotlinx.coroutines.flow.MutableStateFlow
8+
import kotlinx.coroutines.flow.asStateFlow
89

910
/**
1011
* Used to track whether the app is in foreground (visible to user) or not.
1112
*/
1213
object ForegroundTracker {
13-
val inForeground: MutableStateFlow<Boolean> = MutableStateFlow(false)
14+
15+
private val _inForeground: MutableStateFlow<Boolean> = MutableStateFlow(false)
16+
17+
/**
18+
* Whether the app is in foreground or not.
19+
*/
20+
val inForeground = _inForeground.asStateFlow()
21+
22+
/**
23+
* Called when the app is resumed (at [androidx.lifecycle.Lifecycle.Event.ON_RESUME])
24+
*/
25+
fun onResume() {
26+
_inForeground.value = true
27+
}
28+
29+
/**
30+
* Called when the app is paused (at [androidx.lifecycle.Lifecycle.Event.ON_PAUSE])
31+
*/
32+
fun onPaused() {
33+
_inForeground.value = false
34+
}
1435
}

0 commit comments

Comments
 (0)