From c6a480b919de42ee2fbb4b5ed68a7fd2303c6435 Mon Sep 17 00:00:00 2001 From: alperozturk Date: Mon, 25 Dec 2023 11:47:56 +0100 Subject: [PATCH] Fix CodeAnalytics Signed-off-by: alperozturk --- .../android/files/services/FileUploaderIT.kt | 2 +- .../files/uploader/UploadNotificationManager.kt | 5 +++-- .../com/nextcloud/client/jobs/FilesUploadWorker.kt | 8 +++----- .../ui/dialog/SetupEncryptionDialogFragment.kt | 2 +- .../owncloud/android/utils/FilesUploadHelper.kt | 14 ++++++++++---- 5 files changed, 18 insertions(+), 13 deletions(-) diff --git a/app/src/androidTest/java/com/owncloud/android/files/services/FileUploaderIT.kt b/app/src/androidTest/java/com/owncloud/android/files/services/FileUploaderIT.kt index b164453597..fc1c08aa3f 100644 --- a/app/src/androidTest/java/com/owncloud/android/files/services/FileUploaderIT.kt +++ b/app/src/androidTest/java/com/owncloud/android/files/services/FileUploaderIT.kt @@ -166,7 +166,7 @@ abstract class FileUploaderIT : AbstractOnServerIT() { user, arrayOf(ocFile2), FilesUploadWorker.LOCAL_BEHAVIOUR_COPY, - NameCollisionPolicy.OVERWRITE, + NameCollisionPolicy.OVERWRITE ) shortSleep() 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 b2db2c331a..92f349204b 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 @@ -67,6 +67,7 @@ class UploadNotificationManager(private val context: Context, private val viewTh notification = notificationBuilder.build() } + @Suppress("MagicNumber") fun notifyForStart(upload: UploadFileOperation, pendingIntent: PendingIntent) { notificationBuilder = NotificationUtils.newNotificationBuilder(context, viewThemeUtils) @@ -90,7 +91,6 @@ class UploadNotificationManager(private val context: Context, private val viewTh pendingIntent ) - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { notificationBuilder.setChannelId(NotificationUtils.NOTIFICATION_CHANNEL_UPLOAD) } @@ -117,7 +117,7 @@ class UploadNotificationManager(private val context: Context, private val viewTh } fun notifyForResult(tickerId: Int) { - notificationBuilder + notificationBuilder .setTicker(context.getString(tickerId)) .setContentTitle(context.getString(tickerId)) .setAutoCancel(true) @@ -158,6 +158,7 @@ class UploadNotificationManager(private val context: Context, private val viewTh notificationManager.notify(WORKER_ID, notificationBuilder.build()) } + @Suppress("MagicNumber") fun updateUploadProgressNotification(filePath: String, percent: Int, currentOperation: UploadFileOperation?) { notificationBuilder.setProgress(100, percent, false) 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 ce49423db8..a027fb50d6 100644 --- a/app/src/main/java/com/nextcloud/client/jobs/FilesUploadWorker.kt +++ b/app/src/main/java/com/nextcloud/client/jobs/FilesUploadWorker.kt @@ -339,9 +339,7 @@ class FilesUploadWorker( FilesUploadHelper().retryUpload(upload, user) } - /** - * Retry a subset of all the stored failed uploads. - */ + @Suppress("ComplexCondition") fun retryFailedUploads( context: Context, uploadsStorageManager: UploadsStorageManager, @@ -351,7 +349,7 @@ class FilesUploadWorker( ) { val failedUploads = uploadsStorageManager.failedUploads if (failedUploads == null || failedUploads.size == 0) { - return //nothing to do + return // nothing to do } val (gotNetwork, _, gotWifi) = connectivityService.connectivity val batteryStatus = powerManagementService.battery @@ -402,6 +400,7 @@ class FilesUploadWorker( return accountName + remotePath } + @Suppress("EmptyIfBlock") class UploadNotificationActionReceiver : BroadcastReceiver() { override fun onReceive(context: Context, intent: Intent) { val accountName = intent.getStringExtra(EXTRA_ACCOUNT_NAME) @@ -418,7 +417,6 @@ class FilesUploadWorker( val uploadHelper = FilesUploadHelper() uploadHelper.cancel(accountName, remotePath, null) } else if (ACTION_PAUSE_BROADCAST == action) { - } else { Log_OC.d(TAG, "Unknown action to perform as UploadNotificationActionReceiver.") } diff --git a/app/src/main/java/com/owncloud/android/ui/dialog/SetupEncryptionDialogFragment.kt b/app/src/main/java/com/owncloud/android/ui/dialog/SetupEncryptionDialogFragment.kt index 8650f1934e..1558ed3af4 100644 --- a/app/src/main/java/com/owncloud/android/ui/dialog/SetupEncryptionDialogFragment.kt +++ b/app/src/main/java/com/owncloud/android/ui/dialog/SetupEncryptionDialogFragment.kt @@ -287,7 +287,7 @@ class SetupEncryptionDialogFragment : DialogFragment(), Injectable { mWeakContext = WeakReference(context) } - @Suppress("ReturnCount") + @Suppress("ReturnCount", "LongMethod") @Deprecated("Deprecated in Java") override fun doInBackground(vararg params: Void?): String? { // fetch private/public key diff --git a/app/src/main/java/com/owncloud/android/utils/FilesUploadHelper.kt b/app/src/main/java/com/owncloud/android/utils/FilesUploadHelper.kt index f0d673b0a5..b7604a6a86 100644 --- a/app/src/main/java/com/owncloud/android/utils/FilesUploadHelper.kt +++ b/app/src/main/java/com/owncloud/android/utils/FilesUploadHelper.kt @@ -46,6 +46,7 @@ import com.owncloud.android.lib.resources.files.model.ServerFileInterface import java.util.concurrent.ExecutionException import javax.inject.Inject +@Suppress("TooManyFunctions") class FilesUploadHelper { @Inject lateinit var backgroundJobManager: BackgroundJobManager @@ -114,7 +115,7 @@ class FilesUploadHelper { createdBy: Int, requiresWifi: Boolean, requiresCharging: Boolean, - nameCollisionPolicy: NameCollisionPolicy, + nameCollisionPolicy: NameCollisionPolicy ) { val uploads = localPaths.mapIndexed { index, localPath -> OCUpload(localPath, remotePaths[index], user.accountName).apply { @@ -144,6 +145,7 @@ class FilesUploadHelper { backgroundJobManager.startFilesUploadJob(user) } + @Suppress("ReturnCount") fun isUploading(user: User?, file: OCFile?): Boolean { if (user == null || file == null || !isWorkScheduled(BackgroundJobManagerImpl.JOB_FILES_UPLOAD)) { return false @@ -153,15 +155,19 @@ class FilesUploadHelper { return upload.uploadStatus == UploadStatus.UPLOAD_IN_PROGRESS } + @Suppress("ReturnCount") fun isUploadingNow(upload: OCUpload?): Boolean { val currentUploadFileOperation = currentUploadFileOperation if (currentUploadFileOperation == null || currentUploadFileOperation.user == null) return false if (upload == null || upload.accountName != currentUploadFileOperation.user.accountName) return false return if (currentUploadFileOperation.oldFile != null) { // For file conflicts check old file remote path - upload.remotePath == currentUploadFileOperation.remotePath || upload.remotePath == currentUploadFileOperation.oldFile!! - .remotePath - } else upload.remotePath == currentUploadFileOperation.remotePath + upload.remotePath == currentUploadFileOperation.remotePath || + upload.remotePath == currentUploadFileOperation.oldFile!! + .remotePath + } else { + upload.remotePath == currentUploadFileOperation.remotePath + } } fun uploadUpdatedFile(