|
@@ -0,0 +1,60 @@
|
|
|
+package eu.kanade.tachiyomi.ui.manga.chapter
|
|
|
+
|
|
|
+import android.content.Context
|
|
|
+import android.graphics.Canvas
|
|
|
+import android.graphics.Rect
|
|
|
+import android.graphics.drawable.Drawable
|
|
|
+import android.view.View
|
|
|
+import androidx.recyclerview.widget.RecyclerView
|
|
|
+
|
|
|
+/**
|
|
|
+ * Mimics a DividerItemDecoration that doesn't draw between the first two items.
|
|
|
+ *
|
|
|
+ * Used in MangaController since the manga info header and chapters header are the first two
|
|
|
+ * items in the list using a ConcatAdapter.
|
|
|
+ */
|
|
|
+class ChapterDividerItemDecoration(context: Context) : RecyclerView.ItemDecoration() {
|
|
|
+
|
|
|
+ private val divider: Drawable
|
|
|
+
|
|
|
+ init {
|
|
|
+ val a = context.obtainStyledAttributes(intArrayOf(android.R.attr.listDivider))
|
|
|
+ divider = a.getDrawable(0)!!
|
|
|
+ a.recycle()
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onDraw(canvas: Canvas, parent: RecyclerView, state: RecyclerView.State) {
|
|
|
+ if (parent.layoutManager == null) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ canvas.save()
|
|
|
+ val childCount = parent.childCount
|
|
|
+ for (i in 1 until childCount) {
|
|
|
+ val child = parent.getChildAt(i)
|
|
|
+ val params = child.layoutParams as RecyclerView.LayoutParams
|
|
|
+ val top = child.bottom + params.bottomMargin
|
|
|
+ val bottom = top + divider.intrinsicHeight
|
|
|
+ val left = parent.paddingStart
|
|
|
+ val right = parent.width - parent.paddingEnd
|
|
|
+ divider.setBounds(left, top, right, bottom)
|
|
|
+ divider.draw(canvas)
|
|
|
+ }
|
|
|
+ canvas.restore()
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun getItemOffsets(
|
|
|
+ outRect: Rect,
|
|
|
+ view: View,
|
|
|
+ parent: RecyclerView,
|
|
|
+ state: RecyclerView.State
|
|
|
+ ) {
|
|
|
+ val position = parent.getChildAdapterPosition(view)
|
|
|
+
|
|
|
+ if (position == 0) {
|
|
|
+ outRect.setEmpty()
|
|
|
+ } else {
|
|
|
+ outRect.set(0, 0, 0, divider.intrinsicHeight)
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|