Introduce calculateSuitableSpanCount
This commit is contained in:
1 parent
22d5832ba2
commit
c3facb9787
3 files changed
+13
-10
No files matched your search
@@ -102,7 +102,6 @@ import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.input.nestedscroll.nestedScroll
|
||||
import androidx.compose.ui.layout.LocalPinnableContainer
|
||||
import androidx.compose.ui.platform.ComposeView
|
||||
import androidx.compose.ui.platform.LocalConfiguration
|
||||
import androidx.compose.ui.res.dimensionResource
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
@@ -173,7 +172,7 @@ import com.hippo.util.addTextToClipboard
|
||||
import com.hippo.util.getParcelableCompat
|
||||
import com.hippo.util.getSystemService
|
||||
import com.hippo.widget.ObservedTextView
|
||||
import com.hippo.widget.recyclerview.getSpanCountForSuitableSize
|
||||
import com.hippo.widget.recyclerview.calculateSuitableSpanCount
|
||||
import com.hippo.yorozuya.FileUtils
|
||||
import com.hippo.yorozuya.ViewUtils
|
||||
import com.hippo.yorozuya.collect.IntList
|
||||
@@ -527,9 +526,7 @@ class GalleryDetailScene : BaseScene(), DownloadInfoListener {
|
||||
composeBindingGD?.let { if (showSheet) GalleryInfoBottomSheet(galleryDetail = it) { showSheet = false } }
|
||||
}
|
||||
val windowSizeClass = calculateWindowSizeClass(requireActivity())
|
||||
// Padding is not subtracted here to have the same column count as gallery list and preview
|
||||
val totalSpace = LocalConfiguration.current.screenWidthDp
|
||||
val columnCount = getSpanCountForSuitableSize(totalSpace, Settings.thumbSizeDp)
|
||||
val columnCount = calculateSuitableSpanCount()
|
||||
when (windowSizeClass.widthSizeClass) {
|
||||
WindowWidthSizeClass.Medium, WindowWidthSizeClass.Compact -> LazyVerticalGrid(
|
||||
columns = GridCells.Fixed(columnCount),
|
||||
|
||||
@@ -32,7 +32,6 @@ import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.input.nestedscroll.nestedScroll
|
||||
import androidx.compose.ui.platform.ComposeView
|
||||
import androidx.compose.ui.platform.LocalConfiguration
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.dimensionResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
@@ -61,7 +60,7 @@ import com.hippo.ehviewer.ui.widget.EhPreviewItem
|
||||
import com.hippo.ehviewer.ui.widget.rememberDialogState
|
||||
import com.hippo.ehviewer.ui.widget.setMD3Content
|
||||
import com.hippo.util.getParcelableCompat
|
||||
import com.hippo.widget.recyclerview.getSpanCountForSuitableSize
|
||||
import com.hippo.widget.recyclerview.calculateSuitableSpanCount
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import moe.tarsin.coroutines.runSuspendCatching
|
||||
@@ -78,9 +77,7 @@ class GalleryPreviewScreen : Fragment() {
|
||||
fun onPreviewCLick(index: Int) = context.navToReader(galleryDetail, index)
|
||||
val toNextPage = rememberSaveable { requireArguments().getBoolean(KEY_NEXT_PAGE) }
|
||||
val scrollBehaviour = TopAppBarDefaults.pinnedScrollBehavior()
|
||||
// Padding is not subtracted here to have the same column count as gallery list and preview
|
||||
val totalSpace = LocalConfiguration.current.screenWidthDp
|
||||
val columnCount = getSpanCountForSuitableSize(totalSpace, Settings.thumbSizeDp)
|
||||
val columnCount = calculateSuitableSpanCount()
|
||||
val state = rememberLazyGridState()
|
||||
val dialogState = rememberDialogState()
|
||||
dialogState.Handler()
|
||||
|
||||
@@ -16,8 +16,11 @@
|
||||
package com.hippo.widget.recyclerview
|
||||
|
||||
import android.view.View
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.platform.LocalConfiguration
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import androidx.recyclerview.widget.StaggeredGridLayoutManager
|
||||
import com.hippo.ehviewer.Settings
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
class AutoStaggeredGridLayoutManager(columnSize: Int, orientation: Int) :
|
||||
@@ -98,6 +101,12 @@ fun getSpanCountForSuitableSize(total: Int, single: Int): Int {
|
||||
return (total / single.toFloat()).roundToInt().coerceAtLeast(1)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun calculateSuitableSpanCount(): Int {
|
||||
val totalSpace = LocalConfiguration.current.screenWidthDp
|
||||
return getSpanCountForSuitableSize(totalSpace, Settings.thumbSizeDp)
|
||||
}
|
||||
|
||||
fun getSpanCountForMinSize(total: Int, single: Int): Int {
|
||||
return (total / single).coerceAtLeast(1)
|
||||
}
|
||||
Reference in new issue
Block a user