Unverified Commit 8daf3d47 authored by Filipe de Lima Brito's avatar Filipe de Lima Brito Committed by GitHub

Merge pull request #1816 from RocketChat/fix-reaction-counter-not-showing

[FIX] Reactions counter not showing
parents 9077de6d dbce689b
...@@ -18,7 +18,9 @@ import chat.rocket.android.util.extensions.toList ...@@ -18,7 +18,9 @@ import chat.rocket.android.util.extensions.toList
import chat.rocket.core.model.Message import chat.rocket.core.model.Message
import chat.rocket.core.model.isSystemMessage import chat.rocket.core.model.isSystemMessage
import com.google.android.flexbox.FlexDirection import com.google.android.flexbox.FlexDirection
import com.google.android.flexbox.FlexWrap
import com.google.android.flexbox.FlexboxLayoutManager import com.google.android.flexbox.FlexboxLayoutManager
import com.google.android.flexbox.JustifyContent
abstract class BaseViewHolder<T : BaseUiModel<*>>( abstract class BaseViewHolder<T : BaseUiModel<*>>(
itemView: View, itemView: View,
...@@ -41,13 +43,12 @@ abstract class BaseViewHolder<T : BaseUiModel<*>>( ...@@ -41,13 +43,12 @@ abstract class BaseViewHolder<T : BaseUiModel<*>>(
private fun bindReactions() { private fun bindReactions() {
data?.let { data?.let {
val recyclerView = itemView.findViewById(R.id.recycler_view_reactions) as RecyclerView val recyclerView = itemView.findViewById(R.id.recycler_view_reactions) as RecyclerView
val adapter: MessageReactionsAdapter val adapter: MessageReactionsAdapter = if (recyclerView.adapter == null) {
if (recyclerView.adapter == null) { MessageReactionsAdapter()
adapter = MessageReactionsAdapter()
} else { } else {
adapter = recyclerView.adapter as MessageReactionsAdapter recyclerView.adapter as MessageReactionsAdapter
adapter.clear()
} }
adapter.clear()
if (it.nextDownStreamMessage == null) { if (it.nextDownStreamMessage == null) {
adapter.listener = object : EmojiReactionListener { adapter.listener = object : EmojiReactionListener {
...@@ -61,13 +62,16 @@ abstract class BaseViewHolder<T : BaseUiModel<*>>( ...@@ -61,13 +62,16 @@ abstract class BaseViewHolder<T : BaseUiModel<*>>(
} }
} }
} }
val context = itemView.context val context = itemView.context
val manager = FlexboxLayoutManager(context, FlexDirection.ROW) val manager = FlexboxLayoutManager(context, FlexDirection.ROW)
manager.justifyContent = JustifyContent.FLEX_START
recyclerView.layoutManager = manager recyclerView.layoutManager = manager
recyclerView.adapter = adapter recyclerView.adapter = adapter
adapter.addReactions(it.reactions.filterNot { reactionUiModel ->
reactionUiModel.unicode.startsWith(":") && reactionUiModel.url.isNullOrEmpty() if (it.reactions.isNotEmpty()) {
}) itemView.post { adapter.addReactions(it.reactions) }
}
} }
} }
} }
...@@ -129,4 +133,4 @@ abstract class BaseViewHolder<T : BaseUiModel<*>>( ...@@ -129,4 +133,4 @@ abstract class BaseViewHolder<T : BaseUiModel<*>>(
} }
return true return true
} }
} }
\ No newline at end of file
...@@ -4,7 +4,6 @@ import android.view.LayoutInflater ...@@ -4,7 +4,6 @@ import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.ImageView import android.widget.ImageView
import android.widget.TextView
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import chat.rocket.android.R import chat.rocket.android.R
...@@ -35,17 +34,17 @@ class MessageReactionsAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>() ...@@ -35,17 +34,17 @@ class MessageReactionsAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>()
} }
else -> { else -> {
view = inflater.inflate(R.layout.item_reaction, parent, false) view = inflater.inflate(R.layout.item_reaction, parent, false)
SingleReactionViewHolder(view, listener) ReactionViewHolder(view, listener)
} }
} }
} }
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
if (holder is SingleReactionViewHolder) { if (holder is ReactionViewHolder) {
holder.bind(reactions[position]) holder.bind(reactions[position])
} else { } else {
holder as AddReactionViewHolder holder as AddReactionViewHolder
holder.bind(reactions[0].messageId) holder.bind(reactions.first().messageId)
} }
} }
...@@ -73,7 +72,7 @@ class MessageReactionsAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>() ...@@ -73,7 +72,7 @@ class MessageReactionsAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>()
fun contains(reactionShortname: String) = fun contains(reactionShortname: String) =
reactions.firstOrNull { it.shortname == reactionShortname } != null reactions.firstOrNull { it.shortname == reactionShortname } != null
class SingleReactionViewHolder( class ReactionViewHolder(
view: View, view: View,
private val listener: EmojiReactionListener? private val listener: EmojiReactionListener?
) : RecyclerView.ViewHolder(view), View.OnClickListener { ) : RecyclerView.ViewHolder(view), View.OnClickListener {
...@@ -97,9 +96,11 @@ class MessageReactionsAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>() ...@@ -97,9 +96,11 @@ class MessageReactionsAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>()
this.reaction = reaction this.reaction = reaction
with(itemView) { with(itemView) {
if (reaction.url.isNullOrEmpty()) { if (reaction.url.isNullOrEmpty()) {
text_emoji.text = reaction.unicode // The view at index 0 corresponds to the one to display unicode text emoji.
view_flipper_reaction.displayedChild = 0 view_flipper_reaction.displayedChild = 0
text_emoji.text = reaction.unicode
} else { } else {
// The view at index 1 corresponds to the one to display custom emojis which are images.
view_flipper_reaction.displayedChild = 1 view_flipper_reaction.displayedChild = 1
val glideRequest = if (reaction.url!!.endsWith("gif", true)) { val glideRequest = if (reaction.url!!.endsWith("gif", true)) {
GlideApp.with(context).asGif() GlideApp.with(context).asGif()
...@@ -110,15 +111,16 @@ class MessageReactionsAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>() ...@@ -110,15 +111,16 @@ class MessageReactionsAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>()
glideRequest.load(reaction.url).into(image_emoji) glideRequest.load(reaction.url).into(image_emoji)
} }
text_count.text = reaction.count.toString()
val myself = localRepository.get(LocalRepository.CURRENT_USERNAME_KEY) val myself = localRepository.get(LocalRepository.CURRENT_USERNAME_KEY)
if (reaction.usernames.contains(myself)) { if (reaction.usernames.contains(myself)) {
val context = itemView.context val context = itemView.context
text_count.setTextColor(ContextCompat.getColor(context, R.color.colorAccent)) text_count.setTextColor(ContextCompat.getColor(context, R.color.colorAccent))
} }
view_flipper_reaction.setOnClickListener(this@SingleReactionViewHolder) text_count.text = reaction.count.toString()
text_count.setOnClickListener(this@SingleReactionViewHolder)
view_flipper_reaction.setOnClickListener(this@ReactionViewHolder)
text_count.setOnClickListener(this@ReactionViewHolder)
} }
} }
......
...@@ -19,7 +19,7 @@ interface LocalComponent { ...@@ -19,7 +19,7 @@ interface LocalComponent {
fun build(): LocalComponent fun build(): LocalComponent
} }
fun inject(adapter: MessageReactionsAdapter.SingleReactionViewHolder) fun inject(adapter: MessageReactionsAdapter.ReactionViewHolder)
fun inject(adapter: MessageReactionsAdapter.AddReactionViewHolder) fun inject(adapter: MessageReactionsAdapter.AddReactionViewHolder)
/*@Component.Builder /*@Component.Builder
......
...@@ -40,7 +40,7 @@ abstract class MessageDao { ...@@ -40,7 +40,7 @@ abstract class MessageDao {
@Insert(onConflict = OnConflictStrategy.REPLACE) @Insert(onConflict = OnConflictStrategy.REPLACE)
abstract fun insert(field: AttachmentFieldEntity) abstract fun insert(field: AttachmentFieldEntity)
@Insert(onConflict = OnConflictStrategy.IGNORE) @Insert(onConflict = OnConflictStrategy.REPLACE)
abstract fun insert(reaction: ReactionEntity) abstract fun insert(reaction: ReactionEntity)
@Insert(onConflict = OnConflictStrategy.REPLACE) @Insert(onConflict = OnConflictStrategy.REPLACE)
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:orientation="horizontal"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginEnd="2dp" android:layout_marginEnd="2dp"
...@@ -10,7 +11,7 @@ ...@@ -10,7 +11,7 @@
<ViewFlipper <ViewFlipper
android:id="@+id/view_flipper_reaction" android:id="@+id/view_flipper_reaction"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/text_count" app:layout_constraintEnd_toStartOf="@+id/text_count"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
...@@ -19,12 +20,13 @@ ...@@ -19,12 +20,13 @@
<TextView <TextView
android:id="@+id/text_emoji" android:id="@+id/text_emoji"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:ellipsize="end" android:ellipsize="end"
android:gravity="center"
android:maxLines="1" android:maxLines="1"
android:paddingStart="4dp" android:paddingStart="4dp"
android:paddingLeft="4dp" android:paddingLeft="4dp"
android:textColor="#868585" android:textColor="@color/reaction_text"
android:textSize="16sp" android:textSize="16sp"
tools:text=":)" /> tools:text=":)" />
...@@ -48,13 +50,12 @@ ...@@ -48,13 +50,12 @@
android:paddingEnd="4dp" android:paddingEnd="4dp"
android:paddingRight="4dp" android:paddingRight="4dp"
android:paddingBottom="4dp" android:paddingBottom="4dp"
android:textColor="#868585" android:textColor="@color/reaction_text"
android:textSize="16sp" android:textSize="16sp"
android:textStyle="bold" android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/view_flipper_reaction"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
tools:text="12" /> tools:text="12" />
</androidx.constraintlayout.widget.ConstraintLayout> </LinearLayout>
...@@ -2,4 +2,4 @@ ...@@ -2,4 +2,4 @@
<androidx.recyclerview.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android" <androidx.recyclerview.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/recycler_view_reactions" android:id="@+id/recycler_view_reactions"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" /> android:layout_height="wrap_content" />
\ No newline at end of file
...@@ -59,4 +59,6 @@ ...@@ -59,4 +59,6 @@
<!-- Default Background Color --> <!-- Default Background Color -->
<color name="default_background">#FAFAFA</color> <color name="default_background">#FAFAFA</color>
<color name="reaction_text">#868585</color>
</resources> </resources>
...@@ -25,7 +25,7 @@ ext { ...@@ -25,7 +25,7 @@ ext {
firebaseAnalytics : '16.0.3', firebaseAnalytics : '16.0.3',
playServices : '16.0.0', playServices : '16.0.0',
exoPlayer : '2.8.2', exoPlayer : '2.8.2',
flexbox : '1.0.0', flexbox : '1.1.0',
material : '1.0.0-beta01', material : '1.0.0-beta01',
room : '2.0.0', room : '2.0.0',
......
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