mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-11 13:45:48 -04:00
Style[bta_profile]: improve code niceness
This commit is contained in:
parent
9e53552a8c
commit
988d3bbcb6
@ -16,8 +16,12 @@ 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/%s/%s/client.jar";
|
private static final String BASE_DOWNLOADS_URL = "https://downloads.betterthanadventure.net/bta-client/";
|
||||||
private static final String BTA_ICON_URL = "https://downloads.betterthanadventure.net/bta-client/%s/%s/auto/%s.png";
|
private static final String CLIENT_JAR_URL = BASE_DOWNLOADS_URL + "%s/%s/client.jar";
|
||||||
|
private static final String ICON_URL = BASE_DOWNLOADS_URL + "%s/%s/auto/%s.png";
|
||||||
|
private static final String MANIFEST_URL = BASE_DOWNLOADS_URL + "%s/versions.json";
|
||||||
|
private static final String BUILD_TYPE_RELEASE = "release";
|
||||||
|
private static final String BUILD_TYPE_NIGHTLY = "nightly";
|
||||||
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");
|
||||||
@ -30,7 +34,21 @@ public class BTAUtils {
|
|||||||
private static String getIconUrl(String version, String buildType) {
|
private static String getIconUrl(String version, String buildType) {
|
||||||
String iconName = version.replace('.','_');
|
String iconName = version.replace('.','_');
|
||||||
if(buildType.equals("nightly")) iconName = "v"+iconName;
|
if(buildType.equals("nightly")) iconName = "v"+iconName;
|
||||||
return String.format(BTA_ICON_URL, buildType, version, iconName);
|
return String.format(ICON_URL, buildType, version, iconName);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getClientJarUrl(String version, String buildType) {
|
||||||
|
return String.format(CLIENT_JAR_URL, buildType, version);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getManifestUrl(String buildType) {
|
||||||
|
return String.format(MANIFEST_URL, buildType);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static <T> T getManifest(String buildType, DownloadUtils.ParseCallback<T> parser)
|
||||||
|
throws DownloadUtils.ParseException, IOException {
|
||||||
|
String manifestUrl = getManifestUrl(buildType);
|
||||||
|
return DownloadUtils.downloadStringCached(manifestUrl,"bta_"+manifestUrl, parser);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<BTAVersion> createVersionList(List<String> versionStrings, String buildType) {
|
private static List<BTAVersion> createVersionList(List<String> versionStrings, String buildType) {
|
||||||
@ -41,7 +59,7 @@ public class BTAUtils {
|
|||||||
if(version == null) continue;
|
if(version == null) continue;
|
||||||
btaVersions.add(new BTAVersion(
|
btaVersions.add(new BTAVersion(
|
||||||
version,
|
version,
|
||||||
String.format(BTA_CLIENT_URL, buildType, version),
|
getClientJarUrl(version, buildType),
|
||||||
getIconUrl(version, buildType)
|
getIconUrl(version, buildType)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@ -51,7 +69,7 @@ public class BTAUtils {
|
|||||||
|
|
||||||
private static List<BTAVersion> processNightliesJson(String nightliesInfo) throws JsonParseException {
|
private static List<BTAVersion> processNightliesJson(String nightliesInfo) throws JsonParseException {
|
||||||
BTAVersionsManifest manifest = Tools.GLOBAL_GSON.fromJson(nightliesInfo, BTAVersionsManifest.class);
|
BTAVersionsManifest manifest = Tools.GLOBAL_GSON.fromJson(nightliesInfo, BTAVersionsManifest.class);
|
||||||
return createVersionList(manifest.versions, "nightly");
|
return createVersionList(manifest.versions, BUILD_TYPE_NIGHTLY);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static BTAVersionList processReleasesJson(String releasesInfo) throws JsonParseException {
|
private static BTAVersionList processReleasesJson(String releasesInfo) throws JsonParseException {
|
||||||
@ -69,20 +87,16 @@ public class BTAUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return new BTAVersionList(
|
return new BTAVersionList(
|
||||||
createVersionList(testedVersions, "release"),
|
createVersionList(testedVersions, BUILD_TYPE_RELEASE),
|
||||||
createVersionList(untestedVersions, "release"),
|
createVersionList(untestedVersions, BUILD_TYPE_RELEASE),
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BTAVersionList downloadVersionList() throws IOException {
|
public static BTAVersionList downloadVersionList() throws IOException {
|
||||||
try {
|
try {
|
||||||
BTAVersionList releases = DownloadUtils.downloadStringCached(
|
BTAVersionList releases = getManifest(BUILD_TYPE_RELEASE, BTAUtils::processReleasesJson);
|
||||||
"https://downloads.betterthanadventure.net/bta-client/release/versions.json",
|
List<BTAVersion> nightlies = getManifest(BUILD_TYPE_NIGHTLY, BTAUtils::processNightliesJson);
|
||||||
"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);
|
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);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user