diff --git a/app/src/main/java/eu/faircode/email/BoundaryCallbackMessages.java b/app/src/main/java/eu/faircode/email/BoundaryCallbackMessages.java index d86c4ff43a..4ff3ce6e62 100644 --- a/app/src/main/java/eu/faircode/email/BoundaryCallbackMessages.java +++ b/app/src/main/java/eu/faircode/email/BoundaryCallbackMessages.java @@ -81,11 +81,11 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback models = new HashMap<>(); + private Map models = new HashMap() { + @Nullable + @Override + public Model put(AdapterMessage.ViewType key, Model value) { + Model existing = this.get(key); + if (existing != null && existing.boundary != null) + existing.boundary.destroy(); + return super.put(key, value); + } + + @Nullable + @Override + public Model remove(@Nullable Object key) { + Model existing = this.get(key); + if (existing != null && existing.boundary != null) + existing.boundary.destroy(); + return super.remove(key); + } + }; private ExecutorService executor = Helper.getBackgroundExecutor(2, "model");