make sure not to send twice the same key for subsequent pages

This commit is contained in:
Matthieu 2021-06-18 08:47:39 +02:00
parent 8dd1906544
commit 68222c2662
4 changed files with 10 additions and 4 deletions

View File

@ -56,7 +56,7 @@ class FollowersPagingSource(
LoadResult.Page(
data = accounts,
prevKey = null,
nextKey = if (accounts.isEmpty() or nextPosition.isEmpty()) null else nextPosition
nextKey = if (accounts.isEmpty() || nextPosition.isEmpty() || nextPosition == position) null else nextPosition
)
} catch (exception: IOException) {
LoadResult.Error(exception)

View File

@ -25,10 +25,12 @@ class HashTagPagingSource(
max_id = position,
)
val nextKey = response.lastOrNull()?.id
LoadResult.Page(
data = response,
prevKey = null,
nextKey = response.lastOrNull()?.id
nextKey = if(nextKey == position) null else nextKey
)
} catch (exception: HttpException) {
LoadResult.Error(exception)

View File

@ -20,10 +20,12 @@ class ProfilePagingSource(
limit = params.loadSize
)
val nextKey = posts.lastOrNull()?.id
LoadResult.Page(
data = posts,
prevKey = null,
nextKey = posts.lastOrNull()?.id
nextKey = if(nextKey == position) null else nextKey
)
} catch (exception: HttpException) {
LoadResult.Error(exception)

View File

@ -34,10 +34,12 @@ class SearchPagingSource<T: FeedContent>(
Results.SearchType.statuses -> response.statuses
} as List<T>
val nextKey = if (repos.isEmpty()) null else (position ?: 0) + repos.size
LoadResult.Page(
data = repos,
prevKey = null,
nextKey = if (repos.isEmpty()) null else (position ?: 0) + repos.size
nextKey = if(nextKey == position) null else nextKey
)
} catch (exception: HttpException) {
LoadResult.Error(exception)