make normalizedNumber nullable

This commit is contained in:
tibbi 2022-02-10 16:55:49 +01:00 committed by Hosted Weblate
parent 178537ae0d
commit 2501d7c985
No known key found for this signature in database
GPG key ID: A3FAAA06E6569B4C
3 changed files with 9 additions and 8 deletions

View file

@ -44,8 +44,9 @@ class SimpleContactsHelper(val context: Context) {
}
allContacts = allContacts.filter { it.name.isNotEmpty() }.distinctBy {
val startIndex = Math.max(0, it.phoneNumbers.first().normalizedNumber.length - 9)
it.phoneNumbers.first().normalizedNumber.substring(startIndex)
val normalizedNumber = it.phoneNumbers.first().normalizedNumber ?: it.phoneNumbers.first().value.normalizePhoneNumber()
val startIndex = Math.max(0, normalizedNumber.length - 9)
normalizedNumber.substring(startIndex)
}.distinctBy { it.rawId }.toMutableList() as ArrayList<SimpleContact>
// if there are duplicate contacts with the same name, while the first one has phone numbers 1234 and 4567, second one has only 4567,
@ -58,7 +59,7 @@ class SimpleContactsHelper(val context: Context) {
if (contacts.any { it.phoneNumbers.size == 1 } && contacts.any { it.phoneNumbers.size > 1 }) {
val multipleNumbersContact = contacts.first()
contacts.subList(1, contacts.size).forEach { contact ->
if (contact.phoneNumbers.all { multipleNumbersContact.doesContainPhoneNumber(it.normalizedNumber) }) {
if (contact.phoneNumbers.all { it.normalizedNumber != null && multipleNumbersContact.doesContainPhoneNumber(it.normalizedNumber!!) }) {
val contactToRemove = allContacts.firstOrNull { it.rawId == contact.rawId }
if (contactToRemove != null) {
contactsToRemove.add(contactToRemove)

View file

@ -1,3 +1,3 @@
package com.simplemobiletools.commons.models
data class PhoneNumber(var value: String, var type: Int, var label: String, var normalizedNumber: String)
data class PhoneNumber(var value: String, var type: Int, var label: String, var normalizedNumber: String?)

View file

@ -31,11 +31,11 @@ data class SimpleContact(
return if (text.isNotEmpty()) {
val normalizedText = text.normalizePhoneNumber()
if (normalizedText.isEmpty()) {
phoneNumbers.map { it.normalizedNumber }.any { phoneNumber ->
phoneNumbers.mapNotNull { it.normalizedNumber }.any { phoneNumber ->
phoneNumber.contains(text)
}
} else {
phoneNumbers.map { it.normalizedNumber }.any { phoneNumber ->
phoneNumbers.mapNotNull { it.normalizedNumber }.any { phoneNumber ->
PhoneNumberUtils.compare(phoneNumber.normalizePhoneNumber(), normalizedText) ||
phoneNumber.contains(text) ||
phoneNumber.normalizePhoneNumber().contains(normalizedText) ||
@ -51,11 +51,11 @@ data class SimpleContact(
return if (text.isNotEmpty()) {
val normalizedText = text.normalizePhoneNumber()
if (normalizedText.isEmpty()) {
phoneNumbers.map { it.normalizedNumber }.any { phoneNumber ->
phoneNumbers.mapNotNull { it.normalizedNumber }.any { phoneNumber ->
phoneNumber == text
}
} else {
phoneNumbers.map { it.normalizedNumber }.any { phoneNumber ->
phoneNumbers.mapNotNull { it.normalizedNumber }.any { phoneNumber ->
PhoneNumberUtils.compare(phoneNumber.normalizePhoneNumber(), normalizedText) ||
phoneNumber == text ||
phoneNumber.normalizePhoneNumber() == normalizedText ||