Fix keyboard issue on some Android devices.

This commit is contained in:
Alex Hart
2021-10-26 10:24:59 -03:00
parent 12565d28ae
commit 85551ca824
2 changed files with 13 additions and 1 deletions

View File

@@ -3,14 +3,26 @@ package org.thoughtcrime.securesms.giph.mp4
import android.graphics.Canvas
import androidx.core.view.children
import androidx.recyclerview.widget.RecyclerView
import kotlin.math.min
/**
* Decoration that will make the video display params update on each recycler redraw.
*/
class GiphyMp4ItemDecoration(val callback: GiphyMp4PlaybackController.Callback) : RecyclerView.ItemDecoration() {
override fun onDraw(c: Canvas, parent: RecyclerView, state: RecyclerView.State) {
setParentRecyclerTranslationY(parent)
parent.children.map { parent.getChildViewHolder(it) }.filterIsInstance(GiphyMp4Playable::class.java).forEach {
callback.updateVideoDisplayPositionAndSize(parent, it)
}
}
private fun setParentRecyclerTranslationY(parent: RecyclerView) {
if (parent.childCount == 0 || parent.canScrollVertically(-1) || parent.canScrollVertically(1)) {
parent.translationY = 0f
} else {
val childTop = parent.children.last().top
parent.translationY = min(0, -childTop).toFloat()
}
}
}