mirror of
https://github.com/nextcloud/android.git
synced 2024-11-27 17:46:37 +03:00
make failed notification go away when uploading makes progress
Signed-off-by: Jonas Mayer <jonas.a.mayer@gmx.net>
This commit is contained in:
parent
73ef692040
commit
c8b3f6fd3c
3 changed files with 39 additions and 5 deletions
|
@ -59,7 +59,6 @@ import com.owncloud.android.utils.ErrorMessageAdapter
|
|||
import com.owncloud.android.utils.FilesUploadHelper
|
||||
import com.owncloud.android.utils.theme.ViewThemeUtils
|
||||
import java.io.File
|
||||
import java.security.SecureRandom
|
||||
|
||||
@Suppress("LongParameterList")
|
||||
class FilesUploadWorker(
|
||||
|
@ -261,8 +260,14 @@ class FilesUploadWorker(
|
|||
uploadResult: RemoteOperationResult<Any?>
|
||||
) {
|
||||
Log_OC.d(TAG, "NotifyUploadResult with resultCode: " + uploadResult.code)
|
||||
|
||||
if (uploadResult.isSuccess){
|
||||
cancelOldErrorNotification(uploadFileOperation)
|
||||
return
|
||||
}
|
||||
|
||||
// Only notify if the upload fails
|
||||
if (uploadResult.isSuccess || uploadResult.isCancelled) {
|
||||
if (uploadResult.isCancelled) {
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -312,9 +317,10 @@ class FilesUploadWorker(
|
|||
)
|
||||
}
|
||||
notificationBuilder.setContentText(content)
|
||||
if (!uploadResult.isSuccess) {
|
||||
notificationManager.notify(SecureRandom().nextInt(), notificationBuilder.build())
|
||||
}
|
||||
|
||||
notificationManager.notify(NotificationUtils.createUploadNotificationTag(uploadFileOperation.file),
|
||||
NOTIFICATION_ERROR_ID, notificationBuilder.build())
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -386,10 +392,18 @@ class FilesUploadWorker(
|
|||
totalToTransfer,
|
||||
fileAbsoluteName
|
||||
)
|
||||
currentUploadFileOperation?.let { cancelOldErrorNotification(it) }
|
||||
}
|
||||
lastPercent = percent
|
||||
}
|
||||
|
||||
private fun cancelOldErrorNotification(uploadFileOperation: UploadFileOperation){
|
||||
notificationManager.cancel(NotificationUtils.createUploadNotificationTag(uploadFileOperation.oldFile),
|
||||
NOTIFICATION_ERROR_ID)
|
||||
notificationManager.cancel(NotificationUtils.createUploadNotificationTag(uploadFileOperation.file),
|
||||
NOTIFICATION_ERROR_ID)
|
||||
}
|
||||
|
||||
override fun onStopped() {
|
||||
super.onStopped()
|
||||
currentUploadFileOperation?.cancel(null)
|
||||
|
@ -399,6 +413,7 @@ class FilesUploadWorker(
|
|||
companion object {
|
||||
val TAG: String = FilesUploadWorker::class.java.simpleName
|
||||
private const val FOREGROUND_SERVICE_ID: Int = 412
|
||||
private const val NOTIFICATION_ERROR_ID: Int = 413
|
||||
private const val MAX_PROGRESS: Int = 100
|
||||
const val ACCOUNT = "data_account"
|
||||
var currentUploadFileOperation: UploadFileOperation? = null
|
||||
|
|
|
@ -135,6 +135,7 @@ public class FileUploader extends Service
|
|||
public static final String ACTION_PAUSE_BROADCAST = "PAUSE";
|
||||
|
||||
private static final int FOREGROUND_SERVICE_ID = 411;
|
||||
private static final int NOTIFICATION_ERROR_ID = 410;
|
||||
|
||||
public static final String KEY_FILE = "FILE";
|
||||
public static final String KEY_LOCAL_FILE = "LOCAL_FILE";
|
||||
|
@ -781,6 +782,7 @@ public class FileUploader extends Service
|
|||
mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
||||
}
|
||||
mNotificationManager.notify(FOREGROUND_SERVICE_ID, mNotificationBuilder.build());
|
||||
cancelOldErrorNotification(mCurrentUpload);
|
||||
}
|
||||
mLastPercent = percent;
|
||||
}
|
||||
|
@ -799,6 +801,10 @@ public class FileUploader extends Service
|
|||
mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
||||
}
|
||||
|
||||
if (uploadResult.isSuccess()){
|
||||
cancelOldErrorNotification(upload);
|
||||
}
|
||||
|
||||
// Only notify if the upload fails
|
||||
if (!uploadResult.isCancelled() &&
|
||||
!uploadResult.isSuccess() &&
|
||||
|
@ -1436,6 +1442,14 @@ public class FileUploader extends Service
|
|||
}
|
||||
}
|
||||
|
||||
private void cancelOldErrorNotification(UploadFileOperation uploadFileOperation){
|
||||
if (uploadFileOperation == null) return;
|
||||
mNotificationManager.cancel(NotificationUtils.createUploadNotificationTag(uploadFileOperation.getOldFile()),
|
||||
NOTIFICATION_ERROR_ID);
|
||||
mNotificationManager.cancel(NotificationUtils.createUploadNotificationTag(uploadFileOperation.getFile()),
|
||||
NOTIFICATION_ERROR_ID);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Upload worker. Performs the pending uploads in the order they were requested.
|
||||
|
|
|
@ -25,6 +25,7 @@ import android.os.Handler;
|
|||
import android.os.HandlerThread;
|
||||
import android.os.Process;
|
||||
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
import com.owncloud.android.utils.theme.ViewThemeUtils;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
|
@ -81,4 +82,8 @@ public final class NotificationUtils {
|
|||
((HandlerThread) Thread.currentThread()).getLooper().quit();
|
||||
}, delayInMillis);
|
||||
}
|
||||
|
||||
public static String createUploadNotificationTag(OCFile file){
|
||||
return file.getRemotePath() + file.getStoragePath();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue