avoid unnecessary null checks in PollMessageViewHolders

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2022-07-19 13:04:43 +02:00 committed by Andy Scherzinger (Rebase PR Action)
parent 880c656be2
commit 6dfed0e5e7
2 changed files with 17 additions and 17 deletions

View file

@ -136,7 +136,7 @@ class IncomingPollMessageViewHolder(incomingView: View, payload: Any) : MessageH
} }
val credentials = ApiUtils.getCredentials(message.activeUser?.username, message.activeUser?.token) val credentials = ApiUtils.getCredentials(message.activeUser?.username, message.activeUser?.token)
ncApi!!.getPoll( ncApi.getPoll(
credentials, credentials,
ApiUtils.getUrlForPoll( ApiUtils.getUrlForPoll(
message.activeUser?.baseUrl, message.activeUser?.baseUrl,
@ -153,10 +153,10 @@ class IncomingPollMessageViewHolder(incomingView: View, payload: Any) : MessageH
override fun onNext(pollOverall: PollOverall) { override fun onNext(pollOverall: PollOverall) {
if (pollOverall.ocs!!.data!!.status == 0) { if (pollOverall.ocs!!.data!!.status == 0) {
binding.messagePollSubtitle.text = binding.messagePollSubtitle.text =
context?.resources?.getString(R.string.message_poll_tap_to_vote) context.resources?.getString(R.string.message_poll_tap_to_vote)
} else { } else {
binding.messagePollSubtitle.text = binding.messagePollSubtitle.text =
context?.resources?.getString(R.string.message_poll_tap_see_results) context.resources?.getString(R.string.message_poll_tap_see_results)
} }
} }
@ -201,8 +201,8 @@ class IncomingPollMessageViewHolder(incomingView: View, payload: Any) : MessageH
} 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) { 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 { } else {
@ -215,7 +215,7 @@ class IncomingPollMessageViewHolder(incomingView: View, payload: Any) : MessageH
.endConfig() .endConfig()
.buildRound( .buildRound(
">", ">",
ResourcesCompat.getColor(context!!.resources, R.color.black, null) ResourcesCompat.getColor(context.resources, R.color.black, null)
) )
binding.messageUserAvatar.visibility = View.VISIBLE binding.messageUserAvatar.visibility = View.VISIBLE
binding.messageUserAvatar.setImageDrawable(drawable) binding.messageUserAvatar.setImageDrawable(drawable)
@ -248,7 +248,7 @@ class IncomingPollMessageViewHolder(incomingView: View, payload: Any) : MessageH
if (!message.isDeleted && message.parentMessage != null) { if (!message.isDeleted && message.parentMessage != null) {
val parentChatMessage = message.parentMessage val parentChatMessage = message.parentMessage
parentChatMessage!!.activeUser = message.activeUser parentChatMessage!!.activeUser = message.activeUser
parentChatMessage!!.imageUrl?.let { parentChatMessage.imageUrl?.let {
binding.messageQuote.quotedMessageImage.visibility = View.VISIBLE binding.messageQuote.quotedMessageImage.visibility = View.VISIBLE
binding.messageQuote.quotedMessageImage.load(it) { binding.messageQuote.quotedMessageImage.load(it) {
addHeader( addHeader(
@ -260,11 +260,11 @@ class IncomingPollMessageViewHolder(incomingView: View, payload: Any) : MessageH
binding.messageQuote.quotedMessageImage.visibility = View.GONE binding.messageQuote.quotedMessageImage.visibility = View.GONE
} }
binding.messageQuote.quotedMessageAuthor.text = parentChatMessage.actorDisplayName binding.messageQuote.quotedMessageAuthor.text = parentChatMessage.actorDisplayName
?: context!!.getText(R.string.nc_nick_guest) ?: context.getText(R.string.nc_nick_guest)
binding.messageQuote.quotedMessage.text = parentChatMessage.text binding.messageQuote.quotedMessage.text = parentChatMessage.text
binding.messageQuote.quotedMessageAuthor binding.messageQuote.quotedMessageAuthor
.setTextColor(ContextCompat.getColor(context!!, R.color.textColorMaxContrast)) .setTextColor(ContextCompat.getColor(context, R.color.textColorMaxContrast))
if (parentChatMessage.actorId?.equals(message.activeUser!!.userId) == true) { if (parentChatMessage.actorId?.equals(message.activeUser!!.userId) == true) {
binding.messageQuote.quoteColoredView.setBackgroundResource(R.color.colorPrimary) binding.messageQuote.quoteColoredView.setBackgroundResource(R.color.colorPrimary)

View file

@ -79,7 +79,7 @@ class OutcomingPollMessageViewHolder(outcomingView: View, payload: Any) : Messag
colorizeMessageBubble(message) colorizeMessageBubble(message)
itemView.isSelected = false itemView.isSelected = false
binding.messageTime.setTextColor(context!!.resources.getColor(R.color.white60)) binding.messageTime.setTextColor(context.resources.getColor(R.color.white60))
// parent message handling // parent message handling
setParentMessageDataOnMessageItem(message) setParentMessageDataOnMessageItem(message)
@ -97,13 +97,13 @@ class OutcomingPollMessageViewHolder(outcomingView: View, payload: Any) : Messag
} }
readStatusDrawableInt?.let { drawableInt -> readStatusDrawableInt?.let { drawableInt ->
AppCompatResources.getDrawable(context!!, drawableInt)?.let { AppCompatResources.getDrawable(context, drawableInt)?.let {
it.setColorFilter(context?.resources!!.getColor(R.color.white60), PorterDuff.Mode.SRC_ATOP) it.setColorFilter(context.resources!!.getColor(R.color.white60), PorterDuff.Mode.SRC_ATOP)
binding.checkMark.setImageDrawable(it) binding.checkMark.setImageDrawable(it)
} }
} }
binding.checkMark.setContentDescription(readStatusContentDescriptionString) binding.checkMark.contentDescription = readStatusContentDescriptionString
setPollPreview(message) setPollPreview(message)
@ -152,7 +152,7 @@ class OutcomingPollMessageViewHolder(outcomingView: View, payload: Any) : Messag
} }
val credentials = ApiUtils.getCredentials(message.activeUser?.username, message.activeUser?.token) val credentials = ApiUtils.getCredentials(message.activeUser?.username, message.activeUser?.token)
ncApi!!.getPoll( ncApi.getPoll(
credentials, credentials,
ApiUtils.getUrlForPoll( ApiUtils.getUrlForPoll(
message.activeUser?.baseUrl, message.activeUser?.baseUrl,
@ -203,12 +203,12 @@ class OutcomingPollMessageViewHolder(outcomingView: View, payload: Any) : Messag
binding.messageQuote.quotedMessageImage.visibility = View.GONE binding.messageQuote.quotedMessageImage.visibility = View.GONE
} }
binding.messageQuote.quotedMessageAuthor.text = parentChatMessage.actorDisplayName binding.messageQuote.quotedMessageAuthor.text = parentChatMessage.actorDisplayName
?: context!!.getText(R.string.nc_nick_guest) ?: context.getText(R.string.nc_nick_guest)
binding.messageQuote.quotedMessage.text = parentChatMessage.text binding.messageQuote.quotedMessage.text = parentChatMessage.text
binding.messageQuote.quotedMessage.setTextColor( binding.messageQuote.quotedMessage.setTextColor(
context!!.resources.getColor(R.color.nc_outcoming_text_default) context.resources.getColor(R.color.nc_outcoming_text_default)
) )
binding.messageQuote.quotedMessageAuthor.setTextColor(context!!.resources.getColor(R.color.nc_grey)) binding.messageQuote.quotedMessageAuthor.setTextColor(context.resources.getColor(R.color.nc_grey))
binding.messageQuote.quoteColoredView.setBackgroundResource(R.color.white) binding.messageQuote.quoteColoredView.setBackgroundResource(R.color.white)