Search in sources :

Example 11 with ActiveUser

use of com.example.first_responder_app.interfaces.ActiveUser 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;
}
Also used : Context(android.content.Context) UsersDataModel(com.example.first_responder_app.dataModels.UsersDataModel) ActiveUser(com.example.first_responder_app.interfaces.ActiveUser) Chat(com.example.first_responder_app.messaging.Chat)

Aggregations

ActiveUser (com.example.first_responder_app.interfaces.ActiveUser)11 UsersDataModel (com.example.first_responder_app.dataModels.UsersDataModel)9 NavDirections (androidx.navigation.NavDirections)7 ViewModelProvider (androidx.lifecycle.ViewModelProvider)6 NavHostFragment (androidx.navigation.fragment.NavHostFragment)6 Bundle (android.os.Bundle)5 View (android.view.View)5 NonNull (androidx.annotation.NonNull)5 NavController (androidx.navigation.NavController)5 FirestoreDatabase (com.example.first_responder_app.FirestoreDatabase)5 TAG (android.content.ContentValues.TAG)4 Log (android.util.Log)4 LayoutInflater (android.view.LayoutInflater)4 ViewGroup (android.view.ViewGroup)4 Toast (android.widget.Toast)4 Nullable (androidx.annotation.Nullable)4 DataBindingUtil (androidx.databinding.DataBindingUtil)4 Navigation (androidx.navigation.Navigation)4 R (com.example.first_responder_app.R)4 QueryDocumentSnapshot (com.google.firebase.firestore.QueryDocumentSnapshot)4