Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,9 @@ class ConversationActivityV2 : ScreenLockActionBarActivity(), InputBarDelegate,
}

private val isScrolledToBottom: Boolean
get() = binding.conversationRecyclerView.isNearBottom
get() = with(binding.conversationRecyclerView){
!canScrollVertically(1) || isNearBottom
}

// When the user clicks on the original message in a reply then we scroll to and highlight that original
// message. To do this we keep track of the replied-to message's location in the recycler view.
Expand Down Expand Up @@ -2120,9 +2122,6 @@ class ConversationActivityV2 : ScreenLockActionBarActivity(), InputBarDelegate,
if (sentMessageInfo != null) {
messageToScrollAuthor.set(sentMessageInfo.first)
messageToScrollTimestamp.set(sentMessageInfo.second)
binding.conversationRecyclerView.postDelayed({
binding.conversationRecyclerView.handleScrollToBottom()
}, 500L)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.thoughtcrime.securesms.util

import android.content.res.Resources
import android.util.Log
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import kotlin.math.roundToInt
Expand All @@ -23,13 +24,23 @@ fun toDp(px: Float, resources: Resources): Float {
return (px / scale)
}

/**
* Returns true if the recyclerview is scrolled within 50dp of the bottom
*/
val RecyclerView.isNearBottom: Boolean
get() = computeVerticalScrollOffset().coerceAtLeast(0) +
computeVerticalScrollExtent() +
toPx(50, resources) >= computeVerticalScrollRange()
get() {
val offset = computeVerticalScrollOffset().coerceAtLeast(0)
val extent = computeVerticalScrollExtent()
val range = computeVerticalScrollRange()
val thresholdPx = toPx(50, resources)

// If there's no scrollable area, don't treat it as "near bottom"
if (range <= extent) {
return false
}

val remaining = range - (offset + extent) // distance from bottom in px

// true only when remaining distance to bottom <= 50dp
return remaining <= thresholdPx
}

val RecyclerView.isFullyScrolled: Boolean
get() {
Expand Down