app / sg.edu.ntu.scse.cz2006.gymbuddies / ChatActivity

ChatActivity

open class ChatActivity : AppCompatActivity, AppConstants, OnClickListener, OnRecyclerViewInteractedListener<ViewHolder!>

The Activity displaying chat history between another user, and allows user to sent and receive message.

Author
Chia Yu

Since
2019-10-22

Constructors

<init>

The Activity displaying chat history between another user, and allows user to sent and receive message.

ChatActivity()

Properties

adapter

adapter to bind #messages onto #rvMessages

var adapter: MessageAdapter!

chatRef

document reference used to get current chat room's info, response of query will be converted to #curChat

var chatRef: DocumentReference!

curChat

actual chat object holds information of current chat room

var curChat: Chat!

etMessage

View reference to EditText, which allow user to input message

var etMessage: EditText!

firestore

Firestore instance to query data

var firestore: FirebaseFirestore!

imgBtnSend

View reference to ImageButton, allow user to send out message

var imgBtnSend: ImageButton!

imgBuddyPic

view reference to ImageView, that shows icon of chat room

var imgBuddyPic: ImageView!

messages

list of chat messages within chat room

var messages: ArrayList<ChatMessage!>!

msgListener

observer to listen to changes on messages changes in current chat room

var msgListener: ListenerRegistration!

rvMessages

view reference to RecyclerView, which display #messages to user with help of #adapter

var rvMessages: RecyclerView!

TAG

TAG is unique identifier to for logging purpose

static val TAG: String

tvTitle

view reference to TextView, that shows title of chat room

var tvTitle: TextView!

uid

current user's id

var uid: String!

Functions

commitMessage

The method performs create/update of chat message on FirebaseFirestore

open fun commitMessage(msg: ChatMessage!): Unit

getProfilePic

The method query another user's profile picture as chat icon

open fun getProfilePic(imgUrl: String!): Unit

init

the method handle on data received from other activity, and based on the data to initialise activity.

open fun init(): Unit

listenToMessages

Register an observer on chat messages changes

open fun listenToMessages(): Unit

onClick

The method provides implementation for View.OnClickListener

open fun onClick(v: View!): Unit

onCreate

Android framework life cycle create reference to frequently update view, and set up adapter to display messages

open fun onCreate(savedInstanceState: Bundle?): Unit

onOptionsItemSelected

Handle option menu action like back button pressed on title bar

open fun onOptionsItemSelected(item: MenuItem!): Boolean

onPause

Android framework lifecycle, unregister an observer to listen to chat message changes

open fun onPause(): Unit

onResume

Android framework lifecycle, register an observer to listen to chat message changes

open fun onResume(): Unit

onViewInteracted

The method provides the implementation on user interacting with RecyclerView's items

open fun onViewInteracted(view: View!, holder: ViewHolder!, action: Int): Unit

queryChatByChatId

The method handle query about chat details from FirebaseFirestore if chat id is provided

open fun queryChatByChatId(): Unit

queryChatByParticipants

The method handle query about chat details from FirebaseFirestore if chat id is not provided, attempt to find chat detail based on member participation

open fun queryChatByParticipants(): Unit

queryCreateChat

The method create new chat record, once there is no chat found in FirebaseFirestore

open fun queryCreateChat(): Unit

recallMessage

The method performs recall of chat message on FirebaseFirestore

open fun recallMessage(msg: ChatMessage!): Unit

stopListenToMessages

Unregister observer on chat message changes

open fun stopListenToMessages(): Unit