diff options
author | Stefan Niedermann <info@niedermann.it> | 2020-10-31 13:28:44 +0300 |
---|---|---|
committer | Stefan Niedermann <info@niedermann.it> | 2020-10-31 13:28:44 +0300 |
commit | 78f476eab855f2ac63758720d1889266ecd20da6 (patch) | |
tree | e9119fb53691dadd54b9c333d8ecd53a14c8c463 /app/src/main/java/it/niedermann/nextcloud/deck/util | |
parent | 96ffc2b2d03dab57790d6f4373a01d11e89af838 (diff) |
Use CameraX
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.java | 15 |
1 files changed, 9 insertions, 6 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 f349561de..c68def2de 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 @@ -59,14 +59,13 @@ public class AttachmentUtil { } public static File copyContentUriToTempFile(@NonNull Context context, @NonNull Uri currentUri, long accountId, Long localCardId) throws IOException, IllegalArgumentException { - String fullTempPath = context.getApplicationContext().getFilesDir().getAbsolutePath() + "/attachments/account-" + accountId + "/card-" + (localCardId == null ? "pending-creation" : localCardId) + '/' + UriUtils.getDisplayNameForUri(currentUri, context); - DeckLog.verbose("----- fullTempPath: " + fullTempPath); - InputStream inputStream = context.getContentResolver().openInputStream(currentUri); + final InputStream inputStream = context.getContentResolver().openInputStream(currentUri); if (inputStream == null) { throw new IOException("Could not open input stream for " + currentUri.getPath()); } - File cacheFile = new File(fullTempPath); - File tempDir = cacheFile.getParentFile(); + final File cacheFile = getTempCacheFile(context, accountId, localCardId, UriUtils.getDisplayNameForUri(currentUri, context)); + DeckLog.verbose("----- fullTempPath: " + cacheFile.getAbsolutePath()); + final File tempDir = cacheFile.getParentFile(); if (tempDir == null) { throw new FileNotFoundException("could not cacheFile.getParentFile()"); } @@ -78,7 +77,7 @@ public class AttachmentUtil { if (!cacheFile.createNewFile()) { throw new IOException("Failed to create cacheFile"); } - final FileOutputStream outputStream = new FileOutputStream(fullTempPath); + final FileOutputStream outputStream = new FileOutputStream(cacheFile); byte[] buffer = new byte[4096]; int count; @@ -88,4 +87,8 @@ public class AttachmentUtil { DeckLog.verbose("----- wrote"); return cacheFile; } + + public static File getTempCacheFile(@NonNull Context context, long accountId, Long localCardId, String fileName) { + return new File(context.getApplicationContext().getFilesDir().getAbsolutePath() + "/attachments/account-" + accountId + "/card-" + (localCardId == null ? "pending-creation" : localCardId) + '/' + fileName); + } } |