Last active
October 18, 2020 09:48
-
-
Save makorowy/43c860e3bd6cc198b743cb07fc81c788 to your computer and use it in GitHub Desktop.
Example of not handling interactions via ViewModel, part 6
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
class Interactor( | |
private val repository: Repository, | |
private val navigator: Navigator, | |
private val viewModel: ViewModel | |
) { | |
fun onInteraction(interaction: Interaction) { | |
when (interaction) { | |
is Interaction.BackButtonClick -> onBackButtonClicked() | |
is Interaction.SkipButtonClick -> onSkipButtonClicked() | |
is Interaction.SaveButtonClick -> onSaveButtonClicked() | |
is Interaction.NameChange -> onNameChanged(interaction.name) | |
} | |
} | |
private fun onBackButtonClicked() { | |
navigator.navigateBack() | |
} | |
private fun onSkipButtonClicked() { | |
navigator.navigateForward() | |
} | |
private fun onSaveButtonClicked() { | |
viewModel.submitProgressState(visible = true) | |
repository.doSomethingAsync() | |
//additional logic | |
//update view state or let changes from repository to do it | |
} | |
private fun onNameChanged(name: String) { | |
repository.saveName(name) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment