diff options
author | Stefan Niedermann <info@niedermann.it> | 2020-12-09 19:59:07 +0300 |
---|---|---|
committer | Stefan Niedermann <info@niedermann.it> | 2020-12-09 19:59:07 +0300 |
commit | df900e53492c7b30cbb90b9180d6c3cdf59f38d9 (patch) | |
tree | b88dc0386e6b448c95cf4fcb46fbeaf8edc8780f /app/src/main/java/it/niedermann/nextcloud/deck/model | |
parent | 034ae108ae4ab4c273ef4d74f1bfd39fbc4d8a84 (diff) | |
parent | f29eed9db4c0906fa7887e446cf0325718ef6827 (diff) |
Merge branch 'master' into fastlanefastlane
# Conflicts:
# fastlane/metadata/android/en-US/images/phoneScreenshots/1.png
# fastlane/metadata/android/en-US/images/phoneScreenshots/2.png
# fastlane/metadata/android/en-US/images/phoneScreenshots/4.png
Diffstat (limited to 'app/src/main/java/it/niedermann/nextcloud/deck/model')
29 files changed, 1014 insertions, 203 deletions
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/model/AccessControl.java b/app/src/main/java/it/niedermann/nextcloud/deck/model/AccessControl.java index 299dd7ca0..e2a3ccc3b 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/model/AccessControl.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/model/AccessControl.java @@ -8,6 +8,7 @@ import androidx.room.Index; import com.google.gson.annotations.SerializedName; import it.niedermann.nextcloud.deck.model.interfaces.AbstractRemoteEntity; +import it.niedermann.nextcloud.deck.model.ocs.user.GroupMemberUIDs; @Entity(inheritSuperIndices = true, indices = { @@ -35,6 +36,8 @@ public class AccessControl extends AbstractRemoteEntity { @Ignore @SerializedName("participant") private User user; + @Ignore + private GroupMemberUIDs groupMemberUIDs; public AccessControl() { super(); @@ -115,6 +118,14 @@ public class AccessControl extends AbstractRemoteEntity { this.user = user; } + public GroupMemberUIDs getGroupMemberUIDs() { + return groupMemberUIDs; + } + + public void setGroupMemberUIDs(GroupMemberUIDs groupMemberUIDs) { + this.groupMemberUIDs = groupMemberUIDs; + } + @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/model/Account.java b/app/src/main/java/it/niedermann/nextcloud/deck/model/Account.java index ba8fb72b7..8abcbced7 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/model/Account.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/model/Account.java @@ -2,6 +2,7 @@ package it.niedermann.nextcloud.deck.model; import android.net.Uri; +import androidx.annotation.ColorInt; import androidx.annotation.NonNull; import androidx.annotation.Px; import androidx.room.ColumnInfo; @@ -18,7 +19,6 @@ import it.niedermann.nextcloud.deck.DeckLog; import it.niedermann.nextcloud.deck.model.ocs.Capabilities; import it.niedermann.nextcloud.deck.model.ocs.Version; import it.niedermann.nextcloud.deck.ui.accountswitcher.AccountSwitcherDialog; -import it.niedermann.nextcloud.deck.util.ColorUtil; @Entity(indices = {@Index(value = "name", unique = true)}) public class Account implements Serializable { @@ -38,12 +38,12 @@ public class Account implements Serializable { private String url; @NonNull - @ColumnInfo(defaultValue = "#0082c9") - private String color = "#0082c9"; + @ColumnInfo(defaultValue = "0") + private Integer color = 0; @NonNull - @ColumnInfo(defaultValue = "#ffffff") - private String textColor = "#ffffff"; + @ColumnInfo(defaultValue = "0") + private Integer textColor = 0; @NonNull @ColumnInfo(defaultValue = "0.6.4") @@ -53,6 +53,9 @@ public class Account implements Serializable { @ColumnInfo(defaultValue = "0") private boolean maintenanceEnabled = false; + private String etag; + private String boardsEtag; + @Ignore public Account(Long id, @NonNull String name, @NonNull String userName, @NonNull String url) { this(name, userName, url); @@ -60,7 +63,7 @@ public class Account implements Serializable { } @Ignore - public Account(String name, String userName, String url) { + public Account(@NonNull String name, @NonNull String userName, @NonNull String url) { this.name = name; this.userName = userName; this.url = url; @@ -74,22 +77,29 @@ public class Account implements Serializable { public Account() { } - public void applyCapabilities(Capabilities capabilities) { + public void applyCapabilities(Capabilities capabilities, String eTag) { + if (capabilities == null) { + maintenanceEnabled = true; + return; + } maintenanceEnabled = capabilities.isMaintenanceEnabled(); if (!isMaintenanceEnabled()) { try { // Nextcloud might return color format #000 which cannot be parsed by Color.parseColor() // https://github.com/stefan-niedermann/nextcloud-deck/issues/466 - color = ColorUtil.formatColorToParsableHexString(capabilities.getColor()); - textColor = ColorUtil.formatColorToParsableHexString(capabilities.getTextColor()); + color = capabilities.getColor(); + textColor = capabilities.getTextColor(); } catch (Exception e) { DeckLog.logError(e); - color = "#0082c9"; - color = "#ffffff"; + color = 0; + color = 0; } if (capabilities.getDeckVersion() != null) { serverDeckVersion = capabilities.getDeckVersion().getOriginalVersion(); } + if (eTag != null) { + this.etag = eTag; + } } } @@ -132,21 +142,23 @@ public class Account implements Serializable { return serialVersionUID; } + @ColorInt @NonNull - public String getColor() { + public Integer getColor() { return color; } - public void setColor(@NonNull String color) { + public void setColor(@NonNull Integer color) { this.color = color; } @NonNull - public String getTextColor() { + public Integer getTextColor() { return textColor; } - public void setTextColor(@NonNull String textColor) { + @Deprecated + public void setTextColor(@NonNull Integer textColor) { this.textColor = textColor; } @@ -171,6 +183,31 @@ public class Account implements Serializable { this.maintenanceEnabled = maintenanceEnabled; } + public String getEtag() { + return etag; + } + + public void setEtag(String etag) { + this.etag = etag; + } + + public String getBoardsEtag() { + return boardsEtag; + } + + public void setBoardsEtag(String boardsEtag) { + this.boardsEtag = boardsEtag; + } + + /** + * A cache buster parameter is added for duplicate account names on different hosts which shall be fetched from the same {@link SingleSignOnAccount} (e. g. {@link AccountSwitcherDialog}) + * + * @return an {@link String} to fetch the avatar for this account. + */ + public String getAvatarUrl(@Px int size) { + return getUrl() + "/index.php/avatar/" + Uri.encode(getUserName()) + "/" + size; + } + @Override public boolean equals(Object o) { if (this == o) return true; @@ -185,16 +222,8 @@ public class Account implements Serializable { if (!url.equals(account.url)) return false; if (!color.equals(account.color)) return false; if (!textColor.equals(account.textColor)) return false; - return serverDeckVersion.equals(account.serverDeckVersion); - } - - /** - * A cache buster parameter is added for duplicate account names on different hosts which shall be fetched from the same {@link SingleSignOnAccount} (e. g. {@link AccountSwitcherDialog}) - * - * @return an {@link String} to fetch the avatar for this account. - */ - public String getAvatarUrl(@Px int size) { - return getUrl() + "/index.php/avatar/" + Uri.encode(getUserName()) + "/" + size; + if (!serverDeckVersion.equals(account.serverDeckVersion)) return false; + return etag != null ? etag.equals(account.etag) : account.etag == null; } @Override @@ -207,6 +236,7 @@ public class Account implements Serializable { result = 31 * result + textColor.hashCode(); result = 31 * result + serverDeckVersion.hashCode(); result = 31 * result + (maintenanceEnabled ? 1 : 0); + result = 31 * result + (etag != null ? etag.hashCode() : 0); return result; } @@ -221,6 +251,7 @@ public class Account implements Serializable { ", textColor='" + textColor + '\'' + ", serverDeckVersion='" + serverDeckVersion + '\'' + ", maintenanceEnabled=" + maintenanceEnabled + + ", eTag='" + etag + '\'' + '}'; } } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/model/Attachment.java b/app/src/main/java/it/niedermann/nextcloud/deck/model/Attachment.java index 91192f597..7eabcbe70 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/model/Attachment.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/model/Attachment.java @@ -2,32 +2,33 @@ package it.niedermann.nextcloud.deck.model; import androidx.room.Entity; import androidx.room.ForeignKey; +import androidx.room.Ignore; import androidx.room.Index; import java.io.Serializable; -import java.util.Date; +import java.time.Instant; import it.niedermann.nextcloud.deck.model.interfaces.AbstractRemoteEntity; @Entity(inheritSuperIndices = true, indices = {@Index("cardId")}, foreignKeys = { - @ForeignKey( - entity = Card.class, - parentColumns = "localId", - childColumns = "cardId", - onDelete = ForeignKey.CASCADE - ) - } + @ForeignKey( + entity = Card.class, + parentColumns = "localId", + childColumns = "cardId", + onDelete = ForeignKey.CASCADE + ) + } ) public class Attachment extends AbstractRemoteEntity implements Comparable<Attachment>, Serializable { private long cardId; private String type = "deck_file"; private String data; - private Date createdAt; + private Instant createdAt; private String createdBy; - private Date deletedAt; + private Instant deletedAt; private long filesize; private String mimetype; private String dirname; @@ -35,6 +36,9 @@ public class Attachment extends AbstractRemoteEntity implements Comparable<Attac private String extension; private String filename; private String localPath; + // TODO should probably be a Long... depends on https://github.com/nextcloud/deck/pull/2638 + @Ignore + private String fileId; public long getCardId() { return cardId; @@ -60,11 +64,11 @@ public class Attachment extends AbstractRemoteEntity implements Comparable<Attac this.data = data; } - public Date getCreatedAt() { + public Instant getCreatedAt() { return createdAt; } - public void setCreatedAt(Date createdAt) { + public void setCreatedAt(Instant createdAt) { this.createdAt = createdAt; } @@ -76,11 +80,11 @@ public class Attachment extends AbstractRemoteEntity implements Comparable<Attac this.createdBy = createdBy; } - public Date getDeletedAt() { + public Instant getDeletedAt() { return deletedAt; } - public void setDeletedAt(Date deletedAt) { + public void setDeletedAt(Instant deletedAt) { this.deletedAt = deletedAt; } @@ -140,6 +144,22 @@ public class Attachment extends AbstractRemoteEntity implements Comparable<Attac this.localPath = localPath; } + /** + * TODO depends on https://github.com/nextcloud/deck/pull/2638 + */ + @Ignore + public String getFileId() { + return this.fileId; + } + + /** + * TODO depends on https://github.com/nextcloud/deck/pull/2638 + */ + @Ignore + public void setFileId(String fileId) { + this.fileId = fileId; + } + @Override public boolean equals(Object o) { if (this == o) return true; @@ -202,7 +222,7 @@ public class Attachment extends AbstractRemoteEntity implements Comparable<Attac private static int longToComparsionResult(long diff) { if (diff > 0) { return 1; - } else if(diff < 0) { + } else if (diff < 0) { return -1; } return 0; @@ -210,18 +230,18 @@ public class Attachment extends AbstractRemoteEntity implements Comparable<Attac public long getModificationTimeForComparsion() { if (lastModifiedLocal != null) { - return lastModifiedLocal.getTime(); + return lastModifiedLocal.toEpochMilli(); } if (lastModified != null) { - return lastModified.getTime(); + return lastModified.toEpochMilli(); } - return new Date().getTime(); + return Instant.now().toEpochMilli(); } public long getCreationTimeForComparsion() { if (createdAt != null) { - return createdAt.getTime(); + return createdAt.toEpochMilli(); } - return new Date().getTime(); + return Instant.now().toEpochMilli(); } }
\ No newline at end of file diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/model/Board.java b/app/src/main/java/it/niedermann/nextcloud/deck/model/Board.java index 29afe844b..27dcd1df8 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/model/Board.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/model/Board.java @@ -1,17 +1,23 @@ package it.niedermann.nextcloud.deck.model; +import android.graphics.Color; + +import androidx.annotation.ColorInt; import androidx.room.Entity; import androidx.room.ForeignKey; import androidx.room.Ignore; import androidx.room.Index; +import com.google.gson.annotations.JsonAdapter; + import java.io.Serializable; -import java.util.Date; +import java.time.Instant; +import it.niedermann.android.util.ColorUtil; import it.niedermann.nextcloud.deck.DeckLog; +import it.niedermann.nextcloud.deck.api.json.JsonColorSerializer; import it.niedermann.nextcloud.deck.model.enums.DBStatus; import it.niedermann.nextcloud.deck.model.interfaces.AbstractRemoteEntity; -import it.niedermann.nextcloud.deck.util.ColorUtil; @Entity( inheritSuperIndices = true, @@ -31,20 +37,18 @@ public class Board extends AbstractRemoteEntity implements Serializable { } @Ignore - public Board(String title, String color) { - this.title = title; + public Board(String title, @ColorInt int color) { + setTitle(title); setColor(color); } private String title; private long ownerId; - /** - * Deck App sends color strings without leading # character - */ - private String color; + @JsonAdapter(JsonColorSerializer.class) + private Integer color; private boolean archived; private int shared; - private Date deletedAt; + private Instant deletedAt; private boolean permissionRead = false; private boolean permissionEdit = false; private boolean permissionManage = false; @@ -52,22 +56,22 @@ public class Board extends AbstractRemoteEntity implements Serializable { @Override - public Date getLastModified() { + public Instant getLastModified() { return lastModified; } @Override - public void setLastModified(Date lastModified) { + public void setLastModified(Instant lastModified) { this.lastModified = lastModified; } @Override - public Date getLastModifiedLocal() { + public Instant getLastModifiedLocal() { return lastModifiedLocal; } @Override - public void setLastModifiedLocal(Date lastModifiedLocal) { + public void setLastModifiedLocal(Instant lastModifiedLocal) { this.lastModifiedLocal = lastModifiedLocal; } @@ -79,21 +83,25 @@ public class Board extends AbstractRemoteEntity implements Serializable { this.id = id; } - public String getColor() { + @ColorInt + public Integer getColor() { return color; } + public void setColor(String color) { try { - // Nextcloud might return color format #000 which cannot be parsed by Color.parseColor() - // https://github.com/stefan-niedermann/nextcloud-deck/issues/466 - this.color = ColorUtil.formatColorToParsableHexString(color).substring(1); + setColor(Color.parseColor(ColorUtil.INSTANCE.formatColorToParsableHexString(color))); } catch (Exception e) { DeckLog.logError(e); - this.color = "757575"; + setColor(Color.GRAY); } } + public void setColor(@ColorInt Integer color) { + this.color = color; + } + public boolean isArchived() { return archived; } @@ -114,11 +122,11 @@ public class Board extends AbstractRemoteEntity implements Serializable { this.shared = shared; } - public Date getDeletedAt() { + public Instant getDeletedAt() { return deletedAt; } - public void setDeletedAt(Date deletedAt) { + public void setDeletedAt(Instant deletedAt) { this.deletedAt = deletedAt; } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/model/Card.java b/app/src/main/java/it/niedermann/nextcloud/deck/model/Card.java index 732ccfc50..6f2b70020 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/model/Card.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/model/Card.java @@ -8,7 +8,7 @@ import androidx.room.Index; import com.google.gson.annotations.SerializedName; -import java.util.Date; +import java.time.Instant; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -16,22 +16,23 @@ import it.niedermann.nextcloud.deck.model.enums.DBStatus; import it.niedermann.nextcloud.deck.model.interfaces.AbstractRemoteEntity; @Entity(inheritSuperIndices = true, - indices = { - @Index(value = "accountId", name = "card_accID"), - @Index("stackId") - }, - foreignKeys = { - @ForeignKey( - entity = Stack.class, - parentColumns = "localId", - childColumns = "stackId", onDelete = ForeignKey.CASCADE - ) - } + indices = { + @Index(value = "accountId", name = "card_accID"), + @Index("stackId") + }, + foreignKeys = { + @ForeignKey( + entity = Stack.class, + parentColumns = "localId", + childColumns = "stackId", onDelete = ForeignKey.CASCADE + ) + } ) public class Card extends AbstractRemoteEntity { private static Pattern PATTERN_MD_TASK = Pattern.compile("\\[([xX ])]"); - public class TaskStatus { + + public static class TaskStatus { public int taskCount; public int doneCount; @@ -49,20 +50,21 @@ public class Card extends AbstractRemoteEntity { @NonNull private Long stackId; private String type; - private Date createdAt; - private Date deletedAt; + private Instant createdAt; + private Instant deletedAt; private int attachmentCount; private Long userId; private int order; private boolean archived; @SerializedName("duedate") - private Date dueDate; + private Instant dueDate; private boolean notified; private int overdue; private int commentsUnread; - public Card() {} + public Card() { + } @Ignore public Card(String title, String description, long stackId) { @@ -89,15 +91,15 @@ public class Card extends AbstractRemoteEntity { this.commentsUnread = card.getCommentsUnread(); } - public TaskStatus getTaskStatus(){ - if (taskStatus == null){ + public TaskStatus getTaskStatus() { + if (taskStatus == null) { int count = 0, done = 0; if (description != null) { Matcher matcher = PATTERN_MD_TASK.matcher(description); - while (matcher.find()){ + while (matcher.find()) { count++; char c = matcher.group().charAt(1); - if (c == 'x' || c == 'X'){ + if (c == 'x' || c == 'X') { done++; } } @@ -164,19 +166,19 @@ public class Card extends AbstractRemoteEntity { this.type = type; } - public Date getCreatedAt() { + public Instant getCreatedAt() { return createdAt; } - public void setCreatedAt(Date createdAt) { + public void setCreatedAt(Instant createdAt) { this.createdAt = createdAt; } - public Date getDeletedAt() { + public Instant getDeletedAt() { return deletedAt; } - public void setDeletedAt(Date deletedAt) { + public void setDeletedAt(Instant deletedAt) { this.deletedAt = deletedAt; } @@ -200,12 +202,12 @@ public class Card extends AbstractRemoteEntity { this.archived = archived; } - public Date getDueDate() { + public Instant getDueDate() { return dueDate; } - public void setDueDate(Date dueDate) { - this.dueDate = dueDate; + public void setDueDate(Instant dateTime) { + this.dueDate = dateTime; } public int getOverdue() { diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/model/Label.java b/app/src/main/java/it/niedermann/nextcloud/deck/model/Label.java index 0d97ce5a0..da24edb5a 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/model/Label.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/model/Label.java @@ -1,27 +1,41 @@ package it.niedermann.nextcloud.deck.model; +import android.graphics.Color; + +import androidx.annotation.ColorInt; +import androidx.annotation.NonNull; +import androidx.room.ColumnInfo; import androidx.room.Entity; import androidx.room.ForeignKey; import androidx.room.Index; +import com.google.gson.annotations.JsonAdapter; + import java.io.Serializable; +import it.niedermann.android.util.ColorUtil; +import it.niedermann.nextcloud.deck.DeckLog; +import it.niedermann.nextcloud.deck.api.json.JsonColorSerializer; import it.niedermann.nextcloud.deck.model.interfaces.AbstractRemoteEntity; @Entity(inheritSuperIndices = true, indices = {@Index("boardId"), @Index(value = {"boardId", "title"}, unique = true, name = "idx_label_title_unique")}, foreignKeys = { - @ForeignKey( - entity = Board.class, - parentColumns = "localId", - childColumns = "boardId", - onDelete = ForeignKey.CASCADE - ) - } + @ForeignKey( + entity = Board.class, + parentColumns = "localId", + childColumns = "boardId", + onDelete = ForeignKey.CASCADE + ) + } ) public class Label extends AbstractRemoteEntity implements Serializable { private String title; - private String color; + + @JsonAdapter(JsonColorSerializer.class) + @NonNull + @ColumnInfo(defaultValue = "0") + private Integer color; private long boardId; public Label() { @@ -42,14 +56,25 @@ public class Label extends AbstractRemoteEntity implements Serializable { this.title = title; } - public String getColor() { + @NonNull + @ColorInt + public Integer getColor() { return color; } - public void setColor(String color) { + public void setColor(@NonNull @ColorInt Integer color) { this.color = color; } + public void setColor(String color) { + try { + setColor(Color.parseColor(ColorUtil.INSTANCE.formatColorToParsableHexString(color))); + } catch (Exception e) { + DeckLog.logError(e); + setColor(Color.GRAY); + } + } + public long getBoardId() { return boardId; } @@ -62,18 +87,20 @@ public class Label extends AbstractRemoteEntity implements Serializable { public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; + if (!super.equals(o)) return false; Label label = (Label) o; if (boardId != label.boardId) return false; if (title != null ? !title.equals(label.title) : label.title != null) return false; - return color != null ? color.equals(label.color) : label.color == null; + return color.equals(label.color); } @Override public int hashCode() { - int result = title != null ? title.hashCode() : 0; - result = 31 * result + (color != null ? color.hashCode() : 0); + int result = super.hashCode(); + result = 31 * result + (title != null ? title.hashCode() : 0); + result = 31 * result + color.hashCode(); result = 31 * result + (int) (boardId ^ (boardId >>> 32)); return result; } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/model/Stack.java b/app/src/main/java/it/niedermann/nextcloud/deck/model/Stack.java index 330ec16d7..00f054605 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/model/Stack.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/model/Stack.java @@ -1,12 +1,11 @@ package it.niedermann.nextcloud.deck.model; -import androidx.annotation.NonNull; import androidx.room.Entity; import androidx.room.ForeignKey; import androidx.room.Ignore; import androidx.room.Index; -import java.util.Date; +import java.time.Instant; import it.niedermann.nextcloud.deck.model.interfaces.AbstractRemoteEntity; @@ -35,12 +34,10 @@ public class Stack extends AbstractRemoteEntity { private String title; - @NonNull private long boardId; - private Date deletedAt; + private Instant deletedAt; - @NonNull private int order; // // @ToMany @@ -64,11 +61,11 @@ public class Stack extends AbstractRemoteEntity { this.boardId = boardId; } - public Date getDeletedAt() { + public Instant getDeletedAt() { return deletedAt; } - public void setDeletedAt(Date deletedAt) { + public void setDeletedAt(Instant deletedAt) { this.deletedAt = deletedAt; } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/model/User.java b/app/src/main/java/it/niedermann/nextcloud/deck/model/User.java index cfb48d543..fd318ce7a 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/model/User.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/model/User.java @@ -4,10 +4,12 @@ import androidx.room.Entity; import androidx.room.Ignore; import androidx.room.Index; +import java.io.Serializable; + import it.niedermann.nextcloud.deck.model.interfaces.AbstractRemoteEntity; @Entity(inheritSuperIndices = true, indices = {@Index(value = "uid", name = "user_uid")}) -public class User extends AbstractRemoteEntity { +public class User extends AbstractRemoteEntity implements Serializable { private String primaryKey; diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/model/appwidgets/StackWidgetModel.java b/app/src/main/java/it/niedermann/nextcloud/deck/model/appwidgets/StackWidgetModel.java new file mode 100644 index 000000000..fb7a74076 --- /dev/null +++ b/app/src/main/java/it/niedermann/nextcloud/deck/model/appwidgets/StackWidgetModel.java @@ -0,0 +1,68 @@ +package it.niedermann.nextcloud.deck.model.appwidgets; + +import androidx.room.Entity; +import androidx.room.ForeignKey; +import androidx.room.Index; +import androidx.room.PrimaryKey; + +import it.niedermann.nextcloud.deck.model.Account; +import it.niedermann.nextcloud.deck.model.Stack; + +@Entity( + indices = { + @Index("stackId"), + @Index("accountId") + }, + foreignKeys = { + @ForeignKey( + entity = Account.class, + parentColumns = "id", + childColumns = "accountId", onDelete = ForeignKey.CASCADE + ), + @ForeignKey( + entity = Stack.class, + parentColumns = "localId", + childColumns = "stackId", onDelete = ForeignKey.CASCADE + ) + } +) +public class StackWidgetModel { + + @PrimaryKey() + private Integer appWidgetId; + private Long accountId; + private Long stackId; + private boolean darkTheme; + + public Integer getAppWidgetId() { + return appWidgetId; + } + + public void setAppWidgetId(Integer appWidgetId) { + this.appWidgetId = appWidgetId; + } + + public Long getAccountId() { + return accountId; + } + + public void setAccountId(Long accountId) { + this.accountId = accountId; + } + + public Long getStackId() { + return stackId; + } + + public void setStackId(Long stackId) { + this.stackId = stackId; + } + + public boolean getDarkTheme() { + return darkTheme; + } + + public void setDarkTheme(boolean darkTheme) { + this.darkTheme = darkTheme; + } +} diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/model/full/FullBoard.java b/app/src/main/java/it/niedermann/nextcloud/deck/model/full/FullBoard.java index 31ad21f16..f9f1643ff 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/model/full/FullBoard.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/model/full/FullBoard.java @@ -1,5 +1,6 @@ package it.niedermann.nextcloud.deck.model.full; +import androidx.annotation.NonNull; import androidx.room.Embedded; import androidx.room.Ignore; import androidx.room.Relation; @@ -29,6 +30,8 @@ public class FullBoard implements IRemoteEntity { @Relation(entity = Stack.class, parentColumn = "localId", entityColumn = "boardId") public List<Stack> stacks; + @Ignore + public List<User> users; public User getOwner() { return owner; @@ -54,9 +57,17 @@ public class FullBoard implements IRemoteEntity { this.labels = labels; } + public List<User> getUsers() { + return users; + } + + public void setUsers(List<User> users) { + this.users = users; + } + @Ignore @Override - public IRemoteEntity getEntity() { + public Board getEntity() { return board; } @@ -102,6 +113,7 @@ public class FullBoard implements IRemoteEntity { return result; } + @NonNull @Override public String toString() { return "FullBoard{" + diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/model/full/FullCard.java b/app/src/main/java/it/niedermann/nextcloud/deck/model/full/FullCard.java index 41303cac6..611baf3df 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/model/full/FullCard.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/model/full/FullCard.java @@ -6,8 +6,6 @@ import androidx.room.Ignore; import androidx.room.Junction; import androidx.room.Relation; -import org.jetbrains.annotations.NotNull; - import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -25,7 +23,7 @@ import it.niedermann.nextcloud.deck.model.ocs.comment.DeckComment; public class FullCard implements IRemoteEntity, DragAndDropModel { @Ignore - private transient boolean isAttachmentsSorted = false; + protected transient boolean isAttachmentsSorted = false; @Embedded public Card card; @@ -48,7 +46,6 @@ public class FullCard implements IRemoteEntity, DragAndDropModel { @Relation(entity = DeckComment.class, parentColumn = "localId", entityColumn = "objectId", projection = "localId") public List<Long> commentIDs; - public FullCard() { super(); } @@ -126,11 +123,11 @@ public class FullCard implements IRemoteEntity, DragAndDropModel { @Ignore @Override - public IRemoteEntity getEntity() { + public Card getEntity() { return card; } - @NotNull + @NonNull @Override public String toString() { return "FullCard{" + diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/model/full/FullCardWithProjects.java b/app/src/main/java/it/niedermann/nextcloud/deck/model/full/FullCardWithProjects.java new file mode 100644 index 000000000..cf43fc86b --- /dev/null +++ b/app/src/main/java/it/niedermann/nextcloud/deck/model/full/FullCardWithProjects.java @@ -0,0 +1,82 @@ +package it.niedermann.nextcloud.deck.model.full; + +import androidx.annotation.NonNull; +import androidx.room.Junction; +import androidx.room.Relation; + +import java.util.ArrayList; +import java.util.List; + +import it.niedermann.nextcloud.deck.model.ocs.projects.JoinCardWithProject; +import it.niedermann.nextcloud.deck.model.ocs.projects.OcsProject; +import it.niedermann.nextcloud.deck.model.ocs.projects.full.OcsProjectWithResources; + +public class FullCardWithProjects extends FullCard { + + + @NonNull + @Relation(entity = OcsProject.class, parentColumn = "localId", entityColumn = "localId", + associateBy = @Junction(value = JoinCardWithProject.class, parentColumn = "cardId", entityColumn = "projectId")) + + private List<OcsProjectWithResources> projects = new ArrayList<>(); + + public FullCardWithProjects() { + super(); + } + + public FullCardWithProjects(FullCardWithProjects fullCard) { + super(fullCard); + this.projects = copyList(fullCard.getProjects()); + } + + @NonNull + public List<OcsProjectWithResources> getProjects() { + return projects; + } + + public void setProjects(@NonNull List<OcsProjectWithResources> projects) { + this.projects = projects; + } + + @NonNull + @Override + public String toString() { + return "FullCard{" + + "card=" + card + + ", labels=" + labels + + ", assignedUsers=" + assignedUsers + + ", owner=" + owner + + ", attachments=" + attachments + + '}'; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + FullCardWithProjects fullCard = (FullCardWithProjects) o; + + if (card != null ? !card.equals(fullCard.card) : fullCard.card != null) return false; + if (labels != null ? !labels.equals(fullCard.labels) : fullCard.labels != null) + return false; + if (assignedUsers != null ? !assignedUsers.equals(fullCard.assignedUsers) : fullCard.assignedUsers != null) + return false; + if (owner != null ? !owner.equals(fullCard.owner) : fullCard.owner != null) return false; + if (attachments != null ? !attachments.equals(fullCard.attachments) : fullCard.attachments != null) + return false; + return commentIDs != null ? commentIDs.equals(fullCard.commentIDs) : fullCard.commentIDs == null; + } + + @Override + public int hashCode() { + int result = (isAttachmentsSorted ? 1 : 0); + result = 31 * result + (card != null ? card.hashCode() : 0); + result = 31 * result + (labels != null ? labels.hashCode() : 0); + result = 31 * result + (assignedUsers != null ? assignedUsers.hashCode() : 0); + result = 31 * result + (owner != null ? owner.hashCode() : 0); + result = 31 * result + (attachments != null ? attachments.hashCode() : 0); + result = 31 * result + (commentIDs != null ? commentIDs.hashCode() : 0); + return result; + } +} diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/model/full/FullStack.java b/app/src/main/java/it/niedermann/nextcloud/deck/model/full/FullStack.java index eddbafce4..1c9e94899 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/model/full/FullStack.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/model/full/FullStack.java @@ -14,7 +14,7 @@ public class FullStack implements IRemoteEntity { @Embedded public Stack stack; - @Relation(entity = Card.class, parentColumn = "localId", entityColumn = "stackId") + @Relation(entity = Card.class, parentColumn = "localId", entityColumn = "stackId") public List<Card> cards; @@ -36,7 +36,7 @@ public class FullStack implements IRemoteEntity { @Ignore @Override - public IRemoteEntity getEntity() { + public Stack getEntity() { return stack; } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/model/interfaces/AbstractJoinEntity.java b/app/src/main/java/it/niedermann/nextcloud/deck/model/interfaces/AbstractJoinEntity.java index 50057dfe4..ce14ac6be 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/model/interfaces/AbstractJoinEntity.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/model/interfaces/AbstractJoinEntity.java @@ -1,21 +1,20 @@ package it.niedermann.nextcloud.deck.model.interfaces; -import androidx.annotation.NonNull; import androidx.room.Entity; import androidx.room.Ignore; + import it.niedermann.nextcloud.deck.model.enums.DBStatus; @Entity() public abstract class AbstractJoinEntity { - @NonNull protected int status = DBStatus.UP_TO_DATE.getId(); public int getStatus() { return status; } - public void setStatus(@NonNull int status) { + public void setStatus(int status) { this.status = status; } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/model/interfaces/AbstractRemoteEntity.java b/app/src/main/java/it/niedermann/nextcloud/deck/model/interfaces/AbstractRemoteEntity.java index 328c642ae..2f7771383 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/model/interfaces/AbstractRemoteEntity.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/model/interfaces/AbstractRemoteEntity.java @@ -1,31 +1,30 @@ package it.niedermann.nextcloud.deck.model.interfaces; -import androidx.annotation.NonNull; import androidx.room.Entity; import androidx.room.ForeignKey; import androidx.room.Ignore; import androidx.room.Index; import androidx.room.PrimaryKey; -import java.util.Date; +import java.time.Instant; import it.niedermann.nextcloud.deck.model.Account; import it.niedermann.nextcloud.deck.model.enums.DBStatus; @Entity( - indices = { - @Index("accountId"), - @Index("id"), - @Index("lastModifiedLocal"), - @Index(value = {"accountId", "id"}, unique = true) - }, - foreignKeys = { - @ForeignKey( - entity = Account.class, - parentColumns = "id", - childColumns = "accountId", onDelete = ForeignKey.CASCADE - ) - } + indices = { + @Index("accountId"), + @Index("id"), + @Index("lastModifiedLocal"), + @Index(value = {"accountId", "id"}, unique = true) + }, + foreignKeys = { + @ForeignKey( + entity = Account.class, + parentColumns = "id", + childColumns = "accountId", onDelete = ForeignKey.CASCADE + ) + } ) public abstract class AbstractRemoteEntity implements IRemoteEntity { @PrimaryKey(autoGenerate = true) @@ -35,11 +34,12 @@ public abstract class AbstractRemoteEntity implements IRemoteEntity { protected Long id; - @NonNull protected int status = DBStatus.UP_TO_DATE.getId(); - protected Date lastModified; - protected Date lastModifiedLocal; + protected Instant lastModified; + protected Instant lastModifiedLocal; + + protected String etag; public AbstractRemoteEntity() { } @@ -102,35 +102,30 @@ public abstract class AbstractRemoteEntity implements IRemoteEntity { @Override - public void setStatus(@NonNull int status) { + public void setStatus(int status) { this.status = status; } - @Override - public Date getLastModified() { + public Instant getLastModified() { return this.lastModified; } - @Override - public void setLastModified(Date lastModified) { + public void setLastModified(Instant lastModified) { this.lastModified = lastModified; } - @Override - public Date getLastModifiedLocal() { + public Instant getLastModifiedLocal() { return this.lastModifiedLocal; } - @Override - public void setLastModifiedLocal(Date lastModifiedLocal) { + public void setLastModifiedLocal(Instant lastModifiedLocal) { this.lastModifiedLocal = lastModifiedLocal; } - @Ignore @Override public DBStatus getStatusEnum() { @@ -144,6 +139,15 @@ public abstract class AbstractRemoteEntity implements IRemoteEntity { this.status = status.getId(); } + @Override + public String getEtag() { + return etag; + } + + @Override + public void setEtag(String etag) { + this.etag = etag; + } @Override public boolean equals(Object o) { diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/model/interfaces/IRemoteEntity.java b/app/src/main/java/it/niedermann/nextcloud/deck/model/interfaces/IRemoteEntity.java index 30a478808..f197c0d30 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/model/interfaces/IRemoteEntity.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/model/interfaces/IRemoteEntity.java @@ -1,94 +1,87 @@ package it.niedermann.nextcloud.deck.model.interfaces; -import androidx.annotation.NonNull; - +import java.time.Instant; import java.util.ArrayList; -import java.util.Date; import java.util.List; import it.niedermann.nextcloud.deck.model.enums.DBStatus; public interface IRemoteEntity { - default IRemoteEntity getEntity() {return this;} + default IRemoteEntity getEntity() { + return this; + } default Long getLocalId() { return getEntity().getLocalId(); } - default void setLocalId(Long localId) { getEntity().setLocalId(localId); } - default long getAccountId() { return getEntity().getAccountId(); } - default void setAccountId(long accountId) { getEntity().setAccountId(accountId); } - default Long getId() { return getEntity().getId(); } - default void setId(Long id) { getEntity().setId(id); } - default int getStatus() { return getEntity().getStatus(); } - - default void setStatus(@NonNull int status) { + default void setStatus(int status) { getEntity().setStatus(status); } - - default Date getLastModified() { + default Instant getLastModified() { return getEntity().getLastModified(); } - - default void setLastModified(Date lastModified) { + default void setLastModified(Instant lastModified) { getEntity().setLastModified(lastModified); } - - default Date getLastModifiedLocal() { + default Instant getLastModifiedLocal() { return getEntity().getLastModifiedLocal(); } - - default void setLastModifiedLocal(Date lastModifiedLocal) { + default void setLastModifiedLocal(Instant lastModifiedLocal) { getEntity().setLastModifiedLocal(lastModifiedLocal); } - default DBStatus getStatusEnum() { return getEntity().getStatusEnum(); } - default void setStatusEnum(DBStatus status) { getEntity().setStatusEnum(status); } + default String getEtag() { + return getEntity().getEtag(); + } + + default void setEtag(String etag) { + getEntity().setEtag(etag); + } + default <T> List<T> copyList(List<T> listToCopy) { if (listToCopy == null) { return null; } List<T> list = new ArrayList<>(listToCopy.size()); - for (T t : listToCopy) { - list.add(t); - } + list.addAll(listToCopy); return list; } } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/model/internal/FilterInformation.java b/app/src/main/java/it/niedermann/nextcloud/deck/model/internal/FilterInformation.java index f3892dfa5..1b5f0879d 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/model/internal/FilterInformation.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/model/internal/FilterInformation.java @@ -3,8 +3,6 @@ package it.niedermann.nextcloud.deck.model.internal; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import org.jetbrains.annotations.NotNull; - import java.io.Serializable; import java.util.ArrayList; import java.util.List; @@ -14,12 +12,21 @@ import it.niedermann.nextcloud.deck.model.User; import it.niedermann.nextcloud.deck.model.enums.EDueType; public class FilterInformation implements Serializable { + + public enum EArchiveStatus{ + ALL, ARCHIVED, NON_ARCHIVED + } + @NonNull private EDueType dueType = EDueType.NO_FILTER; + private boolean noAssignedLabel = false; + private boolean noAssignedUser = false; @NonNull private List<User> users = new ArrayList<>(); @NonNull private List<Label> labels = new ArrayList<>(); + @NonNull + private EArchiveStatus archiveStatus = EArchiveStatus.NON_ARCHIVED; public FilterInformation() { // Default constructor @@ -28,8 +35,12 @@ public class FilterInformation implements Serializable { public FilterInformation(@Nullable FilterInformation filterInformation) { if (filterInformation != null) { this.dueType = filterInformation.getDueType(); + this.archiveStatus = filterInformation.getArchiveStatus(); this.users.addAll(filterInformation.getUsers()); this.labels.addAll(filterInformation.getLabels()); + this.noAssignedUser = filterInformation.isNoAssignedUser(); + this.noAssignedLabel = filterInformation.isNoAssignedLabel(); + this.archiveStatus = filterInformation.getArchiveStatus(); } } @@ -47,7 +58,7 @@ public class FilterInformation implements Serializable { return users; } - @NotNull + @NonNull public List<Label> getLabels() { return labels; } @@ -68,23 +79,55 @@ public class FilterInformation implements Serializable { users.remove(user); } - @NotNull + public boolean isNoAssignedUser() { + return noAssignedUser; + } + + public void setNoAssignedUser(boolean noAssignedUser) { + this.noAssignedUser = noAssignedUser; + } + + public boolean isNoAssignedLabel() { + return noAssignedLabel; + } + + public void setNoAssignedLabel(boolean noAssignedLabel) { + this.noAssignedLabel = noAssignedLabel; + } + + public void setArchiveStatus(@NonNull EArchiveStatus archiveStatus) { + this.archiveStatus = archiveStatus; + } + + @NonNull + public EArchiveStatus getArchiveStatus() { + return archiveStatus; + } + + @NonNull @Override public String toString() { return "FilterInformation{" + "dueType=" + dueType + + ", noAssignedLabel=" + noAssignedLabel + + ", noAssignedUser=" + noAssignedUser + ", users=" + users + ", labels=" + labels + + ", archiveStatus=" + archiveStatus + '}'; } /** - * @return whether or not the given filterInformation has any actual filters set + * @return whether or not the given {@param filterInformation} has any actual filters set */ public static boolean hasActiveFilter(@Nullable FilterInformation filterInformation) { if (filterInformation == null) { return false; } - return filterInformation.getDueType() != EDueType.NO_FILTER || filterInformation.getUsers().size() > 0 || filterInformation.getLabels().size() > 0; + return filterInformation.getDueType() != EDueType.NO_FILTER + || filterInformation.getUsers().size() > 0 + || filterInformation.getLabels().size() > 0 + || filterInformation.noAssignedUser + || filterInformation.noAssignedLabel; } } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/model/ocs/Capabilities.java b/app/src/main/java/it/niedermann/nextcloud/deck/model/ocs/Capabilities.java index 9ff4d7945..12e8692d4 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/model/ocs/Capabilities.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/model/ocs/Capabilities.java @@ -5,8 +5,8 @@ public class Capabilities { private Version deckVersion; private Version nextcloudVersion; - private String color = "#0082c9"; - private String textColor = "#ffffff"; + private int color = 0; + private int textColor = 0; private boolean maintenanceEnabled = false; public Capabilities() { @@ -28,19 +28,19 @@ public class Capabilities { this.nextcloudVersion = nextcloudVersion; } - public String getColor() { + public int getColor() { return color; } - public void setColor(String color) { + public void setColor(int color) { this.color = color; } - public String getTextColor() { + public int getTextColor() { return textColor; } - public void setTextColor(String textColor) { + public void setTextColor(int textColor) { this.textColor = textColor; } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/model/ocs/Version.java b/app/src/main/java/it/niedermann/nextcloud/deck/model/ocs/Version.java index 7ef97a294..cfd973831 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/model/ocs/Version.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/model/ocs/Version.java @@ -6,18 +6,18 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.StringRes; -import org.jetbrains.annotations.NotNull; - import java.util.regex.Matcher; import java.util.regex.Pattern; import it.niedermann.nextcloud.deck.R; +import it.niedermann.nextcloud.deck.model.Attachment; import it.niedermann.nextcloud.deck.model.ocs.comment.DeckComment; public class Version implements Comparable<Version> { private static final Pattern NUMBER_EXTRACTION_PATTERN = Pattern.compile("[0-9]+"); private static final Version VERSION_1_0_0 = new Version("1.0.0", 1, 0, 0); private static final Version VERSION_1_0_3 = new Version("1.0.3", 1, 0, 3); + private static final Version VERSION_1_3_0 = new Version("1.3.0", 1, 3, 0); @Nullable private static Version VERSION_MINIMUM_SUPPORTED; @@ -125,7 +125,7 @@ public class Version implements Comparable<Version> { return 0; } - @NotNull + @NonNull @Override public String toString() { return "Version{" + @@ -157,6 +157,22 @@ public class Version implements Comparable<Version> { } /** + * Before {@link #VERSION_1_3_0} all {@link Attachment}s have been stored in a special folder at the server. + * Starting with {@link #VERSION_1_3_0} {@link Attachment}s can be stored as regular files, allowing for example to make use of server side thumbnail generation. + * <p> + * Since the migration takes a long time, it does not happen on upgrading the server app but step by step via a cronjob. + * Therefore this method is just an indicator, that it is possible that {@link Attachment}s are stored as files, but it is no guarantee that all {@link Attachment}s already have been migrated to files. + * + * @return whether or not the server supports file attachments + * @see <a href="https://github.com/nextcloud/deck/pull/2638">documentation in PR</a> + */ + public boolean supportsFileAttachments() { + return false; +// TODO depends on https://github.com/nextcloud/deck/pull/2638 +// return isGreaterOrEqualTo(VERSION_1_3_0); + } + + /** * Title max length has been increased from 100 to 255 characters beginning with server {@link Version} 1.0.0 * * @return the number of characters that the title fields of cards allow @@ -167,6 +183,7 @@ public class Version implements Comparable<Version> { ? 255 : 100; } + /** * URL to view a card in the web interface has been changed in {@link Version} 1.0.0 * diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/model/ocs/comment/DeckComment.java b/app/src/main/java/it/niedermann/nextcloud/deck/model/ocs/comment/DeckComment.java index 707bae974..8bba9740b 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/model/ocs/comment/DeckComment.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/model/ocs/comment/DeckComment.java @@ -5,12 +5,13 @@ import androidx.room.ForeignKey; import androidx.room.Ignore; import androidx.room.Index; +import java.time.Instant; import java.util.ArrayList; -import java.util.Date; import java.util.List; import it.niedermann.nextcloud.deck.model.Card; import it.niedermann.nextcloud.deck.model.interfaces.AbstractRemoteEntity; + @Entity(inheritSuperIndices = true, indices = { @Index(value = "accountId", name = "comment_accID"), @@ -35,7 +36,7 @@ public class DeckComment extends AbstractRemoteEntity { private Long objectId; private String actorType; - private Date creationDateTime; + private Instant creationDateTime; private String actorId; private String actorDisplayName; private String message; @@ -47,7 +48,7 @@ public class DeckComment extends AbstractRemoteEntity { } @Ignore - public DeckComment(String message, String actorDisplayName, Date creationDateTime) { + public DeckComment(String message, String actorDisplayName, Instant creationDateTime) { setMessage(message); setActorDisplayName(actorDisplayName); setCreationDateTime(creationDateTime); @@ -76,11 +77,11 @@ public class DeckComment extends AbstractRemoteEntity { this.actorType = actorType; } - public Date getCreationDateTime() { + public Instant getCreationDateTime() { return creationDateTime; } - public void setCreationDateTime(Date creationDateTime) { + public void setCreationDateTime(Instant creationDateTime) { this.creationDateTime = creationDateTime; } @@ -121,8 +122,8 @@ public class DeckComment extends AbstractRemoteEntity { } public void setMessage(String message) { - if (message!= null && message.length() > MAX_MESSAGE_LENGTH) { - throw new IllegalArgumentException("The server won't accept messages longer than "+MAX_MESSAGE_LENGTH+" characters!"); + if (message != null && message.length() > MAX_MESSAGE_LENGTH) { + throw new IllegalArgumentException("The server won't accept messages longer than " + MAX_MESSAGE_LENGTH + " characters!"); } this.message = message; } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/model/ocs/projects/JoinCardWithProject.java b/app/src/main/java/it/niedermann/nextcloud/deck/model/ocs/projects/JoinCardWithProject.java new file mode 100644 index 000000000..615c7a2a2 --- /dev/null +++ b/app/src/main/java/it/niedermann/nextcloud/deck/model/ocs/projects/JoinCardWithProject.java @@ -0,0 +1,66 @@ +package it.niedermann.nextcloud.deck.model.ocs.projects; + +import androidx.annotation.NonNull; +import androidx.room.Entity; +import androidx.room.ForeignKey; +import androidx.room.Index; + +import it.niedermann.nextcloud.deck.model.Card; +import it.niedermann.nextcloud.deck.model.interfaces.AbstractJoinEntity; + +@Entity( + primaryKeys = {"projectId", "cardId"}, + indices = {@Index("cardId"), @Index("projectId")}, + foreignKeys = { + @ForeignKey(entity = OcsProject.class, + parentColumns = "localId", + childColumns = "projectId", + onDelete = ForeignKey.CASCADE + ), + @ForeignKey(entity = Card.class, + parentColumns = "localId", + childColumns = "cardId", + onDelete = ForeignKey.CASCADE + ) + }) +public class JoinCardWithProject extends AbstractJoinEntity { + @NonNull + private Long projectId; + @NonNull + private Long cardId; + + @NonNull + public Long getProjectId() { + return projectId; + } + + public void setProjectId(@NonNull Long projectId) { + this.projectId = projectId; + } + + public Long getCardId() { + return cardId; + } + + public void setCardId(Long cardId) { + this.cardId = cardId; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + JoinCardWithProject that = (JoinCardWithProject) o; + + if (!projectId.equals(that.projectId)) return false; + return cardId.equals(that.cardId); + } + + @Override + public int hashCode() { + int result = projectId.hashCode(); + result = 31 * result + cardId.hashCode(); + return result; + } +} diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/model/ocs/projects/OcsProject.java b/app/src/main/java/it/niedermann/nextcloud/deck/model/ocs/projects/OcsProject.java new file mode 100644 index 000000000..49bc7296d --- /dev/null +++ b/app/src/main/java/it/niedermann/nextcloud/deck/model/ocs/projects/OcsProject.java @@ -0,0 +1,45 @@ +package it.niedermann.nextcloud.deck.model.ocs.projects; + +import androidx.annotation.NonNull; +import androidx.room.Entity; +import androidx.room.Ignore; +import androidx.room.Index; + +import java.util.ArrayList; +import java.util.List; + +import it.niedermann.nextcloud.deck.model.interfaces.AbstractRemoteEntity; + +@Entity(inheritSuperIndices = true, + indices = { + @Index(value = "accountId", name = "index_project_accID"), + }, + foreignKeys = { + } +) +public class OcsProject extends AbstractRemoteEntity { + @NonNull + private String name; + + @Ignore + @NonNull + private ArrayList<OcsProjectResource> resources = new ArrayList<>(); + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @NonNull + public ArrayList<OcsProjectResource> getResources() { + return resources; + } + + public void setResources(@NonNull List<OcsProjectResource> resources) { + this.resources.clear(); + this.resources.addAll(resources); + } +} diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/model/ocs/projects/OcsProjectList.java b/app/src/main/java/it/niedermann/nextcloud/deck/model/ocs/projects/OcsProjectList.java new file mode 100644 index 000000000..af42b8432 --- /dev/null +++ b/app/src/main/java/it/niedermann/nextcloud/deck/model/ocs/projects/OcsProjectList.java @@ -0,0 +1,24 @@ +package it.niedermann.nextcloud.deck.model.ocs.projects; + +import java.util.ArrayList; +import java.util.List; + +public class OcsProjectList { + List<OcsProject> projects; + + public OcsProjectList() { + projects = new ArrayList<>(); + } + + public OcsProjectList(List<OcsProject> projects) { + this.projects = projects; + } + + public List<OcsProject> getProjects() { + return projects; + } + + public void add(OcsProject project) { + projects.add(project); + } +} diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/model/ocs/projects/OcsProjectResource.java b/app/src/main/java/it/niedermann/nextcloud/deck/model/ocs/projects/OcsProjectResource.java new file mode 100644 index 000000000..cd63ccde4 --- /dev/null +++ b/app/src/main/java/it/niedermann/nextcloud/deck/model/ocs/projects/OcsProjectResource.java @@ -0,0 +1,135 @@ +package it.niedermann.nextcloud.deck.model.ocs.projects; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.room.Entity; +import androidx.room.ForeignKey; +import androidx.room.Index; +import androidx.room.RoomWarnings; + +import java.io.Serializable; + +import it.niedermann.nextcloud.deck.model.interfaces.AbstractRemoteEntity; + +@SuppressWarnings(RoomWarnings.INDEX_FROM_PARENT_IS_DROPPED) +@Entity( + indices = { + @Index(value = "id", name = "index_OcsProjectResource_id"), + @Index(value = "lastModifiedLocal", name = "index_OcsProjectResource_lastModifiedLocal"), + @Index(value = {"accountId", "id", "idString", "projectId"}, name = "index_OcsProjectResource_accountId_id", unique = true), + @Index(value = "accountId", name = "index_projectResource_accID"), + @Index(value = "projectId", name = "index_projectResource_projectId"), + }, + foreignKeys = { + @ForeignKey( + entity = OcsProject.class, + parentColumns = "localId", + childColumns = "projectId", onDelete = ForeignKey.CASCADE + ) + } +) +public class OcsProjectResource extends AbstractRemoteEntity implements Serializable { + @Nullable + private String type; + @Nullable + private String name; + @Nullable + private String link; + @Nullable + private String path; + @Nullable + private String iconUrl; + @Nullable + private String mimetype; + @Nullable + private Boolean previewAvailable; + @Nullable + private String idString; + + + @NonNull + private Long projectId; + + public Long getProjectId() { + return projectId; + } + + public void setProjectId(Long projectId) { + this.projectId = projectId; + } + + @Nullable + public String getType() { + return type; + } + + public void setType(@Nullable String type) { + this.type = type; + } + + @Nullable + public String getName() { + return name; + } + + public void setName(@Nullable String name) { + this.name = name; + } + + /** + * Caution: the Link might be a full url or only the relative path! + * @return The link to the Resource + */ + @Nullable + public String getLink() { + return link; + } + + public void setLink(@Nullable String link) { + this.link = link; + } + + @Nullable + public String getIconUrl() { + return iconUrl; + } + + public void setIconUrl(@Nullable String iconUrl) { + this.iconUrl = iconUrl; + } + + @Nullable + public String getPath() { + return path; + } + + public void setPath(@Nullable String path) { + this.path = path; + } + + @Nullable + public String getMimetype() { + return mimetype; + } + + public void setMimetype(@Nullable String mimetype) { + this.mimetype = mimetype; + } + + public Boolean getPreviewAvailable() { + return Boolean.TRUE.equals(previewAvailable); + } + + public void setPreviewAvailable(@Nullable Boolean previewAvailable) { + this.previewAvailable = previewAvailable; + } + + @Nullable + public String getIdString() { + return idString; + } + + public void setIdString(@Nullable String idString) { + this.idString = idString; + } +} diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/model/ocs/projects/full/OcsProjectWithResources.java b/app/src/main/java/it/niedermann/nextcloud/deck/model/ocs/projects/full/OcsProjectWithResources.java new file mode 100644 index 000000000..257cf6f60 --- /dev/null +++ b/app/src/main/java/it/niedermann/nextcloud/deck/model/ocs/projects/full/OcsProjectWithResources.java @@ -0,0 +1,50 @@ +package it.niedermann.nextcloud.deck.model.ocs.projects.full; + +import androidx.annotation.NonNull; +import androidx.room.Embedded; +import androidx.room.Relation; + +import java.util.List; + +import it.niedermann.nextcloud.deck.model.interfaces.IRemoteEntity; +import it.niedermann.nextcloud.deck.model.ocs.projects.OcsProject; +import it.niedermann.nextcloud.deck.model.ocs.projects.OcsProjectResource; + +public class OcsProjectWithResources implements IRemoteEntity { + @Embedded + public OcsProject project; + + + @Relation(entity = OcsProjectResource.class, parentColumn = "localId", entityColumn = "projectId") + public List<OcsProjectResource> resources; + + public OcsProject getProject() { + return project; + } + + public void setProject(OcsProject project) { + this.project = project; + } + + @NonNull + public List<OcsProjectResource> getResources() { + return resources; + } + + public void setResources(List<OcsProjectResource> resources) { + this.resources = resources; + } + + public String getName() { + return project.getName(); + } + + public void setName(String name) { + project.setName(name); + } + + @Override + public IRemoteEntity getEntity() { + return project; + } +} diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/model/ocs/user/GroupMemberUIDs.java b/app/src/main/java/it/niedermann/nextcloud/deck/model/ocs/user/GroupMemberUIDs.java new file mode 100644 index 000000000..085ca786e --- /dev/null +++ b/app/src/main/java/it/niedermann/nextcloud/deck/model/ocs/user/GroupMemberUIDs.java @@ -0,0 +1,27 @@ +package it.niedermann.nextcloud.deck.model.ocs.user; + +import java.util.ArrayList; +import java.util.List; + +public class GroupMemberUIDs { + private List<String> uids = new ArrayList<>(); + + public List<String> getUids() { + return uids; + } + + public void setUids(List<String> uids) { + this.uids = uids; + } + + @Override + public String toString() { + return "GroupMemberUIDs{" + + "uids=" + uids + + '}'; + } + + public void add(String uid) { + uids.add(uid); + } +} diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/model/ocs/user/OcsUserList.java b/app/src/main/java/it/niedermann/nextcloud/deck/model/ocs/user/OcsUserList.java index a10ae005d..818d5b96e 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/model/ocs/user/OcsUserList.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/model/ocs/user/OcsUserList.java @@ -1,7 +1,16 @@ package it.niedermann.nextcloud.deck.model.ocs.user; import java.util.ArrayList; +import java.util.List; -public class OcsUserList extends ArrayList<String> { - // nothing. +public class OcsUserList { + private List<OcsUser> users = new ArrayList<>(); + + public List<OcsUser> getUsers() { + return users; + } + + public void addUser(OcsUser user) { + this.users.add(user); + } } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/model/relations/UserInBoard.java b/app/src/main/java/it/niedermann/nextcloud/deck/model/relations/UserInBoard.java new file mode 100644 index 000000000..1f167bad1 --- /dev/null +++ b/app/src/main/java/it/niedermann/nextcloud/deck/model/relations/UserInBoard.java @@ -0,0 +1,71 @@ +package it.niedermann.nextcloud.deck.model.relations; + +import androidx.annotation.NonNull; +import androidx.room.Entity; +import androidx.room.ForeignKey; +import androidx.room.Index; + +import it.niedermann.nextcloud.deck.model.Board; +import it.niedermann.nextcloud.deck.model.User; + +@Entity( + primaryKeys = {"userId", "boardId"}, + indices = {@Index("userId"), @Index("boardId"), @Index(name = "unique_idx_user_board", value = {"userId","boardId"}, unique = true)}, + foreignKeys = { + @ForeignKey(entity = User.class, + parentColumns = "localId", + childColumns = "userId", onDelete = ForeignKey.CASCADE), + @ForeignKey(entity = Board.class, + parentColumns = "localId", + childColumns = "boardId", onDelete = ForeignKey.CASCADE) + }) +public class UserInBoard { + @NonNull + private Long userId; + @NonNull + private Long boardId; + + @NonNull + public Long getUserId() { + return userId; + } + + public void setUserId(@NonNull Long userId) { + this.userId = userId; + } + + @NonNull + public Long getBoardId() { + return boardId; + } + + public void setBoardId(@NonNull Long boardId) { + this.boardId = boardId; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + UserInBoard that = (UserInBoard) o; + + if (!userId.equals(that.userId)) return false; + return boardId.equals(that.boardId); + } + + @Override + public int hashCode() { + int result = userId.hashCode(); + result = 31 * result + boardId.hashCode(); + return result; + } + + @Override + public String toString() { + return "UserInGroup{" + + "userId=" + userId + + ", boardId=" + boardId + + '}'; + } +} diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/model/relations/UserInGroup.java b/app/src/main/java/it/niedermann/nextcloud/deck/model/relations/UserInGroup.java new file mode 100644 index 000000000..48e16cce5 --- /dev/null +++ b/app/src/main/java/it/niedermann/nextcloud/deck/model/relations/UserInGroup.java @@ -0,0 +1,70 @@ +package it.niedermann.nextcloud.deck.model.relations; + +import androidx.annotation.NonNull; +import androidx.room.Entity; +import androidx.room.ForeignKey; +import androidx.room.Index; + +import it.niedermann.nextcloud.deck.model.User; + +@Entity( + primaryKeys = {"groupId", "memberId"}, + indices = {@Index("groupId"), @Index("memberId"), @Index(name = "unique_idx_group_member", value = {"groupId","memberId"}, unique = true)}, + foreignKeys = { + @ForeignKey(entity = User.class, + parentColumns = "localId", + childColumns = "groupId", onDelete = ForeignKey.CASCADE), + @ForeignKey(entity = User.class, + parentColumns = "localId", + childColumns = "memberId", onDelete = ForeignKey.CASCADE) + }) +public class UserInGroup { + @NonNull + private Long groupId; + @NonNull + private Long memberId; + + @NonNull + public Long getGroupId() { + return groupId; + } + + public void setGroupId(@NonNull Long groupId) { + this.groupId = groupId; + } + + @NonNull + public Long getMemberId() { + return memberId; + } + + public void setMemberId(@NonNull Long memberId) { + this.memberId = memberId; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + UserInGroup that = (UserInGroup) o; + + if (!groupId.equals(that.groupId)) return false; + return memberId.equals(that.memberId); + } + + @Override + public int hashCode() { + int result = groupId.hashCode(); + result = 31 * result + memberId.hashCode(); + return result; + } + + @Override + public String toString() { + return "UserInGroup{" + + "groupId=" + groupId + + ", memberId=" + memberId + + '}'; + } +} |