use of com.google.firebase.firestore.QueryDocumentSnapshot in project FirstResponse by mattpost1700.
the class HomeFragment method populateResponders.
public void populateResponders() {
db.collection("users").whereEqualTo(FirestoreDatabase.FIELD_FIRE_DEPARTMENT_ID, activeUser.getFire_department_id()).whereGreaterThanOrEqualTo(FirestoreDatabase.FIELD_RESPONDING_TIME, AppUtil.earliestTime(requireContext())).get().addOnCompleteListener(userTask -> {
Log.d(TAG, "READ DATABASE - HOME FRAGMENT (populateResponders)");
if (userTask.isSuccessful()) {
ArrayList<UsersDataModel> temp = new ArrayList<>();
for (QueryDocumentSnapshot userDoc : userTask.getResult()) {
UsersDataModel user = userDoc.toObject(UsersDataModel.class);
List<String> responses = user.getResponses();
if (responses != null && responses.size() > 0 && isActive(responses.get(responses.size() - 1)))
temp.add(user);
}
respondersList.clear();
respondersList.addAll(temp);
respondersRecyclerViewAdapter.notifyDataSetChanged();
// TODO: Should refresh
Log.d("TAG", "populateResponders: ");
}
});
}
use of com.google.firebase.firestore.QueryDocumentSnapshot in project FirstResponse by mattpost1700.
the class IncidentFragment method populateResponders.
public void populateResponders(int startIdx, int endIdx) {
FirestoreDatabase.getInstance().getDb().collection("users").whereIn(FieldPath.documentId(), incidentDataModel.getResponding().subList(startIdx, endIdx)).get().addOnCompleteListener(responderTask -> {
Log.d(TAG, "READ DATABASE - EVENT FRAGMENT");
if (responderTask.isSuccessful()) {
List<UsersDataModel> tempList = new ArrayList<>();
for (QueryDocumentSnapshot userDoc : responderTask.getResult()) {
UsersDataModel userData = userDoc.toObject(UsersDataModel.class);
tempList.add(userData);
}
responderList.addAll(tempList);
responderArr = new CharSequence[responderList.size()];
for (int i = 0; i < responderList.size(); i++) {
responderArr[i] = responderList.get(i).getFull_name();
}
} else {
Log.w(TAG, "populateResponderList: Responder data failed to query", responderTask.getException());
}
});
}
use of com.google.firebase.firestore.QueryDocumentSnapshot in project FirstResponse by mattpost1700.
the class IncidentGroupFragment method refreshData.
private void refreshData() {
db.collection("incident").whereArrayContains(FirestoreDatabase.FIELD_FIRE_DEPARTMENTS, activeUser.getFire_department_id()).get().addOnCompleteListener(incidentTask -> {
Log.d(TAG, "READ DATABASE - INCIDENT GROUP FRAGMENT");
if (incidentTask.isSuccessful()) {
ArrayList<IncidentDataModel> temp = new ArrayList<>();
for (QueryDocumentSnapshot incidentDoc : incidentTask.getResult()) {
IncidentDataModel incidentDataModel = incidentDoc.toObject(IncidentDataModel.class);
temp.add(incidentDataModel);
}
listOfIncidentDataModel.clear();
listOfIncidentDataModel.addAll(temp);
checkIncidentsEmpty();
incidentGroupRecyclerViewAdapter.notifyDataSetChanged();
} else {
Log.w(TAG, "onCreateView: get failed in HomeFragment with", incidentTask.getException());
}
});
}
use of com.google.firebase.firestore.QueryDocumentSnapshot in project FirstResponse by mattpost1700.
the class LoginFragment method populateUserList.
private void populateUserList(String usernameInput) {
db.collection("users").whereEqualTo("username", usernameInput).get().addOnCompleteListener(usersTask -> {
Log.d(TAG, "READ DATABASE - LOGIN FRAGMENT");
if (usersTask.isSuccessful()) {
for (QueryDocumentSnapshot userDoc : usersTask.getResult()) {
user = userDoc.toObject(UsersDataModel.class);
checkExist = true;
}
} else {
Log.d(TAG, "db get failed in Login page " + usersTask.getException());
checkExist = false;
}
});
}
use of com.google.firebase.firestore.QueryDocumentSnapshot in project FirstResponse by mattpost1700.
the class LoginFragment method onStart.
@Override
public void onStart() {
super.onStart();
SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE);
String usernameQuickLogin = sharedPref.getString("savedUsername", null);
String passwordQuickLogin = sharedPref.getString("savedPassword", null);
Log.d("testing", "usernameQuick: " + usernameQuickLogin);
Log.d("testing", "pwQuick: " + passwordQuickLogin);
if (usernameQuickLogin != null && passwordQuickLogin != null) {
db.collection("users").whereEqualTo("username", usernameQuickLogin).whereEqualTo("password", passwordQuickLogin).get().addOnCompleteListener(usersTask -> {
Log.d(TAG, "READ DATABASE - LOGIN FRAGMENT");
if (usersTask.isSuccessful()) {
for (QueryDocumentSnapshot userDoc : usersTask.getResult()) {
user = userDoc.toObject(UsersDataModel.class);
checkExist = true;
if (user.getPassword().equals(passwordQuickLogin)) {
Log.d(TAG, "onStart: LOGIN");
ActiveUser activeUser = ((ActiveUser) getActivity());
activeUser.setActive(user);
if (FirestoreDatabase.getInstance().setActiveUser(user)) {
successfullyHidAdminOptions();
NavDirections action = LoginFragmentDirections.actionLoginFragmentToHomeFragment();
Navigation.findNavController(binding.getRoot()).navigate(action);
} else {
// User cannot make good queries
Toast.makeText(getContext(), "User does not have a department", Toast.LENGTH_SHORT).show();
}
}
}
} else {
Log.d(TAG, "db get failed in Login page " + usersTask.getException());
checkExist = false;
}
});
}
}
Aggregations