-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Gradle 8.3, Kotlin 1.9.10, AGP 8.1.0, SDK 34, Coroutines 1.7.3, Compo…
…se Compiler 1.5.3, Koin 3.5.0, Dagger 2.48 with KSP, kmp-viewmodel 0.5.0, FlowExt 0.7.1 and refactor. (#90) * deps * Update build.gradle.kts kapt { correctErrorTypes = true } * Update deps.kt * a * deps * deps: hilt ksp google/dagger#2349 * fix ios * refactor android * jdk 17 * fix tests * gradle * gradle * gradle
- Loading branch information
Showing
51 changed files
with
1,087 additions
and
993 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
...dApp/src/main/java/com/hoc081098/github_search_kmm/android/compose_utils/StableWrapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.hoc081098.github_search_kmm.android.compose_utils | ||
|
||
import androidx.compose.runtime.Stable | ||
|
||
@Stable | ||
@JvmInline | ||
value class StableWrapper<T>(val value: T) |
84 changes: 84 additions & 0 deletions
84
...n/java/com/hoc081098/github_search_kmm/android/compose_utils/rememberFlowWithLifecycle.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package com.hoc081098.github_search_kmm.android.compose_utils | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.NonRestartableComposable | ||
import androidx.compose.runtime.RememberObserver | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.rememberUpdatedState | ||
import androidx.compose.ui.platform.LocalLifecycleOwner | ||
import androidx.lifecycle.Lifecycle | ||
import androidx.lifecycle.LifecycleOwner | ||
import androidx.lifecycle.flowWithLifecycle | ||
import androidx.lifecycle.repeatOnLifecycle | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.Job | ||
import kotlinx.coroutines.cancel | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.launch | ||
|
||
@Composable | ||
fun <T> rememberFlowWithLifecycle( | ||
flow: Flow<T>, | ||
lifecycle: Lifecycle = LocalLifecycleOwner.current.lifecycle, | ||
minActiveState: Lifecycle.State = Lifecycle.State.STARTED | ||
): Flow<T> = remember(flow, lifecycle, minActiveState) { | ||
flow.flowWithLifecycle( | ||
lifecycle = lifecycle, | ||
minActiveState = minActiveState | ||
) | ||
} | ||
|
||
/** | ||
* Collect the given [Flow] in a Effect that runs in the [Dispatchers.Main.immediate] coroutine, | ||
* when [LifecycleOwner.lifecycle] is at least at [minActiveState]. | ||
*/ | ||
@Composable | ||
fun <T> Flow<T>.CollectWithLifecycleEffect( | ||
vararg keys: Any?, | ||
lifecycleOwner: LifecycleOwner = LocalLifecycleOwner.current, | ||
minActiveState: Lifecycle.State = Lifecycle.State.STARTED, | ||
collector: (T) -> Unit, | ||
) { | ||
val flow = this | ||
val currentCollector by rememberUpdatedState(collector) | ||
|
||
LaunchedEffectInImmediateMain(flow, lifecycleOwner, minActiveState, *keys) { | ||
lifecycleOwner.repeatOnLifecycle(minActiveState) { | ||
flow.collect { currentCollector(it) } | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
@NonRestartableComposable | ||
@Suppress("ArrayReturn") | ||
private fun LaunchedEffectInImmediateMain( | ||
vararg keys: Any?, | ||
block: suspend CoroutineScope.() -> Unit, | ||
) { | ||
remember(*keys) { LaunchedEffectImpl(block) } | ||
} | ||
|
||
private class LaunchedEffectImpl( | ||
private val task: suspend CoroutineScope.() -> Unit, | ||
) : RememberObserver { | ||
private val scope = CoroutineScope(Dispatchers.Main.immediate) | ||
private var job: Job? = null | ||
|
||
override fun onRemembered() { | ||
job?.cancel("Old job was still running!") | ||
job = scope.launch(block = task) | ||
} | ||
|
||
override fun onForgotten() { | ||
job?.cancel() | ||
job = null | ||
} | ||
|
||
override fun onAbandoned() { | ||
job?.cancel() | ||
job = null | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...m/android/rememberStableCoroutineScope.kt → ...ose_utils/rememberStableCoroutineScope.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
..._search_kmm/android/getReadableMessage.kt → ...kmm/android/core_ui/getReadableMessage.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 0 additions & 51 deletions
51
...oidApp/src/main/java/com/hoc081098/github_search_kmm/android/rememberFlowWithLifecycle.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip | ||
networkTimeout=10000 | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip | ||
networkTimeout=10000 | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
Oops, something went wrong.