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>2020-06-21 14:54:57 +0300
committerNiedermann IT-Dienstleistungen <stefan-niedermann@users.noreply.github.com>2020-06-21 17:18:46 +0300
commit27623eaac7ccaabba7a4653fdb0152be106e8fbe (patch)
treef0154eea9d2a48ece32f22175c42994fc286db88 /app/src/main/java/it/niedermann/nextcloud/deck/util
parent8344d216c73e19c1ab0afefb531f43dc4eda6fcd (diff)
Only handle content URIs and no longer file uris
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.java55
1 files changed, 24 insertions, 31 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 81d6a8e35..5addd0c34 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
@@ -12,12 +12,9 @@ import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.util.ArrayList;
import java.util.List;
-import java.util.UUID;
import it.niedermann.nextcloud.deck.DeckLog;
-import it.niedermann.nextcloud.deck.model.Attachment;
import it.niedermann.nextcloud.deck.model.full.FullCard;
import it.niedermann.nextcloud.deck.persistence.sync.SyncManager;
@@ -30,44 +27,40 @@ public class AttachmentUtil {
private AttachmentUtil() {
}
- public static String getUrl(String accountUrl, long cardRemoteId, long attachmentRemoteId) {
+ public static String getRemoteUrl(String accountUrl, long cardRemoteId, long attachmentRemoteId) {
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) {
-
- List<Uri> contentUris = new ArrayList<>();
-
for (Parcelable sourceStream : streamsToUpload) {
- Uri sourceUri = (Uri) sourceStream;
- if (sourceUri != null) {
- if (ContentResolver.SCHEME_CONTENT.equals(sourceUri.getScheme())) {
- contentUris.add(sourceUri);
- DeckLog.verbose("--- found content URL, remember for later: " + sourceUri.getPath());
- } else if (ContentResolver.SCHEME_FILE.equals(sourceUri.getScheme())) {
- /// file: uris should point to a local file, should be safe let FileUploader handle them
- DeckLog.verbose("--- found file URL, directly upload: " + sourceUri.getPath());
- syncManager.addAttachmentToCard(fullCard.getAccountId(), fullCard.getCard().getLocalId(), Attachment.getMimetypeForUri(context, sourceUri), new File(sourceUri.getPath()));
+ 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());
+ }
}
- }
- }
-
- if (!contentUris.isEmpty()) {
- /// content: uris will be copied to temporary files before calling {@link FileUploader}
- for (Uri contentUri : contentUris) {
- try {
- DeckLog.verbose("---- so, now copy&upload: " + contentUri.getPath());
- File copiedFile = copyContentUriToTempFile(context, contentUri, fullCard.getAccountId(), fullCard.getCard().getLocalId());
- syncManager.addAttachmentToCard(fullCard.getAccountId(), fullCard.getCard().getLocalId(), context.getContentResolver().getType(contentUri), copiedFile);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
+ }).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 + '/' + UUID.randomUUID() + '/' + UriUtils.getDisplayNameForUri(currentUri, context);
+ String fullTempPath = context.getApplicationContext().getFilesDir().getAbsolutePath() + "/attachments/account-" + accountId + "/card-" + (localId == null ? "pending-creation" : localId) + '/' + UriUtils.getDisplayNameForUri(currentUri, context);
DeckLog.verbose("----- fullTempPath: " + fullTempPath);
InputStream inputStream = context.getContentResolver().openInputStream(currentUri);
if (inputStream == null) {