Search in sources :

Example 11 with UsersDataModel

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();
}
Also used : UsersDataModel(com.example.first_responder_app.dataModels.UsersDataModel)

Example 12 with UsersDataModel

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);
}
Also used : UsersDataModel(com.example.first_responder_app.dataModels.UsersDataModel) SuppressLint(android.annotation.SuppressLint)

Example 13 with UsersDataModel

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();
}
Also used : UsersDataModel(com.example.first_responder_app.dataModels.UsersDataModel) Spinner(android.widget.Spinner) NavController(androidx.navigation.NavController) View(android.view.View) AdapterView(android.widget.AdapterView) NavDirections(androidx.navigation.NavDirections) EditUserViewModel(com.example.first_responder_app.viewModels.EditUserViewModel) UserViewModel(com.example.first_responder_app.viewModels.UserViewModel) FragmentEditUserBinding(com.example.first_responder_app.databinding.FragmentEditUserBinding) AdapterView(android.widget.AdapterView) NavHostFragment(androidx.navigation.fragment.NavHostFragment) FirestoreDatabase(com.example.first_responder_app.FirestoreDatabase) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Example 14 with UsersDataModel

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());
        }
    });
}
Also used : UsersDataModel(com.example.first_responder_app.dataModels.UsersDataModel) QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot) ArrayList(java.util.ArrayList)

Example 15 with UsersDataModel

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);
    }
}
Also used : QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot) DocumentSnapshot(com.google.firebase.firestore.DocumentSnapshot) UsersDataModel(com.example.first_responder_app.dataModels.UsersDataModel) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

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