mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-17 03:18:06 +00:00
Scroll to latest match during chat message search in case user scrolled away
This commit is contained in:
parent
9096225b45
commit
71bb569fde
2 changed files with 23 additions and 9 deletions
|
|
@ -832,9 +832,21 @@ open class ConversationFragment : SlidingPaneChildFragment() {
|
|||
|
||||
viewModel.itemToScrollTo.observe(viewLifecycleOwner) { position ->
|
||||
if (position >= 0) {
|
||||
Log.i("$TAG Scrolling to message/event at position [$position]")
|
||||
val recyclerView = binding.eventsList
|
||||
recyclerView.scrollToPosition(position)
|
||||
val layoutManager = recyclerView.layoutManager as LinearLayoutManager
|
||||
val firstDisplayedItemPosition = layoutManager.findFirstVisibleItemPosition()
|
||||
val lastDisplayedItemPosition = layoutManager.findLastVisibleItemPosition()
|
||||
Log.i(
|
||||
"$TAG Scrolling to message/event at position [$position], " +
|
||||
"display show events between positions [$firstDisplayedItemPosition] and [$lastDisplayedItemPosition]"
|
||||
)
|
||||
if (firstDisplayedItemPosition > position && position > 0) {
|
||||
recyclerView.scrollToPosition(position - 1)
|
||||
} else if (lastDisplayedItemPosition < position && position < layoutManager.itemCount - 1) {
|
||||
recyclerView.scrollToPosition(position + 1)
|
||||
} else {
|
||||
recyclerView.scrollToPosition(position)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -988,6 +988,14 @@ class ConversationViewModel
|
|||
val message = if (latestMatch == null) {
|
||||
R.string.conversation_search_no_match_found
|
||||
} else {
|
||||
// Scroll to last matching event anyway, user may have scrolled away
|
||||
val found = eventsList.find {
|
||||
it.eventLog == latestMatch
|
||||
}
|
||||
if (found != null) { // This should always be true
|
||||
val index = eventsList.indexOf(found)
|
||||
itemToScrollTo.postValue(index)
|
||||
}
|
||||
R.string.conversation_search_no_more_match
|
||||
}
|
||||
showRedToast(message, R.drawable.magnifying_glass)
|
||||
|
|
@ -1007,13 +1015,7 @@ class ConversationViewModel
|
|||
Log.i("$TAG Found result is already in history, no need to load more history")
|
||||
(found.model as? MessageModel)?.highlightText(textToSearch)
|
||||
val index = eventsList.indexOf(found)
|
||||
if (direction == SearchDirection.Down && index < eventsList.size - 1) {
|
||||
// Go to next message to prevent the message we are looking for to be behind the scroll to bottom button
|
||||
itemToScrollTo.postValue(index + 1)
|
||||
} else {
|
||||
// Go to previous message so target message won't be displayed stuck to the top
|
||||
itemToScrollTo.postValue(index - 1)
|
||||
}
|
||||
itemToScrollTo.postValue(index)
|
||||
searchInProgress.postValue(false)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue