diff --git a/app/build.gradle b/app/build.gradle index dadae90f..b0cacb82 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -45,7 +45,7 @@ ext { } dependencies { - implementation 'com.simplemobiletools:commons:4.6.5' + implementation 'com.simplemobiletools:commons:4.6.6' implementation 'joda-time:joda-time:2.9.9' implementation 'com.facebook.stetho:stetho:1.5.0' implementation 'com.android.support.constraint:constraint-layout:1.1.2' diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/extensions/String.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/extensions/String.kt deleted file mode 100644 index b76c81b7..00000000 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/extensions/String.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.simplemobiletools.contacts.extensions - -import com.simplemobiletools.contacts.helpers.normalizeRegex -import java.text.Normalizer - -fun String.normalizeString() = Normalizer.normalize(this, Normalizer.Form.NFD).replace(normalizeRegex, "") diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/fragments/MyViewPagerFragment.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/fragments/MyViewPagerFragment.kt index 1409077e..fea5f0b4 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/fragments/MyViewPagerFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/fragments/MyViewPagerFragment.kt @@ -236,32 +236,35 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet) } fun onSearchQueryChanged(text: String) { + val shouldNormalize = text.normalizeString() == text (fragment_list.adapter as? ContactsAdapter)?.apply { val filtered = contactsIgnoringSearch.filter { - it.getFullName().contains(text, true) || + getProperText(it.getFullName(), shouldNormalize).contains(text, true) || it.phoneNumbers.any { it.value.contains(text, true) } || it.emails.any { it.value.contains(text, true) } || - it.addresses.any { it.value.contains(text, true) } || - it.notes.contains(text, true) || - it.organization.company.contains(text, true) || - it.organization.jobPosition.contains(text, true) || + it.addresses.any { getProperText(it.value, shouldNormalize).contains(text, true) } || + getProperText(it.notes, shouldNormalize).contains(text, true) || + getProperText(it.organization.company, shouldNormalize).contains(text, true) || + getProperText(it.organization.jobPosition, shouldNormalize).contains(text, true) || it.websites.any { it.contains(text, true) } } as ArrayList Contact.sorting = config.sorting Contact.startWithSurname = config.startNameWithSurname filtered.sort() - filtered.sortBy { !it.getFullName().startsWith(text, true) } + filtered.sortBy { !getProperText(it.getFullName(), shouldNormalize).startsWith(text, true) } if (filtered.isEmpty() && this@MyViewPagerFragment is FavoritesFragment) { fragment_placeholder.text = activity.getString(R.string.no_items_found) } fragment_placeholder.beVisibleIf(filtered.isEmpty()) - updateItems(filtered, text) + updateItems(filtered, text.normalizeString()) } } + private fun getProperText(text: String, shouldNormalize: Boolean) = if (shouldNormalize) text.normalizeString() else text + fun onSearchOpened() { contactsIgnoringSearch = (fragment_list?.adapter as? ContactsAdapter)?.contactItems ?: ArrayList() } diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/Constants.kt index 6e3c1608..0ee6468e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/Constants.kt @@ -122,5 +122,3 @@ val localAccountTypes = arrayListOf("vnd.sec.contact.phone", "com.android.huawei.phone", "Local Phone Account" ) - -val normalizeRegex = "\\p{InCombiningDiacriticalMarks}+".toRegex() diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/models/Contact.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/models/Contact.kt index 06cd24d4..e8229f51 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/models/Contact.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/models/Contact.kt @@ -1,10 +1,10 @@ package com.simplemobiletools.contacts.models import android.graphics.Bitmap +import com.simplemobiletools.commons.extensions.normalizeString import com.simplemobiletools.commons.helpers.SORT_BY_FIRST_NAME import com.simplemobiletools.commons.helpers.SORT_BY_MIDDLE_NAME import com.simplemobiletools.commons.helpers.SORT_DESCENDING -import com.simplemobiletools.contacts.extensions.normalizeString import com.simplemobiletools.contacts.helpers.PHONE_NUMBER_PATTERN data class Contact(val id: Int, var prefix: String, var firstName: String, var middleName: String, var surname: String, var suffix: String, var photoUri: String,