Created
February 2, 2021 16:18
-
-
Save YuanLiou/a24446b8ecc0597c4b7cb9ed5351c45d to your computer and use it in GitHub Desktop.
HandleEventWithViewEffect
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
override fun onCreate(savedInstanceStates: Bundle?) { | |
viewModel.viewEffectPublisher.observe(this, Observer<Event<ViewEffect>> { event -> | |
event.getContentIfNotHandled()?.let { | |
handleViewEffects(it) | |
} | |
}) | |
} | |
private fun handleViewEffects(viewEffect: ViewEffect) { | |
when (viewEffect) { | |
is ShowToast -> { | |
Toast.makeText(this, viewEffect.message, Toast.LENGTH_SHORT).show() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment