File tree 3 files changed +36
-2
lines changed
core-domain/src/commonMain/kotlin/com/coderwise/core/domain/arch
core-permissions/src/androidMain/kotlin/com/coderwise/core/permissions/impl
core-ui/src/commonMain/kotlin/com/coderwise/core/ui/utils 3 files changed +36
-2
lines changed Original file line number Diff line number Diff line change @@ -53,8 +53,8 @@ fun <T> Outcome<T>.dataOrNull(): T? =
53
53
fun <T , R > Flow<Outcome<T>>.mapSuccess (transform : suspend (T ) -> R ): Flow <Outcome <R >> =
54
54
map { outcome ->
55
55
when (outcome) {
56
- is Outcome .Success -> com.coderwise.core.domain.arch. Outcome .Success (transform(outcome.data))
57
- is Outcome .Error -> com.coderwise.core.domain.arch. Outcome . Error ( outcome.exception)
56
+ is Outcome .Success -> Outcome .Success (transform(outcome.data))
57
+ is Outcome .Error -> outcome
58
58
}
59
59
}
60
60
@@ -63,3 +63,9 @@ fun <T> Flow<Outcome<T>>.filterSuccess(): Flow<T> = filter {
63
63
}.map {
64
64
(it as Outcome .Success ).data
65
65
}
66
+
67
+ suspend fun <T > tryOutcome (block : suspend () -> T ): Outcome <T > = try {
68
+ Outcome .Success (block())
69
+ } catch (e: Exception ) {
70
+ Outcome .Error (e)
71
+ }
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ class AndroidPermissionService(
18
18
! isGranted && ! shouldShowRationale -> Permission .Status .DENIED
19
19
else -> Permission .Status .PENDING
20
20
}
21
+ updateStatus(permission, status)
21
22
return status
22
23
}
23
24
Original file line number Diff line number Diff line change
1
+ package com.coderwise.core.ui.utils
2
+
3
+ import androidx.compose.runtime.Composable
4
+ import androidx.compose.runtime.DisposableEffect
5
+ import androidx.lifecycle.Lifecycle
6
+ import androidx.lifecycle.LifecycleEventObserver
7
+ import androidx.lifecycle.LifecycleOwner
8
+ import androidx.lifecycle.compose.LocalLifecycleOwner
9
+
10
+ @Composable
11
+ fun OnResumeEffect (
12
+ key : Any? = null,
13
+ lifecycleOwner : LifecycleOwner = LocalLifecycleOwner .current,
14
+ onResume : () -> Unit
15
+ ) {
16
+ DisposableEffect (key, lifecycleOwner) {
17
+ val observer = LifecycleEventObserver { _, event ->
18
+ if (event == Lifecycle .Event .ON_RESUME ) {
19
+ onResume()
20
+ }
21
+ }
22
+ lifecycleOwner.lifecycle.addObserver(observer)
23
+ onDispose {
24
+ lifecycleOwner.lifecycle.removeObserver(observer)
25
+ }
26
+ }
27
+ }
You can’t perform that action at this time.
0 commit comments