Fix unfold menus soft-lock after tab is switched to another

This commit is contained in:
YTKAB0BP
2024-11-13 21:26:37 +03:00
parent 0b2ba24c7f
commit 596f0f6dda
4 changed files with 28 additions and 7 deletions
@@ -27,6 +27,7 @@ public abstract class UnfoldMenu {
protected BedFragment fragment;
private boolean isVisible;
private boolean isDismissing;
private SpringAnimation spring;
private DynamicAnimation.OnAnimationUpdateListener updateListener;
private FrameLayout containerLayout;
@@ -121,13 +122,21 @@ public abstract class UnfoldMenu {
return true;
}
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
if (isVisible) {
onCreate();
}
}
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
if (isVisible) {
onDestroy();
isVisible = false;
}
}
};
@@ -138,7 +147,6 @@ public abstract class UnfoldMenu {
rootView.setTranslationX(fromTranslationX);
rootView.setTranslationY(fromTranslationY);
onCreate();
dimmView = new View(ctx);
dimmView.setBackgroundColor(0x40000000);
dimmView.setTranslationX(toTranslationX);
@@ -207,6 +215,10 @@ public abstract class UnfoldMenu {
updateListener.onAnimationUpdate(spring, 1f, 0f);
}
public boolean isAttached() {
return rootView.getParent() != null && !isDismissing;
}
public void dismiss() {
dismiss(false);
}
@@ -215,7 +227,9 @@ public abstract class UnfoldMenu {
if (!isVisible) return;
this.isVisible = false;
isDismissing = true;
onDestroy();
isDismissing = false;
if (alphaOnly) {
ValueAnimator anim = ValueAnimator.ofFloat(0, 1).setDuration(150);
@@ -71,7 +71,7 @@ public class SliceMenu extends ListBedMenu {
protected List<SimpleRecyclerItem> onCreateItems(boolean portrait) {
lastUid = SliceBeam.CONFIG_UID;
List<SimpleRecyclerItem> items = new ArrayList<>(Arrays.asList(
new BedMenuItem(R.string.MenuSliceInfo, R.drawable.square_stack_up_outline_28).onClick(v -> fragment.showUnfoldMenu(new PrintInfoMenu(), v)),
new BedMenuItem(R.string.MenuSliceInfo, R.drawable.square_stack_up_outline_28).onClick(v -> fragment.showUnfoldMenu(new LayersMenu(), v)),
new BedMenuItem(R.string.MenuSliceExportToFile, R.drawable.folder_simple_arrow_right_outline_28).onClick(v -> {
if (fragment.getContext() instanceof Activity) {
Activity act = (Activity) fragment.getContext();
@@ -176,7 +176,7 @@ public class SliceMenu extends ListBedMenu {
});
}
private final static class PrintInfoMenu extends UnfoldMenu {
private final static class LayersMenu extends UnfoldMenu {
private PositionScrollView fromTrack, toTrack;
private TextView title;
@@ -123,7 +123,10 @@ public class BedFragment extends Fragment {
public void showUnfoldMenu(UnfoldMenu menu, View from) {
if (currentUnfoldMenu != null) return;
menu.setOnDismiss(()-> currentUnfoldMenu = null);
menu.setOnDismiss(()-> {
if (menu.isAttached()) return;
currentUnfoldMenu = null;
});
currentUnfoldMenu = menu;
menu.show(from, this);
}