File tree 2 files changed +24
-3
lines changed
app/src/main/kotlin/at/bitfire/davdroid/ui
2 files changed +24
-3
lines changed Original file line number Diff line number Diff line change @@ -50,9 +50,9 @@ fun AppTheme(
50
50
51
51
// Track if the app is in the foreground
52
52
LifecycleResumeEffect (view) {
53
- ForegroundTracker .inForeground.value = true
53
+ ForegroundTracker .onResume()
54
54
onPauseOrDispose {
55
- ForegroundTracker .inForeground.value = false
55
+ ForegroundTracker .onPaused()
56
56
}
57
57
}
58
58
}
Original file line number Diff line number Diff line change 5
5
package at.bitfire.davdroid.ui
6
6
7
7
import kotlinx.coroutines.flow.MutableStateFlow
8
+ import kotlinx.coroutines.flow.asStateFlow
8
9
9
10
/* *
10
11
* Used to track whether the app is in foreground (visible to user) or not.
11
12
*/
12
13
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
+ }
14
35
}
You can’t perform that action at this time.
0 commit comments