0
0
mirror of https://github.com/mediathekview/zapp.git synced 2024-09-19 20:02:17 +02:00

Removed duplicate entries when scrolling the mediathek list #279

This commit is contained in:
Christine Coenen 2024-04-14 11:48:20 +02:00
parent a7323c7642
commit b29c970865
2 changed files with 8 additions and 16 deletions

View File

@ -17,17 +17,8 @@ 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> {
@ -35,22 +26,20 @@ class MediathekPagingSource(
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.

View File

@ -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