mirror of
https://github.com/nextcloud/android.git
synced 2024-12-20 07:52:18 +03:00
add cancel sync functionality
Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
parent
0c5db2c5bf
commit
a54bdb7559
5 changed files with 22 additions and 14 deletions
|
@ -172,6 +172,6 @@ interface BackgroundJobManager {
|
|||
fun startPeriodicallyOfflineOperation()
|
||||
fun scheduleInternal2WaySync(intervalMinutes: Long)
|
||||
fun cancelAllFilesDownloadJobs()
|
||||
fun syncFolder(files: List<OCFile>)
|
||||
fun cancelSyncFolder()
|
||||
fun syncFolder(files: List<OCFile>, folderId: Long)
|
||||
fun cancelSyncFolder(folderId: Long)
|
||||
}
|
||||
|
|
|
@ -715,8 +715,7 @@ internal class BackgroundJobManagerImpl(
|
|||
workManager.enqueueUniquePeriodicWork(JOB_INTERNAL_TWO_WAY_SYNC, ExistingPeriodicWorkPolicy.UPDATE, request)
|
||||
}
|
||||
|
||||
// TODO: Add tag for chosen folder
|
||||
override fun syncFolder(files: List<OCFile>) {
|
||||
override fun syncFolder(files: List<OCFile>, folderId: Long) {
|
||||
val filePaths = files.map { it.decryptedRemotePath }
|
||||
|
||||
val data = Data.Builder()
|
||||
|
@ -724,15 +723,14 @@ internal class BackgroundJobManagerImpl(
|
|||
.build()
|
||||
|
||||
val request = oneTimeRequestBuilder(SyncWorker::class, JOB_SYNC_FOLDER)
|
||||
.addTag(JOB_SYNC_FOLDER)
|
||||
.addTag(JOB_SYNC_FOLDER + folderId.toString())
|
||||
.setInputData(data)
|
||||
.build()
|
||||
|
||||
workManager.enqueueUniqueWork(JOB_SYNC_FOLDER, ExistingWorkPolicy.REPLACE, request)
|
||||
}
|
||||
|
||||
// TODO: Add cancellation for chosen folder
|
||||
override fun cancelSyncFolder() {
|
||||
TODO("Not yet implemented")
|
||||
override fun cancelSyncFolder(folderId: Long) {
|
||||
workManager.cancelAllWorkByTag(JOB_SYNC_FOLDER + folderId.toString())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,6 +28,9 @@ class FileDownloadHelper {
|
|||
@Inject
|
||||
lateinit var uploadsStorageManager: UploadsStorageManager
|
||||
|
||||
@Inject
|
||||
lateinit var fileStorageManager: FileDataStorageManager
|
||||
|
||||
companion object {
|
||||
private var instance: FileDownloadHelper? = null
|
||||
|
||||
|
@ -139,6 +142,8 @@ class FileDownloadHelper {
|
|||
}
|
||||
|
||||
fun syncFolder(files: List<OCFile>) {
|
||||
backgroundJobManager.syncFolder(files)
|
||||
val firstFile = files.first()
|
||||
val topParentFileId = fileStorageManager.getTopParentId(firstFile)
|
||||
backgroundJobManager.syncFolder(files, topParentFileId)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ import com.nextcloud.client.account.UserAccountManager
|
|||
import com.nextcloud.client.device.BatteryStatus
|
||||
import com.nextcloud.client.device.PowerManagementService
|
||||
import com.nextcloud.client.jobs.BackgroundJobManager
|
||||
import com.nextcloud.client.jobs.BackgroundJobManagerImpl.Companion.JOB_SYNC_FOLDER
|
||||
import com.nextcloud.client.jobs.upload.FileUploadWorker.Companion.currentUploadFileOperation
|
||||
import com.nextcloud.client.network.Connectivity
|
||||
import com.nextcloud.client.network.ConnectivityService
|
||||
|
@ -245,6 +246,8 @@ class FileUploadHelper {
|
|||
}
|
||||
}
|
||||
|
||||
fun cancelSyncFolder(folderId: Long) = backgroundJobManager.cancelSyncFolder(folderId)
|
||||
|
||||
fun cancelFileUploads(uploads: List<OCUpload>, accountName: String) {
|
||||
for (upload in uploads) {
|
||||
upload.uploadStatus = UploadStatus.UPLOAD_CANCELLED
|
||||
|
|
|
@ -975,18 +975,20 @@ public class FileOperationsHelper {
|
|||
}
|
||||
}
|
||||
|
||||
final var fileUploadHelper = FileUploadHelper.Companion.instance();
|
||||
if (file.isFolder()) {
|
||||
// TODO: Call cancellation function
|
||||
fileUploadHelper.cancelSyncFolder(file.getFileId());
|
||||
}
|
||||
|
||||
if (FileDownloadHelper.Companion.instance().isDownloading(currentUser, file)) {
|
||||
final var fileDownloadHelper = FileDownloadHelper.Companion.instance();
|
||||
if (fileDownloadHelper.isDownloading(currentUser, file)) {
|
||||
List<OCFile> files = fileActivity.getStorageManager().getAllFilesRecursivelyInsideFolder(file);
|
||||
FileDownloadHelper.Companion.instance().cancelPendingOrCurrentDownloads(currentUser, files);
|
||||
fileDownloadHelper.cancelPendingOrCurrentDownloads(currentUser, files);
|
||||
}
|
||||
|
||||
if (FileUploadHelper.Companion.instance().isUploading(currentUser, file)) {
|
||||
if (fileUploadHelper.isUploading(currentUser, file)) {
|
||||
try {
|
||||
FileUploadHelper.Companion.instance().cancelFileUpload(file.getRemotePath(), currentUser.getAccountName());
|
||||
fileUploadHelper.cancelFileUpload(file.getRemotePath(), currentUser.getAccountName());
|
||||
} catch (NoSuchElementException e) {
|
||||
Log_OC.e(TAG, "Error cancelling current upload because user does not exist!");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue