Aim
Group Chats has already been created. I would like to prompt out the name of the Group Chats onto a RecyclerView.
Database Tree
I have an Admin Account to create these Group Chats for the users.
The Android, Asia, and Europe group chats that are seen within the Database ARE NOT fixed variables. They are names. A newly Group Chat name could be "Earth".
Therefore there is no way of calling it by a variable other than calling it by the Node itself.
Problem
I am unable to prompt out any of the Group Chat "names" created by the Admin. Meaning, I am unable to prompt out the "Android", "Asia", and "Europe" or any Group Chats created and stored within the Group Chats node
Flow of Activities
AdminActivity---{Creates Group Chat.func}
Users----views---->GroupFragment{GroupChats are Prompted}
AdminActivity.java - createGroupChat Function
public void createGroupChat(){
Map<String, Object> groupChatMap = new HashMap<String, Object>();
groupChatMap.put(jAdminGroupChatName.getText().toString(),"");
groupChatRoot.updateChildren(groupChatMap);
Toast.makeText(AdminActivity.this, "Group Chat Created", Toast.LENGTH_SHORT).show();
jAdminGroupChatName.setText("");
}
GroupChats Class
// GET GROUP CHAT NAME
public class GroupChats {
public String name;
public GroupChats() {
}
public GroupChats(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
GroupFragment.java
@Override
public void onStart() {
super.onStart();
FirebaseRecyclerAdapter<GroupChats, GroupChatViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<GroupChats, GroupChatViewHolder>(
GroupChats.class,
R.layout.layout_groups,
GroupChatViewHolder.class,
jGroupsDatabase
){
@Override
protected void populateViewHolder(GroupChatViewHolder viewHolder, GroupChats model, int position) {
viewHolder.setName(model.getName());
final String viewGroupID = getRef(position).getKey();
viewHolder.jGroupChatView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intentGroupChat = new Intent(getActivity(), ChatFragment.class);
intentGroupChat.putExtra("viewGroupID", viewGroupID);
startActivity(intentGroupChat);
}
});
}
};
jGroupChatList.setAdapter(firebaseRecyclerAdapter);
}
public static class GroupChatViewHolder extends RecyclerView.ViewHolder{
View jGroupChatView;
public GroupChatViewHolder(View itemView) {
super(itemView);
jGroupChatView = itemView;
}
public void setName(String groupName){
TextView jAllGroupChatName = jGroupChatView.findViewById(R.id.groupChatNameTxt);
jAllGroupChatName.setText(groupName);
}
}
}
Additional Comments
- Online Tutorial
I have watched an Android Firebase Group Chat tutorial on youtube. The link is https://www.youtube.com/watch?v=wVCz1a3ogqk. In that video, the developer wrote the code in a way which prompts the Group Chat names within the same class which is the MainActivity.java.
Tutorial Flow:
MainActivity----{Creates Group Chat.func}----{Group Chat Prompt.func}
- Task Requirement
The requirements of my task makes it necessary for me to create it from the AdminActivity and prompt the Group Chat names only for the User's view.
Task Flow:
AdminActivity---{Creates Group Chat.function}
Users----views---->GroupFragment{GroupChats are Prompted}
Future Implementations - Future Question
If I'm able to solve this problem with the help of Stackoverflow users, my future implementation is to allow the Users to click on the "Group Chat" names which will then bring them into the group chat itself, thereby allowing the Email Authenticated(Firebase) users to chat with others inside that Group Chat. Of course, if I am unable to write the codes for that, I will ask for a solution in another Question.