Lock mod installer until no tasks are ongoing, and return installer with custom args

This commit is contained in:
artdeell 2022-11-14 15:40:16 +03:00 committed by ArtDev
parent c7c28173ba
commit a99d5a8aa5

View File

@ -5,6 +5,7 @@ import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@ -16,6 +17,7 @@ import net.kdt.pojavlaunch.R;
import net.kdt.pojavlaunch.Tools;
import net.kdt.pojavlaunch.extra.ExtraConstants;
import net.kdt.pojavlaunch.extra.ExtraCore;
import net.kdt.pojavlaunch.progresskeeper.ProgressKeeper;
public class MainMenuFragment extends Fragment {
public static final String TAG = "MainMenuFragment";
@ -35,10 +37,20 @@ public class MainMenuFragment extends Fragment {
mNewsButton.setOnClickListener(v -> Tools.openURL(requireActivity(), Tools.URL_HOME));
mCustomControlButton.setOnClickListener(v -> startActivity(new Intent(requireContext(), CustomControlsActivity.class)));
mInstallJarButton.setOnClickListener(v -> Tools.installMod(requireActivity(), false));
mInstallJarButton.setOnClickListener(v -> runInstallerWithConfirmation(false));
mInstallJarButton.setOnLongClickListener(v->{
runInstallerWithConfirmation(true);
return true;
});
mEditProfileButton.setOnClickListener(v -> Tools.swapFragment(requireActivity(), ProfileEditorFragment.class, ProfileEditorFragment.TAG, true, null));
mPlayButton.setOnClickListener(v -> ExtraCore.setValue(ExtraConstants.LAUNCH_GAME, true));
}
private void runInstallerWithConfirmation(boolean isCustomArgs) {
if (ProgressKeeper.getTaskCount() == 0)
Tools.installMod(requireActivity(), isCustomArgs);
else
Toast.makeText(requireContext(), R.string.tasks_ongoing, Toast.LENGTH_LONG).show();
}
}