From f0715f16e0e49df0161302c79a33fc46d5b546ca Mon Sep 17 00:00:00 2001 From: andrew Date: Mon, 8 May 2023 14:07:36 +0930 Subject: [PATCH] Fix scroll to bottom button always visible if last item is taller than RecyclerView --- .../securesms/conversation/v2/ConversationActivityV2.kt | 5 +---- .../java/org/session/libsession/utilities/ViewUtils.kt | 9 ++++++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt index cabb583085..107627b2c1 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt @@ -212,10 +212,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe var searchViewItem: MenuItem? = null private val isScrolledToBottom: Boolean - get() { - val position = layoutManager?.findFirstCompletelyVisibleItemPosition() ?: 0 - return position == 0 - } + get() = binding?.conversationRecyclerView?.isScrolledToBottom ?: true private val layoutManager: LinearLayoutManager? get() { return binding?.conversationRecyclerView?.layoutManager as LinearLayoutManager? } diff --git a/libsession/src/main/java/org/session/libsession/utilities/ViewUtils.kt b/libsession/src/main/java/org/session/libsession/utilities/ViewUtils.kt index 5781ea3e2c..f67abe8ec4 100644 --- a/libsession/src/main/java/org/session/libsession/utilities/ViewUtils.kt +++ b/libsession/src/main/java/org/session/libsession/utilities/ViewUtils.kt @@ -4,6 +4,7 @@ import android.content.Context import android.util.TypedValue import androidx.annotation.AttrRes import androidx.annotation.ColorInt +import androidx.recyclerview.widget.RecyclerView @ColorInt fun Context.getColorFromAttr( @@ -13,4 +14,10 @@ fun Context.getColorFromAttr( ): Int { theme.resolveAttribute(attrColor, typedValue, resolveRefs) return typedValue.data -} \ No newline at end of file +} + +val RecyclerView.isScrolledToBottom: Boolean + get() { + val contentHeight = height - (paddingTop + paddingBottom) + return computeVerticalScrollRange() == computeVerticalScrollOffset() + contentHeight + }