jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/357020 )

Change subject: Change the download location of files
......................................................................


Change the download location of files

Previously the location of the download
was inside app directory. It was changed
to a public directory to,

 - Allow users to easily access the
   downloaded files

 - Allow other media applications to discover
   the files

Things that this commit introduces,

 - Corrected variable names

 - Download files into a subdirectory that identifies
   the app because,

   - It helps the users who download multiple photos

   - It prevents the common "Pictures" folder
     from being cluttered up

Bug: T166434
Change-Id: I6b97b47b9b7dac6e4d3b23a25dda2096b6f55fa3
---
M app/src/main/java/org/wikipedia/gallery/MediaDownloadReceiver.java
1 file changed, 23 insertions(+), 12 deletions(-)

Approvals:
  Dbrant: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/app/src/main/java/org/wikipedia/gallery/MediaDownloadReceiver.java 
b/app/src/main/java/org/wikipedia/gallery/MediaDownloadReceiver.java
index f67f5fb..373a7c3 100644
--- a/app/src/main/java/org/wikipedia/gallery/MediaDownloadReceiver.java
+++ b/app/src/main/java/org/wikipedia/gallery/MediaDownloadReceiver.java
@@ -14,9 +14,12 @@
 import android.support.annotation.Nullable;
 
 import org.wikipedia.R;
+import org.wikipedia.WikipediaApp;
 import org.wikipedia.feed.image.FeaturedImage;
 import org.wikipedia.util.FeedbackUtil;
 import org.wikipedia.util.FileUtil;
+
+import java.io.File;
 
 public class MediaDownloadReceiver extends BroadcastReceiver {
     private static final String FILE_NAMESPACE = "File:";
@@ -30,31 +33,39 @@
     }
 
     public void download(@NonNull FeaturedImage featuredImage) {
-        String filename = FileUtil.sanitizeFileName(featuredImage.title());
-        String targetDirectory = Environment.DIRECTORY_PICTURES;
-        performDownloadRequest(featuredImage.image().source(), 
targetDirectory, filename, null);
+        String targetFileName = 
FileUtil.sanitizeFileName(featuredImage.title());
+        String targetDirectoryType = Environment.DIRECTORY_PICTURES;
+        performDownloadRequest(featuredImage.image().source(), 
targetDirectoryType, targetFileName, null);
     }
 
     public void download(@NonNull GalleryItem galleryItem) {
         String saveFilename = 
FileUtil.sanitizeFileName(trimFileNamespace(galleryItem.getName()));
-        String targetDirectory;
+        String targetDirectoryType;
         if (FileUtil.isVideo(galleryItem.getMimeType())) {
-            targetDirectory = Environment.DIRECTORY_MOVIES;
+            targetDirectoryType = Environment.DIRECTORY_MOVIES;
         } else if (FileUtil.isAudio(galleryItem.getMimeType())) {
-            targetDirectory = Environment.DIRECTORY_MUSIC;
+            targetDirectoryType = Environment.DIRECTORY_MUSIC;
         } else if (FileUtil.isImage(galleryItem.getMimeType())) {
-            targetDirectory = Environment.DIRECTORY_PICTURES;
+            targetDirectoryType = Environment.DIRECTORY_PICTURES;
         } else {
-            targetDirectory = Environment.DIRECTORY_DOWNLOADS;
+            targetDirectoryType = Environment.DIRECTORY_DOWNLOADS;
         }
-        performDownloadRequest(Uri.parse(galleryItem.getUrl()), 
targetDirectory, saveFilename,
+        performDownloadRequest(Uri.parse(galleryItem.getUrl()), 
targetDirectoryType, saveFilename,
                 galleryItem.getMimeType());
     }
 
-    private void performDownloadRequest(@NonNull Uri uri, @NonNull String 
targetDirectory,
-                                        @NonNull String filename, @Nullable 
String mimeType) {
+    private void performDownloadRequest(@NonNull Uri uri, @NonNull String 
targetDirectoryType,
+                                        @NonNull String targetFileName, 
@Nullable String mimeType) {
+        final String targetSubfolderName = 
WikipediaApp.getInstance().getString(R.string.app_name);
+        final File categoryFolder = 
Environment.getExternalStoragePublicDirectory(targetDirectoryType);
+        final File targetFolder = new File(categoryFolder, 
targetSubfolderName);
+        final File targetFile = new File(targetFolder, targetFileName);
+
+        // creates the directory if it doesn't exist else it's harmless
+        targetFolder.mkdir();
+
         DownloadManager.Request request = new DownloadManager.Request(uri);
-        request.setDestinationInExternalFilesDir(activity, targetDirectory, 
filename);
+        request.setDestinationUri(Uri.fromFile(targetFile));
         
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
         if (mimeType != null) {
             request.setMimeType(mimeType);

-- 
To view, visit https://gerrit.wikimedia.org/r/357020
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I6b97b47b9b7dac6e4d3b23a25dda2096b6f55fa3
Gerrit-PatchSet: 4
Gerrit-Project: apps/android/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Kaartic <kaarticsivaraam91...@gmail.com>
Gerrit-Reviewer: Brion VIBBER <br...@wikimedia.org>
Gerrit-Reviewer: Dbrant <dbr...@wikimedia.org>
Gerrit-Reviewer: Mholloway <mhollo...@wikimedia.org>
Gerrit-Reviewer: Niedzielski <sniedziel...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to