diff --git a/src/com/edlplan/ui/ActivityOverlay.kt b/src/com/edlplan/ui/ActivityOverlay.kt index 0ffa2537c..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 @@ -39,13 +37,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 +50,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 } 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 { 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() { 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..e11ce73c2 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,13 @@ public void selectBeatmap(final BeatmapInfo beatmapInfo, boolean reloadBG) { Replay.oldFLFollowDelay = ModMenu.getInstance().getFLfollowDelay(); + Execution.mainThread(() -> { + ModMenu.getInstance().hide(); + if (searchBar != null) { + searchBar.dismiss(); + } + }); + game.startGame(beatmapInfo, null); return; } @@ -1569,10 +1576,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); }