Skip to content

Instantly share code, notes, and snippets.

@Levi-Moreira
Last active February 13, 2019 12:58
Show Gist options
  • Save Levi-Moreira/60ccfdff9fa709bc46e572bc85b52e55 to your computer and use it in GitHub Desktop.
Save Levi-Moreira/60ccfdff9fa709bc46e572bc85b52e55 to your computer and use it in GitHub Desktop.
class UsersRepository @Inject constructor(
var dataSourceFactory: UsersDataSourceFactory
) {
fun getUsers(): Observable<PagedList<User>> {
val config = PagedList.Config.Builder()
.setInitialLoadSizeHint(SO_PAGE_SIZE)
.setPageSize(SO_PAGE_SIZE)
.build()
val users: Observable<PagedList<User>> =
RxPagedListBuilder(dataSourceFactory, config)
.setInitialLoadKey(1)
.setFetchScheduler(Schedulers.io())
.setNotifyScheduler(AndroidSchedulers.mainThread())
.buildObservable()
return users
}
fun getDataLoadStatus(): Observable<NetworkState> {
return dataSourceFactory.observableEmitter.switchMap { dataSource ->
dataSource.loadState
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment