Fixed popup menu lifecycle

This commit is contained in:
M66B 2019-09-21 20:28:03 +02:00
parent e6d3999a4e
commit fade38f07d
9 changed files with 17 additions and 30 deletions

View File

@ -418,7 +418,7 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
}
@Override
public void onViewRecycled(@NonNull ViewHolder holder) {
public void onViewDetachedFromWindow(@NonNull ViewHolder holder) {
holder.powner.recreate();
}
}

View File

@ -307,7 +307,7 @@ public class AdapterAnswer extends RecyclerView.Adapter<AdapterAnswer.ViewHolder
}
@Override
public void onViewRecycled(@NonNull ViewHolder holder) {
public void onViewDetachedFromWindow(@NonNull ViewHolder holder) {
holder.powner.recreate();
}
}

View File

@ -421,7 +421,7 @@ public class AdapterContact extends RecyclerView.Adapter<AdapterContact.ViewHold
}
@Override
public void onViewRecycled(@NonNull ViewHolder holder) {
public void onViewDetachedFromWindow(@NonNull ViewHolder holder) {
holder.powner.recreate();
}
}

View File

@ -904,11 +904,6 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
return new ViewHolder(inflater.inflate(viewType, parent, false));
}
@Override
public void onViewRecycled(@NonNull ViewHolder holder) {
holder.powner.recreate();
}
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
holder.unwire();
@ -919,6 +914,11 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
holder.wire();
}
@Override
public void onViewDetachedFromWindow(@NonNull ViewHolder holder) {
holder.powner.recreate();
}
interface IFolderSelectedListener {
void onFolderSelected(TupleFolderEx folder);
}

View File

@ -350,7 +350,7 @@ public class AdapterIdentity extends RecyclerView.Adapter<AdapterIdentity.ViewHo
}
@Override
public void onViewRecycled(@NonNull ViewHolder holder) {
public void onViewDetachedFromWindow(@NonNull ViewHolder holder) {
holder.powner.recreate();
}
}

View File

@ -3570,7 +3570,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
}
@Override
public void onViewRecycled(@NonNull ViewHolder holder) {
public void onViewDetachedFromWindow(@NonNull ViewHolder holder) {
holder.cowner.stop();
holder.powner.recreate();
}

View File

@ -332,11 +332,6 @@ public class AdapterOperation extends RecyclerView.Adapter<AdapterOperation.View
return new ViewHolder(inflater.inflate(R.layout.item_operation, parent, false));
}
@Override
public void onViewRecycled(@NonNull ViewHolder holder) {
holder.powner.recreate();
}
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
holder.unwire();
@ -346,4 +341,9 @@ public class AdapterOperation extends RecyclerView.Adapter<AdapterOperation.View
holder.wire();
}
@Override
public void onViewDetachedFromWindow(@NonNull ViewHolder holder) {
holder.powner.recreate();
}
}

View File

@ -428,7 +428,7 @@ public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> {
}
@Override
public void onViewRecycled(@NonNull ViewHolder holder) {
public void onViewDetachedFromWindow(@NonNull ViewHolder holder) {
holder.powner.recreate();
}
}

View File

@ -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;
}
}