show the callers name, number and photo, if available
This commit is contained in:
parent
824a385b11
commit
e5f3da5434
5 changed files with 59 additions and 4 deletions
|
@ -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()
|
||||
|
|
|
@ -36,7 +36,7 @@ fun Context.getEmptyContact(): Contact {
|
|||
val originalContactSource = if (hasContactPermissions()) config.lastUsedContactSource else SMT_PRIVATE
|
||||
val organization = Organization("", "")
|
||||
return Contact(0, "", "", "", "", "", "", "", ArrayList(), ArrayList(), ArrayList(), ArrayList(), originalContactSource, 0, 0, "",
|
||||
null, "", ArrayList(), organization, ArrayList(), ArrayList())
|
||||
null, "", ArrayList(), organization, ArrayList(), ArrayList())
|
||||
}
|
||||
|
||||
fun Context.viewContact(contact: Contact) {
|
||||
|
@ -226,7 +226,7 @@ fun Context.sendSMSToContacts(contacts: ArrayList<Contact>) {
|
|||
val numbers = StringBuilder()
|
||||
contacts.forEach {
|
||||
val number = it.phoneNumbers.firstOrNull { it.type == ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE }
|
||||
?: it.phoneNumbers.firstOrNull()
|
||||
?: it.phoneNumbers.firstOrNull()
|
||||
if (number != null) {
|
||||
numbers.append("${number.value};")
|
||||
}
|
||||
|
@ -312,7 +312,7 @@ fun Context.getVisibleContactSources(): ArrayList<String> {
|
|||
val sources = getAllContactSources()
|
||||
val ignoredContactSources = config.ignoredContactSources
|
||||
return ArrayList(sources).filter { !ignoredContactSources.contains(it.getFullIdentifier()) }
|
||||
.map { it.name }.toMutableList() as ArrayList<String>
|
||||
.map { it.name }.toMutableList() as ArrayList<String>
|
||||
}
|
||||
|
||||
fun Context.getAllContactSources(): ArrayList<ContactSource> {
|
||||
|
|
|
@ -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 a new issue