mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-02-17 12:00:39 +01:00
make string normalizing a string extension
This commit is contained in:
parent
6bf77d73bd
commit
fd775bf050
@ -0,0 +1,6 @@
|
|||||||
|
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, "")
|
@ -122,3 +122,5 @@ val localAccountTypes = arrayListOf("vnd.sec.contact.phone",
|
|||||||
"com.android.huawei.phone",
|
"com.android.huawei.phone",
|
||||||
"Local Phone Account"
|
"Local Phone Account"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
val normalizeRegex = "\\p{InCombiningDiacriticalMarks}+".toRegex()
|
||||||
|
@ -4,8 +4,8 @@ import android.graphics.Bitmap
|
|||||||
import com.simplemobiletools.commons.helpers.SORT_BY_FIRST_NAME
|
import com.simplemobiletools.commons.helpers.SORT_BY_FIRST_NAME
|
||||||
import com.simplemobiletools.commons.helpers.SORT_BY_MIDDLE_NAME
|
import com.simplemobiletools.commons.helpers.SORT_BY_MIDDLE_NAME
|
||||||
import com.simplemobiletools.commons.helpers.SORT_DESCENDING
|
import com.simplemobiletools.commons.helpers.SORT_DESCENDING
|
||||||
|
import com.simplemobiletools.contacts.extensions.normalizeString
|
||||||
import com.simplemobiletools.contacts.helpers.PHONE_NUMBER_PATTERN
|
import com.simplemobiletools.contacts.helpers.PHONE_NUMBER_PATTERN
|
||||||
import java.text.Normalizer
|
|
||||||
|
|
||||||
data class Contact(val id: Int, var prefix: String, var firstName: String, var middleName: String, var surname: String, var suffix: String, var photoUri: String,
|
data class Contact(val id: Int, var prefix: String, var firstName: String, var middleName: String, var surname: String, var suffix: String, var photoUri: String,
|
||||||
var phoneNumbers: ArrayList<PhoneNumber>, var emails: ArrayList<Email>, var addresses: ArrayList<Address>, var events: ArrayList<Event>,
|
var phoneNumbers: ArrayList<PhoneNumber>, var emails: ArrayList<Email>, var addresses: ArrayList<Address>, var events: ArrayList<Event>,
|
||||||
@ -14,7 +14,6 @@ data class Contact(val id: Int, var prefix: String, var firstName: String, var m
|
|||||||
companion object {
|
companion object {
|
||||||
var sorting = 0
|
var sorting = 0
|
||||||
var startWithSurname = false
|
var startWithSurname = false
|
||||||
val regex = "\\p{InCombiningDiacriticalMarks}+".toRegex()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun compareTo(other: Contact): Int {
|
override fun compareTo(other: Contact): Int {
|
||||||
@ -23,25 +22,25 @@ data class Contact(val id: Int, var prefix: String, var firstName: String, var m
|
|||||||
|
|
||||||
when {
|
when {
|
||||||
sorting and SORT_BY_FIRST_NAME != 0 -> {
|
sorting and SORT_BY_FIRST_NAME != 0 -> {
|
||||||
firstString = normalizeString(firstName)
|
firstString = firstName.normalizeString()
|
||||||
secondString = normalizeString(other.firstName)
|
secondString = other.firstName.normalizeString()
|
||||||
}
|
}
|
||||||
sorting and SORT_BY_MIDDLE_NAME != 0 -> {
|
sorting and SORT_BY_MIDDLE_NAME != 0 -> {
|
||||||
firstString = normalizeString(middleName)
|
firstString = middleName.normalizeString()
|
||||||
secondString = normalizeString(other.middleName)
|
secondString = other.middleName.normalizeString()
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
firstString = normalizeString(surname)
|
firstString = surname.normalizeString()
|
||||||
secondString = normalizeString(other.surname)
|
secondString = other.surname.normalizeString()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (firstString.isEmpty() && firstName.isEmpty() && middleName.isEmpty() && surname.isEmpty() && organization.company.isNotEmpty()) {
|
if (firstString.isEmpty() && firstName.isEmpty() && middleName.isEmpty() && surname.isEmpty() && organization.company.isNotEmpty()) {
|
||||||
firstString = normalizeString(organization.company)
|
firstString = organization.company.normalizeString()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (secondString.isEmpty() && other.firstName.isEmpty() && other.middleName.isEmpty() && other.surname.isEmpty() && other.organization.company.isNotEmpty()) {
|
if (secondString.isEmpty() && other.firstName.isEmpty() && other.middleName.isEmpty() && other.surname.isEmpty() && other.organization.company.isNotEmpty()) {
|
||||||
secondString = normalizeString(other.organization.company)
|
secondString = other.organization.company.normalizeString()
|
||||||
}
|
}
|
||||||
|
|
||||||
var result = if (firstString.firstOrNull()?.isLetter() == true && secondString.firstOrNull()?.isLetter() == false) {
|
var result = if (firstString.firstOrNull()?.isLetter() == true && secondString.firstOrNull()?.isLetter() == false) {
|
||||||
@ -69,8 +68,6 @@ data class Contact(val id: Int, var prefix: String, var firstName: String, var m
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun normalizeString(string: String) = Normalizer.normalize(string, Normalizer.Form.NFD).replace(regex, "")
|
|
||||||
|
|
||||||
fun getBubbleText() = when {
|
fun getBubbleText() = when {
|
||||||
sorting and SORT_BY_FIRST_NAME != 0 -> firstName
|
sorting and SORT_BY_FIRST_NAME != 0 -> firstName
|
||||||
sorting and SORT_BY_MIDDLE_NAME != 0 -> middleName
|
sorting and SORT_BY_MIDDLE_NAME != 0 -> middleName
|
||||||
|
Loading…
x
Reference in New Issue
Block a user