updating commons with PhoneNumber containing multiple fields

This commit is contained in:
tibbi 2022-02-06 22:44:20 +01:00
parent 07e906e19c
commit 591f473a1f
10 changed files with 39 additions and 31 deletions

View File

@ -62,7 +62,7 @@ android {
} }
dependencies { dependencies {
implementation 'com.github.SimpleMobileTools:Simple-Commons:4d36cc84e9' implementation 'com.github.SimpleMobileTools:Simple-Commons:1539cc92c2'
implementation 'org.greenrobot:eventbus:3.2.0' implementation 'org.greenrobot:eventbus:3.2.0'
implementation 'com.klinkerapps:android-smsmms:5.2.6' implementation 'com.klinkerapps:android-smsmms:5.2.6'
implementation 'com.github.tibbi:IndicatorFastScroll:4524cd0b61' implementation 'com.github.tibbi:IndicatorFastScroll:4524cd0b61'

View File

@ -64,7 +64,7 @@ class NewConversationActivity : SimpleActivity() {
val searchString = it val searchString = it
val filteredContacts = ArrayList<SimpleContact>() val filteredContacts = ArrayList<SimpleContact>()
allContacts.forEach { allContacts.forEach {
if (it.phoneNumbers.any { it.contains(searchString, true) } || if (it.phoneNumbers.any { it.normalizedNumber.contains(searchString, true) } ||
it.name.contains(searchString, true) || it.name.contains(searchString, true) ||
it.name.contains(searchString.normalizeString(), true) || it.name.contains(searchString.normalizeString(), true) ||
it.name.normalizeString().contains(searchString, true)) { it.name.normalizeString().contains(searchString, true)) {
@ -147,14 +147,14 @@ class NewConversationActivity : SimpleActivity() {
if (phoneNumbers.size > 1) { if (phoneNumbers.size > 1) {
val items = ArrayList<RadioItem>() val items = ArrayList<RadioItem>()
phoneNumbers.forEachIndexed { index, phoneNumber -> phoneNumbers.forEachIndexed { index, phoneNumber ->
items.add(RadioItem(index, phoneNumber, phoneNumber)) items.add(RadioItem(index, phoneNumber.normalizedNumber, phoneNumber))
} }
RadioGroupDialog(this, items) { RadioGroupDialog(this, items) {
launchThreadActivity(it as String, contact.name) launchThreadActivity(it as String, contact.name)
} }
} else { } else {
launchThreadActivity(phoneNumbers.first(), contact.name) launchThreadActivity(phoneNumbers.first().normalizedNumber, contact.name)
} }
}.apply { }.apply {
contacts_list.adapter = this contacts_list.adapter = this
@ -193,7 +193,7 @@ class NewConversationActivity : SimpleActivity() {
SimpleContactsHelper(this@NewConversationActivity).loadContactImage(contact.photoUri, suggested_contact_image, contact.name) SimpleContactsHelper(this@NewConversationActivity).loadContactImage(contact.photoUri, suggested_contact_image, contact.name)
suggestions_holder.addView(this) suggestions_holder.addView(this)
setOnClickListener { setOnClickListener {
launchThreadActivity(contact.phoneNumbers.first(), contact.name) launchThreadActivity(contact.phoneNumbers.first().normalizedNumber, contact.name)
} }
} }
} }

View File

@ -37,6 +37,7 @@ import com.klinker.android.send_message.Transaction
import com.simplemobiletools.commons.dialogs.ConfirmationDialog import com.simplemobiletools.commons.dialogs.ConfirmationDialog
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.* import com.simplemobiletools.commons.helpers.*
import com.simplemobiletools.commons.models.PhoneNumber
import com.simplemobiletools.commons.models.SimpleContact import com.simplemobiletools.commons.models.SimpleContact
import com.simplemobiletools.smsmessenger.R import com.simplemobiletools.smsmessenger.R
import com.simplemobiletools.smsmessenger.adapters.AutoCompleteTextViewAdapter import com.simplemobiletools.smsmessenger.adapters.AutoCompleteTextViewAdapter
@ -239,7 +240,7 @@ class ThreadActivity : SimpleActivity() {
messages = getMessages(threadId) messages = getMessages(threadId)
val hasParticipantWithoutName = participants.any { val hasParticipantWithoutName = participants.any {
it.phoneNumbers.contains(it.name) it.phoneNumbers.map { it.normalizedNumber }.contains(it.name)
} }
try { try {
@ -256,8 +257,8 @@ class ThreadActivity : SimpleActivity() {
if (privateContacts.isNotEmpty()) { if (privateContacts.isNotEmpty()) {
val senderNumbersToReplace = HashMap<String, String>() val senderNumbersToReplace = HashMap<String, String>()
participants.filter { it.doesHavePhoneNumber(it.name) }.forEach { participant -> participants.filter { it.doesHavePhoneNumber(it.name) }.forEach { participant ->
privateContacts.firstOrNull { it.doesHavePhoneNumber(participant.phoneNumbers.first()) }?.apply { privateContacts.firstOrNull { it.doesHavePhoneNumber(participant.phoneNumbers.first().normalizedNumber) }?.apply {
senderNumbersToReplace[participant.phoneNumbers.first()] = name senderNumbersToReplace[participant.phoneNumbers.first().normalizedNumber] = name
participant.name = name participant.name = name
participant.photoUri = photoUri participant.photoUri = photoUri
} }
@ -279,7 +280,8 @@ class ThreadActivity : SimpleActivity() {
return@ensureBackgroundThread return@ensureBackgroundThread
} }
val contact = SimpleContact(0, 0, name, "", arrayListOf(number), ArrayList(), ArrayList()) val phoneNumber = PhoneNumber(number, 0, "", number)
val contact = SimpleContact(0, 0, name, "", arrayListOf(phoneNumber), ArrayList(), ArrayList())
participants.add(contact) participants.add(contact)
} }
@ -335,7 +337,8 @@ class ThreadActivity : SimpleActivity() {
confirm_inserted_number?.setOnClickListener { confirm_inserted_number?.setOnClickListener {
val number = add_contact_or_number.value val number = add_contact_or_number.value
val contact = SimpleContact(number.hashCode(), number.hashCode(), number, "", arrayListOf(number), ArrayList(), ArrayList()) val phoneNumber = PhoneNumber(number, 0, "", number)
val contact = SimpleContact(number.hashCode(), number.hashCode(), number, "", arrayListOf(phoneNumber), ArrayList(), ArrayList())
addSelectedContact(contact) addSelectedContact(contact)
} }
} }
@ -371,7 +374,7 @@ class ThreadActivity : SimpleActivity() {
val numbers = HashSet<String>() val numbers = HashSet<String>()
participants.forEach { participants.forEach {
it.phoneNumbers.forEach { it.phoneNumbers.forEach {
numbers.add(it) numbers.add(it.normalizedNumber)
} }
} }
@ -466,7 +469,7 @@ class ThreadActivity : SimpleActivity() {
val numbers = ArrayList<String>() val numbers = ArrayList<String>()
participants.forEach { participants.forEach {
it.phoneNumbers.forEach { it.phoneNumbers.forEach {
numbers.add(it) numbers.add(it.normalizedNumber)
} }
} }
@ -498,7 +501,7 @@ class ThreadActivity : SimpleActivity() {
val numbers = ArrayList<String>() val numbers = ArrayList<String>()
participants.forEach { participants.forEach {
it.phoneNumbers.forEach { it.phoneNumbers.forEach {
numbers.add(it) numbers.add(it.normalizedNumber)
} }
} }
@ -529,7 +532,7 @@ class ThreadActivity : SimpleActivity() {
} }
private fun dialNumber() { private fun dialNumber() {
val phoneNumber = participants.first().phoneNumbers.first() val phoneNumber = participants.first().phoneNumbers.first().normalizedNumber
dialNumber(phoneNumber) dialNumber(phoneNumber)
} }
@ -761,7 +764,7 @@ class ThreadActivity : SimpleActivity() {
val numbers = ArrayList<String>() val numbers = ArrayList<String>()
participants.forEach { participants.forEach {
it.phoneNumbers.forEach { it.phoneNumbers.forEach {
numbers.add(it) numbers.add(it.normalizedNumber)
} }
} }
@ -894,15 +897,15 @@ class ThreadActivity : SimpleActivity() {
for (participant in participants) { for (participant in participants) {
participant.phoneNumbers = participant.phoneNumbers.map { participant.phoneNumbers = participant.phoneNumbers.map {
val numberWithoutPlus = number.replace("+", "") val numberWithoutPlus = number.replace("+", "")
if (numberWithoutPlus == it.trim()) { if (numberWithoutPlus == it.normalizedNumber.trim()) {
if (participant.name == it) { if (participant.name == it.normalizedNumber) {
participant.name = number participant.name = number
} }
number number
} else { } else {
it it
} }
} as ArrayList<String> } as ArrayList<PhoneNumber>
} }
} }

View File

@ -42,7 +42,7 @@ class AutoCompleteTextViewAdapter(val activity: SimpleActivity, val contacts: Ar
if (contact != null) { if (contact != null) {
findViewById<TextView>(R.id.item_contact_name).text = contact.name findViewById<TextView>(R.id.item_contact_name).text = contact.name
findViewById<TextView>(R.id.item_contact_number).text = contact.phoneNumbers.first() findViewById<TextView>(R.id.item_contact_number).text = contact.phoneNumbers.first().normalizedNumber
SimpleContactsHelper(context).loadContactImage(contact.photoUri, findViewById(R.id.item_contact_image), contact.name) SimpleContactsHelper(context).loadContactImage(contact.photoUri, findViewById(R.id.item_contact_image), contact.name)
} }
} }

View File

@ -69,7 +69,7 @@ class ContactsAdapter(
} }
findViewById<TextView>(R.id.item_contact_number).apply { findViewById<TextView>(R.id.item_contact_number).apply {
text = contact.phoneNumbers.first() text = contact.phoneNumbers.first().normalizedNumber
setTextColor(textColor) setTextColor(textColor)
setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize) setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize)
} }

View File

@ -237,7 +237,7 @@ class ThreadAdapter(
thread_message_sender_photo.beVisible() thread_message_sender_photo.beVisible()
thread_message_sender_photo.setOnClickListener { thread_message_sender_photo.setOnClickListener {
val contact = message.participants.first() val contact = message.participants.first()
context.getContactFromAddress(contact.phoneNumbers.first()) { context.getContactFromAddress(contact.phoneNumbers.first().normalizedNumber) {
if (it != null) { if (it != null) {
(activity as ThreadActivity).startContactDetailsIntent(it) (activity as ThreadActivity).startContactDetailsIntent(it)
} }

View File

@ -23,6 +23,7 @@ import androidx.core.app.NotificationCompat
import androidx.core.app.RemoteInput import androidx.core.app.RemoteInput
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.* import com.simplemobiletools.commons.helpers.*
import com.simplemobiletools.commons.models.PhoneNumber
import com.simplemobiletools.commons.models.SimpleContact import com.simplemobiletools.commons.models.SimpleContact
import com.simplemobiletools.smsmessenger.R import com.simplemobiletools.smsmessenger.R
import com.simplemobiletools.smsmessenger.activities.ThreadActivity import com.simplemobiletools.smsmessenger.activities.ThreadActivity
@ -99,7 +100,8 @@ fun Context.getMessages(threadId: Long): ArrayList<Message> {
val thread = cursor.getLongValue(Sms.THREAD_ID) val thread = cursor.getLongValue(Sms.THREAD_ID)
val subscriptionId = cursor.getIntValue(Sms.SUBSCRIPTION_ID) val subscriptionId = cursor.getIntValue(Sms.SUBSCRIPTION_ID)
val status = cursor.getIntValue(Sms.STATUS) val status = cursor.getIntValue(Sms.STATUS)
val participant = SimpleContact(0, 0, senderName, photoUri, arrayListOf(senderNumber), ArrayList(), ArrayList()) val phoneNumber = PhoneNumber(senderNumber, 0, "", senderNumber)
val participant = SimpleContact(0, 0, senderName, photoUri, arrayListOf(phoneNumber), ArrayList(), ArrayList())
val isMMS = false val isMMS = false
val message = Message(id, body, type, status, arrayListOf(participant), date, read, thread, isMMS, null, senderName, photoUri, subscriptionId) val message = Message(id, body, type, status, arrayListOf(participant), date, read, thread, isMMS, null, senderName, photoUri, subscriptionId)
messages.add(message) messages.add(message)
@ -382,10 +384,11 @@ fun Context.getThreadParticipants(threadId: Long, contactsMap: HashMap<Int, Simp
return@forEach return@forEach
} }
val phoneNumber = getPhoneNumberFromAddressId(addressId) val number = getPhoneNumberFromAddressId(addressId)
val namePhoto = getNameAndPhotoFromPhoneNumber(phoneNumber) val namePhoto = getNameAndPhotoFromPhoneNumber(number)
val name = namePhoto.name val name = namePhoto.name
val photoUri = namePhoto.photoUri ?: "" val photoUri = namePhoto.photoUri ?: ""
val phoneNumber = PhoneNumber(number, 0, "", number)
val contact = SimpleContact(addressId, addressId, name, photoUri, arrayListOf(phoneNumber), ArrayList(), ArrayList()) val contact = SimpleContact(addressId, addressId, name, photoUri, arrayListOf(phoneNumber), ArrayList(), ArrayList())
participants.add(contact) participants.add(contact)
} }
@ -465,7 +468,7 @@ fun Context.getSuggestedContacts(privateContacts: ArrayList<SimpleContact>): Arr
return@queryCursor return@queryCursor
} else if (namePhoto.name == senderNumber) { } else if (namePhoto.name == senderNumber) {
if (privateContacts.isNotEmpty()) { if (privateContacts.isNotEmpty()) {
val privateContact = privateContacts.firstOrNull { it.phoneNumbers.first() == senderNumber } val privateContact = privateContacts.firstOrNull { it.phoneNumbers.first().normalizedNumber == senderNumber }
if (privateContact != null) { if (privateContact != null) {
senderName = privateContact.name senderName = privateContact.name
photoUri = privateContact.photoUri photoUri = privateContact.photoUri
@ -477,8 +480,9 @@ fun Context.getSuggestedContacts(privateContacts: ArrayList<SimpleContact>): Arr
} }
} }
val contact = SimpleContact(0, 0, senderName, photoUri, arrayListOf(senderNumber), ArrayList(), ArrayList()) val phoneNumber = PhoneNumber(senderNumber, 0, "", senderNumber)
if (!contacts.map { it.phoneNumbers.first().trimToComparableNumber() }.contains(senderNumber.trimToComparableNumber())) { val contact = SimpleContact(0, 0, senderName, photoUri, arrayListOf(phoneNumber), ArrayList(), ArrayList())
if (!contacts.map { it.phoneNumbers.first().normalizedNumber.trimToComparableNumber() }.contains(senderNumber.trimToComparableNumber())) {
contacts.add(contact) contacts.add(contact)
} }
} }

View File

@ -180,5 +180,4 @@ class ImageCompressor(private val context: Context) {
} }
} }
} }
} }

View File

@ -14,7 +14,7 @@ import com.simplemobiletools.smsmessenger.extensions.*
class MmsReceiver : com.klinker.android.send_message.MmsReceivedReceiver() { class MmsReceiver : com.klinker.android.send_message.MmsReceivedReceiver() {
override fun onMessageReceived(context: Context, messageUri: Uri) { override fun onMessageReceived(context: Context, messageUri: Uri) {
val mms = context.getLatestMMS() ?: return val mms = context.getLatestMMS() ?: return
val address = mms.participants.firstOrNull()?.phoneNumbers?.first() ?: "" val address = mms.participants.firstOrNull()?.phoneNumbers?.first()?.normalizedNumber ?: ""
if (context.isNumberBlocked(address)) { if (context.isNumberBlocked(address)) {
return return
} }

View File

@ -14,6 +14,7 @@ import com.bumptech.glide.request.RequestOptions
import com.simplemobiletools.commons.extensions.isNumberBlocked import com.simplemobiletools.commons.extensions.isNumberBlocked
import com.simplemobiletools.commons.helpers.SimpleContactsHelper import com.simplemobiletools.commons.helpers.SimpleContactsHelper
import com.simplemobiletools.commons.helpers.ensureBackgroundThread import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.commons.models.PhoneNumber
import com.simplemobiletools.commons.models.SimpleContact import com.simplemobiletools.commons.models.SimpleContact
import com.simplemobiletools.smsmessenger.R import com.simplemobiletools.smsmessenger.R
import com.simplemobiletools.smsmessenger.extensions.* import com.simplemobiletools.smsmessenger.extensions.*
@ -63,7 +64,8 @@ class SmsReceiver : BroadcastReceiver() {
} }
val senderName = context.getNameFromAddress(address, privateCursor) val senderName = context.getNameFromAddress(address, privateCursor)
val participant = SimpleContact(0, 0, senderName, "", arrayListOf(address), ArrayList(), ArrayList()) val phoneNumber = PhoneNumber(address, 0, "", address)
val participant = SimpleContact(0, 0, senderName, "", arrayListOf(phoneNumber), ArrayList(), ArrayList())
val participants = arrayListOf(participant) val participants = arrayListOf(participant)
val messageDate = (date / 1000).toInt() val messageDate = (date / 1000).toInt()