use of com.example.first_responder_app.dataModels.UsersDataModel in project FirstResponse by mattpost1700.
the class SearchUserAdapter method filter.
public void filter(String charText) {
charText = charText.toLowerCase(Locale.getDefault());
usersList.clear();
if (charText.length() == 0) {
usersList.addAll(origUserList);
} else {
for (UsersDataModel mUser : origUserList) {
if (mUser.getFull_name().toLowerCase(Locale.getDefault()).contains(charText)) {
usersList.add(mUser);
}
}
}
notifyDataSetChanged();
}
use of com.example.first_responder_app.dataModels.UsersDataModel in project FirstResponse by mattpost1700.
the class RespondersRecyclerViewAdapter 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);
}
use of com.example.first_responder_app.dataModels.UsersDataModel in project FirstResponse by mattpost1700.
the class EditUserFragment method onCreateView.
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
// binding fragment with nav_map by using navHostFragment, throw this block of code in there and that allows you to switch to other fragments
FragmentEditUserBinding binding = DataBindingUtil.inflate(inflater, R.layout.fragment_edit_user, container, false);
NavHostFragment navHostFragment = (NavHostFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.nav_host_fragment);
// TODO: navCont created for side bar(still need to be implemented)
NavController navController = navHostFragment.getNavController();
// sharedViewModel = new ViewModelProvider(requireActivity()).get(SharedViewModel.class);
firestoreDatabase = new FirestoreDatabase();
db = firestoreDatabase.getDb();
activeUser = (ActiveUser) getActivity();
if (activeUser != null) {
user = activeUser.getActive();
}
Spinner rankSpinner = binding.userRank;
ranksAndIds = new HashMap<>();
populateRanks(rankSpinner);
populateEditTexts(binding.userFirstName, binding.userLastName, binding.userPhone, binding.userAddress);
rankSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
rankSpinner.setSelection(position);
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
// can leave this empty
}
});
binding.saveButton.setOnClickListener(v -> {
String firstName = binding.userFirstName.getText().toString();
String lastName = binding.userLastName.getText().toString();
String phone = binding.userPhone.getText().toString();
String address = binding.userAddress.getText().toString();
String id = "";
if (activeUser != null) {
UsersDataModel user = activeUser.getActive();
if (user != null) {
id = user.getDocumentId();
}
}
String rankName = binding.userRank.getSelectedItem().toString();
String rankID = ranksAndIds.get(rankName);
if (id != null) {
String errorMsg = "";
if (!firestoreDatabase.validateName(firstName)) {
errorMsg = "First name has invalid format";
} else if (!firestoreDatabase.validateName(lastName)) {
errorMsg = "Last name has invalid format";
} else if (!firestoreDatabase.validatePhone(phone)) {
errorMsg = "Phone number has invalid format";
}
if (errorMsg.equals("")) {
// TODO: await
firestoreDatabase.editUser(firstName, lastName, rankID, phone, address, id, getActivity());
user.setFirst_name(firstName);
user.setLast_name(lastName);
user.setRank_id(rankID);
user.setPhone_number(phone);
user.setAddress(address);
UserViewModel userViewModel = new ViewModelProvider(this).get(UserViewModel.class);
userViewModel.setUserDataModel(user);
NavDirections action = EditUserFragmentDirections.actionEditUserFragmentToUserFragment();
Navigation.findNavController(binding.getRoot()).navigate(action);
} else {
Toast.makeText(getActivity(), errorMsg, Toast.LENGTH_SHORT).show();
}
} else {
Log.d("User", "No active user found");
}
});
return binding.getRoot();
}
use of com.example.first_responder_app.dataModels.UsersDataModel in project FirstResponse by mattpost1700.
the class EventFragment method populateParticipantList.
private void populateParticipantList(int startIdx, int endIdx) {
Log.d(TAG, "populateParticipantList: ");
participants.clear();
db.collection("users").whereIn(FieldPath.documentId(), eventInfo.getParticipants().subList(startIdx, endIdx)).get().addOnCompleteListener(participantTask -> {
Log.d(TAG, "READ DATABASE - EVENT FRAGMENT");
if (participantTask.isSuccessful()) {
List<UsersDataModel> tempList = new ArrayList<>();
for (QueryDocumentSnapshot userDoc : participantTask.getResult()) {
UsersDataModel userData = userDoc.toObject(UsersDataModel.class);
tempList.add(userData);
}
participants.addAll(tempList);
checkParticipantsEmpty();
Log.d(TAG, "populateParticipantList: " + participants.size());
eventRecyclerViewAdapter.notifyDataSetChanged();
} else {
Log.w(TAG, "populateParticipantList: Participant data failed to query", participantTask.getException());
}
});
}
use of com.example.first_responder_app.dataModels.UsersDataModel in project FirstResponse by mattpost1700.
the class EventFragment method updateUI.
private void updateUI(boolean checkDB) {
if (isParticipating) {
binding.signUp.setText("Withdraw");
} else {
binding.signUp.setText("Sign up");
}
if (checkDB)
populateParticipantListFromDB();
binding.eventEventTitle.setText(eventInfo.getTitle());
binding.eventEventDescription.setText(eventInfo.getDescription());
binding.eventEventLocation.setText(eventInfo.getLocation());
binding.eventEventParticipantsNum.setText(eventInfo.getParticipantsSize() + "");
if (eventInfo.getUser_created_id() != null) {
db.collection("users").document(eventInfo.getUser_created_id()).get().addOnCompleteListener(task -> {
if (task.isSuccessful()) {
DocumentSnapshot doc = task.getResult();
UsersDataModel user = doc.toObject(UsersDataModel.class);
if (user != null) {
String text = "Created by: " + user.getFirst_name() + " " + user.getLast_name();
binding.eventCreatedByText.setText(text);
}
} else {
Log.d(TAG, "Error getting user: " + task.getException());
}
});
}
// Display the event start and end time
if (eventInfo.getEvent_time() != null && eventInfo.getDuration_in_minutes() > 0) {
Date start = eventInfo.getEvent_time().toDate();
Date end = new Date(start.getTime() + ((long) eventInfo.getDuration_in_minutes() * 60 * 1000));
SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yy", Locale.getDefault());
SimpleDateFormat timeFormat = new SimpleDateFormat("h:mm aa", Locale.getDefault());
String dateStart = dateFormat.format(start);
String timeStart = timeFormat.format(start);
String dateEnd = dateFormat.format(end);
String timeEnd = timeFormat.format(end);
String date = "";
if (dateEnd.equals(dateStart)) {
date = dateStart + '\n';
date += timeStart + " - " + timeEnd;
} else {
date = dateStart + " " + timeStart + " - ";
date += dateEnd + " " + timeEnd;
}
binding.eventTimeTextView.setText(date);
} else if (eventInfo.getEvent_time() != null && eventInfo.getDuration_in_minutes() <= 0) {
Date start = eventInfo.getEvent_time().toDate();
String date = new SimpleDateFormat("MM/dd/yy\nh:mm aa", Locale.getDefault()).format(start);
binding.eventTimeTextView.setText(date);
}
}
Aggregations