Commit c8a365ae authored by Leonardo Aramaki's avatar Leonardo Aramaki

Clear scrapped reaction views and fix layout

parent 1f108732
...@@ -32,13 +32,20 @@ abstract class BaseViewHolder<T : BaseViewModel<*>>( ...@@ -32,13 +32,20 @@ abstract class BaseViewHolder<T : BaseViewModel<*>>(
private fun bindReactions() { private fun bindReactions() {
data?.let { data?.let {
val recyclerView = itemView.findViewById(R.id.recycler_view_reactions) as RecyclerView
val adapter: MessageReactionsAdapter
if (recyclerView.adapter == null) {
adapter = MessageReactionsAdapter()
} else {
adapter = recyclerView.adapter as MessageReactionsAdapter
adapter.clear()
}
if (it.nextDownStreamMessage == null) { if (it.nextDownStreamMessage == null) {
val recyclerView = itemView.findViewById(R.id.recycler_view_reactions) as RecyclerView
val adapter = MessageReactionsAdapter()
val manager = GridLayoutManager(itemView.context, 6) val manager = GridLayoutManager(itemView.context, 6)
recyclerView.layoutManager = manager recyclerView.layoutManager = manager
recyclerView.adapter = adapter recyclerView.adapter = adapter
adapter.addReactions(it.reactions) adapter.addReactions(it.reactions.filterNot { it.shortname.startsWith(":") })
} }
} }
} }
......
...@@ -34,6 +34,12 @@ class MessageReactionsAdapter : RecyclerView.Adapter<MessageReactionsViewHolder> ...@@ -34,6 +34,12 @@ class MessageReactionsAdapter : RecyclerView.Adapter<MessageReactionsViewHolder>
notifyItemRangeInserted(0, reactions.size) notifyItemRangeInserted(0, reactions.size)
} }
fun clear() {
val oldSize = reactions.size
reactions.clear()
notifyItemRangeRemoved(0, oldSize)
}
class MessageReactionsViewHolder(view: View) : RecyclerView.ViewHolder(view) { class MessageReactionsViewHolder(view: View) : RecyclerView.ViewHolder(view) {
@Inject lateinit var localRepository: LocalRepository @Inject lateinit var localRepository: LocalRepository
......
...@@ -171,6 +171,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardPopup.Listener { ...@@ -171,6 +171,7 @@ class ChatRoomFragment : Fragment(), ChatRoomView, EmojiKeyboardPopup.Listener {
val oldMessagesCount = adapter.itemCount val oldMessagesCount = adapter.itemCount
adapter.appendData(dataSet) adapter.appendData(dataSet)
recycler_view.scrollToPosition(92)
if (oldMessagesCount == 0 && dataSet.isNotEmpty()) { if (oldMessagesCount == 0 && dataSet.isNotEmpty()) {
recycler_view.scrollToPosition(0) recycler_view.scrollToPosition(0)
} }
......
...@@ -48,6 +48,6 @@ ...@@ -48,6 +48,6 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="@+id/text_description" app:layout_constraintEnd_toEndOf="@+id/text_description"
app:layout_constraintStart_toStartOf="@+id/text_description" app:layout_constraintStart_toStartOf="@+id/image_preview"
app:layout_constraintTop_toBottomOf="@+id/text_description" /> app:layout_constraintTop_toBottomOf="@+id/text_description" />
</android.support.constraint.ConstraintLayout> </android.support.constraint.ConstraintLayout>
\ No newline at end of file
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