Search in sources :

Example 1 with FireDepartmentDataModel

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

the class MainActivity method setRespAddr.

public void setRespAddr() {
    FirestoreDatabase.getInstance().getDb().collection("fire_department").document(activeUser.getFire_department_id()).get().addOnCompleteListener(task -> {
        if (task.isSuccessful()) {
            FireDepartmentDataModel department = task.getResult().toObject(FireDepartmentDataModel.class);
            if (department != null)
                fireDeptAddr = department.getLocation();
            Log.d(TAG, "setDeptAddr: " + fireDeptAddr);
            if (activeUser != null && AppUtil.timeIsWithin(activeUser.getResponding_time(), this)) {
                setActiveUserRespondingAddr();
            } else {
                stopETA();
            }
        } else {
            Log.d(TAG, "Error getting department address");
        }
    });
}
Also used : FireDepartmentDataModel(com.example.first_responder_app.dataModels.FireDepartmentDataModel)

Example 2 with FireDepartmentDataModel

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

the class CreateDepartmentFragment method onCreateView.

@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    DrawerLocker drawerLocker = ((DrawerLocker) getActivity());
    if (drawerLocker != null) {
        drawerLocker.setDrawerLocked(true);
    }
    CreateDepartmentFragmentBinding binding = DataBindingUtil.inflate(inflater, R.layout.create_department_fragment, container, false);
    NavHostFragment navHostFragment = (NavHostFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.nav_host_fragment);
    binding.createDepartmentCreateButton.setOnClickListener(v -> {
        String location = binding.createDepartmentLocationEditText.getText().toString();
        String name = binding.createDepartmentNameEditText.getText().toString();
        FireDepartmentDataModel fireDepartmentDataModel = new FireDepartmentDataModel(location, name);
        if (!location.equals("") && !name.equals("")) {
            FirestoreDatabase.getInstance().getDb().collection(FirestoreDatabase.FIRE_DEPARTMENT_COLLECTION_DIR).add(fireDepartmentDataModel).addOnSuccessListener(documentReference -> {
                String fireDeptId = documentReference.getId();
                new AlertDialog.Builder(getContext()).setTitle("Remember this id!").setMessage("The only way for you or anyone else to join this department is with this id. You cannot get this id again until someone joins the department." + "\n\nID: " + fireDeptId).setIcon(android.R.drawable.ic_dialog_alert).setNegativeButton(android.R.string.ok, (dialog, which) -> {
                    NavDirections action = CreateDepartmentFragmentDirections.actionCreateDepartmentFragmentToLoginFragment();
                    Navigation.findNavController(binding.getRoot()).navigate(action);
                }).setPositiveButton("Create account for department", (dialog, which) -> {
                    CreateUserViewModel createUserViewModel = new ViewModelProvider(requireActivity()).get(CreateUserViewModel.class);
                    createUserViewModel.setFireDepartmentId(fireDeptId);
                    NavDirections action = CreateDepartmentFragmentDirections.actionCreateDepartmentFragmentToCreateUserFragment();
                    Navigation.findNavController(binding.getRoot()).navigate(action);
                }).setNeutralButton("Copy ID to clipboard", (dialog, which) -> {
                    ClipboardManager clipboard = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
                    ClipData clip = ClipData.newPlainText("Copied Text", fireDeptId);
                    clipboard.setPrimaryClip(clip);
                }).show();
            }).addOnFailureListener(e -> Toast.makeText(getContext(), "Failed to make fire department", Toast.LENGTH_SHORT).show());
        } else {
            Toast.makeText(getContext(), "Invalid entries", Toast.LENGTH_SHORT).show();
        }
    });
    return binding.getRoot();
}
Also used : Context(android.content.Context) Bundle(android.os.Bundle) AlertDialog(androidx.appcompat.app.AlertDialog) CreateUserViewModel(com.example.first_responder_app.viewModels.CreateUserViewModel) ViewModelProvider(androidx.lifecycle.ViewModelProvider) NavDirections(androidx.navigation.NavDirections) LayoutInflater(android.view.LayoutInflater) NonNull(androidx.annotation.NonNull) FirestoreDatabase(com.example.first_responder_app.FirestoreDatabase) CreateDepartmentFragmentBinding(com.example.first_responder_app.databinding.CreateDepartmentFragmentBinding) CreateDepartmentViewModel(com.example.first_responder_app.viewModels.CreateDepartmentViewModel) ViewGroup(android.view.ViewGroup) DrawerLocker(com.example.first_responder_app.interfaces.DrawerLocker) FireDepartmentDataModel(com.example.first_responder_app.dataModels.FireDepartmentDataModel) ClipData(android.content.ClipData) R(com.example.first_responder_app.R) Nullable(androidx.annotation.Nullable) Toast(android.widget.Toast) Fragment(androidx.fragment.app.Fragment) ClipboardManager(android.content.ClipboardManager) View(android.view.View) Navigation(androidx.navigation.Navigation) NavHostFragment(androidx.navigation.fragment.NavHostFragment) DataBindingUtil(androidx.databinding.DataBindingUtil) ClipboardManager(android.content.ClipboardManager) CreateDepartmentFragmentBinding(com.example.first_responder_app.databinding.CreateDepartmentFragmentBinding) FireDepartmentDataModel(com.example.first_responder_app.dataModels.FireDepartmentDataModel) DrawerLocker(com.example.first_responder_app.interfaces.DrawerLocker) CreateUserViewModel(com.example.first_responder_app.viewModels.CreateUserViewModel) NavHostFragment(androidx.navigation.fragment.NavHostFragment) ClipData(android.content.ClipData) NavDirections(androidx.navigation.NavDirections) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Aggregations

FireDepartmentDataModel (com.example.first_responder_app.dataModels.FireDepartmentDataModel)2 ClipData (android.content.ClipData)1 ClipboardManager (android.content.ClipboardManager)1 Context (android.content.Context)1 Bundle (android.os.Bundle)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 Toast (android.widget.Toast)1 NonNull (androidx.annotation.NonNull)1 Nullable (androidx.annotation.Nullable)1 AlertDialog (androidx.appcompat.app.AlertDialog)1 DataBindingUtil (androidx.databinding.DataBindingUtil)1 Fragment (androidx.fragment.app.Fragment)1 ViewModelProvider (androidx.lifecycle.ViewModelProvider)1 NavDirections (androidx.navigation.NavDirections)1 Navigation (androidx.navigation.Navigation)1 NavHostFragment (androidx.navigation.fragment.NavHostFragment)1 FirestoreDatabase (com.example.first_responder_app.FirestoreDatabase)1 R (com.example.first_responder_app.R)1