Merge pull request #507 from Naveen3Singh/photo_glitch_fix

Save sender name, photo when receiving a message
This commit is contained in:
Tibor Kaputa 2022-11-25 21:58:25 +01:00 committed by GitHub
commit 6b4dbeec88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 8 deletions

View File

@ -62,10 +62,11 @@ class SmsReceiver : BroadcastReceiver() {
private fun handleMessage( private fun handleMessage(
context: Context, address: String, subject: String, body: String, date: Long, read: Int, threadId: Long, type: Int, subscriptionId: Int, status: Int context: Context, address: String, subject: String, body: String, date: Long, read: Int, threadId: Long, type: Int, subscriptionId: Int, status: Int
) { ) {
val bitmap = getPhotoForNotification(address, context) val photoUri = SimpleContactsHelper(context).getPhotoUriFromPhoneNumber(address)
val bitmap = getPhotoForNotification(photoUri, context)
Handler(Looper.getMainLooper()).post { Handler(Looper.getMainLooper()).post {
if (!context.isNumberBlocked(address)) { if (!context.isNumberBlocked(address)) {
val privateCursor = context.getMyContactsCursor(false, true) val privateCursor = context.getMyContactsCursor(favoritesOnly = false, withPhoneNumbersOnly = true)
ensureBackgroundThread { ensureBackgroundThread {
val newMessageId = context.insertNewSMS(address, subject, body, date, read, threadId, type, subscriptionId) val newMessageId = context.insertNewSMS(address, subject, body, date, read, threadId, type, subscriptionId)
@ -82,12 +83,12 @@ class SmsReceiver : BroadcastReceiver() {
val senderName = context.getNameFromAddress(address, privateCursor) val senderName = context.getNameFromAddress(address, privateCursor)
val phoneNumber = PhoneNumber(address, 0, "", address) val phoneNumber = PhoneNumber(address, 0, "", address)
val participant = SimpleContact(0, 0, senderName, "", arrayListOf(phoneNumber), ArrayList(), ArrayList()) val participant = SimpleContact(0, 0, senderName, photoUri, arrayListOf(phoneNumber), ArrayList(), ArrayList())
val participants = arrayListOf(participant) val participants = arrayListOf(participant)
val messageDate = (date / 1000).toInt() val messageDate = (date / 1000).toInt()
val message = val message =
Message(newMessageId, body, type, status, participants, messageDate, false, threadId, false, null, address, "", subscriptionId) Message(newMessageId, body, type, status, participants, messageDate, false, threadId, false, null, senderName, photoUri, subscriptionId)
context.messagesDB.insertOrUpdate(message) context.messagesDB.insertOrUpdate(message)
refreshMessages() refreshMessages()
} }
@ -97,10 +98,9 @@ class SmsReceiver : BroadcastReceiver() {
} }
} }
private fun getPhotoForNotification(address: String, context: Context): Bitmap? { private fun getPhotoForNotification(photoUri: String, context: Context): Bitmap? {
val photo = SimpleContactsHelper(context).getPhotoUriFromPhoneNumber(address)
val size = context.resources.getDimension(R.dimen.notification_large_icon_size).toInt() val size = context.resources.getDimension(R.dimen.notification_large_icon_size).toInt()
if (photo.isEmpty()) { if (photoUri.isEmpty()) {
return null return null
} }
@ -111,7 +111,7 @@ class SmsReceiver : BroadcastReceiver() {
return try { return try {
Glide.with(context) Glide.with(context)
.asBitmap() .asBitmap()
.load(photo) .load(photoUri)
.apply(options) .apply(options)
.apply(RequestOptions.circleCropTransform()) .apply(RequestOptions.circleCropTransform())
.into(size, size) .into(size, size)