Fix chapters grid view
This commit is contained in:
@@ -24,7 +24,7 @@ fun chapterGridItemAD(
|
|||||||
|
|
||||||
bind { payloads ->
|
bind { payloads ->
|
||||||
if (payloads.isEmpty()) {
|
if (payloads.isEmpty()) {
|
||||||
binding.textViewTitle.text = item.chapter.formatNumber()
|
binding.textViewTitle.text = item.chapter.formatNumber() ?: "?"
|
||||||
}
|
}
|
||||||
binding.imageViewNew.isVisible = item.isNew
|
binding.imageViewNew.isVisible = item.isNew
|
||||||
binding.imageViewCurrent.isVisible = item.isCurrent
|
binding.imageViewCurrent.isVisible = item.isCurrent
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import android.view.View
|
|||||||
import androidx.recyclerview.widget.GridLayoutManager
|
import androidx.recyclerview.widget.GridLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
|
import org.koitharu.kotatsu.list.ui.adapter.ListItemType
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
class ChapterGridSpanHelper private constructor() : View.OnLayoutChangeListener {
|
class ChapterGridSpanHelper private constructor() : View.OnLayoutChangeListener {
|
||||||
@@ -29,6 +30,22 @@ class ChapterGridSpanHelper private constructor() : View.OnLayoutChangeListener
|
|||||||
(rv.layoutManager as? GridLayoutManager)?.spanCount = getSpanCount(rv)
|
(rv.layoutManager as? GridLayoutManager)?.spanCount = getSpanCount(rv)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class SpanSizeLookup(
|
||||||
|
private val recyclerView: RecyclerView
|
||||||
|
) : GridLayoutManager.SpanSizeLookup() {
|
||||||
|
|
||||||
|
override fun getSpanSize(position: Int): Int {
|
||||||
|
return when (recyclerView.adapter?.getItemViewType(position)) {
|
||||||
|
ListItemType.CHAPTER_LIST.ordinal, // for smooth transition
|
||||||
|
ListItemType.HEADER.ordinal -> getTotalSpans()
|
||||||
|
|
||||||
|
else -> 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getTotalSpans() = (recyclerView.layoutManager as? GridLayoutManager)?.spanCount ?: 1
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
fun attach(view: RecyclerView) {
|
fun attach(view: RecyclerView) {
|
||||||
|
|||||||
@@ -66,7 +66,9 @@ class ChaptersFragment :
|
|||||||
)
|
)
|
||||||
viewModel.isChaptersInGridView.observe(viewLifecycleOwner) { chaptersInGridView ->
|
viewModel.isChaptersInGridView.observe(viewLifecycleOwner) { chaptersInGridView ->
|
||||||
binding.recyclerViewChapters.layoutManager = if (chaptersInGridView) {
|
binding.recyclerViewChapters.layoutManager = if (chaptersInGridView) {
|
||||||
GridLayoutManager(context, ChapterGridSpanHelper.getSpanCount(binding.recyclerViewChapters))
|
GridLayoutManager(context, ChapterGridSpanHelper.getSpanCount(binding.recyclerViewChapters)).apply {
|
||||||
|
spanSizeLookup = ChapterGridSpanHelper.SpanSizeLookup(binding.recyclerViewChapters)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
LinearLayoutManager(context)
|
LinearLayoutManager(context)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,4 +86,5 @@ class TypedListSpacingDecoration(
|
|||||||
|| this == ListItemType.FILTER_SORT
|
|| this == ListItemType.FILTER_SORT
|
||||||
|| this == ListItemType.FILTER_TAG
|
|| this == ListItemType.FILTER_TAG
|
||||||
|| this == ListItemType.CHAPTER_LIST
|
|| this == ListItemType.CHAPTER_LIST
|
||||||
|
|| this == ListItemType.CHAPTER_GRID
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,7 +93,9 @@ class ChaptersSheet : BaseAdaptiveSheet<SheetChaptersBinding>(),
|
|||||||
}
|
}
|
||||||
ChapterGridSpanHelper.attach(binding.recyclerView)
|
ChapterGridSpanHelper.attach(binding.recyclerView)
|
||||||
binding.recyclerView.layoutManager = if (settings.isChaptersGridView) {
|
binding.recyclerView.layoutManager = if (settings.isChaptersGridView) {
|
||||||
GridLayoutManager(context, ChapterGridSpanHelper.getSpanCount(binding.recyclerView))
|
GridLayoutManager(context, ChapterGridSpanHelper.getSpanCount(binding.recyclerView)).apply {
|
||||||
|
spanSizeLookup = ChapterGridSpanHelper.SpanSizeLookup(binding.recyclerView)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
LinearLayoutManager(context)
|
LinearLayoutManager(context)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user