diff options
author | Stefan Niedermann <info@niedermann.it> | 2021-05-03 18:36:24 +0300 |
---|---|---|
committer | Stefan Niedermann <info@niedermann.it> | 2021-05-03 19:22:38 +0300 |
commit | bbf569b0e9a1a93e4fff8074cc180274fc1f2d24 (patch) | |
tree | e43c3237b7a36d8d3f4881129cd977e93690f9db /app/src/main/java/it/niedermann/owncloud/notes/shared | |
parent | e3c4c1cb40ba229f50dd534c9edef42cb807ed18 (diff) | |
parent | 1cc44ede8e6c605345d794452c099a07a49d2f49 (diff) |
Merge branch 'master' into 916-settings
# Conflicts:
# app/src/main/java/it/niedermann/owncloud/notes/manageaccounts/ManageAccountAdapter.java
# app/src/main/java/it/niedermann/owncloud/notes/manageaccounts/ManageAccountsActivity.java
# app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesClient.java
# app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesClientV1.java
# app/src/main/java/it/niedermann/owncloud/notes/shared/model/ApiVersion.java
# app/src/main/res/values/strings.xml
Diffstat (limited to 'app/src/main/java/it/niedermann/owncloud/notes/shared')
7 files changed, 95 insertions, 159 deletions
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/shared/model/ApiVersion.java b/app/src/main/java/it/niedermann/owncloud/notes/shared/model/ApiVersion.java index b4c62f5b..ee2fdc3a 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/shared/model/ApiVersion.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/shared/model/ApiVersion.java @@ -3,6 +3,7 @@ package it.niedermann.owncloud.notes.shared.model; import androidx.annotation.NonNull; +import java.util.Objects; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -11,6 +12,14 @@ public class ApiVersion implements Comparable<ApiVersion> { private static final Pattern NUMBER_EXTRACTION_PATTERN = Pattern.compile("[0-9]+"); private static final ApiVersion VERSION_1_2 = new ApiVersion("1.2", 1, 2); + public static final ApiVersion API_VERSION_0_2 = new ApiVersion(0, 2); + public static final ApiVersion API_VERSION_1_0 = new ApiVersion(1, 0); + + public static final ApiVersion[] SUPPORTED_API_VERSIONS = new ApiVersion[]{ + API_VERSION_1_0, + API_VERSION_0_2 + }; + private String originalVersion = "?"; private final int major; private final int minor; @@ -66,7 +75,7 @@ public class ApiVersion implements Comparable<ApiVersion> { * 1 if the compared major version is <strong>lower</strong> than the current major version */ @Override - public int compareTo(ApiVersion compare) { + public int compareTo(@NonNull ApiVersion compare) { if (compare.getMajor() > getMajor()) { return -1; } else if (compare.getMajor() < getMajor()) { @@ -77,7 +86,21 @@ public class ApiVersion implements Comparable<ApiVersion> { public boolean supportsSettings() { // TODO - return true;//getMajor() >= VERSION_1_2.getMajor() && getMinor() >= VERSION_1_2.getMinor(); + return true; +// return getMajor() >= 1 && getMinor() >= 2; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ApiVersion that = (ApiVersion) o; + return compareTo(that) == 0; + } + + @Override + public int hashCode() { + return Objects.hash(major, minor); } @NonNull diff --git a/app/src/main/java/it/niedermann/owncloud/notes/shared/model/Capabilities.java b/app/src/main/java/it/niedermann/owncloud/notes/shared/model/Capabilities.java index 1c1bed3d..5514a91b 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/shared/model/Capabilities.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/shared/model/Capabilities.java @@ -6,6 +6,7 @@ import android.util.Log; import androidx.annotation.ColorInt; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.annotation.VisibleForTesting; import com.bumptech.glide.load.HttpException; import com.nextcloud.android.sso.exceptions.NextcloudHttpRequestFailedException; @@ -38,12 +39,17 @@ public class Capabilities { private String apiVersion = null; @ColorInt - private Integer color = -16743735; + private int color = -16743735; @ColorInt - private Integer textColor = -16777216; + private int textColor = -16777216; @Nullable - private final String eTag; + private String eTag; + public Capabilities() { + + } + + @VisibleForTesting public Capabilities(@NonNull String response, @Nullable String eTag) throws NextcloudHttpRequestFailedException { this.eTag = eTag; final JSONObject ocs; @@ -92,6 +98,10 @@ public class Capabilities { } } + public void setApiVersion(String apiVersion) { + this.apiVersion = apiVersion; + } + public String getApiVersion() { return apiVersion; } @@ -101,14 +111,26 @@ public class Capabilities { return eTag; } - public Integer getColor() { + public void setETag(@Nullable String eTag) { + this.eTag = eTag; + } + + public int getColor() { return color; } - public Integer getTextColor() { + public void setColor(@ColorInt int color) { + this.color = color; + } + + public int getTextColor() { return textColor; } + public void setTextColor(@ColorInt int textColor) { + this.textColor = textColor; + } + @NonNull @Override public String toString() { diff --git a/app/src/main/java/it/niedermann/owncloud/notes/shared/model/IResponseCallback.java b/app/src/main/java/it/niedermann/owncloud/notes/shared/model/IResponseCallback.java index 2c329727..707931b0 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/shared/model/IResponseCallback.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/shared/model/IResponseCallback.java @@ -2,8 +2,8 @@ package it.niedermann.owncloud.notes.shared.model; import androidx.annotation.NonNull; -public interface IResponseCallback { - void onSuccess(); +public interface IResponseCallback<T> { + void onSuccess(T result); void onError(@NonNull Throwable t); } diff --git a/app/src/main/java/it/niedermann/owncloud/notes/shared/model/NotesSettings.java b/app/src/main/java/it/niedermann/owncloud/notes/shared/model/NotesSettings.java new file mode 100644 index 00000000..ff11434f --- /dev/null +++ b/app/src/main/java/it/niedermann/owncloud/notes/shared/model/NotesSettings.java @@ -0,0 +1,34 @@ +package it.niedermann.owncloud.notes.shared.model; + +import androidx.annotation.Nullable; + +public class NotesSettings { + + @Nullable + private String notesPath; + @Nullable + private String fileSuffix; + + public NotesSettings(@Nullable String notesPath, @Nullable String fileSuffix) { + this.notesPath = notesPath; + this.fileSuffix = fileSuffix; + } + + @Nullable + public String getNotesPath() { + return notesPath; + } + + public void setNotesPath(@Nullable String notesPath) { + this.notesPath = notesPath; + } + + @Nullable + public String getFileSuffix() { + return fileSuffix; + } + + public void setFileSuffix(@Nullable String fileSuffix) { + this.fileSuffix = fileSuffix; + } +} diff --git a/app/src/main/java/it/niedermann/owncloud/notes/shared/model/ServerResponse.java b/app/src/main/java/it/niedermann/owncloud/notes/shared/model/ServerResponse.java deleted file mode 100644 index dca53fb9..00000000 --- a/app/src/main/java/it/niedermann/owncloud/notes/shared/model/ServerResponse.java +++ /dev/null @@ -1,103 +0,0 @@ -package it.niedermann.owncloud.notes.shared.model; - -import androidx.annotation.Nullable; - -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - -import java.util.ArrayList; -import java.util.Calendar; -import java.util.List; - -import it.niedermann.owncloud.notes.persistence.NotesClient; -import it.niedermann.owncloud.notes.persistence.entity.Note; - -/** - * Provides entity classes for handling server responses with a single note ({@link NoteResponse}) or a list of notes ({@link NotesResponse}). - */ -public class ServerResponse { - - public static class NoteResponse extends ServerResponse { - public NoteResponse(NotesClient.ResponseData response) { - super(response); - } - - public Note getNote() throws JSONException { - return getNoteFromJSON(new JSONObject(getContent())); - } - } - - public static class NotesResponse extends ServerResponse { - public NotesResponse(NotesClient.ResponseData response) { - super(response); - } - - public List<Note> getNotes() throws JSONException { - List<Note> notesList = new ArrayList<>(); - JSONArray notes = new JSONArray(getContent()); - for (int i = 0; i < notes.length(); i++) { - JSONObject json = notes.getJSONObject(i); - notesList.add(getNoteFromJSON(json)); - } - return notesList; - } - } - - - private final NotesClient.ResponseData response; - - ServerResponse(NotesClient.ResponseData response) { - this.response = response; - } - - protected String getContent() { - return response == null ? null : response.getContent(); - } - - public String getETag() { - return response.getETag(); - } - - public Calendar getLastModified() { - return response.getLastModified(); - } - - @Nullable - public String getSupportedApiVersions() { - return response.getSupportedApiVersions(); - } - - Note getNoteFromJSON(JSONObject json) throws JSONException { - long remoteId = 0; - String title = ""; - String content = ""; - Calendar modified = null; - boolean favorite = false; - String category = ""; - String etag = null; - if (!json.isNull(NotesClient.JSON_ID)) { - remoteId = json.getLong(NotesClient.JSON_ID); - } - if (!json.isNull(NotesClient.JSON_TITLE)) { - title = json.getString(NotesClient.JSON_TITLE); - } - if (!json.isNull(NotesClient.JSON_CONTENT)) { - content = json.getString(NotesClient.JSON_CONTENT); - } - if (!json.isNull(NotesClient.JSON_MODIFIED)) { - modified = Calendar.getInstance(); - modified.setTimeInMillis(json.getLong(NotesClient.JSON_MODIFIED) * 1_000); - } - if (!json.isNull(NotesClient.JSON_FAVORITE)) { - favorite = json.getBoolean(NotesClient.JSON_FAVORITE); - } - if (!json.isNull(NotesClient.JSON_CATEGORY)) { - category = json.getString(NotesClient.JSON_CATEGORY); - } - if (!json.isNull(NotesClient.JSON_ETAG)) { - etag = json.getString(NotesClient.JSON_ETAG); - } - return new Note(remoteId, modified, title, content, category, favorite, etag); - } -} diff --git a/app/src/main/java/it/niedermann/owncloud/notes/shared/model/ServerSettings.java b/app/src/main/java/it/niedermann/owncloud/notes/shared/model/ServerSettings.java deleted file mode 100644 index e977b697..00000000 --- a/app/src/main/java/it/niedermann/owncloud/notes/shared/model/ServerSettings.java +++ /dev/null @@ -1,47 +0,0 @@ -package it.niedermann.owncloud.notes.shared.model; - -import org.json.JSONException; -import org.json.JSONObject; - -import java.io.Serializable; - -import static it.niedermann.owncloud.notes.persistence.NotesClient.JSON_SETTINGS_FILE_SUFFIX; -import static it.niedermann.owncloud.notes.persistence.NotesClient.JSON_SETTINGS_NOTES_PATH; - -public class ServerSettings implements Serializable { - private String notesPath = ""; - private String fileSuffix = ""; - - public ServerSettings(String notesPath, String fileSuffix) { - setNotesPath(notesPath); - setFileSuffix(fileSuffix); - } - - public static ServerSettings from(JSONObject settings) throws JSONException { - String notesPath = ""; - if (settings.has(JSON_SETTINGS_NOTES_PATH)) { - notesPath = settings.getString(JSON_SETTINGS_NOTES_PATH); - } - String fileSuffix = ""; - if (settings.has(JSON_SETTINGS_FILE_SUFFIX)) { - fileSuffix = settings.getString(JSON_SETTINGS_FILE_SUFFIX); - } - return new ServerSettings(notesPath, fileSuffix); - } - - public String getNotesPath() { - return notesPath; - } - - public void setNotesPath(String notesPath) { - this.notesPath = notesPath; - } - - public String getFileSuffix() { - return fileSuffix; - } - - public void setFileSuffix(String fileSuffix) { - this.fileSuffix = fileSuffix; - } -}
\ No newline at end of file diff --git a/app/src/main/java/it/niedermann/owncloud/notes/shared/model/SyncResultStatus.java b/app/src/main/java/it/niedermann/owncloud/notes/shared/model/SyncResultStatus.java index 2031568b..41ba850a 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/shared/model/SyncResultStatus.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/shared/model/SyncResultStatus.java @@ -3,4 +3,11 @@ package it.niedermann.owncloud.notes.shared.model; public class SyncResultStatus { public boolean pullSuccessful = true; public boolean pushSuccessful = true; + + public static final SyncResultStatus FAILED = new SyncResultStatus(); + + static { + FAILED.pullSuccessful = false; + FAILED.pushSuccessful = false; + } } |