Last active
March 6, 2019 00:09
-
-
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.
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 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