Skip to content
Merged
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
10 changes: 10 additions & 0 deletions app/src/main/java/com/nextcloud/client/database/dao/UploadDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ interface UploadDao {
)
suspend fun updateStatus(remotePath: String, accountName: String, status: Int): Int

@Query(
"""
UPDATE ${ProviderTableMeta.UPLOADS_TABLE_NAME}
SET ${ProviderTableMeta.UPLOADS_STATUS} = :status
WHERE ${ProviderTableMeta.UPLOADS_ACCOUNT_NAME} = :accountName
AND ${ProviderTableMeta.UPLOADS_REMOTE_PATH} IN (:remotePaths)
"""
)
suspend fun updateStatuses(remotePaths: List<String>, accountName: String, status: Int): Int

@Query(
"""
SELECT * FROM ${ProviderTableMeta.UPLOADS_TABLE_NAME}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import com.owncloud.android.utils.FileUtil
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.io.File
import java.util.concurrent.Semaphore
import javax.inject.Inject
Expand Down Expand Up @@ -331,6 +332,11 @@ class FileUploadHelper {
}
}

suspend fun updateUploadStatuses(remotePaths: List<String>, accountName: String, status: UploadStatus) =
withContext(Dispatchers.IO) {
uploadsStorageManager.uploadDao.updateStatuses(remotePaths, accountName, status.value)
}

/**
* Retrieves uploads filtered by their status, optionally for a specific account.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ class FileUploadWorker(
onCompleted()
}

suspend fun cancelUploads(remotePaths: List<String>, accountName: String) {
withContext(Dispatchers.IO) {
remotePaths.forEach {
cancelUpload(it, accountName)
}
}
}

fun getCurrentUpload(id: Long?): UploadFileOperation? = activeOperations[id]

fun isUploading(remotePath: String?, accountName: String?): Boolean = activeOperations.values.any {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,21 +159,16 @@ class UploadListAdapter(
private fun cancelAllCurrentUploads(group: UploadListSection) {
val items = group.items.takeIf { it.isNotEmpty() } ?: return
val accountName = items[0].accountName
var completedCount = 0
items.forEach { upload ->
uploadHelper.updateUploadStatus(
upload.remotePath,
val remotePaths = items.map { it.remotePath }
activity.lifecycleScope.launch(Dispatchers.IO) {
uploadHelper.updateUploadStatuses(
remotePaths,
accountName,
UploadsStorageManager.UploadStatus.UPLOAD_CANCELLED
) {
FileUploadWorker.cancelUpload(upload.remotePath, accountName) {
completedCount++
if (completedCount == items.size) {
Log_OC.d(TAG, "refreshing upload items")
loadUploadItemsFromDb()
}
}
}
)
FileUploadWorker.cancelUploads(remotePaths, accountName)
Log_OC.d(TAG, "refreshing upload items")
loadUploadItemsFromDb()
}
}

Expand Down
Loading