mirror of
https://github.com/SimpleMobileTools/Simple-Dialer.git
synced 2025-06-05 21:49:23 +02:00
improve handling of recent calls, if a contact has multiple numbers
This commit is contained in:
@ -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) {
|
||||
|
@ -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()
|
||||
|
Reference in New Issue
Block a user