@@ -14,6 +14,7 @@ import com.simplemobiletools.commons.dialogs.ConfirmationDialog
1414import com.simplemobiletools.commons.dialogs.RadioGroupDialog
1515import com.simplemobiletools.commons.extensions.beVisibleIf
1616import com.simplemobiletools.commons.extensions.getColoredDrawableWithColor
17+ import com.simplemobiletools.commons.extensions.highlightTextPart
1718import com.simplemobiletools.commons.extensions.isActivityDestroyed
1819import com.simplemobiletools.commons.models.RadioItem
1920import com.simplemobiletools.commons.views.FastScroller
@@ -36,6 +37,7 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: ArrayList<Cont
3637
3738 private lateinit var contactDrawable: Drawable
3839 private var config = activity.config
40+ private var textToHighlight = " "
3941 var startNameWithSurname: Boolean
4042 var showContactThumbnails: Boolean
4143 var showPhoneNumbers: Boolean
@@ -114,11 +116,15 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: ArrayList<Cont
114116 contactDrawable = activity.resources.getColoredDrawableWithColor(R .drawable.ic_person, textColor)
115117 }
116118
117- fun updateItems (newItems : ArrayList <Contact >) {
119+ fun updateItems (newItems : ArrayList <Contact >, highlightText : String = "" ) {
118120 if (newItems.hashCode() != contactItems.hashCode()) {
119121 contactItems = newItems
122+ textToHighlight = highlightText
120123 notifyDataSetChanged()
121124 finishActMode()
125+ } else if (textToHighlight != highlightText) {
126+ textToHighlight = highlightText
127+ notifyDataSetChanged()
122128 }
123129 }
124130
@@ -243,13 +249,18 @@ class ContactsAdapter(activity: SimpleActivity, var contactItems: ArrayList<Cont
243249
244250 private fun setupView (view : View , contact : Contact ) {
245251 view.apply {
246- contact_name.text = contact.getFullName()
252+ val fullName = contact.getFullName()
253+ val nameText = if (textToHighlight.isEmpty()) fullName else fullName.highlightTextPart(textToHighlight, primaryColor)
254+ contact_name.text = nameText
247255 contact_name.setTextColor(textColor)
248256 contact_name.setPadding(if (showContactThumbnails) smallPadding else bigPadding, smallPadding, smallPadding, 0 )
249257
250- contact_number?.text = contact.phoneNumbers.firstOrNull()?.value ? : " "
251- contact_number?.setTextColor(textColor)
252- contact_number?.setPadding(if (showContactThumbnails) smallPadding else bigPadding, 0 , smallPadding, 0 )
258+ if (contact_number != null ) {
259+ val numberText = contact.phoneNumbers.firstOrNull()?.value ? : " "
260+ contact_number.text = if (textToHighlight.isEmpty()) numberText else numberText.highlightTextPart(textToHighlight, primaryColor)
261+ contact_number.setTextColor(textColor)
262+ contact_number.setPadding(if (showContactThumbnails) smallPadding else bigPadding, 0 , smallPadding, 0 )
263+ }
253264
254265 contact_tmb.beVisibleIf(showContactThumbnails)
255266
0 commit comments