Skip to content

Commit 79ab1da

Browse files
committed
Kotlin conversion of UploadFileOperation
Signed-off-by: Hannes Achleitner <hannes.software@gmx.at>
1 parent e57afed commit 79ab1da

13 files changed

Lines changed: 1921 additions & 1848 deletions

File tree

.idea/codeStyles/Project.xml

Lines changed: 0 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/androidTest/java/com/owncloud/android/files/services/FileUploaderIT.kt

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ abstract class FileUploaderIT : AbstractOnServerIT() {
7171
//
7272
// assertTrue(
7373
// UploadFileOperation(
74-
// uploadsStorageManager,
74+
// uploadsStorageManager!!,
7575
// connectivityServiceMock,
7676
// powerManagementServiceMock,
7777
// user,
@@ -97,7 +97,7 @@ abstract class FileUploaderIT : AbstractOnServerIT() {
9797
//
9898
// assertTrue(
9999
// UploadFileOperation(
100-
// uploadsStorageManager,
100+
// uploadsStorageManager!!,
101101
// connectivityServiceMock,
102102
// powerManagementServiceMock,
103103
// user,
@@ -175,7 +175,7 @@ abstract class FileUploaderIT : AbstractOnServerIT() {
175175

176176
assertTrue(
177177
UploadFileOperation(
178-
uploadsStorageManager,
178+
uploadsStorageManager!!,
179179
connectivityServiceMock,
180180
powerManagementServiceMock,
181181
user,
@@ -203,7 +203,7 @@ abstract class FileUploaderIT : AbstractOnServerIT() {
203203

204204
assertTrue(
205205
UploadFileOperation(
206-
uploadsStorageManager,
206+
uploadsStorageManager!!,
207207
connectivityServiceMock,
208208
powerManagementServiceMock,
209209
user,
@@ -215,10 +215,11 @@ abstract class FileUploaderIT : AbstractOnServerIT() {
215215
false,
216216
false,
217217
storageManager
218-
)
219-
.addRenameUploadListener {
218+
).addRenameUploadListener(object : UploadFileOperation.OnRenameListener {
219+
override fun onRenameUpload() {
220220
renameListenerWasTriggered = true
221221
}
222+
})
222223
.execute(client)
223224
.isSuccess
224225
)
@@ -294,7 +295,7 @@ abstract class FileUploaderIT : AbstractOnServerIT() {
294295

295296
assertTrue(
296297
UploadFileOperation(
297-
uploadsStorageManager,
298+
uploadsStorageManager!!,
298299
connectivityServiceMock,
299300
powerManagementServiceMock,
300301
user,
@@ -321,7 +322,7 @@ abstract class FileUploaderIT : AbstractOnServerIT() {
321322

322323
assertFalse(
323324
UploadFileOperation(
324-
uploadsStorageManager,
325+
uploadsStorageManager!!,
325326
connectivityServiceMock,
326327
powerManagementServiceMock,
327328
user,
@@ -397,7 +398,7 @@ abstract class FileUploaderIT : AbstractOnServerIT() {
397398

398399
assertTrue(
399400
UploadFileOperation(
400-
uploadsStorageManager,
401+
uploadsStorageManager!!,
401402
connectivityServiceMock,
402403
powerManagementServiceMock,
403404
user,
@@ -423,7 +424,7 @@ abstract class FileUploaderIT : AbstractOnServerIT() {
423424
val ocUpload2 = OCUpload(getDummyFile("empty.txt").absolutePath, "/testFile.txt", account.name)
424425

425426
val uploadResult = UploadFileOperation(
426-
uploadsStorageManager,
427+
uploadsStorageManager!!,
427428
connectivityServiceMock,
428429
powerManagementServiceMock,
429430
user,

app/src/main/java/com/nextcloud/client/jobs/upload/FileUploadWorker.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import kotlinx.coroutines.withContext
5252
import java.io.File
5353
import java.util.concurrent.ConcurrentHashMap
5454
import kotlin.random.Random
55+
import kotlin.time.Duration.Companion.milliseconds
5556

5657
@Suppress("LongParameterList", "TooGenericExceptionCaught")
5758
class FileUploadWorker(
@@ -250,7 +251,7 @@ class FileUploadWorker(
250251
for ((index, upload) in uploads.withIndex()) {
251252
ensureActive()
252253

253-
delay(retryPolicy.getDelay())
254+
delay(retryPolicy.getDelay().milliseconds)
254255

255256
if (!skipAutoUploadCheck && isBelongToAnySyncedFolder(upload, syncFolderHelper, syncedFolders)) {
256257
Log_OC.d(TAG, "skipping upload, will be handled by AutoUploadWorker: ${upload.localPath}")
@@ -368,7 +369,7 @@ class FileUploadWorker(
368369
result = operation.execute(client)
369370
val task = ThumbnailsCacheManager.ThumbnailGenerationTask(storageManager, user)
370371
val file = File(operation.originalStoragePath)
371-
val remoteId: String? = operation.file.remoteId
372+
val remoteId: String? = operation.file!!.remoteId
372373
task.execute(ThumbnailsCacheManager.ThumbnailGenerationTaskObject(file, remoteId))
373374
fileUploadEventBroadcaster.sendUploadStarted(operation, context)
374375
} catch (e: Exception) {
@@ -387,7 +388,7 @@ class FileUploadWorker(
387388
val showSameFileAlreadyExistsNotification =
388389
inputData.getBoolean(SHOW_SAME_FILE_ALREADY_EXISTS_NOTIFICATION, false)
389390
if (showSameFileAlreadyExistsNotification) {
390-
notificationManager.showSameFileAlreadyExistsNotification(operation.fileName)
391+
notificationManager.showSameFileAlreadyExistsNotification(operation.fileName!!)
391392
}
392393
}
393394
},

app/src/main/java/com/nextcloud/client/jobs/upload/UploadNotificationManager.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class UploadNotificationManager(private val context: Context, viewThemeUtils: Vi
9999
setProgress(0, 0, false)
100100
}.build()
101101

102-
showNotification(operation.file.fileId.toInt(), notification)
102+
showNotification(operation.file!!.fileId.toInt(), notification)
103103
}
104104

105105
fun showConnectionErrorNotification() {

app/src/main/java/com/nextcloud/client/jobs/utils/UploadErrorNotificationManager.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ object UploadErrorNotificationManager {
5757
) {
5858
Log_OC.d(TAG, "handle upload result with result code: " + result.code)
5959

60-
if (result.isSuccess || operation.isMissingPermissionThrown) {
60+
if (result.isSuccess || operation.isMissingPermissionThrown()) {
6161
Log_OC.d(TAG, "operation is successful, cancelled or lack of storage permission, notification skipped")
6262
return
6363
}

app/src/main/java/com/owncloud/android/operations/CopyFileOperation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ protected RemoteOperationResult run(OwnCloudClient client) {
7070
if (file.isFolder()) {
7171
targetPath = targetParentPath + file.getFileName();
7272
}
73-
targetPath = UploadFileOperation.getNewAvailableRemotePath(client, targetPath, null, false);
73+
targetPath = UploadFileOperation.Companion.getNewAvailableRemotePath(client, targetPath, null, false);
7474

7575
if (file.isFolder()) {
7676
targetPath += OCFile.PATH_SEPARATOR;

app/src/main/java/com/owncloud/android/operations/UploadException.java

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Nextcloud - Android Client
3+
*
4+
* SPDX-FileCopyrightText: 2019 Andy Scherzinger <info@andy-scherzinger.de>
5+
* SPDX-License-Identifier: AGPL-3.0-or-later OR GPL-2.0-only
6+
*/
7+
package com.owncloud.android.operations
8+
9+
class UploadException : Exception {
10+
11+
constructor(message: String?) : super(message)
12+
13+
companion object {
14+
private const val serialVersionUID = 5931153844211429915L
15+
}
16+
}

0 commit comments

Comments
 (0)