Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/stefan-niedermann/nextcloud-deck.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiedermann IT-Dienstleistungen <stefan-niedermann@users.noreply.github.com>2020-10-03 23:47:12 +0300
committerGitHub <noreply@github.com>2020-10-03 23:47:12 +0300
commit04d85196c4dc37b5ab237191d9f73792fb33a484 (patch)
treec1fd5e6e10034b335b35680c4d517369a7e2234f /app/src/main/java/it/niedermann/nextcloud/deck/model
parent8e0b4546aa33b3215a394e55a8fbee33f72621fb (diff)
🎨 Store colors as integer in database (#603)
* #556 Store colors as integer in database - UI should only use @ColorInt from model * Merge master Signed-off-by: Stefan Niedermann <info@niedermann.it> * #556 Store colors as integer in database Signed-off-by: Stefan Niedermann <info@niedermann.it> * #556 Store colors as integer in database Signed-off-by: Stefan Niedermann <info@niedermann.it> * merged into branch Co-authored-by: desperateCoder <echotodevnull@gmail.com>
Diffstat (limited to 'app/src/main/java/it/niedermann/nextcloud/deck/model')
-rw-r--r--app/src/main/java/it/niedermann/nextcloud/deck/model/Account.java48
-rw-r--r--app/src/main/java/it/niedermann/nextcloud/deck/model/Board.java20
-rw-r--r--app/src/main/java/it/niedermann/nextcloud/deck/model/Label.java35
-rw-r--r--app/src/main/java/it/niedermann/nextcloud/deck/model/ocs/Capabilities.java12
4 files changed, 66 insertions, 49 deletions
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 991a1d495..1c189d162 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")
@@ -62,7 +62,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;
@@ -86,12 +86,12 @@ public class Account implements Serializable {
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();
@@ -141,21 +141,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;
}
@@ -188,6 +190,15 @@ public class Account implements Serializable {
this.etag = etag;
}
+ /**
+ * 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;
@@ -206,15 +217,6 @@ public class Account implements Serializable {
return etag != null ? etag.equals(account.etag) : account.etag == null;
}
- /**
- * 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 int hashCode() {
int result = id != null ? id.hashCode() : 0;
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..fa69e425e 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,5 +1,8 @@
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;
@@ -38,10 +41,7 @@ public class Board extends AbstractRemoteEntity implements Serializable {
private String title;
private long ownerId;
- /**
- * Deck App sends color strings without leading # character
- */
- private String color;
+ private Integer color;
private boolean archived;
private int shared;
private Date deletedAt;
@@ -79,21 +79,27 @@ 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);
+ this.color = Color.parseColor(ColorUtil.formatColorToParsableHexString(color));
} catch (Exception e) {
DeckLog.logError(e);
- this.color = "757575";
+ this.color = 0;
}
}
+ public void setColor(Integer color) {
+ this.color = color;
+ }
+
public boolean isArchived() {
return archived;
}
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..34e05d639 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,5 +1,8 @@
package it.niedermann.nextcloud.deck.model;
+import androidx.annotation.ColorInt;
+import androidx.annotation.NonNull;
+import androidx.room.ColumnInfo;
import androidx.room.Entity;
import androidx.room.ForeignKey;
import androidx.room.Index;
@@ -11,17 +14,20 @@ 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;
+
+ @NonNull
+ @ColumnInfo(defaultValue = "0")
+ private Integer color;
private long boardId;
public Label() {
@@ -42,11 +48,12 @@ public class Label extends AbstractRemoteEntity implements Serializable {
this.title = title;
}
- public String getColor() {
+ @ColorInt
+ public Integer getColor() {
return color;
}
- public void setColor(String color) {
+ public void setColor(Integer color) {
this.color = color;
}
@@ -62,18 +69,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/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;
}