Skip to content

Commit

Permalink
Fix #13 "Varies by Device" on certain Google Play apps
Browse files Browse the repository at this point in the history
  • Loading branch information
javiersantos committed Feb 28, 2016
1 parent 846be26 commit 18836d2
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -220,13 +222,21 @@ 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();
}

interface LibraryListener {
void onSuccess(String version);
void onFailed(AppUpdaterError error);
}

private String getDescriptionUpdate(Context context, String version) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.github.javiersantos.appupdater.enums;

public enum AppUpdaterError {
UPDATE_VARIES_BY_DEVICE
}

0 comments on commit 18836d2

Please sign in to comment.