mirror of
https://github.com/oxen-io/session-android.git
synced 2025-06-09 14:28:34 +00:00
Updated the 'scrollToBottom' behaviour to be more efficient
This commit is contained in:
parent
810430e806
commit
afa42daab1
@ -315,13 +315,26 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
|
|||||||
restoreDraftIfNeeded()
|
restoreDraftIfNeeded()
|
||||||
setUpUiStateObserver()
|
setUpUiStateObserver()
|
||||||
binding!!.scrollToBottomButton.setOnClickListener {
|
binding!!.scrollToBottomButton.setOnClickListener {
|
||||||
val layoutManager = binding?.conversationRecyclerView?.layoutManager ?: return@setOnClickListener
|
val layoutManager = (binding?.conversationRecyclerView?.layoutManager as? LinearLayoutManager) ?: return@setOnClickListener
|
||||||
|
|
||||||
if (layoutManager.isSmoothScrolling) {
|
if (layoutManager.isSmoothScrolling) {
|
||||||
binding?.conversationRecyclerView?.scrollToPosition(0)
|
binding?.conversationRecyclerView?.scrollToPosition(0)
|
||||||
} else {
|
} else {
|
||||||
|
// It looks like 'smoothScrollToPosition' will actually load all intermediate items in
|
||||||
|
// order to do the scroll, this can be very slow if there are a lot of messages so
|
||||||
|
// instead we check the current position and if there are more than 10 items to scroll
|
||||||
|
// we jump instantly to the 10th item and scroll from there (this should happen quick
|
||||||
|
// enough to give a similar scroll effect without having to load everything)
|
||||||
|
val position = layoutManager.findFirstVisibleItemPosition()
|
||||||
|
if (position > 10) {
|
||||||
|
binding?.conversationRecyclerView?.scrollToPosition(10)
|
||||||
|
}
|
||||||
|
|
||||||
|
binding?.conversationRecyclerView?.post {
|
||||||
binding?.conversationRecyclerView?.smoothScrollToPosition(0)
|
binding?.conversationRecyclerView?.smoothScrollToPosition(0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
unreadCount = mmsSmsDb.getUnreadCount(viewModel.threadId)
|
unreadCount = mmsSmsDb.getUnreadCount(viewModel.threadId)
|
||||||
updateUnreadCountIndicator()
|
updateUnreadCountIndicator()
|
||||||
setUpTypingObserver()
|
setUpTypingObserver()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user