From b830d438839c7079b36f2c71963c598fc942b485 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 21 May 2020 21:50:47 +0200 Subject: [PATCH] fetch private contact data at the call screen --- .../dialer/helpers/CallManager.kt | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/dialer/helpers/CallManager.kt b/app/src/main/kotlin/com/simplemobiletools/dialer/helpers/CallManager.kt index 9b210d5a..81d44624 100644 --- a/app/src/main/kotlin/com/simplemobiletools/dialer/helpers/CallManager.kt +++ b/app/src/main/kotlin/com/simplemobiletools/dialer/helpers/CallManager.kt @@ -6,7 +6,10 @@ import android.net.Uri import android.telecom.Call import android.telecom.InCallService import android.telecom.VideoProfile +import com.simplemobiletools.commons.extensions.getMyContactsContentProviderCursorLoader +import com.simplemobiletools.commons.helpers.MyContactsContentProvider import com.simplemobiletools.commons.helpers.SimpleContactsHelper +import com.simplemobiletools.commons.helpers.ensureBackgroundThread import com.simplemobiletools.dialer.models.CallContact // inspired by https://github.com/Chooloo/call_manage @@ -65,7 +68,19 @@ class CallManager { callContact.name = SimpleContactsHelper(context).getNameFromPhoneNumber(number) callContact.photoUri = SimpleContactsHelper(context).getPhotoUriFromPhoneNumber(number) - callback(callContact) + if (callContact.name != callContact.number) { + callback(callContact) + } else { + val privateCursor = context.getMyContactsContentProviderCursorLoader().loadInBackground() + ensureBackgroundThread { + val privateContacts = MyContactsContentProvider.getSimpleContacts(context, privateCursor) + val privateContact = privateContacts.firstOrNull { it.phoneNumber == callContact.number } + if (privateContact != null) { + callContact.name = privateContact.name + } + callback(callContact) + } + } } } }