Bug 1238139 - Show snackbar for completed downloads. r? draft
authorSebastian Kaspari <s.kaspari@gmail.com>
Fri, 08 Jan 2016 23:12:31 +0100
changeset 320170 0559e8c2d58e2a6d519bdd5476f012d4d6179981
parent 320169 895e44661a5fcfd826d95c560990ecea25228b25
child 512698 31d22d3d510c8ee1bf2a61a55c04d4bb9abc6a2c
push id9146
push users.kaspari@gmail.com
push dateFri, 08 Jan 2016 22:13:08 +0000
bugs1238139
milestone46.0a1
Bug 1238139 - Show snackbar for completed downloads. r?
mobile/android/locales/en-US/chrome/browser.properties
mobile/android/modules/DownloadNotifications.jsm
--- a/mobile/android/locales/en-US/chrome/browser.properties
+++ b/mobile/android/locales/en-US/chrome/browser.properties
@@ -20,16 +20,18 @@ alertDownloadsStart2=Download starting
 alertDownloadsDone2=Download complete
 alertCantOpenDownload=Can't open file. Tap to save it.
 alertDownloadsSize=Download too big
 alertDownloadsNoSpace=Not enough storage space
 alertDownloadsToast=Download started…
 alertDownloadsPause=Pause
 alertDownloadsResume=Resume
 alertDownloadsCancel=Cancel
+# LOCALIZATION NOTE (alertDownloadSucceeded): %S will be replaced by the file name of the download
+alertDownloadSucceeded=%S downloaded
 # LOCALIZATION NOTE (undoCloseToast.message): This message appears in a toast
 # when the user tries to download something in Guest mode.
 downloads.disabledInGuest=Downloads are disabled in guest sessions
 
 alertFullScreenToast=Press BACK to leave full-screen mode
 
 # LOCALIZATION NOTE (alertSearchEngineAddedToast, alertSearchEngineErrorToast, alertSearchEngineDuplicateToast)
 # %S will be replaced by the name of the search engine (exposed by the current page)
--- a/mobile/android/modules/DownloadNotifications.jsm
+++ b/mobile/android/modules/DownloadNotifications.jsm
@@ -75,16 +75,32 @@ var DownloadNotifications = {
 
     // If this is a new download, show a snackbar as well.
     if (this._viewAdded) {
       Snackbars.show(strings.GetStringFromName("alertDownloadsToast"), Snackbars.LENGTH_LONG);
     }
   },
 
   onDownloadChanged: function (download) {
+    if (download.succeeded) {
+      let file = new FileUtils.File(download.target.path);
+
+      Snackbars.show(strings.formatStringFromName("alertDownloadSucceeded", [file.leafName], 1), Snackbars.LENGTH_LONG, {
+        action: {
+          label: 'Open',
+          callback: () => {
+            try {
+              file.launch();
+            } catch (ex) {
+              this.showInAboutDownloads(download);
+            }
+          }
+        }});
+    }
+
     let notification = notifications.get(download);
     if (!notification) {
       Cu.reportError("Download doesn't have a notification.");
       return;
     }
 
     notification.showOrUpdate();
   },