diff --git a/app/src/main/java/com/nextcloud/client/files/downloader/FilesDownloadHelper.kt b/app/src/main/java/com/nextcloud/client/files/downloader/FilesDownloadHelper.kt index 8a0a855f84b5..94803b9b297c 100644 --- a/app/src/main/java/com/nextcloud/client/files/downloader/FilesDownloadHelper.kt +++ b/app/src/main/java/com/nextcloud/client/files/downloader/FilesDownloadHelper.kt @@ -46,7 +46,7 @@ class FilesDownloadHelper { user, ocFile, "", - null, + DownloadType.DOWNLOAD, "", "", null @@ -58,7 +58,7 @@ class FilesDownloadHelper { user, ocFile, behaviour, - null, + DownloadType.DOWNLOAD, "", "", null @@ -82,7 +82,7 @@ class FilesDownloadHelper { user, ocFile, "", - null, + DownloadType.DOWNLOAD, "", "", conflictUploadId diff --git a/app/src/main/java/com/nextcloud/client/files/downloader/FilesDownloadWorker.kt b/app/src/main/java/com/nextcloud/client/files/downloader/FilesDownloadWorker.kt index bb46aa399ddc..b9bd074c64ef 100644 --- a/app/src/main/java/com/nextcloud/client/files/downloader/FilesDownloadWorker.kt +++ b/app/src/main/java/com/nextcloud/client/files/downloader/FilesDownloadWorker.kt @@ -115,7 +115,7 @@ class FilesDownloadWorker( private lateinit var notificationBuilder: NotificationCompat.Builder private val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager private val pendingDownloads = IndexedForest() - private var downloadBinder: IBinder? = null + private var downloadBinder: IBinder = FileDownloaderBinder() private var currentUser = Optional.empty() private var startedDownload = false private var storageManager: FileDataStorageManager? = null @@ -158,6 +158,7 @@ class FilesDownloadWorker( val packageName = inputData.keyValueMap[PACKAGE_NAME] as String val requestedDownloads: AbstractList = Vector() + try { val operation = DownloadFileOperation( user, @@ -169,16 +170,19 @@ class FilesDownloadWorker( downloadType ) operation.addDatatransferProgressListener(this) - operation.addDatatransferProgressListener(downloadBinder as FileDownloaderBinder?) + operation.addDatatransferProgressListener(downloadBinder as FileDownloaderBinder) val putResult = pendingDownloads.putIfAbsent( user?.accountName, file.remotePath, operation ) - val downloadKey = putResult.first - requestedDownloads.add(downloadKey) - sendBroadcastNewDownload(operation, putResult.second) + if (putResult != null) { + val downloadKey = putResult.first + requestedDownloads.add(downloadKey) + sendBroadcastNewDownload(operation, putResult.second) + } + } catch (e: IllegalArgumentException) { Log_OC.e(TAG, "Not enough information provided in intent: " + e.message) } @@ -207,12 +211,14 @@ class FilesDownloadWorker( private fun startDownloadForEachRequest(requestDownloads: AbstractList) { val it: Iterator = requestDownloads.iterator() + while (it.hasNext()) { val next = it.next() Log_OC.e(TAG, "Download Key: $next") - downloadFile(next) } + + startedDownload = false } private fun downloadFile(downloadKey: String) { diff --git a/app/src/main/java/com/owncloud/android/ui/activity/ComponentsGetter.java b/app/src/main/java/com/owncloud/android/ui/activity/ComponentsGetter.java index 4b0ab8c6de2e..9ae88f3c7248 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/ComponentsGetter.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/ComponentsGetter.java @@ -30,7 +30,7 @@ public interface ComponentsGetter { /** * To be invoked when the parent activity is fully created to get a reference - * to the FileDownloader service API. + * to the FileDownloadWorker. */ public FilesDownloadWorker.FileDownloaderBinder getFileDownloaderBinder(); diff --git a/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java b/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java index 9fdd7aff3b21..a49673e778dc 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -94,6 +94,7 @@ import com.owncloud.android.lib.resources.files.SearchRemoteOperation; import com.owncloud.android.operations.CopyFileOperation; import com.owncloud.android.operations.CreateFolderOperation; +import com.owncloud.android.operations.DownloadType; import com.owncloud.android.operations.MoveFileOperation; import com.owncloud.android.operations.RefreshFolderOperation; import com.owncloud.android.operations.RemoveFileOperation; @@ -1953,7 +1954,7 @@ public void run() { private void requestForDownload(OCFile file, String downloadBehaviour, String packageName, String activityName) { final User currentUser = getUser().orElseThrow(RuntimeException::new); if (!mDownloaderBinder.isDownloading(currentUser, mWaitingToPreview)) { - new FilesDownloadHelper().downloadFile(currentUser, file, downloadBehaviour, null, activityName, packageName, null); + new FilesDownloadHelper().downloadFile(currentUser, file, downloadBehaviour, DownloadType.DOWNLOAD, activityName, packageName, null); } }