Skip to content

Instantly share code, notes, and snippets.

@CristianMG
Last active June 8, 2019 08:44
Show Gist options
  • Select an option

  • Save CristianMG/359981aab5c466ead3c929172e3eadc0 to your computer and use it in GitHub Desktop.

Select an option

Save CristianMG/359981aab5c466ead3c929172e3eadc0 to your computer and use it in GitHub Desktop.
Android paging Network + Database 4 snippet
/**
* For a clean architecture
* encapsulated all methods for paginate in this class
*
* For more information
* @see https://github.com/googlesamples/android-architecture-components/blob/master/PagingWithNetworkSample
**/
interface Listing<T> {
fun getBoundaryCallback(): LiveData<GenericBoundaryCallback<T>>
fun getDataSource(): LiveData<PagedList<CharacterModel>>
fun getNetworkState(): LiveData<NetworkState> = Transformations.switchMap(getBoundaryCallback()) { it.networkState }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment