moving the contact avatar creation into Commons
This commit is contained in:
parent
1251d09900
commit
3a515486ea
|
@ -56,7 +56,7 @@ android {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.simplemobiletools:commons:5.25.17'
|
||||
implementation 'com.simplemobiletools:commons:5.25.18'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta4'
|
||||
implementation 'org.greenrobot:eventbus:3.2.0'
|
||||
implementation 'com.klinkerapps:android-smsmms:5.2.6'
|
||||
|
|
|
@ -12,13 +12,13 @@ import com.simplemobiletools.commons.dialogs.ConfirmationDialog
|
|||
import com.simplemobiletools.commons.extensions.applyColorFilter
|
||||
import com.simplemobiletools.commons.extensions.formatDateOrTime
|
||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||
import com.simplemobiletools.commons.helpers.letterBackgroundColors
|
||||
import com.simplemobiletools.commons.views.FastScroller
|
||||
import com.simplemobiletools.commons.views.MyRecyclerView
|
||||
import com.simplemobiletools.smsmessenger.R
|
||||
import com.simplemobiletools.smsmessenger.activities.SimpleActivity
|
||||
import com.simplemobiletools.smsmessenger.extensions.deleteConversation
|
||||
import com.simplemobiletools.smsmessenger.extensions.loadImage
|
||||
import com.simplemobiletools.smsmessenger.helpers.letterBackgroundColors
|
||||
import com.simplemobiletools.smsmessenger.helpers.refreshMessages
|
||||
import com.simplemobiletools.smsmessenger.models.Conversation
|
||||
import kotlinx.android.synthetic.main.item_conversation.view.*
|
||||
|
|
|
@ -9,8 +9,6 @@ import android.content.ContentValues
|
|||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Paint
|
||||
import android.graphics.drawable.BitmapDrawable
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.media.AudioAttributes
|
||||
|
@ -25,7 +23,6 @@ import android.provider.ContactsContract.PhoneLookup
|
|||
import android.provider.Telephony.*
|
||||
import android.text.TextUtils
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import androidx.core.app.NotificationCompat
|
||||
import com.bumptech.glide.Glide
|
||||
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
||||
|
@ -37,7 +34,6 @@ import com.simplemobiletools.smsmessenger.R
|
|||
import com.simplemobiletools.smsmessenger.activities.ThreadActivity
|
||||
import com.simplemobiletools.smsmessenger.helpers.Config
|
||||
import com.simplemobiletools.smsmessenger.helpers.THREAD_ID
|
||||
import com.simplemobiletools.smsmessenger.helpers.letterBackgroundColors
|
||||
import com.simplemobiletools.smsmessenger.models.*
|
||||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
|
@ -659,7 +655,7 @@ fun Context.showReceivedMessageNotification(address: String, body: String, threa
|
|||
val summaryText = getString(R.string.new_message)
|
||||
val sender = getNameAndPhotoFromPhoneNumber(address)?.name ?: ""
|
||||
|
||||
val largeIcon = bitmap ?: getNotificationLetterIcon(sender)
|
||||
val largeIcon = bitmap ?: getContactLetterIcon(sender)
|
||||
val builder = NotificationCompat.Builder(this, channelId)
|
||||
.setContentTitle(sender)
|
||||
.setContentText(body)
|
||||
|
@ -677,38 +673,8 @@ fun Context.showReceivedMessageNotification(address: String, body: String, threa
|
|||
notificationManager.notify(threadID, builder.build())
|
||||
}
|
||||
|
||||
fun Context.getNotificationLetterIcon(name: String): Bitmap {
|
||||
val letter = name.getNameLetter()
|
||||
val size = resources.getDimension(R.dimen.notification_large_icon_size).toInt()
|
||||
val bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888)
|
||||
val canvas = Canvas(bitmap)
|
||||
val view = TextView(this)
|
||||
view.layout(0, 0, size, size)
|
||||
|
||||
val circlePaint = Paint().apply {
|
||||
color = letterBackgroundColors[Math.abs(name.hashCode()) % letterBackgroundColors.size].toInt()
|
||||
isAntiAlias = true
|
||||
}
|
||||
|
||||
val wantedTextSize = size / 2f
|
||||
val textPaint = Paint().apply {
|
||||
color = circlePaint.color.getContrastColor()
|
||||
isAntiAlias = true
|
||||
textAlign = Paint.Align.CENTER
|
||||
textSize = wantedTextSize
|
||||
}
|
||||
|
||||
canvas.drawCircle(size / 2f, size / 2f, size / 2f, circlePaint)
|
||||
|
||||
val xPos = canvas.width / 2f
|
||||
val yPos = canvas.height / 2 - (textPaint.descent() + textPaint.ascent()) / 2
|
||||
canvas.drawText(letter, xPos, yPos, textPaint)
|
||||
view.draw(canvas)
|
||||
return bitmap
|
||||
}
|
||||
|
||||
fun Context.loadImage(path: String, imageView: ImageView, placeholderName: String, placeholderImage: Drawable? = null) {
|
||||
val placeholder = placeholderImage ?: BitmapDrawable(resources, getNotificationLetterIcon(placeholderName))
|
||||
val placeholder = placeholderImage ?: BitmapDrawable(resources, getContactLetterIcon(placeholderName))
|
||||
|
||||
val options = RequestOptions()
|
||||
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
package com.simplemobiletools.smsmessenger.extensions
|
||||
|
||||
import com.simplemobiletools.commons.extensions.normalizeString
|
||||
import java.util.*
|
||||
|
||||
// get the contact names first letter at showing the placeholder without image
|
||||
fun String.getNameLetter() = normalizeString().toCharArray().getOrNull(0)?.toString()?.toUpperCase(Locale.getDefault()) ?: "S"
|
|
@ -23,17 +23,3 @@ const val MESSAGE_ADDRESS = "message_address"
|
|||
fun refreshMessages() {
|
||||
EventBus.getDefault().post(Events.RefreshMessages())
|
||||
}
|
||||
|
||||
// most app icon colors from md_app_icon_colors with reduced alpha
|
||||
val letterBackgroundColors = arrayListOf(
|
||||
0xCCD32F2F,
|
||||
0xCCC2185B,
|
||||
0xCC1976D2,
|
||||
0xCC0288D1,
|
||||
0xCC0097A7,
|
||||
0xCC00796B,
|
||||
0xCC388E3C,
|
||||
0xCC689F38,
|
||||
0xCCF57C00,
|
||||
0xCCE64A19
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue