fix #132, fix searching with UTF8 chars
This commit is contained in:
parent
9ab6f9d7df
commit
0bcbf9bb94
|
@ -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'
|
||||
|
|
|
@ -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, "")
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -122,5 +122,3 @@ val localAccountTypes = arrayListOf("vnd.sec.contact.phone",
|
|||
"com.android.huawei.phone",
|
||||
"Local Phone Account"
|
||||
)
|
||||
|
||||
val normalizeRegex = "\\p{InCombiningDiacriticalMarks}+".toRegex()
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue