use of com.example.first_responder_app.dataModels.UsersDataModel in project FirstResponse by mattpost1700.
the class NewChatFragment method onCreateView.
@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
ChatNewFragmentBinding binding = DataBindingUtil.inflate(inflater, R.layout.chat_new_fragment, container, false);
NavHostFragment navHostFragment = (NavHostFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.nav_host_fragment);
// TODO: navCont created for side bar(still need to be implemented)
NavController navController = navHostFragment.getNavController();
firestoreDatabase = new FirestoreDatabase();
db = FirebaseFirestore.getInstance();
activeUser = (ActiveUser) getActivity();
if (activeUser != null) {
user = activeUser.getActive();
}
listOfUsers = new ArrayList<>();
populateUserList();
listOfNewUsers = new ArrayList<>();
NewChatRecyclerViewAdapter.ItemClickListener userClickListener = ((view, position, data) -> {
// remove user
listOfNewUsers.remove(data);
newChatRecyclerViewAdapter.notifyDataSetChanged();
});
RecyclerView newChatRecyclerView = binding.newChatRecyclerView;
newChatRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
newChatRecyclerViewAdapter = new NewChatRecyclerViewAdapter(getContext(), listOfNewUsers);
newChatRecyclerViewAdapter.setClickListener(userClickListener);
newChatRecyclerView.setAdapter(newChatRecyclerViewAdapter);
newChatRecyclerView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
@Override
public void onLayoutChange(View view, int i, int i1, int i2, int i3, int i4, int i5, int i6, int i7) {
newChatRecyclerView.removeOnLayoutChangeListener(this);
// newChatRecyclerView.scrollToPosition(newChatRecyclerView.getAdapter().getItemCount() - 1);
}
});
binding.newChatAddUserFab.setOnClickListener(v -> {
String newUserName = binding.newChatUsersEditText.getText().toString();
UsersDataModel result = listOfUsers.stream().filter(u -> newUserName.equals(u.getFull_name())).findAny().orElse(null);
// If user exists, is not the current user, and has not already been added
if (result != null && !result.getDocumentId().equals(user.getDocumentId()) && !listOfNewUsers.contains(result)) {
binding.newChatErrorMsg.setText("");
listOfNewUsers.add(result);
newChatRecyclerViewAdapter.notifyDataSetChanged();
} else {
binding.newChatErrorMsg.setText("User not found");
}
});
binding.newChatCreateConfirm.setOnClickListener(v -> {
String chatName = binding.newChatChatNameEditText.getText().toString();
if (listOfNewUsers.size() == 0) {
binding.newChatErrorMsg.setText("Must add users to the chat");
} else if (chatName.length() == 0) {
binding.newChatErrorMsg.setText("Chat name must not be blank");
} else {
listOfNewUsers.add(user);
firestoreDatabase.addChat(chatName, listOfNewUsers);
}
NavDirections action = NewChatFragmentDirections.actionNewChatFragmentToChatGroupFragment();
Navigation.findNavController(binding.getRoot()).navigate(action);
});
return binding.getRoot();
}
use of com.example.first_responder_app.dataModels.UsersDataModel in project FirstResponse by mattpost1700.
the class SearchUserFragment method onCreateView.
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
SearchUserFragmentBinding binding = DataBindingUtil.inflate(inflater, R.layout.search_user_fragment, container, false);
activeUser = AppUtil.getActiveUser(getActivity());
listOfAllFireDepartmentUsers = new ArrayList<>();
adapter = new SearchUserAdapter(getContext(), listOfAllFireDepartmentUsers);
searchView = binding.search;
listView = binding.listview;
fillList();
listView.setOnItemClickListener((parent, view, position, id) -> {
UsersDataModel selectedUser = listOfAllFireDepartmentUsers.get(position);
// Go to admin edit user
mViewModel = new ViewModelProvider(requireActivity()).get(SearchUserViewModel.class);
mViewModel.setSelectedUser(selectedUser);
NavDirections action = SearchUserFragmentDirections.actionSearchUserFragmentToAdminEditUserFragment();
Navigation.findNavController(binding.getRoot()).navigate(action);
});
final SwipeRefreshLayout pullToRefresh = binding.searchUserSwipe;
pullToRefresh.setOnRefreshListener(() -> {
fillList();
pullToRefresh.setRefreshing(false);
});
listView.setAdapter(adapter);
searchView.setOnQueryTextListener(this);
return binding.getRoot();
}
use of com.example.first_responder_app.dataModels.UsersDataModel in project FirstResponse by mattpost1700.
the class FirestoreDatabase method addAnnouncement.
// TODO: Add group id
public void addAnnouncement(String title, String description, UsersDataModel user) {
setActiveUser(user);
AnnouncementsDataModel newAnnoun = new AnnouncementsDataModel(activeUserFireDepartmentId, user.getDocumentId(), activeUser.getDocumentId(), title, description);
db.collection(ANNOUNCEMENTS_COLLECTION_DIR).add(newAnnoun).addOnSuccessListener(documentReference -> Log.d("new announcement page", "new announcement has been successfully created in the DB")).addOnFailureListener(e -> Log.d("new announcement page", "failed to create new announcement"));
}
use of com.example.first_responder_app.dataModels.UsersDataModel in project FirstResponse by mattpost1700.
the class FirestoreDatabase method userModelMembersToStringMembers.
private List<String> userModelMembersToStringMembers(List<UsersDataModel> userModelMembers) {
ArrayList<String> stringMembers = new ArrayList<String>();
for (UsersDataModel u : userModelMembers) {
String memberName = u.getFull_name() + "/" + u.getDocumentId();
stringMembers.add(memberName);
}
return stringMembers;
}
use of com.example.first_responder_app.dataModels.UsersDataModel in project FirstResponse by mattpost1700.
the class MainActivity method setActive.
/**
* Set the logged in user
* @param user the user who just logged in
*/
@Override
public void setActive(UsersDataModel user) {
Log.d(TAG, "setActive: " + user);
if (user == null) {
this.activeUser = null;
if (userListener != null) {
userListener.remove();
userListener = null;
}
if (incidentListener != null) {
incidentListener.remove();
incidentListener = null;
}
stopETA();
return;
}
this.activeUser = user;
NavigationView navView = findViewById(R.id.navView);
View header = navView.getHeaderView(0);
TextView name = header.findViewById(R.id.nav_name);
TextView username = header.findViewById(R.id.nav_username);
String fullName = user.getFirst_name() + " " + user.getLast_name();
name.setText(fullName);
username.setText(user.getUsername());
// Ensure that the active user data is updated if database is updated
if (userListener == null) {
DocumentReference docRef = FirestoreDatabase.getInstance().getDb().collection("users").document(user.getDocumentId());
userListener = docRef.addSnapshotListener((snapshot, err) -> {
Log.d(TAG, "READ DATABASE - MAIN ACTIVITY");
if (err != null) {
System.err.println("Listen failed: " + err);
return;
}
if (snapshot != null && snapshot.exists()) {
activeUser = snapshot.toObject(UsersDataModel.class);
// Find the address of the department and determine where they are responding
setRespAddr();
// Download profile pic
try {
if (activeUser.getRemote_path_to_profile_picture() != null) {
final File localFile = File.createTempFile("Images", "bmp");
StorageReference ref = FirestoreDatabase.profilePictureRef.child(activeUser.getRemote_path_to_profile_picture());
ref.getFile(localFile).addOnSuccessListener(bytes -> {
try {
((ImageView) findViewById(R.id.appDrawerProfilePicImageView)).setImageBitmap(BitmapFactory.decodeFile(localFile.getAbsolutePath()));
} catch (Exception e) {
Log.d(TAG, "onCreateView: No profile picture found");
}
}).addOnFailureListener(e -> {
Log.w(TAG, "getUserProfile: Could not load profile picture!", e);
});
}
} catch (IOException e) {
Log.e(TAG, "onCreateView: Failed creating temp file", e);
} catch (NullPointerException e) {
Log.e(TAG, "onCreate: Cannot get user", e);
} catch (IllegalArgumentException e) {
Log.e(TAG, "onCreate: User has no image", e);
}
} else {
System.out.print("Current data: null");
}
});
}
}
Aggregations