mirror of
https://github.com/SimpleMobileTools/Simple-Contacts.git
synced 2025-02-03 17:27:43 +01:00
remove special chars from phone numbers at creating, not just at sorting
This commit is contained in:
parent
461ffdfd0e
commit
26c4da4f69
@ -507,7 +507,7 @@ class EditContactActivity : ContactActivity() {
|
|||||||
originalContactSource = if (hasContactPermissions()) config.lastUsedContactSource else SMT_PRIVATE
|
originalContactSource = if (hasContactPermissions()) config.lastUsedContactSource else SMT_PRIVATE
|
||||||
val organization = Organization("", "")
|
val organization = Organization("", "")
|
||||||
contact = Contact(0, "", "", "", "", "", "", "", ArrayList(), ArrayList(), ArrayList(), ArrayList(), originalContactSource, 0, 0, "",
|
contact = Contact(0, "", "", "", "", "", "", "", ArrayList(), ArrayList(), ArrayList(), ArrayList(), originalContactSource, 0, 0, "",
|
||||||
null, "", ArrayList(), organization, ArrayList())
|
null, "", ArrayList(), organization, ArrayList(), ArrayList())
|
||||||
contact_source.text = getPublicContactSource(contact!!.source)
|
contact_source.text = getPublicContactSource(contact!!.source)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ import com.simplemobiletools.contacts.models.*
|
|||||||
import com.simplemobiletools.contacts.overloads.times
|
import com.simplemobiletools.contacts.overloads.times
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
import kotlin.collections.ArrayList
|
||||||
|
|
||||||
class ContactsHelper(val activity: Activity) {
|
class ContactsHelper(val activity: Activity) {
|
||||||
private val BATCH_SIZE = 100
|
private val BATCH_SIZE = 100
|
||||||
@ -127,7 +128,7 @@ class ContactsHelper(val activity: Activity) {
|
|||||||
val suffix = cursor.getStringValue(CommonDataKinds.StructuredName.SUFFIX) ?: ""
|
val suffix = cursor.getStringValue(CommonDataKinds.StructuredName.SUFFIX) ?: ""
|
||||||
val nickname = ""
|
val nickname = ""
|
||||||
val photoUri = cursor.getStringValue(CommonDataKinds.StructuredName.PHOTO_URI) ?: ""
|
val photoUri = cursor.getStringValue(CommonDataKinds.StructuredName.PHOTO_URI) ?: ""
|
||||||
val number = ArrayList<PhoneNumber>() // proper value is obtained below
|
val numbers = ArrayList<PhoneNumber>() // proper value is obtained below
|
||||||
val emails = ArrayList<Email>()
|
val emails = ArrayList<Email>()
|
||||||
val addresses = ArrayList<Address>()
|
val addresses = ArrayList<Address>()
|
||||||
val events = ArrayList<Event>()
|
val events = ArrayList<Event>()
|
||||||
@ -139,8 +140,9 @@ class ContactsHelper(val activity: Activity) {
|
|||||||
val groups = ArrayList<Group>()
|
val groups = ArrayList<Group>()
|
||||||
val organization = Organization("", "")
|
val organization = Organization("", "")
|
||||||
val websites = ArrayList<String>()
|
val websites = ArrayList<String>()
|
||||||
val contact = Contact(id, prefix, firstName, middleName, surname, suffix, nickname, photoUri, number, emails, addresses,
|
val cleanNumbers = ArrayList<PhoneNumber>()
|
||||||
events, accountName, starred, contactId, thumbnailUri, null, notes, groups, organization, websites)
|
val contact = Contact(id, prefix, firstName, middleName, surname, suffix, nickname, photoUri, numbers, emails, addresses,
|
||||||
|
events, accountName, starred, contactId, thumbnailUri, null, notes, groups, organization, websites, cleanNumbers)
|
||||||
|
|
||||||
contacts.put(id, contact)
|
contacts.put(id, contact)
|
||||||
} while (cursor.moveToNext())
|
} while (cursor.moveToNext())
|
||||||
@ -155,7 +157,15 @@ class ContactsHelper(val activity: Activity) {
|
|||||||
var size = phoneNumbers.size()
|
var size = phoneNumbers.size()
|
||||||
for (i in 0 until size) {
|
for (i in 0 until size) {
|
||||||
val key = phoneNumbers.keyAt(i)
|
val key = phoneNumbers.keyAt(i)
|
||||||
contacts[key]?.phoneNumbers = phoneNumbers.valueAt(i)
|
if (contacts[key] != null) {
|
||||||
|
val numbers = phoneNumbers.valueAt(i)
|
||||||
|
contacts[key].phoneNumbers = numbers
|
||||||
|
|
||||||
|
// remove all spaces, dashes etc from numbers for easier comparing, used only at list views
|
||||||
|
numbers.forEach {
|
||||||
|
numbers.mapTo(contacts[key].cleanPhoneNumbers) { PhoneNumber(it.value.replace(PHONE_NUMBER_PATTERN.toRegex(), ""), 0, "") }
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val nicknames = getNicknames()
|
val nicknames = getNicknames()
|
||||||
@ -726,7 +736,7 @@ class ContactsHelper(val activity: Activity) {
|
|||||||
val organization = getOrganizations(id)[id] ?: Organization("", "")
|
val organization = getOrganizations(id)[id] ?: Organization("", "")
|
||||||
val websites = getWebsites(id)[id] ?: ArrayList()
|
val websites = getWebsites(id)[id] ?: ArrayList()
|
||||||
return Contact(id, prefix, firstName, middleName, surname, suffix, nickname, photoUri, number, emails, addresses, events,
|
return Contact(id, prefix, firstName, middleName, surname, suffix, nickname, photoUri, number, emails, addresses, events,
|
||||||
accountName, starred, contactId, thumbnailUri, null, notes, groups, organization, websites)
|
accountName, starred, contactId, thumbnailUri, null, notes, groups, organization, websites, ArrayList())
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
cursor?.close()
|
cursor?.close()
|
||||||
|
@ -335,8 +335,11 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||||||
val websites = if (websitesJson == "[]") ArrayList() else gson.fromJson<ArrayList<String>>(websitesJson, websitesToken)
|
val websites = if (websitesJson == "[]") ArrayList() else gson.fromJson<ArrayList<String>>(websitesJson, websitesToken)
|
||||||
?: ArrayList(1)
|
?: ArrayList(1)
|
||||||
|
|
||||||
|
val cleanPhoneNumbers = ArrayList<PhoneNumber>()
|
||||||
|
phoneNumbers.mapTo(cleanPhoneNumbers) { PhoneNumber(it.value.replace(PHONE_NUMBER_PATTERN.toRegex(), ""), 0, "") }
|
||||||
|
|
||||||
val contact = Contact(id, prefix, firstName, middleName, surname, suffix, nickname, "", phoneNumbers, emails, addresses,
|
val contact = Contact(id, prefix, firstName, middleName, surname, suffix, nickname, "", phoneNumbers, emails, addresses,
|
||||||
events, SMT_PRIVATE, starred, id, "", photo, notes, groups, organization, websites)
|
events, SMT_PRIVATE, starred, id, "", photo, notes, groups, organization, websites, cleanPhoneNumbers)
|
||||||
contacts.add(contact)
|
contacts.add(contact)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -110,9 +110,10 @@ class VcfImporter(val activity: SimpleActivity) {
|
|||||||
val photoData = ezContact.photos.firstOrNull()?.data
|
val photoData = ezContact.photos.firstOrNull()?.data
|
||||||
val photo = null
|
val photo = null
|
||||||
val thumbnailUri = savePhoto(photoData)
|
val thumbnailUri = savePhoto(photoData)
|
||||||
|
val cleanPhoneNumbers = ArrayList<PhoneNumber>()
|
||||||
|
|
||||||
val contact = Contact(0, prefix, firstName, middleName, surname, suffix, nickname, photoUri, phoneNumbers, emails, addresses, events,
|
val contact = Contact(0, prefix, firstName, middleName, surname, suffix, nickname, photoUri, phoneNumbers, emails, addresses, events,
|
||||||
targetContactSource, starred, contactId, thumbnailUri, photo, notes, groups, organization, websites)
|
targetContactSource, starred, contactId, thumbnailUri, photo, notes, groups, organization, websites, cleanPhoneNumbers)
|
||||||
|
|
||||||
if (ContactsHelper(activity).insertContact(contact)) {
|
if (ContactsHelper(activity).insertContact(contact)) {
|
||||||
contactsImported++
|
contactsImported++
|
||||||
|
@ -5,12 +5,12 @@ import com.simplemobiletools.commons.extensions.normalizeString
|
|||||||
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.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 nickname: String,
|
data class Contact(val id: Int, var prefix: String, var firstName: String, var middleName: String, var surname: String, var suffix: String, var nickname: String,
|
||||||
var photoUri: String, var phoneNumbers: ArrayList<PhoneNumber>, var emails: ArrayList<Email>, var addresses: ArrayList<Address>,
|
var photoUri: String, var phoneNumbers: ArrayList<PhoneNumber>, var emails: ArrayList<Email>, var addresses: ArrayList<Address>,
|
||||||
var events: ArrayList<Event>, var source: String, var starred: Int, val contactId: Int, val thumbnailUri: String, var photo: Bitmap?, var notes: String,
|
var events: ArrayList<Event>, var source: String, var starred: Int, val contactId: Int, val thumbnailUri: String, var photo: Bitmap?, var notes: String,
|
||||||
var groups: ArrayList<Group>, var organization: Organization, var websites: ArrayList<String>) : Comparable<Contact> {
|
var groups: ArrayList<Group>, var organization: Organization, var websites: ArrayList<String>, var cleanPhoneNumbers: ArrayList<PhoneNumber>) :
|
||||||
|
Comparable<Contact> {
|
||||||
companion object {
|
companion object {
|
||||||
var sorting = 0
|
var sorting = 0
|
||||||
var startWithSurname = false
|
var startWithSurname = false
|
||||||
@ -93,14 +93,11 @@ data class Contact(val id: Int, var prefix: String, var firstName: String, var m
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun getStringToCompare(): String {
|
fun getStringToCompare(): String {
|
||||||
val newPhoneNumbers = ArrayList<PhoneNumber>()
|
|
||||||
phoneNumbers.mapTo(newPhoneNumbers) { PhoneNumber(it.value.replace(PHONE_NUMBER_PATTERN.toRegex(), ""), 0, "") }
|
|
||||||
|
|
||||||
val newEmails = ArrayList<Email>()
|
val newEmails = ArrayList<Email>()
|
||||||
emails.mapTo(newEmails) { Email(it.value, 0, "") }
|
emails.mapTo(newEmails) { Email(it.value, 0, "") }
|
||||||
|
|
||||||
return copy(id = 0, prefix = "", firstName = getFullName().toLowerCase(), middleName = "", surname = "", suffix = "", nickname = "", photoUri = "",
|
return copy(id = 0, prefix = "", firstName = getFullName().toLowerCase(), middleName = "", surname = "", suffix = "", nickname = "", photoUri = "",
|
||||||
phoneNumbers = phoneNumbers, events = ArrayList(), addresses = ArrayList(), emails = newEmails, source = "", starred = 0,
|
phoneNumbers = ArrayList(), events = ArrayList(), addresses = ArrayList(), emails = newEmails, source = "", starred = 0,
|
||||||
contactId = 0, thumbnailUri = "", notes = "", groups = ArrayList(), websites = ArrayList(), organization = Organization("", "")).toString()
|
contactId = 0, thumbnailUri = "", notes = "", groups = ArrayList(), websites = ArrayList(), organization = Organization("", "")).toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user