Created
June 17, 2019 11:20
-
-
Save TobiAlbert/ea5dd542a5ed30838905df8f844ea6f3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class RoomViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { | |
| fun bind(message: Message, championId: String) { | |
| val layoutParams = itemView.message_root_view.layoutParams as LinearLayoutCompat.LayoutParams | |
| if (message.sender.id == championId) { | |
| layoutParams.gravity = Gravity.END | |
| itemView.message_root_view.layoutParams = layoutParams | |
| } else { | |
| layoutParams.gravity = Gravity.START | |
| itemView.message_root_view.layoutParams = layoutParams | |
| } | |
| val payload = message.parts.first().payload | |
| val messageText = when (payload) { | |
| is Payload.Inline -> payload.content | |
| else -> "" | |
| } | |
| itemView.message_text.text = messageText | |
| } | |
| companion object { | |
| fun create(parent: ViewGroup): RoomViewHolder { | |
| val rootView = LayoutInflater.from(parent.context) | |
| .inflate(R.layout.chat_item, parent, false) | |
| return RoomViewHolder(rootView) | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment