properly handle contacts with multiple phone numbers
This commit is contained in:
parent
cdad404b2a
commit
41fb730511
|
@ -57,7 +57,7 @@ android {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.simplemobiletools:commons:5.29.7'
|
||||
implementation 'com.simplemobiletools:commons:5.29.19'
|
||||
implementation 'org.greenrobot:eventbus:3.2.0'
|
||||
implementation 'com.klinkerapps:android-smsmms:5.2.6'
|
||||
implementation 'com.github.tibbi:IndicatorFastScroll:08f512858a'
|
||||
|
|
|
@ -173,7 +173,7 @@ class MainActivity : SimpleActivity() {
|
|||
}
|
||||
|
||||
private fun getNewConversations(cachedConversations: ArrayList<Conversation>) {
|
||||
val privateCursor = getMyContactsContentProviderCursorLoader().loadInBackground()
|
||||
val privateCursor = getMyContactsCursor().loadInBackground()
|
||||
ensureBackgroundThread {
|
||||
val conversations = getConversations()
|
||||
|
||||
|
@ -181,9 +181,11 @@ class MainActivity : SimpleActivity() {
|
|||
val privateContacts = MyContactsContentProvider.getSimpleContacts(this, privateCursor)
|
||||
if (privateContacts.isNotEmpty()) {
|
||||
conversations.filter { it.title == it.phoneNumber }.forEach { conversation ->
|
||||
privateContacts.firstOrNull { it.phoneNumber == conversation.phoneNumber }?.apply {
|
||||
conversation.title = name
|
||||
conversation.photoUri = photoUri
|
||||
privateContacts.forEach { contact ->
|
||||
if (contact.doesContainPhoneNumber(conversation.phoneNumber)) {
|
||||
conversation.title = contact.name
|
||||
conversation.photoUri = contact.photoUri
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ class NewConversationActivity : SimpleActivity() {
|
|||
val searchString = it
|
||||
val filteredContacts = ArrayList<SimpleContact>()
|
||||
allContacts.forEach {
|
||||
if (it.phoneNumber.contains(searchString, true) || it.name.contains(searchString, true)) {
|
||||
if (it.phoneNumbers.any { it.contains(searchString, true) } || it.name.contains(searchString, true)) {
|
||||
filteredContacts.add(it)
|
||||
}
|
||||
}
|
||||
|
@ -134,7 +134,7 @@ class NewConversationActivity : SimpleActivity() {
|
|||
|
||||
ContactsAdapter(this, contacts, contacts_list, null) {
|
||||
hideKeyboard()
|
||||
launchThreadActivity((it as SimpleContact).phoneNumber, it.name)
|
||||
launchThreadActivity((it as SimpleContact).phoneNumbers.first(), it.name)
|
||||
}.apply {
|
||||
contacts_list.adapter = this
|
||||
}
|
||||
|
@ -143,7 +143,7 @@ class NewConversationActivity : SimpleActivity() {
|
|||
}
|
||||
|
||||
private fun fillSuggestedContacts(callback: () -> Unit) {
|
||||
val privateCursor = getMyContactsContentProviderCursorLoader().loadInBackground()
|
||||
val privateCursor = getMyContactsCursor().loadInBackground()
|
||||
ensureBackgroundThread {
|
||||
privateContacts = MyContactsContentProvider.getSimpleContacts(this, privateCursor)
|
||||
val suggestions = getSuggestedContacts(privateContacts)
|
||||
|
@ -162,7 +162,7 @@ class NewConversationActivity : SimpleActivity() {
|
|||
SimpleContactsHelper(this@NewConversationActivity).loadContactImage(contact.photoUri, suggested_contact_image, contact.name)
|
||||
suggestions_holder.addView(this)
|
||||
setOnClickListener {
|
||||
launchThreadActivity(contact.phoneNumber, contact.name)
|
||||
launchThreadActivity(contact.phoneNumbers.first(), contact.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,7 +87,7 @@ class ThreadActivity : SimpleActivity() {
|
|||
}
|
||||
|
||||
private fun setupThread() {
|
||||
val privateCursor = getMyContactsContentProviderCursorLoader().loadInBackground()
|
||||
val privateCursor = getMyContactsCursor().loadInBackground()
|
||||
ensureBackgroundThread {
|
||||
messages = getMessages(threadId)
|
||||
participants = if (messages.isEmpty()) {
|
||||
|
@ -100,9 +100,9 @@ class ThreadActivity : SimpleActivity() {
|
|||
privateContacts = MyContactsContentProvider.getSimpleContacts(this, privateCursor)
|
||||
if (privateContacts.isNotEmpty()) {
|
||||
val senderNumbersToReplace = HashMap<String, String>()
|
||||
participants.filter { it.name == it.phoneNumber }.forEach { participant ->
|
||||
privateContacts.firstOrNull { it.phoneNumber == participant.phoneNumber }?.apply {
|
||||
senderNumbersToReplace[participant.phoneNumber] = name
|
||||
participants.filter { it.doesContainPhoneNumber(it.name) }.forEach { participant ->
|
||||
privateContacts.firstOrNull { it.doesContainPhoneNumber(participant.phoneNumbers.first()) }?.apply {
|
||||
senderNumbersToReplace[participant.phoneNumbers.first()] = name
|
||||
participant.name = name
|
||||
participant.photoUri = photoUri
|
||||
}
|
||||
|
@ -124,7 +124,7 @@ class ThreadActivity : SimpleActivity() {
|
|||
return@ensureBackgroundThread
|
||||
}
|
||||
|
||||
val contact = SimpleContact(0, 0, name, "", number)
|
||||
val contact = SimpleContact(0, 0, name, "", arrayListOf(number))
|
||||
participants.add(contact)
|
||||
}
|
||||
|
||||
|
@ -241,7 +241,7 @@ class ThreadActivity : SimpleActivity() {
|
|||
|
||||
confirm_inserted_number?.setOnClickListener {
|
||||
val number = add_contact_or_number.value
|
||||
val contact = SimpleContact(number.hashCode(), number.hashCode(), number, "", number)
|
||||
val contact = SimpleContact(number.hashCode(), number.hashCode(), number, "", arrayListOf(number))
|
||||
addSelectedContact(contact)
|
||||
}
|
||||
}
|
||||
|
@ -266,7 +266,13 @@ class ThreadActivity : SimpleActivity() {
|
|||
hideKeyboard()
|
||||
thread_add_contacts.beGone()
|
||||
|
||||
val numbers = participants.map { it.phoneNumber }.toSet()
|
||||
val numbers = HashSet<String>()
|
||||
participants.forEach {
|
||||
it.phoneNumbers.forEach {
|
||||
numbers.add(it)
|
||||
}
|
||||
}
|
||||
|
||||
val newThreadId = getThreadId(numbers).toInt()
|
||||
if (threadId != newThreadId) {
|
||||
Intent(this, ThreadActivity::class.java).apply {
|
||||
|
@ -305,7 +311,13 @@ class ThreadActivity : SimpleActivity() {
|
|||
availableSIMCards.add(SIMCard)
|
||||
}
|
||||
|
||||
val numbers = participants.map { it.phoneNumber }.toTypedArray()
|
||||
val numbers = ArrayList<String>()
|
||||
participants.forEach {
|
||||
it.phoneNumbers.forEach {
|
||||
numbers.add(it)
|
||||
}
|
||||
}
|
||||
|
||||
currentSIMCardIndex = availableSIMs.indexOfFirstOrNull { it.subscriptionId == config.getUseSIMIdAtNumber(numbers.first()) } ?: 0
|
||||
|
||||
thread_select_sim_icon.applyColorFilter(config.textColor)
|
||||
|
@ -327,7 +339,13 @@ class ThreadActivity : SimpleActivity() {
|
|||
}
|
||||
|
||||
private fun blockNumber() {
|
||||
val numbers = participants.map { it.phoneNumber }
|
||||
val numbers = ArrayList<String>()
|
||||
participants.forEach {
|
||||
it.phoneNumbers.forEach {
|
||||
numbers.add(it)
|
||||
}
|
||||
}
|
||||
|
||||
val numbersString = TextUtils.join(", ", numbers)
|
||||
val question = String.format(resources.getString(R.string.block_confirmation), numbersString)
|
||||
|
||||
|
@ -518,7 +536,13 @@ class ThreadActivity : SimpleActivity() {
|
|||
return
|
||||
}
|
||||
|
||||
val numbers = participants.map { it.phoneNumber }.toTypedArray()
|
||||
val numbers = ArrayList<String>()
|
||||
participants.forEach {
|
||||
it.phoneNumbers.forEach {
|
||||
numbers.add(it)
|
||||
}
|
||||
}
|
||||
|
||||
val settings = Settings()
|
||||
settings.useSystemSending = true
|
||||
|
||||
|
@ -531,7 +555,7 @@ class ThreadActivity : SimpleActivity() {
|
|||
}
|
||||
|
||||
val transaction = Transaction(this, settings)
|
||||
val message = com.klinker.android.send_message.Message(msg, numbers)
|
||||
val message = com.klinker.android.send_message.Message(msg, numbers.toTypedArray())
|
||||
|
||||
if (attachmentUris.isNotEmpty()) {
|
||||
for (uri in attachmentUris) {
|
||||
|
|
|
@ -31,7 +31,7 @@ class AutoCompleteTextViewAdapter(val activity: SimpleActivity, val contacts: Ar
|
|||
}
|
||||
|
||||
findViewById<TextView>(R.id.item_contact_name).text = contact.name
|
||||
findViewById<TextView>(R.id.item_contact_number).text = contact.phoneNumber
|
||||
findViewById<TextView>(R.id.item_contact_number).text = contact.phoneNumbers.first()
|
||||
|
||||
SimpleContactsHelper(context).loadContactImage(contact.photoUri, findViewById(R.id.item_contact_image), contact.name)
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ class AutoCompleteTextViewAdapter(val activity: SimpleActivity, val contacts: Ar
|
|||
resultList.clear()
|
||||
val searchString = constraint.toString().normalizeString()
|
||||
contacts.forEach {
|
||||
if (it.phoneNumber.contains(searchString, true) || it.name.contains(searchString, true)) {
|
||||
if (it.doesContainPhoneNumber(searchString) || it.name.contains(searchString, true)) {
|
||||
resultList.add(it)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ class ContactsAdapter(activity: SimpleActivity, var contacts: ArrayList<SimpleCo
|
|||
}
|
||||
|
||||
findViewById<TextView>(R.id.item_contact_number).apply {
|
||||
text = contact.phoneNumber
|
||||
text = contact.phoneNumbers.first()
|
||||
setTextColor(textColor)
|
||||
setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize)
|
||||
}
|
||||
|
|
|
@ -83,7 +83,7 @@ fun Context.getMessages(threadId: Int): ArrayList<Message> {
|
|||
val read = cursor.getIntValue(Sms.READ) == 1
|
||||
val thread = cursor.getIntValue(Sms.THREAD_ID)
|
||||
val subscriptionId = cursor.getIntValue(Sms.SUBSCRIPTION_ID)
|
||||
val participant = SimpleContact(0, 0, senderName, photoUri, senderNumber)
|
||||
val participant = SimpleContact(0, 0, senderName, photoUri, arrayListOf(senderNumber))
|
||||
val isMMS = false
|
||||
val message = Message(id, body, type, arrayListOf(participant), date, read, thread, isMMS, null, senderName, photoUri, subscriptionId)
|
||||
messages.add(message)
|
||||
|
@ -334,7 +334,7 @@ fun Context.getThreadParticipants(threadId: Int, contactsMap: HashMap<Int, Simpl
|
|||
val namePhoto = getNameAndPhotoFromPhoneNumber(phoneNumber)
|
||||
val name = namePhoto?.name ?: ""
|
||||
val photoUri = namePhoto?.photoUri ?: ""
|
||||
val contact = SimpleContact(addressId, addressId, name, photoUri, phoneNumber)
|
||||
val contact = SimpleContact(addressId, addressId, name, photoUri, arrayListOf(phoneNumber))
|
||||
participants.add(contact)
|
||||
}
|
||||
}
|
||||
|
@ -403,7 +403,7 @@ fun Context.getSuggestedContacts(privateContacts: ArrayList<SimpleContact>): Arr
|
|||
return@queryCursor
|
||||
} else if (namePhoto.name == senderNumber) {
|
||||
if (privateContacts.isNotEmpty()) {
|
||||
val privateContact = privateContacts.firstOrNull { it.phoneNumber == senderNumber }
|
||||
val privateContact = privateContacts.firstOrNull { it.phoneNumbers.first() == senderNumber }
|
||||
if (privateContact != null) {
|
||||
senderName = privateContact.name
|
||||
photoUri = privateContact.photoUri
|
||||
|
@ -415,8 +415,8 @@ fun Context.getSuggestedContacts(privateContacts: ArrayList<SimpleContact>): Arr
|
|||
}
|
||||
}
|
||||
|
||||
val contact = SimpleContact(0, 0, senderName, photoUri, senderNumber)
|
||||
if (!contacts.map { it.phoneNumber.trimToComparableNumber() }.contains(senderNumber.trimToComparableNumber())) {
|
||||
val contact = SimpleContact(0, 0, senderName, photoUri, arrayListOf(senderNumber))
|
||||
if (!contacts.map { it.phoneNumbers.first().trimToComparableNumber() }.contains(senderNumber.trimToComparableNumber())) {
|
||||
contacts.add(contact)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ import com.simplemobiletools.smsmessenger.extensions.showReceivedMessageNotifica
|
|||
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()?.phoneNumber ?: ""
|
||||
val address = mms.participants.firstOrNull()?.phoneNumbers?.first() ?: ""
|
||||
if (context.isNumberBlocked(address)) {
|
||||
return
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ buildscript {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:3.6.3'
|
||||
classpath 'com.android.tools.build:gradle:4.0.1'
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#Fri Apr 03 09:58:13 CEST 2020
|
||||
#Mon Jul 27 21:27:47 CEST 2020
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
|
||||
|
|
Loading…
Reference in New Issue