diff --git a/app/src/main/java/com/nextcloud/client/jobs/BackgroundJobFactory.kt b/app/src/main/java/com/nextcloud/client/jobs/BackgroundJobFactory.kt index 50deb4beb977..bf8e11eb774e 100644 --- a/app/src/main/java/com/nextcloud/client/jobs/BackgroundJobFactory.kt +++ b/app/src/main/java/com/nextcloud/client/jobs/BackgroundJobFactory.kt @@ -30,7 +30,6 @@ import androidx.work.WorkerFactory import androidx.work.WorkerParameters import com.nextcloud.client.account.UserAccountManager import com.nextcloud.client.core.Clock -import com.nextcloud.client.device.DeviceInfo import com.nextcloud.client.device.PowerManagementService import com.nextcloud.client.documentscan.GeneratePDFUseCase import com.nextcloud.client.documentscan.GeneratePdfFromImagesWork @@ -59,7 +58,6 @@ class BackgroundJobFactory @Inject constructor( private val clock: Clock, private val powerManagementService: PowerManagementService, private val backgroundJobManager: Provider, - private val deviceInfo: DeviceInfo, private val accountManager: UserAccountManager, private val resources: Resources, private val dataProvider: ArbitraryDataProvider, diff --git a/app/src/main/java/com/nextcloud/client/jobs/FilesUploadWorker.kt b/app/src/main/java/com/nextcloud/client/jobs/FilesUploadWorker.kt index 3e57d5ba9ced..774ecfc39292 100644 --- a/app/src/main/java/com/nextcloud/client/jobs/FilesUploadWorker.kt +++ b/app/src/main/java/com/nextcloud/client/jobs/FilesUploadWorker.kt @@ -43,6 +43,7 @@ import com.owncloud.android.datamodel.FileDataStorageManager import com.owncloud.android.datamodel.ThumbnailsCacheManager import com.owncloud.android.datamodel.UploadsStorageManager import com.owncloud.android.db.OCUpload +import com.owncloud.android.db.UploadResult import com.owncloud.android.lib.common.OwnCloudAccount import com.owncloud.android.lib.common.OwnCloudClientManagerFactory import com.owncloud.android.lib.common.network.OnDatatransferProgressListener @@ -50,6 +51,7 @@ import com.owncloud.android.lib.common.operations.RemoteOperationResult import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode import com.owncloud.android.lib.common.utils.Log_OC import com.owncloud.android.lib.resources.files.FileUtils +import com.owncloud.android.lib.resources.users.GetUserInfoRemoteOperation import com.owncloud.android.operations.UploadFileOperation import com.owncloud.android.ui.activity.ConflictsResolveActivity import com.owncloud.android.ui.activity.UploadListActivity @@ -104,9 +106,25 @@ class FilesUploadWorker( private fun handlePendingUploads(uploads: List, accountName: String) { val user = userAccountManager.getUser(accountName) + val factory = OwnCloudClientManagerFactory.getDefaultSingleton() + + for (upload in uploads) { // create upload file operation if (user.isPresent) { + if (upload.lastResult == UploadResult.QUOTA_EXCEEDED) { + val client = factory.getNextcloudClientFor(user.get().toOwnCloudAccount(), context) + val userInfo = GetUserInfoRemoteOperation().execute(client) + + if (userInfo.isSuccess) { + val free = userInfo.resultData.quota?.free ?: -1L + + if (free == -1L || free <= upload.fileSize) { + continue + } + } + } + val uploadFileOperation = createUploadFileOperation(upload, user.get()) val result = upload(uploadFileOperation, user.get()) diff --git a/app/src/main/java/com/owncloud/android/datamodel/UploadsStorageManager.java b/app/src/main/java/com/owncloud/android/datamodel/UploadsStorageManager.java index 0aac8b984abe..33d45e85f9c5 100644 --- a/app/src/main/java/com/owncloud/android/datamodel/UploadsStorageManager.java +++ b/app/src/main/java/com/owncloud/android/datamodel/UploadsStorageManager.java @@ -204,7 +204,9 @@ private int updateUploadInternal(Cursor c, UploadStatus status, UploadResult res + upload.toFormattedString() + ")"); upload.setUploadStatus(status); - upload.setLastResult(result); + if (result != null) { + upload.setLastResult(result); + } upload.setRemotePath(remotePath); if (localPath != null) { upload.setLocalPath(localPath); @@ -687,7 +689,7 @@ public void updateDatabaseUploadStart(UploadFileOperation upload) { updateUploadStatus( upload.getOCUploadId(), UploadStatus.UPLOAD_IN_PROGRESS, - UploadResult.UNKNOWN, + null, upload.getRemotePath(), localPath ); diff --git a/app/src/main/java/com/owncloud/android/db/OCUpload.java b/app/src/main/java/com/owncloud/android/db/OCUpload.java index cf1917f64dc1..5c867cb8df8a 100644 --- a/app/src/main/java/com/owncloud/android/db/OCUpload.java +++ b/app/src/main/java/com/owncloud/android/db/OCUpload.java @@ -196,7 +196,7 @@ public void setDataFixed(FileUploader.FileUploaderBinder binder) { */ public void setUploadStatus(UploadStatus uploadStatus) { this.uploadStatus = uploadStatus; - setLastResult(UploadResult.UNKNOWN); + // setLastResult(UploadResult.UNKNOWN); } /** diff --git a/app/src/main/java/com/owncloud/android/db/UploadResult.java b/app/src/main/java/com/owncloud/android/db/UploadResult.java index 34a6d99d0289..17533f0413be 100644 --- a/app/src/main/java/com/owncloud/android/db/UploadResult.java +++ b/app/src/main/java/com/owncloud/android/db/UploadResult.java @@ -44,7 +44,8 @@ public enum UploadResult { OLD_ANDROID_API(18), SYNC_CONFLICT(19), CANNOT_CREATE_FILE(20), - LOCAL_STORAGE_NOT_COPIED(21); + LOCAL_STORAGE_NOT_COPIED(21), + QUOTA_EXCEEDED(22); private final int value; @@ -104,6 +105,8 @@ public static UploadResult fromValue(int value) { return CANNOT_CREATE_FILE; case 21: return LOCAL_STORAGE_NOT_COPIED; + case 22: + return QUOTA_EXCEEDED; } return UNKNOWN; } @@ -162,6 +165,8 @@ public static UploadResult fromOperationResult(RemoteOperationResult result) { return VIRUS_DETECTED; case CANNOT_CREATE_FILE: return CANNOT_CREATE_FILE; + case QUOTA_EXCEEDED: + return QUOTA_EXCEEDED; default: return UNKNOWN; } diff --git a/app/src/main/java/com/owncloud/android/ui/adapter/UploadListAdapter.java b/app/src/main/java/com/owncloud/android/ui/adapter/UploadListAdapter.java index 0298ef49bc0e..b5d5532fe40f 100755 --- a/app/src/main/java/com/owncloud/android/ui/adapter/UploadListAdapter.java +++ b/app/src/main/java/com/owncloud/android/ui/adapter/UploadListAdapter.java @@ -703,6 +703,9 @@ private String getUploadFailedStatusText(UploadResult result) { case LOCAL_STORAGE_NOT_COPIED: status = parentActivity.getString(R.string.upload_local_storage_not_copied); break; + case QUOTA_EXCEEDED: + status = parentActivity.getString(R.string.quota_exceeded); + break; default: status = parentActivity.getString(R.string.upload_unknown_error); break; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d552f8c69bc1..85362b526f74 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1107,4 +1107,5 @@ Year Year/Month Year/Month/Day + Quota exceeded. Free up some space on server.