mirror of
https://github.com/SimpleMobileTools/Simple-Dialer.git
synced 2025-06-05 21:49:23 +02:00
fix #172, show more accurate call screen info if a contact has multiple numbers
This commit is contained in:
@ -307,9 +307,13 @@ class CallActivity : SimpleActivity() {
|
||||
|
||||
caller_name_label.text = if (callContact!!.name.isNotEmpty()) callContact!!.name else getString(R.string.unknown_caller)
|
||||
if (callContact!!.number.isNotEmpty() && callContact!!.number != callContact!!.name) {
|
||||
caller_number_label.text = callContact!!.number
|
||||
caller_number.text = callContact!!.number
|
||||
|
||||
if (callContact!!.numberLabel.isNotEmpty()) {
|
||||
caller_number.text = "${callContact!!.number} - ${callContact!!.numberLabel}"
|
||||
}
|
||||
} else {
|
||||
caller_number_label.beGone()
|
||||
caller_number.beGone()
|
||||
}
|
||||
|
||||
if (avatar != null) {
|
||||
|
@ -2,12 +2,11 @@ package com.simplemobiletools.dialer.helpers
|
||||
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.telecom.Call
|
||||
import android.telecom.InCallService
|
||||
import android.telecom.VideoProfile
|
||||
import com.simplemobiletools.commons.extensions.getMyContactsCursor
|
||||
import com.simplemobiletools.commons.extensions.getPhoneNumberTypeText
|
||||
import com.simplemobiletools.commons.helpers.MyContactsContentProvider
|
||||
import com.simplemobiletools.commons.helpers.SimpleContactsHelper
|
||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||
@ -53,8 +52,9 @@ class CallManager {
|
||||
}
|
||||
|
||||
fun getCallContact(context: Context, callback: (CallContact?) -> Unit) {
|
||||
val privateCursor = context.getMyContactsCursor(false, true)?.loadInBackground()
|
||||
ensureBackgroundThread {
|
||||
val callContact = CallContact("", "", "")
|
||||
val callContact = CallContact("", "", "", "")
|
||||
val handle = try {
|
||||
call?.details?.handle?.toString()
|
||||
} catch (e: NullPointerException) {
|
||||
@ -69,24 +69,35 @@ class CallManager {
|
||||
val uri = Uri.decode(handle)
|
||||
if (uri.startsWith("tel:")) {
|
||||
val number = uri.substringAfter("tel:")
|
||||
callContact.number = number
|
||||
callContact.name = SimpleContactsHelper(context).getNameFromPhoneNumber(number)
|
||||
callContact.photoUri = SimpleContactsHelper(context).getPhotoUriFromPhoneNumber(number)
|
||||
SimpleContactsHelper(context).getAvailableContacts(false) { contacts ->
|
||||
val privateContacts = MyContactsContentProvider.getSimpleContacts(context, privateCursor)
|
||||
if (privateContacts.isNotEmpty()) {
|
||||
contacts.addAll(privateContacts)
|
||||
}
|
||||
|
||||
if (callContact.name != callContact.number) {
|
||||
callback(callContact)
|
||||
} else {
|
||||
Handler(Looper.getMainLooper()).post {
|
||||
val privateCursor = context.getMyContactsCursor(false, true)?.loadInBackground()
|
||||
ensureBackgroundThread {
|
||||
val privateContacts = MyContactsContentProvider.getSimpleContacts(context, privateCursor)
|
||||
val privateContact = privateContacts.firstOrNull { it.doesContainPhoneNumber(callContact.number) }
|
||||
if (privateContact != null) {
|
||||
callContact.name = privateContact.name
|
||||
}
|
||||
callback(callContact)
|
||||
val contactsWithMultipleNumbers = contacts.filter { it.phoneNumbers.size > 1 }
|
||||
val numbersToContactIDMap = HashMap<String, Int>()
|
||||
contactsWithMultipleNumbers.forEach { contact ->
|
||||
contact.phoneNumbers.forEach { phoneNumber ->
|
||||
numbersToContactIDMap[phoneNumber.value] = contact.contactId
|
||||
numbersToContactIDMap[phoneNumber.normalizedNumber] = contact.contactId
|
||||
}
|
||||
}
|
||||
|
||||
callContact.number = number
|
||||
val contact = contacts.firstOrNull { it.doesHavePhoneNumber(number) }
|
||||
if (contact != null) {
|
||||
callContact.name = contact.name
|
||||
callContact.photoUri = contact.photoUri
|
||||
|
||||
if (contact.phoneNumbers.size > 1) {
|
||||
val specificPhoneNumber = contact.phoneNumbers.firstOrNull { it.value == number }
|
||||
if (specificPhoneNumber != null) {
|
||||
callContact.numberLabel = context.getPhoneNumberTypeText(specificPhoneNumber.type, specificPhoneNumber.label)
|
||||
}
|
||||
}
|
||||
}
|
||||
callback(callContact)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -52,7 +52,11 @@ class CallNotificationManager(private val context: Context) {
|
||||
declineCallIntent.action = DECLINE_CALL
|
||||
val declinePendingIntent = PendingIntent.getBroadcast(context, DECLINE_CALL_CODE, declineCallIntent, PendingIntent.FLAG_CANCEL_CURRENT)
|
||||
|
||||
val callerName = if (callContact != null && callContact.name.isNotEmpty()) callContact.name else context.getString(R.string.unknown_caller)
|
||||
var callerName = if (callContact != null && callContact.name.isNotEmpty()) callContact.name else context.getString(R.string.unknown_caller)
|
||||
if (callContact?.numberLabel?.isNotEmpty() == true) {
|
||||
callerName += " - ${callContact.numberLabel}"
|
||||
}
|
||||
|
||||
val contentTextId = when (callState) {
|
||||
Call.STATE_RINGING -> R.string.is_calling
|
||||
Call.STATE_DIALING -> R.string.dialing
|
||||
|
@ -1,4 +1,4 @@
|
||||
package com.simplemobiletools.dialer.models
|
||||
|
||||
// a simpler Contact model containing just info needed at the call screen
|
||||
data class CallContact(var name: String, var photoUri: String, var number: String)
|
||||
data class CallContact(var name: String, var photoUri: String, var number: String, var numberLabel: String)
|
||||
|
@ -31,7 +31,7 @@
|
||||
tools:text="Caller name" />
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextView
|
||||
android:id="@+id/caller_number_label"
|
||||
android:id="@+id/caller_number"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/normal_margin"
|
||||
@ -52,7 +52,7 @@
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.5"
|
||||
app:layout_constraintStart_toEndOf="@+id/call_sim_image"
|
||||
app:layout_constraintTop_toBottomOf="@+id/caller_number_label"
|
||||
app:layout_constraintTop_toBottomOf="@+id/caller_number"
|
||||
tools:text="Is Calling" />
|
||||
|
||||
<ImageView
|
||||
|
Reference in New Issue
Block a user