diff options
author | desperateCoder <echotodevnull@gmail.com> | 2020-10-04 12:19:17 +0300 |
---|---|---|
committer | desperateCoder <echotodevnull@gmail.com> | 2020-10-04 12:19:17 +0300 |
commit | 180983642de284cf60266c6cedc0012bf1cf4a17 (patch) | |
tree | a29e8cda496d889ed563ec6335a06256dfa393a0 /app/src | |
parent | 79b0f29b0c0b841d102e287975413154a8e31661 (diff) |
fixed color upsync
Diffstat (limited to 'app/src')
4 files changed, 38 insertions, 0 deletions
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/api/json/JsonColorSerializer.java b/app/src/main/java/it/niedermann/nextcloud/deck/api/json/JsonColorSerializer.java new file mode 100644 index 000000000..9ce238236 --- /dev/null +++ b/app/src/main/java/it/niedermann/nextcloud/deck/api/json/JsonColorSerializer.java @@ -0,0 +1,26 @@ +package it.niedermann.nextcloud.deck.api.json; + +import com.google.gson.TypeAdapter; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; + +import java.io.IOException; + +import it.niedermann.nextcloud.deck.util.ColorUtil; + +public class JsonColorSerializer extends TypeAdapter<Integer> { + @Override + public void write(JsonWriter out, Integer value) throws IOException { + if (value == null) { + out.nullValue(); + } else { + out.value(ColorUtil.intColorToHexString(value)); + } + } + + @Override + public Integer read(JsonReader in) throws IOException { + // currently not needed + return null; + } +} 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 895b109e6..ba1abe3c1 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 @@ -8,10 +8,13 @@ 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 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; @@ -41,6 +44,7 @@ public class Board extends AbstractRemoteEntity implements Serializable { private String title; private long ownerId; + @JsonAdapter(JsonColorSerializer.class) private Integer color; private boolean archived; private int shared; 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 e709ae83a..6ae40a5ec 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 @@ -9,9 +9,12 @@ 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.nextcloud.deck.DeckLog; +import it.niedermann.nextcloud.deck.api.json.JsonColorSerializer; import it.niedermann.nextcloud.deck.model.interfaces.AbstractRemoteEntity; import it.niedermann.nextcloud.deck.util.ColorUtil; @@ -29,6 +32,7 @@ import it.niedermann.nextcloud.deck.util.ColorUtil; public class Label extends AbstractRemoteEntity implements Serializable { private String title; + @JsonAdapter(JsonColorSerializer.class) @NonNull @ColumnInfo(defaultValue = "0") private Integer color; diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/util/ColorUtil.java b/app/src/main/java/it/niedermann/nextcloud/deck/util/ColorUtil.java index f84175211..c9a9fd922 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/util/ColorUtil.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/util/ColorUtil.java @@ -179,4 +179,8 @@ public final class ColorUtil { return result; } } + + public static String intColorToHexString(int color) { + return String.format("%06X", (0xFFFFFF & color)); + } } |