app / sg.edu.ntu.scse.cz2006.gymbuddies.adapter / MessageAdapter

MessageAdapter

open class MessageAdapter : Adapter<ViewHolder!>

Recycler Adapter for Chat Message For sg.edu.ntu.scse.cz2006.gymbuddies.adapter in Gym Buddies! The adapter is used to display chat message between users.

Author
Chia Yu

Since
2019-10-19

Types

MessageReceivedViewHolder

View Holder for message sent out from current user, it holds reference to frequent update views and provides helper method to bind data information onto views

open class MessageReceivedViewHolder : ViewHolder

MessageSentViewHolder

View Holder for message received from other user, it holds reference to frequent update views and provides helper method to bind data information onto views

open class MessageSentViewHolder : ViewHolder, OnLongClickListener

Constructors

<init>

Constructor method to set up MessageAdapter

MessageAdapter(messages: ArrayList<ChatMessage!>!, sender: String!)

Properties

ACTION_LONG_CLICK_ON_VIEW

unique identifier to specify user long clicked on a view

static val ACTION_LONG_CLICK_ON_VIEW: Int

listener

interface that allow activity to observe user interaction with RecyclerView

var listener: OnRecyclerViewInteractedListener<ViewHolder!>!

messages

list that holds the chat history with another user in the same chat room

var messages: ArrayList<ChatMessage!>!

sdfDate

It is used to format timestamp from long to String for ChatMessage date

var sdfDate: SimpleDateFormat!

sdfTime

It is used to format timestamp from long to String for ChatMessage time

var sdfTime: SimpleDateFormat!

sender

UID of current user, used to identify message is sent out or received

var sender: String!

TAG

TAG is unique identifier to for logging purpose

static val TAG: String

VIEW_TYPE_MSG_RECEIVED

unique identifier to type of view to be render for ChatMessage object

static val VIEW_TYPE_MSG_RECEIVED: Int

VIEW_TYPE_MSG_SENT

unique identifier to type of view to be render for ChatMessage object

static val VIEW_TYPE_MSG_SENT: Int

Functions

getItemCount

the method is return number of messages to be display on RecyclerView

open fun getItemCount(): Int

getItemViewType

the method return type of view based on current user id view type will determine either message sent or received item layout to be rendered on screen

open fun getItemViewType(position: Int): Int

onBindViewHolder

this method make use of view holder to update display information onto the view

open fun onBindViewHolder(holder: ViewHolder, position: Int): Unit

onCreateViewHolder

the method based on view type to render a view and associate the view with respective view holder

open fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder

setOnRecyclerViewInteractListener

The method provides an interface to allow other class to register itself as observer of user interacting event

open fun setOnRecyclerViewInteractListener(listener: OnRecyclerViewInteractedListener<ViewHolder!>!): Unit