app / sg.edu.ntu.scse.cz2006.gymbuddies.ui.bdlist / BuddyListFragment

BuddyListFragment

open class BuddyListFragment : Fragment, AppConstants, OnRecyclerViewInteractedListener<ViewHolder!>

The fragment display list of buddies (favoured user) of current user it allow user to view profile information, start chat and un-favour of user

Author
Chia Yu

Since
2019-09-06

See Also
AppConstantsOnRecyclerViewInteractedListener

Constructors

<init>

The fragment display list of buddies (favoured user) of current user it allow user to view profile information, start chat and un-favour of user

BuddyListFragment()

Properties

adapter

adapter to bind data onto RecyclerView

var adapter: BuddyResultAdapter!

buddyListViewModel

view model to separate data from activity life cycle

var buddyListViewModel: BuddyListViewModel!

favBuddiesRef

document reference used to query user's favoured buddies record

var favBuddiesRef: DocumentReference!

favRecord

actual data holder user's favoured buddies record

var favRecord: FavBuddyRecord!

firestore

Firestore instance to query data

var firestore: FirebaseFirestore!

listFavUserIds

list to hold buddies's user id

var listFavUserIds: ArrayList<String!>!

listFavUsers

list to hold queried user data

var listFavUsers: ArrayList<User!>!

rvResult

reference to RecyclerView, which display list of user as search result

var rvResult: RecyclerView!

srlUpdateFav

reference to SwipeRefreshLayout, allow user to drag down for refresh data

var srlUpdateFav: SwipeRefreshLayout!

TAG

TAG is unique identifier to for logging purpose

val TAG: String!

tvEmptyMessage

view reference to empty view, when there is no user matched the condition, this view will be displayed

var tvEmptyMessage: TextView!

Functions

commitFavRecord

commit changes of removing user from buddies record in firestore

open fun commitFavRecord(): Unit

goChatActivity

redirect user to chat activity

open fun goChatActivity(other: User!): Unit

notifyAndUpdateView

notify recycler view about data is being modified. if nothing to display, it display empty view

open fun notifyAndUpdateView(): Unit

onCreateView

Android lifecycle fragment for creating the fragment view

open fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View?

onStart

Android framework lifecycle, perform update on data

open fun onStart(): Unit

onViewInteracted

interface for observer to handle event when subject notify the view interaction of RecyclerView

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

queryBuddies

called after #queryFavUserRecord() retrieved user's favoured record, perform another query to retrieve buddies' profile information

open fun queryBuddies(): Unit

queryFavUserRecord

query to Firestore to retrieve user's favoured buddies record

open fun queryFavUserRecord(): Unit

readData

start query to get data from Firestore Step 1: query user's favoured buddies record Step 2: query buddies user profile

open fun readData(): Unit

readFavRecordDoc

upon retrieving user's favoured buddies record, read documentation snapshot and save all record to #listFavUserIds

open fun readFavRecordDoc(documentSnapshot: DocumentSnapshot!): Unit

readUserQuerySnapshot

upon retrieving buddies' profile information, read documentation snapshot and save all record to #listFavUsers

open fun readUserQuerySnapshot(snapshots: QuerySnapshot!): Unit

unfavUser

remove user as buddy, it calls #commitFavRecord() to update favoured record to firestore

open fun unfavUser(other: User!): Unit