Option to specify a custom version comparator.
I would like to be able to specify when UpdateChecker should notify the user based on the actual version string fetched from Google Play Store. A typical use case is when I or some beta tester are running a newer version of the app than the one published. The current version of UpdateChecker will notify about "new version", even though the version on Play Store is older.
Here is one way it could be implemented: Let UpdateChecker.showDialog be overloaded with an extra argument, an instance of VersionComparator. The instance may be stored in the argument bundle using Bundle.putSerializable as it is implementing the Serializable interface.
public interface VersionComparator extends Serializable {
boolean isNewer(String googlePlayVersion, String installedVersion);
}
I could then make my own subclass of VersionComparator, crafted for my version names, and pass it to showDialog:
private class MyVersionComparator implements VersionComparator {
@Override
public boolean isNewer(String googlePlayVersion, String installedVersion) {
// Assumes that version strings are on format 'x.xx', eg '2.12'
String[] split = googlePlayVersion.split("\\.");
int googleMajor = Integer.parseInt(split[0]);
int googleMinor = Integer.parseInt(split[1]);
split = installedVersion.split("\\.");
int installedMajor = Integer.parseInt(split[0]);
int installedMinor = Integer.parseInt(split[1]);
return googleMajor > installedMajor || (googleMajor == installedMajor && googleMinor > installedMinor);
}
}
UpdateChecker.checkForDialog(this, 15, new MyVersionComparator());
So interesting idea. I'm rewriting the library, so I'll add this feature on version 2.0.0 Thanks a lot!
Also, this function can replace /integrate the argument int mSuccessfulChecksRequired not to simple and efficient.
I have implemented the feature, similar to the proposal I posted. You can look at the implementation here bjorncs/UpdateChecker@c1be46c1c8832d8e95ef3c25d73de0a200bcc1c0. Note that there are couple of other major changes in my codebase, like the removal of StyledDialogs and introduction of Gradle as build system. The example app is not compiling at the moment. Feel free to ask any questions.
Great! I'll merge it indevelop branch to continue the develop of 2.0.0 version.
I'll test it tomorrow. I've already planned to remove StyledDialogs in the project.
Cool! I will send you my Skype username in case you have any questions :)
In 2.1.0 i've introduced a more powerful version comparator (class here). Is this similar to what you were talking about? Any more requests?
I just needed to add that, my version name included "BETA" and the app crashed on me. I had to remove the non numeric part to get it to work. This is a good feature you should add but all in all, awesome, it works great.
Do you have any suggestion? Or should I remove only the non-numerical part from the string?
Hey rampo, I can't myself suggest how to make having strings work within version names for the library, but 1+ for supporting it one way or another as indeed I use 'beta' within the name too. Thanks!
One way could be to split the string using " " (space) as a delimiter and use the first part allowing the rest of the string to contain anything. This is based on the assumption that almost if not all devs start with the version numeric