use of com.example.first_responder_app.interfaces.DrawerLocker 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;
}
use of com.example.first_responder_app.interfaces.DrawerLocker in project FirstResponse by mattpost1700.
the class LoginFragment method onCreateView.
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
// lock drawer on login page
DrawerLocker drawerLocker = ((DrawerLocker) getActivity());
if (drawerLocker != null) {
drawerLocker.setDrawerLocked(true);
}
Context context = getActivity();
// 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_login, container, false);
NavHostFragment navHostFragment = (NavHostFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.nav_host_fragment);
assert navHostFragment != null;
NavController navController = navHostFragment.getNavController();
sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE);
// check whether user finished typing and query the data
binding.loginUsername.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
last_text_edit = System.currentTimeMillis();
handler.removeCallbacks(input_finish_checker);
}
@Override
public void afterTextChanged(Editable editable) {
mViewModel.setUsername(binding.loginUsername.getText().toString());
if (binding.loginPassword.getText().length() > 0) {
last_text_edit = System.currentTimeMillis();
handler.postDelayed(input_finish_checker, 500);
}
}
});
binding.loginPassword.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
last_text_edit = System.currentTimeMillis();
handler.removeCallbacks(input_finish_checker);
}
@Override
public void afterTextChanged(Editable editable) {
mViewModel.setPassword(binding.loginPassword.getText().toString());
if (binding.loginPassword.getText().length() > 0) {
last_text_edit = System.currentTimeMillis();
handler.postDelayed(input_finish_checker, 500);
}
}
});
binding.loginCreateAccountFab.setOnClickListener(v -> {
NavDirections action = LoginFragmentDirections.actionLoginFragmentToCreateUserFragment();
Navigation.findNavController(binding.getRoot()).navigate(action);
});
binding.loginCreateDepartmentFab.setOnClickListener(v -> {
NavDirections action = LoginFragmentDirections.actionLoginFragmentToCreateDepartmentFragment();
Navigation.findNavController(binding.getRoot()).navigate(action);
});
binding.loginSubmit.setOnClickListener(v -> {
if (mViewModel.getUsername() == null || mViewModel.getPassword() == null) {
binding.loginLog.setText(R.string.loginFailMsg);
binding.loginLog.setVisibility(View.VISIBLE);
Log.d("testing", "login failed: wrong username/password");
} else {
if (checkUsernameExists(mViewModel.getUsername())) {
if (checkPwMatch(mViewModel.getUsername(), mViewModel.getPassword())) {
// wraps the shared preferences and auto encrypts keys and values using a two-schemed method
try {
SharedPreferences.Editor editor = sharedPref.edit();
editor.putString("savedUsername", mViewModel.getUsername());
editor.putString("savedPassword", mViewModel.getPassword());
editor.apply();
String masterKeyAlias = MasterKeys.getOrCreate(MasterKeys.AES256_GCM_SPEC);
sharedPref = EncryptedSharedPreferences.create("secret_shared_prefs", masterKeyAlias, context, EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV, EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM);
} catch (Exception e) {
Log.d("Login Encryption: ", "Encryption failed");
}
ActiveUser activeUser = ((ActiveUser) getActivity());
activeUser.setActive(user);
successfullyHidAdminOptions();
NavDirections action = LoginFragmentDirections.actionLoginFragmentToHomeFragment();
Navigation.findNavController(binding.getRoot()).navigate(action);
Log.d("testing", "username: " + mViewModel.getUsername() + " pw: " + mViewModel.getPassword() + " Login success.");
} else {
binding.loginLog.setText(R.string.loginFailMsg);
binding.loginLog.setVisibility(View.VISIBLE);
Log.d("testing", "login failed: wrong username/password");
}
} else {
binding.loginLog.setText(R.string.loginFailMsg);
binding.loginLog.setVisibility(View.VISIBLE);
Log.d("testing", "login failed: wrong username/password");
}
}
});
binding.bypassBtn.setOnClickListener(v -> {
successfullyHidAdminOptions();
NavDirections action = LoginFragmentDirections.actionLoginFragmentToHomeFragment();
Navigation.findNavController(binding.getRoot()).navigate(action);
});
return binding.getRoot();
}
use of com.example.first_responder_app.interfaces.DrawerLocker 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();
}
use of com.example.first_responder_app.interfaces.DrawerLocker in project FirstResponse by mattpost1700.
the class CreateUserFragment 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);
}
binding = DataBindingUtil.inflate(inflater, R.layout.create_user_fragment, container, false);
mViewModel = new ViewModelProvider(requireActivity()).get(CreateUserViewModel.class);
binding.createUserFireDepartmentIdEditText.setText(mViewModel.getFireDepartmentId());
binding.createUserCreateButton.setOnClickListener(v -> {
if (validInput()) {
FirestoreDatabase.getInstance().getDb().collection(FirestoreDatabase.FIRE_DEPARTMENT_COLLECTION_DIR).document(binding.createUserFireDepartmentIdEditText.getText().toString()).get().addOnSuccessListener(documentSnapshot -> {
if (documentSnapshot.toObject(UsersDataModel.class) != null) {
UsersDataModel newUser = new UsersDataModel();
fillUser(newUser);
FirestoreDatabase.getInstance().getDb().collection(FirestoreDatabase.USERS_COLLECTION_DIR).add(newUser).addOnSuccessListener(documentReference -> {
// Success, login
if (FirestoreDatabase.getInstance().setActiveUser(newUser)) {
newUser.setDocumentId(documentReference.getId());
ActiveUser activeUser = ((ActiveUser) getActivity());
activeUser.setActive(newUser);
NavDirections action = CreateUserFragmentDirections.actionCreateUserFragmentToHomeFragment();
Navigation.findNavController(binding.getRoot()).navigate(action);
} else {
Toast.makeText(getContext(), "User does not have a department", Toast.LENGTH_SHORT).show();
}
}).addOnFailureListener(e -> Toast.makeText(getContext(), "Failed to upload user. Network error", Toast.LENGTH_SHORT).show());
} else {
Toast.makeText(getContext(), "Fire department does not exist", Toast.LENGTH_SHORT).show();
}
}).addOnFailureListener(e -> Toast.makeText(getContext(), "Cannot check for fire department. Network error", Toast.LENGTH_SHORT).show());
} else {
Toast.makeText(getContext(), "You must fill all of the text fields", Toast.LENGTH_SHORT).show();
}
});
return binding.getRoot();
}
Aggregations