From 4aec0d538ae1625a05bcfa91223e437c5c323277 Mon Sep 17 00:00:00 2001 From: artdeell Date: Sat, 1 Jul 2023 16:33:48 +0300 Subject: [PATCH] Get the user to the main fragment before starting mod installation --- .../kdt/pojavlaunch/fragments/FabricInstallFragment.java | 9 +++++++++ .../pojavlaunch/fragments/ModVersionListFragment.java | 2 ++ .../pojavlaunch/fragments/ProfileTypeSelectFragment.java | 3 +++ 3 files changed, 14 insertions(+) diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/fragments/FabricInstallFragment.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/fragments/FabricInstallFragment.java index 3fad00e14..4626a1df9 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/fragments/FabricInstallFragment.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/fragments/FabricInstallFragment.java @@ -3,6 +3,7 @@ package net.kdt.pojavlaunch.fragments; import android.content.Context; import android.content.Intent; import android.os.Bundle; +import android.util.Log; import android.view.View; import android.widget.Adapter; import android.widget.AdapterView; @@ -16,6 +17,7 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentManager; import net.kdt.pojavlaunch.JavaGUILauncherActivity; import net.kdt.pojavlaunch.R; @@ -127,6 +129,13 @@ public class FabricInstallFragment extends Fragment implements AdapterView.OnIte sTaskProxy.detachListener(); sTaskProxy = null; mStartButton.setEnabled(true); + // This works because the due to the fact that we have transitioned here + // without adding a transaction to the back stack, which caused the previous + // transaction to be amended (i guess?? thats how the back stack dump looks like) + // we can get back to the main fragment with just one back stack pop. + // For some reason that amendment causes the transaction to lose its tag + // so we cant use the tag here. + getParentFragmentManager().popBackStackImmediate(); Intent intent = new Intent(context, JavaGUILauncherActivity.class); FabricUtils.addAutoInstallArgs(intent, downloadedFile, mSelectedGameVersion, mSelectedLoaderVersion, mSelectedSnapshot, true); context.startActivity(intent); diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/fragments/ModVersionListFragment.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/fragments/ModVersionListFragment.java index afb7f06e8..4da58ff82 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/fragments/ModVersionListFragment.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/fragments/ModVersionListFragment.java @@ -117,6 +117,8 @@ public abstract class ModVersionListFragment extends Fragment implements Runn getTaskProxy().detachListener(); setTaskProxy(null); mExpandableListView.setEnabled(true); + // Read FabricInstallFragment line 132-137 to see why + getParentFragmentManager().popBackStack(); onDownloadFinished(context, downloadedFile); }); } diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/fragments/ProfileTypeSelectFragment.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/fragments/ProfileTypeSelectFragment.java index 6b742d55f..e3d1f0690 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/fragments/ProfileTypeSelectFragment.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/fragments/ProfileTypeSelectFragment.java @@ -21,6 +21,9 @@ public class ProfileTypeSelectFragment extends Fragment { super.onViewCreated(view, savedInstanceState); view.findViewById(R.id.vanilla_profile).setOnClickListener(v -> Tools.swapFragment(requireActivity(), ProfileEditorFragment.class, ProfileEditorFragment.TAG, false, new Bundle(1))); + + // NOTE: Special care needed! If you wll decide to add these to the back stack, please read FabricInstallFragment line 132-137 + // and amend FabricInstallFragment line 138 and ModVersionListFragment line 121 view.findViewById(R.id.optifine_profile).setOnClickListener(v -> Tools.swapFragment(requireActivity(), OptiFineInstallFragment.class, OptiFineInstallFragment.TAG, false, null)); view.findViewById(R.id.modded_profile_fabric).setOnClickListener((v)->