show contacts name at the Call Screen, even if stored at the private space
This commit is contained in:
parent
3a62e38ef5
commit
e8c9958306
|
@ -56,11 +56,16 @@ class CallActivity : SimpleActivity() {
|
|||
initButtons()
|
||||
|
||||
audioManager.mode = AudioManager.MODE_IN_CALL
|
||||
callContact = CallManager.getCallContact(applicationContext)
|
||||
CallManager.getCallContact(applicationContext) { contact ->
|
||||
callContact = contact
|
||||
callContactAvatar = getCallContactAvatar()
|
||||
addLockScreenFlags()
|
||||
setupNotification()
|
||||
runOnUiThread {
|
||||
updateOtherPersonsInfo()
|
||||
}
|
||||
}
|
||||
|
||||
addLockScreenFlags()
|
||||
initProximitySensor()
|
||||
|
||||
CallManager.registerCallback(callCallback)
|
||||
|
@ -176,8 +181,7 @@ class CallActivity : SimpleActivity() {
|
|||
return
|
||||
}
|
||||
|
||||
val callContact = CallManager.getCallContact(applicationContext) ?: return
|
||||
caller_name_label.text = if (callContact.name.isNotEmpty()) callContact.name else getString(R.string.unknown_caller)
|
||||
caller_name_label.text = if (callContact!!.name.isNotEmpty()) callContact!!.name else getString(R.string.unknown_caller)
|
||||
|
||||
if (callContactAvatar != null) {
|
||||
caller_avatar.setImageBitmap(callContactAvatar)
|
||||
|
|
|
@ -7,6 +7,8 @@ import android.telecom.Call
|
|||
import android.telecom.VideoProfile
|
||||
import com.simplemobiletools.commons.extensions.getNameFromPhoneNumber
|
||||
import com.simplemobiletools.commons.extensions.getPhotoUriFromPhoneNumber
|
||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||
import com.simplemobiletools.contacts.pro.extensions.contactsDB
|
||||
import com.simplemobiletools.contacts.pro.models.CallContact
|
||||
|
||||
// inspired by https://github.com/Chooloo/call_manage
|
||||
|
@ -50,10 +52,11 @@ class CallManager {
|
|||
call?.stopDtmfTone()
|
||||
}
|
||||
|
||||
fun getCallContact(context: Context): CallContact? {
|
||||
fun getCallContact(context: Context, callback: (CallContact?) -> Unit) {
|
||||
val callContact = CallContact("", "", "")
|
||||
if (call == null) {
|
||||
return callContact
|
||||
callback(callContact)
|
||||
return
|
||||
}
|
||||
|
||||
val uri = Uri.decode(call!!.details.handle.toString())
|
||||
|
@ -62,9 +65,23 @@ class CallManager {
|
|||
callContact.number = number
|
||||
callContact.name = context.getNameFromPhoneNumber(number)
|
||||
callContact.photoUri = context.getPhotoUriFromPhoneNumber(number)
|
||||
|
||||
if (callContact.name == callContact.number) {
|
||||
ensureBackgroundThread {
|
||||
val localContact = context.contactsDB.getContactWithNumber("%$number%")
|
||||
if (localContact != null) {
|
||||
val storedGroups = ContactsHelper(context).getStoredGroupsSync()
|
||||
val newContact = LocalContactsHelper(context).convertLocalContactToContact(localContact, storedGroups)
|
||||
callContact.name = newContact!!.getNameToDisplay()
|
||||
callContact.photoUri = newContact.photoUri
|
||||
}
|
||||
|
||||
return callContact
|
||||
callback(callContact)
|
||||
}
|
||||
} else {
|
||||
callback(callContact)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -81,7 +81,7 @@ class LocalContactsHelper(val context: Context) {
|
|||
return scaledSizePhotoData
|
||||
}
|
||||
|
||||
private fun convertLocalContactToContact(localContact: LocalContact?, storedGroups: ArrayList<Group>): Contact? {
|
||||
fun convertLocalContactToContact(localContact: LocalContact?, storedGroups: ArrayList<Group>): Contact? {
|
||||
if (localContact == null) {
|
||||
return null
|
||||
}
|
||||
|
|
|
@ -14,6 +14,9 @@ interface ContactsDao {
|
|||
@Query("SELECT * FROM contacts WHERE id = :id")
|
||||
fun getContactWithId(id: Int): LocalContact?
|
||||
|
||||
@Query("SELECT * FROM contacts WHERE phone_numbers LIKE :number")
|
||||
fun getContactWithNumber(number: String): LocalContact?
|
||||
|
||||
@Query("UPDATE contacts SET starred = :isStarred WHERE id = :id")
|
||||
fun updateStarred(isStarred: Int, id: Int)
|
||||
|
||||
|
|
Loading…
Reference in New Issue