From 3aacf4bcd2b823c117753c2c1b09acb4ad821bf6 Mon Sep 17 00:00:00 2001 From: Alex Hart Date: Fri, 19 May 2023 12:55:49 -0300 Subject: [PATCH] Add search highlight to call rows. --- .../securesms/calls/log/CallLogAdapter.kt | 18 +++++++++++++++--- .../securesms/calls/log/CallLogRow.kt | 1 + .../securesms/database/CallTable.kt | 3 ++- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/calls/log/CallLogAdapter.kt b/app/src/main/java/org/thoughtcrime/securesms/calls/log/CallLogAdapter.kt index a06d521d38..90ec1f09ed 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/calls/log/CallLogAdapter.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/calls/log/CallLogAdapter.kt @@ -1,6 +1,7 @@ package org.thoughtcrime.securesms.calls.log import android.content.res.ColorStateList +import android.text.style.TextAppearanceSpan import android.view.View import androidx.annotation.DrawableRes import androidx.annotation.StringRes @@ -15,6 +16,7 @@ import org.thoughtcrime.securesms.databinding.ConversationListItemClearFilterBin import org.thoughtcrime.securesms.mms.GlideApp import org.thoughtcrime.securesms.recipients.Recipient import org.thoughtcrime.securesms.util.DateUtils +import org.thoughtcrime.securesms.util.SearchUtil import org.thoughtcrime.securesms.util.adapter.mapping.BindingFactory import org.thoughtcrime.securesms.util.adapter.mapping.BindingViewHolder import org.thoughtcrime.securesms.util.adapter.mapping.MappingModel @@ -153,15 +155,25 @@ class CallLogAdapter( return } - presentRecipientDetails(model.call.peer) + presentRecipientDetails(model.call.peer, model.call.searchQuery) presentCallInfo(model.call, model.call.date) presentCallType(model) } - private fun presentRecipientDetails(recipient: Recipient) { + private fun presentRecipientDetails(recipient: Recipient, searchQuery: String?) { binding.callRecipientAvatar.setAvatar(GlideApp.with(binding.callRecipientAvatar), recipient, true) binding.callRecipientBadge.setBadgeFromRecipient(recipient) - binding.callRecipientName.text = recipient.getDisplayName(context) + binding.callRecipientName.text = if (searchQuery != null) { + SearchUtil.getHighlightedSpan( + Locale.getDefault(), + { arrayOf(TextAppearanceSpan(context, R.style.Signal_Text_TitleSmall)) }, + recipient.getDisplayName(context), + searchQuery, + SearchUtil.MATCH_ALL + ) + } else { + recipient.getDisplayName(context) + } } private fun presentCallInfo(call: CallLogRow.Call, date: Long) { diff --git a/app/src/main/java/org/thoughtcrime/securesms/calls/log/CallLogRow.kt b/app/src/main/java/org/thoughtcrime/securesms/calls/log/CallLogRow.kt index 4c153180e1..545155b158 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/calls/log/CallLogRow.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/calls/log/CallLogRow.kt @@ -25,6 +25,7 @@ sealed class CallLogRow { val date: Long, val groupCallState: GroupCallState, val children: Set, + val searchQuery: String?, override val id: Id = Id.Call(children) ) : CallLogRow() diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/CallTable.kt b/app/src/main/java/org/thoughtcrime/securesms/database/CallTable.kt index faa797e7a5..905e6f2092 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/CallTable.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/database/CallTable.kt @@ -974,7 +974,8 @@ class CallTable(context: Context, databaseHelper: SignalDatabase) : DatabaseTabl date = call.timestamp, peer = Recipient.resolved(call.peer), groupCallState = CallLogRow.GroupCallState.fromDetails(groupCallDetails), - children = actualChildren.toSet() + children = actualChildren.toSet(), + searchQuery = searchTerm ) } }