Search in sources :

Example 1 with IncidentDataModel

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

the class IncidentRecyclerViewAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(@NonNull IncidentRecyclerViewAdapter.ViewHolder holder, int position) {
    IncidentDataModel incident = incidentList.get(position);
    Date date = incident.getCreated_at().toDate();
    String dateString = new SimpleDateFormat("h:mm aa", Locale.getDefault()).format(date);
    holder.incidentAddressTextView.setText(incident.getLocation());
    holder.incidentTimeTextView.setText(dateString);
    holder.incidentTypeChip.setText(incident.getIncident_type());
}
Also used : IncidentDataModel(com.example.first_responder_app.dataModels.IncidentDataModel) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 2 with IncidentDataModel

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

the class RespondersGroupRecyclerViewAdapter method setResponseLocation.

/**
 * Set the responding location field on the card
 *
 * @param holder The ViewHolder object
 * @param user The user who is responding
 */
public void setResponseLocation(ViewHolder holder, UsersDataModel user) {
    StringBuilder responding = new StringBuilder();
    Log.d(TAG, "setResponseLocation: ");
    for (int i = 0; i < incidentList.size(); i++) {
        IncidentDataModel incident = incidentList.get(i);
        Map<String, String> status = incident.getStatus();
        List<String> responses = user.getResponses();
        if (responses != null && responses.size() > 0 && responses.get(responses.size() - 1).equals(incident.getDocumentId())) {
            if (status != null && status.containsKey(user.getDocumentId()) && status.get(user.getDocumentId()).equals("Station")) {
                holder.responderRankTextView.setText("Station");
            } else if (status != null && status.containsKey(user.getDocumentId()) && status.get(user.getDocumentId()).equals("Unavailable")) {
                holder.responderRankTextView.setText("Unavailable");
            } else {
                holder.responderRankTextView.setText(incident.getLocation());
            }
            return;
        }
    }
}
Also used : IncidentDataModel(com.example.first_responder_app.dataModels.IncidentDataModel) SuppressLint(android.annotation.SuppressLint)

Example 3 with IncidentDataModel

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

the class RespondersRecyclerViewAdapter method setEta.

public void setEta(ViewHolder holder, UsersDataModel user) {
    for (int i = 0; i < incidentList.size(); i++) {
        IncidentDataModel incident = incidentList.get(i);
        Map<String, String> etas = incident.getEta();
        List<String> responses = user.getResponses();
        if (responses != null && responses.size() > 0 && responses.get(responses.size() - 1).equals(incident.getDocumentId())) {
            if (etas != null && etas.containsKey(user.getDocumentId())) {
                String eta = "ETA: " + etas.get(user.getDocumentId());
                holder.responderEtaTextView.setText(eta);
                return;
            }
        }
    }
}
Also used : IncidentDataModel(com.example.first_responder_app.dataModels.IncidentDataModel) SuppressLint(android.annotation.SuppressLint)

Example 4 with IncidentDataModel

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

the class RespondersRecyclerViewAdapter method setResponseLocation.

/**
 * Set the responding location field on the card
 *
 * @param holder The ViewHolder object
 * @param user The user who is responding
 */
public void setResponseLocation(ViewHolder holder, UsersDataModel user) {
    StringBuilder responding = new StringBuilder();
    Log.d(TAG, "setResponseLocation: ");
    for (int i = 0; i < incidentList.size(); i++) {
        IncidentDataModel incident = incidentList.get(i);
        Map<String, String> status = incident.getStatus();
        List<String> responses = user.getResponses();
        if (responses != null && responses.size() > 0 && responses.get(responses.size() - 1).equals(incident.getDocumentId())) {
            if (status != null && status.containsKey(user.getDocumentId()) && status.get(user.getDocumentId()).equals("Station")) {
                holder.responderRankTextView.setText("Station");
            } else if (status != null && status.containsKey(user.getDocumentId()) && status.get(user.getDocumentId()).equals("Unavailable")) {
                holder.responderRankTextView.setText("Unavailable");
            } else {
                holder.responderRankTextView.setText(incident.getLocation());
            }
            return;
        }
    }
}
Also used : IncidentDataModel(com.example.first_responder_app.dataModels.IncidentDataModel) SuppressLint(android.annotation.SuppressLint)

Example 5 with IncidentDataModel

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

the class HomeFragment method onCreateView.

@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    DrawerLocker drawerLocker = ((DrawerLocker) getActivity());
    if (drawerLocker != null) {
        drawerLocker.setDrawerLocked(false);
    }
    FragmentHomeBinding binding = DataBindingUtil.inflate(inflater, R.layout.fragment_home, container, false);
    NavHostFragment navHostFragment = (NavHostFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.nav_host_fragment);
    bindingView = binding.getRoot();
    // TODO: navCont created for side bar(still need to be implemented)
    NavController navController = navHostFragment.getNavController();
    // switch to Home fragment upon clicking it
    // also if you have any other code relates to onCreateView just add it from here
    activeUser = AppUtil.getActiveUser(getActivity());
    if (activeUser == null) {
        getActivity().getFragmentManager().popBackStack();
        Toast.makeText(getContext(), "User is not logged in!", Toast.LENGTH_SHORT).show();
    }
    // Setup click listeners for the view all incidents and view all responders buttons
    binding.viewAllIncidents.setOnClickListener(view -> {
        NavDirections action = HomeFragmentDirections.actionHomeFragmentToIncidentGroupFragment();
        Navigation.findNavController(binding.getRoot()).navigate(action);
    });
    binding.viewAllResponders.setOnClickListener(view -> {
        NavDirections action = HomeFragmentDirections.actionHomeFragmentToRespondingFragment();
        Navigation.findNavController(binding.getRoot()).navigate(action);
    });
    binding.sortIncidentsButton.setOnClickListener(view -> {
        PopupMenu popupMenu = new PopupMenu(getContext(), view);
        popupMenu.setOnMenuItemClickListener(this);
        popupMenu.inflate(R.menu.incident_popup_menu);
        popupMenu.show();
    });
    binding.sortRespondersButton.setOnClickListener(view -> {
        PopupMenu popupMenu = new PopupMenu(getContext(), view);
        popupMenu.setOnMenuItemClickListener(this);
        popupMenu.inflate(R.menu.user_popup_menu);
        popupMenu.show();
    });
    final SwipeRefreshLayout pullToRefresh = bindingView.findViewById(R.id.homeSwipeRefreshLayout);
    pullToRefresh.setOnRefreshListener(() -> {
        // your code
        refreshData();
        pullToRefresh.setRefreshing(false);
    });
    listOfIncidentDataModel = new ArrayList<>();
    respondersList = new ArrayList<>();
    listOfRanks = new ArrayList<>();
    // automatically subscribes everyone who logs in to get notifications for these topics
    FirebaseMessaging.getInstance().subscribeToTopic("events").addOnCompleteListener(new OnCompleteListener<>() {

        @Override
        public void onComplete(@NonNull Task<Void> task) {
        }
    });
    FirebaseMessaging.getInstance().subscribeToTopic("announcements").addOnCompleteListener(new OnCompleteListener<Void>() {

        @Override
        public void onComplete(@NonNull Task<Void> task) {
        }
    });
    FirebaseMessaging.getInstance().subscribeToTopic("incidents").addOnCompleteListener(new OnCompleteListener<Void>() {

        @Override
        public void onComplete(@NonNull Task<Void> task) {
        }
    });
    saveRanksCollection();
    RespondersRecyclerViewAdapter.ResponderClickListener responderClickListener = (view, position) -> {
        UserViewModel userViewModel = new ViewModelProvider(requireActivity()).get(UserViewModel.class);
        userViewModel.setUserDataModel(respondersList.get(position));
        NavDirections action = HomeFragmentDirections.actionHomeFragmentToUserFragment();
        Navigation.findNavController(binding.getRoot()).navigate(action);
    };
    IncidentRecyclerViewAdapter.IncidentClickListener incidentClickListener = (view, position) -> {
        IncidentDataModel incident = listOfIncidentDataModel.get(position);
        IncidentViewModel incidentViewModel = new ViewModelProvider(requireActivity()).get(IncidentViewModel.class);
        incidentViewModel.setIncidentDataModel(incident);
        NavDirections action = HomeFragmentDirections.actionHomeFragmentToIncidentFragment();
        Navigation.findNavController(binding.getRoot()).navigate(action);
    };
    // RecyclerViews
    RecyclerView incidentRecyclerView = bindingView.findViewById(R.id.incidents_recycler_view);
    incidentRecyclerView.setLayoutManager(new LinearLayoutManager(bindingView.getContext()));
    incidentRecyclerViewAdapter = new IncidentRecyclerViewAdapter(bindingView.getContext(), listOfIncidentDataModel);
    incidentRecyclerViewAdapter.setIncidentClickListener(incidentClickListener);
    incidentRecyclerView.setAdapter(incidentRecyclerViewAdapter);
    RecyclerView respondersRecyclerView = bindingView.findViewById(R.id.responders_recycler_view);
    respondersRecyclerView.setLayoutManager(new LinearLayoutManager(bindingView.getContext()));
    respondersRecyclerViewAdapter = new RespondersRecyclerViewAdapter(bindingView.getContext(), respondersList, listOfIncidentDataModel);
    respondersRecyclerViewAdapter.setResponderClickListener(responderClickListener);
    respondersRecyclerView.setAdapter(respondersRecyclerViewAdapter);
    // Start event listeners (live data)
    addIncidentEventListener();
    addResponderEventListener();
    return bindingView;
}
Also used : Bundle(android.os.Bundle) NonNull(androidx.annotation.NonNull) IncidentRecyclerViewAdapter(com.example.first_responder_app.recyclerViews.IncidentRecyclerViewAdapter) DrawerLocker(com.example.first_responder_app.interfaces.DrawerLocker) Task(com.google.android.gms.tasks.Task) MenuItem(android.view.MenuItem) NavController(androidx.navigation.NavController) ArrayList(java.util.ArrayList) QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot) IncidentDataModel(com.example.first_responder_app.dataModels.IncidentDataModel) PopupMenu(android.widget.PopupMenu) Toast(android.widget.Toast) Fragment(androidx.fragment.app.Fragment) HomeViewModel(com.example.first_responder_app.viewModels.HomeViewModel) View(android.view.View) ListenerRegistration(com.google.firebase.firestore.ListenerRegistration) RecyclerView(androidx.recyclerview.widget.RecyclerView) TAG(android.content.ContentValues.TAG) Log(android.util.Log) NavHostFragment(androidx.navigation.fragment.NavHostFragment) DataBindingUtil(androidx.databinding.DataBindingUtil) UsersDataModel(com.example.first_responder_app.dataModels.UsersDataModel) FragmentManager(androidx.fragment.app.FragmentManager) ViewModelProvider(androidx.lifecycle.ViewModelProvider) NavDirections(androidx.navigation.NavDirections) LayoutInflater(android.view.LayoutInflater) SwipeRefreshLayout(androidx.swiperefreshlayout.widget.SwipeRefreshLayout) AppUtil(com.example.first_responder_app.AppUtil) FragmentHomeBinding(com.example.first_responder_app.databinding.FragmentHomeBinding) FirebaseMessaging(com.google.firebase.messaging.FirebaseMessaging) FirestoreDatabase(com.example.first_responder_app.FirestoreDatabase) IncidentViewModel(com.example.first_responder_app.viewModels.IncidentViewModel) OnCompleteListener(com.google.android.gms.tasks.OnCompleteListener) FragmentTransaction(androidx.fragment.app.FragmentTransaction) ViewGroup(android.view.ViewGroup) UserViewModel(com.example.first_responder_app.viewModels.UserViewModel) R(com.example.first_responder_app.R) FirebaseFirestore(com.google.firebase.firestore.FirebaseFirestore) List(java.util.List) Nullable(androidx.annotation.Nullable) Navigation(androidx.navigation.Navigation) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) RespondersRecyclerViewAdapter(com.example.first_responder_app.recyclerViews.RespondersRecyclerViewAdapter) RanksDataModel(com.example.first_responder_app.dataModels.RanksDataModel) IncidentViewModel(com.example.first_responder_app.viewModels.IncidentViewModel) RespondersRecyclerViewAdapter(com.example.first_responder_app.recyclerViews.RespondersRecyclerViewAdapter) IncidentDataModel(com.example.first_responder_app.dataModels.IncidentDataModel) NavController(androidx.navigation.NavController) DrawerLocker(com.example.first_responder_app.interfaces.DrawerLocker) FragmentHomeBinding(com.example.first_responder_app.databinding.FragmentHomeBinding) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) SwipeRefreshLayout(androidx.swiperefreshlayout.widget.SwipeRefreshLayout) NavDirections(androidx.navigation.NavDirections) UserViewModel(com.example.first_responder_app.viewModels.UserViewModel) RecyclerView(androidx.recyclerview.widget.RecyclerView) IncidentRecyclerViewAdapter(com.example.first_responder_app.recyclerViews.IncidentRecyclerViewAdapter) NavHostFragment(androidx.navigation.fragment.NavHostFragment) PopupMenu(android.widget.PopupMenu) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Aggregations

IncidentDataModel (com.example.first_responder_app.dataModels.IncidentDataModel)11 SuppressLint (android.annotation.SuppressLint)6 QueryDocumentSnapshot (com.google.firebase.firestore.QueryDocumentSnapshot)5 ArrayList (java.util.ArrayList)5 TAG (android.content.ContentValues.TAG)3 Bundle (android.os.Bundle)3 Log (android.util.Log)3 LayoutInflater (android.view.LayoutInflater)3 View (android.view.View)3 ViewGroup (android.view.ViewGroup)3 Toast (android.widget.Toast)3 NonNull (androidx.annotation.NonNull)3 Nullable (androidx.annotation.Nullable)3 DataBindingUtil (androidx.databinding.DataBindingUtil)3 ViewModelProvider (androidx.lifecycle.ViewModelProvider)3 NavDirections (androidx.navigation.NavDirections)3 Navigation (androidx.navigation.Navigation)3 AppUtil (com.example.first_responder_app.AppUtil)3 FirestoreDatabase (com.example.first_responder_app.FirestoreDatabase)3 R (com.example.first_responder_app.R)3