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
f282bf689c
commit
4d55b089a6
2 changed files with 23 additions and 9 deletions
|
|
@ -832,9 +832,21 @@ open class ConversationFragment : SlidingPaneChildFragment() {
|
||||||
|
|
||||||
viewModel.itemToScrollTo.observe(viewLifecycleOwner) { position ->
|
viewModel.itemToScrollTo.observe(viewLifecycleOwner) { position ->
|
||||||
if (position >= 0) {
|
if (position >= 0) {
|
||||||
Log.i("$TAG Scrolling to message/event at position [$position]")
|
|
||||||
val recyclerView = binding.eventsList
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -968,6 +968,14 @@ class ConversationViewModel
|
||||||
val message = if (latestMatch == null) {
|
val message = if (latestMatch == null) {
|
||||||
R.string.conversation_search_no_match_found
|
R.string.conversation_search_no_match_found
|
||||||
} else {
|
} 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
|
R.string.conversation_search_no_more_match
|
||||||
}
|
}
|
||||||
showRedToast(message, R.drawable.magnifying_glass)
|
showRedToast(message, R.drawable.magnifying_glass)
|
||||||
|
|
@ -987,13 +995,7 @@ class ConversationViewModel
|
||||||
Log.i("$TAG Found result is already in history, no need to load more history")
|
Log.i("$TAG Found result is already in history, no need to load more history")
|
||||||
(found.model as? MessageModel)?.highlightText(textToSearch)
|
(found.model as? MessageModel)?.highlightText(textToSearch)
|
||||||
val index = eventsList.indexOf(found)
|
val index = eventsList.indexOf(found)
|
||||||
if (direction == SearchDirection.Down && index < eventsList.size - 1) {
|
itemToScrollTo.postValue(index)
|
||||||
// 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)
|
|
||||||
}
|
|
||||||
searchInProgress.postValue(false)
|
searchInProgress.postValue(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue