improve handling of recent calls, if a contact has multiple numbers

This commit is contained in:
tibbi
2022-02-06 15:34:21 +01:00
parent e303b8b62a
commit f77b240a93
2 changed files with 25 additions and 2 deletions

View File

@ -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<String, Int>()
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<Int>()
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) {

View File

@ -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<Int>, val simID: Int
var neighbourIDs: ArrayList<Int>, val simID: Int, var specificNumber: String, var specificType: String
) {
fun doesContainPhoneNumber(text: String): Boolean {
val normalizedText = text.normalizePhoneNumber()