Skip to content

Commit fd64ca6

Browse files
authored
Merge pull request #225 from tunjid/fix-paging-source
Fix unresolved use of ITEMS_PER_PAGE
2 parents 8d21579 + 2e39054 commit fd64ca6

2 files changed

Lines changed: 2 additions & 3 deletions

File tree

basic/end/app/src/main/java/com/example/android/codelabs/paging/data/ArticlePagingSource.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ class ArticlePagingSource : PagingSource<Int, Article>() {
6868
// The refresh key is used for the initial load of the next PagingSource, after invalidation
6969
override fun getRefreshKey(state: PagingState<Int, Article>): Int? {
7070
// In our case we grab the item closest to the anchor position
71-
// then return its id - ITEMS_PER_PAGE as a buffer
71+
// then return its id - (state.config.pageSize / 2) as a buffer
7272
val anchorPosition = state.anchorPosition ?: return null
7373
val article = state.closestItemToPosition(anchorPosition) ?: return null
74-
return ensureValidKey(key = article.id - ITEMS_PER_PAGE)
74+
return ensureValidKey(key = article.id - (state.config.pageSize / 2))
7575
}
7676

7777
/**

basic/end/app/src/main/java/com/example/android/codelabs/paging/ui/ArticleViewModel.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import androidx.paging.PagingData
2424
import androidx.paging.cachedIn
2525
import com.example.android.codelabs.paging.data.Article
2626
import com.example.android.codelabs.paging.data.ArticleRepository
27-
import com.example.android.codelabs.paging.data.ITEMS_PER_PAGE
2827
import kotlinx.coroutines.flow.Flow
2928

3029
private const val ITEMS_PER_PAGE = 50

0 commit comments

Comments
 (0)