diff --git a/app/src/main/java/com/nextcloud/client/jobs/upload/FileUploadHelper.kt b/app/src/main/java/com/nextcloud/client/jobs/upload/FileUploadHelper.kt index 05d9bd1d55..19f5ee3926 100644 --- a/app/src/main/java/com/nextcloud/client/jobs/upload/FileUploadHelper.kt +++ b/app/src/main/java/com/nextcloud/client/jobs/upload/FileUploadHelper.kt @@ -39,6 +39,8 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import java.io.File +import java.util.concurrent.CompletableFuture +import java.util.concurrent.ExecutionException import java.util.concurrent.Semaphore import javax.inject.Inject @@ -57,6 +59,8 @@ class FileUploadHelper { @Inject lateinit var fileStorageManager: FileDataStorageManager + private val ioScope = CoroutineScope(Dispatchers.IO) + init { MainApp.getAppComponent().inject(this) } @@ -231,11 +235,13 @@ class FileUploadHelper { } fun cancelFileUpload(remotePath: String, accountName: String) { - val upload = uploadsStorageManager.getUploadByRemotePath(remotePath) - if (upload != null) { - cancelFileUploads(listOf(upload), accountName) - } else { - Log_OC.e(TAG, "Error cancelling current upload because upload does not exist!") + ioScope.launch { + val upload = uploadsStorageManager.getUploadByRemotePath(remotePath) + if (upload != null) { + cancelFileUploads(listOf(upload), accountName) + } else { + Log_OC.e(TAG, "Error cancelling current upload because upload does not exist!") + } } } @@ -266,8 +272,21 @@ class FileUploadHelper { return false } - val upload: OCUpload = uploadsStorageManager.getUploadByRemotePath(file.remotePath) ?: return false - return upload.uploadStatus == UploadStatus.UPLOAD_IN_PROGRESS + val uploadCompletableFuture = CompletableFuture.supplyAsync { + uploadsStorageManager.getUploadByRemotePath(file.remotePath) + } + return try { + val upload = uploadCompletableFuture.get() + if (upload != null) { + upload.uploadStatus == UploadStatus.UPLOAD_IN_PROGRESS + } else { + false + } + } catch (e: ExecutionException) { + false + } catch (e: InterruptedException) { + false + } } private fun checkConnectivity(connectivityService: ConnectivityService): Boolean { diff --git a/app/src/main/java/com/nextcloud/client/jobs/upload/UploadNotificationManager.kt b/app/src/main/java/com/nextcloud/client/jobs/upload/UploadNotificationManager.kt index 1912070c3b..bade8ed798 100644 --- a/app/src/main/java/com/nextcloud/client/jobs/upload/UploadNotificationManager.kt +++ b/app/src/main/java/com/nextcloud/client/jobs/upload/UploadNotificationManager.kt @@ -10,6 +10,7 @@ package com.nextcloud.client.jobs.upload import android.app.PendingIntent import android.content.Context import com.nextcloud.client.jobs.notification.WorkerNotificationManager +import com.nextcloud.utils.extensions.isFileSpecificError import com.owncloud.android.R import com.owncloud.android.lib.common.operations.RemoteOperationResult import com.owncloud.android.operations.UploadFileOperation @@ -107,7 +108,11 @@ class UploadNotificationManager(private val context: Context, viewThemeUtils: Vi setContentText(errorMessage) } - showNewNotification(uploadFileOperation) + if (resultCode.isFileSpecificError()) { + showNewNotification(uploadFileOperation) + } else { + showNotification() + } } private fun getFailedResultTitleId(resultCode: RemoteOperationResult.ResultCode): Int { diff --git a/app/src/main/java/com/nextcloud/utils/extensions/FragmentExtensions.kt b/app/src/main/java/com/nextcloud/utils/extensions/FragmentExtensions.kt new file mode 100644 index 0000000000..e8a71ea9ee --- /dev/null +++ b/app/src/main/java/com/nextcloud/utils/extensions/FragmentExtensions.kt @@ -0,0 +1,18 @@ +/* + * Nextcloud - Android Client + * + * SPDX-FileCopyrightText: 2024 Alper Ozturk + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +package com.nextcloud.utils.extensions + +import androidx.fragment.app.Fragment + +inline fun Fragment.typedActivity(): T? { + return if (isAdded && activity != null && activity is T) { + activity as T + } else { + null + } +} diff --git a/app/src/main/java/com/nextcloud/utils/extensions/RemoteOperationResultExtensions.kt b/app/src/main/java/com/nextcloud/utils/extensions/RemoteOperationResultExtensions.kt index eacf09a8fe..f2a4999d50 100644 --- a/app/src/main/java/com/nextcloud/utils/extensions/RemoteOperationResultExtensions.kt +++ b/app/src/main/java/com/nextcloud/utils/extensions/RemoteOperationResultExtensions.kt @@ -14,6 +14,7 @@ import com.owncloud.android.datamodel.FileDataStorageManager import com.owncloud.android.datamodel.OCFile import com.owncloud.android.lib.common.operations.RemoteOperation import com.owncloud.android.lib.common.operations.RemoteOperationResult +import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode import com.owncloud.android.lib.resources.files.model.RemoteFile import com.owncloud.android.utils.ErrorMessageAdapter import com.owncloud.android.utils.FileStorageUtils @@ -46,6 +47,28 @@ fun RemoteOperationResult<*>?.getConflictedRemoteIdsWithOfflineOperations( return result.ifEmpty { null } } +fun ResultCode.isFileSpecificError(): Boolean { + val errorCodes = listOf( + ResultCode.INSTANCE_NOT_CONFIGURED, + ResultCode.QUOTA_EXCEEDED, + ResultCode.LOCAL_STORAGE_FULL, + ResultCode.WRONG_CONNECTION, + ResultCode.UNAUTHORIZED, + ResultCode.OK_NO_SSL, + ResultCode.MAINTENANCE_MODE, + ResultCode.UNTRUSTED_DOMAIN, + ResultCode.ACCOUNT_NOT_THE_SAME, + ResultCode.ACCOUNT_EXCEPTION, + ResultCode.ACCOUNT_NOT_NEW, + ResultCode.ACCOUNT_NOT_FOUND, + ResultCode.ACCOUNT_USES_STANDARD_PASSWORD, + ResultCode.INCORRECT_ADDRESS, + ResultCode.BAD_OC_VERSION + ) + + return !errorCodes.contains(this) +} + @Suppress("Deprecation") fun RemoteOperationResult<*>?.toOCFile(): List? { return if (this?.isSuccess == true) { diff --git a/app/src/main/java/com/owncloud/android/ui/dialog/CreateFolderDialogFragment.kt b/app/src/main/java/com/owncloud/android/ui/dialog/CreateFolderDialogFragment.kt index a2fe6821de..80fb96e8dd 100644 --- a/app/src/main/java/com/owncloud/android/ui/dialog/CreateFolderDialogFragment.kt +++ b/app/src/main/java/com/owncloud/android/ui/dialog/CreateFolderDialogFragment.kt @@ -27,6 +27,7 @@ import com.nextcloud.client.account.CurrentAccountProvider import com.nextcloud.client.di.Injectable import com.nextcloud.client.network.ConnectivityService import com.nextcloud.utils.extensions.getParcelableArgument +import com.nextcloud.utils.extensions.typedActivity import com.nextcloud.utils.fileNameValidator.FileNameValidator import com.owncloud.android.R import com.owncloud.android.databinding.EditBoxDialogBinding @@ -185,7 +186,7 @@ class CreateFolderDialogFragment : DialogFragment(), DialogInterface.OnClickList val path = parentFolder?.decryptedRemotePath + newFolderName + OCFile.PATH_SEPARATOR lifecycleScope.launch(Dispatchers.IO) { if (connectivityService.isNetworkAndServerAvailable()) { - (requireActivity() as ComponentsGetter).fileOperationsHelper.createFolder(path) + typedActivity()?.fileOperationsHelper?.createFolder(path) } else { Log_OC.d(TAG, "Network not available, creating offline operation") fileDataStorageManager.addCreateFolderOfflineOperation( @@ -196,8 +197,7 @@ class CreateFolderDialogFragment : DialogFragment(), DialogInterface.OnClickList ) launch(Dispatchers.Main) { - val fileDisplayActivity = requireActivity() as? FileDisplayActivity - fileDisplayActivity?.syncAndUpdateFolder(true) + (requireActivity() as? FileDisplayActivity)?.syncAndUpdateFolder(true) } } } diff --git a/app/src/main/res/layout/preview_image_fragment.xml b/app/src/main/res/layout/preview_image_fragment.xml index f003d954c1..e385e4bff8 100644 --- a/app/src/main/res/layout/preview_image_fragment.xml +++ b/app/src/main/res/layout/preview_image_fragment.xml @@ -9,7 +9,7 @@ ~ SPDX-FileCopyrightText: 2013 David A. Velasco ~ SPDX-License-Identifier: GPL-2.0-only AND (AGPL-3.0-or-later OR GPL-2.0-only) --> - - +