Keep popup menu on update

This commit is contained in:
M66B
2020-11-12 08:07:30 +01:00
parent f6ce93d564
commit c4d85ab121
10 changed files with 33 additions and 58 deletions

View File

@@ -26,10 +26,13 @@ import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.LifecycleRegistry;
import androidx.lifecycle.OnLifecycleEvent;
import java.util.Objects;
// This class can be used as an externally controlled standalone or child life cycle owner
public class TwoStateOwner implements LifecycleOwner {
private String name;
private Object condition;
private LifecycleRegistry registry;
// https://developer.android.com/topic/libraries/architecture/lifecycle#lc
@@ -87,6 +90,13 @@ public class TwoStateOwner implements LifecycleOwner {
create();
}
void recreate(Object condition) {
if (!Objects.equals(this.condition, condition)) {
this.condition = condition;
recreate();
}
}
void destroy() {
Lifecycle.State state = registry.getCurrentState();
if (!state.equals(Lifecycle.State.DESTROYED)) {