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

View File

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