diff options
Diffstat (limited to 'app/src')
6 files changed, 25 insertions, 15 deletions
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/api/JsonToEntityParser.java b/app/src/main/java/it/niedermann/nextcloud/deck/api/JsonToEntityParser.java index e57ebe27c..37b38af59 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/api/JsonToEntityParser.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/api/JsonToEntityParser.java @@ -469,7 +469,9 @@ public class JsonToEntityParser { JsonObject extendedData = e.getAsJsonObject("extendedData").getAsJsonObject(); a.setFilesize(extendedData.get("filesize").getAsLong()); a.setMimetype(extendedData.get("mimetype").getAsString()); - a.setFileid(extendedData.get("fileid").getAsLong()); + if (extendedData.has("fileid") && !extendedData.get("fileid").isJsonNull()) { + a.setFileId(extendedData.get("fileid").getAsLong()); + } if (extendedData.has("info") && !extendedData.get("info").isJsonNull()) { JsonObject info = extendedData.getAsJsonObject("info").getAsJsonObject(); a.setDirname(info.get("dirname").getAsString()); 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 cbcd8f4bf..eaa50dfa1 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 @@ -39,7 +39,7 @@ public class Attachment extends AbstractRemoteEntity implements Comparable<Attac private String filename; private String localPath; @Nullable - private Long fileid; + private Long fileId; public long getCardId() { return cardId; @@ -146,12 +146,12 @@ public class Attachment extends AbstractRemoteEntity implements Comparable<Attac } @Nullable - public Long getFileid() { - return this.fileid; + public Long getFileId() { + return this.fileId; } - public void setFileid(@Nullable Long fileid) { - this.fileid = fileid; + public void setFileId(@Nullable Long fileId) { + this.fileId = fileId; } @Override diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/model/enums/EAttachmentType.java b/app/src/main/java/it/niedermann/nextcloud/deck/model/enums/EAttachmentType.java index 60b43c719..92c15d6e0 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/model/enums/EAttachmentType.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/model/enums/EAttachmentType.java @@ -3,7 +3,8 @@ package it.niedermann.nextcloud.deck.model.enums; public enum EAttachmentType { // Do not change values. They match the Deck server apps values. DECK_FILE(1, "deck_file"), - FILE(2, "file"); + FILE(2, "file"), + UNKNOWN(1337, "unknown"); private final int id; private final String value; @@ -23,7 +24,7 @@ public enum EAttachmentType { return s; } } - throw new IllegalArgumentException("unknown " + EAttachmentType.class.getSimpleName() + " value: " + value); + return UNKNOWN; } public String getValue() { diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/DeckDatabase.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/DeckDatabase.java index 9967dcb51..ee2aff1a4 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/DeckDatabase.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/DeckDatabase.java @@ -125,7 +125,7 @@ import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao.widgets.fil FilterWidgetSort.class, }, exportSchema = false, - version = 27 + version = 28 ) @TypeConverters({DateTypeConverter.class, EnumConverter.class}) public abstract class DeckDatabase extends RoomDatabase { @@ -506,6 +506,12 @@ public abstract class DeckDatabase extends RoomDatabase { database.execSQL("DROP TABLE `StackWidgetModel`"); } }; + private static final Migration MIGRATION_27_28 = new Migration(27, 28) { + @Override + public void migrate(SupportSQLiteDatabase database) { + database.execSQL("ALTER TABLE `Attachment` ADD COLUMN `fileId` INTEGER"); + } + }; public static final RoomDatabase.Callback ON_CREATE_CALLBACK = new RoomDatabase.Callback() { @Override @@ -586,6 +592,7 @@ public abstract class DeckDatabase extends RoomDatabase { .addMigrations(MIGRATION_24_25) .addMigrations(MIGRATION_25_26) .addMigrations(MIGRATION_26_27) + .addMigrations(MIGRATION_27_28) .fallbackToDestructiveMigration() .addCallback(ON_CREATE_CALLBACK) .build(); diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/util/AttachmentUtil.java b/app/src/main/java/it/niedermann/nextcloud/deck/util/AttachmentUtil.java index d1567fcf2..aefd14b30 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/util/AttachmentUtil.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/util/AttachmentUtil.java @@ -42,8 +42,8 @@ public class AttachmentUtil { public static String getThumbnailUrl(@NonNull Version version, @NonNull String accountUrl, @NonNull Long cardRemoteId, @NonNull Attachment attachment, @Px int previewSize) { return version.supportsFileAttachments() && EAttachmentType.FILE.equals(attachment.getType()) && - attachment.getFileid() != null - ? accountUrl + "/index.php/core/preview?fileId=" + attachment.getFileid() + "&x=" + previewSize + "&y=" + previewSize + attachment.getFileId() != null + ? accountUrl + "/index.php/core/preview?fileId=" + attachment.getFileId() + "&x=" + previewSize + "&y=" + previewSize : getRemoteOrLocalUrl(accountUrl, cardRemoteId, attachment); } diff --git a/app/src/test/java/it/niedermann/nextcloud/deck/util/AttachmentUtilTest.java b/app/src/test/java/it/niedermann/nextcloud/deck/util/AttachmentUtilTest.java index 6273379e3..653657540 100644 --- a/app/src/test/java/it/niedermann/nextcloud/deck/util/AttachmentUtilTest.java +++ b/app/src/test/java/it/niedermann/nextcloud/deck/util/AttachmentUtilTest.java @@ -24,13 +24,13 @@ public class AttachmentUtilTest { final String accountUrl = "https://example.com"; final Attachment attachment1 = new Attachment(); - attachment1.setFileid(1337L); + attachment1.setFileId(1337L); attachment1.setType(EAttachmentType.FILE); final String thumbnailUrl1 = AttachmentUtil.getThumbnailUrl(versionThatDoesSupportFileAttachments, accountUrl, -1L, attachment1, 500); assertEquals("https://example.com/index.php/core/preview?fileId=1337&x=500&y=500", thumbnailUrl1); final Attachment attachment2 = new Attachment(); - attachment2.setFileid(815L); + attachment2.setFileId(815L); attachment2.setType(EAttachmentType.FILE); final String thumbnailUrl2 = AttachmentUtil.getThumbnailUrl(versionThatDoesSupportFileAttachments, accountUrl, 0L, attachment2, 4711); assertEquals("https://example.com/index.php/core/preview?fileId=815&x=4711&y=4711", thumbnailUrl2); @@ -38,7 +38,7 @@ public class AttachmentUtilTest { // Given there is an invalid fileId... final Attachment attachment3 = new Attachment(); attachment3.setId(999L); - attachment3.setFileid(null); + attachment3.setFileId(null); final String thumbnailUrl3 = AttachmentUtil.getThumbnailUrl(versionThatDoesSupportFileAttachments, accountUrl, 15L, attachment3, 205); // ... a fallback to the attachment itself should be returned assertEquals("https://example.com/index.php/apps/deck/cards/15/attachment/999", thumbnailUrl3); @@ -46,7 +46,7 @@ public class AttachmentUtilTest { // Given the server version does not support file attachments yet... final Attachment attachment4 = new Attachment(); attachment4.setId(111L); - attachment4.setFileid(222L); + attachment4.setFileId(222L); final String thumbnailUrl4 = AttachmentUtil.getThumbnailUrl(versionThatDoesNotSupportFileAttachments, accountUrl, 333L, attachment4, 444); // ... a fallback to the attachment itself should be returned assertEquals("https://example.com/index.php/apps/deck/cards/333/attachment/111", thumbnailUrl4); |