Prevent mod install from starting when tasks are ongoing

This commit is contained in:
BuildTools 2023-06-30 13:00:17 +03:00
parent 84a2bd24c7
commit d4f912afcd
3 changed files with 17 additions and 4 deletions

View File

@ -11,6 +11,7 @@ import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@ -24,6 +25,7 @@ import net.kdt.pojavlaunch.modloaders.FabricUtils;
import net.kdt.pojavlaunch.modloaders.ModloaderDownloadListener;
import net.kdt.pojavlaunch.modloaders.ModloaderListenerProxy;
import net.kdt.pojavlaunch.profiles.VersionSelectorDialog;
import net.kdt.pojavlaunch.progresskeeper.ProgressKeeper;
import java.io.File;
import java.io.IOException;
@ -79,6 +81,10 @@ public class FabricInstallFragment extends Fragment implements AdapterView.OnIte
}
private void onClickStart(View v) {
if(ProgressKeeper.hasOngoingTasks()) {
Toast.makeText(v.getContext(), R.string.tasks_ongoing, Toast.LENGTH_LONG).show();
return;
}
sTaskProxy = new ModloaderListenerProxy();
FabricDownloadTask fabricDownloadTask = new FabricDownloadTask(sTaskProxy, mDestinationDir);
sTaskProxy.attachListener(this);
@ -105,7 +111,7 @@ public class FabricInstallFragment extends Fragment implements AdapterView.OnIte
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
Adapter adapter = (Adapter) adapterView.getAdapter();
Adapter adapter = adapterView.getAdapter();
mSelectedLoaderVersion = (String) adapter.getItem(i);
}

View File

@ -8,6 +8,7 @@ import android.widget.ExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@ -17,13 +18,13 @@ import net.kdt.pojavlaunch.R;
import net.kdt.pojavlaunch.Tools;
import net.kdt.pojavlaunch.modloaders.ModloaderDownloadListener;
import net.kdt.pojavlaunch.modloaders.ModloaderListenerProxy;
import net.kdt.pojavlaunch.progresskeeper.ProgressKeeper;
import java.io.File;
import java.io.IOException;
public abstract class ModVersionListFragment<T> extends Fragment implements Runnable, View.OnClickListener, ExpandableListView.OnChildClickListener, ModloaderDownloadListener {
public static final String TAG = "ForgeInstallFragment";
//private static ModloaderListenerProxy sTaskProxy;
private ExpandableListView mExpandableListView;
private ProgressBar mProgressBar;
private LayoutInflater mInflater;
@ -37,7 +38,6 @@ public abstract class ModVersionListFragment<T> extends Fragment implements Runn
public void onAttach(@NonNull Context context) {
super.onAttach(context);
this.mInflater = LayoutInflater.from(context);
//this.mDestinationFile = new File(Tools.DIR_CACHE, "forge-installer.jar");
}
@Override
@ -96,10 +96,13 @@ public abstract class ModVersionListFragment<T> extends Fragment implements Runn
@Override
public boolean onChildClick(ExpandableListView expandableListView, View view, int i, int i1, long l) {
if(ProgressKeeper.hasOngoingTasks()) {
Toast.makeText(expandableListView.getContext(), R.string.tasks_ongoing, Toast.LENGTH_LONG).show();
return true;
}
Object forgeVersion = expandableListView.getExpandableListAdapter().getChild(i, i1);
ModloaderListenerProxy taskProxy = new ModloaderListenerProxy();
Runnable downloadTask = createDownloadTask(forgeVersion, taskProxy);
//ForgeDownloadTask downloadTask = new ForgeDownloadTask(taskProxy, forgeVersion, mDestinationFile);
setTaskProxy(taskProxy);
taskProxy.attachListener(this);
mExpandableListView.setEnabled(false);

View File

@ -100,4 +100,8 @@ public class ProgressKeeper {
public static synchronized int getTaskCount() {
return sProgressStates.size();
}
public static boolean hasOngoingTasks() {
return getTaskCount() > 0;
}
}