use of com.example.first_responder_app.databinding.FragmentUserBinding in project FirstResponse by mattpost1700.
the class UserFragment method onCreateView.
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
FragmentUserBinding binding = DataBindingUtil.inflate(inflater, R.layout.fragment_user, container, false);
NavHostFragment navHostFragment = (NavHostFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.nav_host_fragment);
mViewModel = new ViewModelProvider(requireActivity()).get(UserViewModel.class);
user = mViewModel.getUserDataModel();
profilePictureImageView = binding.userProfilePictureImageView;
// Get active user id
ActiveUser active = (ActiveUser) getActivity();
if (active != null) {
activeUser = active.getActive();
}
// TODO: navCont created for side bar(still need to be implemented)
NavController navController = navHostFragment.getNavController();
boolean THIS_IS_CURRENT_USER = user != null && activeUser != null && activeUser.getDocumentId().equals(user.getDocumentId());
if (THIS_IS_CURRENT_USER) {
binding.userSendMessageFab.setVisibility(View.GONE);
binding.userEditFab.setOnClickListener(v -> {
NavDirections action = UserFragmentDirections.actionUserFragmentToEditUserFragment2();
Navigation.findNavController(binding.getRoot()).navigate(action);
});
} else {
binding.userEditFab.setVisibility(View.GONE);
binding.userSendMessageFab.setOnClickListener(v -> {
Snackbar.make(getView(), "Send msg!", Snackbar.LENGTH_SHORT).show();
// TODO: Send message
});
}
setText(binding);
try {
final File localFile = File.createTempFile("Images", "bmp");
StorageReference ref = FirestoreDatabase.profilePictureRef.child(user.getRemote_path_to_profile_picture());
ref.getFile(localFile).addOnSuccessListener(bytes -> {
try {
profilePictureImageView.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 (IllegalArgumentException e) {
Log.d(TAG, "No profile picture");
}
return binding.getRoot();
}
Aggregations