diff --git a/README.md b/README.md index 4e768b56d..e69de29bb 100644 --- a/README.md +++ b/README.md @@ -1 +0,0 @@ -# \ No newline at end of file diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 502707d5e..e19bb38cd 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -11,4 +11,6 @@ android.namespace = "io.github.droidkaigi.confsched2022" dependencies { implementation(projects.featureHome) implementation(projects.coreUi) + + implementation(libs.hiltNavigationCompose) } \ No newline at end of file diff --git a/build-logic/gradle/wrapper/gradle-wrapper.jar b/build-logic/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 000000000..249e5832f Binary files /dev/null and b/build-logic/gradle/wrapper/gradle-wrapper.jar differ diff --git a/build-logic/gradle/wrapper/gradle-wrapper.properties b/build-logic/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 000000000..8049c684f --- /dev/null +++ b/build-logic/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/core-model/src/androidTest/java/io/github/droidkaigi/confsched2022/ExampleInstrumentedTest.kt b/core-model/src/androidTest/java/io/github/droidkaigi/confsched2022/ExampleInstrumentedTest.kt deleted file mode 100644 index 0fe3dd7a1..000000000 --- a/core-model/src/androidTest/java/io/github/droidkaigi/confsched2022/ExampleInstrumentedTest.kt +++ /dev/null @@ -1,13 +0,0 @@ -package io.github.droidkaigi.confsched2022 - -import androidx.test.ext.junit.runners.AndroidJUnit4 -import org.junit.Test -import org.junit.runner.RunWith - -@RunWith(AndroidJUnit4::class) -class ExampleInstrumentedTest { - @Test - fun useAppContext() { - // Context of the app under test. - } -} diff --git a/core-model/src/androidMain/AndroidManifest.xml b/core-model/src/commonMain/AndroidManifest.xml similarity index 100% rename from core-model/src/androidMain/AndroidManifest.xml rename to core-model/src/commonMain/AndroidManifest.xml diff --git a/core-model/src/androidMain/java/io/github/droidkaigi/confsched2022/Session.kt b/core-model/src/commonMain/kotlin/io/github/droidkaigi/confsched2022/Session.kt similarity index 100% rename from core-model/src/androidMain/java/io/github/droidkaigi/confsched2022/Session.kt rename to core-model/src/commonMain/kotlin/io/github/droidkaigi/confsched2022/Session.kt diff --git a/core-model/src/androidMain/java/io/github/droidkaigi/confsched2022/SessionGroup.kt b/core-model/src/commonMain/kotlin/io/github/droidkaigi/confsched2022/Sessions.kt similarity index 63% rename from core-model/src/androidMain/java/io/github/droidkaigi/confsched2022/SessionGroup.kt rename to core-model/src/commonMain/kotlin/io/github/droidkaigi/confsched2022/Sessions.kt index c06c5214b..4b48c883c 100644 --- a/core-model/src/androidMain/java/io/github/droidkaigi/confsched2022/SessionGroup.kt +++ b/core-model/src/commonMain/kotlin/io/github/droidkaigi/confsched2022/Sessions.kt @@ -2,4 +2,4 @@ package io.github.droidkaigi.confsched2022 import kotlinx.collections.immutable.ImmutableList -class SessionGroup(val sessions: ImmutableList) \ No newline at end of file +class Sessions(val sessions: ImmutableList) \ No newline at end of file diff --git a/core-model/src/test/java/io/github/droidkaigi/confsched2022/ExampleUnitTest.kt b/core-model/src/test/java/io/github/droidkaigi/confsched2022/ExampleUnitTest.kt deleted file mode 100644 index 4141a31b1..000000000 --- a/core-model/src/test/java/io/github/droidkaigi/confsched2022/ExampleUnitTest.kt +++ /dev/null @@ -1,16 +0,0 @@ -package io.github.droidkaigi.confsched2022 - -import org.junit.Assert.assertEquals -import org.junit.Test - -/** - * Example local unit test, which will execute on the development machine (host). - * - * See [testing documentation](http://d.android.com/tools/testing). - */ -class ExampleUnitTest { - @Test - fun addition_isCorrect() { - assertEquals(4, 2 + 2) - } -} diff --git a/feature-home/build.gradle.kts b/feature-home/build.gradle.kts index c20e0cc90..9ed1adb8e 100644 --- a/feature-home/build.gradle.kts +++ b/feature-home/build.gradle.kts @@ -8,6 +8,7 @@ dependencies { implementation(projects.coreUi) implementation(projects.coreModel) + implementation(libs.hiltNavigationCompose) implementation(libs.androidxCoreKtx) implementation(libs.composeUi) implementation(libs.composeMaterial) diff --git a/feature-home/src/main/java/io/github/droidkaigi/confsched2022/Sessions.kt b/feature-home/src/main/java/io/github/droidkaigi/confsched2022/Sessions.kt index 4e5bdfc4d..264644ba2 100644 --- a/feature-home/src/main/java/io/github/droidkaigi/confsched2022/Sessions.kt +++ b/feature-home/src/main/java/io/github/droidkaigi/confsched2022/Sessions.kt @@ -1,15 +1,25 @@ package io.github.droidkaigi.confsched2022 +import androidx.compose.foundation.clickable import androidx.compose.material.Text import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.ui.Modifier import androidx.compose.ui.tooling.preview.Preview +import androidx.hilt.navigation.compose.hiltViewModel import io.github.droidkaigi.confsched2022.ui.theme.DroidKaigi2022Theme @Composable fun Sessions() { - Text(text = "Hello!") + val hiltViewModel = hiltViewModel() + val state by hiltViewModel.state + Text( + text = "Hello! $state", + modifier = Modifier.clickable { + hiltViewModel.onToggle() + } + ) } - @Preview(showBackground = true) @Composable fun SessionsPreview() { diff --git a/feature-home/src/main/java/io/github/droidkaigi/confsched2022/SessionsUiModel.kt b/feature-home/src/main/java/io/github/droidkaigi/confsched2022/SessionsUiModel.kt index b9b99aa6c..ca1494776 100644 --- a/feature-home/src/main/java/io/github/droidkaigi/confsched2022/SessionsUiModel.kt +++ b/feature-home/src/main/java/io/github/droidkaigi/confsched2022/SessionsUiModel.kt @@ -1,10 +1,11 @@ package io.github.droidkaigi.confsched2022 -class SessionsUiModel( - val sessionListState: SessionListState +data class SessionsUiModel( + val sessionsState: SessionsState, + val isFilterOn: Boolean ) { - sealed interface SessionListState { - class Loaded() : SessionListState - object Loading : SessionListState + sealed interface SessionsState { + class Loaded(sessions: Sessions) : SessionsState + object Loading : SessionsState } } diff --git a/feature-home/src/main/java/io/github/droidkaigi/confsched2022/SessionsViewModel.kt b/feature-home/src/main/java/io/github/droidkaigi/confsched2022/SessionsViewModel.kt index d19ed46a5..d69499f71 100644 --- a/feature-home/src/main/java/io/github/droidkaigi/confsched2022/SessionsViewModel.kt +++ b/feature-home/src/main/java/io/github/droidkaigi/confsched2022/SessionsViewModel.kt @@ -6,32 +6,40 @@ import androidx.compose.runtime.State import androidx.compose.runtime.mutableStateOf import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope +import app.cash.molecule.AndroidUiDispatcher import app.cash.molecule.RecompositionClock +import app.cash.molecule.RecompositionClock.ContextClock import app.cash.molecule.launchMolecule import dagger.hilt.android.lifecycle.HiltViewModel -import io.github.droidkaigi.confsched2022.SessionsUiModel.SessionListState +import io.github.droidkaigi.confsched2022.SessionsUiModel.SessionsState import javax.inject.Inject import kotlinx.coroutines.CoroutineScope @HiltViewModel class SessionsViewModel @Inject constructor() : ViewModel() { val filter = mutableStateOf(false) - val state = viewModelScope.moleculeComposeState { - SessionsUiModel(SessionListState.Loading) + + private val moleculeScope = + CoroutineScope(viewModelScope.coroutineContext + AndroidUiDispatcher.Main) + + val state = moleculeScope.moleculeComposeState(clock = ContextClock) { + SessionsUiModel(SessionsState.Loading, isFilterOn = filter.value) } fun onToggle() { + println("toggle") filter.value = !filter.value } } fun CoroutineScope.moleculeComposeState( + clock: RecompositionClock, body: @Composable () -> T, ): State { var mutableState: MutableState? = null - launchMolecule( - RecompositionClock.ContextClock, + launchMolecule( + clock, emitter = { value -> val outputFlow = mutableState if (outputFlow != null) { diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 625914736..0eb2edfdf 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -8,7 +8,8 @@ androidDesugarJdkLibs = "1.2.0" compose = "1.2.0" composeCompiler = "1.2.0" androidxLifecycle = "2.5.0" -androidxActivity = "1.5.0" +androidxActivity = "1.6.0-alpha05" +hiltNavigationCompose = "1.0.0" junit = "4.13.2" androidxTestExt = "1.1.3" androidxTestEspresso = "3.4.0" @@ -41,6 +42,7 @@ kotlinxCollectionsImmutable = { module = "org.jetbrains.kotlinx:kotlinx-collecti androidxCoreKtx = { module = "androidx.core:core-ktx", version.ref = "androidxCore" } androidxLifecycleLifecycleRuntimeKtx = { module = "androidx.lifecycle:lifecycle-runtime-ktx", version.ref = "androidxLifecycle" } androidxActivityActivityCompose = { module = "androidx.activity:activity-compose", version.ref = "androidxActivity" } +hiltNavigationCompose = { module = "androidx.hilt:hilt-navigation-compose", version.ref = "hiltNavigationCompose" } junit = { module = "junit:junit", version.ref = "junit" } androidxTestExtJunit = { module = "androidx.test.ext:junit", version.ref = "androidxTestExt" } androidxTestEspressoEspressoCore = { module = "androidx.test.espresso:espresso-core", version.ref = "androidxTestEspresso" }