Skip to content
This repository has been archived by the owner on Dec 9, 2024. It is now read-only.

Commit

Permalink
Fix unresolved use of ITEMS_PER_PAGE
Browse files Browse the repository at this point in the history
Change-Id: I5f4ebe8700b28c17ec92532c84a8d6fefa714f75
  • Loading branch information
tunjid committed May 23, 2022
1 parent 8d21579 commit 2e39054
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ class ArticlePagingSource : PagingSource<Int, Article>() {
// The refresh key is used for the initial load of the next PagingSource, after invalidation
override fun getRefreshKey(state: PagingState<Int, Article>): Int? {
// In our case we grab the item closest to the anchor position
// then return its id - ITEMS_PER_PAGE as a buffer
// then return its id - (state.config.pageSize / 2) as a buffer
val anchorPosition = state.anchorPosition ?: return null
val article = state.closestItemToPosition(anchorPosition) ?: return null
return ensureValidKey(key = article.id - ITEMS_PER_PAGE)
return ensureValidKey(key = article.id - (state.config.pageSize / 2))
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import androidx.paging.PagingData
import androidx.paging.cachedIn
import com.example.android.codelabs.paging.data.Article
import com.example.android.codelabs.paging.data.ArticleRepository
import com.example.android.codelabs.paging.data.ITEMS_PER_PAGE
import kotlinx.coroutines.flow.Flow

private const val ITEMS_PER_PAGE = 50
Expand Down

0 comments on commit 2e39054

Please sign in to comment.