Browse Source

Rebase master

Signed-off-by: alperozturk <alper_ozturk@proton.me>
alperozturk 1 year ago
parent
commit
860e619a63
31 changed files with 283 additions and 1059 deletions
  1. 1 1
      app/src/androidTest/java/com/nextcloud/client/files/downloader/TransferManagerTest.kt
  2. 2 2
      app/src/androidTest/java/com/owncloud/android/files/FileMenuFilterIT.kt
  3. 2 2
      app/src/debug/java/com/nextcloud/test/TestActivity.kt
  4. 1 1
      app/src/main/AndroidManifest.xml
  5. 2 2
      app/src/main/java/com/nextcloud/client/di/AppComponent.java
  6. 0 2
      app/src/main/java/com/nextcloud/client/di/ComponentsModule.java
  7. 1 3
      app/src/main/java/com/nextcloud/client/files/downloader/DownloadTask.kt
  8. 48 56
      app/src/main/java/com/nextcloud/client/files/downloader/FileDownloadHelper.kt
  9. 2 17
      app/src/main/java/com/nextcloud/client/files/downloader/FileDownloadIntents.kt
  10. 143 251
      app/src/main/java/com/nextcloud/client/files/downloader/FileDownloadWorker.kt
  11. 0 150
      app/src/main/java/com/nextcloud/client/files/downloader/FilesDownloadHelper.kt
  12. 0 83
      app/src/main/java/com/nextcloud/client/files/downloader/FilesDownloadIntents.kt
  13. 0 408
      app/src/main/java/com/nextcloud/client/files/downloader/FilesDownloadWorker.kt
  14. 2 2
      app/src/main/java/com/nextcloud/client/files/transfer/TransferManagerImpl.kt
  15. 4 4
      app/src/main/java/com/nextcloud/client/jobs/BackgroundJobFactory.kt
  16. 9 9
      app/src/main/java/com/nextcloud/client/jobs/BackgroundJobManagerImpl.kt
  17. 2 2
      app/src/main/java/com/nextcloud/client/jobs/FilesExportWork.kt
  18. 3 3
      app/src/main/java/com/owncloud/android/files/FileMenuFilter.java
  19. 2 2
      app/src/main/java/com/owncloud/android/operations/SynchronizeFileOperation.java
  20. 2 2
      app/src/main/java/com/owncloud/android/operations/SynchronizeFolderOperation.java
  21. 1 1
      app/src/main/java/com/owncloud/android/providers/DocumentsStorageProvider.java
  22. 8 8
      app/src/main/java/com/owncloud/android/services/SyncFolderHandler.java
  23. 2 2
      app/src/main/java/com/owncloud/android/ui/activity/ComponentsGetter.java
  24. 2 2
      app/src/main/java/com/owncloud/android/ui/activity/ConflictsResolveActivity.kt
  25. 5 5
      app/src/main/java/com/owncloud/android/ui/activity/FileActivity.java
  26. 16 16
      app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java
  27. 4 4
      app/src/main/java/com/owncloud/android/ui/activity/ManageAccountsActivity.java
  28. 4 4
      app/src/main/java/com/owncloud/android/ui/fragment/FileDetailFragment.java
  29. 2 2
      app/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java
  30. 11 11
      app/src/main/java/com/owncloud/android/ui/preview/PreviewImageActivity.java
  31. 2 2
      app/src/main/java/com/owncloud/android/ui/preview/PreviewMediaFragment.java

+ 1 - 1
app/src/androidTest/java/com/nextcloud/client/files/downloader/TransferManagerTest.kt

@@ -107,7 +107,7 @@ class TransferManagerTest {
 
 
         private fun createMockTask(): DownloadTask {
         private fun createMockTask(): DownloadTask {
             val task = mockk<DownloadTask>()
             val task = mockk<DownloadTask>()
-            every { task.download(any(), any(), any()) } answers {
+            every { task.download(any()) } answers {
                 taskProgress.forEach {
                 taskProgress.forEach {
                     arg<OnProgressCallback<Int>>(1).invoke(it)
                     arg<OnProgressCallback<Int>>(1).invoke(it)
                 }
                 }

+ 2 - 2
app/src/androidTest/java/com/owncloud/android/files/FileMenuFilterIT.kt

@@ -23,7 +23,7 @@ package com.owncloud.android.files
 import androidx.test.core.app.launchActivity
 import androidx.test.core.app.launchActivity
 import androidx.test.ext.junit.runners.AndroidJUnit4
 import androidx.test.ext.junit.runners.AndroidJUnit4
 import com.nextcloud.client.account.User
 import com.nextcloud.client.account.User
-import com.nextcloud.client.files.downloader.FilesDownloadWorker
+import com.nextcloud.client.files.downloader.FileDownloadWorker
 import com.nextcloud.test.TestActivity
 import com.nextcloud.test.TestActivity
 import com.nextcloud.utils.EditorUtils
 import com.nextcloud.utils.EditorUtils
 import com.owncloud.android.AbstractIT
 import com.owncloud.android.AbstractIT
@@ -62,7 +62,7 @@ class FileMenuFilterIT : AbstractIT() {
     private lateinit var mockFileUploaderBinder: FileUploader.FileUploaderBinder
     private lateinit var mockFileUploaderBinder: FileUploader.FileUploaderBinder
 
 
     @MockK
     @MockK
-    private lateinit var mockFileDownloaderBinder: FilesDownloadWorker.FileDownloaderBinder
+    private lateinit var mockFileDownloaderBinder: FileDownloadWorker.FileDownloaderBinder
 
 
     @MockK
     @MockK
     private lateinit var mockOperationsServiceBinder: OperationsService.OperationsServiceBinder
     private lateinit var mockOperationsServiceBinder: OperationsService.OperationsServiceBinder

+ 2 - 2
app/src/debug/java/com/nextcloud/test/TestActivity.kt

@@ -25,7 +25,7 @@ import android.os.Bundle
 import android.view.View
 import android.view.View
 import androidx.fragment.app.Fragment
 import androidx.fragment.app.Fragment
 import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
 import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
-import com.nextcloud.client.files.downloader.FilesDownloadWorker
+import com.nextcloud.client.files.downloader.FileDownloadWorker
 import com.nextcloud.client.network.Connectivity
 import com.nextcloud.client.network.Connectivity
 import com.nextcloud.client.network.ConnectivityService
 import com.nextcloud.client.network.ConnectivityService
 import com.nextcloud.utils.EditorUtils
 import com.nextcloud.utils.EditorUtils
@@ -130,7 +130,7 @@ class TestActivity :
         return null
         return null
     }
     }
 
 
-    override fun getFileDownloaderBinder(): FilesDownloadWorker.FileDownloaderBinder? {
+    override fun getFileDownloaderBinder(): FileDownloadWorker.FileDownloaderBinder? {
         return null
         return null
     }
     }
 
 

+ 1 - 1
app/src/main/AndroidManifest.xml

@@ -394,7 +394,7 @@
             android:name=".services.OperationsService"
             android:name=".services.OperationsService"
             android:exported="false" />
             android:exported="false" />
         <service
         <service
-            android:name="com.nextcloud.client.files.downloader.FileTransferService"
+            android:name="com.nextcloud.client.files.transfer.FileTransferService"
             android:foregroundServiceType="dataSync"
             android:foregroundServiceType="dataSync"
             android:exported="false" />
             android:exported="false" />
         <service
         <service

+ 2 - 2
app/src/main/java/com/nextcloud/client/di/AppComponent.java

@@ -26,7 +26,7 @@ import com.nextcloud.appReview.InAppReviewModule;
 import com.nextcloud.client.appinfo.AppInfoModule;
 import com.nextcloud.client.appinfo.AppInfoModule;
 import com.nextcloud.client.database.DatabaseModule;
 import com.nextcloud.client.database.DatabaseModule;
 import com.nextcloud.client.device.DeviceModule;
 import com.nextcloud.client.device.DeviceModule;
-import com.nextcloud.client.files.downloader.FilesDownloadHelper;
+import com.nextcloud.client.files.downloader.FileDownloadHelper;
 import com.nextcloud.client.integrations.IntegrationsModule;
 import com.nextcloud.client.integrations.IntegrationsModule;
 import com.nextcloud.client.jobs.JobsModule;
 import com.nextcloud.client.jobs.JobsModule;
 import com.nextcloud.client.network.NetworkModule;
 import com.nextcloud.client.network.NetworkModule;
@@ -72,7 +72,7 @@ public interface AppComponent {
 
 
     void inject(FilesUploadHelper filesUploadHelper);
     void inject(FilesUploadHelper filesUploadHelper);
 
 
-    void inject(FilesDownloadHelper filesDownloadHelper);
+    void inject(FileDownloadHelper fileDownloadHelper);
 
 
     void inject(ProgressIndicator progressIndicator);
     void inject(ProgressIndicator progressIndicator);
 
 

+ 0 - 2
app/src/main/java/com/nextcloud/client/di/ComponentsModule.java

@@ -135,8 +135,6 @@ import com.owncloud.android.ui.preview.pdf.PreviewPdfFragment;
 import com.owncloud.android.ui.trashbin.TrashbinActivity;
 import com.owncloud.android.ui.trashbin.TrashbinActivity;
 import com.owncloud.android.utils.FilesUploadHelper;
 import com.owncloud.android.utils.FilesUploadHelper;
 
 
-import java.io.File;
-
 import dagger.Module;
 import dagger.Module;
 import dagger.android.ContributesAndroidInjector;
 import dagger.android.ContributesAndroidInjector;
 
 

+ 1 - 3
app/src/main/java/com/nextcloud/client/files/downloader/DownloadTask.kt

@@ -21,7 +21,6 @@ package com.nextcloud.client.files.downloader
 
 
 import android.content.ContentResolver
 import android.content.ContentResolver
 import android.content.Context
 import android.content.Context
-import com.nextcloud.client.core.IsCancelled
 import com.nextcloud.client.files.DownloadRequest
 import com.nextcloud.client.files.DownloadRequest
 import com.owncloud.android.datamodel.FileDataStorageManager
 import com.owncloud.android.datamodel.FileDataStorageManager
 import com.owncloud.android.datamodel.OCFile
 import com.owncloud.android.datamodel.OCFile
@@ -63,8 +62,7 @@ class DownloadTask(
         }
         }
     }
     }
 
 
-    // Unused progress, isCancelled arguments needed for TransferManagerTest
-    fun download(request: DownloadRequest, progress: (Int) -> Unit, isCancelled: IsCancelled): Result {
+    fun download(request: DownloadRequest): Result {
         val op = DownloadFileOperation(request.user, request.file, context)
         val op = DownloadFileOperation(request.user, request.file, context)
         val client = clientProvider.invoke()
         val client = clientProvider.invoke()
         val result = op.execute(client)
         val result = op.execute(client)

+ 48 - 56
app/src/main/java/com/nextcloud/client/files/downloader/FileDownloadHelper.kt

@@ -41,51 +41,10 @@ class FileDownloadHelper {
     @Inject
     @Inject
     lateinit var uploadsStorageManager: UploadsStorageManager
     lateinit var uploadsStorageManager: UploadsStorageManager
 
 
-    companion object {
-        private var instance: FileDownloadHelper? = null
-
-        fun instance(): FileDownloadHelper {
-            return instance ?: synchronized(this) {
-                instance ?: FileDownloadHelper().also { instance = it }
-            }
-        }
-    }
-
     init {
     init {
         MainApp.getAppComponent().inject(this)
         MainApp.getAppComponent().inject(this)
     }
     }
 
 
-    fun isDownloading(user: User?, file: OCFile?): Boolean {
-        if (user == null || file == null) {
-            return false
-        }
-
-        return backgroundJobManager.isStartFileDownloadJobScheduled(user, file.fileId) ||
-            backgroundJobManager.isStartFileDownloadJobScheduled(user, file.parentId)
-    }
-
-    fun cancelPendingOrCurrentDownloads(user: User?, file: OCFile?) {
-        if (user == null || file == null) return
-
-        FileDownloadWorker.cancelOperation(user.accountName, file.fileId)
-        backgroundJobManager.cancelFilesDownloadJob(user, file.fileId)
-    }
-
-    fun cancelAllDownloadsForAccount(accountName: String?, currentDownload: DownloadFileOperation?) {
-        if (accountName == null || currentDownload == null) return
-
-        val currentUser = currentDownload.user
-        val currentFile = currentDownload.file
-
-        if (!currentUser.nameEquals(accountName)) {
-            return
-        }
-
-        currentDownload.cancel()
-        FileDownloadWorker.cancelOperation(currentUser.accountName, currentFile.fileId)
-        backgroundJobManager.cancelFilesDownloadJob(currentUser, currentFile.fileId)
-    }
-
     fun saveFile(
     fun saveFile(
         file: OCFile,
         file: OCFile,
         currentDownload: DownloadFileOperation?,
         currentDownload: DownloadFileOperation?,
@@ -120,32 +79,65 @@ class FileDownloadHelper {
         storageManager?.saveConflict(file, null)
         storageManager?.saveConflict(file, null)
     }
     }
 
 
-    fun downloadFileIfNotStartedBefore(user: User, file: OCFile) {
-        if (!isDownloading(user, file)) {
-            downloadFile(user, file, downloadType = DownloadType.DOWNLOAD)
-        }
+    fun downloadFile(user: User, ocFile: OCFile) {
+        backgroundJobManager.startFilesDownloadJob(
+            user,
+            ocFile,
+            "",
+            DownloadType.DOWNLOAD,
+            "",
+            "",
+            null
+        )
+    }
+
+    fun downloadFile(user: User, ocFile: OCFile, behaviour: String) {
+        backgroundJobManager.startFilesDownloadJob(
+            user,
+            ocFile,
+            behaviour,
+            DownloadType.DOWNLOAD,
+            "",
+            "",
+            null
+        )
     }
     }
 
 
-    fun downloadFolder(folder: OCFile, user: User, files: List<OCFile>) {
-        val filesPath = files.map { it.remotePath }
-        backgroundJobManager.startFolderDownloadJob(folder, user, filesPath)
+    fun downloadFile(user: User, ocFile: OCFile, downloadType: DownloadType) {
+        backgroundJobManager.startFilesDownloadJob(
+            user,
+            ocFile,
+            "",
+            downloadType,
+            "",
+            "",
+            null
+        )
     }
     }
 
 
-    fun downloadFile(user: User, file: OCFile) {
-        downloadFile(user, file, downloadType = DownloadType.DOWNLOAD)
+    fun downloadFile(user: User, ocFile: OCFile, conflictUploadId: Long) {
+        backgroundJobManager.startFilesDownloadJob(
+            user,
+            ocFile,
+            "",
+            DownloadType.DOWNLOAD,
+            "",
+            "",
+            conflictUploadId
+        )
     }
     }
 
 
     @Suppress("LongParameterList")
     @Suppress("LongParameterList")
     fun downloadFile(
     fun downloadFile(
         user: User,
         user: User,
         ocFile: OCFile,
         ocFile: OCFile,
-        behaviour: String = "",
-        downloadType: DownloadType? = DownloadType.DOWNLOAD,
-        activityName: String = "",
-        packageName: String = "",
-        conflictUploadId: Long? = null
+        behaviour: String,
+        downloadType: DownloadType?,
+        activityName: String,
+        packageName: String,
+        conflictUploadId: Long?
     ) {
     ) {
-        backgroundJobManager.startFileDownloadJob(
+        backgroundJobManager.startFilesDownloadJob(
             user,
             user,
             ocFile,
             ocFile,
             behaviour,
             behaviour,

+ 2 - 17
app/src/main/java/com/nextcloud/client/files/downloader/FileDownloadIntents.kt

@@ -23,8 +23,6 @@ package com.nextcloud.client.files.downloader
 
 
 import android.content.Context
 import android.content.Context
 import android.content.Intent
 import android.content.Intent
-import com.nextcloud.client.account.User
-import com.owncloud.android.authentication.AuthenticatorActivity
 import com.owncloud.android.lib.common.operations.RemoteOperationResult
 import com.owncloud.android.lib.common.operations.RemoteOperationResult
 import com.owncloud.android.operations.DownloadFileOperation
 import com.owncloud.android.operations.DownloadFileOperation
 import com.owncloud.android.ui.activity.FileActivity
 import com.owncloud.android.ui.activity.FileActivity
@@ -41,7 +39,7 @@ class FileDownloadIntents(private val context: Context) {
         linkedToRemotePath: String
         linkedToRemotePath: String
     ): Intent {
     ): Intent {
         return Intent(FileDownloadWorker.getDownloadAddedMessage()).apply {
         return Intent(FileDownloadWorker.getDownloadAddedMessage()).apply {
-            putExtra(FileDownloadWorker.EXTRA_ACCOUNT_NAME, download.user.accountName)
+            putExtra(FileDownloadWorker.ACCOUNT_NAME, download.user.accountName)
             putExtra(FileDownloadWorker.EXTRA_REMOTE_PATH, download.remotePath)
             putExtra(FileDownloadWorker.EXTRA_REMOTE_PATH, download.remotePath)
             putExtra(FileDownloadWorker.EXTRA_LINKED_TO_PATH, linkedToRemotePath)
             putExtra(FileDownloadWorker.EXTRA_LINKED_TO_PATH, linkedToRemotePath)
             setPackage(context.packageName)
             setPackage(context.packageName)
@@ -55,7 +53,7 @@ class FileDownloadIntents(private val context: Context) {
     ): Intent {
     ): Intent {
         return Intent(FileDownloadWorker.getDownloadFinishMessage()).apply {
         return Intent(FileDownloadWorker.getDownloadFinishMessage()).apply {
             putExtra(FileDownloadWorker.EXTRA_DOWNLOAD_RESULT, downloadResult.isSuccess)
             putExtra(FileDownloadWorker.EXTRA_DOWNLOAD_RESULT, downloadResult.isSuccess)
-            putExtra(FileDownloadWorker.EXTRA_ACCOUNT_NAME, download.user.accountName)
+            putExtra(FileDownloadWorker.ACCOUNT_NAME, download.user.accountName)
             putExtra(FileDownloadWorker.EXTRA_REMOTE_PATH, download.remotePath)
             putExtra(FileDownloadWorker.EXTRA_REMOTE_PATH, download.remotePath)
             putExtra(OCFileListFragment.DOWNLOAD_BEHAVIOUR, download.behaviour)
             putExtra(OCFileListFragment.DOWNLOAD_BEHAVIOUR, download.behaviour)
             putExtra(SendShareDialog.ACTIVITY_NAME, download.activityName)
             putExtra(SendShareDialog.ACTIVITY_NAME, download.activityName)
@@ -67,19 +65,6 @@ class FileDownloadIntents(private val context: Context) {
         }
         }
     }
     }
 
 
-    fun credentialContentIntent(user: User): Intent {
-        return Intent(context, AuthenticatorActivity::class.java).apply {
-            putExtra(AuthenticatorActivity.EXTRA_ACCOUNT, user.toPlatformAccount())
-            putExtra(
-                AuthenticatorActivity.EXTRA_ACTION,
-                AuthenticatorActivity.ACTION_UPDATE_EXPIRED_TOKEN
-            )
-            addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
-            addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS)
-            addFlags(Intent.FLAG_FROM_BACKGROUND)
-        }
-    }
-
     fun detailsIntent(operation: DownloadFileOperation?): Intent {
     fun detailsIntent(operation: DownloadFileOperation?): Intent {
         return if (operation != null) {
         return if (operation != null) {
             if (PreviewImageFragment.canBePreviewed(operation.file)) {
             if (PreviewImageFragment.canBePreviewed(operation.file)) {

+ 143 - 251
app/src/main/java/com/nextcloud/client/files/downloader/FileDownloadWorker.kt

@@ -26,23 +26,23 @@ import android.accounts.AccountManager
 import android.accounts.OnAccountsUpdateListener
 import android.accounts.OnAccountsUpdateListener
 import android.app.PendingIntent
 import android.app.PendingIntent
 import android.content.Context
 import android.content.Context
-import androidx.core.util.component1
-import androidx.core.util.component2
+import android.os.Binder
+import android.os.IBinder
+import android.util.Pair
 import androidx.localbroadcastmanager.content.LocalBroadcastManager
 import androidx.localbroadcastmanager.content.LocalBroadcastManager
 import androidx.work.Worker
 import androidx.work.Worker
 import androidx.work.WorkerParameters
 import androidx.work.WorkerParameters
+import com.google.gson.Gson
 import com.nextcloud.client.account.User
 import com.nextcloud.client.account.User
 import com.nextcloud.client.account.UserAccountManager
 import com.nextcloud.client.account.UserAccountManager
+import com.nextcloud.client.notifications.download.DownloadNotificationManager
 import com.nextcloud.java.util.Optional
 import com.nextcloud.java.util.Optional
-import com.nextcloud.model.WorkerState
-import com.nextcloud.model.WorkerStateLiveData
-import com.nextcloud.utils.ForegroundServiceHelper
-import com.owncloud.android.R
 import com.owncloud.android.datamodel.FileDataStorageManager
 import com.owncloud.android.datamodel.FileDataStorageManager
-import com.owncloud.android.datamodel.ForegroundServiceType
 import com.owncloud.android.datamodel.OCFile
 import com.owncloud.android.datamodel.OCFile
+import com.owncloud.android.datamodel.UploadsStorageManager
 import com.owncloud.android.files.services.IndexedForest
 import com.owncloud.android.files.services.IndexedForest
 import com.owncloud.android.lib.common.OwnCloudAccount
 import com.owncloud.android.lib.common.OwnCloudAccount
+import com.owncloud.android.lib.common.OwnCloudClient
 import com.owncloud.android.lib.common.OwnCloudClientManagerFactory
 import com.owncloud.android.lib.common.OwnCloudClientManagerFactory
 import com.owncloud.android.lib.common.network.OnDatatransferProgressListener
 import com.owncloud.android.lib.common.network.OnDatatransferProgressListener
 import com.owncloud.android.lib.common.operations.RemoteOperationResult
 import com.owncloud.android.lib.common.operations.RemoteOperationResult
@@ -51,14 +51,14 @@ import com.owncloud.android.lib.common.utils.Log_OC
 import com.owncloud.android.operations.DownloadFileOperation
 import com.owncloud.android.operations.DownloadFileOperation
 import com.owncloud.android.operations.DownloadType
 import com.owncloud.android.operations.DownloadType
 import com.owncloud.android.utils.theme.ViewThemeUtils
 import com.owncloud.android.utils.theme.ViewThemeUtils
-import java.security.SecureRandom
 import java.util.AbstractList
 import java.util.AbstractList
 import java.util.Vector
 import java.util.Vector
 
 
-@Suppress("LongParameterList", "TooManyFunctions")
+@Suppress("LongParameterList")
 class FileDownloadWorker(
 class FileDownloadWorker(
     private val viewThemeUtils: ViewThemeUtils,
     private val viewThemeUtils: ViewThemeUtils,
     private val accountManager: UserAccountManager,
     private val accountManager: UserAccountManager,
+    private val uploadsStorageManager: UploadsStorageManager,
     private var localBroadcastManager: LocalBroadcastManager,
     private var localBroadcastManager: LocalBroadcastManager,
     private val context: Context,
     private val context: Context,
     params: WorkerParameters
     params: WorkerParameters
@@ -67,30 +67,19 @@ class FileDownloadWorker(
     companion object {
     companion object {
         private val TAG = FileDownloadWorker::class.java.simpleName
         private val TAG = FileDownloadWorker::class.java.simpleName
 
 
-        private val pendingDownloads = IndexedForest<DownloadFileOperation>()
-
-        fun cancelOperation(accountName: String, fileId: Long) {
-            pendingDownloads.all.forEach {
-                it.value.payload?.cancelMatchingOperation(accountName, fileId)
-            }
-        }
-
-        const val WORKER_ID = "WORKER_ID"
-        const val FILES_SEPARATOR = ","
-        const val FOLDER_REMOTE_PATH = "FOLDER_REMOTE_PATH"
-        const val FILE_REMOTE_PATH = "FILE_REMOTE_PATH"
-        const val FILES_REMOTE_PATH = "FILES_REMOTE_PATH"
-        const val ACCOUNT_NAME = "ACCOUNT_NAME"
+        const val USER_NAME = "USER"
+        const val FILE = "FILE"
         const val BEHAVIOUR = "BEHAVIOUR"
         const val BEHAVIOUR = "BEHAVIOUR"
         const val DOWNLOAD_TYPE = "DOWNLOAD_TYPE"
         const val DOWNLOAD_TYPE = "DOWNLOAD_TYPE"
         const val ACTIVITY_NAME = "ACTIVITY_NAME"
         const val ACTIVITY_NAME = "ACTIVITY_NAME"
         const val PACKAGE_NAME = "PACKAGE_NAME"
         const val PACKAGE_NAME = "PACKAGE_NAME"
         const val CONFLICT_UPLOAD_ID = "CONFLICT_UPLOAD_ID"
         const val CONFLICT_UPLOAD_ID = "CONFLICT_UPLOAD_ID"
-
-        const val EXTRA_DOWNLOAD_RESULT = "EXTRA_DOWNLOAD_RESULT"
-        const val EXTRA_REMOTE_PATH = "EXTRA_REMOTE_PATH"
-        const val EXTRA_LINKED_TO_PATH = "EXTRA_LINKED_TO_PATH"
-        const val EXTRA_ACCOUNT_NAME = "EXTRA_ACCOUNT_NAME"
+        const val EXTRA_USER = "USER"
+        const val EXTRA_FILE = "FILE"
+        const val EXTRA_DOWNLOAD_RESULT = "RESULT"
+        const val EXTRA_REMOTE_PATH = "REMOTE_PATH"
+        const val EXTRA_LINKED_TO_PATH = "LINKED_TO"
+        const val ACCOUNT_NAME = "ACCOUNT_NAME"
 
 
         fun getDownloadAddedMessage(): String {
         fun getDownloadAddedMessage(): String {
             return FileDownloadWorker::class.java.name + "DOWNLOAD_ADDED"
             return FileDownloadWorker::class.java.name + "DOWNLOAD_ADDED"
@@ -102,223 +91,116 @@ class FileDownloadWorker(
     }
     }
 
 
     private var currentDownload: DownloadFileOperation? = null
     private var currentDownload: DownloadFileOperation? = null
-
     private var conflictUploadId: Long? = null
     private var conflictUploadId: Long? = null
     private var lastPercent = 0
     private var lastPercent = 0
-
     private val intents = FileDownloadIntents(context)
     private val intents = FileDownloadIntents(context)
-    private lateinit var notificationManager: DownloadNotificationManager
-    private var downloadProgressListener = FileDownloadProgressListener()
-
-    private var user: User? = null
+    private val notificationManager = DownloadNotificationManager(context, viewThemeUtils)
+    private val pendingDownloads = IndexedForest<DownloadFileOperation>()
+    private var downloadBinder: IBinder = FileDownloaderBinder()
     private var currentUser = Optional.empty<User>()
     private var currentUser = Optional.empty<User>()
-
-    private var currentUserFileStorageManager: FileDataStorageManager? = null
-    private var fileDataStorageManager: FileDataStorageManager? = null
-
-    private var workerId: Int? = null
-    private var folder: OCFile? = null
-    private var isAnyOperationFailed = false
+    private val helper = FileDownloadHelper()
+    private var startedDownload = false
+    private var storageManager: FileDataStorageManager? = null
+    private var downloadClient: OwnCloudClient? = null
+    private val gson = Gson()
 
 
     @Suppress("TooGenericExceptionCaught")
     @Suppress("TooGenericExceptionCaught")
     override fun doWork(): Result {
     override fun doWork(): Result {
         return try {
         return try {
             val requestDownloads = getRequestDownloads()
             val requestDownloads = getRequestDownloads()
-            notificationManager =
-                DownloadNotificationManager(workerId ?: SecureRandom().nextInt(), context, viewThemeUtils)
 
 
+            notificationManager.init()
             addAccountUpdateListener()
             addAccountUpdateListener()
-
-            val foregroundInfo = ForegroundServiceHelper.createWorkerForegroundInfo(
-                notificationManager.getId(),
-                notificationManager.getNotification(),
-                ForegroundServiceType.DataSync
-            )
-            setForegroundAsync(foregroundInfo)
-
-            requestDownloads.forEach {
-                downloadFile(it)
-            }
-
-            showSuccessNotification()
-            setIdleWorkerState()
+            startDownloadForEachRequest(requestDownloads)
 
 
             Log_OC.e(TAG, "FilesDownloadWorker successfully completed")
             Log_OC.e(TAG, "FilesDownloadWorker successfully completed")
             Result.success()
             Result.success()
         } catch (t: Throwable) {
         } catch (t: Throwable) {
-            notificationManager.showCompleteNotification(context.getString(R.string.downloader_unexpected_error))
             Log_OC.e(TAG, "Error caught at FilesDownloadWorker(): " + t.localizedMessage)
             Log_OC.e(TAG, "Error caught at FilesDownloadWorker(): " + t.localizedMessage)
-            setIdleWorkerState()
             Result.failure()
             Result.failure()
         }
         }
     }
     }
 
 
-    override fun onStopped() {
-        Log_OC.e(TAG, "FilesDownloadWorker stopped")
-
-        notificationManager.dismissNotification()
-        cancelAllDownloads()
-        removePendingDownload(currentDownload?.user?.accountName)
-        setIdleWorkerState()
-
-        super.onStopped()
-    }
-
-    private fun setWorkerState(user: User?) {
-        WorkerStateLiveData.instance().setWorkState(WorkerState.Download(user, currentDownload))
-    }
-
-    private fun setIdleWorkerState() {
-        currentDownload = null
-        WorkerStateLiveData.instance().setWorkState(WorkerState.Idle)
-    }
-
-    private fun cancelAllDownloads() {
-        pendingDownloads.all.forEach {
-            it.value.payload?.cancel()
-        }
-    }
-
-    private fun removePendingDownload(accountName: String?) {
-        pendingDownloads.remove(accountName)
-    }
-
-    @Suppress("MagicNumber")
-    private fun showSuccessNotification() {
-        if (isAnyOperationFailed) {
-            notificationManager.dismissNotification()
-            return
-        }
-
-        val successText = if (folder != null) {
-            context.getString(R.string.downloader_folder_downloaded, folder?.fileName)
-        } else if (currentDownload?.file != null) {
-            context.getString(R.string.downloader_file_downloaded, currentDownload?.file?.fileName)
-        } else {
-            context.getString(R.string.downloader_download_completed)
-        }
-
-        notificationManager.showCompleteNotification(successText)
-    }
-
     private fun getRequestDownloads(): AbstractList<String> {
     private fun getRequestDownloads(): AbstractList<String> {
-        workerId = inputData.keyValueMap[WORKER_ID] as Int
-
-        isAnyOperationFailed = false
-        setUser()
-        setFolder()
-        val files = getFiles()
-        val downloadType = getDownloadType()
-
         conflictUploadId = inputData.keyValueMap[CONFLICT_UPLOAD_ID] as Long?
         conflictUploadId = inputData.keyValueMap[CONFLICT_UPLOAD_ID] as Long?
-        val behaviour = inputData.keyValueMap[BEHAVIOUR] as String? ?: ""
-        val activityName = inputData.keyValueMap[ACTIVITY_NAME] as String? ?: ""
-        val packageName = inputData.keyValueMap[PACKAGE_NAME] as String? ?: ""
+        val file = gson.fromJson(inputData.keyValueMap[FILE] as String, OCFile::class.java)
+        val accountName = inputData.keyValueMap[USER_NAME] as String
+        val user = accountManager.getUser(accountName).get()
+        val downloadTypeAsString = inputData.keyValueMap[DOWNLOAD_TYPE] as String?
+        val downloadType = if (downloadTypeAsString != null) {
+            if (downloadTypeAsString == DownloadType.DOWNLOAD.toString()) {
+                DownloadType.DOWNLOAD
+            } else {
+                DownloadType.EXPORT
+            }
+        } else {
+            null
+        }
+        val behaviour = inputData.keyValueMap[BEHAVIOUR] as String
+        val activityName = inputData.keyValueMap[ACTIVITY_NAME] as String
+        val packageName = inputData.keyValueMap[PACKAGE_NAME] as String
 
 
         val requestedDownloads: AbstractList<String> = Vector()
         val requestedDownloads: AbstractList<String> = Vector()
 
 
-        return try {
-            files.forEach { file ->
-                val operation = DownloadFileOperation(
-                    user,
-                    file,
-                    behaviour,
-                    activityName,
-                    packageName,
-                    context,
-                    downloadType
-                )
-
-                operation.addDownloadDataTransferProgressListener(this)
-                operation.addDownloadDataTransferProgressListener(downloadProgressListener)
-                val (downloadKey, linkedToRemotePath) = pendingDownloads.putIfAbsent(
-                    user?.accountName,
-                    file.remotePath,
-                    operation
-                )
-
-                if (downloadKey != null) {
-                    requestedDownloads.add(downloadKey)
-                    localBroadcastManager.sendBroadcast(intents.newDownloadIntent(operation, linkedToRemotePath))
-                }
-            }
+        try {
+            val operation = DownloadFileOperation(
+                user,
+                file,
+                behaviour,
+                activityName,
+                packageName,
+                context,
+                downloadType
+            )
+            operation.addDatatransferProgressListener(this)
+            operation.addDatatransferProgressListener(downloadBinder as FileDownloaderBinder)
+            val putResult = pendingDownloads.putIfAbsent(
+                user?.accountName,
+                file.remotePath,
+                operation
+            )
 
 
-            requestedDownloads
+            if (putResult != null) {
+                val downloadKey = putResult.first
+                requestedDownloads.add(downloadKey)
+                localBroadcastManager.sendBroadcast(intents.newDownloadIntent(operation, putResult.second))
+            }
         } catch (e: IllegalArgumentException) {
         } catch (e: IllegalArgumentException) {
             Log_OC.e(TAG, "Not enough information provided in intent: " + e.message)
             Log_OC.e(TAG, "Not enough information provided in intent: " + e.message)
-            requestedDownloads
         }
         }
-    }
 
 
-    private fun setUser() {
-        val accountName = inputData.keyValueMap[ACCOUNT_NAME] as String
-        user = accountManager.getUser(accountName).get()
-        fileDataStorageManager = FileDataStorageManager(user, context.contentResolver)
+        return requestedDownloads
     }
     }
 
 
-    private fun setFolder() {
-        val folderPath = inputData.keyValueMap[FOLDER_REMOTE_PATH] as? String?
-        if (folderPath != null) {
-            folder = fileDataStorageManager?.getFileByEncryptedRemotePath(folderPath)
-        }
+    private fun addAccountUpdateListener() {
+        val am = AccountManager.get(context)
+        am.addOnAccountsUpdatedListener(this, null, false)
     }
     }
 
 
-    private fun getFiles(): List<OCFile> {
-        val result = arrayListOf<OCFile>()
-
-        val filesPath = inputData.keyValueMap[FILES_REMOTE_PATH] as String?
-        val filesPathList = filesPath?.split(FILES_SEPARATOR)
+    private fun startDownloadForEachRequest(requestDownloads: AbstractList<String>) {
+        val it: Iterator<String> = requestDownloads.iterator()
 
 
-        if (filesPathList != null) {
-            filesPathList.forEach {
-                fileDataStorageManager?.getFileByEncryptedRemotePath(it)?.let { file ->
-                    result.add(file)
-                }
-            }
-        } else {
-            val remotePath = inputData.keyValueMap[FILE_REMOTE_PATH] as String
-            fileDataStorageManager?.getFileByEncryptedRemotePath(remotePath)?.let { file ->
-                result.add(file)
-            }
+        while (it.hasNext()) {
+            val next = it.next()
+            Log_OC.e(TAG, "Download Key: $next")
+            downloadFile(next)
         }
         }
 
 
-        return result
-    }
-
-    private fun getDownloadType(): DownloadType? {
-        val typeAsString = inputData.keyValueMap[DOWNLOAD_TYPE] as String?
-        return if (typeAsString != null) {
-            if (typeAsString == DownloadType.DOWNLOAD.toString()) {
-                DownloadType.DOWNLOAD
-            } else {
-                DownloadType.EXPORT
-            }
-        } else {
-            null
-        }
-    }
-
-    private fun addAccountUpdateListener() {
-        val am = AccountManager.get(context)
-        am.addOnAccountsUpdatedListener(this, null, false)
+        startedDownload = false
     }
     }
 
 
     @Suppress("TooGenericExceptionCaught")
     @Suppress("TooGenericExceptionCaught")
     private fun downloadFile(downloadKey: String) {
     private fun downloadFile(downloadKey: String) {
+        startedDownload = true
         currentDownload = pendingDownloads.get(downloadKey)
         currentDownload = pendingDownloads.get(downloadKey)
 
 
         if (currentDownload == null) {
         if (currentDownload == null) {
             return
             return
         }
         }
 
 
-        val fileName = currentDownload?.file?.fileName
-
-        setWorkerState(user)
-        Log_OC.e(TAG, "FilesDownloadWorker downloading: $downloadKey")
-
         val isAccountExist = accountManager.exists(currentDownload?.user?.toPlatformAccount())
         val isAccountExist = accountManager.exists(currentDownload?.user?.toPlatformAccount())
         if (!isAccountExist) {
         if (!isAccountExist) {
-            removePendingDownload(currentDownload?.user?.accountName)
+            cancelPendingDownloads(currentDownload?.user?.accountName)
             return
             return
         }
         }
 
 
@@ -326,30 +208,33 @@ class FileDownloadWorker(
         var downloadResult: RemoteOperationResult<*>? = null
         var downloadResult: RemoteOperationResult<*>? = null
         try {
         try {
             val ocAccount = getOCAccountForDownload()
             val ocAccount = getOCAccountForDownload()
-            val downloadClient =
+            downloadClient =
                 OwnCloudClientManagerFactory.getDefaultSingleton().getClientFor(ocAccount, context)
                 OwnCloudClientManagerFactory.getDefaultSingleton().getClientFor(ocAccount, context)
 
 
             downloadResult = currentDownload?.execute(downloadClient)
             downloadResult = currentDownload?.execute(downloadClient)
             if (downloadResult?.isSuccess == true && currentDownload?.downloadType === DownloadType.DOWNLOAD) {
             if (downloadResult?.isSuccess == true && currentDownload?.downloadType === DownloadType.DOWNLOAD) {
                 getCurrentFile()?.let {
                 getCurrentFile()?.let {
-                    FileDownloadHelper.instance().saveFile(it, currentDownload, currentUserFileStorageManager)
+                    helper.saveFile(it, currentDownload, storageManager)
                 }
                 }
             }
             }
         } catch (e: Exception) {
         } catch (e: Exception) {
             Log_OC.e(TAG, "Error downloading", e)
             Log_OC.e(TAG, "Error downloading", e)
             downloadResult = RemoteOperationResult<Any?>(e)
             downloadResult = RemoteOperationResult<Any?>(e)
         } finally {
         } finally {
-            cleanupDownloadProcess(downloadResult, fileName)
+            cleanupDownloadProcess(downloadResult)
         }
         }
     }
     }
 
 
+    private fun cancelPendingDownloads(accountName: String?) {
+        pendingDownloads.remove(accountName)
+    }
+
     private fun notifyDownloadStart(download: DownloadFileOperation) {
     private fun notifyDownloadStart(download: DownloadFileOperation) {
         lastPercent = 0
         lastPercent = 0
 
 
-        notificationManager.run {
-            prepareForStart(download)
-            setContentIntent(intents.detailsIntent(download), PendingIntent.FLAG_IMMUTABLE)
-        }
+        notificationManager.notifyForStart(download)
+        notificationManager.setContentIntent(intents.detailsIntent(download), PendingIntent.FLAG_IMMUTABLE)
+        notificationManager.showDownloadInProgressNotification()
     }
     }
 
 
     private fun getOCAccountForDownload(): OwnCloudAccount {
     private fun getOCAccountForDownload(): OwnCloudAccount {
@@ -357,16 +242,16 @@ class FileDownloadWorker(
         val currentDownloadUser = accountManager.getUser(currentDownloadAccount?.name)
         val currentDownloadUser = accountManager.getUser(currentDownloadAccount?.name)
         if (currentUser != currentDownloadUser) {
         if (currentUser != currentDownloadUser) {
             currentUser = currentDownloadUser
             currentUser = currentDownloadUser
-            currentUserFileStorageManager = FileDataStorageManager(currentUser.get(), context.contentResolver)
+            storageManager = FileDataStorageManager(currentUser.get(), context.contentResolver)
         }
         }
         return currentDownloadUser.get().toOwnCloudAccount()
         return currentDownloadUser.get().toOwnCloudAccount()
     }
     }
 
 
     private fun getCurrentFile(): OCFile? {
     private fun getCurrentFile(): OCFile? {
-        var file: OCFile? = currentDownload?.file?.fileId?.let { currentUserFileStorageManager?.getFileById(it) }
+        var file: OCFile? = currentDownload?.file?.fileId?.let { storageManager?.getFileById(it) }
 
 
         if (file == null) {
         if (file == null) {
-            file = currentUserFileStorageManager?.getFileByDecryptedRemotePath(currentDownload?.file?.remotePath)
+            file = storageManager?.getFileByDecryptedRemotePath(currentDownload?.file?.remotePath)
         }
         }
 
 
         if (file == null) {
         if (file == null) {
@@ -377,11 +262,7 @@ class FileDownloadWorker(
         return file
         return file
     }
     }
 
 
-    private fun cleanupDownloadProcess(result: RemoteOperationResult<*>?, fileName: String?) {
-        result?.let {
-            showFailedDownloadNotifications(it, fileName)
-        }
-
+    private fun cleanupDownloadProcess(result: RemoteOperationResult<*>?) {
         val removeResult = pendingDownloads.removePayload(
         val removeResult = pendingDownloads.removePayload(
             currentDownload?.user?.accountName,
             currentDownload?.user?.accountName,
             currentDownload?.remotePath
             currentDownload?.remotePath
@@ -391,39 +272,15 @@ class FileDownloadWorker(
 
 
         currentDownload?.run {
         currentDownload?.run {
             notifyDownloadResult(this, downloadResult)
             notifyDownloadResult(this, downloadResult)
-
             val downloadFinishedIntent = intents.downloadFinishedIntent(
             val downloadFinishedIntent = intents.downloadFinishedIntent(
                 this,
                 this,
                 downloadResult,
                 downloadResult,
                 removeResult.second
                 removeResult.second
             )
             )
-
             localBroadcastManager.sendBroadcast(downloadFinishedIntent)
             localBroadcastManager.sendBroadcast(downloadFinishedIntent)
         }
         }
     }
     }
 
 
-    private fun showFailedDownloadNotifications(result: RemoteOperationResult<*>, fileName: String?) {
-        if (result.isSuccess) {
-            return
-        }
-
-        isAnyOperationFailed = true
-
-        val failMessage = if (result.isCancelled) {
-            context.getString(
-                R.string.downloader_file_download_cancelled,
-                fileName
-            )
-        } else {
-            context.getString(
-                R.string.downloader_file_download_failed,
-                fileName
-            )
-        }
-
-        notificationManager.showNewNotification(failMessage)
-    }
-
     private fun notifyDownloadResult(
     private fun notifyDownloadResult(
         download: DownloadFileOperation,
         download: DownloadFileOperation,
         downloadResult: RemoteOperationResult<*>
         downloadResult: RemoteOperationResult<*>
@@ -432,20 +289,31 @@ class FileDownloadWorker(
             return
             return
         }
         }
 
 
+        if (downloadResult.isSuccess) {
+            dismissDownloadInProgressNotification()
+            return
+        }
+
         val needsToUpdateCredentials = (ResultCode.UNAUTHORIZED == downloadResult.code)
         val needsToUpdateCredentials = (ResultCode.UNAUTHORIZED == downloadResult.code)
-        notificationManager.run {
-            prepareForResult()
-
-            if (needsToUpdateCredentials) {
-                showNewNotification(context.getString(R.string.downloader_download_failed_credentials_error))
-                setContentIntent(
-                    intents.credentialContentIntent(download.user),
-                    PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_IMMUTABLE
-                )
-            } else {
-                setContentIntent(intents.detailsIntent(null), PendingIntent.FLAG_IMMUTABLE)
+        notificationManager.prepareForResult(downloadResult, needsToUpdateCredentials)
+
+        if (needsToUpdateCredentials) {
+            notificationManager.setCredentialContentIntent(download.user)
+        } else {
+            notificationManager.setContentIntent(intents.detailsIntent(null), PendingIntent.FLAG_IMMUTABLE)
+        }
+
+        notificationManager.notifyForResult(downloadResult, download)
+    }
+
+    private fun dismissDownloadInProgressNotification() {
+        conflictUploadId?.let {
+            if (it > 0) {
+                uploadsStorageManager.removeUpload(it)
             }
             }
         }
         }
+
+        notificationManager.dismissDownloadInProgressNotification()
     }
     }
 
 
     override fun onAccountsUpdated(accounts: Array<out Account>?) {
     override fun onAccountsUpdated(accounts: Array<out Account>?) {
@@ -464,19 +332,43 @@ class FileDownloadWorker(
         val percent: Int = (100.0 * totalTransferredSoFar.toDouble() / totalToTransfer.toDouble()).toInt()
         val percent: Int = (100.0 * totalTransferredSoFar.toDouble() / totalToTransfer.toDouble()).toInt()
 
 
         if (percent != lastPercent) {
         if (percent != lastPercent) {
-            notificationManager.run {
-                updateDownloadProgress(filePath, percent, totalToTransfer)
-            }
+            notificationManager.updateDownloadProgressNotification(filePath, percent, totalToTransfer)
+            notificationManager.showDownloadInProgressNotification()
         }
         }
 
 
         lastPercent = percent
         lastPercent = percent
     }
     }
 
 
-    inner class FileDownloadProgressListener : OnDatatransferProgressListener {
+    inner class FileDownloaderBinder : Binder(), OnDatatransferProgressListener {
         private val boundListeners: MutableMap<Long, OnDatatransferProgressListener> = HashMap()
         private val boundListeners: MutableMap<Long, OnDatatransferProgressListener> = HashMap()
 
 
+        fun cancelPendingOrCurrentDownloads(account: Account, file: OCFile) {
+            val removeResult: Pair<DownloadFileOperation, String> =
+                pendingDownloads.remove(account.name, file.remotePath)
+            val download = removeResult.first
+
+            if (download != null) {
+                download.cancel()
+            } else {
+                if (currentUser?.isPresent == true &&
+                    currentDownload?.remotePath?.startsWith(file.remotePath) == true &&
+                    account.name == currentUser.get()?.accountName
+                ) {
+                    currentDownload?.cancel()
+                }
+            }
+        }
+
+        fun cancelAllDownloadsForAccount(accountName: String?) {
+            if (currentDownload?.user?.nameEquals(accountName) == true) {
+                currentDownload?.cancel()
+            }
+
+            cancelPendingDownloads(accountName)
+        }
+
         fun isDownloading(user: User?, file: OCFile?): Boolean {
         fun isDownloading(user: User?, file: OCFile?): Boolean {
-            return FileDownloadHelper.instance().isDownloading(user, file)
+            return user != null && file != null && pendingDownloads.contains(user.accountName, file.remotePath)
         }
         }
 
 
         fun addDataTransferProgressListener(listener: OnDatatransferProgressListener?, file: OCFile?) {
         fun addDataTransferProgressListener(listener: OnDatatransferProgressListener?, file: OCFile?) {

+ 0 - 150
app/src/main/java/com/nextcloud/client/files/downloader/FilesDownloadHelper.kt

@@ -1,150 +0,0 @@
-/*
- * Nextcloud Android client application
- *
- * @author Alper Ozturk
- * Copyright (C) 2023 Alper Ozturk
- * Copyright (C) 2023 Nextcloud GmbH
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- */
-
-package com.nextcloud.client.files.downloader
-
-import com.nextcloud.client.account.User
-import com.nextcloud.client.jobs.BackgroundJobManager
-import com.owncloud.android.MainApp
-import com.owncloud.android.datamodel.FileDataStorageManager
-import com.owncloud.android.datamodel.OCFile
-import com.owncloud.android.datamodel.UploadsStorageManager
-import com.owncloud.android.operations.DownloadFileOperation
-import com.owncloud.android.operations.DownloadType
-import com.owncloud.android.utils.MimeTypeUtil
-import java.io.File
-import javax.inject.Inject
-
-class FilesDownloadHelper {
-
-    @Inject
-    lateinit var backgroundJobManager: BackgroundJobManager
-
-    @Inject
-    lateinit var uploadsStorageManager: UploadsStorageManager
-
-    init {
-        MainApp.getAppComponent().inject(this)
-    }
-
-    fun saveFile(
-        file: OCFile,
-        currentDownload: DownloadFileOperation?,
-        storageManager: FileDataStorageManager?
-    ) {
-        val syncDate = System.currentTimeMillis()
-
-        file.apply {
-            lastSyncDateForProperties = syncDate
-            lastSyncDateForData = syncDate
-            isUpdateThumbnailNeeded = true
-            modificationTimestamp = currentDownload?.modificationTimestamp ?: 0L
-            modificationTimestampAtLastSyncForData = currentDownload?.modificationTimestamp ?: 0L
-            etag = currentDownload?.etag
-            mimeType = currentDownload?.mimeType
-            storagePath = currentDownload?.savePath
-
-            val savePathFile = currentDownload?.savePath?.let { File(it) }
-            savePathFile?.let {
-                fileLength = savePathFile.length()
-            }
-
-            remoteId = currentDownload?.file?.remoteId
-        }
-
-        storageManager?.saveFile(file)
-
-        if (MimeTypeUtil.isMedia(currentDownload?.mimeType)) {
-            FileDataStorageManager.triggerMediaScan(file.storagePath, file)
-        }
-
-        storageManager?.saveConflict(file, null)
-    }
-
-    fun downloadFile(user: User, ocFile: OCFile) {
-        backgroundJobManager.startFilesDownloadJob(
-            user,
-            ocFile,
-            "",
-            DownloadType.DOWNLOAD,
-            "",
-            "",
-            null
-        )
-    }
-
-    fun downloadFile(user: User, ocFile: OCFile, behaviour: String) {
-        backgroundJobManager.startFilesDownloadJob(
-            user,
-            ocFile,
-            behaviour,
-            DownloadType.DOWNLOAD,
-            "",
-            "",
-            null
-        )
-    }
-
-    fun downloadFile(user: User, ocFile: OCFile, downloadType: DownloadType) {
-        backgroundJobManager.startFilesDownloadJob(
-            user,
-            ocFile,
-            "",
-            downloadType,
-            "",
-            "",
-            null
-        )
-    }
-
-    fun downloadFile(user: User, ocFile: OCFile, conflictUploadId: Long) {
-        backgroundJobManager.startFilesDownloadJob(
-            user,
-            ocFile,
-            "",
-            DownloadType.DOWNLOAD,
-            "",
-            "",
-            conflictUploadId
-        )
-    }
-
-    @Suppress("LongParameterList")
-    fun downloadFile(
-        user: User,
-        ocFile: OCFile,
-        behaviour: String,
-        downloadType: DownloadType?,
-        activityName: String,
-        packageName: String,
-        conflictUploadId: Long?
-    ) {
-        backgroundJobManager.startFilesDownloadJob(
-            user,
-            ocFile,
-            behaviour,
-            downloadType,
-            activityName,
-            packageName,
-            conflictUploadId
-        )
-    }
-}

+ 0 - 83
app/src/main/java/com/nextcloud/client/files/downloader/FilesDownloadIntents.kt

@@ -1,83 +0,0 @@
-/*
- * Nextcloud Android client application
- *
- * @author Alper Ozturk
- * Copyright (C) 2023 Alper Ozturk
- * Copyright (C) 2023 Nextcloud GmbH
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- */
-
-package com.nextcloud.client.files.downloader
-
-import android.content.Context
-import android.content.Intent
-import com.owncloud.android.lib.common.operations.RemoteOperationResult
-import com.owncloud.android.operations.DownloadFileOperation
-import com.owncloud.android.ui.activity.FileActivity
-import com.owncloud.android.ui.activity.FileDisplayActivity
-import com.owncloud.android.ui.dialog.SendShareDialog
-import com.owncloud.android.ui.fragment.OCFileListFragment
-import com.owncloud.android.ui.preview.PreviewImageActivity
-import com.owncloud.android.ui.preview.PreviewImageFragment
-
-class FilesDownloadIntents(private val context: Context) {
-
-    fun newDownloadIntent(
-        download: DownloadFileOperation,
-        linkedToRemotePath: String
-    ): Intent {
-        return Intent(FilesDownloadWorker.getDownloadAddedMessage()).apply {
-            putExtra(FilesDownloadWorker.ACCOUNT_NAME, download.user.accountName)
-            putExtra(FilesDownloadWorker.EXTRA_REMOTE_PATH, download.remotePath)
-            putExtra(FilesDownloadWorker.EXTRA_LINKED_TO_PATH, linkedToRemotePath)
-            setPackage(context.packageName)
-        }
-    }
-
-    fun downloadFinishedIntent(
-        download: DownloadFileOperation,
-        downloadResult: RemoteOperationResult<*>,
-        unlinkedFromRemotePath: String?
-    ): Intent {
-        return Intent(FilesDownloadWorker.getDownloadFinishMessage()).apply {
-            putExtra(FilesDownloadWorker.EXTRA_DOWNLOAD_RESULT, downloadResult.isSuccess)
-            putExtra(FilesDownloadWorker.ACCOUNT_NAME, download.user.accountName)
-            putExtra(FilesDownloadWorker.EXTRA_REMOTE_PATH, download.remotePath)
-            putExtra(OCFileListFragment.DOWNLOAD_BEHAVIOUR, download.behaviour)
-            putExtra(SendShareDialog.ACTIVITY_NAME, download.activityName)
-            putExtra(SendShareDialog.PACKAGE_NAME, download.packageName)
-            if (unlinkedFromRemotePath != null) {
-                putExtra(FilesDownloadWorker.EXTRA_LINKED_TO_PATH, unlinkedFromRemotePath)
-            }
-            setPackage(context.packageName)
-        }
-    }
-
-    fun detailsIntent(operation: DownloadFileOperation?): Intent {
-        return if (operation != null) {
-            if (PreviewImageFragment.canBePreviewed(operation.file)) {
-                Intent(context, PreviewImageActivity::class.java)
-            } else {
-                Intent(context, FileDisplayActivity::class.java)
-            }.apply {
-                putExtra(FileActivity.EXTRA_FILE, operation.file)
-                putExtra(FileActivity.EXTRA_USER, operation.user)
-                flags = Intent.FLAG_ACTIVITY_CLEAR_TOP
-            }
-        } else {
-            Intent()
-        }
-    }
-}

+ 0 - 408
app/src/main/java/com/nextcloud/client/files/downloader/FilesDownloadWorker.kt

@@ -1,408 +0,0 @@
-/*
- * Nextcloud Android client application
- *
- * @author Alper Ozturk
- * Copyright (C) 2023 Alper Ozturk
- * Copyright (C) 2023 Nextcloud GmbH
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- */
-
-package com.nextcloud.client.files.downloader
-
-import android.accounts.Account
-import android.accounts.AccountManager
-import android.accounts.OnAccountsUpdateListener
-import android.app.PendingIntent
-import android.content.Context
-import android.os.Binder
-import android.os.IBinder
-import android.util.Pair
-import androidx.localbroadcastmanager.content.LocalBroadcastManager
-import androidx.work.Worker
-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.notifications.download.DownloadNotificationManager
-import com.nextcloud.java.util.Optional
-import com.owncloud.android.datamodel.FileDataStorageManager
-import com.owncloud.android.datamodel.OCFile
-import com.owncloud.android.datamodel.UploadsStorageManager
-import com.owncloud.android.files.services.IndexedForest
-import com.owncloud.android.lib.common.OwnCloudAccount
-import com.owncloud.android.lib.common.OwnCloudClient
-import com.owncloud.android.lib.common.OwnCloudClientManagerFactory
-import com.owncloud.android.lib.common.network.OnDatatransferProgressListener
-import com.owncloud.android.lib.common.operations.RemoteOperationResult
-import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode
-import com.owncloud.android.lib.common.utils.Log_OC
-import com.owncloud.android.operations.DownloadFileOperation
-import com.owncloud.android.operations.DownloadType
-import com.owncloud.android.utils.theme.ViewThemeUtils
-import java.util.AbstractList
-import java.util.Vector
-
-@Suppress("LongParameterList")
-class FilesDownloadWorker(
-    private val viewThemeUtils: ViewThemeUtils,
-    private val accountManager: UserAccountManager,
-    private val uploadsStorageManager: UploadsStorageManager,
-    private var localBroadcastManager: LocalBroadcastManager,
-    private val context: Context,
-    params: WorkerParameters
-) : Worker(context, params), OnAccountsUpdateListener, OnDatatransferProgressListener {
-
-    companion object {
-        private val TAG = FilesDownloadWorker::class.java.simpleName
-
-        const val USER_NAME = "USER"
-        const val FILE = "FILE"
-        const val BEHAVIOUR = "BEHAVIOUR"
-        const val DOWNLOAD_TYPE = "DOWNLOAD_TYPE"
-        const val ACTIVITY_NAME = "ACTIVITY_NAME"
-        const val PACKAGE_NAME = "PACKAGE_NAME"
-        const val CONFLICT_UPLOAD_ID = "CONFLICT_UPLOAD_ID"
-        const val EXTRA_USER = "USER"
-        const val EXTRA_FILE = "FILE"
-        const val EXTRA_DOWNLOAD_RESULT = "RESULT"
-        const val EXTRA_REMOTE_PATH = "REMOTE_PATH"
-        const val EXTRA_LINKED_TO_PATH = "LINKED_TO"
-        const val ACCOUNT_NAME = "ACCOUNT_NAME"
-
-        fun getDownloadAddedMessage(): String {
-            return FilesDownloadWorker::class.java.name + "DOWNLOAD_ADDED"
-        }
-
-        fun getDownloadFinishMessage(): String {
-            return FilesDownloadWorker::class.java.name + "DOWNLOAD_FINISH"
-        }
-    }
-
-    private var currentDownload: DownloadFileOperation? = null
-    private var conflictUploadId: Long? = null
-    private var lastPercent = 0
-    private val intents = FilesDownloadIntents(context)
-    private val notificationManager = DownloadNotificationManager(context, viewThemeUtils)
-    private val pendingDownloads = IndexedForest<DownloadFileOperation>()
-    private var downloadBinder: IBinder = FileDownloaderBinder()
-    private var currentUser = Optional.empty<User>()
-    private val helper = FilesDownloadHelper()
-    private var startedDownload = false
-    private var storageManager: FileDataStorageManager? = null
-    private var downloadClient: OwnCloudClient? = null
-    private val gson = Gson()
-
-    @Suppress("TooGenericExceptionCaught")
-    override fun doWork(): Result {
-        return try {
-            val requestDownloads = getRequestDownloads()
-
-            notificationManager.init()
-            addAccountUpdateListener()
-            startDownloadForEachRequest(requestDownloads)
-
-            Log_OC.e(TAG, "FilesDownloadWorker successfully completed")
-            Result.success()
-        } catch (t: Throwable) {
-            Log_OC.e(TAG, "Error caught at FilesDownloadWorker(): " + t.localizedMessage)
-            Result.failure()
-        }
-    }
-
-    private fun getRequestDownloads(): AbstractList<String> {
-        conflictUploadId = inputData.keyValueMap[CONFLICT_UPLOAD_ID] as Long?
-        val file = gson.fromJson(inputData.keyValueMap[FILE] as String, OCFile::class.java)
-        val accountName = inputData.keyValueMap[USER_NAME] as String
-        val user = accountManager.getUser(accountName).get()
-        val downloadTypeAsString = inputData.keyValueMap[DOWNLOAD_TYPE] as String?
-        val downloadType = if (downloadTypeAsString != null) {
-            if (downloadTypeAsString == DownloadType.DOWNLOAD.toString()) {
-                DownloadType.DOWNLOAD
-            } else {
-                DownloadType.EXPORT
-            }
-        } else {
-            null
-        }
-        val behaviour = inputData.keyValueMap[BEHAVIOUR] as String
-        val activityName = inputData.keyValueMap[ACTIVITY_NAME] as String
-        val packageName = inputData.keyValueMap[PACKAGE_NAME] as String
-
-        val requestedDownloads: AbstractList<String> = Vector()
-
-        try {
-            val operation = DownloadFileOperation(
-                user,
-                file,
-                behaviour,
-                activityName,
-                packageName,
-                context,
-                downloadType
-            )
-            operation.addDatatransferProgressListener(this)
-            operation.addDatatransferProgressListener(downloadBinder as FileDownloaderBinder)
-            val putResult = pendingDownloads.putIfAbsent(
-                user?.accountName,
-                file.remotePath,
-                operation
-            )
-
-            if (putResult != null) {
-                val downloadKey = putResult.first
-                requestedDownloads.add(downloadKey)
-                localBroadcastManager.sendBroadcast(intents.newDownloadIntent(operation, putResult.second))
-            }
-        } catch (e: IllegalArgumentException) {
-            Log_OC.e(TAG, "Not enough information provided in intent: " + e.message)
-        }
-
-        return requestedDownloads
-    }
-
-    private fun addAccountUpdateListener() {
-        val am = AccountManager.get(context)
-        am.addOnAccountsUpdatedListener(this, null, false)
-    }
-
-    private fun startDownloadForEachRequest(requestDownloads: AbstractList<String>) {
-        val it: Iterator<String> = requestDownloads.iterator()
-
-        while (it.hasNext()) {
-            val next = it.next()
-            Log_OC.e(TAG, "Download Key: $next")
-            downloadFile(next)
-        }
-
-        startedDownload = false
-    }
-
-    @Suppress("TooGenericExceptionCaught")
-    private fun downloadFile(downloadKey: String) {
-        startedDownload = true
-        currentDownload = pendingDownloads.get(downloadKey)
-
-        if (currentDownload == null) {
-            return
-        }
-
-        val isAccountExist = accountManager.exists(currentDownload?.user?.toPlatformAccount())
-        if (!isAccountExist) {
-            cancelPendingDownloads(currentDownload?.user?.accountName)
-            return
-        }
-
-        notifyDownloadStart(currentDownload!!)
-        var downloadResult: RemoteOperationResult<*>? = null
-        try {
-            val ocAccount = getOCAccountForDownload()
-            downloadClient =
-                OwnCloudClientManagerFactory.getDefaultSingleton().getClientFor(ocAccount, context)
-
-            downloadResult = currentDownload?.execute(downloadClient)
-            if (downloadResult?.isSuccess == true && currentDownload?.downloadType === DownloadType.DOWNLOAD) {
-                getCurrentFile()?.let {
-                    helper.saveFile(it, currentDownload, storageManager)
-                }
-            }
-        } catch (e: Exception) {
-            Log_OC.e(TAG, "Error downloading", e)
-            downloadResult = RemoteOperationResult<Any?>(e)
-        } finally {
-            cleanupDownloadProcess(downloadResult)
-        }
-    }
-
-    private fun cancelPendingDownloads(accountName: String?) {
-        pendingDownloads.remove(accountName)
-    }
-
-    private fun notifyDownloadStart(download: DownloadFileOperation) {
-        lastPercent = 0
-
-        notificationManager.notifyForStart(download)
-        notificationManager.setContentIntent(intents.detailsIntent(download), PendingIntent.FLAG_IMMUTABLE)
-        notificationManager.showDownloadInProgressNotification()
-    }
-
-    private fun getOCAccountForDownload(): OwnCloudAccount {
-        val currentDownloadAccount = currentDownload?.user?.toPlatformAccount()
-        val currentDownloadUser = accountManager.getUser(currentDownloadAccount?.name)
-        if (currentUser != currentDownloadUser) {
-            currentUser = currentDownloadUser
-            storageManager = FileDataStorageManager(currentUser.get(), context.contentResolver)
-        }
-        return currentDownloadUser.get().toOwnCloudAccount()
-    }
-
-    private fun getCurrentFile(): OCFile? {
-        var file: OCFile? = currentDownload?.file?.fileId?.let { storageManager?.getFileById(it) }
-
-        if (file == null) {
-            file = storageManager?.getFileByDecryptedRemotePath(currentDownload?.file?.remotePath)
-        }
-
-        if (file == null) {
-            Log_OC.e(this, "Could not save " + currentDownload?.file?.remotePath)
-            return null
-        }
-
-        return file
-    }
-
-    private fun cleanupDownloadProcess(result: RemoteOperationResult<*>?) {
-        val removeResult = pendingDownloads.removePayload(
-            currentDownload?.user?.accountName,
-            currentDownload?.remotePath
-        )
-
-        val downloadResult = result ?: RemoteOperationResult<Any?>(RuntimeException("Error downloading…"))
-
-        currentDownload?.run {
-            notifyDownloadResult(this, downloadResult)
-            val downloadFinishedIntent = intents.downloadFinishedIntent(
-                this,
-                downloadResult,
-                removeResult.second
-            )
-            localBroadcastManager.sendBroadcast(downloadFinishedIntent)
-        }
-    }
-
-    private fun notifyDownloadResult(
-        download: DownloadFileOperation,
-        downloadResult: RemoteOperationResult<*>
-    ) {
-        if (downloadResult.isCancelled) {
-            return
-        }
-
-        if (downloadResult.isSuccess) {
-            dismissDownloadInProgressNotification()
-            return
-        }
-
-        val needsToUpdateCredentials = (ResultCode.UNAUTHORIZED == downloadResult.code)
-        notificationManager.prepareForResult(downloadResult, needsToUpdateCredentials)
-
-        if (needsToUpdateCredentials) {
-            notificationManager.setCredentialContentIntent(download.user)
-        } else {
-            notificationManager.setContentIntent(intents.detailsIntent(null), PendingIntent.FLAG_IMMUTABLE)
-        }
-
-        notificationManager.notifyForResult(downloadResult, download)
-    }
-
-    private fun dismissDownloadInProgressNotification() {
-        conflictUploadId?.let {
-            if (it > 0) {
-                uploadsStorageManager.removeUpload(it)
-            }
-        }
-
-        notificationManager.dismissDownloadInProgressNotification()
-    }
-
-    override fun onAccountsUpdated(accounts: Array<out Account>?) {
-        if (!accountManager.exists(currentDownload?.user?.toPlatformAccount())) {
-            currentDownload?.cancel()
-        }
-    }
-
-    @Suppress("MagicNumber")
-    override fun onTransferProgress(
-        progressRate: Long,
-        totalTransferredSoFar: Long,
-        totalToTransfer: Long,
-        filePath: String
-    ) {
-        val percent: Int = (100.0 * totalTransferredSoFar.toDouble() / totalToTransfer.toDouble()).toInt()
-
-        if (percent != lastPercent) {
-            notificationManager.updateDownloadProgressNotification(filePath, percent, totalToTransfer)
-            notificationManager.showDownloadInProgressNotification()
-        }
-
-        lastPercent = percent
-    }
-
-    inner class FileDownloaderBinder : Binder(), OnDatatransferProgressListener {
-        private val boundListeners: MutableMap<Long, OnDatatransferProgressListener> = HashMap()
-
-        fun cancelPendingOrCurrentDownloads(account: Account, file: OCFile) {
-            val removeResult: Pair<DownloadFileOperation, String> =
-                pendingDownloads.remove(account.name, file.remotePath)
-            val download = removeResult.first
-
-            if (download != null) {
-                download.cancel()
-            } else {
-                if (currentUser?.isPresent == true &&
-                    currentDownload?.remotePath?.startsWith(file.remotePath) == true &&
-                    account.name == currentUser.get()?.accountName
-                ) {
-                    currentDownload?.cancel()
-                }
-            }
-        }
-
-        fun cancelAllDownloadsForAccount(accountName: String?) {
-            if (currentDownload?.user?.nameEquals(accountName) == true) {
-                currentDownload?.cancel()
-            }
-
-            cancelPendingDownloads(accountName)
-        }
-
-        fun isDownloading(user: User?, file: OCFile?): Boolean {
-            return user != null && file != null && pendingDownloads.contains(user.accountName, file.remotePath)
-        }
-
-        fun addDataTransferProgressListener(listener: OnDatatransferProgressListener?, file: OCFile?) {
-            if (file == null || listener == null) {
-                return
-            }
-
-            boundListeners[file.fileId] = listener
-        }
-
-        fun removeDataTransferProgressListener(listener: OnDatatransferProgressListener?, file: OCFile?) {
-            if (file == null || listener == null) {
-                return
-            }
-
-            val fileId = file.fileId
-            if (boundListeners[fileId] === listener) {
-                boundListeners.remove(fileId)
-            }
-        }
-
-        override fun onTransferProgress(
-            progressRate: Long,
-            totalTransferredSoFar: Long,
-            totalToTransfer: Long,
-            fileName: String
-        ) {
-            val listener = boundListeners[currentDownload?.file?.fileId]
-            listener?.onTransferProgress(
-                progressRate,
-                totalTransferredSoFar,
-                totalToTransfer,
-                fileName
-            )
-        }
-    }
-}

+ 2 - 2
app/src/main/java/com/nextcloud/client/files/transfer/TransferManagerImpl.kt

@@ -138,8 +138,8 @@ class TransferManagerImpl(
             }
             }
         } else {
         } else {
             val downloadTask = downloadTaskFactory.create()
             val downloadTask = downloadTaskFactory.create()
-            val wrapper: TaskFunction<DownloadTask.Result, Int> = { progress: ((Int) -> Unit), isCancelled ->
-                downloadTask.download(request, progress, isCancelled)
+            val wrapper: TaskFunction<DownloadTask.Result, Int> = { _: ((Int) -> Unit), _ ->
+                downloadTask.download(request)
             }
             }
             wrapper
             wrapper
         }
         }

+ 4 - 4
app/src/main/java/com/nextcloud/client/jobs/BackgroundJobFactory.kt

@@ -34,7 +34,7 @@ import com.nextcloud.client.device.DeviceInfo
 import com.nextcloud.client.device.PowerManagementService
 import com.nextcloud.client.device.PowerManagementService
 import com.nextcloud.client.documentscan.GeneratePDFUseCase
 import com.nextcloud.client.documentscan.GeneratePDFUseCase
 import com.nextcloud.client.documentscan.GeneratePdfFromImagesWork
 import com.nextcloud.client.documentscan.GeneratePdfFromImagesWork
-import com.nextcloud.client.files.downloader.FilesDownloadWorker
+import com.nextcloud.client.files.downloader.FileDownloadWorker
 import com.nextcloud.client.integrations.deck.DeckApi
 import com.nextcloud.client.integrations.deck.DeckApi
 import com.nextcloud.client.logger.Logger
 import com.nextcloud.client.logger.Logger
 import com.nextcloud.client.network.ConnectivityService
 import com.nextcloud.client.network.ConnectivityService
@@ -103,7 +103,7 @@ class BackgroundJobFactory @Inject constructor(
                 CalendarImportWork::class -> createCalendarImportWork(context, workerParameters)
                 CalendarImportWork::class -> createCalendarImportWork(context, workerParameters)
                 FilesExportWork::class -> createFilesExportWork(context, workerParameters)
                 FilesExportWork::class -> createFilesExportWork(context, workerParameters)
                 FilesUploadWorker::class -> createFilesUploadWorker(context, workerParameters)
                 FilesUploadWorker::class -> createFilesUploadWorker(context, workerParameters)
-                FilesDownloadWorker::class -> createFilesDownloadWorker(context, workerParameters)
+                FileDownloadWorker::class -> createFilesDownloadWorker(context, workerParameters)
                 GeneratePdfFromImagesWork::class -> createPDFGenerateWork(context, workerParameters)
                 GeneratePdfFromImagesWork::class -> createPDFGenerateWork(context, workerParameters)
                 HealthStatusWork::class -> createHealthStatusWork(context, workerParameters)
                 HealthStatusWork::class -> createHealthStatusWork(context, workerParameters)
                 TestJob::class -> createTestJob(context, workerParameters)
                 TestJob::class -> createTestJob(context, workerParameters)
@@ -255,8 +255,8 @@ class BackgroundJobFactory @Inject constructor(
         )
         )
     }
     }
 
 
-    private fun createFilesDownloadWorker(context: Context, params: WorkerParameters): FilesDownloadWorker {
-        return FilesDownloadWorker(
+    private fun createFilesDownloadWorker(context: Context, params: WorkerParameters): FileDownloadWorker {
+        return FileDownloadWorker(
             viewThemeUtils.get(),
             viewThemeUtils.get(),
             accountManager,
             accountManager,
             uploadsStorageManager,
             uploadsStorageManager,

+ 9 - 9
app/src/main/java/com/nextcloud/client/jobs/BackgroundJobManagerImpl.kt

@@ -39,7 +39,7 @@ import com.nextcloud.client.account.User
 import com.nextcloud.client.core.Clock
 import com.nextcloud.client.core.Clock
 import com.nextcloud.client.di.Injectable
 import com.nextcloud.client.di.Injectable
 import com.nextcloud.client.documentscan.GeneratePdfFromImagesWork
 import com.nextcloud.client.documentscan.GeneratePdfFromImagesWork
-import com.nextcloud.client.files.downloader.FilesDownloadWorker
+import com.nextcloud.client.files.downloader.FileDownloadWorker
 import com.nextcloud.client.preferences.AppPreferences
 import com.nextcloud.client.preferences.AppPreferences
 import com.owncloud.android.datamodel.OCFile
 import com.owncloud.android.datamodel.OCFile
 import com.owncloud.android.operations.DownloadType
 import com.owncloud.android.operations.DownloadType
@@ -521,16 +521,16 @@ internal class BackgroundJobManagerImpl(
         val gson = Gson()
         val gson = Gson()
 
 
         val data = workDataOf(
         val data = workDataOf(
-            FilesDownloadWorker.USER_NAME to user.accountName,
-            FilesDownloadWorker.FILE to gson.toJson(ocFile),
-            FilesDownloadWorker.BEHAVIOUR to behaviour,
-            FilesDownloadWorker.DOWNLOAD_TYPE to downloadType.toString(),
-            FilesDownloadWorker.ACTIVITY_NAME to activityName,
-            FilesDownloadWorker.PACKAGE_NAME to packageName,
-            FilesDownloadWorker.CONFLICT_UPLOAD_ID to conflictUploadId
+            FileDownloadWorker.USER_NAME to user.accountName,
+            FileDownloadWorker.FILE to gson.toJson(ocFile),
+            FileDownloadWorker.BEHAVIOUR to behaviour,
+            FileDownloadWorker.DOWNLOAD_TYPE to downloadType.toString(),
+            FileDownloadWorker.ACTIVITY_NAME to activityName,
+            FileDownloadWorker.PACKAGE_NAME to packageName,
+            FileDownloadWorker.CONFLICT_UPLOAD_ID to conflictUploadId
         )
         )
 
 
-        val request = oneTimeRequestBuilder(FilesDownloadWorker::class, JOB_FILES_DOWNLOAD, user)
+        val request = oneTimeRequestBuilder(FileDownloadWorker::class, JOB_FILES_DOWNLOAD, user)
             .setInputData(data)
             .setInputData(data)
             .build()
             .build()
 
 

+ 2 - 2
app/src/main/java/com/nextcloud/client/jobs/FilesExportWork.kt

@@ -33,7 +33,7 @@ import androidx.core.app.NotificationCompat
 import androidx.work.Worker
 import androidx.work.Worker
 import androidx.work.WorkerParameters
 import androidx.work.WorkerParameters
 import com.nextcloud.client.account.User
 import com.nextcloud.client.account.User
-import com.nextcloud.client.files.downloader.FilesDownloadHelper
+import com.nextcloud.client.files.downloader.FileDownloadHelper
 import com.owncloud.android.R
 import com.owncloud.android.R
 import com.owncloud.android.datamodel.FileDataStorageManager
 import com.owncloud.android.datamodel.FileDataStorageManager
 import com.owncloud.android.datamodel.OCFile
 import com.owncloud.android.datamodel.OCFile
@@ -111,7 +111,7 @@ class FilesExportWork(
     }
     }
 
 
     private fun downloadFile(ocFile: OCFile) {
     private fun downloadFile(ocFile: OCFile) {
-        FilesDownloadHelper().downloadFile(
+        FileDownloadHelper().downloadFile(
             user,
             user,
             ocFile,
             ocFile,
             DownloadType.EXPORT
             DownloadType.EXPORT

+ 3 - 3
app/src/main/java/com/owncloud/android/files/FileMenuFilter.java

@@ -31,7 +31,7 @@ import android.view.Menu;
 import com.nextcloud.android.files.FileLockingHelper;
 import com.nextcloud.android.files.FileLockingHelper;
 import com.nextcloud.client.account.User;
 import com.nextcloud.client.account.User;
 import com.nextcloud.client.editimage.EditImageActivity;
 import com.nextcloud.client.editimage.EditImageActivity;
-import com.nextcloud.client.files.downloader.FilesDownloadWorker;
+import com.nextcloud.client.files.downloader.FileDownloadWorker;
 import com.nextcloud.utils.EditorUtils;
 import com.nextcloud.utils.EditorUtils;
 import com.owncloud.android.R;
 import com.owncloud.android.R;
 import com.owncloud.android.datamodel.FileDataStorageManager;
 import com.owncloud.android.datamodel.FileDataStorageManager;
@@ -380,7 +380,7 @@ public class FileMenuFilter {
         if (componentsGetter != null && !files.isEmpty() && user != null) {
         if (componentsGetter != null && !files.isEmpty() && user != null) {
             OperationsServiceBinder opsBinder = componentsGetter.getOperationsServiceBinder();
             OperationsServiceBinder opsBinder = componentsGetter.getOperationsServiceBinder();
             FileUploaderBinder uploaderBinder = componentsGetter.getFileUploaderBinder();
             FileUploaderBinder uploaderBinder = componentsGetter.getFileUploaderBinder();
-            FilesDownloadWorker.FileDownloaderBinder downloaderBinder = componentsGetter.getFileDownloaderBinder();
+            FileDownloadWorker.FileDownloaderBinder downloaderBinder = componentsGetter.getFileDownloaderBinder();
             synchronizing = anyFileSynchronizing(opsBinder) ||      // comparing local and remote
             synchronizing = anyFileSynchronizing(opsBinder) ||      // comparing local and remote
                             anyFileDownloading(downloaderBinder) ||
                             anyFileDownloading(downloaderBinder) ||
                             anyFileUploading(uploaderBinder);
                             anyFileUploading(uploaderBinder);
@@ -398,7 +398,7 @@ public class FileMenuFilter {
         return synchronizing;
         return synchronizing;
     }
     }
 
 
-    private boolean anyFileDownloading(FilesDownloadWorker.FileDownloaderBinder downloaderBinder) {
+    private boolean anyFileDownloading(FileDownloadWorker.FileDownloaderBinder downloaderBinder) {
         boolean downloading = false;
         boolean downloading = false;
         if (downloaderBinder != null) {
         if (downloaderBinder != null) {
             for (Iterator<OCFile> iterator = files.iterator(); !downloading && iterator.hasNext(); ) {
             for (Iterator<OCFile> iterator = files.iterator(); !downloading && iterator.hasNext(); ) {

+ 2 - 2
app/src/main/java/com/owncloud/android/operations/SynchronizeFileOperation.java

@@ -25,7 +25,7 @@ import android.content.Context;
 import android.text.TextUtils;
 import android.text.TextUtils;
 
 
 import com.nextcloud.client.account.User;
 import com.nextcloud.client.account.User;
-import com.nextcloud.client.files.downloader.FilesDownloadHelper;
+import com.nextcloud.client.files.downloader.FileDownloadHelper;
 import com.owncloud.android.datamodel.FileDataStorageManager;
 import com.owncloud.android.datamodel.FileDataStorageManager;
 import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.files.services.FileUploader;
 import com.owncloud.android.files.services.FileUploader;
@@ -316,7 +316,7 @@ public class SynchronizeFileOperation extends SyncOperation {
      * @param file OCFile object representing the file to download
      * @param file OCFile object representing the file to download
      */
      */
     private void requestForDownload(OCFile file) {
     private void requestForDownload(OCFile file) {
-        FilesDownloadHelper downloadHelper = new FilesDownloadHelper();
+        FileDownloadHelper downloadHelper = new FileDownloadHelper();
 
 
         downloadHelper.downloadFile(
         downloadHelper.downloadFile(
             mUser,
             mUser,

+ 2 - 2
app/src/main/java/com/owncloud/android/operations/SynchronizeFolderOperation.java

@@ -25,7 +25,7 @@ import android.content.Intent;
 import android.text.TextUtils;
 import android.text.TextUtils;
 
 
 import com.nextcloud.client.account.User;
 import com.nextcloud.client.account.User;
-import com.nextcloud.client.files.downloader.FilesDownloadHelper;
+import com.nextcloud.client.files.downloader.FileDownloadHelper;
 import com.owncloud.android.datamodel.DecryptedFolderMetadata;
 import com.owncloud.android.datamodel.DecryptedFolderMetadata;
 import com.owncloud.android.datamodel.FileDataStorageManager;
 import com.owncloud.android.datamodel.FileDataStorageManager;
 import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.datamodel.OCFile;
@@ -452,7 +452,7 @@ public class SynchronizeFolderOperation extends SyncOperation {
                     throw new OperationCancelledException();
                     throw new OperationCancelledException();
                 }
                 }
 
 
-                FilesDownloadHelper downloadHelper = new FilesDownloadHelper();
+                FileDownloadHelper downloadHelper = new FileDownloadHelper();
 
 
                 downloadHelper.downloadFile(user, file);
                 downloadHelper.downloadFile(user, file);
             }
             }

+ 1 - 1
app/src/main/java/com/owncloud/android/providers/DocumentsStorageProvider.java

@@ -307,7 +307,7 @@ public class DocumentsStorageProvider extends DocumentsProvider {
     /**
     /**
      * Updates the OC File after a successful download.
      * Updates the OC File after a successful download.
      *
      *
-     * TODO unify with code from {@link com.nextcloud.client.files.downloader.FilesDownloadWorker} and {@link DownloadTask}.
+     * TODO unify with code from {@link com.nextcloud.client.files.downloader.FileDownloadWorker} and {@link DownloadTask}.
      */
      */
     private void saveDownloadedFile(FileDataStorageManager storageManager, DownloadFileOperation dfo, OCFile file) {
     private void saveDownloadedFile(FileDataStorageManager storageManager, DownloadFileOperation dfo, OCFile file) {
         long syncDate = System.currentTimeMillis();
         long syncDate = System.currentTimeMillis();

+ 8 - 8
app/src/main/java/com/owncloud/android/services/SyncFolderHandler.java

@@ -28,7 +28,7 @@ import android.os.Message;
 import android.util.Pair;
 import android.util.Pair;
 
 
 import com.nextcloud.client.account.User;
 import com.nextcloud.client.account.User;
-import com.nextcloud.client.files.downloader.FilesDownloadWorker;
+import com.nextcloud.client.files.downloader.FileDownloadWorker;
 import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.files.services.IndexedForest;
 import com.owncloud.android.files.services.IndexedForest;
 import com.owncloud.android.lib.common.OwnCloudAccount;
 import com.owncloud.android.lib.common.OwnCloudAccount;
@@ -169,9 +169,9 @@ class SyncFolderHandler extends Handler {
      * this is a fast and ugly patch.
      * this is a fast and ugly patch.
      */
      */
     private void sendBroadcastNewSyncFolder(Account account, String remotePath) {
     private void sendBroadcastNewSyncFolder(Account account, String remotePath) {
-        Intent added = new Intent(FilesDownloadWorker.Companion.getDownloadAddedMessage());
-        added.putExtra(FilesDownloadWorker.ACCOUNT_NAME, account.name);
-        added.putExtra(FilesDownloadWorker.EXTRA_REMOTE_PATH, remotePath);
+        Intent added = new Intent(FileDownloadWorker.Companion.getDownloadAddedMessage());
+        added.putExtra(FileDownloadWorker.ACCOUNT_NAME, account.name);
+        added.putExtra(FileDownloadWorker.EXTRA_REMOTE_PATH, remotePath);
         added.setPackage(mService.getPackageName());
         added.setPackage(mService.getPackageName());
         LocalBroadcastManager.getInstance(mService.getApplicationContext()).sendBroadcast(added);
         LocalBroadcastManager.getInstance(mService.getApplicationContext()).sendBroadcast(added);
     }
     }
@@ -182,10 +182,10 @@ class SyncFolderHandler extends Handler {
      */
      */
     private void sendBroadcastFinishedSyncFolder(Account account, String remotePath,
     private void sendBroadcastFinishedSyncFolder(Account account, String remotePath,
                                                  boolean success) {
                                                  boolean success) {
-        Intent finished = new Intent(FilesDownloadWorker.Companion.getDownloadFinishMessage());
-        finished.putExtra(FilesDownloadWorker.ACCOUNT_NAME, account.name);
-        finished.putExtra(FilesDownloadWorker.EXTRA_REMOTE_PATH, remotePath);
-        finished.putExtra(FilesDownloadWorker.EXTRA_DOWNLOAD_RESULT, success);
+        Intent finished = new Intent(FileDownloadWorker.Companion.getDownloadFinishMessage());
+        finished.putExtra(FileDownloadWorker.ACCOUNT_NAME, account.name);
+        finished.putExtra(FileDownloadWorker.EXTRA_REMOTE_PATH, remotePath);
+        finished.putExtra(FileDownloadWorker.EXTRA_DOWNLOAD_RESULT, success);
         finished.setPackage(mService.getPackageName());
         finished.setPackage(mService.getPackageName());
         LocalBroadcastManager.getInstance(mService.getApplicationContext()).sendBroadcast(finished);
         LocalBroadcastManager.getInstance(mService.getApplicationContext()).sendBroadcast(finished);
     }
     }

+ 2 - 2
app/src/main/java/com/owncloud/android/ui/activity/ComponentsGetter.java

@@ -20,7 +20,7 @@
 
 
 package com.owncloud.android.ui.activity;
 package com.owncloud.android.ui.activity;
 
 
-import com.nextcloud.client.files.downloader.FilesDownloadWorker;
+import com.nextcloud.client.files.downloader.FileDownloadWorker;
 import com.owncloud.android.datamodel.FileDataStorageManager;
 import com.owncloud.android.datamodel.FileDataStorageManager;
 import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
 import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
 import com.owncloud.android.services.OperationsService.OperationsServiceBinder;
 import com.owncloud.android.services.OperationsService.OperationsServiceBinder;
@@ -32,7 +32,7 @@ public interface ComponentsGetter {
      * To be invoked when the parent activity is fully created to get a reference
      * To be invoked when the parent activity is fully created to get a reference
      * to the FileDownloadWorker.
      * to the FileDownloadWorker.
      */
      */
-    public FilesDownloadWorker.FileDownloaderBinder getFileDownloaderBinder();
+    public FileDownloadWorker.FileDownloaderBinder getFileDownloaderBinder();
 
 
     
     
     /**
     /**

+ 2 - 2
app/src/main/java/com/owncloud/android/ui/activity/ConflictsResolveActivity.kt

@@ -21,7 +21,7 @@ import android.content.Intent
 import android.os.Bundle
 import android.os.Bundle
 import android.widget.Toast
 import android.widget.Toast
 import com.nextcloud.client.account.User
 import com.nextcloud.client.account.User
-import com.nextcloud.client.files.downloader.FilesDownloadHelper
+import com.nextcloud.client.files.downloader.FileDownloadHelper
 import com.nextcloud.model.HTTPStatusCodes
 import com.nextcloud.model.HTTPStatusCodes
 import com.nextcloud.utils.extensions.getParcelableArgument
 import com.nextcloud.utils.extensions.getParcelableArgument
 import com.owncloud.android.R
 import com.owncloud.android.R
@@ -115,7 +115,7 @@ class ConflictsResolveActivity : FileActivity(), OnConflictDecisionMadeListener
                 Decision.KEEP_SERVER -> if (!shouldDeleteLocal()) {
                 Decision.KEEP_SERVER -> if (!shouldDeleteLocal()) {
                     // Overwrite local file
                     // Overwrite local file
                     file?.let {
                     file?.let {
-                        FilesDownloadHelper().downloadFile(
+                        FileDownloadHelper().downloadFile(
                             getUser().orElseThrow { RuntimeException() },
                             getUser().orElseThrow { RuntimeException() },
                             file,
                             file,
                             conflictUploadId
                             conflictUploadId

+ 5 - 5
app/src/main/java/com/owncloud/android/ui/activity/FileActivity.java

@@ -43,8 +43,8 @@ import android.text.TextUtils;
 import com.google.android.material.snackbar.Snackbar;
 import com.google.android.material.snackbar.Snackbar;
 import com.nextcloud.client.account.User;
 import com.nextcloud.client.account.User;
 import com.nextcloud.client.account.UserAccountManager;
 import com.nextcloud.client.account.UserAccountManager;
-import com.nextcloud.client.files.downloader.FilesDownloadHelper;
-import com.nextcloud.client.files.downloader.FilesDownloadWorker;
+import com.nextcloud.client.files.downloader.FileDownloadHelper;
+import com.nextcloud.client.files.downloader.FileDownloadWorker;
 import com.nextcloud.client.jobs.BackgroundJobManager;
 import com.nextcloud.client.jobs.BackgroundJobManager;
 import com.nextcloud.client.network.ConnectivityService;
 import com.nextcloud.client.network.ConnectivityService;
 import com.nextcloud.utils.EditorUtils;
 import com.nextcloud.utils.EditorUtils;
@@ -166,7 +166,7 @@ public abstract class FileActivity extends DrawerActivity
 
 
     private boolean mResumed;
     private boolean mResumed;
 
 
-    protected FilesDownloadWorker.FileDownloaderBinder mDownloaderBinder;
+    protected FileDownloadWorker.FileDownloaderBinder mDownloaderBinder;
     protected FileUploaderBinder mUploaderBinder;
     protected FileUploaderBinder mUploaderBinder;
     private ServiceConnection mUploadServiceConnection;
     private ServiceConnection mUploadServiceConnection;
 
 
@@ -234,7 +234,7 @@ public abstract class FileActivity extends DrawerActivity
                 Context.BIND_AUTO_CREATE);
                 Context.BIND_AUTO_CREATE);
 
 
         if (user != null) {
         if (user != null) {
-            new FilesDownloadHelper().downloadFile(user, mFile);
+            new FileDownloadHelper().downloadFile(user, mFile);
         }
         }
 
 
         mUploadServiceConnection = newTransferenceServiceConnection();
         mUploadServiceConnection = newTransferenceServiceConnection();
@@ -612,7 +612,7 @@ public abstract class FileActivity extends DrawerActivity
     }
     }
 
 
     @Override
     @Override
-    public FilesDownloadWorker.FileDownloaderBinder getFileDownloaderBinder() {
+    public FileDownloadWorker.FileDownloaderBinder getFileDownloaderBinder() {
         return mDownloaderBinder;
         return mDownloaderBinder;
     }
     }
 
 

+ 16 - 16
app/src/main/java/com/owncloud/android/ui/activity/FileDisplayActivity.java

@@ -65,8 +65,8 @@ import com.nextcloud.client.core.AsyncRunner;
 import com.nextcloud.client.di.Injectable;
 import com.nextcloud.client.di.Injectable;
 import com.nextcloud.client.editimage.EditImageActivity;
 import com.nextcloud.client.editimage.EditImageActivity;
 import com.nextcloud.client.files.DeepLinkHandler;
 import com.nextcloud.client.files.DeepLinkHandler;
-import com.nextcloud.client.files.downloader.FilesDownloadHelper;
-import com.nextcloud.client.files.downloader.FilesDownloadWorker;
+import com.nextcloud.client.files.downloader.FileDownloadHelper;
+import com.nextcloud.client.files.downloader.FileDownloadWorker;
 import com.nextcloud.client.media.PlayerServiceConnection;
 import com.nextcloud.client.media.PlayerServiceConnection;
 import com.nextcloud.client.network.ClientFactory;
 import com.nextcloud.client.network.ClientFactory;
 import com.nextcloud.client.network.ConnectivityService;
 import com.nextcloud.client.network.ConnectivityService;
@@ -685,12 +685,12 @@ public class FileDisplayActivity extends FileActivity
                 // the user browsed to other file ; forget the automatic preview
                 // the user browsed to other file ; forget the automatic preview
                 mWaitingToPreview = null;
                 mWaitingToPreview = null;
 
 
-            } else if (downloadEvent.equals(FilesDownloadWorker.Companion.getDownloadAddedMessage())) {
+            } else if (downloadEvent.equals(FileDownloadWorker.Companion.getDownloadAddedMessage())) {
                 // grant that the details fragment updates the progress bar
                 // grant that the details fragment updates the progress bar
                 detailsFragment.listenForTransferProgress();
                 detailsFragment.listenForTransferProgress();
                 detailsFragment.updateFileDetails(true, false);
                 detailsFragment.updateFileDetails(true, false);
 
 
-            } else if (downloadEvent.equals(FilesDownloadWorker.Companion.getDownloadFinishMessage())) {
+            } else if (downloadEvent.equals(FileDownloadWorker.Companion.getDownloadFinishMessage())) {
                 //  update the details panel
                 //  update the details panel
                 boolean detailsFragmentChanged = false;
                 boolean detailsFragmentChanged = false;
                 if (waitedPreview) {
                 if (waitedPreview) {
@@ -1116,8 +1116,8 @@ public class FileDisplayActivity extends FileActivity
         localBroadcastManager.registerReceiver(mUploadFinishReceiver, uploadIntentFilter);
         localBroadcastManager.registerReceiver(mUploadFinishReceiver, uploadIntentFilter);
 
 
         // Listen for download messages
         // Listen for download messages
-        IntentFilter downloadIntentFilter = new IntentFilter(FilesDownloadWorker.Companion.getDownloadAddedMessage());
-        downloadIntentFilter.addAction(FilesDownloadWorker.Companion.getDownloadFinishMessage());
+        IntentFilter downloadIntentFilter = new IntentFilter(FileDownloadWorker.Companion.getDownloadAddedMessage());
+        downloadIntentFilter.addAction(FileDownloadWorker.Companion.getDownloadFinishMessage());
         mDownloadFinishReceiver = new DownloadFinishReceiver();
         mDownloadFinishReceiver = new DownloadFinishReceiver();
         localBroadcastManager.registerReceiver(mDownloadFinishReceiver, downloadIntentFilter);
         localBroadcastManager.registerReceiver(mDownloadFinishReceiver, downloadIntentFilter);
 
 
@@ -1418,7 +1418,7 @@ public class FileDisplayActivity extends FileActivity
 
 
 
 
     /**
     /**
-     * Class waiting for broadcast events from the {@link FilesDownloadWorker} service.
+     * Class waiting for broadcast events from the {@link FileDownloadWorker} service.
      * <p>
      * <p>
      * Updates the UI when a download is started or finished, provided that it is relevant for the current folder.
      * Updates the UI when a download is started or finished, provided that it is relevant for the current folder.
      */
      */
@@ -1427,16 +1427,16 @@ public class FileDisplayActivity extends FileActivity
         @Override
         @Override
         public void onReceive(Context context, Intent intent) {
         public void onReceive(Context context, Intent intent) {
             boolean sameAccount = isSameAccount(intent);
             boolean sameAccount = isSameAccount(intent);
-            String downloadedRemotePath = intent.getStringExtra(FilesDownloadWorker.EXTRA_REMOTE_PATH);
+            String downloadedRemotePath = intent.getStringExtra(FileDownloadWorker.EXTRA_REMOTE_PATH);
             String downloadBehaviour = intent.getStringExtra(OCFileListFragment.DOWNLOAD_BEHAVIOUR);
             String downloadBehaviour = intent.getStringExtra(OCFileListFragment.DOWNLOAD_BEHAVIOUR);
             boolean isDescendant = isDescendant(downloadedRemotePath);
             boolean isDescendant = isDescendant(downloadedRemotePath);
 
 
             if (sameAccount && isDescendant) {
             if (sameAccount && isDescendant) {
-                String linkedToRemotePath = intent.getStringExtra(FilesDownloadWorker.EXTRA_LINKED_TO_PATH);
+                String linkedToRemotePath = intent.getStringExtra(FileDownloadWorker.EXTRA_LINKED_TO_PATH);
                 if (linkedToRemotePath == null || isAscendant(linkedToRemotePath)) {
                 if (linkedToRemotePath == null || isAscendant(linkedToRemotePath)) {
                     updateListOfFilesFragment(false);
                     updateListOfFilesFragment(false);
                 }
                 }
-                refreshDetailsFragmentIfVisible(intent.getAction(), downloadedRemotePath, intent.getBooleanExtra(FilesDownloadWorker.EXTRA_DOWNLOAD_RESULT, false));
+                refreshDetailsFragmentIfVisible(intent.getAction(), downloadedRemotePath, intent.getBooleanExtra(FileDownloadWorker.EXTRA_DOWNLOAD_RESULT, false));
             }
             }
 
 
             if (mWaitingToSend != null) {
             if (mWaitingToSend != null) {
@@ -1469,7 +1469,7 @@ public class FileDisplayActivity extends FileActivity
         }
         }
 
 
         private boolean isSameAccount(Intent intent) {
         private boolean isSameAccount(Intent intent) {
-            String accountName = intent.getStringExtra(FilesDownloadWorker.ACCOUNT_NAME);
+            String accountName = intent.getStringExtra(FileDownloadWorker.ACCOUNT_NAME);
             return accountName != null && getAccount() != null && accountName.equals(getAccount().name);
             return accountName != null && getAccount() != null && accountName.equals(getAccount().name);
         }
         }
     }
     }
@@ -1571,9 +1571,9 @@ public class FileDisplayActivity extends FileActivity
 
 
         @Override
         @Override
         public void onServiceConnected(ComponentName component, IBinder service) {
         public void onServiceConnected(ComponentName component, IBinder service) {
-            if (component.equals(new ComponentName(FileDisplayActivity.this, FilesDownloadWorker.class))) {
+            if (component.equals(new ComponentName(FileDisplayActivity.this, FileDownloadWorker.class))) {
                 Log_OC.d(TAG, "Download service connected");
                 Log_OC.d(TAG, "Download service connected");
-                mDownloaderBinder = (FilesDownloadWorker.FileDownloaderBinder) service;
+                mDownloaderBinder = (FileDownloadWorker.FileDownloaderBinder) service;
                 if (mWaitingToPreview != null && getStorageManager() != null) {
                 if (mWaitingToPreview != null && getStorageManager() != null) {
                     // update the file
                     // update the file
                     mWaitingToPreview = getStorageManager().getFileById(mWaitingToPreview.getFileId());
                     mWaitingToPreview = getStorageManager().getFileById(mWaitingToPreview.getFileId());
@@ -1604,7 +1604,7 @@ public class FileDisplayActivity extends FileActivity
 
 
         @Override
         @Override
         public void onServiceDisconnected(ComponentName component) {
         public void onServiceDisconnected(ComponentName component) {
-            if (component.equals(new ComponentName(FileDisplayActivity.this, FilesDownloadWorker.class))) {
+            if (component.equals(new ComponentName(FileDisplayActivity.this, FileDownloadWorker.class))) {
                 Log_OC.d(TAG, "Download service disconnected");
                 Log_OC.d(TAG, "Download service disconnected");
                 mDownloaderBinder = null;
                 mDownloaderBinder = null;
             } else if (component.equals(new ComponentName(FileDisplayActivity.this, FileUploader.class))) {
             } else if (component.equals(new ComponentName(FileDisplayActivity.this, FileUploader.class))) {
@@ -1886,7 +1886,7 @@ public class FileDisplayActivity extends FileActivity
         User user = getUser().orElseThrow(RuntimeException::new);
         User user = getUser().orElseThrow(RuntimeException::new);
         //if (!mWaitingToPreview.isDownloading()) {
         //if (!mWaitingToPreview.isDownloading()) {
         if (!mDownloaderBinder.isDownloading(user, mWaitingToPreview)) {
         if (!mDownloaderBinder.isDownloading(user, mWaitingToPreview)) {
-            new FilesDownloadHelper().downloadFile(user, mWaitingToPreview);
+            new FileDownloadHelper().downloadFile(user, mWaitingToPreview);
         }
         }
     }
     }
 
 
@@ -1958,7 +1958,7 @@ public class FileDisplayActivity extends FileActivity
     private void requestForDownload(OCFile file, String downloadBehaviour, String packageName, String activityName) {
     private void requestForDownload(OCFile file, String downloadBehaviour, String packageName, String activityName) {
         final User currentUser = getUser().orElseThrow(RuntimeException::new);
         final User currentUser = getUser().orElseThrow(RuntimeException::new);
         if (!mDownloaderBinder.isDownloading(currentUser, mWaitingToPreview)) {
         if (!mDownloaderBinder.isDownloading(currentUser, mWaitingToPreview)) {
-            new FilesDownloadHelper().downloadFile(currentUser, file, downloadBehaviour, DownloadType.DOWNLOAD, activityName, packageName, null);
+            new FileDownloadHelper().downloadFile(currentUser, file, downloadBehaviour, DownloadType.DOWNLOAD, activityName, packageName, null);
         }
         }
     }
     }
 
 

+ 4 - 4
app/src/main/java/com/owncloud/android/ui/activity/ManageAccountsActivity.java

@@ -41,7 +41,7 @@ import android.view.View;
 import com.google.common.collect.Sets;
 import com.google.common.collect.Sets;
 import com.nextcloud.client.account.User;
 import com.nextcloud.client.account.User;
 import com.nextcloud.client.account.UserAccountManager;
 import com.nextcloud.client.account.UserAccountManager;
-import com.nextcloud.client.files.downloader.FilesDownloadWorker;
+import com.nextcloud.client.files.downloader.FileDownloadWorker;
 import com.nextcloud.client.jobs.BackgroundJobManager;
 import com.nextcloud.client.jobs.BackgroundJobManager;
 import com.nextcloud.client.onboarding.FirstRunActivity;
 import com.nextcloud.client.onboarding.FirstRunActivity;
 import com.nextcloud.java.util.Optional;
 import com.nextcloud.java.util.Optional;
@@ -525,8 +525,8 @@ public class ManageAccountsActivity extends FileActivity implements UserListAdap
         @Override
         @Override
         public void onServiceConnected(ComponentName component, IBinder service) {
         public void onServiceConnected(ComponentName component, IBinder service) {
 
 
-            if (component.equals(new ComponentName(ManageAccountsActivity.this, FilesDownloadWorker.class))) {
-                mDownloaderBinder = (FilesDownloadWorker.FileDownloaderBinder) service;
+            if (component.equals(new ComponentName(ManageAccountsActivity.this, FileDownloadWorker.class))) {
+                mDownloaderBinder = (FileDownloadWorker.FileDownloaderBinder) service;
 
 
             } else if (component.equals(new ComponentName(ManageAccountsActivity.this, FileUploader.class))) {
             } else if (component.equals(new ComponentName(ManageAccountsActivity.this, FileUploader.class))) {
                 Log_OC.d(TAG, "Upload service connected");
                 Log_OC.d(TAG, "Upload service connected");
@@ -536,7 +536,7 @@ public class ManageAccountsActivity extends FileActivity implements UserListAdap
 
 
         @Override
         @Override
         public void onServiceDisconnected(ComponentName component) {
         public void onServiceDisconnected(ComponentName component) {
-            if (component.equals(new ComponentName(ManageAccountsActivity.this, FilesDownloadWorker.class))) {
+            if (component.equals(new ComponentName(ManageAccountsActivity.this, FileDownloadWorker.class))) {
                 Log_OC.d(TAG, "Download service suddenly disconnected");
                 Log_OC.d(TAG, "Download service suddenly disconnected");
                 mDownloaderBinder = null;
                 mDownloaderBinder = null;
             } else if (component.equals(new ComponentName(ManageAccountsActivity.this, FileUploader.class))) {
             } else if (component.equals(new ComponentName(ManageAccountsActivity.this, FileUploader.class))) {

+ 4 - 4
app/src/main/java/com/owncloud/android/ui/fragment/FileDetailFragment.java

@@ -44,7 +44,7 @@ import com.google.android.material.tabs.TabLayout;
 import com.nextcloud.client.account.User;
 import com.nextcloud.client.account.User;
 import com.nextcloud.client.account.UserAccountManager;
 import com.nextcloud.client.account.UserAccountManager;
 import com.nextcloud.client.di.Injectable;
 import com.nextcloud.client.di.Injectable;
-import com.nextcloud.client.files.downloader.FilesDownloadWorker;
+import com.nextcloud.client.files.downloader.FileDownloadWorker;
 import com.nextcloud.client.jobs.BackgroundJobManager;
 import com.nextcloud.client.jobs.BackgroundJobManager;
 import com.nextcloud.client.network.ClientFactory;
 import com.nextcloud.client.network.ClientFactory;
 import com.nextcloud.client.network.ConnectivityService;
 import com.nextcloud.client.network.ConnectivityService;
@@ -502,7 +502,7 @@ public class FileDetailFragment extends FileFragment implements OnClickListener,
      * TODO Remove parameter when the transferring state of files is kept in database.
      * TODO Remove parameter when the transferring state of files is kept in database.
      *
      *
      * @param transferring Flag signaling if the file should be considered as downloading or uploading, although
      * @param transferring Flag signaling if the file should be considered as downloading or uploading, although
-     *                     {@link com.nextcloud.client.files.downloader.FilesDownloadWorker.FileDownloaderBinder#isDownloading(User, OCFile)}  and
+     *                     {@link com.nextcloud.client.files.downloader.FileDownloadWorker.FileDownloaderBinder#isDownloading(User, OCFile)}  and
      *                     {@link FileUploaderBinder#isUploading(User, OCFile)} return false.
      *                     {@link FileUploaderBinder#isUploading(User, OCFile)} return false.
      * @param refresh      If 'true', try to refresh the whole file from the database
      * @param refresh      If 'true', try to refresh the whole file from the database
      */
      */
@@ -534,7 +534,7 @@ public class FileDetailFragment extends FileFragment implements OnClickListener,
             setFavoriteIconStatus(file.isFavorite());
             setFavoriteIconStatus(file.isFavorite());
 
 
             // configure UI for depending upon local state of the file
             // configure UI for depending upon local state of the file
-            FilesDownloadWorker.FileDownloaderBinder downloaderBinder = containerActivity.getFileDownloaderBinder();
+            FileDownloadWorker.FileDownloaderBinder downloaderBinder = containerActivity.getFileDownloaderBinder();
             FileUploaderBinder uploaderBinder = containerActivity.getFileUploaderBinder();
             FileUploaderBinder uploaderBinder = containerActivity.getFileUploaderBinder();
             if (transferring
             if (transferring
                 || (downloaderBinder != null && downloaderBinder.isDownloading(user, file))
                 || (downloaderBinder != null && downloaderBinder.isDownloading(user, file))
@@ -659,7 +659,7 @@ public class FileDetailFragment extends FileFragment implements OnClickListener,
             // show the progress bar for the transfer
             // show the progress bar for the transfer
             binding.progressBlock.setVisibility(View.VISIBLE);
             binding.progressBlock.setVisibility(View.VISIBLE);
             binding.progressText.setVisibility(View.VISIBLE);
             binding.progressText.setVisibility(View.VISIBLE);
-            FilesDownloadWorker.FileDownloaderBinder downloaderBinder = containerActivity.getFileDownloaderBinder();
+            FileDownloadWorker.FileDownloaderBinder downloaderBinder = containerActivity.getFileDownloaderBinder();
             FileUploaderBinder uploaderBinder = containerActivity.getFileUploaderBinder();
             FileUploaderBinder uploaderBinder = containerActivity.getFileUploaderBinder();
             //if (getFile().isDownloading()) {
             //if (getFile().isDownloading()) {
             if (downloaderBinder != null && downloaderBinder.isDownloading(user, getFile())) {
             if (downloaderBinder != null && downloaderBinder.isDownloading(user, getFile())) {

+ 2 - 2
app/src/main/java/com/owncloud/android/ui/helpers/FileOperationsHelper.java

@@ -47,7 +47,7 @@ import android.webkit.MimeTypeMap;
 
 
 import com.nextcloud.client.account.CurrentAccountProvider;
 import com.nextcloud.client.account.CurrentAccountProvider;
 import com.nextcloud.client.account.User;
 import com.nextcloud.client.account.User;
-import com.nextcloud.client.files.downloader.FilesDownloadWorker;
+import com.nextcloud.client.files.downloader.FileDownloadWorker;
 import com.nextcloud.client.jobs.BackgroundJobManager;
 import com.nextcloud.client.jobs.BackgroundJobManager;
 import com.nextcloud.client.network.ConnectivityService;
 import com.nextcloud.client.network.ConnectivityService;
 import com.nextcloud.java.util.Optional;
 import com.nextcloud.java.util.Optional;
@@ -997,7 +997,7 @@ public class FileOperationsHelper {
         }
         }
 
 
         // for both files and folders
         // for both files and folders
-        FilesDownloadWorker.FileDownloaderBinder downloaderBinder = fileActivity.getFileDownloaderBinder();
+        FileDownloadWorker.FileDownloaderBinder downloaderBinder = fileActivity.getFileDownloaderBinder();
         if (downloaderBinder != null && downloaderBinder.isDownloading(currentUser, file)) {
         if (downloaderBinder != null && downloaderBinder.isDownloading(currentUser, file)) {
             downloaderBinder.cancelPendingOrCurrentDownloads(currentUser.toPlatformAccount(), file);
             downloaderBinder.cancelPendingOrCurrentDownloads(currentUser.toPlatformAccount(), file);
         }
         }

+ 11 - 11
app/src/main/java/com/owncloud/android/ui/preview/PreviewImageActivity.java

@@ -37,8 +37,8 @@ import android.view.View;
 import com.nextcloud.client.account.User;
 import com.nextcloud.client.account.User;
 import com.nextcloud.client.di.Injectable;
 import com.nextcloud.client.di.Injectable;
 import com.nextcloud.client.editimage.EditImageActivity;
 import com.nextcloud.client.editimage.EditImageActivity;
-import com.nextcloud.client.files.downloader.FilesDownloadHelper;
-import com.nextcloud.client.files.downloader.FilesDownloadWorker;
+import com.nextcloud.client.files.downloader.FileDownloadHelper;
+import com.nextcloud.client.files.downloader.FileDownloadWorker;
 import com.nextcloud.client.preferences.AppPreferences;
 import com.nextcloud.client.preferences.AppPreferences;
 import com.nextcloud.java.util.Optional;
 import com.nextcloud.java.util.Optional;
 import com.nextcloud.utils.extensions.IntentExtensionsKt;
 import com.nextcloud.utils.extensions.IntentExtensionsKt;
@@ -311,8 +311,8 @@ public class PreviewImageActivity extends FileActivity implements
         public void onServiceConnected(ComponentName component, IBinder service) {
         public void onServiceConnected(ComponentName component, IBinder service) {
 
 
             if (component.equals(new ComponentName(PreviewImageActivity.this,
             if (component.equals(new ComponentName(PreviewImageActivity.this,
-                    FilesDownloadWorker.class))) {
-                mDownloaderBinder = (FilesDownloadWorker.FileDownloaderBinder) service;
+                                                   FileDownloadWorker.class))) {
+                mDownloaderBinder = (FileDownloadWorker.FileDownloaderBinder) service;
                 if (mRequestWaitingForBinder) {
                 if (mRequestWaitingForBinder) {
                     mRequestWaitingForBinder = false;
                     mRequestWaitingForBinder = false;
                     Log_OC.d(TAG, "Simulating reselection of current page after connection " +
                     Log_OC.d(TAG, "Simulating reselection of current page after connection " +
@@ -331,7 +331,7 @@ public class PreviewImageActivity extends FileActivity implements
         @Override
         @Override
         public void onServiceDisconnected(ComponentName component) {
         public void onServiceDisconnected(ComponentName component) {
             if (component.equals(new ComponentName(PreviewImageActivity.this,
             if (component.equals(new ComponentName(PreviewImageActivity.this,
-                    FilesDownloadWorker.class))) {
+                                                   FileDownloadWorker.class))) {
                 Log_OC.d(TAG, "Download service suddenly disconnected");
                 Log_OC.d(TAG, "Download service suddenly disconnected");
                 mDownloaderBinder = null;
                 mDownloaderBinder = null;
             } else if (component.equals(new ComponentName(PreviewImageActivity.this,
             } else if (component.equals(new ComponentName(PreviewImageActivity.this,
@@ -359,7 +359,7 @@ public class PreviewImageActivity extends FileActivity implements
         super.onResume();
         super.onResume();
 
 
         mDownloadFinishReceiver = new DownloadFinishReceiver();
         mDownloadFinishReceiver = new DownloadFinishReceiver();
-        IntentFilter downloadIntentFilter = new IntentFilter(FilesDownloadWorker.Companion.getDownloadFinishMessage());
+        IntentFilter downloadIntentFilter = new IntentFilter(FileDownloadWorker.Companion.getDownloadFinishMessage());
         localBroadcastManager.registerReceiver(mDownloadFinishReceiver, downloadIntentFilter);
         localBroadcastManager.registerReceiver(mDownloadFinishReceiver, downloadIntentFilter);
 
 
         mUploadFinishReceiver = new UploadFinishReceiver();
         mUploadFinishReceiver = new UploadFinishReceiver();
@@ -413,7 +413,7 @@ public class PreviewImageActivity extends FileActivity implements
 
 
         } else if (!mDownloaderBinder.isDownloading(getUserAccountManager().getUser(), file)) {
         } else if (!mDownloaderBinder.isDownloading(getUserAccountManager().getUser(), file)) {
             final User user = getUser().orElseThrow(RuntimeException::new);
             final User user = getUser().orElseThrow(RuntimeException::new);
-            new FilesDownloadHelper().downloadFile(user, file, downloadBehaviour);
+            new FileDownloadHelper().downloadFile(user, file, downloadBehaviour);
         }
         }
     }
     }
 
 
@@ -478,7 +478,7 @@ public class PreviewImageActivity extends FileActivity implements
     }
     }
 
 
     /**
     /**
-     * Class waiting for broadcast events from the {@link FilesDownloadWorker} service.
+     * Class waiting for broadcast events from the {@link FileDownloadWorker} service.
      *
      *
      * Updates the UI when a download is started or finished, provided that it is relevant for the
      * Updates the UI when a download is started or finished, provided that it is relevant for the
      * folder displayed in the gallery.
      * folder displayed in the gallery.
@@ -498,12 +498,12 @@ public class PreviewImageActivity extends FileActivity implements
     }
     }
 
 
     private void previewNewImage(Intent intent) {
     private void previewNewImage(Intent intent) {
-        String accountName = intent.getStringExtra(FilesDownloadWorker.ACCOUNT_NAME);
-        String downloadedRemotePath = intent.getStringExtra(FilesDownloadWorker.EXTRA_REMOTE_PATH);
+        String accountName = intent.getStringExtra(FileDownloadWorker.ACCOUNT_NAME);
+        String downloadedRemotePath = intent.getStringExtra(FileDownloadWorker.EXTRA_REMOTE_PATH);
         String downloadBehaviour = intent.getStringExtra(OCFileListFragment.DOWNLOAD_BEHAVIOUR);
         String downloadBehaviour = intent.getStringExtra(OCFileListFragment.DOWNLOAD_BEHAVIOUR);
         if (getAccount().name.equals(accountName) && downloadedRemotePath != null) {
         if (getAccount().name.equals(accountName) && downloadedRemotePath != null) {
             OCFile file = getStorageManager().getFileByPath(downloadedRemotePath);
             OCFile file = getStorageManager().getFileByPath(downloadedRemotePath);
-            boolean downloadWasFine = intent.getBooleanExtra(FilesDownloadWorker.EXTRA_DOWNLOAD_RESULT, false);
+            boolean downloadWasFine = intent.getBooleanExtra(FileDownloadWorker.EXTRA_DOWNLOAD_RESULT, false);
 
 
             if (EditImageActivity.OPEN_IMAGE_EDITOR.equals(downloadBehaviour)) {
             if (EditImageActivity.OPEN_IMAGE_EDITOR.equals(downloadBehaviour)) {
                 startImageEditor(file);
                 startImageEditor(file);

+ 2 - 2
app/src/main/java/com/owncloud/android/ui/preview/PreviewMediaFragment.java

@@ -53,7 +53,7 @@ import android.view.ViewGroup;
 import com.nextcloud.client.account.User;
 import com.nextcloud.client.account.User;
 import com.nextcloud.client.account.UserAccountManager;
 import com.nextcloud.client.account.UserAccountManager;
 import com.nextcloud.client.di.Injectable;
 import com.nextcloud.client.di.Injectable;
-import com.nextcloud.client.files.downloader.FilesDownloadHelper;
+import com.nextcloud.client.files.downloader.FileDownloadHelper;
 import com.nextcloud.client.jobs.BackgroundJobManager;
 import com.nextcloud.client.jobs.BackgroundJobManager;
 import com.nextcloud.client.media.ExoplayerListener;
 import com.nextcloud.client.media.ExoplayerListener;
 import com.nextcloud.client.media.NextcloudExoPlayer;
 import com.nextcloud.client.media.NextcloudExoPlayer;
@@ -479,7 +479,7 @@ public class PreviewMediaFragment extends FileFragment implements OnTouchListene
                                                                     backgroundJobManager);
                                                                     backgroundJobManager);
         } else if (itemId == R.id.action_download_file) {
         } else if (itemId == R.id.action_download_file) {
             if (!containerActivity.getFileDownloaderBinder().isDownloading(user, getFile())) {
             if (!containerActivity.getFileDownloaderBinder().isDownloading(user, getFile())) {
-                new FilesDownloadHelper().downloadFile(user, getFile());
+                new FileDownloadHelper().downloadFile(user, getFile());
             }
             }
         }
         }
     }
     }