use of com.example.first_responder_app.messaging.Chat in project FirstResponse by mattpost1700.
the class ChatGroupFragment method populateChatList.
private void populateChatList() {
db.collection("chat").get().addOnCompleteListener(task -> {
if (task.isSuccessful()) {
ArrayList<Chat> temp = new ArrayList<>();
for (QueryDocumentSnapshot doc : task.getResult()) {
ArrayList<String> members = (ArrayList<String>) doc.get("members");
if (user != null) {
String memberName = user.getFirst_name() + " " + user.getLast_name() + "/" + user.getDocumentId();
if (members.contains(memberName)) {
Timestamp t = (Timestamp) doc.get("most_recent_message_time");
Chat chat = new Chat(doc.getId(), (String) doc.get("most_recent_message"), members, (String) doc.get("chat_name"), t);
temp.add(chat);
}
}
}
listOfChats.clear();
listOfChats.addAll(temp);
Collections.sort(listOfChats);
Collections.reverse(listOfChats);
chatGroupRecyclerViewAdapter.notifyDataSetChanged();
} else {
Log.d(TAG, "db get failed in chat group page " + task.getException());
}
});
}
use of com.example.first_responder_app.messaging.Chat in project FirstResponse by mattpost1700.
the class ChatGroupRecyclerViewAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
Chat chat = mData.get(position);
Context context = holder.itemView.getContext();
String userId = "";
ActiveUser activeUser = (ActiveUser) context;
if (activeUser != null) {
UsersDataModel user = activeUser.getActive();
if (user != null) {
userId = user.getDocumentId();
}
}
ArrayList<String> members = chat.getMembers();
String a = holder.name.getText().toString();
String chatName = "";
// If it is direct message, set chat name to user's name, otherwise set chat name to the name stored in db
if (members.size() == 2) {
String[] memberAndId0 = members.get(0).split("/");
String[] memberAndId1 = members.get(1).split("/");
if (memberAndId0[1].equals(userId)) {
holder.name.setText(memberAndId1[0]);
} else {
holder.name.setText(memberAndId0[0]);
}
} else {
holder.name.setText(chat.getChatName());
a = holder.name.getText().toString();
}
holder.recentMsg.setText(chat.getMostRecentMessage());
holder.data = chat;
}
Aggregations