Skip to content

Commit

Permalink
Removed duplicate entries when scrolling the mediathek list #279
Browse files Browse the repository at this point in the history
  • Loading branch information
cemrich committed Apr 14, 2024
1 parent a7323c7 commit b29c970
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,29 @@ class MediathekPagingSource(
) : PagingSource<Int, MediathekShow>() {

override fun getRefreshKey(state: PagingState<Int, MediathekShow>): Int? {
// Try to find the page key of the closest page to anchorPosition, from
// either the prevKey or the nextKey, but you need to handle nullability
// here:
// * prevKey == null -> anchorPage is the first page.
// * nextKey == null -> anchorPage is the last page.
// * both prevKey and nextKey null -> anchorPage is the initial page, so
// just return null.
return state.anchorPosition?.let { anchorPosition ->
val anchorPage = state.closestPageToPosition(anchorPosition)
anchorPage?.prevKey?.plus(1) ?: anchorPage?.nextKey?.minus(1)
}
return ((state.anchorPosition ?: 0) - state.config.initialLoadSize / 2)
.coerceAtLeast(0)
}

override suspend fun load(params: LoadParams<Int>): LoadResult<Int, MediathekShow> {

queryInfoResultPublisher.emit(null)

return try {
// Start refresh at page 1 if undefined.
val nextPageNumber = params.key ?: 1
query.size = params.loadSize
query.offset = nextPageNumber.minus(1) * params.loadSize
query.offset = params.key ?: 0

val response = mediathekApi.listShows(query)

val showList = response.result?.results ?: throw Error(response.err)
val nextKey = if (showList.isEmpty()) null else nextPageNumber.plus(1)
val nextOffset = if (showList.size < query.size) null else query.offset + query.size

queryInfoResultPublisher.emit(response.result.queryInfo)

LoadResult.Page(
data = showList,
prevKey = null, // Only paging forward.
nextKey = nextKey
nextKey = nextOffset
)
} catch (e: IOException) {
// IOException for network failures.
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/raw/changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# v-next
* Duplikate beim Scrollen in der Mediathek-Liste entfernt

# 8.5.1
* Dynamische Farben wurden auf manchen Geräten nicht übernommen

Expand Down

0 comments on commit b29c970

Please sign in to comment.