Search in sources :

Example 21 with UsersDataModel

use of com.example.first_responder_app.dataModels.UsersDataModel in project FirstResponse by mattpost1700.

the class RespondingFragment method refreshData.

private void refreshData() {
    db.collection("users").whereEqualTo(FirestoreDatabase.FIELD_FIRE_DEPARTMENT_ID, activeUser.getFire_department_id()).whereGreaterThanOrEqualTo("responding_time", AppUtil.earliestTime(requireContext())).get().addOnCompleteListener(userTask -> {
        Log.d(TAG, "READ DATABASE - RESPONDING FRAGMENT");
        if (userTask.isSuccessful()) {
            ArrayList<UsersDataModel> temp = new ArrayList<>();
            for (QueryDocumentSnapshot userDoc : userTask.getResult()) {
                UsersDataModel user = userDoc.toObject(UsersDataModel.class);
                List<String> responses = user.getResponses();
                Log.d(TAG, "refreshData: " + isActive(responses.get(responses.size() - 1)));
                if (responses != null && responses.size() > 0 && isActive(responses.get(responses.size() - 1)))
                    temp.add(user);
            }
            Log.d(TAG, "refreshData: " + AppUtil.earliestTime(requireContext()).toDate());
            listOfRespondingDataModel.clear();
            listOfRespondingDataModel.addAll(temp);
            checkRespondersEmpty();
            respondingRecyclerViewAdapter.notifyDataSetChanged();
            Log.d("TAG", "populateResponders: ");
        } else {
            Log.w(TAG, "refreshData: Could not refresh", userTask.getException());
        }
    });
}
Also used : UsersDataModel(com.example.first_responder_app.dataModels.UsersDataModel) QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot) ArrayList(java.util.ArrayList)

Example 22 with UsersDataModel

use of com.example.first_responder_app.dataModels.UsersDataModel in project FirstResponse by mattpost1700.

the class NewChatRecyclerViewAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
    UsersDataModel u = mData.get(position);
    holder.newUser.setText("Remove " + u.getFull_name());
    holder.data = u;
}
Also used : UsersDataModel(com.example.first_responder_app.dataModels.UsersDataModel)

Example 23 with UsersDataModel

use of com.example.first_responder_app.dataModels.UsersDataModel in project FirstResponse by mattpost1700.

the class RespondersGroupRecyclerViewAdapter method onBindViewHolder.

@SuppressLint("SetTextI18n")
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
    UsersDataModel responder = responderList.get(position);
    holder.responderNameTextView.setText(responder.getFirst_name() + " " + responder.getLast_name());
    setResponseLocation(holder, responder);
    setEta(holder, responder);
}
Also used : UsersDataModel(com.example.first_responder_app.dataModels.UsersDataModel) SuppressLint(android.annotation.SuppressLint)

Example 24 with UsersDataModel

use of com.example.first_responder_app.dataModels.UsersDataModel 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)

Example 25 with UsersDataModel

use of com.example.first_responder_app.dataModels.UsersDataModel in project FirstResponse by mattpost1700.

the class RespondersRecyclerViewAdapterTest method setUp.

@BeforeEach
void setUp() {
    adapter = new RespondersRecyclerViewAdapter(mockFragment.getContext(), listOfResponders);
    mockView = mock(View.class);
    mockFragment = mock(Fragment.class);
    user1 = new UsersDataModel("address1", "first_name1", "last_name1", "password1", 1234567890L, "rank1", "username1", Timestamp.now(), "remote_path_to_profile_picture1");
    user2 = new UsersDataModel("address2", "first_name2", "last_name2", "password2", 1234567890L, "rank2", "username2", Timestamp.now(), "remote_path_to_profile_picture2");
}
Also used : UsersDataModel(com.example.first_responder_app.dataModels.UsersDataModel) View(com.google.firebase.firestore.core.View) Fragment(androidx.fragment.app.Fragment) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

UsersDataModel (com.example.first_responder_app.dataModels.UsersDataModel)26 ArrayList (java.util.ArrayList)10 QueryDocumentSnapshot (com.google.firebase.firestore.QueryDocumentSnapshot)9 ActiveUser (com.example.first_responder_app.interfaces.ActiveUser)8 SuppressLint (android.annotation.SuppressLint)6 View (android.view.View)6 ViewModelProvider (androidx.lifecycle.ViewModelProvider)6 NavDirections (androidx.navigation.NavDirections)6 NonNull (androidx.annotation.NonNull)5 NavHostFragment (androidx.navigation.fragment.NavHostFragment)5 FirestoreDatabase (com.example.first_responder_app.FirestoreDatabase)5 TAG (android.content.ContentValues.TAG)4 Context (android.content.Context)4 Bundle (android.os.Bundle)4 Log (android.util.Log)4 Toast (android.widget.Toast)4 Fragment (androidx.fragment.app.Fragment)4 UserViewModel (com.example.first_responder_app.viewModels.UserViewModel)4 List (java.util.List)4 Manifest (android.Manifest)3