Created
March 2, 2020 16:32
-
-
Save RohitSurwase/c1637a2304fd696ba8411b27e5d543a0 to your computer and use it in GitHub Desktop.
Abstract Activity for MVI architecture using LiveData and ViewModel.
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
abstract class AacMviActivity<STATE, EFFECT, EVENT, ViewModel : AacMviViewModel<STATE, EFFECT, EVENT>> : | |
AppCompatActivity() { | |
abstract val viewModel: ViewModel | |
private val viewStateObserver = Observer<STATE> { | |
Log.d(TAG, "observed viewState : $it") | |
renderViewState(it) | |
} | |
private val viewEffectObserver = Observer<EFFECT> { | |
Log.d(TAG, "observed viewEffect : $it") | |
renderViewEffect(it) | |
} | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
viewModel.viewStates().observe(this, viewStateObserver) | |
viewModel.viewEffects().observe(this, viewEffectObserver) | |
} | |
abstract fun renderViewState(viewState: STATE) | |
abstract fun renderViewEffect(viewEffect: EFFECT) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment