diff options
author | Stefan Niedermann <info@niedermann.it> | 2021-04-22 11:22:11 +0300 |
---|---|---|
committer | Stefan Niedermann <info@niedermann.it> | 2021-04-22 11:26:53 +0300 |
commit | e3c4c1cb40ba229f50dd534c9edef42cb807ed18 (patch) | |
tree | d77940487f9f0714d6f44561d929f6e20d3e3d1d /app/src/main/java/it/niedermann/owncloud/notes/shared | |
parent | a5a84360bea5a9d4d7c755200ce87a8888cfbb2d (diff) | |
parent | c6eed04bfdd3c6d3a8276584239e626b888d7f52 (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/ManageAccountViewHolder.java
# app/src/main/java/it/niedermann/owncloud/notes/manageaccounts/ManageAccountsActivity.java
# app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesClientV1.java
Diffstat (limited to 'app/src/main/java/it/niedermann/owncloud/notes/shared')
18 files changed, 235 insertions, 428 deletions
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/shared/account/AccountChooserAdapter.java b/app/src/main/java/it/niedermann/owncloud/notes/shared/account/AccountChooserAdapter.java index dd28f431..6804ee62 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/shared/account/AccountChooserAdapter.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/shared/account/AccountChooserAdapter.java @@ -10,16 +10,16 @@ import androidx.recyclerview.widget.RecyclerView; import java.util.List; import it.niedermann.owncloud.notes.databinding.ItemAccountChooseBinding; -import it.niedermann.owncloud.notes.shared.model.LocalAccount; +import it.niedermann.owncloud.notes.persistence.entity.Account; public class AccountChooserAdapter extends RecyclerView.Adapter<AccountChooserViewHolder> { @NonNull - private final List<LocalAccount> localAccounts; + private final List<Account> localAccounts; @NonNull - private final Consumer<LocalAccount> targetAccountConsumer; + private final Consumer<Account> targetAccountConsumer; - public AccountChooserAdapter(@NonNull List<LocalAccount> localAccounts, @NonNull Consumer<LocalAccount> targetAccountConsumer) { + public AccountChooserAdapter(@NonNull List<Account> localAccounts, @NonNull Consumer<Account> targetAccountConsumer) { super(); this.localAccounts = localAccounts; this.targetAccountConsumer = targetAccountConsumer; diff --git a/app/src/main/java/it/niedermann/owncloud/notes/shared/account/AccountChooserViewHolder.java b/app/src/main/java/it/niedermann/owncloud/notes/shared/account/AccountChooserViewHolder.java index 143adabc..7688b1b1 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/shared/account/AccountChooserViewHolder.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/shared/account/AccountChooserViewHolder.java @@ -11,7 +11,7 @@ import com.bumptech.glide.request.RequestOptions; import it.niedermann.nextcloud.sso.glide.SingleSignOnUrl; import it.niedermann.owncloud.notes.R; import it.niedermann.owncloud.notes.databinding.ItemAccountChooseBinding; -import it.niedermann.owncloud.notes.shared.model.LocalAccount; +import it.niedermann.owncloud.notes.persistence.entity.Account; public class AccountChooserViewHolder extends RecyclerView.ViewHolder { private final ItemAccountChooseBinding binding; @@ -21,7 +21,7 @@ public class AccountChooserViewHolder extends RecyclerView.ViewHolder { this.binding = binding; } - public void bind(LocalAccount localAccount, Consumer<LocalAccount> targetAccountConsumer) { + public void bind(Account localAccount, Consumer<Account> targetAccountConsumer) { Glide .with(binding.accountItemAvatar.getContext()) .load(new SingleSignOnUrl(localAccount.getAccountName(), localAccount.getUrl() + "/index.php/avatar/" + Uri.encode(localAccount.getUserName()) + "/64")) 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 b182ca63..1c1bed3d 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 @@ -1,7 +1,9 @@ package it.niedermann.owncloud.notes.shared.model; +import android.graphics.Color; import android.util.Log; +import androidx.annotation.ColorInt; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -11,10 +13,12 @@ import com.nextcloud.android.sso.exceptions.NextcloudHttpRequestFailedException; import org.json.JSONException; import org.json.JSONObject; +import it.niedermann.android.util.ColorUtil; + import static java.net.HttpURLConnection.HTTP_UNAVAILABLE; /** - * This entity class is used to return relevant data of the HTTP reponse. + * This entity class is used to return relevant data of the HTTP response. */ public class Capabilities { @@ -32,10 +36,13 @@ public class Capabilities { private static final String JSON_OCS_DATA_CAPABILITIES_THEMING_COLOR_TEXT = "color-text"; private String apiVersion = null; - private String color = null; - private String textColor = null; + + @ColorInt + private Integer color = -16743735; + @ColorInt + private Integer textColor = -16777216; @Nullable - private String eTag; + private final String eTag; public Capabilities(@NonNull String response, @Nullable String eTag) throws NextcloudHttpRequestFailedException { this.eTag = eTag; @@ -64,10 +71,18 @@ public class Capabilities { if (capabilities.has(JSON_OCS_DATA_CAPABILITIES_THEMING)) { final JSONObject theming = capabilities.getJSONObject(JSON_OCS_DATA_CAPABILITIES_THEMING); if (theming.has(JSON_OCS_DATA_CAPABILITIES_THEMING_COLOR)) { - this.color = theming.getString(JSON_OCS_DATA_CAPABILITIES_THEMING_COLOR); + try { + this.color = Color.parseColor(ColorUtil.INSTANCE.formatColorToParsableHexString(theming.getString(JSON_OCS_DATA_CAPABILITIES_THEMING_COLOR))); + } catch (Exception e) { + e.printStackTrace(); + } } if (theming.has(JSON_OCS_DATA_CAPABILITIES_THEMING_COLOR_TEXT)) { - this.textColor = theming.getString(JSON_OCS_DATA_CAPABILITIES_THEMING_COLOR_TEXT); + try { + this.textColor = Color.parseColor(ColorUtil.INSTANCE.formatColorToParsableHexString(theming.getString(JSON_OCS_DATA_CAPABILITIES_THEMING_COLOR_TEXT))); + } catch (Exception e) { + e.printStackTrace(); + } } } } @@ -81,17 +96,17 @@ public class Capabilities { return apiVersion; } - public String getColor() { - return color; + @Nullable + public String getETag() { + return eTag; } - public String getTextColor() { - return textColor; + public Integer getColor() { + return color; } - @Nullable - public String getETag() { - return eTag; + public Integer getTextColor() { + return textColor; } @NonNull @@ -99,8 +114,9 @@ public class Capabilities { public String toString() { return "Capabilities{" + "apiVersion='" + apiVersion + '\'' + - ", color='" + color + '\'' + - ", textColor='" + textColor + '\'' + + ", color=" + color + + ", textColor=" + textColor + + ", eTag='" + eTag + '\'' + '}'; } }
\ No newline at end of file diff --git a/app/src/main/java/it/niedermann/owncloud/notes/shared/model/Category.java b/app/src/main/java/it/niedermann/owncloud/notes/shared/model/Category.java deleted file mode 100644 index ab1d10a1..00000000 --- a/app/src/main/java/it/niedermann/owncloud/notes/shared/model/Category.java +++ /dev/null @@ -1,18 +0,0 @@ -package it.niedermann.owncloud.notes.shared.model; - -import androidx.annotation.Nullable; - -import java.io.Serializable; - -public class Category implements Serializable { - - @Nullable - public final String category; - @Nullable - public final Boolean favorite; - - public Category(@Nullable String category, @Nullable Boolean favorite) { - this.category = category; - this.favorite = favorite; - } -} diff --git a/app/src/main/java/it/niedermann/owncloud/notes/shared/model/CategorySortingMethod.java b/app/src/main/java/it/niedermann/owncloud/notes/shared/model/CategorySortingMethod.java index 35ab8b66..94bcda38 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/shared/model/CategorySortingMethod.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/shared/model/CategorySortingMethod.java @@ -1,41 +1,48 @@ package it.niedermann.owncloud.notes.shared.model; public enum CategorySortingMethod { - SORT_MODIFIED_DESC("MODIFIED DESC"), - SORT_LEXICOGRAPHICAL_ASC("TITLE COLLATE NOCASE ASC"); + SORT_MODIFIED_DESC(0, "MODIFIED DESC"), + SORT_LEXICOGRAPHICAL_ASC(1, "TITLE COLLATE NOCASE ASC"); - private String sorder; // sorting method OrderBy for SQL + private final int id; + private final String title; // sorting method OrderBy for SQL /*** * Constructor - * @param orderby given sorting method OrderBy + * @param title given sorting method OrderBy */ - CategorySortingMethod(String orderby) { - this.sorder = orderby; + CategorySortingMethod(int id, String title) { + this.id = id; + this.title = title; } /*** * Retrieve the sorting method id represented in database * @return the sorting method id for the enum item */ - public int getCSMID() { - return this.ordinal(); + public int getId() { + return this.id; } /*** * Retrieve the sorting method order for SQL * @return the sorting method order for the enum item */ - public String getSorder() { - return this.sorder; + public String getTitle() { + return this.title; } /*** * Retrieve the corresponding enum value with given the index (ordinal) - * @param index the index / ordinal of the corresponding enum value stored in DB + * @param id the id of the corresponding enum value stored in DB * @return the corresponding enum item with the index (ordinal) */ - public static CategorySortingMethod getCSM(int index) { - return CategorySortingMethod.values()[index]; + public static CategorySortingMethod findById(int id) { + for (CategorySortingMethod csm : values()) { + if (csm.getId() == id) { + return csm; + } + } + return SORT_MODIFIED_DESC; } } diff --git a/app/src/main/java/it/niedermann/owncloud/notes/shared/model/CloudNote.java b/app/src/main/java/it/niedermann/owncloud/notes/shared/model/CloudNote.java deleted file mode 100644 index e194b11e..00000000 --- a/app/src/main/java/it/niedermann/owncloud/notes/shared/model/CloudNote.java +++ /dev/null @@ -1,104 +0,0 @@ -package it.niedermann.owncloud.notes.shared.model; - -import androidx.annotation.NonNull; - -import java.io.Serializable; -import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.Locale; - -import it.niedermann.android.markdown.MarkdownUtil; -import it.niedermann.owncloud.notes.shared.util.NoteUtil; - -/** - * CloudNote represents a remote note from an OwnCloud server. - * It can be directly generated from the JSON answer from the server. - */ -public class CloudNote implements Serializable { - private long remoteId; - private String title = ""; - private Calendar modified; - private String content = ""; - private boolean favorite = false; - private String category = ""; - private String etag = ""; - private static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss"; - - public CloudNote(long remoteId, Calendar modified, String title, String content, boolean favorite, String category, String etag) { - this.remoteId = remoteId; - setTitle(title); - setContent(content); - setFavorite(favorite); - setCategory(category); - setEtag(etag); - this.modified = modified; - } - - public long getRemoteId() { - return remoteId; - } - - public void setRemoteId(long remoteId) { - this.remoteId = remoteId; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = MarkdownUtil.removeMarkdown(title); - } - - public Calendar getModified() { - return modified; - } - - public String getModified(String format) { - if (modified == null) - return null; - return new SimpleDateFormat(format, Locale.GERMANY).format(this.getModified().getTimeInMillis()); - } - - public void setModified(Calendar modified) { - this.modified = modified; - } - - public String getContent() { - return content; - } - - public void setContent(String content) { - this.content = content; - } - - public boolean isFavorite() { - return favorite; - } - - public void setFavorite(boolean favorite) { - this.favorite = favorite; - } - - public String getEtag() { - return etag; - } - - public void setEtag(String etag) { - this.etag = etag; - } - - public String getCategory() { - return category; - } - - public void setCategory(String category) { - this.category = category == null ? "" : category; - } - - @NonNull - @Override - public String toString() { - return "R" + getRemoteId() + " " + (isFavorite() ? " (*) " : " ") + getCategory() + " / " + getTitle() + " (" + getModified(DATE_FORMAT) + " / " + getEtag() + ")"; - } -}
\ No newline at end of file diff --git a/app/src/main/java/it/niedermann/owncloud/notes/shared/model/DBNote.java b/app/src/main/java/it/niedermann/owncloud/notes/shared/model/DBNote.java deleted file mode 100644 index 059a1ce3..00000000 --- a/app/src/main/java/it/niedermann/owncloud/notes/shared/model/DBNote.java +++ /dev/null @@ -1,80 +0,0 @@ -package it.niedermann.owncloud.notes.shared.model; - -import androidx.annotation.NonNull; - -import java.io.Serializable; -import java.util.Calendar; - -/** - * DBNote represents a single note from the local SQLite database with all attributes. - * It extends CloudNote with attributes required for local data management. - */ -public class DBNote extends CloudNote implements Item, Serializable { - - private final long id; - private final long accountId; - private DBStatus status; - private String excerpt; - private int scrollY; - - public DBNote(long id, long remoteId, Calendar modified, String title, String content, boolean favorite, String category, String etag, DBStatus status, long accountId, String excerpt, int scrollY) { - super(remoteId, modified, title, content, favorite, category, etag); - this.id = id; - this.excerpt = excerpt; - this.status = status; - this.accountId = accountId; - this.scrollY = scrollY; - } - - public long getId() { - return id; - } - - public long getAccountId() { - return accountId; - } - - public DBStatus getStatus() { - return status; - } - - public void setStatus(DBStatus status) { - this.status = status; - } - - public String getExcerpt() { - return excerpt; - } - - public void setExcerpt(String excerpt) { - this.excerpt = excerpt; - } - - public void setContent(String content) { - super.setContent(content); - } - - @Override - public boolean isSection() { - return false; - } - - @NonNull - @Override - public String toString() { - return "DBNote{" + - "id=" + id + - ", accountId=" + accountId + - ", status=" + status + - ", excerpt='" + excerpt + '\'' + - '}'; - } - - public int getScrollY() { - return scrollY; - } - - public void setScrollY(int scrollY) { - this.scrollY = scrollY; - } -} diff --git a/app/src/main/java/it/niedermann/owncloud/notes/shared/model/DBStatus.java b/app/src/main/java/it/niedermann/owncloud/notes/shared/model/DBStatus.java index 4b7e61e4..ef06a277 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/shared/model/DBStatus.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/shared/model/DBStatus.java @@ -1,5 +1,7 @@ package it.niedermann.owncloud.notes.shared.model; +import androidx.annotation.NonNull; + /** * Helps to distinguish between different local change types for Server Synchronization. * Created by stefan on 19.09.15. @@ -24,27 +26,15 @@ public enum DBStatus { */ LOCAL_DELETED("LOCAL_DELETED"); + @NonNull private final String title; + @NonNull public String getTitle() { return title; } - DBStatus(String title) { + DBStatus(@NonNull String title) { this.title = title; } - - /** - * Parse a String an get the appropriate DBStatus enum element. - * - * @param str The String containing the DBStatus identifier. Must not null. - * @return The DBStatus fitting to the String. - */ - public static DBStatus parse(String str) { - if (str.isEmpty()) { - return DBStatus.VOID; - } else { - return DBStatus.valueOf(str); - } - } } diff --git a/app/src/main/java/it/niedermann/owncloud/notes/shared/model/ENavigationCategoryType.java b/app/src/main/java/it/niedermann/owncloud/notes/shared/model/ENavigationCategoryType.java new file mode 100644 index 00000000..871a12d4 --- /dev/null +++ b/app/src/main/java/it/niedermann/owncloud/notes/shared/model/ENavigationCategoryType.java @@ -0,0 +1,10 @@ +package it.niedermann.owncloud.notes.shared.model; + +import java.io.Serializable; + +public enum ENavigationCategoryType implements Serializable { + RECENT, + FAVORITES, + UNCATEGORIZED, + DEFAULT_CATEGORY +} 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 new file mode 100644 index 00000000..2c329727 --- /dev/null +++ b/app/src/main/java/it/niedermann/owncloud/notes/shared/model/IResponseCallback.java @@ -0,0 +1,9 @@ +package it.niedermann.owncloud.notes.shared.model; + +import androidx.annotation.NonNull; + +public interface IResponseCallback { + void onSuccess(); + + void onError(@NonNull Throwable t); +} diff --git a/app/src/main/java/it/niedermann/owncloud/notes/shared/model/Item.java b/app/src/main/java/it/niedermann/owncloud/notes/shared/model/Item.java index 362bc390..234acb91 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/shared/model/Item.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/shared/model/Item.java @@ -1,5 +1,7 @@ package it.niedermann.owncloud.notes.shared.model; public interface Item { - boolean isSection(); + default boolean isSection() { + return false; + } } diff --git a/app/src/main/java/it/niedermann/owncloud/notes/shared/model/LocalAccount.java b/app/src/main/java/it/niedermann/owncloud/notes/shared/model/LocalAccount.java deleted file mode 100644 index aaafd750..00000000 --- a/app/src/main/java/it/niedermann/owncloud/notes/shared/model/LocalAccount.java +++ /dev/null @@ -1,155 +0,0 @@ -package it.niedermann.owncloud.notes.shared.model; - - -import androidx.annotation.ColorInt; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - -import org.json.JSONArray; -import org.json.JSONException; - -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.NoSuchElementException; - -import it.niedermann.owncloud.notes.persistence.NotesClient; - -public class LocalAccount { - - private long id; - private String userName; - private String accountName; - private String url; - private String etag; - private String capabilitiesETag; - private long modified; - @Nullable - private ApiVersion preferredApiVersion; - @ColorInt - private int color; - @ColorInt - private int textColor; - - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } - - public String getUserName() { - return userName; - } - - public void setUserName(String userName) { - this.userName = userName; - } - - public String getUrl() { - return url; - } - - public void setUrl(String url) { - this.url = url; - } - - public String getEtag() { - return etag; - } - - public void setETag(String etag) { - this.etag = etag; - } - - public String getAccountName() { - return accountName; - } - - public void setAccountName(String accountName) { - this.accountName = accountName; - } - - public long getModified() { - return modified; - } - - public void setModified(long modified) { - this.modified = modified; - } - - @Nullable - public ApiVersion getPreferredApiVersion() { - return preferredApiVersion; - } - - public String getCapabilitiesETag() { - return capabilitiesETag; - } - - public void setCapabilitiesETag(String capabilitiesETag) { - this.capabilitiesETag = capabilitiesETag; - } - - /** - * @param availableApiVersions <code>["0.2", "1.0", ...]</code> - */ - public void setPreferredApiVersion(@Nullable String availableApiVersions) { - // TODO move this logic to NotesClient? - try { - if (availableApiVersions == null) { - this.preferredApiVersion = null; - return; - } - JSONArray versionsArray = new JSONArray(availableApiVersions); - Collection<ApiVersion> 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) { - if (temp.compareTo(parsedApiVersion) == 0) { - supportedApiVersions.add(parsedApiVersion); - break; - } - } - } - this.preferredApiVersion = Collections.max(supportedApiVersions); - } catch (JSONException | NoSuchElementException e) { - e.printStackTrace(); - this.preferredApiVersion = null; - } - } - - public int getColor() { - return color; - } - - 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() { - return "LocalAccount{" + - "id=" + id + - ", userName='" + userName + '\'' + - ", accountName='" + accountName + '\'' + - ", url='" + url + '\'' + - ", etag='" + etag + '\'' + - ", modified=" + modified + - ", preferredApiVersion='" + preferredApiVersion + '\'' + - ", color=" + color + - ", textColor=" + textColor + - ", capabilitiesETag=" + capabilitiesETag + - '}'; - } -} diff --git a/app/src/main/java/it/niedermann/owncloud/notes/shared/model/NavigationCategory.java b/app/src/main/java/it/niedermann/owncloud/notes/shared/model/NavigationCategory.java new file mode 100644 index 00000000..52a3a117 --- /dev/null +++ b/app/src/main/java/it/niedermann/owncloud/notes/shared/model/NavigationCategory.java @@ -0,0 +1,76 @@ +package it.niedermann.owncloud.notes.shared.model; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import java.io.Serializable; + +import static it.niedermann.owncloud.notes.shared.model.ENavigationCategoryType.DEFAULT_CATEGORY; + +public class NavigationCategory implements Serializable { + + @NonNull + private final ENavigationCategoryType type; + @Nullable + private final String category; + private final long accountId; + + public NavigationCategory(@NonNull ENavigationCategoryType type) { + if (type == DEFAULT_CATEGORY) { + throw new IllegalArgumentException("If you want to provide a " + DEFAULT_CATEGORY + ", call the constructor with an accountId and category as arguments"); + } + this.type = type; + this.category = null; + this.accountId = Long.MIN_VALUE; + } + + public NavigationCategory(long accountId, @Nullable String category) { + this.type = DEFAULT_CATEGORY; + this.category = category; + this.accountId = accountId; + } + + @NonNull + public ENavigationCategoryType getType() { + return type; + } + + public long getAccountId() { + return accountId; + } + + @Nullable + public String getCategory() { + return category; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof NavigationCategory)) return false; + + NavigationCategory that = (NavigationCategory) o; + + if (accountId != that.accountId) return false; + if (type != that.type) return false; + return category != null ? category.equals(that.category) : that.category == null; + } + + @Override + public int hashCode() { + int result = type.hashCode(); + result = 31 * result + (category != null ? category.hashCode() : 0); + result = 31 * result + (int) (accountId ^ (accountId >>> 32)); + return result; + } + + @NonNull + @Override + public String toString() { + return "NavigationCategory{" + + "type=" + type + + ", category='" + category + '\'' + + ", accountId=" + accountId + + '}'; + } +} diff --git a/app/src/main/java/it/niedermann/owncloud/notes/shared/model/NoteClickListener.java b/app/src/main/java/it/niedermann/owncloud/notes/shared/model/NoteClickListener.java index 7194752c..e34c005b 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/shared/model/NoteClickListener.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/shared/model/NoteClickListener.java @@ -6,6 +6,4 @@ public interface NoteClickListener { void onNoteClick(int position, View v); void onNoteFavoriteClick(int position, View v); - - boolean onNoteLongClick(int position, View v); }
\ No newline at end of file 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 index 9f34b907..dca53fb9 100644 --- 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 @@ -8,10 +8,10 @@ import org.json.JSONObject; import java.util.ArrayList; import java.util.Calendar; -import java.util.GregorianCalendar; 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}). @@ -23,7 +23,7 @@ public class ServerResponse { super(response); } - public CloudNote getNote() throws JSONException { + public Note getNote() throws JSONException { return getNoteFromJSON(new JSONObject(getContent())); } } @@ -33,8 +33,8 @@ public class ServerResponse { super(response); } - public List<CloudNote> getNotes() throws JSONException { - List<CloudNote> notesList = new ArrayList<>(); + 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); @@ -59,7 +59,7 @@ public class ServerResponse { return response.getETag(); } - public long getLastModified() { + public Calendar getLastModified() { return response.getLastModified(); } @@ -68,16 +68,16 @@ public class ServerResponse { return response.getSupportedApiVersions(); } - CloudNote getNoteFromJSON(JSONObject json) throws JSONException { - long id = 0; + Note getNoteFromJSON(JSONObject json) throws JSONException { + long remoteId = 0; String title = ""; String content = ""; Calendar modified = null; boolean favorite = false; - String category = null; + String category = ""; String etag = null; if (!json.isNull(NotesClient.JSON_ID)) { - id = json.getLong(NotesClient.JSON_ID); + remoteId = json.getLong(NotesClient.JSON_ID); } if (!json.isNull(NotesClient.JSON_TITLE)) { title = json.getString(NotesClient.JSON_TITLE); @@ -86,8 +86,8 @@ public class ServerResponse { content = json.getString(NotesClient.JSON_CONTENT); } if (!json.isNull(NotesClient.JSON_MODIFIED)) { - modified = GregorianCalendar.getInstance(); - modified.setTimeInMillis(json.getLong(NotesClient.JSON_MODIFIED) * 1000); + modified = Calendar.getInstance(); + modified.setTimeInMillis(json.getLong(NotesClient.JSON_MODIFIED) * 1_000); } if (!json.isNull(NotesClient.JSON_FAVORITE)) { favorite = json.getBoolean(NotesClient.JSON_FAVORITE); @@ -98,6 +98,6 @@ public class ServerResponse { if (!json.isNull(NotesClient.JSON_ETAG)) { etag = json.getString(NotesClient.JSON_ETAG); } - return new CloudNote(id, modified, title, content, favorite, category, etag); + return new Note(remoteId, modified, title, content, category, favorite, etag); } } diff --git a/app/src/main/java/it/niedermann/owncloud/notes/shared/util/DatabaseIndexUtil.java b/app/src/main/java/it/niedermann/owncloud/notes/shared/util/DatabaseIndexUtil.java index 235711ef..8506c713 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/shared/util/DatabaseIndexUtil.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/shared/util/DatabaseIndexUtil.java @@ -5,6 +5,7 @@ import android.database.sqlite.SQLiteDatabase; import android.util.Log; import androidx.annotation.NonNull; +import androidx.sqlite.db.SupportSQLiteDatabase; public class DatabaseIndexUtil { @@ -14,20 +15,20 @@ public class DatabaseIndexUtil { } - public static void createIndex(@NonNull SQLiteDatabase db, @NonNull String table, @NonNull String ...columns) { - for (String column: columns) { + public static void createIndex(@NonNull SupportSQLiteDatabase db, @NonNull String table, @NonNull String... columns) { + for (String column : columns) { createIndex(db, table, column); } } - public static void createIndex(@NonNull SQLiteDatabase db, @NonNull String table, @NonNull String column) { + public static void createIndex(@NonNull SupportSQLiteDatabase db, @NonNull String table, @NonNull String column) { String indexName = table + "_" + column + "_idx"; Log.v(TAG, "Creating database index: CREATE INDEX IF NOT EXISTS " + indexName + " ON " + table + "(" + column + ")"); - db.execSQL("CREATE INDEX IF NOT EXISTS " + indexName + " ON " + table + "(" + column + ")"); + db.execSQL("CREATE INDEX " + indexName + " ON " + table + "(" + column + ")"); } - public static void dropIndexes(@NonNull SQLiteDatabase db) { - try (Cursor c = db.query("sqlite_master", new String[]{"name", "sql"}, "type=?", new String[]{"index"}, null, null, null)) { + public static void dropIndexes(@NonNull SupportSQLiteDatabase db) { + try (Cursor c = db.query("SELECT name, sql FROM sqlite_master WHERE type = 'index'")) { while (c.moveToNext()) { // Skip automatic indexes which we can't drop manually if (c.getString(1) != null) { diff --git a/app/src/main/java/it/niedermann/owncloud/notes/shared/util/DisplayUtils.java b/app/src/main/java/it/niedermann/owncloud/notes/shared/util/DisplayUtils.java new file mode 100644 index 00000000..ad6b6793 --- /dev/null +++ b/app/src/main/java/it/niedermann/owncloud/notes/shared/util/DisplayUtils.java @@ -0,0 +1,55 @@ +package it.niedermann.owncloud.notes.shared.util; + +import android.content.Context; +import android.content.res.Resources; +import android.graphics.Color; +import android.text.Spannable; +import android.text.TextPaint; +import android.text.TextUtils; +import android.text.style.MetricAffectingSpan; + +import androidx.annotation.ColorInt; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.core.content.ContextCompat; + +import java.util.Collection; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Collectors; + +import it.niedermann.android.util.ColorUtil; +import it.niedermann.owncloud.notes.NotesApplication; +import it.niedermann.owncloud.notes.R; +import it.niedermann.owncloud.notes.branding.BrandingUtil; +import it.niedermann.owncloud.notes.main.navigation.NavigationAdapter; +import it.niedermann.owncloud.notes.main.navigation.NavigationItem; +import it.niedermann.owncloud.notes.persistence.entity.CategoryWithNotesCount; + +public class DisplayUtils { + + private DisplayUtils() { + + } + + public static List<NavigationItem.CategoryNavigationItem> convertToCategoryNavigationItem(@NonNull Context context, @NonNull Collection<CategoryWithNotesCount> counter) { + return counter.stream() + .map(ctr -> convertToCategoryNavigationItem(context, ctr)) + .collect(Collectors.toList()); + } + + public static NavigationItem.CategoryNavigationItem convertToCategoryNavigationItem(@NonNull Context context, @NonNull CategoryWithNotesCount counter) { + Resources res = context.getResources(); + String category = counter.getCategory().toLowerCase(); + int icon = NavigationAdapter.ICON_FOLDER; + if (category.equals(res.getString(R.string.category_music).toLowerCase())) { + icon = R.drawable.ic_library_music_grey600_24dp; + } else if (category.equals(res.getString(R.string.category_movies).toLowerCase()) || category.equals(res.getString(R.string.category_movie).toLowerCase())) { + icon = R.drawable.ic_local_movies_grey600_24dp; + } else if (category.equals(res.getString(R.string.category_work).toLowerCase())) { + icon = R.drawable.ic_work_grey600_24dp; + } + return new NavigationItem.CategoryNavigationItem("category:" + counter.getCategory(), counter.getCategory(), counter.getTotalNotes(), icon, counter.getAccountId(), counter.getCategory()); + } +} diff --git a/app/src/main/java/it/niedermann/owncloud/notes/shared/util/NoteUtil.java b/app/src/main/java/it/niedermann/owncloud/notes/shared/util/NoteUtil.java index 456b85bb..e5b8afae 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/shared/util/NoteUtil.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/shared/util/NoteUtil.java @@ -65,7 +65,7 @@ public class NoteUtil { @NonNull public static String generateNoteExcerpt(@NonNull String content, @Nullable String title) { content = removeMarkdown(replaceCheckboxesWithEmojis(content.trim())); - if(TextUtils.isEmpty(content)) { + if (TextUtils.isEmpty(content)) { return ""; } if (!TextUtils.isEmpty(title)) { |