Search in sources :

Example 1 with UsersDataModel

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

the class RespondersRecyclerViewAdapterTest method getItemShouldReturnSameItemInListAtDifferentIndex_returnsTrue.

@Test
void getItemShouldReturnSameItemInListAtDifferentIndex_returnsTrue() {
    listOfResponders.add(user1);
    listOfResponders.add(user1);
    UsersDataModel adapterUser = adapter.getItem(1);
    UsersDataModel listUser = listOfResponders.get(2);
    Truth.assertThat(adapterUser == listUser).isTrue();
}
Also used : UsersDataModel(com.example.first_responder_app.dataModels.UsersDataModel) Test(org.junit.jupiter.api.Test)

Example 2 with UsersDataModel

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

the class RespondersRecyclerViewAdapterTest method getItemShouldReturnSameItemInList_returnsTrue.

@Test
void getItemShouldReturnSameItemInList_returnsTrue() {
    listOfResponders.add(user1);
    listOfResponders.add(user2);
    UsersDataModel adapterUser = adapter.getItem(2);
    UsersDataModel listUser = listOfResponders.get(2);
    Truth.assertThat(adapterUser == listUser).isTrue();
}
Also used : UsersDataModel(com.example.first_responder_app.dataModels.UsersDataModel) Test(org.junit.jupiter.api.Test)

Example 3 with UsersDataModel

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

the class FirestoreDatabase method editUser.

/**
 * Update a user's data
 *
 * @param firstName The user's first name
 * @param lastName The user's last name
 * @param phone The user's prone number (as a String)
 * @param rank The user's rank (document ID, not rank name)
 * @param address The user's address
 * @param id The document id of the user being updated
 * @param context The context
 */
public void editUser(String firstName, String lastName, String rank, String phone, String address, String id, Context context) {
    String phoneNum = parsePhone(phone);
    db.collection("users").document(id).update("first_name", firstName, "last_name", lastName, "address", address, "phone_number", phoneNum, FIELD_RANK_ID, rank).addOnSuccessListener(new OnSuccessListener<Void>() {

        @Override
        public void onSuccess(Void aVoid) {
            Log.d("DB", "User successfully updated");
            ActiveUser activeUser = (ActiveUser) context;
            if (activeUser != null) {
                UsersDataModel user = activeUser.getActive();
                if (user != null && (user.getDocumentId().equals(id))) {
                    user.setRank_id(rank);
                    user.setFirst_name(firstName);
                    user.setLast_name(lastName);
                    user.setPhone_number(phoneNum);
                    activeUser.setActive(user);
                }
            }
        }
    }).addOnFailureListener(new OnFailureListener() {

        @Override
        public void onFailure(@NonNull Exception e) {
            Log.w("DB", "Error updating user " + id, e);
        }
    });
}
Also used : UsersDataModel(com.example.first_responder_app.dataModels.UsersDataModel) ActiveUser(com.example.first_responder_app.interfaces.ActiveUser) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) OnFailureListener(com.google.android.gms.tasks.OnFailureListener)

Example 4 with UsersDataModel

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

the class EventFragment method onCreateView.

@SuppressLint("SetTextI18n")
@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
    binding = DataBindingUtil.inflate(inflater, R.layout.fragment_event, container, false);
    NavHostFragment navHostFragment = (NavHostFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.nav_host_fragment);
    NavController navController = navHostFragment.getNavController();
    // initialize vars as well as fetching userID
    participants = new ArrayList<>();
    ActiveUser activeUser = (ActiveUser) getActivity();
    UsersDataModel user = activeUser.getActive();
    userID = user.getDocumentId();
    // getting data from event group
    mViewModel = new ViewModelProvider(requireActivity()).get(EventViewModel.class);
    eventInfo = mViewModel.getEventDetail();
    isParticipating = eventInfo.getParticipants().contains(user.getDocumentId());
    EventRecyclerViewAdapter.ItemClickListener listener = (view, pos) -> {
        UsersDataModel u = participants.get(pos);
        UserViewModel userViewModel = new ViewModelProvider(requireActivity()).get(UserViewModel.class);
        userViewModel.setUserDataModel(u);
        NavDirections action = EventFragmentDirections.actionEventFragmentToUserFragment();
        Navigation.findNavController(binding.getRoot()).navigate(action);
    };
    // recycler binding
    RecyclerView eventRecyclerView = binding.eventEventRecycler;
    eventRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    eventRecyclerViewAdapter = new EventRecyclerViewAdapter(getContext(), participants, isAnyParticipants);
    eventRecyclerViewAdapter.setClickListener(listener);
    eventRecyclerView.setAdapter(eventRecyclerViewAdapter);
    updateUI(false);
    final SwipeRefreshLayout pullToRefresh = binding.eventRefreshLayout;
    pullToRefresh.setOnRefreshListener(() -> {
        participants.clear();
        updateUI(true);
        pullToRefresh.setRefreshing(false);
    });
    addParticipatingEventListener();
    binding.signUp.setOnClickListener(v -> {
        if (binding.signUp.getText().equals("Withdraw")) {
            eventInfo.getParticipants().remove(userID);
            db.collection(FirestoreDatabase.EVENTS_COLLECTION_DIR).document(eventInfo.getDocumentId()).set(eventInfo).addOnSuccessListener(documentReference -> {
                isParticipating = false;
                binding.signUp.setText("Sign Up");
            }).addOnFailureListener(e -> Log.w(TAG, "onCreateView: Could not update event UI", e));
        } else {
            eventInfo.getParticipants().add(userID);
            db.collection(FirestoreDatabase.EVENTS_COLLECTION_DIR).document(eventInfo.getDocumentId()).set(eventInfo).addOnSuccessListener(documentReference -> {
                isParticipating = true;
                binding.signUp.setText("Withdraw");
            }).addOnFailureListener(e -> Log.w(TAG, "onCreateView: Could not update event UI", e));
            // sends the event that includes the following:
            // title, location, description, duration
            Intent intent = new Intent(Intent.ACTION_INSERT);
            intent.setData(CalendarContract.Events.CONTENT_URI);
            intent.putExtra(CalendarContract.Events.TITLE, eventInfo.getTitle());
            intent.putExtra(CalendarContract.Events.EVENT_LOCATION, eventInfo.getLocation());
            intent.putExtra(CalendarContract.Events.DESCRIPTION, eventInfo.getDescription());
            intent.putExtra(CalendarContract.Events.DURATION, eventInfo.getDuration_in_minutes());
            if (intent.resolveActivity(requireContext().getPackageManager()) != null) {
                startActivity(intent);
            } else {
                Log.d("EVENT INTENT: ", "Event setup Failed");
            }
        // // Calendar intent
        // Calendar cal = Calendar.getInstance();
        // Intent intent = new Intent(Intent.ACTION_EDIT);
        // long startTime = eventInfo.getEvent_time().toDate().toInstant().toEpochMilli();
        // intent.putExtra("beginTime", startTime);
        // //intent.putExtra("allDay", true);
        // intent.putExtra("endTime", startTime + AppUtil.numOfMinutesToMilliSeconds(eventInfo.getDuration_in_minutes()));
        // intent.putExtra("title", "A Test Event from android app");
        // startActivity(intent);
        }
    });
    return binding.getRoot();
}
Also used : Bundle(android.os.Bundle) PackageManager(android.content.pm.PackageManager) NonNull(androidx.annotation.NonNull) Date(java.util.Date) Uri(android.net.Uri) CalendarContract(android.provider.CalendarContract) NavController(androidx.navigation.NavController) EventsDataModel(com.example.first_responder_app.dataModels.EventsDataModel) ActiveUser(com.example.first_responder_app.interfaces.ActiveUser) Manifest(android.Manifest) FieldPath(com.google.firebase.firestore.FieldPath) ContentResolver(android.content.ContentResolver) Locale(java.util.Locale) Fragment(androidx.fragment.app.Fragment) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) Log(android.util.Log) NavHostFragment(androidx.navigation.fragment.NavHostFragment) DataBindingUtil(androidx.databinding.DataBindingUtil) Timestamp(com.google.firebase.Timestamp) NavDirections(androidx.navigation.NavDirections) AppUtil(com.example.first_responder_app.AppUtil) IncidentViewModel(com.example.first_responder_app.viewModels.IncidentViewModel) ViewGroup(android.view.ViewGroup) R(com.example.first_responder_app.R) Objects(java.util.Objects) List(java.util.List) Nullable(androidx.annotation.Nullable) ContentValues(android.content.ContentValues) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) EventViewModel(com.example.first_responder_app.viewModels.EventViewModel) SimpleDateFormat(java.text.SimpleDateFormat) Intent(android.content.Intent) FragmentEventBinding(com.example.first_responder_app.databinding.FragmentEventBinding) ArrayList(java.util.ArrayList) SuppressLint(android.annotation.SuppressLint) Calendar(java.util.Calendar) QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot) Toast(android.widget.Toast) ListenerRegistration(com.google.firebase.firestore.ListenerRegistration) TAG(android.content.ContentValues.TAG) EventRecyclerViewAdapter(com.example.first_responder_app.recyclerViews.EventRecyclerViewAdapter) DocumentSnapshot(com.google.firebase.firestore.DocumentSnapshot) UsersDataModel(com.example.first_responder_app.dataModels.UsersDataModel) ViewModelProvider(androidx.lifecycle.ViewModelProvider) LayoutInflater(android.view.LayoutInflater) ActivityCompat(androidx.core.app.ActivityCompat) SwipeRefreshLayout(androidx.swiperefreshlayout.widget.SwipeRefreshLayout) User(com.google.firebase.firestore.auth.User) FirestoreDatabase(com.example.first_responder_app.FirestoreDatabase) UserViewModel(com.example.first_responder_app.viewModels.UserViewModel) FirebaseFirestore(com.google.firebase.firestore.FirebaseFirestore) Navigation(androidx.navigation.Navigation) UsersDataModel(com.example.first_responder_app.dataModels.UsersDataModel) NavController(androidx.navigation.NavController) Intent(android.content.Intent) EventRecyclerViewAdapter(com.example.first_responder_app.recyclerViews.EventRecyclerViewAdapter) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) SwipeRefreshLayout(androidx.swiperefreshlayout.widget.SwipeRefreshLayout) NavDirections(androidx.navigation.NavDirections) EventViewModel(com.example.first_responder_app.viewModels.EventViewModel) UserViewModel(com.example.first_responder_app.viewModels.UserViewModel) ActiveUser(com.example.first_responder_app.interfaces.ActiveUser) RecyclerView(androidx.recyclerview.widget.RecyclerView) NavHostFragment(androidx.navigation.fragment.NavHostFragment) ViewModelProvider(androidx.lifecycle.ViewModelProvider) SuppressLint(android.annotation.SuppressLint)

Example 5 with UsersDataModel

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

the class IncidentFragment method respondingButtonClicked.

/**
 * When responding button is clicked update active users responding status
 *
 * @param b the button that was clicked
 */
public void respondingButtonClicked(View b) {
    Log.d(TAG, "respondingButtonClicked: " + ((Button) b).getText());
    String text = ((Button) b).getText().toString();
    String id = incidentDataModel.getDocumentId();
    // Get active user id
    ActiveUser active = (ActiveUser) getActivity();
    UsersDataModel activeUser = null;
    if (active != null) {
        activeUser = active.getActive();
    }
    if (activeUser == null && context != null) {
        Toast.makeText(context, "You must be logged in", Toast.LENGTH_LONG).show();
    } else if (activeUser != null) {
        List<String> responses = activeUser.getResponses();
        if (!AppUtil.timeIsWithin(activeUser.getResponding_time(), requireContext())) {
            responses = new ArrayList<>();
        }
        // TODO: remove hardcoded string
        if (text.equals("Unavailable")) {
            FirestoreDatabase.getInstance().responding(activeUser.getDocumentId(), incidentDataModel, text, false, responses, null);
            setActiveButton(text);
        } else {
            FirestoreDatabase.getInstance().responding(activeUser.getDocumentId(), incidentDataModel, text, true, responses, () -> {
                RefreshETAs refreshETAs = (RefreshETAs) getActivity();
                refreshETAs.refresh();
            });
            setActiveButton(text);
        }
    }
}
Also used : UsersDataModel(com.example.first_responder_app.dataModels.UsersDataModel) Button(android.widget.Button) ActiveUser(com.example.first_responder_app.interfaces.ActiveUser) ArrayList(java.util.ArrayList) ColorStateList(android.content.res.ColorStateList) List(java.util.List) ArrayList(java.util.ArrayList) RefreshETAs(com.example.first_responder_app.interfaces.RefreshETAs)

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