From 3bb4772aeae625fbf442ebf1142e7ee6053eecbb Mon Sep 17 00:00:00 2001 From: FooIbar <118464521+FooIbar@users.noreply.github.com> Date: Tue, 4 Apr 2023 09:03:05 +0800 Subject: [PATCH] Use the same strategy as gallery detail preview --- app/src/main/java/com/hippo/ehviewer/Settings.kt | 8 ++------ .../java/com/hippo/ehviewer/ui/scene/GalleryAdapter.kt | 4 ++-- .../hippo/ehviewer/ui/scene/GalleryPreviewsScene.kt | 10 ++++------ 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/com/hippo/ehviewer/Settings.kt b/app/src/main/java/com/hippo/ehviewer/Settings.kt index 83472f787..3c905dfac 100755 --- a/app/src/main/java/com/hippo/ehviewer/Settings.kt +++ b/app/src/main/java/com/hippo/ehviewer/Settings.kt @@ -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 diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryAdapter.kt b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryAdapter.kt index f0f9537c1..9e8b1fdcd 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryAdapter.kt +++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryAdapter.kt @@ -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!!) } diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryPreviewsScene.kt b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryPreviewsScene.kt index 2c775a806..dc05bf5e5 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryPreviewsScene.kt +++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/GalleryPreviewsScene.kt @@ -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()