-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1b6d012
commit b658fb5
Showing
12 changed files
with
119 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 12 additions & 5 deletions
17
...on/src/main/java/com/freeletics/mad/sample/feature/bottomsheet/BottomSheetStateMachine.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<BottomSheetState, BottomSheetAction> { | ||
override val state: Flow<BottomSheetState> = flowOf(Init) | ||
private val _state = MutableStateFlow(BottomSheetState(route.number)) | ||
override val state: Flow<BottomSheetState> = _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() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 10 additions & 2 deletions
12
...plementation/src/main/java/com/freeletics/mad/sample/feature/dialog/DialogStateMachine.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<DialogState, DialogAction> { | ||
private val _state = MutableStateFlow(DialogState) | ||
private val _state = MutableStateFlow(DialogState(route.number)) | ||
override val state: Flow<DialogState> = _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() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters