mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-16 16:16:04 -04:00
Feat,wip[modpack-install]: auto modloader install
This commit is contained in:
parent
f8078ad8bf
commit
b1d022cccd
@ -63,6 +63,7 @@ public class ModItemAdapter extends RecyclerView.Adapter<ModItemAdapter.ViewHold
|
|||||||
|
|
||||||
mExtendedButton.setOnClickListener(v1 -> {
|
mExtendedButton.setOnClickListener(v1 -> {
|
||||||
mModpackApi.handleInstallation(
|
mModpackApi.handleInstallation(
|
||||||
|
mExtendedButton.getContext().getApplicationContext(),
|
||||||
mModDetail,
|
mModDetail,
|
||||||
mExtendedSpinner.getSelectedItemPosition());
|
mExtendedSpinner.getSelectedItemPosition());
|
||||||
|
|
||||||
|
@ -104,9 +104,9 @@ public class CurseforgeApi implements ModpackApi{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void installMod(ModDetail modDetail, int selectedVersion) {
|
public ModLoader installMod(ModDetail modDetail, int selectedVersion) {
|
||||||
//TODO considering only modpacks for now
|
//TODO considering only modpacks for now
|
||||||
ModpackInstaller.installModpack(modDetail, selectedVersion, this::installCurseforgeZip);
|
return ModpackInstaller.installModpack(modDetail, selectedVersion, this::installCurseforgeZip);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,11 +1,18 @@
|
|||||||
package net.kdt.pojavlaunch.modloaders.modpacks.api;
|
package net.kdt.pojavlaunch.modloaders.modpacks.api;
|
||||||
|
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import net.kdt.pojavlaunch.PojavApplication;
|
import net.kdt.pojavlaunch.PojavApplication;
|
||||||
|
import net.kdt.pojavlaunch.modloaders.ModloaderDownloadListener;
|
||||||
import net.kdt.pojavlaunch.modloaders.modpacks.models.ModDetail;
|
import net.kdt.pojavlaunch.modloaders.modpacks.models.ModDetail;
|
||||||
import net.kdt.pojavlaunch.modloaders.modpacks.models.ModItem;
|
import net.kdt.pojavlaunch.modloaders.modpacks.models.ModItem;
|
||||||
import net.kdt.pojavlaunch.modloaders.modpacks.models.SearchFilters;
|
import net.kdt.pojavlaunch.modloaders.modpacks.models.SearchFilters;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@ -29,9 +36,29 @@ public interface ModpackApi {
|
|||||||
* @param modDetail The mod detail data
|
* @param modDetail The mod detail data
|
||||||
* @param selectedVersion The selected version
|
* @param selectedVersion The selected version
|
||||||
*/
|
*/
|
||||||
default void handleInstallation(ModDetail modDetail, int selectedVersion) {
|
default void handleInstallation(Context context, ModDetail modDetail, int selectedVersion) {
|
||||||
PojavApplication.sExecutorService.execute(() -> {
|
PojavApplication.sExecutorService.execute(() -> {
|
||||||
installMod(modDetail, selectedVersion);
|
ModLoader loaderInfo = installMod(modDetail, selectedVersion);
|
||||||
|
if (loaderInfo == null) return;
|
||||||
|
|
||||||
|
loaderInfo.getDownloadTask(new ModloaderDownloadListener() {
|
||||||
|
@Override
|
||||||
|
public void onDownloadFinished(File downloadedFile) {
|
||||||
|
Intent intent = loaderInfo.getInstallationIntent(context, downloadedFile);
|
||||||
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
context.startActivity(intent);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDataNotAvailable() {
|
||||||
|
Toast.makeText(context, "Version gathering failed", Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDownloadError(Exception e) {
|
||||||
|
Toast.makeText(context, "download failed", Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
}).run();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,5 +69,5 @@ public interface ModpackApi {
|
|||||||
* @param modDetail The mod detail data
|
* @param modDetail The mod detail data
|
||||||
* @param selectedVersion The selected version
|
* @param selectedVersion The selected version
|
||||||
*/
|
*/
|
||||||
void installMod(ModDetail modDetail, int selectedVersion);
|
ModLoader installMod(ModDetail modDetail, int selectedVersion);
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import com.kdt.mcgui.ProgressLayout;
|
|||||||
|
|
||||||
import net.kdt.pojavlaunch.R;
|
import net.kdt.pojavlaunch.R;
|
||||||
import net.kdt.pojavlaunch.Tools;
|
import net.kdt.pojavlaunch.Tools;
|
||||||
|
import net.kdt.pojavlaunch.modloaders.ModloaderDownloadListener;
|
||||||
import net.kdt.pojavlaunch.modloaders.modpacks.imagecache.ModIconCache;
|
import net.kdt.pojavlaunch.modloaders.modpacks.imagecache.ModIconCache;
|
||||||
import net.kdt.pojavlaunch.modloaders.modpacks.models.ModDetail;
|
import net.kdt.pojavlaunch.modloaders.modpacks.models.ModDetail;
|
||||||
import net.kdt.pojavlaunch.progresskeeper.DownloaderProgressWrapper;
|
import net.kdt.pojavlaunch.progresskeeper.DownloaderProgressWrapper;
|
||||||
@ -17,7 +18,7 @@ import java.util.Locale;
|
|||||||
|
|
||||||
public class ModpackInstaller {
|
public class ModpackInstaller {
|
||||||
|
|
||||||
public static void installModpack(ModDetail modDetail, int selectedVersion, InstallFunction installFunction) {
|
public static ModLoader installModpack(ModDetail modDetail, int selectedVersion, InstallFunction installFunction) {
|
||||||
String versionUrl = modDetail.versionUrls[selectedVersion];
|
String versionUrl = modDetail.versionUrls[selectedVersion];
|
||||||
String modpackName = modDetail.title.toLowerCase(Locale.ROOT).trim().replace(" ", "_" );
|
String modpackName = modDetail.title.toLowerCase(Locale.ROOT).trim().replace(" ", "_" );
|
||||||
|
|
||||||
@ -33,6 +34,7 @@ public class ModpackInstaller {
|
|||||||
ProgressLayout.INSTALL_MODPACK));
|
ProgressLayout.INSTALL_MODPACK));
|
||||||
// Install the modpack
|
// Install the modpack
|
||||||
modLoaderInfo = installFunction.installModpack(modpackFile, new File(Tools.DIR_GAME_HOME, "custom_instances/"+modpackName));
|
modLoaderInfo = installFunction.installModpack(modpackFile, new File(Tools.DIR_GAME_HOME, "custom_instances/"+modpackName));
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
} finally {
|
} finally {
|
||||||
@ -40,7 +42,7 @@ public class ModpackInstaller {
|
|||||||
ProgressLayout.clearProgress(ProgressLayout.INSTALL_MODPACK);
|
ProgressLayout.clearProgress(ProgressLayout.INSTALL_MODPACK);
|
||||||
}
|
}
|
||||||
if(modLoaderInfo == null) {
|
if(modLoaderInfo == null) {
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the instance
|
// Create the instance
|
||||||
@ -53,6 +55,8 @@ public class ModpackInstaller {
|
|||||||
|
|
||||||
LauncherProfiles.mainProfileJson.profiles.put(modpackName, profile);
|
LauncherProfiles.mainProfileJson.profiles.put(modpackName, profile);
|
||||||
LauncherProfiles.update();
|
LauncherProfiles.update();
|
||||||
|
|
||||||
|
return modLoaderInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface InstallFunction {
|
interface InstallFunction {
|
||||||
|
@ -86,9 +86,9 @@ public class ModrinthApi implements ModpackApi{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void installMod(ModDetail modDetail, int selectedVersion) {
|
public ModLoader installMod(ModDetail modDetail, int selectedVersion) {
|
||||||
//TODO considering only modpacks for now
|
//TODO considering only modpacks for now
|
||||||
ModpackInstaller.installModpack(modDetail, selectedVersion, this::installMrpack);
|
return ModpackInstaller.installModpack(modDetail, selectedVersion, this::installMrpack);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ModLoader createInfo(ModrinthIndex modrinthIndex) {
|
private static ModLoader createInfo(ModrinthIndex modrinthIndex) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user