Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
hoc081098 committed Sep 20, 2024
1 parent 0cff633 commit 4972545
Show file tree
Hide file tree
Showing 7 changed files with 181 additions and 145 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ jobs:

steps:
- uses: actions/checkout@v4
- name: Set up JDK 11
- name: Set up JDK 22
uses: actions/setup-java@v4
with:
java-version: '11'
java-version: '22'
distribution: 'zulu'
- name: Build with Gradle
uses: gradle/[email protected]
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ Kotlin playground with various files of examples, and personal experiments.

[![Build](https://github.com/hoc081098/kotlin_playground/actions/workflows/gradle.yml/badge.svg)](https://github.com/hoc081098/kotlin_playground/actions/workflows/gradle.yml)
[![Hits](https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2Fhoc081098%2Fkotlin_playground&count_bg=%2379C83D&title_bg=%23555555&icon=&icon_color=%23E7E7E7&title=hits&edge_flat=false)](https://hits.seeyoufarm.com)
[![Kotlin version](https://img.shields.io/badge/Kotlin-1.9.21-blueviolet?logo=kotlin&logoColor=white)](http://kotlinlang.org)
[![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)
[![Kotlin version](https://img.shields.io/badge/Kotlin-2.0.20-blueviolet?logo=kotlin&logoColor=white)](http://kotlinlang.org)
[![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)
42 changes: 27 additions & 15 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
val kotlinVersion = "2.0.20"
kotlin("jvm") version kotlinVersion
id("org.jetbrains.compose") version "1.6.11"
id("org.jetbrains.kotlin.plugin.compose") version kotlinVersion
id("org.jetbrains.compose") version "1.6.11"
}

group = "com.hoc.kotlin_playground"
Expand All @@ -26,36 +24,49 @@ configurations.all {
}

composeCompiler {
enableStrongSkippingMode = true
featureFlags.add(
org.jetbrains.kotlin.compose.compiler.gradle.ComposeFeatureFlag.Companion.OptimizeNonSkippingGroups,
)
}

dependencies {
testImplementation(kotlin("test"))

// Kotlin Flow Extensions
implementation("io.github.hoc081098:FlowExt:1.0.0-RC")

// Kotlin Multiplatform ViewModel, SavedStateHandle, Compose Multiplatform ViewModel
val kmpViewModel = "0.8.0"
implementation("io.github.hoc081098:kmp-viewmodel:$kmpViewModel")
implementation("io.github.hoc081098:kmp-viewmodel-savedstate:$kmpViewModel")
implementation("io.github.hoc081098:kmp-viewmodel-compose:$kmpViewModel")
// Kotlin Channel Event Bus
implementation("io.github.hoc081098:channel-event-bus:0.1.0")
// Solivagant - Compose Multiplatform Navigation
implementation("io.github.hoc081098:solivagant-navigation:0.5.0")

// Compose
implementation(compose.runtime)
implementation(compose.foundation)
implementation(compose.material3)
implementation(compose.materialIconsExtended)
implementation(compose.desktop.currentOs)

// Coroutines
val coroutines = "1.9.0"
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-swing:$coroutines")
implementation("org.jetbrains.kotlinx:kotlinx-collections-immutable:0.3.8")

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

// reactivestate
api(platform("com.ensody.reactivestate:reactivestate-bom:5.8.1"))
implementation("com.ensody.reactivestate:reactivestate")

// Arrow-kt
val arrow = "1.2.4"
implementation("io.arrow-kt:arrow-core:$arrow")
implementation("io.arrow-kt:arrow-fx-coroutines:$arrow")
Expand All @@ -66,20 +77,21 @@ tasks.test {
useJUnitPlatform()
}

tasks.withType<KotlinCompile> {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_13.toString()
freeCompilerArgs = freeCompilerArgs + arrayOf(
"-XXLanguage:+RangeUntilOperator",
"-Xcontext-receivers"
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
compilerOptions {
freeCompilerArgs.addAll(
"-Xcontext-receivers",
)
compilerOptions
.languageVersion
.set(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_1_9)
}
}

java {
sourceCompatibility = JavaVersion.VERSION_13
targetCompatibility = JavaVersion.VERSION_13
sourceCompatibility = JavaVersion.VERSION_22
targetCompatibility = JavaVersion.VERSION_22
}

kotlin {
jvmToolchain {
languageVersion = JavaLanguageVersion.of(22)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package com.hoc081098.kotlin_playground.solivagant

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.material3.Button
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Immutable
import androidx.compose.runtime.Stable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.style.TextAlign
import com.hoc081098.channeleventbus.ChannelEventBusException
import com.hoc081098.channeleventbus.ValidationBeforeClosing
import com.hoc081098.flowext.FlowExtPreview
import com.hoc081098.flowext.catchAndResume
import com.hoc081098.kmp.viewmodel.Closeable
import com.hoc081098.solivagant.lifecycle.compose.collectAsStateWithLifecycle
import com.hoc081098.solivagant.navigation.NavRoot
import com.hoc081098.solivagant.navigation.ScreenDestination
import com.hoc081098.solivagant.navigation.rememberCloseableOnRoute
import kotlin.random.Random
import kotlinx.coroutines.flow.emptyFlow

@Immutable
data object FirstRoute : NavRoot {
@OptIn(FlowExtPreview::class)
@JvmStatic
@Stable
val Destination = ScreenDestination<FirstRoute> { route, modifier ->
val result by remember {
EventBus
.receiveAsFlow(SecondResultToFirst)
.catchAndResume {
if (it is ChannelEventBusException.FlowAlreadyCollected) emptyFlow()
else throw it
}
}.collectAsStateWithLifecycle(null)

rememberCloseableOnRoute(route) {
Closeable {
EventBus.closeKey(
key = SecondResultToFirst,
validations = ValidationBeforeClosing.NONE,
)
}
}

Box(
modifier = modifier.background(Color.Red.copy(alpha = 0.2f)),
contentAlignment = Alignment.Center,
) {
Column(horizontalAlignment = Alignment.CenterHorizontally) {
Text(
text = "result: $result",
textAlign = TextAlign.Center,
style = MaterialTheme.typography.titleLarge,
)

Button(
onClick = {
Navigator.navigateTo(
SecondRoute(
id = Random.nextInt().toString(),
otherIds = List(2) { Random.nextInt().toString() }
)
)
}
) { Text("Go to second route") }
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.hoc081098.kotlin_playground.solivagant

import androidx.compose.runtime.Immutable
import com.hoc081098.channeleventbus.ChannelEvent
import com.hoc081098.channeleventbus.ChannelEventKey

@Immutable
data class SecondResultToFirst(val number: Int) : ChannelEvent<SecondResultToFirst> {
override val key = Key

companion object Key : ChannelEventKey<SecondResultToFirst>(SecondResultToFirst::class)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.hoc081098.kotlin_playground.solivagant

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Button
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Immutable
import androidx.compose.runtime.Stable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import com.hoc081098.channeleventbus.OptionWhenSendingToBusDoesNotExist
import com.hoc081098.solivagant.navigation.NavRoute
import com.hoc081098.solivagant.navigation.ScreenDestination
import kotlin.random.Random

@Immutable
data class SecondRoute(
val id: String,
val otherIds: List<String>
) : NavRoute {
companion object {
@JvmStatic
@Stable
val Destination = ScreenDestination<SecondRoute> { route, modifier ->
Box(
modifier = modifier.background(Color.Green.copy(alpha = 0.2f)),
contentAlignment = Alignment.Center,
) {
Column(
modifier = Modifier.padding(16.dp),
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(
text = route.toString(),
textAlign = TextAlign.Center,
style = MaterialTheme.typography.titleLarge,
)
Spacer(Modifier.height(16.dp))
Button(
onClick = {
Navigator.navigateBack()
EventBus.send(
event = SecondResultToFirst(number = Random.nextInt()),
option = OptionWhenSendingToBusDoesNotExist.DO_NOTHING
)
}
) {
Text("Back to first route")
}
}
}
}
}
}
Loading

0 comments on commit 4972545

Please sign in to comment.