Grab some RestrictedApi to make lint happy
This commit is contained in:
1 parent
f5a9a41790
commit
14810b4c2c
2 files changed
+24
-3
No files matched your search
@@ -35,9 +35,6 @@ import androidx.paging.cachedIn
|
||||
import androidx.paging.compose.collectAsLazyPagingItems
|
||||
import androidx.paging.compose.itemContentType
|
||||
import androidx.paging.compose.itemKey
|
||||
import androidx.room.paging.util.getClippedRefreshKey
|
||||
import androidx.room.paging.util.getLimit
|
||||
import androidx.room.paging.util.getOffset
|
||||
import arrow.fx.coroutines.parMap
|
||||
import coil3.imageLoader
|
||||
import com.hippo.ehviewer.R
|
||||
@@ -54,6 +51,9 @@ import com.hippo.ehviewer.ui.main.EhPreviewItem
|
||||
import com.hippo.ehviewer.ui.navToReader
|
||||
import com.hippo.ehviewer.ui.tools.FastScrollLazyVerticalGrid
|
||||
import com.hippo.ehviewer.ui.tools.foldToLoadResult
|
||||
import com.hippo.ehviewer.ui.tools.getClippedRefreshKey
|
||||
import com.hippo.ehviewer.ui.tools.getLimit
|
||||
import com.hippo.ehviewer.ui.tools.getOffset
|
||||
import com.hippo.ehviewer.ui.tools.rememberInVM
|
||||
import com.ramcosta.composedestinations.annotation.Destination
|
||||
import eu.kanade.tachiyomi.util.lang.withIOContext
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
package com.hippo.ehviewer.ui.tools
|
||||
|
||||
import androidx.paging.PagingSource.LoadParams
|
||||
import androidx.paging.PagingSource.LoadParams.Append
|
||||
import androidx.paging.PagingSource.LoadParams.Prepend
|
||||
import androidx.paging.PagingSource.LoadParams.Refresh
|
||||
import androidx.paging.PagingSource.LoadResult
|
||||
import androidx.paging.PagingState
|
||||
|
||||
inline fun <K : Any, V : Any, R : LoadResult.Page<K, V>, T> Result<T>.foldToLoadResult(
|
||||
onSuccess: (value: T) -> R,
|
||||
@@ -8,3 +13,19 @@ inline fun <K : Any, V : Any, R : LoadResult.Page<K, V>, T> Result<T>.foldToLoad
|
||||
onSuccess = onSuccess,
|
||||
onFailure = { LoadResult.Error(it) },
|
||||
)
|
||||
|
||||
fun <Value : Any> PagingState<Int, Value>.getClippedRefreshKey() = when (val anchorPosition = anchorPosition) {
|
||||
null -> null
|
||||
else -> maxOf(0, anchorPosition - (config.initialLoadSize / 2))
|
||||
}
|
||||
|
||||
fun getOffset(params: LoadParams<Int>, key: Int, itemCount: Int) = when (params) {
|
||||
is Prepend -> if (key < params.loadSize) 0 else key - params.loadSize
|
||||
is Append -> key
|
||||
is Refresh -> if (key >= itemCount) maxOf(0, itemCount - params.loadSize) else key
|
||||
}
|
||||
|
||||
fun getLimit(params: LoadParams<Int>, key: Int) = when (params) {
|
||||
is Prepend -> if (key < params.loadSize) key else params.loadSize
|
||||
else -> params.loadSize
|
||||
}
|
||||
Reference in new issue
Block a user