Browse Source

Merge pull request #7949 from nextcloud/fix/7651/singlenotification

Dont dismiss notification after each upload/download
Andy Scherzinger 4 years ago
parent
commit
09cead89a9

BIN
screenshots/gplay/debug/com.owncloud.android.ui.fragment.FileDetailFragmentStaticServerIT_showDetailsActivitiesNone_light_white.png


BIN
screenshots/gplay/debug/com.owncloud.android.ui.fragment.FileDetailFragmentStaticServerIT_showDetailsActivities_light_white.png


+ 2 - 0
src/androidTest/java/com/owncloud/android/ui/activity/NotificationsActivityIT.kt

@@ -48,6 +48,8 @@ class NotificationsActivityIT : AbstractIT() {
     fun empty() {
         val sut: NotificationsActivity = activityRule.launchActivity(null)
 
+        waitForIdleSync()
+
         sut.runOnUiThread { sut.populateList(ArrayList<Notification>()) }
 
         shortSleep()

+ 10 - 2
src/androidTest/java/com/owncloud/android/ui/fragment/FileDetailFragmentStaticServerIT.kt

@@ -49,6 +49,8 @@ class FileDetailFragmentStaticServerIT : AbstractIT() {
         sut.addFragment(FileDetailActivitiesFragment.newInstance(file, user))
 
         waitForIdleSync()
+        shortSleep()
+        shortSleep()
         screenshot(sut)
     }
 
@@ -59,6 +61,8 @@ class FileDetailFragmentStaticServerIT : AbstractIT() {
         sut.addFragment(FileDetailSharingFragment.newInstance(file, user))
 
         waitForIdleSync()
+        shortSleep()
+        shortSleep()
         screenshot(sut)
     }
 
@@ -128,6 +132,8 @@ class FileDetailFragmentStaticServerIT : AbstractIT() {
             sut.fileDetailActivitiesFragment.populateList(activities as List<Any>?, true)
         }
 
+        shortSleep()
+        shortSleep()
         screenshot(activity)
     }
 
@@ -145,7 +151,7 @@ class FileDetailFragmentStaticServerIT : AbstractIT() {
         }
 
         shortSleep()
-
+        shortSleep()
         screenshot(activity)
     }
 
@@ -166,7 +172,6 @@ class FileDetailFragmentStaticServerIT : AbstractIT() {
 
         shortSleep()
         shortSleep()
-
         screenshot(activity)
     }
 
@@ -177,6 +182,9 @@ class FileDetailFragmentStaticServerIT : AbstractIT() {
         sut.addFragment(FileDetailFragment.newInstance(file, user, 1))
 
         waitForIdleSync()
+
+        shortSleep()
+        shortSleep()
         screenshot(sut)
     }
 }

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

@@ -69,6 +69,7 @@ import com.owncloud.android.utils.MimeTypeUtil;
 import com.owncloud.android.utils.theme.ThemeColorUtils;
 
 import java.io.File;
+import java.security.SecureRandom;
 import java.util.AbstractList;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -80,6 +81,7 @@ import javax.inject.Inject;
 import androidx.core.app.NotificationCompat;
 import androidx.localbroadcastmanager.content.LocalBroadcastManager;
 import dagger.android.AndroidInjection;
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 
 public class FileDownloader extends Service
         implements OnDatatransferProgressListener, OnAccountsUpdateListener {
@@ -419,6 +421,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);
         }
@@ -612,17 +615,18 @@ public class FileDownloader extends Service
      * @param downloadResult Result of the download operation.
      * @param download       Finished download operation
      */
+    @SuppressFBWarnings("DMI")
     private void notifyDownloadResult(DownloadFileOperation download,
                                       RemoteOperationResult downloadResult) {
         if (mNotificationManager == null) {
             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 +655,7 @@ public class FileDownloader extends Service
                     download, getResources()));
 
             if (mNotificationManager != null) {
-                mNotificationManager.notify(tickerId, mNotificationBuilder.build());
+                mNotificationManager.notify((new SecureRandom()).nextInt(), mNotificationBuilder.build());
 
                 // Remove success notification
                 if (downloadResult.isSuccess()) {

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

@@ -80,6 +80,7 @@ import com.owncloud.android.utils.ErrorMessageAdapter;
 import com.owncloud.android.utils.theme.ThemeColorUtils;
 
 import java.io.File;
+import java.security.SecureRandom;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -92,6 +93,7 @@ import androidx.annotation.NonNull;
 import androidx.core.app.NotificationCompat;
 import androidx.localbroadcastmanager.content.LocalBroadcastManager;
 import dagger.android.AndroidInjection;
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 
 /**
  * Service for uploading files. Invoke using context.startService(...).
@@ -744,6 +746,7 @@ public class FileUploader extends Service
      * @param uploadResult Result of the upload operation.
      * @param upload       Finished upload operation
      */
+    @SuppressFBWarnings("DMI")
     private void notifyUploadResult(UploadFileOperation upload, RemoteOperationResult uploadResult) {
         Log_OC.d(TAG, "NotifyUploadResult with resultCode: " + uploadResult.getCode());
         // cancelled operation or success -> silent removal of progress notification
@@ -751,8 +754,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 +827,10 @@ public class FileUploader extends Service
             }
 
             mNotificationBuilder.setContentText(content);
-            mNotificationManager.notify(tickerId, mNotificationBuilder.build());
+            if (!uploadResult.isSuccess()) {
+                mNotificationManager.notify((new SecureRandom()).nextInt(), mNotificationBuilder.build());
+            }
+
         }
     }
 
@@ -1405,6 +1409,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);
         }