properly handle contacts with multiple phone numbers
This commit is contained in:
parent
cdad404b2a
commit
41fb730511
10 changed files with 58 additions and 32 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue