Commit da692e15 authored by Leonardo Aramaki's avatar Leonardo Aramaki

Fix view less/view more button getting lost

parent 2b9e7144
......@@ -3,6 +3,7 @@ package chat.rocket.android.chatroom.adapter
import android.animation.ValueAnimator
import android.text.method.LinkMovementMethod
import android.view.View
import android.view.ViewGroup
import android.view.animation.LinearInterpolator
import androidx.core.view.isVisible
import chat.rocket.android.R
......@@ -16,8 +17,6 @@ class MessageAttachmentViewHolder(
reactionListener: EmojiReactionListener? = null
) : BaseViewHolder<MessageAttachmentUiModel>(itemView, listener, reactionListener) {
private var expanded = true
init {
with(itemView) {
setupActionMenu(attachment_container)
......@@ -33,7 +32,11 @@ class MessageAttachmentViewHolder(
text_message_time.text = data.time
text_sender.text = data.senderName
text_content.text = data.content
text_view_more.text = viewLess
text_view_more.isVisible = true
text_view_more.text = if (isExpanded())viewLess else viewMore
val lp = text_content.layoutParams
lp.height = ViewGroup.LayoutParams.WRAP_CONTENT
text_content.layoutParams = lp
text_content.addOnLayoutChangeListener(object : View.OnLayoutChangeListener {
override fun onLayoutChange(v: View, left: Int, top: Int, right: Int, bottom: Int,
......@@ -45,8 +48,6 @@ class MessageAttachmentViewHolder(
return
}
text_view_more.isVisible = true
val expandAnimation = ValueAnimator
.ofInt(collapsedHeight, textMeasuredHeight)
.setDuration(300)
......@@ -57,18 +58,15 @@ class MessageAttachmentViewHolder(
.setDuration(300)
collapseAnimation.interpolator = LinearInterpolator()
val lp = text_content.layoutParams
expandAnimation.addUpdateListener {
val value = it.animatedValue as Int
lp.height = value
text_content.layoutParams = lp
expanded = if (value == textMeasuredHeight) {
if (value == textMeasuredHeight) {
text_view_more.text = viewLess
true
lp.height = ViewGroup.LayoutParams.WRAP_CONTENT
} else {
text_view_more.text = viewMore
false
}
}
......@@ -76,19 +74,18 @@ class MessageAttachmentViewHolder(
val value = it.animatedValue as Int
lp.height = value
text_content.layoutParams = lp
expanded = if (value == textMeasuredHeight) {
if (value == textMeasuredHeight) {
text_view_more.text = viewLess
true
lp.height = ViewGroup.LayoutParams.WRAP_CONTENT
} else {
text_view_more.text = viewMore
false
}
}
text_view_more.setOnClickListener {
if (expandAnimation.isRunning) return@setOnClickListener
if (expanded) {
if (isExpanded()) {
collapseAnimation.start()
} else {
expandAnimation.start()
......@@ -100,4 +97,11 @@ class MessageAttachmentViewHolder(
})
}
}
private fun isExpanded(): Boolean {
with(itemView) {
val lp = text_content.layoutParams
return lp.height == ViewGroup.LayoutParams.WRAP_CONTENT
}
}
}
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