From 071ee8228c00ce51b4f18d1e9bbca7453e678ac1 Mon Sep 17 00:00:00 2001 From: Stefan Niedermann Date: Wed, 22 Apr 2020 13:55:37 +0200 Subject: [PATCH] Only compare major versions of API --- .../owncloud/notes/model/ApiVersion.java | 16 ++++------------ .../owncloud/notes/model/LocalAccount.java | 6 +++--- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/it/niedermann/owncloud/notes/model/ApiVersion.java b/app/src/main/java/it/niedermann/owncloud/notes/model/ApiVersion.java index 5eeede61..5b463db1 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/model/ApiVersion.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/model/ApiVersion.java @@ -32,16 +32,12 @@ public class ApiVersion implements Comparable { return minor; } - public boolean isGreaterOrEqualTo(ApiVersion v) { - return compareTo(v) >= 0; - } - public String getOriginalVersion() { return originalVersion; } public static ApiVersion of(String versionString) { - int major = 0, minor = 0, micro = 0; + int major = 0, minor = 0; if (versionString != null) { String[] split = versionString.split("\\."); if (split.length > 0) { @@ -64,9 +60,9 @@ public class ApiVersion implements Comparable { /** * @param compare another version object - * @return -1 if the compared version is higher than the current version - * 0 if the compared version is equal to the current version - * 1 if the compared version is lower than the current version + * @return -1 if the compared major version is higher than the current major version + * 0 if the compared major version is equal to the current major version + * 1 if the compared major version is lower than the current major version */ @Override public int compareTo(ApiVersion compare) { @@ -74,10 +70,6 @@ public class ApiVersion implements Comparable { return -1; } else if (compare.getMajor() < getMajor()) { return 1; - } else if (compare.getMinor() > getMinor()) { - return -1; - } else if (compare.getMinor() < getMinor()) { - return 1; } return 0; } diff --git a/app/src/main/java/it/niedermann/owncloud/notes/model/LocalAccount.java b/app/src/main/java/it/niedermann/owncloud/notes/model/LocalAccount.java index e7648dd6..4b76ec5b 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/model/LocalAccount.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/model/LocalAccount.java @@ -8,9 +8,9 @@ import androidx.annotation.Nullable; import org.json.JSONArray; import org.json.JSONException; -import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.HashSet; import java.util.NoSuchElementException; import it.niedermann.owncloud.notes.persistence.NotesClient; @@ -87,12 +87,12 @@ public class LocalAccount { public void setPreferredApiVersion(@Nullable String availableApiVersions) { // TODO move this logic to NotesClient? try { - if(availableApiVersions == null) { + if (availableApiVersions == null) { this.preferredApiVersion = null; return; } JSONArray versionsArray = new JSONArray(availableApiVersions); - Collection supportedApiVersions = new ArrayList<>(versionsArray.length()); + Collection supportedApiVersions = new HashSet<>(versionsArray.length()); for (int i = 0; i < versionsArray.length(); i++) { ApiVersion parsedApiVersion = ApiVersion.of(versionsArray.getString(i)); for (ApiVersion temp : NotesClient.SUPPORTED_API_VERSIONS) {