mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-12 06:05:10 -04:00
Feat[bta_profile]: add the ability to install nightlies
This commit is contained in:
parent
740568fafa
commit
9e53552a8c
@ -16,8 +16,8 @@ import java.util.List;
|
|||||||
import java.util.ListIterator;
|
import java.util.ListIterator;
|
||||||
|
|
||||||
public class BTAUtils {
|
public class BTAUtils {
|
||||||
private static final String BTA_CLIENT_URL = "https://downloads.betterthanadventure.net/bta-client/release/%s/client.jar";
|
private static final String BTA_CLIENT_URL = "https://downloads.betterthanadventure.net/bta-client/%s/%s/client.jar";
|
||||||
private static final String BTA_ICON_URL = "https://downloads.betterthanadventure.net/bta-client/release/%s/auto/%s.png";
|
private static final String BTA_ICON_URL = "https://downloads.betterthanadventure.net/bta-client/%s/%s/auto/%s.png";
|
||||||
private static final List<String> BTA_TESTED_VERSIONS = new ArrayList<>();
|
private static final List<String> BTA_TESTED_VERSIONS = new ArrayList<>();
|
||||||
static {
|
static {
|
||||||
BTA_TESTED_VERSIONS.add("v7.3");
|
BTA_TESTED_VERSIONS.add("v7.3");
|
||||||
@ -27,26 +27,33 @@ public class BTAUtils {
|
|||||||
BTA_TESTED_VERSIONS.add("v7.1");
|
BTA_TESTED_VERSIONS.add("v7.1");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getIconUrl(String version) {
|
private static String getIconUrl(String version, String buildType) {
|
||||||
String versionUnderscore = version.replace('.','_');
|
String iconName = version.replace('.','_');
|
||||||
return String.format(BTA_ICON_URL, version, versionUnderscore);
|
if(buildType.equals("nightly")) iconName = "v"+iconName;
|
||||||
|
return String.format(BTA_ICON_URL, buildType, version, iconName);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<BTAVersion> createVersionList(List<String> versionStrings) {
|
private static List<BTAVersion> createVersionList(List<String> versionStrings, String buildType) {
|
||||||
ListIterator<String> iterator = versionStrings.listIterator(versionStrings.size());
|
ListIterator<String> iterator = versionStrings.listIterator(versionStrings.size());
|
||||||
ArrayList<BTAVersion> btaVersions = new ArrayList<>(versionStrings.size());
|
ArrayList<BTAVersion> btaVersions = new ArrayList<>(versionStrings.size());
|
||||||
while(iterator.hasPrevious()) {
|
while(iterator.hasPrevious()) {
|
||||||
String version = iterator.previous();
|
String version = iterator.previous();
|
||||||
|
if(version == null) continue;
|
||||||
btaVersions.add(new BTAVersion(
|
btaVersions.add(new BTAVersion(
|
||||||
version,
|
version,
|
||||||
String.format(BTA_CLIENT_URL, version),
|
String.format(BTA_CLIENT_URL, buildType, version),
|
||||||
getIconUrl(version)
|
getIconUrl(version, buildType)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
btaVersions.trimToSize();
|
btaVersions.trimToSize();
|
||||||
return btaVersions;
|
return btaVersions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static List<BTAVersion> processNightliesJson(String nightliesInfo) throws JsonParseException {
|
||||||
|
BTAVersionsManifest manifest = Tools.GLOBAL_GSON.fromJson(nightliesInfo, BTAVersionsManifest.class);
|
||||||
|
return createVersionList(manifest.versions, "nightly");
|
||||||
|
}
|
||||||
|
|
||||||
private static BTAVersionList processReleasesJson(String releasesInfo) throws JsonParseException {
|
private static BTAVersionList processReleasesJson(String releasesInfo) throws JsonParseException {
|
||||||
BTAVersionsManifest manifest = Tools.GLOBAL_GSON.fromJson(releasesInfo, BTAVersionsManifest.class);
|
BTAVersionsManifest manifest = Tools.GLOBAL_GSON.fromJson(releasesInfo, BTAVersionsManifest.class);
|
||||||
List<String> stringVersions = manifest.versions;
|
List<String> stringVersions = manifest.versions;
|
||||||
@ -62,16 +69,21 @@ public class BTAUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return new BTAVersionList(
|
return new BTAVersionList(
|
||||||
createVersionList(testedVersions),
|
createVersionList(testedVersions, "release"),
|
||||||
createVersionList(untestedVersions)
|
createVersionList(untestedVersions, "release"),
|
||||||
|
null
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BTAVersionList downloadVersionList() throws IOException {
|
public static BTAVersionList downloadVersionList() throws IOException {
|
||||||
try {
|
try {
|
||||||
return DownloadUtils.downloadStringCached(
|
BTAVersionList releases = DownloadUtils.downloadStringCached(
|
||||||
"https://downloads.betterthanadventure.net/bta-client/release/versions.json",
|
"https://downloads.betterthanadventure.net/bta-client/release/versions.json",
|
||||||
"bta_releases", BTAUtils::processReleasesJson);
|
"bta_releases", BTAUtils::processReleasesJson);
|
||||||
|
List<BTAVersion> nightlies = DownloadUtils.downloadStringCached(
|
||||||
|
"https://downloads.betterthanadventure.net/bta-client/nightly/versions.json",
|
||||||
|
"bta_nightlies", BTAUtils::processNightliesJson);
|
||||||
|
return new BTAVersionList(releases.testedVersions, releases.untestedVersions, nightlies);
|
||||||
}catch (DownloadUtils.ParseException e) {
|
}catch (DownloadUtils.ParseException e) {
|
||||||
Log.e("BTAUtils", "Failed to process json", e);
|
Log.e("BTAUtils", "Failed to process json", e);
|
||||||
return null;
|
return null;
|
||||||
@ -100,10 +112,12 @@ public class BTAUtils {
|
|||||||
public static class BTAVersionList {
|
public static class BTAVersionList {
|
||||||
public final List<BTAVersion> testedVersions;
|
public final List<BTAVersion> testedVersions;
|
||||||
public final List<BTAVersion> untestedVersions;
|
public final List<BTAVersion> untestedVersions;
|
||||||
|
public final List<BTAVersion> nightlyVersions;
|
||||||
|
|
||||||
public BTAVersionList(List<BTAVersion> mTestedVersions, List<BTAVersion> mUntestedVersions) {
|
public BTAVersionList(List<BTAVersion> mTestedVersions, List<BTAVersion> mUntestedVersions, List<BTAVersion> nightlyVersions) {
|
||||||
this.testedVersions = mTestedVersions;
|
this.testedVersions = mTestedVersions;
|
||||||
this.untestedVersions = mUntestedVersions;
|
this.untestedVersions = mUntestedVersions;
|
||||||
|
this.nightlyVersions = nightlyVersions;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,10 @@ public class BTAVersionListAdapter extends BaseExpandableListAdapter implements
|
|||||||
mGroupNames.add(context.getString(R.string.bta_installer_untested_versions));
|
mGroupNames.add(context.getString(R.string.bta_installer_untested_versions));
|
||||||
mGroups.add(versionList.untestedVersions);
|
mGroups.add(versionList.untestedVersions);
|
||||||
}
|
}
|
||||||
|
if(!versionList.nightlyVersions.isEmpty()) {
|
||||||
|
mGroupNames.add(context.getString(R.string.bta_installer_nightly_versions));
|
||||||
|
mGroups.add(versionList.nightlyVersions);
|
||||||
|
}
|
||||||
mGroupNames.trimToSize();
|
mGroupNames.trimToSize();
|
||||||
mGroups.trimToSize();
|
mGroups.trimToSize();
|
||||||
}
|
}
|
||||||
|
@ -428,4 +428,5 @@
|
|||||||
<string name="select_bta_version">Select \"Better than Adventure!\" version</string>
|
<string name="select_bta_version">Select \"Better than Adventure!\" version</string>
|
||||||
<string name="bta_installer_available_versions">Supported BTA versions</string>
|
<string name="bta_installer_available_versions">Supported BTA versions</string>
|
||||||
<string name="bta_installer_untested_versions">Untested BTA versions</string>
|
<string name="bta_installer_untested_versions">Untested BTA versions</string>
|
||||||
|
<string name="bta_installer_nightly_versions">Nightly BTA versions</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user