Use launcher icon as bot-avatar/system-conversation-icon on pre-Android O

Fixes #1417

Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
Andy Scherzinger 2021-07-08 13:50:04 +02:00
parent 9da85eec83
commit 5e88dc6f57
No known key found for this signature in database
GPG Key ID: 6CADC7E3523C308B
5 changed files with 32 additions and 20 deletions

View File

@ -27,9 +27,9 @@ import android.content.Context;
import android.content.res.ColorStateList; import android.content.res.ColorStateList;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable; import android.graphics.drawable.LayerDrawable;
import android.os.Build;
import android.text.TextUtils; import android.text.TextUtils;
import android.text.format.DateUtils; import android.text.format.DateUtils;
import android.view.View; import android.view.View;
@ -215,13 +215,16 @@ public class ConversationItem extends AbstractFlexibleItem<ConversationItem.Conv
} }
if (Conversation.ConversationType.ROOM_SYSTEM.equals(conversation.getType())) { if (Conversation.ConversationType.ROOM_SYSTEM.equals(conversation.getType())) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Drawable[] layers = new Drawable[2]; Drawable[] layers = new Drawable[2];
layers[0] = context.getDrawable(R.drawable.ic_launcher_background); layers[0] = ContextCompat.getDrawable(context, R.drawable.ic_launcher_background);
layers[1] = context.getDrawable(R.drawable.ic_launcher_foreground); layers[1] = ContextCompat.getDrawable(context, R.drawable.ic_launcher_foreground);
LayerDrawable layerDrawable = new LayerDrawable(layers); LayerDrawable layerDrawable = new LayerDrawable(layers);
holder.dialogAvatar.getHierarchy().setPlaceholderImage(DisplayUtils.getRoundedDrawable(layerDrawable)); holder.dialogAvatar.getHierarchy().setPlaceholderImage(DisplayUtils.getRoundedDrawable(layerDrawable));
} else {
holder.dialogAvatar.getHierarchy().setPlaceholderImage(R.mipmap.ic_launcher);
}
shouldLoadAvatar = false; shouldLoadAvatar = false;
} }

View File

@ -28,11 +28,11 @@ import android.annotation.SuppressLint
import android.content.Context import android.content.Context
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.graphics.drawable.LayerDrawable import android.graphics.drawable.LayerDrawable
import android.os.Build
import android.text.TextUtils import android.text.TextUtils
import android.util.Log import android.util.Log
import android.view.View import android.view.View
import android.widget.SeekBar import android.widget.SeekBar
import androidx.appcompat.content.res.AppCompatResources
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.core.content.res.ResourcesCompat import androidx.core.content.res.ResourcesCompat
import androidx.core.view.ViewCompat import androidx.core.view.ViewCompat
@ -201,11 +201,15 @@ class IncomingVoiceMessageViewHolder(incomingView: View) : MessageHolders
if (message.actorType == "guests") { if (message.actorType == "guests") {
// do nothing, avatar is set // do nothing, avatar is set
} else if (message.actorType == "bots" && message.actorId == "changelog") { } else if (message.actorType == "bots" && message.actorId == "changelog") {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val layers = arrayOfNulls<Drawable>(2) val layers = arrayOfNulls<Drawable>(2)
layers[0] = AppCompatResources.getDrawable(context!!, R.drawable.ic_launcher_background) layers[0] = ContextCompat.getDrawable(context!!, R.drawable.ic_launcher_background)
layers[1] = AppCompatResources.getDrawable(context!!, R.drawable.ic_launcher_foreground) layers[1] = ContextCompat.getDrawable(context!!, R.drawable.ic_launcher_foreground)
val layerDrawable = LayerDrawable(layers) val layerDrawable = LayerDrawable(layers)
binding.messageUserAvatar.setImageDrawable(DisplayUtils.getRoundedDrawable(layerDrawable)) binding.messageUserAvatar.setImageDrawable(DisplayUtils.getRoundedDrawable(layerDrawable))
} else {
binding.messageUserAvatar.setImageResource(R.mipmap.ic_launcher)
}
} else if (message.actorType == "bots") { } else if (message.actorType == "bots") {
val drawable = TextDrawable.builder() val drawable = TextDrawable.builder()
.beginConfig() .beginConfig()

View File

@ -27,6 +27,7 @@ import android.content.Intent
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.graphics.drawable.LayerDrawable import android.graphics.drawable.LayerDrawable
import android.net.Uri import android.net.Uri
import android.os.Build
import android.text.Spannable import android.text.Spannable
import android.text.SpannableString import android.text.SpannableString
import android.text.TextUtils import android.text.TextUtils
@ -81,11 +82,15 @@ class MagicIncomingTextMessageViewHolder(itemView: View) : MessageHolders
// do nothing, avatar is set // do nothing, avatar is set
} else if (message.actorType == "bots" && message.actorId == "changelog") { } else if (message.actorType == "bots" && message.actorId == "changelog") {
if (context != null) { if (context != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val layers = arrayOfNulls<Drawable>(2) val layers = arrayOfNulls<Drawable>(2)
layers[0] = ContextCompat.getDrawable(context!!, R.drawable.ic_launcher_background) layers[0] = ContextCompat.getDrawable(context!!, R.drawable.ic_launcher_background)
layers[1] = ContextCompat.getDrawable(context!!, R.drawable.ic_launcher_foreground) layers[1] = ContextCompat.getDrawable(context!!, R.drawable.ic_launcher_foreground)
val layerDrawable = LayerDrawable(layers) val layerDrawable = LayerDrawable(layers)
binding.messageUserAvatar.setImageDrawable(DisplayUtils.getRoundedDrawable(layerDrawable)) binding.messageUserAvatar.setImageDrawable(DisplayUtils.getRoundedDrawable(layerDrawable))
} else {
binding.messageUserAvatar.setImageResource(R.mipmap.ic_launcher)
}
} }
} else if (message.actorType == "bots") { } else if (message.actorType == "bots") {
val drawable = TextDrawable.builder() val drawable = TextDrawable.builder()

View File

@ -55,7 +55,7 @@ public class UserUtils {
public List getUsers() { public List getUsers() {
Result findUsersQueryResult = dataStore.select(User.class).where Result findUsersQueryResult = dataStore.select(User.class).where
(UserEntity.SCHEDULED_FOR_DELETION.notEqual(true)).get(); (UserEntity.SCHEDULED_FOR_DELETION.notEqual(Boolean.TRUE)).get();
return findUsersQueryResult.toList(); return findUsersQueryResult.toList();
} }

View File

@ -1,2 +1,2 @@
DO NOT TOUCH; GENERATED BY DRONE DO NOT TOUCH; GENERATED BY DRONE
<span class="mdl-layout-title">Lint Report: 3 errors and 274 warnings</span> <span class="mdl-layout-title">Lint Report: 3 errors and 272 warnings</span>