Skip to content

Instantly share code, notes, and snippets.

@edujtm
Last active March 6, 2019 00:09
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 edujtm/c831916f8b5abd2095ef9a9b01d56d0d to your computer and use it in GitHub Desktop.
Save edujtm/c831916f8b5abd2095ef9a9b01d56d0d to your computer and use it in GitHub Desktop.
The BoundaryCallback example from the Google talk on the Android Paging Library for future reference.
class ItemBoundaryCallback(private val service: MyApi,
private val database: MyDatabase) : PagedList.BoundaryCallback<Item> {
val isLoading = false
override fun onItemAtEndLoaded(itemAtEnd: Item) {
if (isLoading) return
isLoading = true
networkExecutor.execute {
val response = service
.getTopAfter(itemAtEnd.name, NETWORK_PAGE_SIZE)
.execute()
if (response.isSucessful) {
ioExecutor.execute {
database.dao().insert(response.body())
isLoading = false
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment