mirror of
https://github.com/M66B/FairEmail.git
synced 2026-01-01 18:41:20 +01:00
Fixed popup menu lifecycle
This commit is contained in:
@@ -30,24 +30,12 @@ import androidx.lifecycle.LifecycleOwner;
|
||||
import androidx.lifecycle.OnLifecycleEvent;
|
||||
|
||||
public class PopupMenuLifecycle extends PopupMenu implements LifecycleObserver {
|
||||
private LifecycleOwner owner;
|
||||
|
||||
public PopupMenuLifecycle(@NonNull Context context, LifecycleOwner owner, @NonNull View anchor) {
|
||||
super(context, anchor);
|
||||
this.owner = owner;
|
||||
Log.i("Instantiate " + this);
|
||||
|
||||
anchor.addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() {
|
||||
@Override
|
||||
public void onViewAttachedToWindow(View v) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewDetachedFromWindow(View v) {
|
||||
PopupMenuLifecycle.this.dismiss();
|
||||
}
|
||||
});
|
||||
owner.getLifecycle().addObserver(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -64,6 +52,5 @@ public class PopupMenuLifecycle extends PopupMenu implements LifecycleObserver {
|
||||
public void onDestroy() {
|
||||
Log.i("Destroy " + this);
|
||||
this.dismiss();
|
||||
owner = null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user