Skip to content

Instantly share code, notes, and snippets.

@makorowy
Last active October 18, 2020 09:48
Show Gist options
  • Save makorowy/43c860e3bd6cc198b743cb07fc81c788 to your computer and use it in GitHub Desktop.
Save makorowy/43c860e3bd6cc198b743cb07fc81c788 to your computer and use it in GitHub Desktop.
Example of not handling interactions via ViewModel, part 6
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