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