Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Android Model-View-Intent with Kotlin Flow - LiveData FeedViewState.kt
// The view observes the immutable LiveData value emissions
private fun initViewStates() {
feedViewModel.state.feedList.observe(viewLifecycleOwner) { pagedList ->
adapter.submitList(pagedList)
}
}
// Mutable
data class _FeedViewState(
val _feedType: FeedType = MAIN,
val _toolbarState: ToolbarState = ToolbarState(),
val _feedList: MutableLiveData<PagedList<Content>> = MutableLiveData(),
val _contentToPlay: MutableLiveData<ContentToPlay?> = MutableLiveData()
)
// Immutable
data class FeedViewState(private val _state: _FeedViewState) {
val feedType: FeedType = _state._feedType
val toolbarState: ToolbarState = _state._toolbarState
val feedList: LiveData<PagedList<Content>> = _state._feedList
val contentToPlay: LiveData<ContentToPlay?> = _state._contentToPlay
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment