Browse Source

Remove divider between manga info header and chapters header

arkon 4 years ago
parent
commit
c37377bffa

+ 2 - 2
app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaController.kt

@@ -14,7 +14,6 @@ import android.view.ViewGroup
 import androidx.appcompat.app.AppCompatActivity
 import androidx.appcompat.view.ActionMode
 import androidx.recyclerview.widget.ConcatAdapter
-import androidx.recyclerview.widget.DividerItemDecoration
 import androidx.recyclerview.widget.LinearLayoutManager
 import androidx.recyclerview.widget.RecyclerView
 import com.bluelinelabs.conductor.ControllerChangeHandler
@@ -47,6 +46,7 @@ import eu.kanade.tachiyomi.ui.library.ChangeMangaCoverDialog
 import eu.kanade.tachiyomi.ui.library.LibraryController
 import eu.kanade.tachiyomi.ui.main.MainActivity
 import eu.kanade.tachiyomi.ui.main.offsetAppbarHeight
+import eu.kanade.tachiyomi.ui.manga.chapter.ChapterDividerItemDecoration
 import eu.kanade.tachiyomi.ui.manga.chapter.ChapterHolder
 import eu.kanade.tachiyomi.ui.manga.chapter.ChapterItem
 import eu.kanade.tachiyomi.ui.manga.chapter.ChaptersAdapter
@@ -187,7 +187,7 @@ class MangaController :
 
         binding.recycler.adapter = ConcatAdapter(mangaInfoAdapter, chaptersHeaderAdapter, chaptersAdapter)
         binding.recycler.layoutManager = LinearLayoutManager(view.context)
-        binding.recycler.addItemDecoration(DividerItemDecoration(view.context, DividerItemDecoration.VERTICAL))
+        binding.recycler.addItemDecoration(ChapterDividerItemDecoration(view.context))
         binding.recycler.setHasFixedSize(true)
         chaptersAdapter?.fastScroller = binding.fastScroller
 

+ 60 - 0
app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChapterDividerItemDecoration.kt

@@ -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)
+        }
+    }
+}