pager: do not skip first batch of packages + fix indexoutofbound exception

This commit is contained in:
Rahul Patel
2026-05-06 03:15:10 +05:30
parent 49718f8723
commit 1484e0f24b
2 changed files with 6 additions and 6 deletions

View File

@@ -8,6 +8,7 @@ package com.aurora.store.data.paging
import androidx.paging.Pager
import androidx.paging.PagingConfig
import androidx.paging.PagingSource
import androidx.paging.PagingSource.LoadResult.Page.Companion.COUNT_UNDEFINED
import androidx.paging.PagingState
import com.aurora.store.data.paging.GenericPagingSource.Companion.manualPager
import com.aurora.store.data.paging.GenericPagingSource.Companion.pager
@@ -65,12 +66,11 @@ class GenericPagingSource<T : Any>(
return try {
withContext(Dispatchers.IO) {
val data = block(page)
val totalPages = if (data.isNotEmpty()) page + 1 else page
LoadResult.Page(
data = data,
prevKey = if (page == 1) null else page - 1,
nextKey = if (page == totalPages) null else totalPages,
itemsAfter = if (page == totalPages) 0 else DEFAULT_PAGE_SIZE
nextKey = if (data.isEmpty()) null else page + 1,
itemsAfter = if (data.isEmpty()) 0 else COUNT_UNDEFINED
)
}
} catch (exception: Exception) {

View File

@@ -64,9 +64,9 @@ class InstalledViewModel @Inject constructor(
manualPager { page ->
try {
webAppDetailsHelper.getAppDetails(
pagedPackages[page].map { it.packageName }
)
// page is 1-indexed, but list is 0-indexed
val chunk = pagedPackages.getOrNull(page - 1) ?: return@manualPager emptyList()
webAppDetailsHelper.getAppDetails(chunk.map { it.packageName })
} catch (exception: Exception) {
Log.e(TAG, "Failed to fetch apps", exception)
emptyList()