diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/adapters/GroupsAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/adapters/GroupsAdapter.kt index 1d6f76d6..09162fe0 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/adapters/GroupsAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/adapters/GroupsAdapter.kt @@ -7,6 +7,8 @@ import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter import com.simplemobiletools.commons.dialogs.ConfirmationDialog import com.simplemobiletools.commons.extensions.applyColorFilter import com.simplemobiletools.commons.extensions.beVisibleIf +import com.simplemobiletools.commons.extensions.getAdjustedPrimaryColor +import com.simplemobiletools.commons.extensions.highlightTextPart import com.simplemobiletools.commons.views.FastScroller import com.simplemobiletools.commons.views.MyRecyclerView import com.simplemobiletools.contacts.pro.R @@ -26,7 +28,9 @@ class GroupsAdapter(activity: SimpleActivity, var groups: ArrayList, val private var smallPadding = activity.resources.getDimension(R.dimen.small_margin).toInt() private var bigPadding = activity.resources.getDimension(R.dimen.normal_margin).toInt() + private var textToHighlight = "" + var adjustedPrimaryColor = activity.getAdjustedPrimaryColor() var showContactThumbnails = activity.config.showContactThumbnails init { @@ -75,10 +79,16 @@ class GroupsAdapter(activity: SimpleActivity, var groups: ArrayList, val private fun getItemWithKey(key: Int): Group? = groups.firstOrNull { it.id!!.toInt() == key } - fun updateItems(newItems: ArrayList) { - groups = newItems - notifyDataSetChanged() - finishActMode() + fun updateItems(newItems: ArrayList, highlightText: String = "") { + if (newItems.hashCode() != groups.hashCode()) { + groups = newItems + textToHighlight = highlightText + notifyDataSetChanged() + finishActMode() + } else if (textToHighlight != highlightText) { + textToHighlight = highlightText + notifyDataSetChanged() + } fastScroller?.measureRecyclerView() } @@ -127,9 +137,16 @@ class GroupsAdapter(activity: SimpleActivity, var groups: ArrayList, val private fun setupView(view: View, group: Group) { view.apply { group_frame?.isSelected = selectedKeys.contains(group.id!!.toInt()) + val titleWithCnt = "${group.title} (${group.contactsCount})" + val groupTitle = if (textToHighlight.isEmpty()) { + titleWithCnt + } else { + titleWithCnt.highlightTextPart(textToHighlight, adjustedPrimaryColor) + } + group_name.apply { setTextColor(textColor) - text = String.format(activity.getString(R.string.groups_placeholder), group.title, group.contactsCount.toString()) + text = groupTitle setPadding(if (showContactThumbnails) smallPadding else bigPadding, smallPadding, smallPadding, 0) } diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/fragments/MyViewPagerFragment.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/fragments/MyViewPagerFragment.kt index a9df7e47..d5a30aef 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/pro/fragments/MyViewPagerFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/pro/fragments/MyViewPagerFragment.kt @@ -79,6 +79,10 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet) (fragment_list.adapter as? ContactsAdapter)?.apply { adjustedPrimaryColor = context.getAdjustedPrimaryColor() } + + (fragment_list.adapter as? GroupsAdapter)?.apply { + adjustedPrimaryColor = context.getAdjustedPrimaryColor() + } } fun startNameWithSurnameChanged(startNameWithSurname: Boolean) { @@ -268,7 +272,7 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet) } fragment_placeholder.beVisibleIf(filtered.isEmpty()) - (adapter as? GroupsAdapter)?.updateItems(filtered) + (adapter as? GroupsAdapter)?.updateItems(filtered, text) } }