Bladeren bron

Dont dismiss notification after each upload/download

Signed-off-by: Felix Nüsse <felix.nuesse@t-online.de>
Felix Nüsse 4 jaren geleden
bovenliggende
commit
4c77c6ad51

+ 7 - 5
src/main/java/com/owncloud/android/files/services/FileDownloader.java

@@ -73,6 +73,7 @@ import java.util.AbstractList;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
+import java.util.Random;
 import java.util.Vector;
 
 import javax.inject.Inject;
@@ -419,6 +420,7 @@ public class FileDownloader extends Service
                 }
             }
             Log_OC.d(TAG, "Stopping after command with id " + msg.arg1);
+            mService.mNotificationManager.cancel(FOREGROUND_SERVICE_ID);
             mService.stopForeground(true);
             mService.stopSelf(msg.arg1);
         }
@@ -618,11 +620,11 @@ public class FileDownloader extends Service
             mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
         }
 
-        if (mNotificationManager != null) {
-            mNotificationManager.cancel(R.string.downloader_download_in_progress_ticker);
-        }
-
         if (!downloadResult.isCancelled()) {
+            if(downloadResult.isSuccess()){
+                // Dont show notification except an error has occured.
+                return;
+            }
             int tickerId = downloadResult.isSuccess() ?
                     R.string.downloader_download_succeeded_ticker : R.string.downloader_download_failed_ticker;
 
@@ -651,7 +653,7 @@ public class FileDownloader extends Service
                     download, getResources()));
 
             if (mNotificationManager != null) {
-                mNotificationManager.notify(tickerId, mNotificationBuilder.build());
+                mNotificationManager.notify((new Random()).nextInt(), mNotificationBuilder.build());
 
                 // Remove success notification
                 if (downloadResult.isSuccess()) {

+ 6 - 3
src/main/java/com/owncloud/android/files/services/FileUploader.java

@@ -84,6 +84,7 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Random;
 
 import javax.annotation.Nullable;
 import javax.inject.Inject;
@@ -751,8 +752,6 @@ public class FileUploader extends Service
             mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
         }
 
-        mNotificationManager.cancel(FOREGROUND_SERVICE_ID);
-
         // Only notify if the upload fails
         if (!uploadResult.isCancelled() &&
             !uploadResult.isSuccess() &&
@@ -826,7 +825,10 @@ public class FileUploader extends Service
             }
 
             mNotificationBuilder.setContentText(content);
-            mNotificationManager.notify(tickerId, mNotificationBuilder.build());
+            if(!uploadResult.isSuccess()){
+                mNotificationManager.notify((new Random()).nextInt(), mNotificationBuilder.build());
+            }
+
         }
     }
 
@@ -1405,6 +1407,7 @@ public class FileUploader extends Service
                 }
             }
             Log_OC.d(TAG, "Stopping command after id " + msg.arg1);
+            mService.mNotificationManager.cancel(FOREGROUND_SERVICE_ID);
             mService.stopForeground(true);
             mService.stopSelf(msg.arg1);
         }