Boundary fixes/improvements

This commit is contained in:
M66B
2020-04-09 21:19:44 +02:00
parent 2e1eb95d78
commit 1e4f726dd5
2 changed files with 37 additions and 19 deletions

View File

@@ -48,7 +48,25 @@ import java.util.concurrent.ExecutorService;
public class ViewModelMessages extends ViewModel {
private AdapterMessage.ViewType last = AdapterMessage.ViewType.UNIFIED;
private Map<AdapterMessage.ViewType, Model> models = new HashMap<>();
private Map<AdapterMessage.ViewType, Model> models = new HashMap<AdapterMessage.ViewType, Model>() {
@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");