Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

render version string countability more imperturbable #136

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,22 @@ static Integer getAppInstalledVersionCode(Context context) {
}

static Boolean isUpdateAvailable(Update installedVersion, Update latestVersion) {
Boolean res = false;

if (latestVersion.getLatestVersionCode() != null && latestVersion.getLatestVersionCode() > 0) {
return latestVersion.getLatestVersionCode() > installedVersion.getLatestVersionCode();
} else {
if (!TextUtils.equals(installedVersion.getLatestVersion(), "0.0.0.0") && !TextUtils.equals(latestVersion.getLatestVersion(), "0.0.0.0")) {
Version installed = new Version(installedVersion.getLatestVersion());
Version latest = new Version(latestVersion.getLatestVersion());
res = installed.compareTo(latest) < 0;
}
try
{
final Version installed = new Version(installedVersion.getLatestVersion());
final Version latest = new Version(latestVersion.getLatestVersion());
return installed.compareTo(latest) < 0;
} catch (Exception e)
{
e.printStackTrace();
return false;
}
} else return false;
}

return res;
}

static Boolean isStringAVersion(String version) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.github.javiersantos.appupdater.objects;

import android.support.annotation.NonNull;
import android.util.Log;

public class Version implements Comparable<Version> {
private String version;
Expand All @@ -10,14 +9,14 @@ public final String get() {
return this.version;
}

public Version(String version) {
final String TAG = "AppUpdater";
if (version == null)
Log.e(TAG, "Version can not be null");
version = version.replaceAll("[^0-9?!\\.]", "");
if (!version.matches("[0-9]+(\\.[0-9]+)*"))
Log.e(TAG, "Invalid version format");
this.version = version;
public Version(@NonNull final String version) throws Exception
{
String trimmedVersion = version.replaceAll("[^0-9?!\\.]", "");
// replace all empty version number-parts with zeros
trimmedVersion = trimmedVersion.replaceAll("\\.(\\.|$)", "\\.0$1");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the crucial change for #136

if (!trimmedVersion.matches("[0-9]+(\\.[0-9]+)*"))
throw new Exception("Invalid version format. Original: `" + version + "` trimmed: `" + trimmedVersion + "`");
this.version = trimmedVersion;
}

@Override
Expand Down