Refresh profile picture in navigation drawer when changing picture from Change profile snippet

I have an Android app that has 4 fragments with a navigation drawer with a pic profile, but the thing is when I change / update the pic profile in Edit Fragment, the pic profile is updated in that snippet and also im save pic. URL in general settings (also upload to server), but when I go back to Home Fragment, the profile picture in the navigation drawer is not updated with the last picture. I am using Glide lib. to load the pic profile, this image loads the url which is stored in the general preference. But when I close the app and open the profile picture in the navigation drawer update with the last snapshot taken. I cannot ask the user to close the app and open it when they change their profile in the Edit Profile section. Is there a way to solve this problem?

 //getting image URL from Shared Preferences.
       imgUrl = Prefrences.getProfile_picture(HomeActivity.this);
       loadImageUrl(imgUrl);

//loading image in navigation drawer with glide in Main Activity
private void loadImageUrl(String imgUrl) {
    if (imgUrl != null && !imgUrl.isEmpty()) {
        Glide.with(this).load(imgUrl).placeholder(R.drawable.avatar)
                .crossFade()
                .thumbnail(0.5f)
                .bitmapTransform(new CircleTransform(this))
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .into(img_profile);
    } else { 
       getUserDetails();  <-- this method is called when imgUrl is Null,
    }

}

      

+3


source to share


2 answers


Your image is probably being cached by Glide.



Check the first 2 answers here Remove image from cache in Glide library

0


source


You can call the nav view to update the data when nav activity is created ....

Separate the data binding part and also call this from onCreate ()



private void updateNavHeaderView(){
View headerView = navigationView.inflateHeaderView(R.layout.nav_header);
        ImageView ivUserProfilePhoto = (ImageView) headerView.findViewById(R.id.ivUserProfilePhoto);
        TextView userName = (TextView) headerView.findViewById(R.id.userName);

        if (user != null && user.getUser_image() != null && !user.getUser_image().equals("")) {
            Picasso.with(MainActivity.this)
                    .load(Config.BASE_IMAGE_URL+"/"+user.getUser_image())
                    .placeholder(R.drawable.user_profile)
                    .resize(avatarSize, avatarSize)
                    .centerCrop()
                    .transform(new CircleTransformation())
                    .into(ivUserProfilePhoto);
        } else {
            ivUserProfilePhoto.setImageDrawable(getResources().getDrawable(R.drawable.user_profile));
        }
        }

      

0


source







All Articles