Use the same strategy as gallery detail preview

This commit is contained in:
FooIbar authored and tarsin committed 2023-04-04 12:11:34 +08:00
1 parent 5b44df4476
commit 3bb4772aea
3 files changed
+8 -14

No files matched your search

@@ -26,6 +26,7 @@ import com.hippo.ehviewer.EhApplication.Companion.application
import com.hippo.ehviewer.client.data.FavListUrlBuilder
import com.hippo.ehviewer.ui.scene.GalleryListScene
import com.hippo.unifile.UniFile
import com.hippo.yorozuya.LayoutUtils.dp2pix
import com.hippo.yorozuya.NumberUtils
import java.util.Locale
@@ -367,16 +368,11 @@ object Settings {
else -> throw IllegalStateException("Unexpected value: $detailSize")
}
val thumbSize: Int
get() = dip2px(getInt(KEY_THUMB_SIZE, DEFAULT_THUMB_SIZE))
get() = dp2pix(application, getInt(KEY_THUMB_SIZE, DEFAULT_THUMB_SIZE).toFloat())
val thumbSizeDp: Dp
get() = getInt(KEY_THUMB_SIZE, DEFAULT_THUMB_SIZE).dp
private fun dip2px(dpValue: Int): Int {
val scale = application.resources.displayMetrics.density
return (dpValue * scale + 0.5f).toInt()
}
val thumbResolution: Int
get() = getIntFromStr(KEY_THUMB_RESOLUTION, DEFAULT_THUMB_RESOLUTION)
val showComments: Boolean
@@ -31,7 +31,6 @@ import com.hippo.ehviewer.databinding.ItemGalleryGridBinding
import com.hippo.ehviewer.databinding.ItemGalleryListBinding
import com.hippo.widget.recyclerview.AutoStaggeredGridLayoutManager
import com.hippo.widget.recyclerview.STRATEGY_MIN_SIZE
import com.hippo.widget.recyclerview.STRATEGY_SUITABLE_SIZE
import com.hippo.yorozuya.ViewUtils
internal abstract class GalleryAdapter(
@@ -60,6 +59,7 @@ internal abstract class GalleryAdapter(
}
mType = type
val recyclerView = mRecyclerView
@SuppressLint("NotifyDataSetChanged")
when (type) {
TYPE_LIST -> {
val columnWidth = mResources.getDimensionPixelOffset(Settings.detailSizeResId)
@@ -85,7 +85,7 @@ internal abstract class GalleryAdapter(
TYPE_GRID -> {
val columnWidth = Settings.thumbSize
mLayoutManager.setColumnSize(columnWidth)
mLayoutManager.setStrategy(STRATEGY_SUITABLE_SIZE)
mLayoutManager.setStrategy(STRATEGY_MIN_SIZE)
if (null != mListDecoration) {
recyclerView.removeItemDecoration(mListDecoration!!)
}
@@ -40,8 +40,7 @@ import com.hippo.ehviewer.databinding.SceneGalleryPreviewsBinding
import com.hippo.util.getParcelableCompat
import com.hippo.widget.ContentLayout.ContentHelper
import com.hippo.widget.recyclerview.AutoGridLayoutManager
import com.hippo.widget.recyclerview.STRATEGY_SUITABLE_SIZE
import com.hippo.yorozuya.LayoutUtils
import com.hippo.widget.recyclerview.STRATEGY_MIN_SIZE
import eu.kanade.tachiyomi.util.lang.launchIO
import java.util.Locale
@@ -98,12 +97,11 @@ class GalleryPreviewsScene : BaseToolbarScene() {
}
binding.contentLayout.recyclerView.adapter = mAdapter
val columnWidth = Settings.thumbSize
val layoutManager =
AutoGridLayoutManager(context, columnWidth, LayoutUtils.dp2pix(context, 16f))
layoutManager.setStrategy(STRATEGY_SUITABLE_SIZE)
val layoutManager = AutoGridLayoutManager(context, columnWidth)
layoutManager.setStrategy(STRATEGY_MIN_SIZE)
binding.contentLayout.recyclerView.layoutManager = layoutManager
binding.contentLayout.recyclerView.clipToPadding = false
val padding = LayoutUtils.dp2pix(context, 4f)
val padding = resources.getDimensionPixelSize(R.dimen.gallery_grid_margin_h)
val decoration = MarginItemDecoration(padding, padding, padding, padding, padding)
binding.contentLayout.recyclerView.addItemDecoration(decoration)
mHelper = GalleryPreviewHelper()