From 59d66d986bc12fcd12a1a616d0ae432d5aa6fb60 Mon Sep 17 00:00:00 2001 From: masensio Date: Thu, 29 May 2014 09:21:00 +0200 Subject: [PATCH 1/8] Remove success upload notifications --- .../android/files/services/FileUploader.java | 37 +------------------ 1 file changed, 2 insertions(+), 35 deletions(-) diff --git a/src/com/owncloud/android/files/services/FileUploader.java b/src/com/owncloud/android/files/services/FileUploader.java index c6408c2860..477e6f1ab4 100644 --- a/src/com/owncloud/android/files/services/FileUploader.java +++ b/src/com/owncloud/android/files/services/FileUploader.java @@ -725,42 +725,10 @@ public class FileUploader extends Service implements OnDatatransferProgressListe */ private void notifyUploadResult(RemoteOperationResult uploadResult, UploadFileOperation upload) { Log_OC.d(TAG, "NotifyUploadResult with resultCode: " + uploadResult.getCode()); - if (uploadResult.isCancelled()) { - // / cancelled operation -> silent removal of progress notification + if (uploadResult.isCancelled() || uploadResult.isSuccess()) { + // / cancelled operation or success -> silent removal of progress notification mNotificationManager.cancel(R.string.uploader_upload_in_progress_ticker); - - } else if (uploadResult.isSuccess()) { - // / success -> silent update of progress notification to success - // message - mNotificationBuilder - .setOngoing(false) - .setAutoCancel(true) - .setProgress(0, 0, false); - /// includes a pending intent in the notification showing the details view of the file - Intent showDetailsIntent = null; - if (PreviewImageFragment.canBePreviewed(upload.getFile())) { - showDetailsIntent = new Intent(this, PreviewImageActivity.class); - } else { - showDetailsIntent = new Intent(this, FileDisplayActivity.class); - } - showDetailsIntent.putExtra(FileActivity.EXTRA_FILE, upload.getFile()); - showDetailsIntent.putExtra(FileActivity.EXTRA_ACCOUNT, upload.getAccount()); - showDetailsIntent.putExtra(FileActivity.EXTRA_FROM_NOTIFICATION, true);; - mNotificationBuilder - .setContentIntent(PendingIntent.getActivity( - this, (int) System.currentTimeMillis(), showDetailsIntent, 0 - )) - .setTicker(getString(R.string.uploader_upload_succeeded_ticker)) - .setContentTitle(getString(R.string.uploader_upload_succeeded_ticker)) - .setContentText(ErrorMessageAdapter.getErrorCauseMessage(uploadResult, upload, getResources())); - - mNotificationManager.notify(R.string.uploader_upload_in_progress_ticker, mNotificationBuilder.build()); // NOT - // AN - DbHandler db = new DbHandler(this.getBaseContext()); - db.removeIUPendingFile(mCurrentUpload.getOriginalStoragePath()); - db.close(); - } else { // / fail -> explicit failure notification @@ -841,7 +809,6 @@ public class FileUploader extends Service implements OnDatatransferProgressListe errorBuilder.setContentText(content); mNotificationManager.notify(tickerId, errorBuilder.build()); } - } /** From ac1bbc86460e522e69ba30adc8828d893ad35aa5 Mon Sep 17 00:00:00 2001 From: masensio Date: Thu, 29 May 2014 10:23:35 +0200 Subject: [PATCH 2/8] Remove unnecessary imports in FileUploader --- src/com/owncloud/android/files/services/FileUploader.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/com/owncloud/android/files/services/FileUploader.java b/src/com/owncloud/android/files/services/FileUploader.java index 477e6f1ab4..f65d958d46 100644 --- a/src/com/owncloud/android/files/services/FileUploader.java +++ b/src/com/owncloud/android/files/services/FileUploader.java @@ -52,8 +52,6 @@ import com.owncloud.android.ui.activity.FailedUploadActivity; import com.owncloud.android.ui.activity.FileActivity; import com.owncloud.android.ui.activity.FileDisplayActivity; import com.owncloud.android.ui.activity.InstantUploadActivity; -import com.owncloud.android.ui.preview.PreviewImageActivity; -import com.owncloud.android.ui.preview.PreviewImageFragment; import com.owncloud.android.utils.ErrorMessageAdapter; import com.owncloud.android.utils.Log_OC; import com.owncloud.android.utils.NotificationBuilderWithProgressBar; From c9ce39241ea7e20a791dcd2ba8a8ca8b8bed3c1b Mon Sep 17 00:00:00 2001 From: masensio Date: Thu, 29 May 2014 10:23:41 +0200 Subject: [PATCH 3/8] Remove success download notifications --- .../files/services/FileDownloader.java | 22 ++++--------------- 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/src/com/owncloud/android/files/services/FileDownloader.java b/src/com/owncloud/android/files/services/FileDownloader.java index 7a03135957..1c53bea47c 100644 --- a/src/com/owncloud/android/files/services/FileDownloader.java +++ b/src/com/owncloud/android/files/services/FileDownloader.java @@ -461,9 +461,8 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis */ private void notifyDownloadResult(DownloadFileOperation download, RemoteOperationResult downloadResult) { mNotificationManager.cancel(R.string.downloader_download_in_progress_ticker); - if (!downloadResult.isCancelled()) { - int tickerId = (downloadResult.isSuccess()) ? R.string.downloader_download_succeeded_ticker : - R.string.downloader_download_failed_ticker; + if (!downloadResult.isCancelled() && !downloadResult.isSuccess()) { + int tickerId = R.string.downloader_download_failed_ticker; boolean needsToUpdateCredentials = (downloadResult.getCode() == ResultCode.UNAUTHORIZED || (downloadResult.isIdPRedirection() @@ -494,21 +493,8 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis mDownloadClient = null; // grant that future retries on the same account will get the fresh credentials } else { - Intent showDetailsIntent = null; - if (downloadResult.isSuccess()) { - if (PreviewImageFragment.canBePreviewed(download.getFile())) { - showDetailsIntent = new Intent(this, PreviewImageActivity.class); - } else { - showDetailsIntent = new Intent(this, FileDisplayActivity.class); - } - showDetailsIntent.putExtra(FileActivity.EXTRA_FILE, download.getFile()); - showDetailsIntent.putExtra(FileActivity.EXTRA_ACCOUNT, download.getAccount()); - showDetailsIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - - } else { - // TODO put something smart in showDetailsIntent - showDetailsIntent = new Intent(); - } + // TODO put something smart in showDetailsIntent + Intent showDetailsIntent = new Intent(); mNotificationBuilder .setContentIntent(PendingIntent.getActivity( this, (int) System.currentTimeMillis(), showDetailsIntent, 0)); From c407a568e09de0c13c9a42fcd3e4662e38744cb2 Mon Sep 17 00:00:00 2001 From: masensio Date: Fri, 30 May 2014 12:38:16 +0200 Subject: [PATCH 4/8] Try to reproduce 'Twitter style': notify success and then remove the notification, instead of just removing it --- .../files/services/FileDownloader.java | 19 ++++++-- .../android/files/services/FileUploader.java | 43 ++++++++++++------- 2 files changed, 43 insertions(+), 19 deletions(-) diff --git a/src/com/owncloud/android/files/services/FileDownloader.java b/src/com/owncloud/android/files/services/FileDownloader.java index 1c53bea47c..b525bc4a14 100644 --- a/src/com/owncloud/android/files/services/FileDownloader.java +++ b/src/com/owncloud/android/files/services/FileDownloader.java @@ -461,8 +461,9 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis */ private void notifyDownloadResult(DownloadFileOperation download, RemoteOperationResult downloadResult) { mNotificationManager.cancel(R.string.downloader_download_in_progress_ticker); - if (!downloadResult.isCancelled() && !downloadResult.isSuccess()) { - int tickerId = R.string.downloader_download_failed_ticker; + if (!downloadResult.isCancelled()) { + int tickerId = (downloadResult.isSuccess()) ? R.string.downloader_download_succeeded_ticker : + R.string.downloader_download_failed_ticker; boolean needsToUpdateCredentials = (downloadResult.getCode() == ResultCode.UNAUTHORIZED || (downloadResult.isIdPRedirection() @@ -501,8 +502,20 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis } mNotificationBuilder.setContentText(ErrorMessageAdapter.getErrorCauseMessage(downloadResult, download, getResources())); - mNotificationManager.notify(tickerId, mNotificationBuilder.build()); + + // Remove success notification + if (downloadResult.isSuccess()) { + // Sleep 2 seconds, so show the notification before remove it + Handler handler = new Handler(); + handler.postDelayed(new Runnable() { + public void run() { + mNotificationManager.cancel(R.string.downloader_download_succeeded_ticker); + } + }, 2000); + + } + } } diff --git a/src/com/owncloud/android/files/services/FileUploader.java b/src/com/owncloud/android/files/services/FileUploader.java index f65d958d46..7a04a22d4c 100644 --- a/src/com/owncloud/android/files/services/FileUploader.java +++ b/src/com/owncloud/android/files/services/FileUploader.java @@ -723,16 +723,15 @@ public class FileUploader extends Service implements OnDatatransferProgressListe */ private void notifyUploadResult(RemoteOperationResult uploadResult, UploadFileOperation upload) { Log_OC.d(TAG, "NotifyUploadResult with resultCode: " + uploadResult.getCode()); - if (uploadResult.isCancelled() || uploadResult.isSuccess()) { - // / cancelled operation or success -> silent removal of progress notification - mNotificationManager.cancel(R.string.uploader_upload_in_progress_ticker); + // / cancelled operation or success -> silent removal of progress notification + mNotificationManager.cancel(R.string.uploader_upload_in_progress_ticker); + + // Show the result: success or fail notification + if (!uploadResult.isCancelled()) { + int tickerId = (uploadResult.isSuccess()) ? R.string.uploader_upload_succeeded_ticker : + R.string.uploader_upload_failed_ticker; - } else { - - // / fail -> explicit failure notification - mNotificationManager.cancel(R.string.uploader_upload_in_progress_ticker); - - NotificationCompat.Builder errorBuilder = new NotificationCompat.Builder(this); + NotificationCompat.Builder resultBuilder = new NotificationCompat.Builder(this); String content = null; @@ -740,10 +739,10 @@ public class FileUploader extends Service implements OnDatatransferProgressListe boolean needsToUpdateCredentials = (uploadResult.getCode() == ResultCode.UNAUTHORIZED || (uploadResult.isIdPRedirection() && mUploadClient.getCredentials() == null)); - int tickerId = (needsToUpdateCredentials) ? - R.string.uploader_upload_failed_credentials_error : R.string.uploader_upload_failed_ticker; + tickerId = (needsToUpdateCredentials) ? + R.string.uploader_upload_failed_credentials_error : tickerId; - errorBuilder + resultBuilder .setSmallIcon(R.drawable.notification_icon) .setTicker(getString(tickerId)) .setContentTitle(getString(tickerId)) @@ -759,7 +758,7 @@ public class FileUploader extends Service implements OnDatatransferProgressListe updateAccountCredentials.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); updateAccountCredentials.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); updateAccountCredentials.addFlags(Intent.FLAG_FROM_BACKGROUND); - errorBuilder.setContentIntent(PendingIntent.getActivity( + resultBuilder.setContentIntent(PendingIntent.getActivity( this, (int) System.currentTimeMillis(), updateAccountCredentials, PendingIntent.FLAG_ONE_SHOT )); @@ -777,7 +776,7 @@ public class FileUploader extends Service implements OnDatatransferProgressListe detailUploadIntent = new Intent(this, FailedUploadActivity.class); detailUploadIntent.putExtra(FailedUploadActivity.MESSAGE, content); } - errorBuilder + resultBuilder .setContentIntent(PendingIntent.getActivity( this, (int) System.currentTimeMillis(), detailUploadIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT )) @@ -804,8 +803,20 @@ public class FileUploader extends Service implements OnDatatransferProgressListe } } - errorBuilder.setContentText(content); - mNotificationManager.notify(tickerId, errorBuilder.build()); + resultBuilder.setContentText(content); + mNotificationManager.notify(tickerId, resultBuilder.build()); + + // Remove success notification + if (uploadResult.isSuccess()) { + // Sleep 2 seconds, so show the notification before remove it + Handler handler = new Handler(); + handler.postDelayed(new Runnable() { + public void run() { + mNotificationManager.cancel(R.string.uploader_upload_succeeded_ticker); + } + }, 2000); + + } } } From 17ffd07e36497be3f81b4874229a121f982b2a5e Mon Sep 17 00:00:00 2001 From: "David A. Velasco" Date: Mon, 2 Jun 2014 10:38:14 +0200 Subject: [PATCH 5/8] Cancelation of notifications on success moved to a separate thread --- .../files/services/FileDownloader.java | 11 +++++-- .../android/files/services/FileUploader.java | 13 ++++---- .../NotificationBuilderWithProgressBar.java | 7 +++- .../notifications/NotificationDelayer.java | 33 +++++++++++++++++++ 4 files changed, 54 insertions(+), 10 deletions(-) rename src/com/owncloud/android/{utils => notifications}/NotificationBuilderWithProgressBar.java (96%) create mode 100644 src/com/owncloud/android/notifications/NotificationDelayer.java diff --git a/src/com/owncloud/android/files/services/FileDownloader.java b/src/com/owncloud/android/files/services/FileDownloader.java index b525bc4a14..ba9824ad21 100644 --- a/src/com/owncloud/android/files/services/FileDownloader.java +++ b/src/com/owncloud/android/files/services/FileDownloader.java @@ -36,6 +36,8 @@ import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.lib.common.network.OnDatatransferProgressListener; import com.owncloud.android.lib.common.OwnCloudClientFactory; import com.owncloud.android.lib.common.OwnCloudClient; +import com.owncloud.android.notifications.NotificationBuilderWithProgressBar; +import com.owncloud.android.notifications.NotificationDelayer; import com.owncloud.android.operations.DownloadFileOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; @@ -46,7 +48,6 @@ import com.owncloud.android.ui.preview.PreviewImageActivity; import com.owncloud.android.ui.preview.PreviewImageFragment; import com.owncloud.android.utils.ErrorMessageAdapter; import com.owncloud.android.utils.Log_OC; -import com.owncloud.android.utils.NotificationBuilderWithProgressBar; import android.accounts.Account; import android.accounts.AccountsException; @@ -507,12 +508,18 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis // Remove success notification if (downloadResult.isSuccess()) { // Sleep 2 seconds, so show the notification before remove it + NotificationDelayer.cancelWithDelay( + mNotificationManager, + R.string.downloader_download_succeeded_ticker, + 2000); + /* Handler handler = new Handler(); handler.postDelayed(new Runnable() { public void run() { mNotificationManager.cancel(R.string.downloader_download_succeeded_ticker); } - }, 2000); + }, 2000); + */ } diff --git a/src/com/owncloud/android/files/services/FileUploader.java b/src/com/owncloud/android/files/services/FileUploader.java index 7a04a22d4c..731522cf4d 100644 --- a/src/com/owncloud/android/files/services/FileUploader.java +++ b/src/com/owncloud/android/files/services/FileUploader.java @@ -33,6 +33,8 @@ import com.owncloud.android.authentication.AuthenticatorActivity; import com.owncloud.android.datamodel.FileDataStorageManager; import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.db.DbHandler; +import com.owncloud.android.notifications.NotificationBuilderWithProgressBar; +import com.owncloud.android.notifications.NotificationDelayer; import com.owncloud.android.operations.CreateFolderOperation; import com.owncloud.android.lib.resources.files.RemoteFile; import com.owncloud.android.lib.common.operations.RemoteOperation; @@ -54,7 +56,6 @@ import com.owncloud.android.ui.activity.FileDisplayActivity; import com.owncloud.android.ui.activity.InstantUploadActivity; import com.owncloud.android.utils.ErrorMessageAdapter; import com.owncloud.android.utils.Log_OC; -import com.owncloud.android.utils.NotificationBuilderWithProgressBar; import android.accounts.Account; import android.accounts.AccountManager; @@ -809,12 +810,10 @@ public class FileUploader extends Service implements OnDatatransferProgressListe // Remove success notification if (uploadResult.isSuccess()) { // Sleep 2 seconds, so show the notification before remove it - Handler handler = new Handler(); - handler.postDelayed(new Runnable() { - public void run() { - mNotificationManager.cancel(R.string.uploader_upload_succeeded_ticker); - } - }, 2000); + NotificationDelayer.cancelWithDelay( + mNotificationManager, + R.string.uploader_upload_succeeded_ticker, + 2000); } } diff --git a/src/com/owncloud/android/utils/NotificationBuilderWithProgressBar.java b/src/com/owncloud/android/notifications/NotificationBuilderWithProgressBar.java similarity index 96% rename from src/com/owncloud/android/utils/NotificationBuilderWithProgressBar.java rename to src/com/owncloud/android/notifications/NotificationBuilderWithProgressBar.java index c47e469e89..3b52f6e408 100644 --- a/src/com/owncloud/android/utils/NotificationBuilderWithProgressBar.java +++ b/src/com/owncloud/android/notifications/NotificationBuilderWithProgressBar.java @@ -15,13 +15,17 @@ * */ -package com.owncloud.android.utils; +package com.owncloud.android.notifications; import com.owncloud.android.R; import android.app.Notification; +import android.app.NotificationManager; import android.content.Context; import android.os.Build; +import android.os.Handler; +import android.os.HandlerThread; +import android.os.Process; import android.support.v4.app.NotificationCompat; import android.view.View; import android.widget.RemoteViews; @@ -128,4 +132,5 @@ public class NotificationBuilderWithProgressBar extends NotificationCompat.Build return result; } + } diff --git a/src/com/owncloud/android/notifications/NotificationDelayer.java b/src/com/owncloud/android/notifications/NotificationDelayer.java new file mode 100644 index 0000000000..61cb07b298 --- /dev/null +++ b/src/com/owncloud/android/notifications/NotificationDelayer.java @@ -0,0 +1,33 @@ +package com.owncloud.android.notifications; + +import java.util.Random; + +import android.app.NotificationManager; +import android.os.Handler; +import android.os.HandlerThread; +import android.os.Process; + +public class NotificationDelayer { + + public static void cancelWithDelay( + final NotificationManager notificationManager, + final int notificationId, + long delayInMillis) { + + HandlerThread thread = new HandlerThread( + "NotificationDelayerThread_" + (new Random(System.currentTimeMillis())).nextInt(), + Process.THREAD_PRIORITY_BACKGROUND); + thread.start(); + + Handler handler = new Handler(thread.getLooper()); + handler.postDelayed(new Runnable() { + public void run() { + notificationManager.cancel(notificationId); + ((HandlerThread)Thread.currentThread()).getLooper().quitSafely(); + } + }, delayInMillis); + + } + + +} From 58b70000ae546ef79e40ce04a00c2d6590081b3c Mon Sep 17 00:00:00 2001 From: "David A. Velasco" Date: Mon, 2 Jun 2014 14:32:33 +0200 Subject: [PATCH 6/8] Fixed repeated upload of instant pictures after connectivity recovery --- .../owncloud/android/files/services/FileUploader.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/com/owncloud/android/files/services/FileUploader.java b/src/com/owncloud/android/files/services/FileUploader.java index 731522cf4d..e9d8d1b87f 100644 --- a/src/com/owncloud/android/files/services/FileUploader.java +++ b/src/com/owncloud/android/files/services/FileUploader.java @@ -807,9 +807,13 @@ public class FileUploader extends Service implements OnDatatransferProgressListe resultBuilder.setContentText(content); mNotificationManager.notify(tickerId, resultBuilder.build()); - // Remove success notification - if (uploadResult.isSuccess()) { - // Sleep 2 seconds, so show the notification before remove it + if (uploadResult.isSuccess()) { + + DbHandler db = new DbHandler(this.getBaseContext()); + db.removeIUPendingFile(mCurrentUpload.getOriginalStoragePath()); + db.close(); + + // remove success notification, with a delay of 2 seconds NotificationDelayer.cancelWithDelay( mNotificationManager, R.string.uploader_upload_succeeded_ticker, From 1caeb59e9dd66e7c4cd0ca1b254d54509ae929a8 Mon Sep 17 00:00:00 2001 From: "David A. Velasco" Date: Tue, 3 Jun 2014 08:24:42 +0200 Subject: [PATCH 7/8] Replaced call to 'Looper#quitSafely()' (API 18) for 'Looper#quit()'; shouldn't be a problem --- src/com/owncloud/android/notifications/NotificationDelayer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/com/owncloud/android/notifications/NotificationDelayer.java b/src/com/owncloud/android/notifications/NotificationDelayer.java index 61cb07b298..aeefe12cf9 100644 --- a/src/com/owncloud/android/notifications/NotificationDelayer.java +++ b/src/com/owncloud/android/notifications/NotificationDelayer.java @@ -23,7 +23,7 @@ public class NotificationDelayer { handler.postDelayed(new Runnable() { public void run() { notificationManager.cancel(notificationId); - ((HandlerThread)Thread.currentThread()).getLooper().quitSafely(); + ((HandlerThread)Thread.currentThread()).getLooper().quit(); } }, delayInMillis); From 185aae4bc345f453479f94e2a78da62e8c9930b0 Mon Sep 17 00:00:00 2001 From: "David A. Velasco" Date: Tue, 3 Jun 2014 14:44:45 +0200 Subject: [PATCH 8/8] Removed commented code --- .../owncloud/android/files/services/FileDownloader.java | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/com/owncloud/android/files/services/FileDownloader.java b/src/com/owncloud/android/files/services/FileDownloader.java index ba9824ad21..80d4a6dc47 100644 --- a/src/com/owncloud/android/files/services/FileDownloader.java +++ b/src/com/owncloud/android/files/services/FileDownloader.java @@ -512,15 +512,6 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis mNotificationManager, R.string.downloader_download_succeeded_ticker, 2000); - /* - Handler handler = new Handler(); - handler.postDelayed(new Runnable() { - public void run() { - mNotificationManager.cancel(R.string.downloader_download_succeeded_ticker); - } - }, 2000); - */ - } }