Improved boundary destroy

This commit is contained in:
M66B
2021-06-18 16:02:46 +02:00
parent 48bcd11414
commit d788d75422
2 changed files with 21 additions and 12 deletions

View File

@@ -54,7 +54,7 @@ public class ViewModelMessages extends ViewModel {
public Model put(AdapterMessage.ViewType key, Model value) {
Model existing = this.get(key);
if (existing != null && existing.boundary != null)
existing.boundary.destroy();
existing.boundary.destroy(existing.boundary.getState());
return super.put(key, value);
}
@@ -63,7 +63,7 @@ public class ViewModelMessages extends ViewModel {
public Model remove(@Nullable Object key) {
Model existing = this.get(key);
if (existing != null && existing.boundary != null)
existing.boundary.destroy();
existing.boundary.destroy(existing.boundary.getState());
return super.remove(key);
}
};
@@ -518,12 +518,12 @@ public class ViewModelMessages extends ViewModel {
void setCallback(LifecycleOwner owner, BoundaryCallbackMessages.IBoundaryCallbackMessages callback) {
if (boundary != null) {
boundary.setCallback(callback);
BoundaryCallbackMessages.State state = boundary.setCallback(callback);
owner.getLifecycle().addObserver(new LifecycleObserver() {
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
public void onDestroyed() {
boundary.destroy();
boundary.destroy(state);
}
});
}