From 460ece8a81a5368651d950750d1b58d3e5cb4b17 Mon Sep 17 00:00:00 2001 From: Reco1l Date: Thu, 21 Nov 2024 11:27:37 -0300 Subject: [PATCH 1/7] Ensure dismiss call is not ignored if the fragment is loading --- src/com/edlplan/ui/ActivityOverlay.kt | 10 +++------ src/com/edlplan/ui/fragment/BaseFragment.kt | 25 +++++++++++++++++---- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/com/edlplan/ui/ActivityOverlay.kt b/src/com/edlplan/ui/ActivityOverlay.kt index 0ffa2537c..1c02c4f45 100644 --- a/src/com/edlplan/ui/ActivityOverlay.kt +++ b/src/com/edlplan/ui/ActivityOverlay.kt @@ -39,13 +39,11 @@ object ActivityOverlay { fun dismissOverlay(fragment: Fragment) { if (fragmentManager != null && fragment.isAdded) { - runSafe { fragmentManager!!.executePendingTransactions() } - if (displayingOverlay.contains(fragment)) { displayingOverlay.remove(fragment) fragmentManager!!.beginTransaction() .remove(fragment) - .commitNowAllowingStateLoss() + .commitAllowingStateLoss() } } } @@ -54,20 +52,18 @@ object ActivityOverlay { fun addOverlay(fragment: Fragment, tag: String?) { if (fragmentManager != null && !fragment.isAdded) { - runSafe { fragmentManager!!.executePendingTransactions() } - if (displayingOverlay.contains(fragment) || fragmentManager!!.findFragmentByTag(tag) != null) { displayingOverlay.remove(fragment) fragmentManager!!.beginTransaction() .remove(fragment) .add(containerId, fragment, tag) - .commitNowAllowingStateLoss() + .commitAllowingStateLoss() return } displayingOverlay.add(fragment) fragmentManager!!.beginTransaction() .add(containerId, fragment, tag) - .commitNowAllowingStateLoss() + .commitAllowingStateLoss() } } diff --git a/src/com/edlplan/ui/fragment/BaseFragment.kt b/src/com/edlplan/ui/fragment/BaseFragment.kt index 81214b4bf..877633dba 100644 --- a/src/com/edlplan/ui/fragment/BaseFragment.kt +++ b/src/com/edlplan/ui/fragment/BaseFragment.kt @@ -23,11 +23,18 @@ abstract class BaseFragment : Fragment(), BackPressListener { private set var isDismissOnBackPress = true + /** * If true, the fragment will intercept back press event when it's received. */ var interceptBackPress = true + + private var isLoaded = false + + private var isDismissCalled = false + + @get:IdRes val backgroundId: Int get() = R.id.frg_background @@ -71,13 +78,14 @@ abstract class BaseFragment : Fragment(), BackPressListener { } open fun show() { - mainThread { - ActivityOverlay.addOverlay(this, this.javaClass.name + "@" + this.hashCode()) - } + ActivityOverlay.addOverlay(this, this.javaClass.name + "@" + this.hashCode()) } open fun dismiss() { - mainThread { + isDismissCalled = true + + if (isLoaded) { + isDismissCalled = false ActivityOverlay.dismissOverlay(this) onDismissListener?.OnDismiss() } @@ -98,6 +106,7 @@ abstract class BaseFragment : Fragment(), BackPressListener { } override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { + isLoaded = false isCreated = true root = inflater.inflate(layoutID, container, false) findViewById(backgroundId)?.setOnClickListener { @@ -105,7 +114,15 @@ abstract class BaseFragment : Fragment(), BackPressListener { dismiss() } } + onLoadView() + isLoaded = true + + if (isDismissCalled) { + dismiss() + isDismissCalled = false + } + return root } From c055faa8d95137e0692bb117b3a4ade4ff66b1fa Mon Sep 17 00:00:00 2001 From: Reco1l Date: Thu, 21 Nov 2024 11:31:12 -0300 Subject: [PATCH 2/7] Remove unused import statements --- src/com/edlplan/ui/ActivityOverlay.kt | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/com/edlplan/ui/ActivityOverlay.kt b/src/com/edlplan/ui/ActivityOverlay.kt index 1c02c4f45..6b55827e0 100644 --- a/src/com/edlplan/ui/ActivityOverlay.kt +++ b/src/com/edlplan/ui/ActivityOverlay.kt @@ -6,8 +6,6 @@ import androidx.fragment.app.Fragment import androidx.fragment.app.FragmentManager import com.edlplan.ui.fragment.BackPressListener import com.edlplan.ui.fragment.BaseFragment -import com.reco1l.toolkt.kotlin.* -import java.util.* object ActivityOverlay { private var fragmentManager: FragmentManager? = null From 6e28a369195c4235c3d5af0d3366516f5eb8d43c Mon Sep 17 00:00:00 2001 From: Reco1l Date: Thu, 21 Nov 2024 11:35:08 -0300 Subject: [PATCH 3/7] Dismiss mod menu and search bar before starting the game --- src/ru/nsu/ccfit/zuev/osu/MainActivity.java | 4 +-- src/ru/nsu/ccfit/zuev/osu/menu/SongMenu.java | 27 +++++++++++--------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/ru/nsu/ccfit/zuev/osu/MainActivity.java b/src/ru/nsu/ccfit/zuev/osu/MainActivity.java index bda67fc85..5cf710ed5 100644 --- a/src/ru/nsu/ccfit/zuev/osu/MainActivity.java +++ b/src/ru/nsu/ccfit/zuev/osu/MainActivity.java @@ -773,11 +773,11 @@ public boolean onKeyDown(final int keyCode, final KeyEvent event) { && GlobalManager.getInstance().getEngine().getScene() == GlobalManager.getInstance().getSongMenu().getScene() && GlobalManager.getInstance().getSongMenu().getScene().hasChildScene()) { if (GlobalManager.getInstance().getSongMenu().getScene().getChildScene() == - GlobalManager.getInstance().getSongMenu().getFilterMenu().getScene()) { + GlobalManager.getInstance().getSongMenu().getSearchBar().getScene()) { if (keyCode == KeyEvent.KEYCODE_ENTER) { InputManager.getInstance().toggleKeyboard(); } - GlobalManager.getInstance().getSongMenu().getFilterMenu().hideMenu(); + GlobalManager.getInstance().getSongMenu().getSearchBar().hideMenu(); } if (GlobalManager.getInstance().getSongMenu().getScene().getChildScene() == ModMenu.getInstance().getScene()) { diff --git a/src/ru/nsu/ccfit/zuev/osu/menu/SongMenu.java b/src/ru/nsu/ccfit/zuev/osu/menu/SongMenu.java index 8ffbcbd9d..5afc4a921 100644 --- a/src/ru/nsu/ccfit/zuev/osu/menu/SongMenu.java +++ b/src/ru/nsu/ccfit/zuev/osu/menu/SongMenu.java @@ -125,7 +125,7 @@ public class SongMenu implements IUpdateHandler, MenuItemListener, private ExtendedSprite currentPressedButton; private ExtendedSprite scoringSwitcher = null; - private SearchBarFragment filterMenu = null; + private SearchBarFragment searchBar = null; private GroupType groupType = GroupType.MapSet; private Timer previousSelectionTimer; @@ -479,9 +479,9 @@ public boolean onAreaTouched(final TouchEvent pSceneTouchEvent, clickShortConfirmSound.play(); } - if (filterMenu == null) loadFilterFragment(); + if (searchBar == null) loadFilterFragment(); - filterMenu.showMenu(SongMenu.this); + searchBar.showMenu(SongMenu.this); } } return true; @@ -697,13 +697,13 @@ public boolean onAreaTouched(TouchEvent pSceneTouchEvent, float pTouchAreaLocalX } public void loadFilterFragment() { - filterMenu = new SearchBarFragment(); - filterMenu.loadConfig(context); + searchBar = new SearchBarFragment(); + searchBar.loadConfig(context); } public void unloadFilterFragment() { scene.clearChildScene(); - filterMenu = null; + searchBar = null; } public void toggleScoringSwitcher() { @@ -721,7 +721,7 @@ public void toggleScoringSwitcher() { public Scene getScene() { return scene; } - public SearchBarFragment getFilterMenu() { return filterMenu; } + public SearchBarFragment getSearchBar() { return searchBar; } public void show() { engine.setScene(scene); @@ -764,8 +764,8 @@ public void setFilter(final String filter, final SortOrder order, } public void sort() { - if (!sortOrder.equals(filterMenu.getOrder())) { - sortOrder = filterMenu.getOrder(); + if (!sortOrder.equals(searchBar.getOrder())) { + sortOrder = searchBar.getOrder(); } Collections.sort(items, (i1, i2) -> { String s1; @@ -1140,6 +1140,9 @@ public void selectBeatmap(final BeatmapInfo beatmapInfo, boolean reloadBG) { Replay.oldFLFollowDelay = ModMenu.getInstance().getFLfollowDelay(); + ModMenu.getInstance().hide(); + searchBar.dismiss(); + game.startGame(beatmapInfo, null); return; } @@ -1569,10 +1572,10 @@ private void reloadMenuItems(GroupType type) { } break; } - final String lowerFilter = filterMenu.getFilter().toLowerCase(); - final boolean favsOnly = filterMenu.isFavoritesOnly(); + final String lowerFilter = searchBar.getFilter().toLowerCase(); + final boolean favsOnly = searchBar.isFavoritesOnly(); - var limit = DatabaseManager.getBeatmapCollectionsTable().getBeatmaps(filterMenu.getFavoriteFolder()); + var limit = DatabaseManager.getBeatmapCollectionsTable().getBeatmaps(searchBar.getFavoriteFolder()); for (final BeatmapSetItem item : items) { item.applyFilter(lowerFilter, favsOnly, limit); } From 124e7a855e071e8ad4a255cb18108565b4e11355 Mon Sep 17 00:00:00 2001 From: Reco1l Date: Thu, 21 Nov 2024 11:38:58 -0300 Subject: [PATCH 4/7] Remove unneeded behavior --- src/com/edlplan/ui/fragment/ModSettingsMenu.kt | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/com/edlplan/ui/fragment/ModSettingsMenu.kt b/src/com/edlplan/ui/fragment/ModSettingsMenu.kt index 41d277d97..787fb2ac1 100644 --- a/src/com/edlplan/ui/fragment/ModSettingsMenu.kt +++ b/src/com/edlplan/ui/fragment/ModSettingsMenu.kt @@ -59,13 +59,6 @@ class ModSettingsMenu : BaseFragment() { override fun onLoadView() { reload(load()) - - // This fragment is expensive to load in older devices, during the loading process the dismiss - // calls are ignored as a result it can remain visible on unexpected places. This is a workaround - // to ensure that the fragment is dismissed when the scene is changed. - if (GlobalManager.getInstance().engine.scene.childScene != ModMenu.getInstance().scene) { - dismiss() - } } override fun onSaveInstanceState(outState: Bundle) = outState.run { From 9755e05a9cfa20f2d3e16f2a76db76a1564bc11a Mon Sep 17 00:00:00 2001 From: Reco1l Date: Thu, 21 Nov 2024 11:44:48 -0300 Subject: [PATCH 5/7] Ensure the dismiss calls are in main thread --- src/ru/nsu/ccfit/zuev/osu/menu/SongMenu.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ru/nsu/ccfit/zuev/osu/menu/SongMenu.java b/src/ru/nsu/ccfit/zuev/osu/menu/SongMenu.java index 5afc4a921..8b3ea9409 100644 --- a/src/ru/nsu/ccfit/zuev/osu/menu/SongMenu.java +++ b/src/ru/nsu/ccfit/zuev/osu/menu/SongMenu.java @@ -1140,8 +1140,10 @@ public void selectBeatmap(final BeatmapInfo beatmapInfo, boolean reloadBG) { Replay.oldFLFollowDelay = ModMenu.getInstance().getFLfollowDelay(); - ModMenu.getInstance().hide(); - searchBar.dismiss(); + Execution.mainThread(() -> { + ModMenu.getInstance().hide(); + searchBar.dismiss(); + }); game.startGame(beatmapInfo, null); return; From a5d0ace0fe6ef2307efc4db23f2d959bf69d58b0 Mon Sep 17 00:00:00 2001 From: Reco1l Date: Thu, 21 Nov 2024 11:45:14 -0300 Subject: [PATCH 6/7] Fix NPE when trying to dismiss search bar when it wasn't created --- .../edlplan/ui/fragment/SearchBarFragment.kt | 52 ++++++++++--------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/src/com/edlplan/ui/fragment/SearchBarFragment.kt b/src/com/edlplan/ui/fragment/SearchBarFragment.kt index 4a8367673..d798882df 100644 --- a/src/com/edlplan/ui/fragment/SearchBarFragment.kt +++ b/src/com/edlplan/ui/fragment/SearchBarFragment.kt @@ -253,31 +253,35 @@ class SearchBarFragment : BaseFragment(), IUpdateHandler, IFilterMenu { private fun playEndAnim(action: () -> Unit) { - val options = findViewById(R.id.options)!! - options.animate().cancel() - options.animate() - .alpha(0f) - .translationY(-400f) - .setInterpolator(EasingHelper.asInterpolator(Easing.InOutQuad)) - .setDuration(300) - .start() - - val body = findViewById(R.id.frg_body)!! - body.animate().cancel() - body.animate() - .alpha(0f) - .translationY(-400f) - .setInterpolator(EasingHelper.asInterpolator(Easing.InOutQuad)) - .setDuration(300) - .setListener( - object : BaseAnimationListener() { - override fun onAnimationEnd(animation: Animator) { - action() + if (isCreated) { + val options = findViewById(R.id.options)!! + options.animate().cancel() + options.animate() + .alpha(0f) + .translationY(-400f) + .setInterpolator(EasingHelper.asInterpolator(Easing.InOutQuad)) + .setDuration(300) + .start() + + val body = findViewById(R.id.frg_body)!! + body.animate().cancel() + body.animate() + .alpha(0f) + .translationY(-400f) + .setInterpolator(EasingHelper.asInterpolator(Easing.InOutQuad)) + .setDuration(300) + .setListener( + object : BaseAnimationListener() { + override fun onAnimationEnd(animation: Animator) { + action() + } } - } - ) - .start() - playBackgroundHideOutAnim(150) + ) + .start() + playBackgroundHideOutAnim(150) + } else { + action() + } } private fun updateOrderButton() { From 4f5ba9122262c8b90e6af1dcc72722c4fc066e29 Mon Sep 17 00:00:00 2001 From: Reco1l Date: Thu, 21 Nov 2024 11:46:06 -0300 Subject: [PATCH 7/7] Fix NPE when search bar is null --- src/ru/nsu/ccfit/zuev/osu/menu/SongMenu.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ru/nsu/ccfit/zuev/osu/menu/SongMenu.java b/src/ru/nsu/ccfit/zuev/osu/menu/SongMenu.java index 8b3ea9409..e11ce73c2 100644 --- a/src/ru/nsu/ccfit/zuev/osu/menu/SongMenu.java +++ b/src/ru/nsu/ccfit/zuev/osu/menu/SongMenu.java @@ -1142,7 +1142,9 @@ public void selectBeatmap(final BeatmapInfo beatmapInfo, boolean reloadBG) { Execution.mainThread(() -> { ModMenu.getInstance().hide(); - searchBar.dismiss(); + if (searchBar != null) { + searchBar.dismiss(); + } }); game.startGame(beatmapInfo, null);