use a different placeholder image at group conversations, not a letter

This commit is contained in:
tibbi 2020-04-11 20:07:39 +02:00
parent a4adf59323
commit 32d3e0b21a
5 changed files with 44 additions and 6 deletions

View File

@ -36,7 +36,7 @@ android {
}
dependencies {
implementation 'com.simplemobiletools:commons:5.25.6'
implementation 'com.simplemobiletools:commons:5.25.7'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta4'
implementation 'org.greenrobot:eventbus:3.2.0'
implementation 'com.klinkerapps:android-smsmms:5.2.6'

View File

@ -1,6 +1,7 @@
package com.simplemobiletools.smsmessenger.adapters
import android.graphics.Typeface
import android.graphics.drawable.LayerDrawable
import android.view.Menu
import android.view.View
import android.view.ViewGroup
@ -8,6 +9,7 @@ import android.widget.TextView
import com.bumptech.glide.Glide
import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter
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.views.FastScroller
@ -16,6 +18,7 @@ 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.*
@ -135,7 +138,17 @@ class ConversationsAdapter(
it.setTextColor(textColor)
}
context.loadImage(conversation.photoUri, conversation_image, conversation.title)
// at group conversations we use an icon as the placeholder, not any letter
val placeholder = if (conversation.isGroupConversation) {
val icon = activity.resources.getDrawable(R.drawable.group_conversation_icon)
val bgColor = letterBackgroundColors[Math.abs(conversation.title.hashCode()) % letterBackgroundColors.size].toInt()
(icon as LayerDrawable).findDrawableByLayerId(R.id.attendee_circular_background).applyColorFilter(bgColor)
icon
} else {
null
}
context.loadImage(conversation.photoUri, conversation_image, conversation.title, placeholder)
}
}
}

View File

@ -12,6 +12,7 @@ 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
import android.media.AudioManager
import android.media.RingtoneManager
@ -159,7 +160,8 @@ fun Context.getConversations(): ArrayList<Conversation> {
val names = getThreadContactNames(phoneNumbers)
val title = TextUtils.join(", ", names.toTypedArray())
val photoUri = if (phoneNumbers.size == 1) getPhotoUriFromPhoneNumber(phoneNumbers.first()) else ""
val conversation = Conversation(id, snippet, date.toInt(), read, title, photoUri)
val isGroupConversation = phoneNumbers.size > 1
val conversation = Conversation(id, snippet, date.toInt(), read, title, photoUri, isGroupConversation)
conversations.add(conversation)
}
return conversations
@ -595,8 +597,12 @@ fun Context.getNotificationLetterIcon(name: String): Bitmap {
return bitmap
}
fun Context.loadImage(path: String, imageView: ImageView, placeholderName: String) {
val placeholder = BitmapDrawable(resources, getNotificationLetterIcon(placeholderName))
fun Context.loadImage(path: String, imageView: ImageView, placeholderName: String, placeholderImage: Drawable? = null) {
val placeholder = if (placeholderImage == null) {
BitmapDrawable(resources, getNotificationLetterIcon(placeholderName))
} else {
placeholderImage
}
val options = RequestOptions()
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)

View File

@ -1,3 +1,6 @@
package com.simplemobiletools.smsmessenger.models
data class Conversation(val id: Int, val snippet: String, val date: Int, val read: Boolean, val title: String, val photoUri: String)
data class Conversation(
val id: Int, val snippet: String, val date: Int, val read: Boolean, val title: String, val photoUri: String,
val isGroupConversation: Boolean
)

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/attendee_circular_background">
<shape android:shape="oval">
<solid android:color="@color/color_primary" />
</shape>
</item>
<item
android:bottom="@dimen/medium_margin"
android:drawable="@drawable/ic_people_vector"
android:left="@dimen/medium_margin"
android:right="@dimen/medium_margin"
android:top="@dimen/medium_margin" />
</layer-list>