convert letters to numbers at search only if we show letters at dialpad

This commit is contained in:
tibbi 2019-01-06 11:29:24 +01:00
parent ad3f5b6725
commit 4071ecbf16
3 changed files with 6 additions and 5 deletions

View File

@ -169,10 +169,10 @@ class DialpadActivity : SimpleActivity() {
(dialpad_list.adapter as? ContactsAdapter)?.finishActMode()
val filtered = contacts.filter {
val convertedName = PhoneNumberUtils.convertKeypadLettersToDigits(it.getNameToDisplay())
it.doesContainPhoneNumber(text) || (showLetters && convertedName.contains(text, true))
it.doesContainPhoneNumber(text, showLetters) || (showLetters && convertedName.contains(text, true))
}.sortedWith(compareBy {
if (showLetters) {
!it.doesContainPhoneNumber(text)
!it.doesContainPhoneNumber(text, showLetters)
} else {
true
}

View File

@ -228,11 +228,12 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
fun onSearchQueryChanged(text: String) {
val shouldNormalize = text.normalizeString() == text
val convertLetters = config.showDialpadLetters
(fragment_list.adapter as? ContactsAdapter)?.apply {
val filtered = contactsIgnoringSearch.filter {
getProperText(it.getNameToDisplay(), shouldNormalize).contains(text, true) ||
getProperText(it.nickname, shouldNormalize).contains(text, true) ||
it.doesContainPhoneNumber(text) ||
it.doesContainPhoneNumber(text, convertLetters) ||
it.emails.any { it.value.contains(text, true) } ||
it.addresses.any { getProperText(it.value, shouldNormalize).contains(text, true) } ||
it.IMs.any { it.value.contains(text, true) } ||

View File

@ -127,9 +127,9 @@ data class Contact(var id: Int, var prefix: String, var firstName: String, var m
fun isABusinessContact() = prefix.isEmpty() && firstName.isEmpty() && middleName.isEmpty() && surname.isEmpty() && suffix.isEmpty() && organization.isNotEmpty()
fun doesContainPhoneNumber(text: String): Boolean {
fun doesContainPhoneNumber(text: String, convertLetters: Boolean): Boolean {
return if (text.isNotEmpty()) {
val normalizedText = text.normalizeNumber()
val normalizedText = if (convertLetters) text.normalizeNumber() else text
phoneNumbers.any {
PhoneNumberUtils.compare(it.normalizedNumber, normalizedText) ||
it.value.contains(text) ||