Skip to content

Commit 9e1038c

Browse files
committed
fix(ui): tapping the same right-pane item twice in landscape opened it twice
openPane()/openPaneFragment() always pushed a new back-stack entry on the right pane's child FragmentManager, even when the fragment being opened was already the one on screen. A quick double-tap on the same trigger (instance row, settings gear, etc.) therefore stacked two identical entries, and Back had to be pressed twice to actually get back to the pane's home screen — the first press just popped the duplicate back to itself. Added isTagAlreadyOnTop(), checked at the top of both navigation helpers: if the requested tag is already the top back-stack entry, the tap is a no-op instead of pushing a duplicate.
1 parent b7ade35 commit 9e1038c

3 files changed

Lines changed: 16 additions & 0 deletions

File tree

-2.71 KB
Loading
-35.8 KB
Loading

app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/fragments/MainMenuFragment.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,24 @@ private void openModStore() {
157157
openPaneFragment(fragment, ModsSearchFragment.TAG);
158158
}
159159

160+
/**
161+
* True if {@code tag} is already the top entry on the right pane's back stack —
162+
* i.e. that fragment is already showing. Used to swallow a double-tap on the
163+
* same trigger instead of pushing a second, identical back-stack entry (which
164+
* made Back have to be pressed twice to actually leave).
165+
*/
166+
private boolean isTagAlreadyOnTop(String tag) {
167+
if (!isTwoPane()) return false;
168+
androidx.fragment.app.FragmentManager fm = getChildFragmentManager();
169+
int count = fm.getBackStackEntryCount();
170+
if (count == 0) return false;
171+
return tag.equals(fm.getBackStackEntryAt(count - 1).getName());
172+
}
173+
160174
/** Navigate to a pre-built fragment instance (preserves args on fresh instances). */
161175
private void openPaneFragment(Fragment fragment, String tag) {
162176
if (isTwoPane()) {
177+
if (isTagAlreadyOnTop(tag)) return; // already showing — ignore the double-tap
163178
getChildFragmentManager()
164179
.beginTransaction()
165180
.setReorderingAllowed(true)
@@ -179,6 +194,7 @@ private void openPaneFragment(Fragment fragment, String tag) {
179194
private void openPane(Class<? extends Fragment> fragmentClass, String tag,
180195
@Nullable Bundle args) {
181196
if (isTwoPane()) {
197+
if (isTagAlreadyOnTop(tag)) return; // already showing — ignore the double-tap
182198
getChildFragmentManager()
183199
.beginTransaction()
184200
.setReorderingAllowed(true)

0 commit comments

Comments
 (0)