Fix pool limits and y-translation issues with CFv2 recycler view.

This commit is contained in:
Cody Henthorne
2023-06-07 12:51:08 -04:00
committed by GitHub
parent d6a03df087
commit 7e0e6c2786
6 changed files with 101 additions and 6 deletions

View File

@@ -1,6 +1,7 @@
package org.thoughtcrime.securesms.giph.mp4
import android.graphics.Canvas
import android.graphics.Rect
import androidx.core.view.children
import androidx.recyclerview.widget.RecyclerView
import org.thoughtcrime.securesms.conversation.ConversationAdapter
@@ -27,18 +28,28 @@ class GiphyMp4ItemDecoration(
parent.translationY = 0f
onRecyclerVerticalTranslationSet(parent.translationY)
} else {
val footerViewHolder = parent.children
val threadHeaderViewHolder = parent.children
.map { parent.getChildViewHolder(it) }
.filter { it is ConversationAdapter.FooterViewHolder || it is ConversationAdapterV2.ThreadHeaderViewHolder }
.firstOrNull()
if (footerViewHolder == null) {
if (threadHeaderViewHolder == null) {
parent.translationY = 0f
onRecyclerVerticalTranslationSet(parent.translationY)
return
}
val childTop: Int = footerViewHolder.itemView.top
val toolbarMargin = if (threadHeaderViewHolder is ConversationAdapterV2.ThreadHeaderViewHolder) {
// A decorator adds the margin for the toolbar, margin is difference of the bounds "height" and the view height
val bounds = Rect()
parent.getDecoratedBoundsWithMargins(threadHeaderViewHolder.itemView, bounds)
bounds.bottom - bounds.top - threadHeaderViewHolder.itemView.height
} else {
// Deprecated not needed for CFv2
0
}
val childTop: Int = threadHeaderViewHolder.itemView.top - toolbarMargin
parent.translationY = min(0, -childTop).toFloat()
onRecyclerVerticalTranslationSet(parent.translationY)
}