Skip to content

Instantly share code, notes, and snippets.

@Marchuck
Last active June 14, 2018 13:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Marchuck/e2ad5d5bbccb16d7fda6e6bfeafb4b54 to your computer and use it in GitHub Desktop.
Save Marchuck/e2ad5d5bbccb16d7fda6e6bfeafb4b54 to your computer and use it in GitHub Desktop.
class SwapiPeoplePagedListProvider(private val factory: DataSource.Factory<Int, Person?>) : PagedListProvider<Person?> {
override fun provide(): LiveData<PagedList<Person?>> {
return LivePagedListBuilder(factory, PagedList.Config.Builder()
.setEnablePlaceholders(false)
.setPageSize(20)
.setInitialLoadSizeHint(20)
.build()
).setFetchExecutor(createFetchExecutor())
.build()
}
private fun createFetchExecutor(): ExecutorService {
val threads = Runtime.getRuntime().availableProcessors() + 1
return Executors.newFixedThreadPool(threads)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment