diff --git a/app/src/main/kotlin/com/simplemobiletools/dialer/helpers/RecentsHelper.kt b/app/src/main/kotlin/com/simplemobiletools/dialer/helpers/RecentsHelper.kt index 7954d78a..b3dcd84a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/dialer/helpers/RecentsHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/dialer/helpers/RecentsHelper.kt @@ -74,6 +74,15 @@ class RecentsHelper(private val context: Context) { context.contentResolver.query(uri, projection, null, null, sortOrder) } + val contactsWithMultipleNumbers = contacts.filter { it.phoneNumbers.size > 1 } + val numbersToContactIDMap = HashMap() + contactsWithMultipleNumbers.forEach { contact -> + contact.phoneNumbers.forEach { phoneNumber -> + numbersToContactIDMap[phoneNumber.value] = contact.contactId + numbersToContactIDMap[phoneNumber.normalizedNumber] = contact.contactId + } + } + if (cursor?.moveToFirst() == true) { do { val id = cursor.getIntValue(Calls._ID) @@ -132,7 +141,20 @@ class RecentsHelper(private val context: Context) { val accountAddress = cursor.getStringValue("phone_account_address") val simID = numberToSimIDMap[accountAddress] ?: 1 val neighbourIDs = ArrayList() - val recentCall = RecentCall(id, number, name, photoUri, startTS, duration, type, neighbourIDs, simID) + var specificNumber = "" + var specificType = "" + + val contactIdWithMultipleNumbers = numbersToContactIDMap[number] + if (contactIdWithMultipleNumbers != null) { + val specificPhoneNumber = + contacts.firstOrNull { it.contactId == contactIdWithMultipleNumbers }?.phoneNumbers?.firstOrNull { it.value == number } + if (specificPhoneNumber != null) { + specificNumber = specificPhoneNumber.value + specificType = context.getPhoneNumberTypeText(specificPhoneNumber.type, specificPhoneNumber.label) + } + } + + val recentCall = RecentCall(id, number, name, photoUri, startTS, duration, type, neighbourIDs, simID, specificNumber, specificType) // if we have multiple missed calls from the same number, show it just once if (!groupSubsequentCalls || "$number$name" != previousRecentCallFrom) { diff --git a/app/src/main/kotlin/com/simplemobiletools/dialer/models/RecentCall.kt b/app/src/main/kotlin/com/simplemobiletools/dialer/models/RecentCall.kt index 07a4b4cc..16ff44ce 100644 --- a/app/src/main/kotlin/com/simplemobiletools/dialer/models/RecentCall.kt +++ b/app/src/main/kotlin/com/simplemobiletools/dialer/models/RecentCall.kt @@ -3,9 +3,10 @@ package com.simplemobiletools.dialer.models import android.telephony.PhoneNumberUtils import com.simplemobiletools.commons.extensions.normalizePhoneNumber +// model used at displaying recent calls, for contacts with multiple numbers specifify the number and type data class RecentCall( var id: Int, var phoneNumber: String, var name: String, var photoUri: String, var startTS: Int, var duration: Int, var type: Int, - var neighbourIDs: ArrayList, val simID: Int + var neighbourIDs: ArrayList, val simID: Int, var specificNumber: String, var specificType: String ) { fun doesContainPhoneNumber(text: String): Boolean { val normalizedText = text.normalizePhoneNumber()