From 9d4d509219a43bc7974324dabbd3ff1fd5a4a99b Mon Sep 17 00:00:00 2001 From: Kiru Date: Wed, 4 Sep 2024 16:28:49 +0200 Subject: [PATCH] download to a specific directory resolves #745 --- .../android/ui/photoviewer/PhotoViewer.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/photoviewer/PhotoViewer.java b/mastodon/src/main/java/org/joinmastodon/android/ui/photoviewer/PhotoViewer.java index 7331d0572a..6cfcfc9d2d 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/photoviewer/PhotoViewer.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/photoviewer/PhotoViewer.java @@ -533,7 +533,7 @@ private OutputStream destinationStreamForFile(Attachment att) throws IOException ContentValues values=new ContentValues(); // values.put(MediaStore.Downloads.DOWNLOAD_URI, att.url); values.put(MediaStore.MediaColumns.DISPLAY_NAME, fileName); - values.put(MediaStore.MediaColumns.RELATIVE_PATH, Environment.DIRECTORY_DOWNLOADS); + values.put(MediaStore.MediaColumns.RELATIVE_PATH, Environment.DIRECTORY_DOWNLOADS + "/" + activity.getApplicationInfo().loadLabel(activity.getPackageManager())); String mime=mimeTypeForFileName(fileName); if(mime!=null) values.put(MediaStore.MediaColumns.MIME_TYPE, mime); @@ -541,7 +541,7 @@ private OutputStream destinationStreamForFile(Attachment att) throws IOException Uri itemUri=cr.insert(MediaStore.Files.getContentUri(MediaStore.VOLUME_EXTERNAL_PRIMARY), values); return cr.openOutputStream(itemUri); }else{ - return new FileOutputStream(new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), fileName)); + return new FileOutputStream(new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), activity.getApplicationInfo().loadLabel(activity.getPackageManager()) + "/" + fileName)); } } @@ -568,7 +568,7 @@ private void doSaveCurrentFile(){ }); if(Build.VERSION.SDK_INT<29){ String fileName=Uri.parse(att.url).getLastPathSegment(); - File dstFile=new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), fileName); + File dstFile=new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), activity.getApplicationInfo().loadLabel(activity.getPackageManager()) + "/" + fileName); MediaScannerConnection.scanFile(activity, new String[]{dstFile.getAbsolutePath()}, new String[]{mimeTypeForFileName(fileName)}, null); } }catch(IOException x){ @@ -596,7 +596,7 @@ private void saveViaDownloadManager(Attachment att){ DownloadManager.Request req=new DownloadManager.Request(uri); req.allowScanningByMediaScanner(); req.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); - req.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, uri.getLastPathSegment()); + req.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, activity.getApplicationInfo().loadLabel(activity.getPackageManager()) + "/" + uri.getLastPathSegment()); if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.TIRAMISU) activity.registerReceiver(downloadCompletedReceiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE), Context.RECEIVER_EXPORTED); else @@ -1108,4 +1108,4 @@ public void onCompletion(MediaPlayer mp){ windowView.removeCallbacks(uiAutoHider); } } -} +} \ No newline at end of file