From fc0962780c12e90108ee4983bef65c9cac84ab8f Mon Sep 17 00:00:00 2001 From: Andy Scherzinger Date: Mon, 21 Jun 2021 23:46:24 +0200 Subject: [PATCH] improve lint score Signed-off-by: Andy Scherzinger --- .../MagicIncomingTextMessageViewHolder.kt | 26 +++++++++++-------- .../MagicOutcomingTextMessageViewHolder.kt | 6 ++--- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicIncomingTextMessageViewHolder.kt b/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicIncomingTextMessageViewHolder.kt index a7b47438c..21e9b6d49 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicIncomingTextMessageViewHolder.kt +++ b/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicIncomingTextMessageViewHolder.kt @@ -32,6 +32,8 @@ import android.text.SpannableString import android.text.TextUtils import android.util.TypedValue import android.view.View +import androidx.core.content.ContextCompat +import androidx.core.content.res.ResourcesCompat import androidx.core.view.ViewCompat import autodagger.AutoInjector import coil.load @@ -78,11 +80,13 @@ class MagicIncomingTextMessageViewHolder(itemView: View) : MessageHolders if (message.actorType == "guests") { // do nothing, avatar is set } else if (message.actorType == "bots" && message.actorId == "changelog") { - val layers = arrayOfNulls(2) - layers[0] = context?.getDrawable(R.drawable.ic_launcher_background) - layers[1] = context?.getDrawable(R.drawable.ic_launcher_foreground) - val layerDrawable = LayerDrawable(layers) - binding.messageUserAvatar.setImageDrawable(DisplayUtils.getRoundedDrawable(layerDrawable)) + if (context != null) { + val layers = arrayOfNulls(2) + layers[0] = ContextCompat.getDrawable(context!!, R.drawable.ic_launcher_background) + layers[1] = ContextCompat.getDrawable(context!!, R.drawable.ic_launcher_foreground) + val layerDrawable = LayerDrawable(layers) + binding.messageUserAvatar.setImageDrawable(DisplayUtils.getRoundedDrawable(layerDrawable)) + } } else if (message.actorType == "bots") { val drawable = TextDrawable.builder() .beginConfig() @@ -90,7 +94,7 @@ class MagicIncomingTextMessageViewHolder(itemView: View) : MessageHolders .endConfig() .buildRound( ">", - context!!.resources.getColor(R.color.black) + ResourcesCompat.getColor(context!!.resources, R.color.black, null) ) binding.messageUserAvatar.visibility = View.VISIBLE binding.messageUserAvatar.setImageDrawable(drawable) @@ -107,9 +111,9 @@ class MagicIncomingTextMessageViewHolder(itemView: View) : MessageHolders val resources = itemView.resources val bgBubbleColor = if (message.isDeleted) { - resources.getColor(R.color.bg_message_list_incoming_bubble_deleted) + ResourcesCompat.getColor(resources, R.color.bg_message_list_incoming_bubble_deleted, null) } else { - resources.getColor(R.color.bg_message_list_incoming_bubble) + ResourcesCompat.getColor(resources, R.color.bg_message_list_incoming_bubble, null) } var bubbleResource = R.drawable.shape_incoming_message @@ -120,7 +124,7 @@ class MagicIncomingTextMessageViewHolder(itemView: View) : MessageHolders val bubbleDrawable = DisplayUtils.getMessageSelector( bgBubbleColor, - resources.getColor(R.color.transparent), + ResourcesCompat.getColor(resources, R.color.transparent, null), bgBubbleColor, bubbleResource ) ViewCompat.setBackground(bubble, bubbleDrawable) @@ -128,7 +132,7 @@ class MagicIncomingTextMessageViewHolder(itemView: View) : MessageHolders val messageParameters = message.messageParameters itemView.isSelected = false - binding.messageTime.setTextColor(context?.resources!!.getColor(R.color.warm_grey_four)) + binding.messageTime.setTextColor(ResourcesCompat.getColor(resources, R.color.warm_grey_four, null)) var messageString: Spannable = SpannableString(message.text) @@ -201,7 +205,7 @@ class MagicIncomingTextMessageViewHolder(itemView: View) : MessageHolders binding.messageQuote.quotedMessage.text = parentChatMessage.text binding.messageQuote.quotedMessageAuthor - .setTextColor(context!!.resources.getColor(R.color.textColorMaxContrast)) + .setTextColor(ContextCompat.getColor(context!!, R.color.textColorMaxContrast)) if (parentChatMessage.actorId?.equals(message.activeUser.userId) == true) { binding.messageQuote.quoteColoredView.setBackgroundResource(R.color.colorPrimary) diff --git a/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicOutcomingTextMessageViewHolder.kt b/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicOutcomingTextMessageViewHolder.kt index 9d04a33d7..0ad9d998b 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicOutcomingTextMessageViewHolder.kt +++ b/app/src/main/java/com/nextcloud/talk/adapters/messages/MagicOutcomingTextMessageViewHolder.kt @@ -150,9 +150,9 @@ class MagicOutcomingTextMessageViewHolder(itemView: View) : OutcomingTextMessage ?: context!!.getText(R.string.nc_nick_guest) binding.messageQuote.quotedMessage.text = parentChatMessage.text binding.messageQuote.quotedMessage.setTextColor( - context!!.resources.getColor(R.color.nc_outcoming_text_default) + ContextCompat.getColor(context!!, R.color.nc_outcoming_text_default) ) - binding.messageQuote.quotedMessageAuthor.setTextColor(context!!.resources.getColor(R.color.nc_grey)) + binding.messageQuote.quotedMessageAuthor.setTextColor(ContextCompat.getColor(context!!, R.color.nc_grey)) binding.messageQuote.quoteColoredView.setBackgroundResource(R.color.white) @@ -174,7 +174,7 @@ class MagicOutcomingTextMessageViewHolder(itemView: View) : OutcomingTextMessage } readStatusDrawableInt?.let { drawableInt -> - ContextCompat.getDrawable(context!!, drawableInt)?.let { + ResourcesCompat.getDrawable(context!!.resources, drawableInt, null)?.let { it.setColorFilter(ContextCompat.getColor(context!!, R.color.white60), PorterDuff.Mode.SRC_ATOP) binding.checkMark.setImageDrawable(it) }