diff --git a/sample/simple/feature/bottom-sheet/implementation/feature-bottom-sheet-implementation.gradle.kts b/sample/simple/feature/bottom-sheet/implementation/feature-bottom-sheet-implementation.gradle.kts index 5297598c1..72178c06f 100644 --- a/sample/simple/feature/bottom-sheet/implementation/feature-bottom-sheet-implementation.gradle.kts +++ b/sample/simple/feature/bottom-sheet/implementation/feature-bottom-sheet-implementation.gradle.kts @@ -23,4 +23,6 @@ dependencies { implementation(libs.mad.whetstone) implementation(libs.mad.whetstone.runtime) implementation(libs.mad.whetstone.scope) + implementation(projects.feature.dialog.nav) + implementation(projects.feature.screen.nav) } diff --git a/sample/simple/feature/bottom-sheet/implementation/src/main/java/com/freeletics/mad/sample/feature/bottomsheet/BottomSheetNavigator.kt b/sample/simple/feature/bottom-sheet/implementation/src/main/java/com/freeletics/mad/sample/feature/bottomsheet/BottomSheetNavigator.kt index fa2ed5ce0..de9abc727 100644 --- a/sample/simple/feature/bottom-sheet/implementation/src/main/java/com/freeletics/mad/sample/feature/bottomsheet/BottomSheetNavigator.kt +++ b/sample/simple/feature/bottom-sheet/implementation/src/main/java/com/freeletics/mad/sample/feature/bottomsheet/BottomSheetNavigator.kt @@ -2,10 +2,27 @@ package com.freeletics.mad.sample.feature.bottomsheet import com.freeletics.mad.navigator.NavEventNavigator import com.freeletics.mad.sample.feature.bottomsheet.nav.BottomSheetRoute +import com.freeletics.mad.sample.feature.dialog.nav.DialogRoute +import com.freeletics.mad.sample.feature.screen.nav.ScreenRoute import com.freeletics.mad.whetstone.ScopeTo import com.squareup.anvil.annotations.ContributesBinding import javax.inject.Inject @ScopeTo(BottomSheetRoute::class) @ContributesBinding(BottomSheetRoute::class, NavEventNavigator::class) -class BottomSheetNavigator @Inject constructor() : NavEventNavigator() +class BottomSheetNavigator @Inject constructor( + private val route: BottomSheetRoute, +) : NavEventNavigator() { + + fun navigateToScreen() { + navigateTo(ScreenRoute(route.number + 1)) + } + + fun navigateToDialog() { + navigateTo(DialogRoute(route.number + 1)) + } + + fun navigateToBottomSheet() { + navigateTo(BottomSheetRoute(route.number + 1)) + } +} diff --git a/sample/simple/feature/bottom-sheet/implementation/src/main/java/com/freeletics/mad/sample/feature/bottomsheet/BottomSheetScreen.kt b/sample/simple/feature/bottom-sheet/implementation/src/main/java/com/freeletics/mad/sample/feature/bottomsheet/BottomSheetScreen.kt index a31e8395d..13890c2e1 100644 --- a/sample/simple/feature/bottom-sheet/implementation/src/main/java/com/freeletics/mad/sample/feature/bottomsheet/BottomSheetScreen.kt +++ b/sample/simple/feature/bottom-sheet/implementation/src/main/java/com/freeletics/mad/sample/feature/bottomsheet/BottomSheetScreen.kt @@ -1,7 +1,10 @@ package com.freeletics.mad.sample.feature.bottomsheet +import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.text.BasicText import androidx.compose.material3.ExperimentalMaterial3Api @@ -22,6 +25,7 @@ import com.freeletics.mad.whetstone.compose.DestinationType ) @Composable fun BottomSheetScreen( + state: BottomSheetState, sendAction: (BottomSheetAction) -> Unit, ) { ModalBottomSheet(onDismissRequest = { sendAction(BottomSheetAction.DismissRequested) }) { @@ -31,7 +35,28 @@ fun BottomSheetScreen( .padding(vertical = 48.dp), horizontalAlignment = Alignment.CenterHorizontally, ) { - BasicText("Feature Bottom Sheet") + BasicText("Feature Bottom Sheet ${state.number}") + + Spacer(Modifier.height(12.dp)) + + BasicText( + modifier = Modifier.clickable { sendAction(BottomSheetAction.ScreenButtonClicked) }, + text = "Open Screen", + ) + + Spacer(Modifier.height(12.dp)) + + BasicText( + modifier = Modifier.clickable { sendAction(BottomSheetAction.DialogButtonClicked) }, + text = "Open Dialog", + ) + + Spacer(Modifier.height(12.dp)) + + BasicText( + modifier = Modifier.clickable { sendAction(BottomSheetAction.BottomSheetButtonClicked) }, + text = "Open Bottom Sheet", + ) } } } diff --git a/sample/simple/feature/bottom-sheet/implementation/src/main/java/com/freeletics/mad/sample/feature/bottomsheet/BottomSheetStateMachine.kt b/sample/simple/feature/bottom-sheet/implementation/src/main/java/com/freeletics/mad/sample/feature/bottomsheet/BottomSheetStateMachine.kt index 6bfe5d329..8d5be3ec4 100644 --- a/sample/simple/feature/bottom-sheet/implementation/src/main/java/com/freeletics/mad/sample/feature/bottomsheet/BottomSheetStateMachine.kt +++ b/sample/simple/feature/bottom-sheet/implementation/src/main/java/com/freeletics/mad/sample/feature/bottomsheet/BottomSheetStateMachine.kt @@ -1,26 +1,33 @@ package com.freeletics.mad.sample.feature.bottomsheet +import com.freeletics.mad.sample.feature.bottomsheet.nav.BottomSheetRoute import com.freeletics.mad.statemachine.StateMachine import javax.inject.Inject import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.flowOf +import kotlinx.coroutines.flow.MutableStateFlow -sealed interface BottomSheetState - -object Init : BottomSheetState +data class BottomSheetState(val number: Int) sealed interface BottomSheetAction { object DismissRequested : BottomSheetAction + object ScreenButtonClicked : BottomSheetAction + object DialogButtonClicked : BottomSheetAction + object BottomSheetButtonClicked : BottomSheetAction } class BottomSheetStateMachine @Inject constructor( + route: BottomSheetRoute, private val navigator: BottomSheetNavigator, ) : StateMachine { - override val state: Flow = flowOf(Init) + private val _state = MutableStateFlow(BottomSheetState(route.number)) + override val state: Flow = _state override suspend fun dispatch(action: BottomSheetAction) { when (action) { BottomSheetAction.DismissRequested -> navigator.navigateBack() + BottomSheetAction.ScreenButtonClicked -> navigator.navigateToScreen() + BottomSheetAction.DialogButtonClicked -> navigator.navigateToDialog() + BottomSheetAction.BottomSheetButtonClicked -> navigator.navigateToBottomSheet() } } } diff --git a/sample/simple/feature/bottom-sheet/nav/src/main/java/com/freeletics/mad/sample/feature/bottomsheet/nav/BottomSheetRoute.kt b/sample/simple/feature/bottom-sheet/nav/src/main/java/com/freeletics/mad/sample/feature/bottomsheet/nav/BottomSheetRoute.kt index abf374cfa..a9de601b1 100644 --- a/sample/simple/feature/bottom-sheet/nav/src/main/java/com/freeletics/mad/sample/feature/bottomsheet/nav/BottomSheetRoute.kt +++ b/sample/simple/feature/bottom-sheet/nav/src/main/java/com/freeletics/mad/sample/feature/bottomsheet/nav/BottomSheetRoute.kt @@ -4,4 +4,4 @@ import com.freeletics.mad.navigator.NavRoute import kotlinx.parcelize.Parcelize @Parcelize -object BottomSheetRoute : NavRoute +data class BottomSheetRoute(val number: Int) : NavRoute diff --git a/sample/simple/feature/dialog/implementation/feature-dialog-implementation.gradle.kts b/sample/simple/feature/dialog/implementation/feature-dialog-implementation.gradle.kts index 4c1565708..616c71276 100644 --- a/sample/simple/feature/dialog/implementation/feature-dialog-implementation.gradle.kts +++ b/sample/simple/feature/dialog/implementation/feature-dialog-implementation.gradle.kts @@ -22,4 +22,6 @@ dependencies { implementation(libs.mad.whetstone) implementation(libs.mad.whetstone.runtime) implementation(libs.mad.whetstone.scope) + implementation(projects.feature.bottomSheet.nav) + implementation(projects.feature.screen.nav) } diff --git a/sample/simple/feature/dialog/implementation/src/main/java/com/freeletics/mad/sample/feature/dialog/DialogNavigator.kt b/sample/simple/feature/dialog/implementation/src/main/java/com/freeletics/mad/sample/feature/dialog/DialogNavigator.kt index 41fcbe369..df0e46b83 100644 --- a/sample/simple/feature/dialog/implementation/src/main/java/com/freeletics/mad/sample/feature/dialog/DialogNavigator.kt +++ b/sample/simple/feature/dialog/implementation/src/main/java/com/freeletics/mad/sample/feature/dialog/DialogNavigator.kt @@ -1,11 +1,27 @@ package com.freeletics.mad.sample.feature.dialog import com.freeletics.mad.navigator.NavEventNavigator +import com.freeletics.mad.sample.feature.bottomsheet.nav.BottomSheetRoute import com.freeletics.mad.sample.feature.dialog.nav.DialogRoute +import com.freeletics.mad.sample.feature.screen.nav.ScreenRoute import com.freeletics.mad.whetstone.ScopeTo import com.squareup.anvil.annotations.ContributesBinding import javax.inject.Inject @ScopeTo(DialogRoute::class) @ContributesBinding(DialogRoute::class, NavEventNavigator::class) -class DialogNavigator @Inject constructor() : NavEventNavigator() +class DialogNavigator @Inject constructor( + private val route: DialogRoute, +) : NavEventNavigator() { + fun navigateToScreen() { + navigateTo(ScreenRoute(route.number + 1)) + } + + fun navigateToDialog() { + navigateTo(DialogRoute(route.number + 1)) + } + + fun navigateToBottomSheet() { + navigateTo(BottomSheetRoute(route.number + 1)) + } +} diff --git a/sample/simple/feature/dialog/implementation/src/main/java/com/freeletics/mad/sample/feature/dialog/DialogScreen.kt b/sample/simple/feature/dialog/implementation/src/main/java/com/freeletics/mad/sample/feature/dialog/DialogScreen.kt index 9cf035f9b..d90c05cd8 100644 --- a/sample/simple/feature/dialog/implementation/src/main/java/com/freeletics/mad/sample/feature/dialog/DialogScreen.kt +++ b/sample/simple/feature/dialog/implementation/src/main/java/com/freeletics/mad/sample/feature/dialog/DialogScreen.kt @@ -1,8 +1,11 @@ package com.freeletics.mad.sample.feature.dialog import androidx.compose.foundation.background +import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.text.BasicText import androidx.compose.runtime.Composable @@ -22,6 +25,7 @@ import com.freeletics.mad.whetstone.compose.DestinationType ) @Composable fun DialogScreen( + state: DialogState, sendAction: (DialogAction) -> Unit, ) { Dialog(onDismissRequest = { sendAction(DialogAction.DismissRequested) }) { @@ -32,7 +36,28 @@ fun DialogScreen( .padding(vertical = 48.dp), horizontalAlignment = Alignment.CenterHorizontally, ) { - BasicText("Feature Dialog") + BasicText("Feature Dialog ${state.number}") + + Spacer(Modifier.height(12.dp)) + + BasicText( + modifier = Modifier.clickable { sendAction(DialogAction.ScreenButtonClicked) }, + text = "Open Screen", + ) + + Spacer(Modifier.height(12.dp)) + + BasicText( + modifier = Modifier.clickable { sendAction(DialogAction.DialogButtonClicked) }, + text = "Open Dialog", + ) + + Spacer(Modifier.height(12.dp)) + + BasicText( + modifier = Modifier.clickable { sendAction(DialogAction.BottomSheetButtonClicked) }, + text = "Open Bottom Sheet", + ) } } } diff --git a/sample/simple/feature/dialog/implementation/src/main/java/com/freeletics/mad/sample/feature/dialog/DialogStateMachine.kt b/sample/simple/feature/dialog/implementation/src/main/java/com/freeletics/mad/sample/feature/dialog/DialogStateMachine.kt index ab393d72d..1753851ae 100644 --- a/sample/simple/feature/dialog/implementation/src/main/java/com/freeletics/mad/sample/feature/dialog/DialogStateMachine.kt +++ b/sample/simple/feature/dialog/implementation/src/main/java/com/freeletics/mad/sample/feature/dialog/DialogStateMachine.kt @@ -1,25 +1,33 @@ package com.freeletics.mad.sample.feature.dialog +import com.freeletics.mad.sample.feature.dialog.nav.DialogRoute import com.freeletics.mad.statemachine.StateMachine import javax.inject.Inject import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableStateFlow -object DialogState +data class DialogState(val number: Int) sealed interface DialogAction { object DismissRequested : DialogAction + object ScreenButtonClicked : DialogAction + object DialogButtonClicked : DialogAction + object BottomSheetButtonClicked : DialogAction } class DialogStateMachine @Inject constructor( + route: DialogRoute, private val navigator: DialogNavigator, ) : StateMachine { - private val _state = MutableStateFlow(DialogState) + private val _state = MutableStateFlow(DialogState(route.number)) override val state: Flow = _state override suspend fun dispatch(action: DialogAction) { when (action) { DialogAction.DismissRequested -> navigator.navigateBack() + DialogAction.ScreenButtonClicked -> navigator.navigateToScreen() + DialogAction.DialogButtonClicked -> navigator.navigateToDialog() + DialogAction.BottomSheetButtonClicked -> navigator.navigateToBottomSheet() } } } diff --git a/sample/simple/feature/dialog/nav/src/main/java/com/freeletics/mad/sample/feature/dialog/nav/DialogRoute.kt b/sample/simple/feature/dialog/nav/src/main/java/com/freeletics/mad/sample/feature/dialog/nav/DialogRoute.kt index 711ae5f35..5e0b8147f 100644 --- a/sample/simple/feature/dialog/nav/src/main/java/com/freeletics/mad/sample/feature/dialog/nav/DialogRoute.kt +++ b/sample/simple/feature/dialog/nav/src/main/java/com/freeletics/mad/sample/feature/dialog/nav/DialogRoute.kt @@ -4,4 +4,4 @@ import com.freeletics.mad.navigator.NavRoute import kotlinx.parcelize.Parcelize @Parcelize -object DialogRoute : NavRoute +data class DialogRoute(val number: Int) : NavRoute diff --git a/sample/simple/feature/root/implementation/src/main/java/com/freeletics/mad/sample/feature/root/RootNavigator.kt b/sample/simple/feature/root/implementation/src/main/java/com/freeletics/mad/sample/feature/root/RootNavigator.kt index e6ed4730b..41ce475f4 100644 --- a/sample/simple/feature/root/implementation/src/main/java/com/freeletics/mad/sample/feature/root/RootNavigator.kt +++ b/sample/simple/feature/root/implementation/src/main/java/com/freeletics/mad/sample/feature/root/RootNavigator.kt @@ -17,10 +17,10 @@ class RootNavigator @Inject constructor() : NavEventNavigator() { } fun navigateToDialog() { - navigateTo(DialogRoute) + navigateTo(DialogRoute(1)) } fun navigateToBottomSheet() { - navigateTo(BottomSheetRoute) + navigateTo(BottomSheetRoute(1)) } } diff --git a/sample/simple/feature/screen/implementation/src/main/java/com/freeletics/mad/sample/feature/screen/ScreenNavigator.kt b/sample/simple/feature/screen/implementation/src/main/java/com/freeletics/mad/sample/feature/screen/ScreenNavigator.kt index 8584387d1..86dfc13bd 100644 --- a/sample/simple/feature/screen/implementation/src/main/java/com/freeletics/mad/sample/feature/screen/ScreenNavigator.kt +++ b/sample/simple/feature/screen/implementation/src/main/java/com/freeletics/mad/sample/feature/screen/ScreenNavigator.kt @@ -19,10 +19,10 @@ class ScreenNavigator @Inject constructor( } fun navigateToDialog() { - navigateTo(DialogRoute) + navigateTo(DialogRoute(route.number + 1)) } fun navigateToBottomSheet() { - navigateTo(BottomSheetRoute) + navigateTo(BottomSheetRoute(route.number + 1)) } }