Commit 8febc00e authored by Leonardo Aramaki's avatar Leonardo Aramaki

Append AddReactionViewHolder to reactions panel

parent f8a6147f
......@@ -6,27 +6,51 @@ import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import chat.rocket.android.R
import chat.rocket.android.chatroom.adapter.MessageReactionsAdapter.MessageReactionsViewHolder
import chat.rocket.android.chatroom.viewmodel.ReactionViewModel
import chat.rocket.android.dagger.DaggerLocalComponent
import chat.rocket.android.infrastructure.LocalRepository
import java.util.concurrent.CopyOnWriteArrayList
import javax.inject.Inject
class MessageReactionsAdapter : RecyclerView.Adapter<MessageReactionsViewHolder>() {
class MessageReactionsAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
companion object {
private const val REACTION_VIEW_TYPE = 0
private const val ADD_REACTION_VIEW_TYPE = 1
}
private val reactions = CopyOnWriteArrayList<ReactionViewModel>()
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MessageReactionsViewHolder {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
val inflater = LayoutInflater.from(parent.context)
val view = inflater.inflate(R.layout.item_reaction, parent, false)
return MessageReactionsViewHolder(view)
val view: View
return when (viewType) {
ADD_REACTION_VIEW_TYPE -> {
view = inflater.inflate(R.layout.item_add_reaction, parent, false)
AddReactionViewHolder(view)
}
else -> {
view = inflater.inflate(R.layout.item_reaction, parent, false)
SingleReactionViewHolder(view)
}
}
}
override fun onBindViewHolder(holder: MessageReactionsViewHolder, position: Int) {
holder.bind(reactions[position])
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
if (holder is SingleReactionViewHolder) {
holder.bind(reactions[position])
} else {
}
}
override fun getItemCount() = reactions.size
override fun getItemCount() = if (reactions.isEmpty()) 0 else reactions.size + 1
override fun getItemViewType(position: Int): Int {
if (position == reactions.size) {
return ADD_REACTION_VIEW_TYPE
}
return REACTION_VIEW_TYPE
}
fun addReactions(reactions: List<ReactionViewModel>) {
this.reactions.clear()
......@@ -40,7 +64,7 @@ class MessageReactionsAdapter : RecyclerView.Adapter<MessageReactionsViewHolder>
notifyItemRangeRemoved(0, oldSize)
}
class MessageReactionsViewHolder(view: View) : RecyclerView.ViewHolder(view) {
class SingleReactionViewHolder(view: View) : RecyclerView.ViewHolder(view) {
@Inject lateinit var localRepository: LocalRepository
init {
......@@ -65,4 +89,8 @@ class MessageReactionsAdapter : RecyclerView.Adapter<MessageReactionsViewHolder>
}
}
}
class AddReactionViewHolder(view: View) : RecyclerView.ViewHolder(view) {
}
}
\ No newline at end of file
......@@ -342,6 +342,19 @@ class ChatRoomPresenter @Inject constructor(private val view: ChatRoomView,
fun toMembersList(chatRoomId: String, chatRoomType: String) = navigator.toMembersList(chatRoomId, chatRoomType)
/**
* Send an emoji reaction to a message.
*/
fun react(messageId: String, emoji: String) {
launchUI(strategy) {
try {
client.react(messageId, emoji)
} catch (ex: RocketChatException) {
Timber.e(ex)
}
}
}
private fun updateMessage(streamedMessage: Message) {
launchUI(strategy) {
val viewModelStreamedMessage = mapper.map(streamedMessage)
......
......@@ -19,7 +19,8 @@ interface LocalComponent {
fun build(): LocalComponent
}
fun inject(adapter: MessageReactionsAdapter.MessageReactionsViewHolder)
fun inject(adapter: MessageReactionsAdapter.SingleReactionViewHolder)
fun inject(adapter: MessageReactionsAdapter.AddReactionViewHolder)
/*@Component.Builder
abstract class Builder : AndroidInjector.Builder<RocketChatApplication>()*/
......
<?xml version="1.0" encoding="utf-8"?>
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="24dp"
android:layout_height="24dp"
android:src="@drawable/ic_add_reaction" />
\ 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