Skip to content

Instantly share code, notes, and snippets.

@juliuscanute
Created July 10, 2019 00:41
Show Gist options
  • Save juliuscanute/4317c6429fb312435f4cf965c91fe3d4 to your computer and use it in GitHub Desktop.
Save juliuscanute/4317c6429fb312435f4cf965c91fe3d4 to your computer and use it in GitHub Desktop.
View Model Main Activity
class MainActivityViewModel(//...) :
ViewModel() {
//...
val words: MediatorLiveData<PagedList<Meaning>> = MediatorLiveData()
//...
private fun addAllWordsAndRemoveSearch() {
removeSearchObserver()
if (!mapOfLiveData.containsKey(ALL)) {
mapOfLiveData[ALL] = LivePagedListBuilder(dataSourceFactory, config).build()
words.addSource(mapOfLiveData[ALL]!!) {
words.value = it
}
}
}
private fun addSearchAndRemoveAllWords() {
removeAllWordsObserver()
if (!mapOfLiveData.containsKey(SEARCH)) {
mapOfLiveData[SEARCH] = LivePagedListBuilder(searchDataSourceFactory, config).build()
words.addSource(mapOfLiveData[SEARCH]!!) {
words.value = it
}
}
}
//...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment