Commit 37073556 authored by Leonardo Aramaki's avatar Leonardo Aramaki

Some minor code refactoring

parent 66bd3831
...@@ -20,23 +20,6 @@ class MessageViewHolder( ...@@ -20,23 +20,6 @@ class MessageViewHolder(
listener: ActionsListener, listener: ActionsListener,
reactionListener: EmojiReactionListener? = null reactionListener: EmojiReactionListener? = null
) : BaseViewHolder<MessageUiModel>(itemView, listener, reactionListener), Drawable.Callback { ) : BaseViewHolder<MessageUiModel>(itemView, listener, reactionListener), Drawable.Callback {
override fun unscheduleDrawable(who: Drawable?, what: Runnable?) {
with(itemView) {
text_content.removeCallbacks(what)
}
}
override fun invalidateDrawable(p0: Drawable?) {
with(itemView) {
text_content.invalidate()
}
}
override fun scheduleDrawable(who: Drawable?, what: Runnable?, w: Long) {
with(itemView) {
text_content.postDelayed(what, w)
}
}
init { init {
with(itemView) { with(itemView) {
...@@ -46,21 +29,14 @@ class MessageViewHolder( ...@@ -46,21 +29,14 @@ class MessageViewHolder(
} }
override fun bindViews(data: MessageUiModel) { override fun bindViews(data: MessageUiModel) {
itemView.day_marker_layout.visibility = if (data.showDayMarker) { with(itemView) {
itemView.day.text = data.currentDayMarkerText day.text = data.currentDayMarkerText
View.VISIBLE day_marker_layout.isVisible = data.showDayMarker
} else {
View.GONE
}
if (data.isFirstUnread) { new_messages_notif.isVisible = data.isFirstUnread
itemView.new_messages_notif.visibility = View.VISIBLE
} else {
itemView.new_messages_notif.visibility = View.GONE
}
itemView.text_message_time.text = data.time text_message_time.text = data.time
itemView.text_sender.text = data.senderName text_sender.text = data.senderName
if (data.content is Spannable) { if (data.content is Spannable) {
val spans = data.content.getSpans(0, data.content.length, ImageSpan::class.java) val spans = data.content.getSpans(0, data.content.length, ImageSpan::class.java)
...@@ -72,27 +48,46 @@ class MessageViewHolder( ...@@ -72,27 +48,46 @@ class MessageViewHolder(
} }
} }
itemView.text_content.text_content.text = data.content text_content.text_content.text = data.content
itemView.image_avatar.setImageURI(data.avatar) image_avatar.setImageURI(data.avatar)
itemView.text_content.setTextColor(if (data.isTemporary) Color.GRAY else Color.BLACK) text_content.setTextColor(if (data.isTemporary) Color.GRAY else Color.BLACK)
data.message.let { data.message.let {
itemView.text_edit_indicator.isVisible = !it.isSystemMessage() && it.editedBy != null text_edit_indicator.isVisible = !it.isSystemMessage() && it.editedBy != null
itemView.image_star_indicator.isVisible = it.starred?.isNotEmpty() ?: false image_star_indicator.isVisible = it.starred?.isNotEmpty() ?: false
} }
if (data.unread == null) { if (data.unread == null) {
itemView.read_receipt_view.isVisible = false read_receipt_view.isVisible = false
} else { } else {
itemView.read_receipt_view.setImageResource( read_receipt_view.setImageResource(
if (data.unread == true) { if (data.unread == true) {
R.drawable.ic_check_unread_24dp R.drawable.ic_check_unread_24dp
} else { } else {
R.drawable.ic_check_read_24dp R.drawable.ic_check_read_24dp
} }
) )
itemView.read_receipt_view.isVisible = true read_receipt_view.isVisible = true
}
}
}
override fun unscheduleDrawable(who: Drawable?, what: Runnable?) {
with(itemView) {
text_content.removeCallbacks(what)
}
}
override fun invalidateDrawable(p0: Drawable?) {
with(itemView) {
text_content.invalidate()
}
}
override fun scheduleDrawable(who: Drawable?, what: Runnable?, w: Long) {
with(itemView) {
text_content.postDelayed(what, w)
} }
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment