From fade38f07d7e1942be8c2f540cfff4742b50929a Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 21 Sep 2019 20:28:03 +0200 Subject: [PATCH] Fixed popup menu lifecycle --- .../java/eu/faircode/email/AdapterAccount.java | 2 +- .../java/eu/faircode/email/AdapterAnswer.java | 2 +- .../java/eu/faircode/email/AdapterContact.java | 2 +- .../java/eu/faircode/email/AdapterFolder.java | 10 +++++----- .../java/eu/faircode/email/AdapterIdentity.java | 2 +- .../java/eu/faircode/email/AdapterMessage.java | 2 +- .../java/eu/faircode/email/AdapterOperation.java | 10 +++++----- .../main/java/eu/faircode/email/AdapterRule.java | 2 +- .../eu/faircode/email/PopupMenuLifecycle.java | 15 +-------------- 9 files changed, 17 insertions(+), 30 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/AdapterAccount.java b/app/src/main/java/eu/faircode/email/AdapterAccount.java index 90876532b4..52b910ff17 100644 --- a/app/src/main/java/eu/faircode/email/AdapterAccount.java +++ b/app/src/main/java/eu/faircode/email/AdapterAccount.java @@ -418,7 +418,7 @@ public class AdapterAccount extends RecyclerView.Adapter { } @Override - public void onViewRecycled(@NonNull ViewHolder holder) { + public void onViewDetachedFromWindow(@NonNull ViewHolder holder) { holder.powner.recreate(); } } diff --git a/app/src/main/java/eu/faircode/email/PopupMenuLifecycle.java b/app/src/main/java/eu/faircode/email/PopupMenuLifecycle.java index e026c9fdf4..07f928d8f5 100644 --- a/app/src/main/java/eu/faircode/email/PopupMenuLifecycle.java +++ b/app/src/main/java/eu/faircode/email/PopupMenuLifecycle.java @@ -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; } }