diff --git a/library/src/main/java/com/github/javiersantos/appupdater/AppUpdater.java b/library/src/main/java/com/github/javiersantos/appupdater/AppUpdater.java index a893aa1f..8badb338 100644 --- a/library/src/main/java/com/github/javiersantos/appupdater/AppUpdater.java +++ b/library/src/main/java/com/github/javiersantos/appupdater/AppUpdater.java @@ -255,6 +255,10 @@ public void onSuccess(Update update) { public void onFailed(AppUpdaterError error) { if (error == AppUpdaterError.UPDATE_VARIES_BY_DEVICE) { Log.e("AppUpdater", "UpdateFrom.GOOGLE_PLAY isn't valid: update varies by device."); + } else if (error == AppUpdaterError.GITHUB_USER_REPO_INVALID) { + throw new IllegalArgumentException("GitHub user or repo is empty!"); + } else if (error == AppUpdaterError.XML_URL_INVALID) { + throw new IllegalArgumentException("XML file is not valid!"); } } }); diff --git a/library/src/main/java/com/github/javiersantos/appupdater/UtilsAsync.java b/library/src/main/java/com/github/javiersantos/appupdater/UtilsAsync.java index 33320d31..fa6aba92 100644 --- a/library/src/main/java/com/github/javiersantos/appupdater/UtilsAsync.java +++ b/library/src/main/java/com/github/javiersantos/appupdater/UtilsAsync.java @@ -37,13 +37,16 @@ protected void onPreExecute() { if (!fromUtils && !libraryPreferences.getAppUpdaterShow()) { cancel(true); } else { - if (updateFrom == UpdateFrom.GITHUB) { - if (!GitHub.isGitHubValid(gitHub)) { - cancel(true); - } + if (updateFrom == UpdateFrom.GITHUB && !GitHub.isGitHubValid(gitHub)) { + listener.onFailed(AppUpdaterError.GITHUB_USER_REPO_INVALID); + cancel(true); + } else if (updateFrom == UpdateFrom.XML && (xmlUrl == null || !UtilsLibrary.isStringAnUrl(xmlUrl))) { + listener.onFailed(AppUpdaterError.XML_URL_INVALID); + cancel(true); } } } else { + listener.onFailed(AppUpdaterError.NETWORK_NOT_AVAILABLE); cancel(true); } } diff --git a/library/src/main/java/com/github/javiersantos/appupdater/UtilsLibrary.java b/library/src/main/java/com/github/javiersantos/appupdater/UtilsLibrary.java index 603c0300..87d7f40c 100644 --- a/library/src/main/java/com/github/javiersantos/appupdater/UtilsLibrary.java +++ b/library/src/main/java/com/github/javiersantos/appupdater/UtilsLibrary.java @@ -62,6 +62,16 @@ static Boolean isStringAVersion(String version) { return version.matches(".*\\d+.*"); } + static Boolean isStringAnUrl(String s) { + Boolean res = false; + try { + new URL(s); + res = true; + } catch (MalformedURLException ignored) {} + + return res; + } + static Boolean getDurationEnumToBoolean(Duration duration) { Boolean res = false; @@ -152,8 +162,7 @@ static Update getLatestAppVersionHttp(Context context, UpdateFrom updateFrom, Gi source = str.toString(); } catch (FileNotFoundException e) { Log.e("AppUpdater", "App wasn't found in the provided source. Is it published?"); - } catch (IOException ignore) { - } + } catch (IOException ignore) {} if (isAvailable) { switch (updateFrom) { diff --git a/library/src/main/java/com/github/javiersantos/appupdater/enums/AppUpdaterError.java b/library/src/main/java/com/github/javiersantos/appupdater/enums/AppUpdaterError.java index e3a8e7fb..cb52ce18 100644 --- a/library/src/main/java/com/github/javiersantos/appupdater/enums/AppUpdaterError.java +++ b/library/src/main/java/com/github/javiersantos/appupdater/enums/AppUpdaterError.java @@ -1,5 +1,23 @@ package com.github.javiersantos.appupdater.enums; public enum AppUpdaterError { - UPDATE_VARIES_BY_DEVICE + /** + * Google Play returned "Varies by device" + */ + UPDATE_VARIES_BY_DEVICE, + + /** + * GitHub user or repo is empty + */ + GITHUB_USER_REPO_INVALID, + + /** + * No Internet connection available + */ + NETWORK_NOT_AVAILABLE, + + /** + * URL for the XML file is not valid + */ + XML_URL_INVALID } diff --git a/library/src/main/java/com/github/javiersantos/appupdater/objects/GitHub.java b/library/src/main/java/com/github/javiersantos/appupdater/objects/GitHub.java index c4559c8a..e13e937d 100644 --- a/library/src/main/java/com/github/javiersantos/appupdater/objects/GitHub.java +++ b/library/src/main/java/com/github/javiersantos/appupdater/objects/GitHub.java @@ -1,7 +1,5 @@ package com.github.javiersantos.appupdater.objects; -import android.util.Log; - public class GitHub { private String gitHubUser; private String gitHubRepo; @@ -29,7 +27,6 @@ public void setGitHubRepo(String repo) { public static Boolean isGitHubValid(GitHub gitHub) { if (gitHub == null || gitHub.getGitHubUser().length() == 0 || gitHub.getGitHubRepo().length() == 0) { - Log.e("AppUpdater", "GitHub user or repo is empty!!"); return false; } else { return true;