Search in sources :

Example 6 with IncidentDataModel

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

the class HomeFragment method populateIncidents.

/**
 * Displays the active incidents
 */
private void populateIncidents() {
    db.collection("incident").whereArrayContains(FirestoreDatabase.FIELD_FIRE_DEPARTMENTS, activeUser.getFire_department_id()).whereEqualTo("incident_complete", false).get().addOnCompleteListener(incidentTask -> {
        Log.d(TAG, "READ DATABASE - HOME FRAGMENT (populateIncidents)");
        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);
            incidentRecyclerViewAdapter.notifyDataSetChanged();
        } else {
            Log.d(TAG, "get failed in HomeFragment with " + incidentTask.getException());
        }
    });
}
Also used : IncidentDataModel(com.example.first_responder_app.dataModels.IncidentDataModel) QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot) ArrayList(java.util.ArrayList)

Example 7 with IncidentDataModel

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

the class IncidentFragment method initializeIncident.

/**
 * Setup the incident data and display it
 *
 * @param incident The incident to be displayed
 */
public void initializeIncident(IncidentDataModel incident) {
    setTextViews(incident);
    Map<String, String> status = incident.getStatus();
    // Get active user id
    ActiveUser activeUser = (ActiveUser) getActivity();
    if (activeUser != null) {
        UsersDataModel user = activeUser.getActive();
        if (user != null)
            active_id = user.getDocumentId();
    }
    // Highlight active button
    if (status != null && status.containsKey(active_id)) {
        setActiveButton(status.get(active_id));
    }
    setRespondingButtonClickListener();
    // Get the Address object of the incident
    incidentAddress = addrToCoords(incident.getLocation());
    setupLocationListener();
    AtomicInteger prevLength = new AtomicInteger();
    if (listenerRegistration == null) {
        // Ensure that the incident data is updated if database is updated
        docRef = FirestoreDatabase.getInstance().getDb().collection("incident").document(incident.getDocumentId());
        listenerRegistration = docRef.addSnapshotListener((snapshot, e) -> {
            Log.d(TAG, "READ DATABASE - INCIDENT FRAGMENT");
            if (e != null) {
                System.err.println("Listen failed: " + e);
                return;
            }
            if (snapshot != null && snapshot.exists()) {
                incidentDataModel = snapshot.toObject(IncidentDataModel.class);
                if (incidentDataModel != null) {
                    setTextViews(incidentDataModel);
                    Map<String, String> statuses = incidentDataModel.getStatus();
                    if (statuses != null) {
                        String status1 = statuses.get(active_id);
                        setActiveButton(status1);
                    }
                    // Get the Address object of the incident
                    incidentAddress = addrToCoords(incidentDataModel.getLocation());
                    int currentLength = incidentDataModel.getResponding().size();
                    if (prevLength.get() != currentLength) {
                        prevLength.set(currentLength);
                        responderList.clear();
                        populateRespondersListFromDB();
                    }
                }
            } else {
                System.out.print("Current data: null");
            }
        });
    }
}
Also used : Address(android.location.Address) CameraUpdateFactory(com.google.android.gms.maps.CameraUpdateFactory) Chip(com.google.android.material.chip.Chip) LinearLayout(android.widget.LinearLayout) Bundle(android.os.Bundle) PackageManager(android.content.pm.PackageManager) NonNull(androidx.annotation.NonNull) LocationListener(android.location.LocationListener) ColorStateList(android.content.res.ColorStateList) ActiveUser(com.example.first_responder_app.interfaces.ActiveUser) Manifest(android.Manifest) FieldPath(com.google.firebase.firestore.FieldPath) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FragmentIncidentBinding(com.example.first_responder_app.databinding.FragmentIncidentBinding) Locale(java.util.Locale) ETA(com.example.first_responder_app.DirectionAPI.ETA) Map(java.util.Map) View(android.view.View) Button(android.widget.Button) ContextCompat(androidx.core.content.ContextCompat) NavHostFragment(androidx.navigation.fragment.NavHostFragment) Log(android.util.Log) DataBindingUtil(androidx.databinding.DataBindingUtil) MapView(com.google.android.gms.maps.MapView) LatLng(com.google.android.gms.maps.model.LatLng) NavDirections(androidx.navigation.NavDirections) AppUtil(com.example.first_responder_app.AppUtil) MaterialColors(com.google.android.material.color.MaterialColors) IncidentViewModel(com.example.first_responder_app.viewModels.IncidentViewModel) Geocoder(android.location.Geocoder) ViewGroup(android.view.ViewGroup) AlertDialog(android.app.AlertDialog) R(com.example.first_responder_app.R) List(java.util.List) Nullable(androidx.annotation.Nullable) TextView(android.widget.TextView) Location(android.location.Location) Marker(com.google.android.gms.maps.model.Marker) LocationManager(android.location.LocationManager) DialogFragment(androidx.fragment.app.DialogFragment) Context(android.content.Context) ChipGroup(com.google.android.material.chip.ChipGroup) Dialog(android.app.Dialog) ArrayList(java.util.ArrayList) SuppressLint(android.annotation.SuppressLint) DocumentReference(com.google.firebase.firestore.DocumentReference) QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot) IncidentDataModel(com.example.first_responder_app.dataModels.IncidentDataModel) Toast(android.widget.Toast) ListenerRegistration(com.google.firebase.firestore.ListenerRegistration) ReportViewModel(com.example.first_responder_app.viewModels.ReportViewModel) TAG(android.content.ContentValues.TAG) DialogInterface(android.content.DialogInterface) UsersDataModel(com.example.first_responder_app.dataModels.UsersDataModel) ViewModelProvider(androidx.lifecycle.ViewModelProvider) ActivityCompat(androidx.core.app.ActivityCompat) LayoutInflater(android.view.LayoutInflater) MarkerOptions(com.google.android.gms.maps.model.MarkerOptions) FirestoreDatabase(com.example.first_responder_app.FirestoreDatabase) IOException(java.io.IOException) UserViewModel(com.example.first_responder_app.viewModels.UserViewModel) OnMapReadyCallback(com.google.android.gms.maps.OnMapReadyCallback) RefreshETAs(com.example.first_responder_app.interfaces.RefreshETAs) Navigation(androidx.navigation.Navigation) GoogleMap(com.google.android.gms.maps.GoogleMap) UsersDataModel(com.example.first_responder_app.dataModels.UsersDataModel) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ActiveUser(com.example.first_responder_app.interfaces.ActiveUser) Map(java.util.Map) GoogleMap(com.google.android.gms.maps.GoogleMap)

Example 8 with IncidentDataModel

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

Example 9 with IncidentDataModel

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

the class IncidentGroupFragment method onCreateView.

@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    binding = DataBindingUtil.inflate(inflater, R.layout.fragment_incident_group, container, false);
    listOfIncidentDataModel = new ArrayList<>();
    activeUser = AppUtil.getActiveUser(getActivity());
    if (activeUser == null) {
        getActivity().getFragmentManager().popBackStack();
        Toast.makeText(getContext(), "User is not logged in!", Toast.LENGTH_SHORT).show();
    }
    final SwipeRefreshLayout pullToRefresh = binding.incidentGroupSwipeRefreshLayout;
    pullToRefresh.setOnRefreshListener(() -> {
        refreshData();
        pullToRefresh.setRefreshing(false);
    });
    IncidentGroupRecyclerViewAdapter.IncidentClickListener incidentClickListener = (view, position) -> {
        IncidentDataModel incident = listOfIncidentDataModel.get(position);
        IncidentViewModel incidentViewModel = new ViewModelProvider(requireActivity()).get(IncidentViewModel.class);
        incidentViewModel.setIncidentDataModel(incident);
        NavDirections action = IncidentGroupFragmentDirections.actionIncidentGroupFragmentToIncidentFragment();
        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();
    });
    // Recycler view
    RecyclerView incidentRecyclerView = binding.incidentsGroupRecyclerView;
    incidentRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    incidentGroupRecyclerViewAdapter = new IncidentGroupRecyclerViewAdapter(getContext(), listOfIncidentDataModel);
    incidentGroupRecyclerViewAdapter.setIncidentClickListener(incidentClickListener);
    incidentRecyclerView.setAdapter(incidentGroupRecyclerViewAdapter);
    addIncidentEventListener();
    // inflater.inflate(R.layout.fragment_incident_group, container, false);
    return binding.getRoot();
}
Also used : Bundle(android.os.Bundle) NonNull(androidx.annotation.NonNull) Query(com.google.firebase.firestore.Query) IncidentGroupViewModel(com.example.first_responder_app.viewModels.IncidentGroupViewModel) MenuItem(android.view.MenuItem) 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) View(android.view.View) ListenerRegistration(com.google.firebase.firestore.ListenerRegistration) RecyclerView(androidx.recyclerview.widget.RecyclerView) TAG(android.content.ContentValues.TAG) Log(android.util.Log) DataBindingUtil(androidx.databinding.DataBindingUtil) UsersDataModel(com.example.first_responder_app.dataModels.UsersDataModel) ViewModelProvider(androidx.lifecycle.ViewModelProvider) NavDirections(androidx.navigation.NavDirections) LayoutInflater(android.view.LayoutInflater) SwipeRefreshLayout(androidx.swiperefreshlayout.widget.SwipeRefreshLayout) AppUtil(com.example.first_responder_app.AppUtil) FirestoreDatabase(com.example.first_responder_app.FirestoreDatabase) IncidentViewModel(com.example.first_responder_app.viewModels.IncidentViewModel) ViewGroup(android.view.ViewGroup) R(com.example.first_responder_app.R) FirebaseFirestore(com.google.firebase.firestore.FirebaseFirestore) List(java.util.List) Nullable(androidx.annotation.Nullable) FragmentIncidentGroupBinding(com.example.first_responder_app.databinding.FragmentIncidentGroupBinding) Navigation(androidx.navigation.Navigation) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) IncidentGroupRecyclerViewAdapter(com.example.first_responder_app.recyclerViews.IncidentGroupRecyclerViewAdapter) IncidentViewModel(com.example.first_responder_app.viewModels.IncidentViewModel) IncidentDataModel(com.example.first_responder_app.dataModels.IncidentDataModel) RecyclerView(androidx.recyclerview.widget.RecyclerView) IncidentGroupRecyclerViewAdapter(com.example.first_responder_app.recyclerViews.IncidentGroupRecyclerViewAdapter) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) SwipeRefreshLayout(androidx.swiperefreshlayout.widget.SwipeRefreshLayout) ViewModelProvider(androidx.lifecycle.ViewModelProvider) NavDirections(androidx.navigation.NavDirections) PopupMenu(android.widget.PopupMenu)

Example 10 with IncidentDataModel

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

the class IncidentGroupRecyclerViewAdapter method onBindViewHolder.

@SuppressLint("SetTextI18n")
@Override
public void onBindViewHolder(@NonNull IncidentGroupRecyclerViewAdapter.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) SuppressLint(android.annotation.SuppressLint)

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