Skip to content

Instantly share code, notes, and snippets.

@tunjid
Created October 19, 2021 14:28
Show Gist options
  • Select an option

  • Save tunjid/7ddfbde1dcd85fe049540d39853f5dd2 to your computer and use it in GitHub Desktop.

Select an option

Save tunjid/7ddfbde1dcd85fe049540d39853f5dd2 to your computer and use it in GitHub Desktop.
override suspend fun load(loadType: LoadType, state: PagingState<Int, Repo>): MediatorResult {
val page = when (loadType) {
LoadType.REFRESH -> …
LoadType.PREPEND -> …
LoadType.APPEND -> …
}
val apiQuery = query + IN_QUALIFIER
try {
val apiResponse = service.searchRepos(apiQuery, page, state.config.pageSize)
val repos = apiResponse.items
val endOfPaginationReached = repos.isEmpty()
repoDatabase.withTransaction {
repoDatabase.reposDao().insertAll(repos)
}
return MediatorResult.Success(endOfPaginationReached = endOfPaginationReached)
} catch (exception: IOException) {
return MediatorResult.Error(exception)
} catch (exception: HttpException) {
return MediatorResult.Error(exception)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment