Skip to content

Commit

Permalink
Add more AppUpdaterError elements
Browse files Browse the repository at this point in the history
  • Loading branch information
javiersantos committed Mar 4, 2016
1 parent 3f5ec75 commit be3e2a6
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.github.javiersantos.appupdater.objects;

import android.util.Log;

public class GitHub {
private String gitHubUser;
private String gitHubRepo;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit be3e2a6

Please sign in to comment.