diff --git a/repos/common/src/main/kotlin/dev/inmo/micro_utils/repos/onetomany/OneToManyAndroidRepo.kt b/repos/common/src/main/kotlin/dev/inmo/micro_utils/repos/onetomany/OneToManyAndroidRepo.kt index d8c4c7d248a..eeda9af65af 100644 --- a/repos/common/src/main/kotlin/dev/inmo/micro_utils/repos/onetomany/OneToManyAndroidRepo.kt +++ b/repos/common/src/main/kotlin/dev/inmo/micro_utils/repos/onetomany/OneToManyAndroidRepo.kt @@ -3,10 +3,7 @@ package dev.inmo.micro_utils.repos.onetomany import android.database.sqlite.SQLiteOpenHelper import androidx.core.content.contentValuesOf import dev.inmo.micro_utils.common.mapNotNullA -import dev.inmo.micro_utils.pagination.FirstPagePagination -import dev.inmo.micro_utils.pagination.Pagination -import dev.inmo.micro_utils.pagination.PaginationResult -import dev.inmo.micro_utils.pagination.createPaginationResult +import dev.inmo.micro_utils.pagination.* import dev.inmo.micro_utils.pagination.utils.reverse import dev.inmo.micro_utils.repos.* import kotlinx.coroutines.flow.Flow @@ -143,6 +140,12 @@ class OneToManyAndroidRepo( pagination: Pagination, reversed: Boolean ): PaginationResult = count(k).let { count -> + if (pagination.firstIndex >= count) { + return@let emptyList().createPaginationResult( + pagination, + count + ) + } val resultPagination = pagination.let { if (reversed) pagination.reverse(count) else pagination } helper.blockingReadableTransaction { select( @@ -169,6 +172,12 @@ class OneToManyAndroidRepo( pagination: Pagination, reversed: Boolean ): PaginationResult = count().let { count -> + if (pagination.firstIndex >= count) { + return@let emptyList().createPaginationResult( + pagination, + count + ) + } val resultPagination = pagination.let { if (reversed) pagination.reverse(count) else pagination } helper.blockingReadableTransaction { select(