Skip to content

Commit a27dc91

Browse files
committed
- fixed android permission check/update, tryOnResume effect moved to core
1 parent 984fc82 commit a27dc91

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

core-domain/src/commonMain/kotlin/com/coderwise/core/domain/arch/Outcome.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ fun <T> Outcome<T>.dataOrNull(): T? =
5353
fun <T, R> Flow<Outcome<T>>.mapSuccess(transform: suspend (T) -> R): Flow<Outcome<R>> =
5454
map { outcome ->
5555
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
5858
}
5959
}
6060

@@ -63,3 +63,9 @@ fun <T> Flow<Outcome<T>>.filterSuccess(): Flow<T> = filter {
6363
}.map {
6464
(it as Outcome.Success).data
6565
}
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+
}

core-permissions/src/androidMain/kotlin/com/coderwise/core/permissions/impl/AndroidPermissionServiceImpl.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class AndroidPermissionService(
1818
!isGranted && !shouldShowRationale -> Permission.Status.DENIED
1919
else -> Permission.Status.PENDING
2020
}
21+
updateStatus(permission, status)
2122
return status
2223
}
2324

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
}

0 commit comments

Comments
 (0)