evict cached previews when file gets deleted

Daniel Gultsch created

Change summary

src/main/java/eu/siacs/conversations/persistance/FileBackend.java        | 2 
src/main/java/eu/siacs/conversations/services/XmppConnectionService.java | 9 
src/main/java/eu/siacs/conversations/ui/ConversationFragment.java        | 1 
3 files changed, 12 insertions(+)

Detailed changes

src/main/java/eu/siacs/conversations/services/XmppConnectionService.java 🔗

@@ -1854,6 +1854,9 @@ public class XmppConnectionService extends Service {
         for (Conversation conversation : getConversations()) {
             deleted |= conversation.markAsDeleted(uuids);
         }
+        for(final String uuid : uuids) {
+            evictPreview(uuid);
+        }
         if (deleted) {
             updateConversationUi();
         }
@@ -4575,6 +4578,12 @@ public class XmppConnectionService extends Service {
         sendIqPacket(account, set, null);
     }
 
+    public void evictPreview(String uuid) {
+        if (mBitmapCache.remove(uuid) != null) {
+            Log.d(Config.LOGTAG,"deleted cached preview");
+        }
+    }
+
     public interface OnMamPreferencesFetched {
         void onPreferencesFetched(Element prefs);
 

src/main/java/eu/siacs/conversations/ui/ConversationFragment.java 🔗

@@ -1653,6 +1653,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
         builder.setPositiveButton(R.string.confirm, (dialog, which) -> {
             if (activity.xmppConnectionService.getFileBackend().deleteFile(message)) {
                 message.setDeleted(true);
+                activity.xmppConnectionService.evictPreview(message.getUuid());
                 activity.xmppConnectionService.updateMessage(message, false);
                 activity.onConversationsListItemUpdated();
                 refresh();