mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-17 03:18:06 +00:00
Remove highlight from previous match when navigating between search results
This commit is contained in:
parent
57644a34de
commit
3f868e02fe
2 changed files with 27 additions and 25 deletions
|
|
@ -676,21 +676,6 @@ class MessageModel
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for search
|
|
||||||
if (highlight.isNotEmpty()) {
|
|
||||||
val indexStart = rawTextContent.indexOf(highlight, 0, ignoreCase = true)
|
|
||||||
if (indexStart >= 0) {
|
|
||||||
isTextHighlighted = true
|
|
||||||
val indexEnd = indexStart + highlight.length
|
|
||||||
spannableBuilder.setSpan(
|
|
||||||
StyleSpan(Typeface.BOLD),
|
|
||||||
indexStart,
|
|
||||||
indexEnd,
|
|
||||||
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for mentions
|
// Check for mentions
|
||||||
val chatRoom = chatMessage.chatRoom
|
val chatRoom = chatMessage.chatRoom
|
||||||
val matcher = Pattern.compile(MENTION_REGEXP).matcher(rawTextContent)
|
val matcher = Pattern.compile(MENTION_REGEXP).matcher(rawTextContent)
|
||||||
|
|
@ -787,6 +772,21 @@ class MessageModel
|
||||||
)
|
)
|
||||||
.build(spannableBuilder)
|
.build(spannableBuilder)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Check for search
|
||||||
|
if (highlight.isNotEmpty()) {
|
||||||
|
val indexStart = rawTextContent.indexOf(highlight, 0, ignoreCase = true)
|
||||||
|
if (indexStart >= 0) {
|
||||||
|
isTextHighlighted = true
|
||||||
|
val indexEnd = indexStart + highlight.length
|
||||||
|
spannableBuilder.setSpan(
|
||||||
|
StyleSpan(Typeface.BOLD),
|
||||||
|
indexStart,
|
||||||
|
indexEnd,
|
||||||
|
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@WorkerThread
|
@WorkerThread
|
||||||
|
|
|
||||||
|
|
@ -152,6 +152,8 @@ class ConversationViewModel
|
||||||
|
|
||||||
private var latestMatch: EventLog? = null
|
private var latestMatch: EventLog? = null
|
||||||
|
|
||||||
|
private var latestMatchModel: MessageModel? = null
|
||||||
|
|
||||||
private val chatRoomListener = object : ChatRoomListenerStub() {
|
private val chatRoomListener = object : ChatRoomListenerStub() {
|
||||||
@WorkerThread
|
@WorkerThread
|
||||||
override fun onConferenceJoined(chatRoom: ChatRoom, eventLog: EventLog) {
|
override fun onConferenceJoined(chatRoom: ChatRoom, eventLog: EventLog) {
|
||||||
|
|
@ -381,20 +383,17 @@ class ConversationViewModel
|
||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
fun closeSearchBar() {
|
fun closeSearchBar() {
|
||||||
|
coreContext.postOnCoreThread {
|
||||||
|
latestMatchModel?.highlightText("")
|
||||||
|
latestMatchModel = null
|
||||||
|
}
|
||||||
|
|
||||||
searchFilter.value = ""
|
searchFilter.value = ""
|
||||||
searchBarVisible.value = false
|
searchBarVisible.value = false
|
||||||
focusSearchBarEvent.value = Event(false)
|
focusSearchBarEvent.value = Event(false)
|
||||||
latestMatch = null
|
latestMatch = null
|
||||||
canSearchDown.value = false
|
canSearchDown.value = false
|
||||||
canSearchUp.value = false
|
canSearchUp.value = false
|
||||||
|
|
||||||
coreContext.postOnCoreThread {
|
|
||||||
for (eventLog in eventsList) {
|
|
||||||
if ((eventLog.model as? MessageModel)?.isTextHighlighted == true) {
|
|
||||||
eventLog.model.highlightText("")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
|
|
@ -1031,11 +1030,13 @@ class ConversationViewModel
|
||||||
canSearchDown.postValue(true)
|
canSearchDown.postValue(true)
|
||||||
canSearchUp.postValue(true)
|
canSearchUp.postValue(true)
|
||||||
|
|
||||||
|
// Clear highlight from previous match
|
||||||
|
latestMatchModel?.highlightText("")
|
||||||
|
|
||||||
Log.i(
|
Log.i(
|
||||||
"$TAG Found result [${match.chatMessage?.messageId}] while looking up for message with text [$textToSearch] in direction [$direction] starting from message [${latestMatch?.chatMessage?.messageId}]"
|
"$TAG Found result [${match.chatMessage?.messageId}] while looking up for message with text [$textToSearch] in direction [$direction] starting from message [${latestMatch?.chatMessage?.messageId}]"
|
||||||
)
|
)
|
||||||
latestMatch = match
|
latestMatch = match
|
||||||
|
|
||||||
val found = eventsList.find {
|
val found = eventsList.find {
|
||||||
it.eventLog == match
|
it.eventLog == match
|
||||||
}
|
}
|
||||||
|
|
@ -1044,7 +1045,8 @@ class ConversationViewModel
|
||||||
loadMessagesUpTo(match)
|
loadMessagesUpTo(match)
|
||||||
} else {
|
} else {
|
||||||
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)
|
latestMatchModel = (found.model as? MessageModel)
|
||||||
|
latestMatchModel?.highlightText(textToSearch)
|
||||||
val index = eventsList.indexOf(found)
|
val index = eventsList.indexOf(found)
|
||||||
itemToScrollTo.postValue(index)
|
itemToScrollTo.postValue(index)
|
||||||
searchInProgress.postValue(false)
|
searchInProgress.postValue(false)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue