show the callers name, number and photo, if available
This commit is contained in:
parent
824a385b11
commit
e5f3da5434
|
@ -57,7 +57,7 @@ android {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.simplemobiletools:commons:5.26.33'
|
||||
implementation 'com.simplemobiletools:commons:5.27.0'
|
||||
implementation 'joda-time:joda-time:2.10.1'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta4'
|
||||
implementation 'com.googlecode.ez-vcard:ez-vcard:0.10.5'
|
||||
|
|
|
@ -10,6 +10,10 @@ import android.os.Bundle
|
|||
import android.telecom.Call
|
||||
import android.widget.RemoteViews
|
||||
import androidx.core.app.NotificationCompat
|
||||
import com.bumptech.glide.Glide
|
||||
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
||||
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
|
||||
import com.bumptech.glide.request.RequestOptions
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.helpers.isOreoPlus
|
||||
import com.simplemobiletools.contacts.pro.R
|
||||
|
@ -33,8 +37,10 @@ class CallActivity : SimpleActivity() {
|
|||
updateTextColors(call_holder)
|
||||
initButtons()
|
||||
showNotification()
|
||||
|
||||
CallManager.registerCallback(getCallCallback())
|
||||
updateCallState(CallManager.getState())
|
||||
updateOtherPersonsInfo()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
|
@ -77,6 +83,24 @@ class CallActivity : SimpleActivity() {
|
|||
call_toggle_microphone.setImageDrawable(getDrawable(drawable))
|
||||
}
|
||||
|
||||
private fun updateOtherPersonsInfo() {
|
||||
val callContact = CallManager.getCallContact(applicationContext) ?: return
|
||||
caller_name_label.text = callContact.name
|
||||
caller_number_label.text = callContact.number
|
||||
caller_number_label.beVisibleIf(callContact.number.isNotEmpty())
|
||||
|
||||
val options = RequestOptions()
|
||||
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
|
||||
.centerCrop()
|
||||
|
||||
Glide.with(this)
|
||||
.load(callContact.photoUri)
|
||||
.transition(DrawableTransitionOptions.withCrossFade())
|
||||
.apply(options)
|
||||
.apply(RequestOptions.circleCropTransform())
|
||||
.into(caller_avatar)
|
||||
}
|
||||
|
||||
private fun updateCallState(state: Int) {
|
||||
when (state) {
|
||||
Call.STATE_ACTIVE -> callStarted()
|
||||
|
|
|
@ -1,8 +1,13 @@
|
|||
package com.simplemobiletools.contacts.pro.helpers
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import android.telecom.Call
|
||||
import android.telecom.VideoProfile
|
||||
import com.simplemobiletools.commons.extensions.getNameFromPhoneNumber
|
||||
import com.simplemobiletools.commons.extensions.getPhotoUriFromPhoneNumber
|
||||
import com.simplemobiletools.contacts.pro.models.CallContact
|
||||
|
||||
// inspired by https://github.com/Chooloo/call_manage
|
||||
@SuppressLint("NewApi")
|
||||
|
@ -35,5 +40,27 @@ class CallManager {
|
|||
} else {
|
||||
call!!.state
|
||||
}
|
||||
|
||||
fun getCallContact(context: Context): CallContact? {
|
||||
val callContact = CallContact("", "", "")
|
||||
if (call == null) {
|
||||
return callContact
|
||||
}
|
||||
|
||||
val uri = Uri.decode(call!!.details.handle.toString())
|
||||
if (uri.startsWith("tel:")) {
|
||||
val number = uri.substringAfter("tel:")
|
||||
callContact.number = number
|
||||
callContact.name = context.getNameFromPhoneNumber(number)
|
||||
callContact.photoUri = context.getPhotoUriFromPhoneNumber(number)
|
||||
}
|
||||
|
||||
if (callContact.name.isEmpty() && callContact.number.isNotEmpty()) {
|
||||
callContact.name = callContact.number
|
||||
callContact.number = ""
|
||||
}
|
||||
|
||||
return callContact
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
package com.simplemobiletools.contacts.pro.models
|
||||
|
||||
// a simpler Contact model containing just info needed at the call screen
|
||||
data class CallContact(var name: String, var number: String, var photoUri: String)
|
Loading…
Reference in New Issue