updating commons with PhoneNumber containing multiple fields
This commit is contained in:
parent
07e906e19c
commit
591f473a1f
|
@ -62,7 +62,7 @@ android {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.github.SimpleMobileTools:Simple-Commons:4d36cc84e9'
|
||||
implementation 'com.github.SimpleMobileTools:Simple-Commons:1539cc92c2'
|
||||
implementation 'org.greenrobot:eventbus:3.2.0'
|
||||
implementation 'com.klinkerapps:android-smsmms:5.2.6'
|
||||
implementation 'com.github.tibbi:IndicatorFastScroll:4524cd0b61'
|
||||
|
|
|
@ -64,7 +64,7 @@ class NewConversationActivity : SimpleActivity() {
|
|||
val searchString = it
|
||||
val filteredContacts = ArrayList<SimpleContact>()
|
||||
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.normalizeString(), true) ||
|
||||
it.name.normalizeString().contains(searchString, true)) {
|
||||
|
@ -147,14 +147,14 @@ class NewConversationActivity : SimpleActivity() {
|
|||
if (phoneNumbers.size > 1) {
|
||||
val items = ArrayList<RadioItem>()
|
||||
phoneNumbers.forEachIndexed { index, phoneNumber ->
|
||||
items.add(RadioItem(index, phoneNumber, phoneNumber))
|
||||
items.add(RadioItem(index, phoneNumber.normalizedNumber, phoneNumber))
|
||||
}
|
||||
|
||||
RadioGroupDialog(this, items) {
|
||||
launchThreadActivity(it as String, contact.name)
|
||||
}
|
||||
} else {
|
||||
launchThreadActivity(phoneNumbers.first(), contact.name)
|
||||
launchThreadActivity(phoneNumbers.first().normalizedNumber, contact.name)
|
||||
}
|
||||
}.apply {
|
||||
contacts_list.adapter = this
|
||||
|
@ -193,7 +193,7 @@ class NewConversationActivity : SimpleActivity() {
|
|||
SimpleContactsHelper(this@NewConversationActivity).loadContactImage(contact.photoUri, suggested_contact_image, contact.name)
|
||||
suggestions_holder.addView(this)
|
||||
setOnClickListener {
|
||||
launchThreadActivity(contact.phoneNumbers.first(), contact.name)
|
||||
launchThreadActivity(contact.phoneNumbers.first().normalizedNumber, contact.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@ import com.klinker.android.send_message.Transaction
|
|||
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.helpers.*
|
||||
import com.simplemobiletools.commons.models.PhoneNumber
|
||||
import com.simplemobiletools.commons.models.SimpleContact
|
||||
import com.simplemobiletools.smsmessenger.R
|
||||
import com.simplemobiletools.smsmessenger.adapters.AutoCompleteTextViewAdapter
|
||||
|
@ -239,7 +240,7 @@ class ThreadActivity : SimpleActivity() {
|
|||
messages = getMessages(threadId)
|
||||
|
||||
val hasParticipantWithoutName = participants.any {
|
||||
it.phoneNumbers.contains(it.name)
|
||||
it.phoneNumbers.map { it.normalizedNumber }.contains(it.name)
|
||||
}
|
||||
|
||||
try {
|
||||
|
@ -256,8 +257,8 @@ class ThreadActivity : SimpleActivity() {
|
|||
if (privateContacts.isNotEmpty()) {
|
||||
val senderNumbersToReplace = HashMap<String, String>()
|
||||
participants.filter { it.doesHavePhoneNumber(it.name) }.forEach { participant ->
|
||||
privateContacts.firstOrNull { it.doesHavePhoneNumber(participant.phoneNumbers.first()) }?.apply {
|
||||
senderNumbersToReplace[participant.phoneNumbers.first()] = name
|
||||
privateContacts.firstOrNull { it.doesHavePhoneNumber(participant.phoneNumbers.first().normalizedNumber) }?.apply {
|
||||
senderNumbersToReplace[participant.phoneNumbers.first().normalizedNumber] = name
|
||||
participant.name = name
|
||||
participant.photoUri = photoUri
|
||||
}
|
||||
|
@ -279,7 +280,8 @@ class ThreadActivity : SimpleActivity() {
|
|||
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)
|
||||
}
|
||||
|
||||
|
@ -335,7 +337,8 @@ class ThreadActivity : SimpleActivity() {
|
|||
|
||||
confirm_inserted_number?.setOnClickListener {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
@ -371,7 +374,7 @@ class ThreadActivity : SimpleActivity() {
|
|||
val numbers = HashSet<String>()
|
||||
participants.forEach {
|
||||
it.phoneNumbers.forEach {
|
||||
numbers.add(it)
|
||||
numbers.add(it.normalizedNumber)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -466,7 +469,7 @@ class ThreadActivity : SimpleActivity() {
|
|||
val numbers = ArrayList<String>()
|
||||
participants.forEach {
|
||||
it.phoneNumbers.forEach {
|
||||
numbers.add(it)
|
||||
numbers.add(it.normalizedNumber)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -498,7 +501,7 @@ class ThreadActivity : SimpleActivity() {
|
|||
val numbers = ArrayList<String>()
|
||||
participants.forEach {
|
||||
it.phoneNumbers.forEach {
|
||||
numbers.add(it)
|
||||
numbers.add(it.normalizedNumber)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -529,7 +532,7 @@ class ThreadActivity : SimpleActivity() {
|
|||
}
|
||||
|
||||
private fun dialNumber() {
|
||||
val phoneNumber = participants.first().phoneNumbers.first()
|
||||
val phoneNumber = participants.first().phoneNumbers.first().normalizedNumber
|
||||
dialNumber(phoneNumber)
|
||||
}
|
||||
|
||||
|
@ -761,7 +764,7 @@ class ThreadActivity : SimpleActivity() {
|
|||
val numbers = ArrayList<String>()
|
||||
participants.forEach {
|
||||
it.phoneNumbers.forEach {
|
||||
numbers.add(it)
|
||||
numbers.add(it.normalizedNumber)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -894,15 +897,15 @@ class ThreadActivity : SimpleActivity() {
|
|||
for (participant in participants) {
|
||||
participant.phoneNumbers = participant.phoneNumbers.map {
|
||||
val numberWithoutPlus = number.replace("+", "")
|
||||
if (numberWithoutPlus == it.trim()) {
|
||||
if (participant.name == it) {
|
||||
if (numberWithoutPlus == it.normalizedNumber.trim()) {
|
||||
if (participant.name == it.normalizedNumber) {
|
||||
participant.name = number
|
||||
}
|
||||
number
|
||||
} else {
|
||||
it
|
||||
}
|
||||
} as ArrayList<String>
|
||||
} as ArrayList<PhoneNumber>
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ class AutoCompleteTextViewAdapter(val activity: SimpleActivity, val contacts: Ar
|
|||
|
||||
if (contact != null) {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ class ContactsAdapter(
|
|||
}
|
||||
|
||||
findViewById<TextView>(R.id.item_contact_number).apply {
|
||||
text = contact.phoneNumbers.first()
|
||||
text = contact.phoneNumbers.first().normalizedNumber
|
||||
setTextColor(textColor)
|
||||
setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize)
|
||||
}
|
||||
|
|
|
@ -237,7 +237,7 @@ class ThreadAdapter(
|
|||
thread_message_sender_photo.beVisible()
|
||||
thread_message_sender_photo.setOnClickListener {
|
||||
val contact = message.participants.first()
|
||||
context.getContactFromAddress(contact.phoneNumbers.first()) {
|
||||
context.getContactFromAddress(contact.phoneNumbers.first().normalizedNumber) {
|
||||
if (it != null) {
|
||||
(activity as ThreadActivity).startContactDetailsIntent(it)
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ import androidx.core.app.NotificationCompat
|
|||
import androidx.core.app.RemoteInput
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.helpers.*
|
||||
import com.simplemobiletools.commons.models.PhoneNumber
|
||||
import com.simplemobiletools.commons.models.SimpleContact
|
||||
import com.simplemobiletools.smsmessenger.R
|
||||
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 subscriptionId = cursor.getIntValue(Sms.SUBSCRIPTION_ID)
|
||||
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 message = Message(id, body, type, status, arrayListOf(participant), date, read, thread, isMMS, null, senderName, photoUri, subscriptionId)
|
||||
messages.add(message)
|
||||
|
@ -382,10 +384,11 @@ fun Context.getThreadParticipants(threadId: Long, contactsMap: HashMap<Int, Simp
|
|||
return@forEach
|
||||
}
|
||||
|
||||
val phoneNumber = getPhoneNumberFromAddressId(addressId)
|
||||
val namePhoto = getNameAndPhotoFromPhoneNumber(phoneNumber)
|
||||
val number = getPhoneNumberFromAddressId(addressId)
|
||||
val namePhoto = getNameAndPhotoFromPhoneNumber(number)
|
||||
val name = namePhoto.name
|
||||
val photoUri = namePhoto.photoUri ?: ""
|
||||
val phoneNumber = PhoneNumber(number, 0, "", number)
|
||||
val contact = SimpleContact(addressId, addressId, name, photoUri, arrayListOf(phoneNumber), ArrayList(), ArrayList())
|
||||
participants.add(contact)
|
||||
}
|
||||
|
@ -465,7 +468,7 @@ fun Context.getSuggestedContacts(privateContacts: ArrayList<SimpleContact>): Arr
|
|||
return@queryCursor
|
||||
} else if (namePhoto.name == senderNumber) {
|
||||
if (privateContacts.isNotEmpty()) {
|
||||
val privateContact = privateContacts.firstOrNull { it.phoneNumbers.first() == senderNumber }
|
||||
val privateContact = privateContacts.firstOrNull { it.phoneNumbers.first().normalizedNumber == senderNumber }
|
||||
if (privateContact != null) {
|
||||
senderName = privateContact.name
|
||||
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())
|
||||
if (!contacts.map { it.phoneNumbers.first().trimToComparableNumber() }.contains(senderNumber.trimToComparableNumber())) {
|
||||
val phoneNumber = PhoneNumber(senderNumber, 0, "", senderNumber)
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -117,7 +117,7 @@ class ImageCompressor(private val context: Context) {
|
|||
|
||||
fun isSatisfied(imageFile: File): Boolean {
|
||||
// If size requirement is not met and maxIteration is reached
|
||||
if(iteration >= maxIteration && imageFile.length() >= maxFileSize) {
|
||||
if (iteration >= maxIteration && imageFile.length() >= maxFileSize) {
|
||||
throw Exception("Unable to compress image to targeted size")
|
||||
}
|
||||
return imageFile.length() <= maxFileSize
|
||||
|
@ -180,5 +180,4 @@ class ImageCompressor(private val context: Context) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ import com.simplemobiletools.smsmessenger.extensions.*
|
|||
class MmsReceiver : com.klinker.android.send_message.MmsReceivedReceiver() {
|
||||
override fun onMessageReceived(context: Context, messageUri: Uri) {
|
||||
val mms = context.getLatestMMS() ?: return
|
||||
val address = mms.participants.firstOrNull()?.phoneNumbers?.first() ?: ""
|
||||
val address = mms.participants.firstOrNull()?.phoneNumbers?.first()?.normalizedNumber ?: ""
|
||||
if (context.isNumberBlocked(address)) {
|
||||
return
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ import com.bumptech.glide.request.RequestOptions
|
|||
import com.simplemobiletools.commons.extensions.isNumberBlocked
|
||||
import com.simplemobiletools.commons.helpers.SimpleContactsHelper
|
||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||
import com.simplemobiletools.commons.models.PhoneNumber
|
||||
import com.simplemobiletools.commons.models.SimpleContact
|
||||
import com.simplemobiletools.smsmessenger.R
|
||||
import com.simplemobiletools.smsmessenger.extensions.*
|
||||
|
@ -63,7 +64,8 @@ class SmsReceiver : BroadcastReceiver() {
|
|||
}
|
||||
|
||||
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 messageDate = (date / 1000).toInt()
|
||||
|
||||
|
|
Loading…
Reference in New Issue