From cc015c45bd0442718fbcd18e1a7c6a45de2aec99 Mon Sep 17 00:00:00 2001 From: Andrew Date: Wed, 14 Jun 2023 10:34:49 +0930 Subject: [PATCH] Add 50 dp buffer to isScrolledToBottom (#1228) --- .../org/thoughtcrime/securesms/util/GeneralUtilities.kt | 7 +++++++ .../java/org/session/libsession/utilities/ViewUtils.kt | 5 ----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/util/GeneralUtilities.kt b/app/src/main/java/org/thoughtcrime/securesms/util/GeneralUtilities.kt index 00e3e44418..a38c93831e 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/util/GeneralUtilities.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/util/GeneralUtilities.kt @@ -3,6 +3,8 @@ package org.thoughtcrime.securesms.util import android.content.res.Resources import android.os.Build import androidx.annotation.ColorRes +import androidx.recyclerview.widget.RecyclerView +import kotlin.math.max import kotlin.math.roundToInt fun Resources.getColorWithID(@ColorRes id: Int, theme: Resources.Theme?): Int { @@ -30,3 +32,8 @@ fun toDp(px: Float, resources: Resources): Float { val scale = resources.displayMetrics.density return (px / scale) } + +val RecyclerView.isScrolledToBottom: Boolean + get() = computeVerticalScrollOffset().coerceAtLeast(0) + + computeVerticalScrollExtent() + + toPx(50, resources) >= computeVerticalScrollRange() 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 dfe0c3b451..80c0293238 100644 --- a/libsession/src/main/java/org/session/libsession/utilities/ViewUtils.kt +++ b/libsession/src/main/java/org/session/libsession/utilities/ViewUtils.kt @@ -4,8 +4,6 @@ import android.content.Context import android.util.TypedValue import androidx.annotation.AttrRes import androidx.annotation.ColorInt -import androidx.recyclerview.widget.RecyclerView -import kotlin.math.max @ColorInt fun Context.getColorFromAttr( @@ -16,6 +14,3 @@ fun Context.getColorFromAttr( theme.resolveAttribute(attrColor, typedValue, resolveRefs) return typedValue.data } - -val RecyclerView.isScrolledToBottom: Boolean - get() = max(0, computeVerticalScrollOffset()) + computeVerticalScrollExtent() >= computeVerticalScrollRange()