Resolve manual update links from selected source
This commit is contained in:
@@ -32,6 +32,10 @@ final class UpdateManager {
|
||||
void onMessage(String message);
|
||||
}
|
||||
|
||||
private interface ReleaseUrlPicker {
|
||||
String pick(ReleaseInfo info);
|
||||
}
|
||||
|
||||
private final Activity activity;
|
||||
private final SharedPreferences prefs;
|
||||
private final Callback callback;
|
||||
@@ -73,6 +77,40 @@ final class UpdateManager {
|
||||
});
|
||||
}
|
||||
|
||||
void openApkDownload() {
|
||||
openSelectedReleaseUrl("APK", info -> info.apkUrl);
|
||||
}
|
||||
|
||||
void openReleasePage() {
|
||||
openSelectedReleaseUrl("Release page", info -> info.releasePageUrl);
|
||||
}
|
||||
|
||||
private void openSelectedReleaseUrl(String label, ReleaseUrlPicker picker) {
|
||||
if (checkInProgress) {
|
||||
postMessage("Update check already running");
|
||||
return;
|
||||
}
|
||||
String manifestUrl = getUpdateManifestUrl();
|
||||
checkInProgress = true;
|
||||
callback.onChecking(true);
|
||||
postMessage("Resolving " + label + " from " + hostLabel(manifestUrl) + "...");
|
||||
executor.execute(() -> {
|
||||
try {
|
||||
ReleaseInfo info = fetchReleaseInfo(manifestUrl);
|
||||
String url = picker.pick(info);
|
||||
if (url == null || url.trim().isEmpty()) {
|
||||
throw new IllegalStateException(label + " URL is missing");
|
||||
}
|
||||
activity.runOnUiThread(() -> openExternalUrl(url.trim(), label));
|
||||
} catch (Exception error) {
|
||||
postMessage(label + " failed: " + error.getMessage());
|
||||
} finally {
|
||||
checkInProgress = false;
|
||||
activity.runOnUiThread(() -> callback.onChecking(false));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private String getUpdateManifestUrl() {
|
||||
String url = prefs.getString("update_url", BuildConfig.DEFAULT_UPDATE_URL);
|
||||
if (url == null || url.trim().isEmpty()) {
|
||||
@@ -260,6 +298,15 @@ final class UpdateManager {
|
||||
}
|
||||
}
|
||||
|
||||
private void openExternalUrl(String url, String label) {
|
||||
try {
|
||||
activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
|
||||
postMessage("Opened " + label);
|
||||
} catch (ActivityNotFoundException error) {
|
||||
postMessage("No app can open " + label);
|
||||
}
|
||||
}
|
||||
|
||||
void resumePendingInstall() {
|
||||
File apk = pendingInstallApk;
|
||||
if (apk == null) {
|
||||
|
||||
Reference in New Issue
Block a user