diff --git a/app/src/main/java/com/nextcloud/client/files/downloader/FileDownloadHelper.kt b/app/src/main/java/com/nextcloud/client/files/downloader/FileDownloadHelper.kt index ecbe944a9a..35288eb166 100644 --- a/app/src/main/java/com/nextcloud/client/files/downloader/FileDownloadHelper.kt +++ b/app/src/main/java/com/nextcloud/client/files/downloader/FileDownloadHelper.kt @@ -80,19 +80,6 @@ class FileDownloadHelper { storageManager?.saveConflict(file, null) } - fun downloadFiles(user: User, ocFile: List, cancelRequest: AtomicBoolean) { - backgroundJobManager.startFilesDownloadJob( - user, - ocFile, - "", - DownloadType.DOWNLOAD, - "", - "", - null, - cancelRequest - ) - } - fun downloadFile(user: User, ocFile: OCFile) { backgroundJobManager.startFileDownloadJob( user, diff --git a/app/src/main/java/com/nextcloud/client/files/downloader/FileDownloadWorker.kt b/app/src/main/java/com/nextcloud/client/files/downloader/FileDownloadWorker.kt index 84d6bfaa24..336557ba98 100644 --- a/app/src/main/java/com/nextcloud/client/files/downloader/FileDownloadWorker.kt +++ b/app/src/main/java/com/nextcloud/client/files/downloader/FileDownloadWorker.kt @@ -34,8 +34,10 @@ import androidx.work.WorkerParameters import com.google.gson.Gson import com.nextcloud.client.account.User import com.nextcloud.client.account.UserAccountManager +import com.nextcloud.client.jobs.BackgroundJobManagerImpl.Companion.JOB_FILES_DOWNLOAD import com.nextcloud.client.notifications.download.DownloadNotificationManager import com.nextcloud.java.util.Optional +import com.nextcloud.utils.extensions.isWorkScheduled import com.owncloud.android.datamodel.FileDataStorageManager import com.owncloud.android.datamodel.OCFile import com.owncloud.android.datamodel.UploadsStorageManager diff --git a/app/src/main/java/com/nextcloud/client/jobs/BackgroundJobManager.kt b/app/src/main/java/com/nextcloud/client/jobs/BackgroundJobManager.kt index 1f3bc87057..f726326574 100644 --- a/app/src/main/java/com/nextcloud/client/jobs/BackgroundJobManager.kt +++ b/app/src/main/java/com/nextcloud/client/jobs/BackgroundJobManager.kt @@ -150,18 +150,6 @@ interface BackgroundJobManager { fun isStartFileDownloadJobScheduled(user: User, file: OCFile): Boolean - @Suppress("LongParameterList") - fun startFilesDownloadJob( - user: User, - files: List, - behaviour: String, - downloadType: DownloadType?, - activityName: String, - packageName: String, - conflictUploadId: Long?, - cancelRequest: AtomicBoolean - ) - @Suppress("LongParameterList") fun startFileDownloadJob( user: User, diff --git a/app/src/main/java/com/nextcloud/client/jobs/BackgroundJobManagerImpl.kt b/app/src/main/java/com/nextcloud/client/jobs/BackgroundJobManagerImpl.kt index 491f03dfc6..79234a8ec8 100644 --- a/app/src/main/java/com/nextcloud/client/jobs/BackgroundJobManagerImpl.kt +++ b/app/src/main/java/com/nextcloud/client/jobs/BackgroundJobManagerImpl.kt @@ -43,12 +43,10 @@ import com.nextcloud.client.files.downloader.FileDownloadWorker import com.nextcloud.client.preferences.AppPreferences import com.nextcloud.utils.extensions.isWorkScheduled import com.owncloud.android.datamodel.OCFile -import com.owncloud.android.lib.common.operations.OperationCancelledException import com.owncloud.android.operations.DownloadType import java.util.Date import java.util.UUID import java.util.concurrent.TimeUnit -import java.util.concurrent.atomic.AtomicBoolean import kotlin.reflect.KClass /** @@ -547,46 +545,6 @@ internal class BackgroundJobManagerImpl( return workManager.isWorkScheduled(startFileDownloadJobTag(user, file)) } - @Throws(OperationCancelledException::class) - override fun startFilesDownloadJob( - user: User, - files: List, - behaviour: String, - downloadType: DownloadType?, - activityName: String, - packageName: String, - conflictUploadId: Long?, - cancelRequest: AtomicBoolean - ) { - val workRequestList = mutableListOf() - - for (file in files) { - synchronized(cancelRequest) { - if (cancelRequest.get()) { - throw OperationCancelledException() - } - - workRequestList.add( - getOneTimeDownloadRequest( - user, - file, - behaviour, - downloadType, - activityName, - packageName, - conflictUploadId - ) - ) - } - } - - val chain = workManager - .beginWith(workRequestList.first()) - .then(workRequestList.subList(1, workRequestList.size)) - - chain.enqueue() - } - override fun startFileDownloadJob( user: User, ocFile: OCFile, diff --git a/app/src/main/java/com/owncloud/android/operations/SynchronizeFolderOperation.java b/app/src/main/java/com/owncloud/android/operations/SynchronizeFolderOperation.java index e69a96821b..0cb9cff609 100644 --- a/app/src/main/java/com/owncloud/android/operations/SynchronizeFolderOperation.java +++ b/app/src/main/java/com/owncloud/android/operations/SynchronizeFolderOperation.java @@ -444,9 +444,17 @@ public class SynchronizeFolderOperation extends SyncOperation { startContentSynchronizations(mFilesToSyncContents); } - private void startDirectDownloads() { + private void startDirectDownloads() throws OperationCancelledException { FileDownloadHelper downloadHelper = new FileDownloadHelper(); - downloadHelper.downloadFiles(user, mFilesForDirectDownload, mCancellationRequested); + + for (OCFile file : mFilesForDirectDownload) { + synchronized(mCancellationRequested) { + if (mCancellationRequested.get()) { + throw new OperationCancelledException(); + } + downloadHelper.downloadFile(user, file); + } + } } /**