From ec8902229bc2778003f3615c600d55e5b0ec1a2d Mon Sep 17 00:00:00 2001 From: parneet-guraya Date: Thu, 5 Sep 2024 19:19:22 +0530 Subject: [PATCH 1/5] use coordinator layout to keep the snackbar attached to fragment in pager Signed-off-by: parneet-guraya --- app/src/main/res/layout/preview_image_fragment.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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) --> - - + From 4af24f1fb1a660c0e24acecdb389a35003b95d71 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Mon, 16 Sep 2024 11:33:22 +0200 Subject: [PATCH 2/5] Use Activity When Fragment Added Signed-off-by: alperozturk --- .../utils/extensions/FragmentExtensions.kt | 18 ++++++++++++++++++ .../ui/dialog/CreateFolderDialogFragment.kt | 6 +++--- 2 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 app/src/main/java/com/nextcloud/utils/extensions/FragmentExtensions.kt 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/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) } } } From 7167916db9e271d20ba2226a9093aa48f7d39e47 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Mon, 16 Sep 2024 14:47:52 +0200 Subject: [PATCH 3/5] getUploadByRemotePath in background thread Signed-off-by: alperozturk --- .../client/jobs/upload/FileUploadHelper.kt | 33 +++++++++++++++---- 1 file changed, 26 insertions(+), 7 deletions(-) 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 { From e6ed12830dfacad801ff541acfeb8f6294ed6444 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Mon, 16 Sep 2024 17:51:19 +0200 Subject: [PATCH 4/5] Show new notifications only for file specific errors Signed-off-by: alperozturk --- .../jobs/upload/UploadNotificationManager.kt | 7 +++++- .../RemoteOperationResultExtensions.kt | 23 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) 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/RemoteOperationResultExtensions.kt b/app/src/main/java/com/nextcloud/utils/extensions/RemoteOperationResultExtensions.kt index eacf09a8fe..477c22b5df 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) { From 3fb48c00ee8191e2e4debb3a5314f7184948feac Mon Sep 17 00:00:00 2001 From: alperozturk Date: Tue, 17 Sep 2024 09:27:46 +0200 Subject: [PATCH 5/5] Fix kt spotless check Signed-off-by: alperozturk --- .../utils/extensions/RemoteOperationResultExtensions.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 477c22b5df..f2a4999d50 100644 --- a/app/src/main/java/com/nextcloud/utils/extensions/RemoteOperationResultExtensions.kt +++ b/app/src/main/java/com/nextcloud/utils/extensions/RemoteOperationResultExtensions.kt @@ -63,7 +63,7 @@ fun ResultCode.isFileSpecificError(): Boolean { ResultCode.ACCOUNT_NOT_FOUND, ResultCode.ACCOUNT_USES_STANDARD_PASSWORD, ResultCode.INCORRECT_ADDRESS, - ResultCode.BAD_OC_VERSION, + ResultCode.BAD_OC_VERSION ) return !errorCodes.contains(this)