Skip to content

Commit 1c47019

Browse files
authored
Gradle 8.3, Kotlin 1.9.10, AGP 8.1.0, SDK 34, Coroutines 1.7.3, Compose 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
1 parent 313a8b3 commit 1c47019

File tree

51 files changed

+1087
-993
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1087
-993
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
uses: actions/setup-java@v3
2323
with:
2424
distribution: 'zulu'
25-
java-version: '11'
25+
java-version: '17'
2626

2727
- name: Cache gradle, wrapper and buildSrc
2828
uses: actions/cache@v3

.github/workflows/gradle-versions-checker.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
uses: actions/setup-java@v3
2121
with:
2222
distribution: 'zulu'
23-
java-version: '11'
23+
java-version: '17'
2424

2525
- name: Cache gradle, wrapper and buildSrc
2626
uses: actions/cache@v3

.github/workflows/ios-build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
uses: actions/setup-java@v3
2424
with:
2525
distribution: 'zulu'
26-
java-version: '11'
26+
java-version: '17'
2727

2828
# - name: Make gradlew executable
2929
# run: chmod +x ./gradlew

.github/workflows/review-suggest.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- uses: actions/setup-java@v3
1919
with:
2020
distribution: 'zulu'
21-
java-version: '11'
21+
java-version: '17'
2222
- name: Cache gradle, wrapper and buildSrc
2323
uses: actions/cache@v3
2424
with:

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
uses: actions/setup-java@v3
2323
with:
2424
distribution: 'zulu'
25-
java-version: '11'
25+
java-version: '17'
2626

2727
- name: Cache gradle, wrapper and buildSrc
2828
uses: actions/cache@v3

androidApp/build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ android {
4646
}
4747

4848
kotlinOptions {
49+
options.jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_11
4950
freeCompilerArgs = freeCompilerArgs + buildComposeMetricsParameters() + listOf(
5051
"-opt-in=kotlin.RequiresOptIn",
5152
// Enable experimental coroutines APIs, including Flow
@@ -63,7 +64,7 @@ android {
6364
all {
6465
if (it.name == "testDebugUnitTest") {
6566
it.extensions.configure<kotlinx.kover.api.KoverTaskExtension> {
66-
isDisabled.set(false)
67+
isDisabled = false
6768
// excludes.addAll(excludedClasses)
6869
}
6970
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.hoc081098.github_search_kmm.android.compose_utils
2+
3+
import androidx.compose.runtime.Stable
4+
5+
@Stable
6+
@JvmInline
7+
value class StableWrapper<T>(val value: T)
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package com.hoc081098.github_search_kmm.android.compose_utils
2+
3+
import androidx.compose.runtime.Composable
4+
import androidx.compose.runtime.NonRestartableComposable
5+
import androidx.compose.runtime.RememberObserver
6+
import androidx.compose.runtime.getValue
7+
import androidx.compose.runtime.remember
8+
import androidx.compose.runtime.rememberUpdatedState
9+
import androidx.compose.ui.platform.LocalLifecycleOwner
10+
import androidx.lifecycle.Lifecycle
11+
import androidx.lifecycle.LifecycleOwner
12+
import androidx.lifecycle.flowWithLifecycle
13+
import androidx.lifecycle.repeatOnLifecycle
14+
import kotlinx.coroutines.CoroutineScope
15+
import kotlinx.coroutines.Dispatchers
16+
import kotlinx.coroutines.Job
17+
import kotlinx.coroutines.cancel
18+
import kotlinx.coroutines.flow.Flow
19+
import kotlinx.coroutines.launch
20+
21+
@Composable
22+
fun <T> rememberFlowWithLifecycle(
23+
flow: Flow<T>,
24+
lifecycle: Lifecycle = LocalLifecycleOwner.current.lifecycle,
25+
minActiveState: Lifecycle.State = Lifecycle.State.STARTED
26+
): Flow<T> = remember(flow, lifecycle, minActiveState) {
27+
flow.flowWithLifecycle(
28+
lifecycle = lifecycle,
29+
minActiveState = minActiveState
30+
)
31+
}
32+
33+
/**
34+
* Collect the given [Flow] in a Effect that runs in the [Dispatchers.Main.immediate] coroutine,
35+
* when [LifecycleOwner.lifecycle] is at least at [minActiveState].
36+
*/
37+
@Composable
38+
fun <T> Flow<T>.CollectWithLifecycleEffect(
39+
vararg keys: Any?,
40+
lifecycleOwner: LifecycleOwner = LocalLifecycleOwner.current,
41+
minActiveState: Lifecycle.State = Lifecycle.State.STARTED,
42+
collector: (T) -> Unit,
43+
) {
44+
val flow = this
45+
val currentCollector by rememberUpdatedState(collector)
46+
47+
LaunchedEffectInImmediateMain(flow, lifecycleOwner, minActiveState, *keys) {
48+
lifecycleOwner.repeatOnLifecycle(minActiveState) {
49+
flow.collect { currentCollector(it) }
50+
}
51+
}
52+
}
53+
54+
@Composable
55+
@NonRestartableComposable
56+
@Suppress("ArrayReturn")
57+
private fun LaunchedEffectInImmediateMain(
58+
vararg keys: Any?,
59+
block: suspend CoroutineScope.() -> Unit,
60+
) {
61+
remember(*keys) { LaunchedEffectImpl(block) }
62+
}
63+
64+
private class LaunchedEffectImpl(
65+
private val task: suspend CoroutineScope.() -> Unit,
66+
) : RememberObserver {
67+
private val scope = CoroutineScope(Dispatchers.Main.immediate)
68+
private var job: Job? = null
69+
70+
override fun onRemembered() {
71+
job?.cancel("Old job was still running!")
72+
job = scope.launch(block = task)
73+
}
74+
75+
override fun onForgotten() {
76+
job?.cancel()
77+
job = null
78+
}
79+
80+
override fun onAbandoned() {
81+
job?.cancel()
82+
job = null
83+
}
84+
}

androidApp/src/main/java/com/hoc081098/github_search_kmm/android/rememberStableCoroutineScope.kt renamed to androidApp/src/main/java/com/hoc081098/github_search_kmm/android/compose_utils/rememberStableCoroutineScope.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Copyright (C) 2023 Slack Technologies, LLC
22
// SPDX-License-Identifier: Apache-2.0
3-
package com.hoc081098.github_search_kmm.android
3+
package com.hoc081098.github_search_kmm.android.compose_utils
44

55
import androidx.compose.runtime.Composable
66
import androidx.compose.runtime.Stable

androidApp/src/main/java/com/hoc081098/github_search_kmm/android/getReadableMessage.kt renamed to androidApp/src/main/java/com/hoc081098/github_search_kmm/android/core_ui/getReadableMessage.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
package com.hoc081098.github_search_kmm.android
1+
package com.hoc081098.github_search_kmm.android.core_ui
22

33
import android.content.Context
44
import androidx.compose.runtime.Composable
55
import androidx.compose.runtime.ReadOnlyComposable
66
import androidx.compose.ui.platform.LocalContext
7+
import com.hoc081098.github_search_kmm.android.R
78
import com.hoc081098.github_search_kmm.domain.model.AppError
89

910
@Composable

0 commit comments

Comments
 (0)