Skip to content

Commit

Permalink
Add possibility to not display DividerItemDecorator depending on the …
Browse files Browse the repository at this point in the history
…view tag
  • Loading branch information
KevinBoulongne committed Feb 1, 2024
1 parent cd57493 commit be77772
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package com.infomaniak.lib.core.views
import android.graphics.Canvas
import android.graphics.drawable.Drawable
import androidx.core.view.children
import androidx.core.view.get
import androidx.recyclerview.widget.RecyclerView
import kotlin.math.roundToInt

Expand All @@ -32,8 +33,14 @@ class DividerItemDecorator(private val divider: Drawable) : RecyclerView.ItemDec
val dividerLeft = parent.paddingLeft
val dividerRight = parent.width - parent.paddingRight

parent.children.forEach { child ->
if (child.y == firstChildY) return@forEach
parent.children.forEachIndexed { index, child ->

if (child.y == firstChildY ||
child.tag == SUPER_COLLAPSED_BLOCK_TAG ||
parent[index - 1].tag == SUPER_COLLAPSED_BLOCK_TAG
) {
return@forEachIndexed
}

val yTranslation = child.translationY.roundToInt()
val dividerTop = child.top - (child.layoutParams as RecyclerView.LayoutParams).topMargin + yTranslation
Expand All @@ -42,4 +49,8 @@ class DividerItemDecorator(private val divider: Drawable) : RecyclerView.ItemDec
divider.draw(canvas)
}
}

companion object {
private const val SUPER_COLLAPSED_BLOCK_TAG = "SuperCollapsedBlock"
}
}

0 comments on commit be77772

Please sign in to comment.