Search in sources :

Example 1 with FragmentUserBinding

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();
}
Also used : Bundle(android.os.Bundle) NonNull(androidx.annotation.NonNull) ImageView(android.widget.ImageView) BitmapFactory(android.graphics.BitmapFactory) NavController(androidx.navigation.NavController) ActiveUser(com.example.first_responder_app.interfaces.ActiveUser) Fragment(androidx.fragment.app.Fragment) View(android.view.View) TAG(android.content.ContentValues.TAG) Log(android.util.Log) NavHostFragment(androidx.navigation.fragment.NavHostFragment) DataBindingUtil(androidx.databinding.DataBindingUtil) UsersDataModel(com.example.first_responder_app.dataModels.UsersDataModel) ViewModelProvider(androidx.lifecycle.ViewModelProvider) NavDirections(androidx.navigation.NavDirections) LayoutInflater(android.view.LayoutInflater) FirestoreDatabase(com.example.first_responder_app.FirestoreDatabase) IOException(java.io.IOException) FragmentUserBinding(com.example.first_responder_app.databinding.FragmentUserBinding) ViewGroup(android.view.ViewGroup) File(java.io.File) UserViewModel(com.example.first_responder_app.viewModels.UserViewModel) R(com.example.first_responder_app.R) FirebaseFirestore(com.google.firebase.firestore.FirebaseFirestore) Nullable(androidx.annotation.Nullable) StorageReference(com.google.firebase.storage.StorageReference) Navigation(androidx.navigation.Navigation) Snackbar(com.google.android.material.snackbar.Snackbar) FragmentUserBinding(com.example.first_responder_app.databinding.FragmentUserBinding) StorageReference(com.google.firebase.storage.StorageReference) NavController(androidx.navigation.NavController) IOException(java.io.IOException) IOException(java.io.IOException) NavDirections(androidx.navigation.NavDirections) UserViewModel(com.example.first_responder_app.viewModels.UserViewModel) ActiveUser(com.example.first_responder_app.interfaces.ActiveUser) NavHostFragment(androidx.navigation.fragment.NavHostFragment) File(java.io.File) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Aggregations

TAG (android.content.ContentValues.TAG)1 BitmapFactory (android.graphics.BitmapFactory)1 Bundle (android.os.Bundle)1 Log (android.util.Log)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 ImageView (android.widget.ImageView)1 NonNull (androidx.annotation.NonNull)1 Nullable (androidx.annotation.Nullable)1 DataBindingUtil (androidx.databinding.DataBindingUtil)1 Fragment (androidx.fragment.app.Fragment)1 ViewModelProvider (androidx.lifecycle.ViewModelProvider)1 NavController (androidx.navigation.NavController)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 UsersDataModel (com.example.first_responder_app.dataModels.UsersDataModel)1