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:
authorStefan Niedermann <info@niedermann.it>2021-03-11 22:24:30 +0300
committerNiedermann IT-Dienstleistungen <stefan-niedermann@users.noreply.github.com>2021-03-12 00:51:04 +0300
commit4e6d0cf9f8d1ea1b1f48cf4aa9582c73bec26c68 (patch)
tree52b0154ffb04f6eb2a6dc245131a05a1eaea7f81 /app/src/main/java/it/niedermann/nextcloud/deck/util
parent2afb1ba66a2001af5c33b12570750172e3139a70 (diff)
Support Deck API 1.1 (server version 1.3+)
Signed-off-by: Stefan Niedermann <info@niedermann.it>
Diffstat (limited to 'app/src/main/java/it/niedermann/nextcloud/deck/util')
-rw-r--r--app/src/main/java/it/niedermann/nextcloud/deck/util/AttachmentUtil.java44
1 files changed, 32 insertions, 12 deletions
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 aefd14b30..72151832e 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
@@ -21,6 +21,7 @@ import java.io.InputStream;
import it.niedermann.nextcloud.deck.DeckLog;
import it.niedermann.nextcloud.deck.R;
+import it.niedermann.nextcloud.deck.model.Account;
import it.niedermann.nextcloud.deck.model.Attachment;
import it.niedermann.nextcloud.deck.model.enums.EAttachmentType;
import it.niedermann.nextcloud.deck.model.ocs.Version;
@@ -39,43 +40,62 @@ public class AttachmentUtil {
* If a thumbnail is not available (see {@link Version#supportsFileAttachments()}), a link to
* the {@link Attachment} itself will be returned instead.
*/
- public static String getThumbnailUrl(@NonNull Version version, @NonNull String accountUrl, @NonNull Long cardRemoteId, @NonNull Attachment attachment, @Px int previewSize) {
- return version.supportsFileAttachments() &&
+ public static String getThumbnailUrl(@NonNull Account account, @NonNull Long cardRemoteId, @NonNull Attachment attachment, @Px int previewSize) {
+ return getThumbnailUrl(account, cardRemoteId, attachment, previewSize, previewSize);
+ }
+
+ public static String getThumbnailUrl(@NonNull Account account, @NonNull Long cardRemoteId, @NonNull Attachment attachment, @Px int previewWidth, @Px int previewHeight) {
+ return account.getServerDeckVersionAsObject().supportsFileAttachments() &&
EAttachmentType.FILE.equals(attachment.getType()) &&
attachment.getFileId() != null
- ? accountUrl + "/index.php/core/preview?fileId=" + attachment.getFileId() + "&x=" + previewSize + "&y=" + previewSize
- : getRemoteOrLocalUrl(accountUrl, cardRemoteId, attachment);
+ ? account.getUrl() + "/index.php/core/preview?fileId=" + attachment.getFileId() + "&x=" + previewWidth + "&y=" + previewHeight + "&a=true"
+ : getRemoteOrLocalUrl(account.getUrl(), cardRemoteId, attachment);
}
/**
- * @return {@link AttachmentUtil#getRemoteUrl} or {@link Attachment#getLocalPath()} as fallback
+ * @return {@link AttachmentUtil#getDeck_1_0_RemoteUrl} or {@link Attachment#getLocalPath()} as fallback
* in case this {@param attachment} has not yet been synced.
*/
@Nullable
- public static String getRemoteOrLocalUrl(@NonNull String accountUrl, @Nullable Long cardRemoteId, @NonNull Attachment attachment) {
+ private static String getRemoteOrLocalUrl(@NonNull String accountUrl, @Nullable Long cardRemoteId, @NonNull Attachment attachment) {
return (attachment.getId() == null || cardRemoteId == null)
? attachment.getLocalPath()
- : getRemoteUrl(accountUrl, cardRemoteId, attachment.getId());
+ : getDeck_1_0_RemoteUrl(accountUrl, cardRemoteId, attachment.getId());
}
/**
* Tries to open the given {@link Attachment} in web browser. Displays a toast on failure.
*/
- public static void openAttachmentInBrowser(@NonNull Context context, @NonNull String accountUrl, Long cardRemoteId, Long attachmentRemoteId) {
+ public static void openAttachmentInBrowser(@NonNull Account account, @NonNull Context context, Long cardRemoteId, Attachment attachment) {
if (cardRemoteId == null) {
Toast.makeText(context, R.string.card_does_not_yet_exist, Toast.LENGTH_LONG).show();
DeckLog.logError(new IllegalArgumentException("cardRemoteId must not be null."));
return;
}
- if (attachmentRemoteId == null) {
+
+ try {
+ context.startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse(getCopyDownloadUrl(account, cardRemoteId, attachment))));
+ } catch (IllegalArgumentException e) {
Toast.makeText(context, R.string.attachment_does_not_yet_exist, Toast.LENGTH_LONG).show();
DeckLog.logError(new IllegalArgumentException("attachmentRemoteId must not be null."));
- return;
}
- context.startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse(AttachmentUtil.getRemoteUrl(accountUrl, cardRemoteId, attachmentRemoteId))));
}
- private static String getRemoteUrl(@NonNull String accountUrl, @NonNull Long cardRemoteId, @NonNull Long attachmentRemoteId) {
+ public static String getCopyDownloadUrl(@NonNull Account account, @NonNull Long cardRemoteId, @NonNull Attachment attachment) {
+ if (attachment.getId() == null) {
+ throw new IllegalArgumentException("attachment id must not be null");
+ }
+
+ return (attachment.getFileId() != null)
+ ? account.getUrl() + "/f/" + attachment.getFileId()
+ : getDeck_1_0_RemoteUrl(account.getUrl(), cardRemoteId, attachment.getId());
+ }
+
+ /**
+ * Attention! This does only work for attachments of type "deck_file" which are a legacy of Deck API 1.0
+ */
+ @Deprecated
+ private static String getDeck_1_0_RemoteUrl(@NonNull String accountUrl, @NonNull Long cardRemoteId, @NonNull Long attachmentRemoteId) {
return accountUrl + "/index.php/apps/deck/cards/" + cardRemoteId + "/attachment/" + attachmentRemoteId;
}