Feat[bta_profile]: add the ability to install nightlies

This commit is contained in:
artdeell 2025-02-04 16:54:39 +03:00 committed by Maksim Belov
parent 740568fafa
commit 9e53552a8c
3 changed files with 31 additions and 12 deletions

View File

@ -16,8 +16,8 @@ import java.util.List;
import java.util.ListIterator;
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_ICON_URL = "https://downloads.betterthanadventure.net/bta-client/release/%s/auto/%s.png";
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/%s/%s/auto/%s.png";
private static final List<String> BTA_TESTED_VERSIONS = new ArrayList<>();
static {
BTA_TESTED_VERSIONS.add("v7.3");
@ -27,26 +27,33 @@ public class BTAUtils {
BTA_TESTED_VERSIONS.add("v7.1");
}
private static String getIconUrl(String version) {
String versionUnderscore = version.replace('.','_');
return String.format(BTA_ICON_URL, version, versionUnderscore);
private static String getIconUrl(String version, String buildType) {
String iconName = version.replace('.','_');
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());
ArrayList<BTAVersion> btaVersions = new ArrayList<>(versionStrings.size());
while(iterator.hasPrevious()) {
String version = iterator.previous();
if(version == null) continue;
btaVersions.add(new BTAVersion(
version,
String.format(BTA_CLIENT_URL, version),
getIconUrl(version)
String.format(BTA_CLIENT_URL, buildType, version),
getIconUrl(version, buildType)
));
}
btaVersions.trimToSize();
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 {
BTAVersionsManifest manifest = Tools.GLOBAL_GSON.fromJson(releasesInfo, BTAVersionsManifest.class);
List<String> stringVersions = manifest.versions;
@ -62,16 +69,21 @@ public class BTAUtils {
}
return new BTAVersionList(
createVersionList(testedVersions),
createVersionList(untestedVersions)
createVersionList(testedVersions, "release"),
createVersionList(untestedVersions, "release"),
null
);
}
public static BTAVersionList downloadVersionList() throws IOException {
try {
return DownloadUtils.downloadStringCached(
BTAVersionList releases = DownloadUtils.downloadStringCached(
"https://downloads.betterthanadventure.net/bta-client/release/versions.json",
"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) {
Log.e("BTAUtils", "Failed to process json", e);
return null;
@ -100,10 +112,12 @@ public class BTAUtils {
public static class BTAVersionList {
public final List<BTAVersion> testedVersions;
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.untestedVersions = mUntestedVersions;
this.nightlyVersions = nightlyVersions;
}
}
}

View File

@ -31,6 +31,10 @@ public class BTAVersionListAdapter extends BaseExpandableListAdapter implements
mGroupNames.add(context.getString(R.string.bta_installer_untested_versions));
mGroups.add(versionList.untestedVersions);
}
if(!versionList.nightlyVersions.isEmpty()) {
mGroupNames.add(context.getString(R.string.bta_installer_nightly_versions));
mGroups.add(versionList.nightlyVersions);
}
mGroupNames.trimToSize();
mGroups.trimToSize();
}

View File

@ -428,4 +428,5 @@
<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_untested_versions">Untested BTA versions</string>
<string name="bta_installer_nightly_versions">Nightly BTA versions</string>
</resources>