Created
July 10, 2019 00:41
-
-
Save juliuscanute/4317c6429fb312435f4cf965c91fe3d4 to your computer and use it in GitHub Desktop.
View Model Main Activity
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
| 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