From 18836d239657554da19f58e6c9460921b71783d5 Mon Sep 17 00:00:00 2001 From: Javier Santos Date: Sun, 28 Feb 2016 16:45:46 +0100 Subject: [PATCH] Fix #13 "Varies by Device" on certain Google Play apps --- .../com/github/javiersantos/appupdater/AppUpdater.java | 10 ++++++++++ .../javiersantos/appupdater/AppUpdaterUtils.java | 8 ++++++++ .../com/github/javiersantos/appupdater/UtilsAsync.java | 7 ++++++- .../github/javiersantos/appupdater/UtilsLibrary.java | 4 ++++ .../javiersantos/appupdater/enums/AppUpdaterError.java | 5 +++++ 5 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 library/src/main/java/com/github/javiersantos/appupdater/enums/AppUpdaterError.java 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 077f12dd..e9329774 100644 --- a/library/src/main/java/com/github/javiersantos/appupdater/AppUpdater.java +++ b/library/src/main/java/com/github/javiersantos/appupdater/AppUpdater.java @@ -2,7 +2,9 @@ import android.content.Context; import android.support.annotation.NonNull; +import android.util.Log; +import com.github.javiersantos.appupdater.enums.AppUpdaterError; import com.github.javiersantos.appupdater.enums.Display; import com.github.javiersantos.appupdater.enums.Duration; import com.github.javiersantos.appupdater.enums.UpdateFrom; @@ -220,6 +222,13 @@ public void onSuccess(String version) { } } } + + @Override + 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."); + } + } }); latestAppVersion.execute(); @@ -227,6 +236,7 @@ public void onSuccess(String version) { interface LibraryListener { void onSuccess(String version); + void onFailed(AppUpdaterError error); } private String getDescriptionUpdate(Context context, String version) { diff --git a/library/src/main/java/com/github/javiersantos/appupdater/AppUpdaterUtils.java b/library/src/main/java/com/github/javiersantos/appupdater/AppUpdaterUtils.java index e10e4034..2d150c07 100644 --- a/library/src/main/java/com/github/javiersantos/appupdater/AppUpdaterUtils.java +++ b/library/src/main/java/com/github/javiersantos/appupdater/AppUpdaterUtils.java @@ -2,6 +2,7 @@ import android.content.Context; +import com.github.javiersantos.appupdater.enums.AppUpdaterError; import com.github.javiersantos.appupdater.enums.UpdateFrom; import com.github.javiersantos.appupdater.objects.GitHub; @@ -14,11 +15,13 @@ public class AppUpdaterUtils { public interface AppUpdaterListener { /** * onSuccess method called after it is successful + * onFailed method called if it can't retrieve the latest version * * @param latestVersion available in the provided source * @param isUpdateAvailable compare installed version with the latest one */ void onSuccess(String latestVersion, Boolean isUpdateAvailable); + void onFailed(AppUpdaterError error); } public AppUpdaterUtils(Context context) { @@ -71,6 +74,11 @@ public void start() { public void onSuccess(String version) { appUpdaterListener.onSuccess(version, UtilsLibrary.isUpdateAvailable(UtilsLibrary.getAppInstalledVersion(context), version)); } + + @Override + public void onFailed(AppUpdaterError error) { + appUpdaterListener.onFailed(error); + } }); latestAppVersion.execute(); 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 3afac7dc..e5c999f2 100644 --- a/library/src/main/java/com/github/javiersantos/appupdater/UtilsAsync.java +++ b/library/src/main/java/com/github/javiersantos/appupdater/UtilsAsync.java @@ -3,6 +3,7 @@ import android.content.Context; import android.os.AsyncTask; +import com.github.javiersantos.appupdater.enums.AppUpdaterError; import com.github.javiersantos.appupdater.enums.UpdateFrom; import com.github.javiersantos.appupdater.objects.GitHub; @@ -47,7 +48,11 @@ protected String doInBackground(Void... voids) { @Override protected void onPostExecute(String version) { super.onPostExecute(version); - listener.onSuccess(version); + if (UtilsLibrary.isStringAVersion(version)) { + listener.onSuccess(version); + } else { + listener.onFailed(AppUpdaterError.UPDATE_VARIES_BY_DEVICE); + } } } 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 cc74900c..c060f79d 100644 --- a/library/src/main/java/com/github/javiersantos/appupdater/UtilsLibrary.java +++ b/library/src/main/java/com/github/javiersantos/appupdater/UtilsLibrary.java @@ -56,6 +56,10 @@ static Boolean isUpdateAvailable(String installedVersion, String latestVersion) return res; } + static Boolean isStringAVersion(String version) { + return version.matches(".*\\d+.*"); + } + static Boolean getDurationEnumToBoolean(Duration duration) { Boolean res = false; 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 new file mode 100644 index 00000000..e3a8e7fb --- /dev/null +++ b/library/src/main/java/com/github/javiersantos/appupdater/enums/AppUpdaterError.java @@ -0,0 +1,5 @@ +package com.github.javiersantos.appupdater.enums; + +public enum AppUpdaterError { + UPDATE_VARIES_BY_DEVICE +}