fetch private contact data at the call screen

This commit is contained in:
tibbi
2020-05-21 21:50:47 +02:00
parent 7e5a15bf28
commit b830d43883

View File

@ -6,7 +6,10 @@ import android.net.Uri
import android.telecom.Call import android.telecom.Call
import android.telecom.InCallService import android.telecom.InCallService
import android.telecom.VideoProfile 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.SimpleContactsHelper
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.dialer.models.CallContact import com.simplemobiletools.dialer.models.CallContact
// inspired by https://github.com/Chooloo/call_manage // inspired by https://github.com/Chooloo/call_manage
@ -65,8 +68,20 @@ class CallManager {
callContact.name = SimpleContactsHelper(context).getNameFromPhoneNumber(number) callContact.name = SimpleContactsHelper(context).getNameFromPhoneNumber(number)
callContact.photoUri = SimpleContactsHelper(context).getPhotoUriFromPhoneNumber(number) callContact.photoUri = SimpleContactsHelper(context).getPhotoUriFromPhoneNumber(number)
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) callback(callContact)
} }
} }
} }
} }
}
}