Skip to content

Commit 9d4d509

Browse files
committed
download to a specific directory
resolves #745
1 parent 2c9e92a commit 9d4d509

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

mastodon/src/main/java/org/joinmastodon/android/ui/photoviewer/PhotoViewer.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -533,15 +533,15 @@ private OutputStream destinationStreamForFile(Attachment att) throws IOException
533533
ContentValues values=new ContentValues();
534534
// values.put(MediaStore.Downloads.DOWNLOAD_URI, att.url);
535535
values.put(MediaStore.MediaColumns.DISPLAY_NAME, fileName);
536-
values.put(MediaStore.MediaColumns.RELATIVE_PATH, Environment.DIRECTORY_DOWNLOADS);
536+
values.put(MediaStore.MediaColumns.RELATIVE_PATH, Environment.DIRECTORY_DOWNLOADS + "/" + activity.getApplicationInfo().loadLabel(activity.getPackageManager()));
537537
String mime=mimeTypeForFileName(fileName);
538538
if(mime!=null)
539539
values.put(MediaStore.MediaColumns.MIME_TYPE, mime);
540540
ContentResolver cr=activity.getContentResolver();
541541
Uri itemUri=cr.insert(MediaStore.Files.getContentUri(MediaStore.VOLUME_EXTERNAL_PRIMARY), values);
542542
return cr.openOutputStream(itemUri);
543543
}else{
544-
return new FileOutputStream(new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), fileName));
544+
return new FileOutputStream(new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), activity.getApplicationInfo().loadLabel(activity.getPackageManager()) + "/" + fileName));
545545
}
546546
}
547547

@@ -568,7 +568,7 @@ private void doSaveCurrentFile(){
568568
});
569569
if(Build.VERSION.SDK_INT<29){
570570
String fileName=Uri.parse(att.url).getLastPathSegment();
571-
File dstFile=new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), fileName);
571+
File dstFile=new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), activity.getApplicationInfo().loadLabel(activity.getPackageManager()) + "/" + fileName);
572572
MediaScannerConnection.scanFile(activity, new String[]{dstFile.getAbsolutePath()}, new String[]{mimeTypeForFileName(fileName)}, null);
573573
}
574574
}catch(IOException x){
@@ -596,7 +596,7 @@ private void saveViaDownloadManager(Attachment att){
596596
DownloadManager.Request req=new DownloadManager.Request(uri);
597597
req.allowScanningByMediaScanner();
598598
req.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
599-
req.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, uri.getLastPathSegment());
599+
req.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, activity.getApplicationInfo().loadLabel(activity.getPackageManager()) + "/" + uri.getLastPathSegment());
600600
if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.TIRAMISU)
601601
activity.registerReceiver(downloadCompletedReceiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE), Context.RECEIVER_EXPORTED);
602602
else
@@ -1108,4 +1108,4 @@ public void onCompletion(MediaPlayer mp){
11081108
windowView.removeCallbacks(uiAutoHider);
11091109
}
11101110
}
1111-
}
1111+
}

0 commit comments

Comments
 (0)