From 85551ca824f9a550ae21c55a9a03064e5b43e285 Mon Sep 17 00:00:00 2001 From: Alex Hart Date: Tue, 26 Oct 2021 10:24:59 -0300 Subject: [PATCH] Fix keyboard issue on some Android devices. --- .../securesms/giph/mp4/GiphyMp4ItemDecoration.kt | 12 ++++++++++++ app/src/main/res/layout/conversation_fragment.xml | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/giph/mp4/GiphyMp4ItemDecoration.kt b/app/src/main/java/org/thoughtcrime/securesms/giph/mp4/GiphyMp4ItemDecoration.kt index 3ff30c920..3762d77b5 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/giph/mp4/GiphyMp4ItemDecoration.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/giph/mp4/GiphyMp4ItemDecoration.kt @@ -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() + } + } } diff --git a/app/src/main/res/layout/conversation_fragment.xml b/app/src/main/res/layout/conversation_fragment.xml index fa0098cf4..a415e4dc7 100644 --- a/app/src/main/res/layout/conversation_fragment.xml +++ b/app/src/main/res/layout/conversation_fragment.xml @@ -26,7 +26,7 @@