瀏覽代碼

Clear cached avatar

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
tobiasKaminsky 4 年之前
父節點
當前提交
43108661e9

+ 6 - 4
app/src/main/java/com/nextcloud/talk/controllers/ProfileController.java

@@ -245,8 +245,10 @@ public class ProfileController extends BaseController {
 
                             @Override
                             public void onNext(@NotNull GenericOverall genericOverall) {
-                                DisplayUtils.loadAvatarImage(currentUser,
-                                        getActivity().findViewById(R.id.avatar_image));
+                                DisplayUtils.loadAvatarImage(
+                                        currentUser,
+                                        getActivity().findViewById(R.id.avatar_image),
+                                        true);
                             }
 
                             @Override
@@ -300,7 +302,7 @@ public class ProfileController extends BaseController {
                 .findViewById(R.id.userinfo_baseurl))
                 .setText(Uri.parse(currentUser.getBaseUrl()).getHost());
 
-        DisplayUtils.loadAvatarImage(currentUser, getActivity().findViewById(R.id.avatar_image));
+        DisplayUtils.loadAvatarImage(currentUser, getActivity().findViewById(R.id.avatar_image), false);
 
         if (!TextUtils.isEmpty(userInfo.getDisplayName())) {
             ((TextView) getActivity().findViewById(R.id.userinfo_fullName)).setText(userInfo.getDisplayName());
@@ -591,7 +593,7 @@ public class ProfileController extends BaseController {
 
                     @Override
                     public void onNext(@NotNull GenericOverall genericOverall) {
-                        DisplayUtils.loadAvatarImage(currentUser, getActivity().findViewById(R.id.avatar_image));
+                        DisplayUtils.loadAvatarImage(currentUser, getActivity().findViewById(R.id.avatar_image), true);
                     }
 
                     @Override

+ 1 - 1
app/src/main/java/com/nextcloud/talk/controllers/SettingsController.java

@@ -562,7 +562,7 @@ public class SettingsController extends BaseController {
                 displayNameTextView.setText(currentUser.getDisplayName());
             }
 
-            DisplayUtils.loadAvatarImage(currentUser, avatarImageView);
+            DisplayUtils.loadAvatarImage(currentUser, avatarImageView, false);
 
             profileQueryDisposable = ncApi.getUserProfile(credentials,
                     ApiUtils.getUrlForUserProfile(currentUser.getBaseUrl()))

+ 13 - 3
app/src/main/java/com/nextcloud/talk/utils/DisplayUtils.java

@@ -534,7 +534,7 @@ public class DisplayUtils {
         }
     }
     
-    public static void loadAvatarImage(UserEntity user, SimpleDraweeView avatarImageView) {
+    public static void loadAvatarImage(UserEntity user, SimpleDraweeView avatarImageView, boolean deleteCache) {
         String avatarId;
         if (!TextUtils.isEmpty(user.getUserId())) {
             avatarId = user.getUserId();
@@ -542,11 +542,21 @@ public class DisplayUtils {
             avatarId = user.getUsername();
         }
 
+        // clear cache
+        if (deleteCache) {
+            String avatarString = ApiUtils.getUrlForAvatarWithName(user.getBaseUrl(), avatarId, R.dimen.avatar_size_big);
+            Uri avatarUri = Uri.parse(avatarString);
+
+            ImagePipeline imagePipeline = Fresco.getImagePipeline();
+            imagePipeline.evictFromMemoryCache(avatarUri);
+            imagePipeline.evictFromDiskCache(avatarUri);
+            imagePipeline.evictFromCache(avatarUri);
+        }
+
         DraweeController draweeController = Fresco.newDraweeControllerBuilder()
                 .setOldController(avatarImageView.getController())
                 .setAutoPlayAnimations(true)
-                .setImageRequest(DisplayUtils.getImageRequestForUrl(ApiUtils.getUrlForAvatarWithName(user.getBaseUrl(),
-                        avatarId, R.dimen.avatar_size_big), null))
+                .setImageRequest(DisplayUtils.getImageRequestForUrl(avatarString, null))
                 .build();
         avatarImageView.setController(draweeController);
     }