Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,17 @@ class FileUploadWorker(

val result = uploadFiles()
backgroundJobManager.logEndOfWorker(workerName, result)
notificationManager.dismissNotification()
if (result == Result.success()) {
setIdleWorkerState()
}
result
} catch (t: Throwable) {
Log_OC.e(TAG, "Error caught at FileUploadWorker $t")
cleanup()
Log_OC.e(TAG, "exception $t")
currentUploadFileOperation?.cancel(null)
Result.failure()
} finally {
// Ensure all database operations are complete before signaling completion
uploadsStorageManager.notifyObserversNow()

notificationManager.dismissNotification()
setIdleWorkerState()
}

private suspend fun trySetForeground() {
Expand Down Expand Up @@ -198,20 +200,12 @@ class FileUploadWorker(
.setSilent(true)
.build()

private fun cleanup() {
Log_OC.e(TAG, "FileUploadWorker stopped")

setIdleWorkerState()
currentUploadFileOperation?.cancel(null)
notificationManager.dismissNotification()
}

private fun setWorkerState(user: User?) {
WorkerStateObserver.send(WorkerState.FileUploadStarted(user))
}

private fun setIdleWorkerState() {
WorkerStateObserver.send(WorkerState.FileUploadCompleted(currentUploadFileOperation?.file))
WorkerStateObserver.send(WorkerState.FileUploadCompleted)
}

@Suppress("ReturnCount", "LongMethod", "DEPRECATION")
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/nextcloud/model/WorkerState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ sealed class WorkerState {
data class FileDownloadCompleted(var currentFile: OCFile?) : WorkerState()

data class FileUploadStarted(var user: User?) : WorkerState()
data class FileUploadCompleted(var currentFile: OCFile?) : WorkerState()
object FileUploadCompleted : WorkerState()

data object OfflineOperationsCompleted : WorkerState()
}
Original file line number Diff line number Diff line change
Expand Up @@ -1917,9 +1917,8 @@ class FileDisplayActivity :
}

is FileUploadCompleted -> {
state.currentFile?.let {
ocFileListFragment?.adapter?.insertFile(it)
}
Log_OC.d(TAG, "one or more files are uploaded")
listOfFilesFragment?.listDirectory(currentDir, MainApp.isOnlyOnDevice(), false)
}

is OfflineOperationsCompleted -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1044,24 +1044,4 @@ public void cleanup() {
ocFileListDelegate.cleanup();
helper.cleanup();
}

public void insertFile(@NonNull OCFile file) {
mFiles.add(file);
mFilesAll.add(file);

// Re-sort to maintain order
if (sortOrder != null) {
boolean foldersBeforeFiles = preferences.isSortFoldersBeforeFiles();
boolean favoritesFirst = preferences.isSortFavoritesFirst();
mFiles = sortOrder.sortCloudFiles(mFiles, foldersBeforeFiles, favoritesFirst);
}

// Find actual position and notify
int position = mFiles.indexOf(file);
if (shouldShowHeader()) {
position++;
}

notifyItemInserted(position);
}
}
Loading