diff --git a/app/src/main/java/com/nextcloud/client/files/uploader/FileUploadHelper.kt b/app/src/main/java/com/nextcloud/client/files/uploader/FileUploadHelper.kt index 41fa64e005..8249c3b291 100644 --- a/app/src/main/java/com/nextcloud/client/files/uploader/FileUploadHelper.kt +++ b/app/src/main/java/com/nextcloud/client/files/uploader/FileUploadHelper.kt @@ -121,9 +121,7 @@ class FileUploadHelper { @Suppress("ReturnCount") fun isUploading(user: User?, file: OCFile?): Boolean { - if (user == null || file == null || !MainApp.getAppContext() - .isWorkScheduled(BackgroundJobManagerImpl.JOB_FILES_UPLOAD) - ) { + if (user == null || file == null || !backgroundJobManager.isStartFileUploadJobScheduled(user)) { return false } diff --git a/app/src/main/java/com/nextcloud/client/files/uploader/FileUploadWorker.kt b/app/src/main/java/com/nextcloud/client/files/uploader/FileUploadWorker.kt index b7c95bd5dc..c6752c448b 100644 --- a/app/src/main/java/com/nextcloud/client/files/uploader/FileUploadWorker.kt +++ b/app/src/main/java/com/nextcloud/client/files/uploader/FileUploadWorker.kt @@ -216,9 +216,9 @@ class FileUploadWorker( return } - val (tickerId, needsToUpdateCredentials) = getTickerId(uploadResult.code) + val needsToUpdateCredentials = (uploadResult.code == ResultCode.UNAUTHORIZED) notificationManager.run { - notifyForResult(tickerId) + notifyForResult(uploadResult.code) setContentIntent(intents.resultIntent(ResultCode.OK, uploadFileOperation)) if (uploadResult.code == ResultCode.SYNC_CONFLICT) { @@ -244,20 +244,6 @@ class FileUploadWorker( } } - private fun getTickerId(resultCode: ResultCode): Pair { - var tickerId = R.string.uploader_upload_failed_ticker - - val needsToUpdateCredentials = (resultCode == ResultCode.UNAUTHORIZED) - - if (needsToUpdateCredentials) { - tickerId = R.string.uploader_upload_failed_credentials_error - } else if (resultCode == ResultCode.SYNC_CONFLICT) { - tickerId = R.string.uploader_upload_failed_sync_conflict_error - } - - return Pair(tickerId, needsToUpdateCredentials) - } - override fun onTransferProgress( progressRate: Long, totalTransferredSoFar: Long, diff --git a/app/src/main/java/com/nextcloud/client/files/uploader/UploadNotificationManager.kt b/app/src/main/java/com/nextcloud/client/files/uploader/UploadNotificationManager.kt index 511385c289..919b1d5dbb 100644 --- a/app/src/main/java/com/nextcloud/client/files/uploader/UploadNotificationManager.kt +++ b/app/src/main/java/com/nextcloud/client/files/uploader/UploadNotificationManager.kt @@ -28,6 +28,7 @@ import android.content.Context import android.graphics.BitmapFactory import androidx.core.app.NotificationCompat import com.owncloud.android.R +import com.owncloud.android.lib.common.operations.RemoteOperationResult import com.owncloud.android.lib.resources.files.FileUtils import com.owncloud.android.operations.UploadFileOperation import com.owncloud.android.ui.notifications.NotificationUtils @@ -51,8 +52,8 @@ class UploadNotificationManager(private val context: Context, private val viewTh private fun initNotificationBuilder() { notificationBuilder = NotificationUtils.newNotificationBuilder(context, viewThemeUtils).apply { - setContentTitle(context.resources.getString(R.string.app_name)) - setContentText(context.resources.getString(R.string.foreground_service_upload)) + setContentTitle(context.getString(R.string.app_name)) + setContentText(context.getString(R.string.worker_upload)) setSmallIcon(R.drawable.notification_icon) setLargeIcon(BitmapFactory.decodeResource(context.resources, R.drawable.notification_icon)) setChannelId(NotificationUtils.NOTIFICATION_CHANNEL_UPLOAD) @@ -91,16 +92,32 @@ class UploadNotificationManager(private val context: Context, private val viewTh } } - fun notifyForResult(tickerId: Int) { + fun notifyForResult(resultCode: RemoteOperationResult.ResultCode) { + val textId = resultText(resultCode) + notificationBuilder - .setTicker(context.getString(tickerId)) - .setContentTitle(context.getString(tickerId)) + .setTicker(context.getString(textId)) + .setContentTitle(context.getString(textId)) .setAutoCancel(true) .setOngoing(false) .setProgress(0, 0, false) .clearActions() } + private fun resultText(resultCode: RemoteOperationResult.ResultCode): Int { + var result = R.string.uploader_upload_failed_ticker + + val needsToUpdateCredentials = (resultCode == RemoteOperationResult.ResultCode.UNAUTHORIZED) + + if (needsToUpdateCredentials) { + result = R.string.uploader_upload_failed_credentials_error + } else if (resultCode == RemoteOperationResult.ResultCode.SYNC_CONFLICT) { + result = R.string.uploader_upload_failed_sync_conflict_error + } + + return result + } + fun setContentIntent(pendingIntent: PendingIntent) { notificationBuilder.setContentIntent(pendingIntent) } diff --git a/app/src/main/java/com/nextcloud/client/jobs/BackgroundJobManager.kt b/app/src/main/java/com/nextcloud/client/jobs/BackgroundJobManager.kt index ea4c19ac58..eb50a7870e 100644 --- a/app/src/main/java/com/nextcloud/client/jobs/BackgroundJobManager.kt +++ b/app/src/main/java/com/nextcloud/client/jobs/BackgroundJobManager.kt @@ -144,6 +144,7 @@ interface BackgroundJobManager { fun startFilesUploadJob(user: User) fun getFileUploads(user: User): LiveData> fun cancelFilesUploadJob(user: User) + fun isStartFileUploadJobScheduled(user: User): Boolean fun cancelFilesDownloadJob(user: User, fileId: Long) diff --git a/app/src/main/java/com/nextcloud/utils/extensions/ContextExtensions.kt b/app/src/main/java/com/nextcloud/utils/extensions/ContextExtensions.kt index 613599ae06..6dc7dde71e 100644 --- a/app/src/main/java/com/nextcloud/utils/extensions/ContextExtensions.kt +++ b/app/src/main/java/com/nextcloud/utils/extensions/ContextExtensions.kt @@ -27,12 +27,7 @@ import android.content.Context import android.content.Intent import android.content.IntentFilter import android.os.Build -import androidx.work.WorkInfo -import androidx.work.WorkManager -import com.google.common.util.concurrent.ListenableFuture import com.owncloud.android.datamodel.ReceiverFlag -import com.owncloud.android.lib.common.utils.Log_OC -import java.util.concurrent.ExecutionException @SuppressLint("UnspecifiedRegisterReceiverFlag") fun Context.registerBroadcastReceiver(receiver: BroadcastReceiver?, filter: IntentFilter, flag: ReceiverFlag): Intent? { @@ -42,25 +37,3 @@ fun Context.registerBroadcastReceiver(receiver: BroadcastReceiver?, filter: Inte registerReceiver(receiver, filter) } } - -fun Context.isWorkScheduled(tag: String): Boolean { - val instance = WorkManager.getInstance(this) - val statuses: ListenableFuture> = instance.getWorkInfosByTag(tag) - var running = false - var workInfoList: List = emptyList() - - try { - workInfoList = statuses.get() - } catch (e: ExecutionException) { - Log_OC.d("Worker", "ExecutionException in isWorkScheduled: $e") - } catch (e: InterruptedException) { - Log_OC.d("Worker", "InterruptedException in isWorkScheduled: $e") - } - - for (workInfo in workInfoList) { - val state = workInfo.state - running = running || (state == WorkInfo.State.RUNNING || state == WorkInfo.State.ENQUEUED) - } - - return running -} diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3aaa421c18..45edc13964 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -640,7 +640,7 @@  • Resharing is not allowed - Uploading files… + Uploading files… Downloading files… Get source code