From 78f476eab855f2ac63758720d1889266ecd20da6 Mon Sep 17 00:00:00 2001 From: Stefan Niedermann Date: Sat, 31 Oct 2020 11:28:44 +0100 Subject: Use CameraX Signed-off-by: Stefan Niedermann --- .../it/niedermann/nextcloud/deck/util/AttachmentUtil.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'app/src/main/java/it/niedermann/nextcloud/deck/util') 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); + } } -- cgit v1.2.3