Last active
February 12, 2019 14:11
-
-
Save PhilippeBoisney/dd043b58941eabd14003888e8a0c14b6 to your computer and use it in GitHub Desktop.
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
class SearchUserViewModel(repository: UserRepository, | |
private val sharedPrefsManager: SharedPrefsManager): BaseViewModel() { | |
// FOR DATA --- | |
private val userDataSource = UserDataSourceFactory(repository = repository, scope = ioScope) | |
// OBSERVABLES --- | |
val users = LivePagedListBuilder(userDataSource, pagedListConfig()).build() | |
// PUBLIC API --- | |
/** | |
* Fetch a list of [User] by name | |
* Called each time an user hits a key through [SearchView]. | |
*/ | |
fun fetchUsersByName(query: String) { | |
val search = query.trim() | |
if (userDataSource.getQuery() == search) return | |
userDataSource.updateQuery(search, sharedPrefsManager.getFilterWhenSearchingUsers().value) | |
} | |
// ... | |
// UTILS --- | |
private fun pagedListConfig() = PagedList.Config.Builder() | |
.setInitialLoadSizeHint(5) | |
.setEnablePlaceholders(false) | |
.setPageSize(5 * 2) | |
.build() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment