Unify list spacing approach

This commit is contained in:
Koitharu
2023-07-26 16:37:53 +03:00
parent 61a7f1c830
commit 2342594885
25 changed files with 166 additions and 327 deletions

View File

@@ -16,7 +16,6 @@ import org.koitharu.kotatsu.core.model.parcelable.ParcelableManga
import org.koitharu.kotatsu.core.prefs.AppSettings
import org.koitharu.kotatsu.core.ui.list.BoundsScrollListener
import org.koitharu.kotatsu.core.ui.list.OnListItemClickListener
import org.koitharu.kotatsu.core.ui.list.decor.SpacingItemDecoration
import org.koitharu.kotatsu.core.ui.sheet.AdaptiveSheetBehavior
import org.koitharu.kotatsu.core.ui.sheet.AdaptiveSheetCallback
import org.koitharu.kotatsu.core.ui.sheet.BaseAdaptiveSheet
@@ -29,6 +28,8 @@ import org.koitharu.kotatsu.core.util.ext.showDistinct
import org.koitharu.kotatsu.core.util.ext.withArgs
import org.koitharu.kotatsu.databinding.SheetPagesBinding
import org.koitharu.kotatsu.list.ui.MangaListSpanResolver
import org.koitharu.kotatsu.list.ui.adapter.ListItemType
import org.koitharu.kotatsu.list.ui.adapter.TypedListSpacingDecoration
import org.koitharu.kotatsu.list.ui.model.ListModel
import org.koitharu.kotatsu.parsers.model.Manga
import org.koitharu.kotatsu.reader.ui.ReaderActivity.IntentBuilder
@@ -74,9 +75,7 @@ class PagesThumbnailsSheet :
clickListener = this@PagesThumbnailsSheet,
)
with(binding.recyclerView) {
addItemDecoration(
SpacingItemDecoration(resources.getDimensionPixelOffset(R.dimen.grid_spacing)),
)
addItemDecoration(TypedListSpacingDecoration(context))
adapter = thumbnailsAdapter
addOnLayoutChangeListener(spanResolver)
spanResolver?.setGridSize(settings.gridSize / 100f, this)
@@ -171,7 +170,7 @@ class PagesThumbnailsSheet :
override fun getSpanSize(position: Int): Int {
val total = (viewBinding?.recyclerView?.layoutManager as? GridLayoutManager)?.spanCount ?: return 1
return when (thumbnailsAdapter?.getItemViewType(position)) {
PageThumbnailAdapter.ITEM_TYPE_THUMBNAIL -> 1
ListItemType.PAGE_THUMB.ordinal -> 1
else -> total
}
}

View File

@@ -6,6 +6,7 @@ import coil.ImageLoader
import org.koitharu.kotatsu.core.ui.BaseListAdapter
import org.koitharu.kotatsu.core.ui.list.OnListItemClickListener
import org.koitharu.kotatsu.core.ui.list.fastscroll.FastScroller
import org.koitharu.kotatsu.list.ui.adapter.ListItemType
import org.koitharu.kotatsu.list.ui.adapter.listHeaderAD
import org.koitharu.kotatsu.list.ui.adapter.loadingFooterAD
import org.koitharu.kotatsu.list.ui.model.ListHeader
@@ -19,9 +20,9 @@ class PageThumbnailAdapter(
) : BaseListAdapter<ListModel>(), FastScroller.SectionIndexer {
init {
delegatesManager.addDelegate(ITEM_TYPE_THUMBNAIL, pageThumbnailAD(coil, lifecycleOwner, clickListener))
.addDelegate(ITEM_TYPE_HEADER, listHeaderAD(null))
.addDelegate(ITEM_LOADING, loadingFooterAD())
addDelegate(ListItemType.PAGE_THUMB, pageThumbnailAD(coil, lifecycleOwner, clickListener))
addDelegate(ListItemType.HEADER, listHeaderAD(null))
addDelegate(ListItemType.FOOTER_LOADING, loadingFooterAD())
}
override fun getSectionText(context: Context, position: Int): CharSequence? {
@@ -34,11 +35,4 @@ class PageThumbnailAdapter(
}
return null
}
companion object {
const val ITEM_TYPE_THUMBNAIL = 0
const val ITEM_TYPE_HEADER = 1
const val ITEM_LOADING = 2
}
}