This file contains hidden or 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
fun addNewRow(runAfter: () -> Unit) { | |
onAction(ListScreenActions.OnAddNewRow, runAfter = runAfter) | |
} | |
fun editNewRow() { onAction(ListScreenActions.OnAddNewRowChanged) } |
This file contains hidden or 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
fun editName() { onAction(ListScreenActions.OnNameEdit) } | |
fun editNameChanged() { onAction(ListScreenActions.OnNameChanged)} |
This file contains hidden or 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
private fun onAction( action: ListScreenActions, | |
runBefore: () -> Unit = {}, | |
runAfter: () -> Unit = {} | |
) { | |
if (state() == action.source) { | |
runBefore() | |
screenState.value = action.target | |
runAfter() | |
} | |
} |
This file contains hidden or 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
class ScreenModel { | |
private lateinit var screenState: MutableState<ListScreenState> | |
@Composable | |
fun Init(state: ListScreenState = Idle) { | |
screenState = remember { | |
mutableStateOf(state) | |
} | |
} |
This file contains hidden or 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
sealed class ListScreenActions( | |
val source: ListScreenState, | |
val target: ListScreenState | |
) { | |
object OnNameEdit : ListScreenActions(Idle, NameEdit) | |
object OnNameChanged : ListScreenActions(NameEdit, NameChanged) | |
object OnAddNewRow : ListScreenActions(Idle, RowNew) | |
This file contains hidden or 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
object RowEditChanged : ListScreenState(RowEdit) { | |
override val editButtonTitle = "Save" | |
override val isAddButtonVisible = false | |
override val isTableVisible = false | |
} | |
object RowNewChanged : ListScreenState(RowNew) { | |
override val editButtonTitle = "Save" | |
override val isAddButtonVisible = false | |
override val isTableVisible = false |
This file contains hidden or 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
object RowEdit : ListScreenState() { | |
override val editButtonTitle = "Done" | |
override val isAddButtonVisible = false | |
override val isTableVisible = false | |
} | |
object RowNew : ListScreenState() { | |
override val editButtonTitle = "Done" | |
override val isAddButtonVisible = false | |
override val isTableVisible = false |
This file contains hidden or 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
object NameChanged : ListScreenState(NameEdit) { | |
override val editButtonTitle = "Save" | |
override val isAddButtonVisible = false | |
override val isEditNameMode = true | |
} |
This file contains hidden or 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
object NameEdit : ListScreenState() { | |
override val editButtonTitle = "Done" | |
override val isAddButtonVisible = false | |
override val isEditNameMode = true | |
} |
This file contains hidden or 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
sealed class ListScreenState( | |
val back: ListScreenState? = Idle | |
){ | |
open val editButtonTitle = "Edit" | |
open val isAddButtonVisible = true | |
open val isEditNameMode = false | |
open val isTableVisible= true | |
object Idle : ListScreenState() |