diff options
author | Stefan Niedermann <info@niedermann.it> | 2020-06-21 16:04:42 +0300 |
---|---|---|
committer | Niedermann IT-Dienstleistungen <stefan-niedermann@users.noreply.github.com> | 2020-06-21 17:18:46 +0300 |
commit | f7cca3a2699787728b36268c031d90c99074be8f (patch) | |
tree | 7c761d3f1baed68671d27d4fb0ec7438fc0e1a71 /app/src/main/java/it/niedermann/nextcloud/deck/util | |
parent | 27623eaac7ccaabba7a4653fdb0152be106e8fbe (diff) |
Enhanced exception handling for uploading attachments
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.java | 33 |
1 files changed, 0 insertions, 33 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 5addd0c34..6d8280bec 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 @@ -1,9 +1,7 @@ package it.niedermann.nextcloud.deck.util; -import android.content.ContentResolver; import android.content.Context; import android.net.Uri; -import android.os.Parcelable; import androidx.annotation.NonNull; @@ -12,11 +10,8 @@ import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; -import java.util.List; import it.niedermann.nextcloud.deck.DeckLog; -import it.niedermann.nextcloud.deck.model.full.FullCard; -import it.niedermann.nextcloud.deck.persistence.sync.SyncManager; /** * Created by stefan on 07.03.20. @@ -31,34 +26,6 @@ public class AttachmentUtil { return accountUrl + "/index.php/apps/deck/cards/" + cardRemoteId + "/attachment/" + attachmentRemoteId; } - public static void appendAttachment(@NonNull Context context, @NonNull SyncManager syncManager, @NonNull List<Parcelable> streamsToUpload, @NonNull FullCard fullCard) { - for (Parcelable sourceStream : streamsToUpload) { - new Thread(() -> { - Uri sourceUri = (Uri) sourceStream; - if (sourceUri != null) { - if (ContentResolver.SCHEME_CONTENT.equals(sourceUri.getScheme())) { - /// content: uris will be copied to temporary files before calling {@link FileUploader} - try { - DeckLog.verbose("---- so, now copy & upload: " + sourceUri.getPath()); - File copiedFile = copyContentUriToTempFile(context, sourceUri, fullCard.getAccountId(), fullCard.getCard().getLocalId()); - String mimeType = context.getContentResolver().getType(sourceUri); - if (mimeType == null) { - mimeType = "application/octet-stream"; - } - syncManager.addAttachmentToCard(fullCard.getAccountId(), fullCard.getCard().getLocalId(), mimeType, copiedFile); - } catch (IOException e) { - e.printStackTrace(); - } - DeckLog.verbose("--- found content URL, remember for later: " + sourceUri.getPath()); - } else { //if (ContentResolver.SCHEME_FILE.equals(sourceUri.getScheme())) { - // TODO can not handle this type - DeckLog.verbose("--- found file URL, directly upload: " + sourceUri.getPath()); - } - } - }).start(); - } - } - public static File copyContentUriToTempFile(@NonNull Context context, @NonNull Uri currentUri, long accountId, Long localId) throws IOException { String fullTempPath = context.getApplicationContext().getFilesDir().getAbsolutePath() + "/attachments/account-" + accountId + "/card-" + (localId == null ? "pending-creation" : localId) + '/' + UriUtils.getDisplayNameForUri(currentUri, context); DeckLog.verbose("----- fullTempPath: " + fullTempPath); |