show contacts name at the Call Screen, even if stored at the private space
This commit is contained in:
parent
3a62e38ef5
commit
e8c9958306
4 changed files with 35 additions and 11 deletions
|
@ -56,11 +56,16 @@ class CallActivity : SimpleActivity() {
|
||||||
initButtons()
|
initButtons()
|
||||||
|
|
||||||
audioManager.mode = AudioManager.MODE_IN_CALL
|
audioManager.mode = AudioManager.MODE_IN_CALL
|
||||||
callContact = CallManager.getCallContact(applicationContext)
|
CallManager.getCallContact(applicationContext) { contact ->
|
||||||
|
callContact = contact
|
||||||
callContactAvatar = getCallContactAvatar()
|
callContactAvatar = getCallContactAvatar()
|
||||||
addLockScreenFlags()
|
|
||||||
setupNotification()
|
setupNotification()
|
||||||
|
runOnUiThread {
|
||||||
updateOtherPersonsInfo()
|
updateOtherPersonsInfo()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
addLockScreenFlags()
|
||||||
initProximitySensor()
|
initProximitySensor()
|
||||||
|
|
||||||
CallManager.registerCallback(callCallback)
|
CallManager.registerCallback(callCallback)
|
||||||
|
@ -176,8 +181,7 @@ class CallActivity : SimpleActivity() {
|
||||||
return
|
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) {
|
if (callContactAvatar != null) {
|
||||||
caller_avatar.setImageBitmap(callContactAvatar)
|
caller_avatar.setImageBitmap(callContactAvatar)
|
||||||
|
|
|
@ -7,6 +7,8 @@ import android.telecom.Call
|
||||||
import android.telecom.VideoProfile
|
import android.telecom.VideoProfile
|
||||||
import com.simplemobiletools.commons.extensions.getNameFromPhoneNumber
|
import com.simplemobiletools.commons.extensions.getNameFromPhoneNumber
|
||||||
import com.simplemobiletools.commons.extensions.getPhotoUriFromPhoneNumber
|
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
|
import com.simplemobiletools.contacts.pro.models.CallContact
|
||||||
|
|
||||||
// inspired by https://github.com/Chooloo/call_manage
|
// inspired by https://github.com/Chooloo/call_manage
|
||||||
|
@ -50,10 +52,11 @@ class CallManager {
|
||||||
call?.stopDtmfTone()
|
call?.stopDtmfTone()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getCallContact(context: Context): CallContact? {
|
fun getCallContact(context: Context, callback: (CallContact?) -> Unit) {
|
||||||
val callContact = CallContact("", "", "")
|
val callContact = CallContact("", "", "")
|
||||||
if (call == null) {
|
if (call == null) {
|
||||||
return callContact
|
callback(callContact)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val uri = Uri.decode(call!!.details.handle.toString())
|
val uri = Uri.decode(call!!.details.handle.toString())
|
||||||
|
@ -62,9 +65,23 @@ class CallManager {
|
||||||
callContact.number = number
|
callContact.number = number
|
||||||
callContact.name = context.getNameFromPhoneNumber(number)
|
callContact.name = context.getNameFromPhoneNumber(number)
|
||||||
callContact.photoUri = context.getPhotoUriFromPhoneNumber(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
|
return scaledSizePhotoData
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun convertLocalContactToContact(localContact: LocalContact?, storedGroups: ArrayList<Group>): Contact? {
|
fun convertLocalContactToContact(localContact: LocalContact?, storedGroups: ArrayList<Group>): Contact? {
|
||||||
if (localContact == null) {
|
if (localContact == null) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,9 @@ interface ContactsDao {
|
||||||
@Query("SELECT * FROM contacts WHERE id = :id")
|
@Query("SELECT * FROM contacts WHERE id = :id")
|
||||||
fun getContactWithId(id: Int): LocalContact?
|
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")
|
@Query("UPDATE contacts SET starred = :isStarred WHERE id = :id")
|
||||||
fun updateStarred(isStarred: Int, id: Int)
|
fun updateStarred(isStarred: Int, id: Int)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue