Browse Source

Fix download progress

Signed-off-by: alperozturk <alper_ozturk@proton.me>
alperozturk 1 year ago
parent
commit
842ff87c84

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

@@ -46,7 +46,7 @@ class FilesDownloadHelper {
             user,
             ocFile,
             "",
-            null,
+            DownloadType.DOWNLOAD,
             "",
             "",
             null
@@ -58,7 +58,7 @@ class FilesDownloadHelper {
             user,
             ocFile,
             behaviour,
-            null,
+            DownloadType.DOWNLOAD,
             "",
             "",
             null
@@ -82,7 +82,7 @@ class FilesDownloadHelper {
             user,
             ocFile,
             "",
-            null,
+            DownloadType.DOWNLOAD,
             "",
             "",
             conflictUploadId

+ 12 - 6
app/src/main/java/com/nextcloud/client/files/downloader/FilesDownloadWorker.kt

@@ -115,7 +115,7 @@ class FilesDownloadWorker(
     private lateinit var notificationBuilder: NotificationCompat.Builder
     private val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
     private val pendingDownloads = IndexedForest<DownloadFileOperation>()
-    private var downloadBinder: IBinder? = null
+    private var downloadBinder: IBinder = FileDownloaderBinder()
     private var currentUser = Optional.empty<User>()
     private var startedDownload = false
     private var storageManager: FileDataStorageManager? = null
@@ -158,6 +158,7 @@ class FilesDownloadWorker(
         val packageName = inputData.keyValueMap[PACKAGE_NAME] as String
 
         val requestedDownloads: AbstractList<String> = Vector()
+
         try {
             val operation = DownloadFileOperation(
                 user,
@@ -169,16 +170,19 @@ class FilesDownloadWorker(
                 downloadType
             )
             operation.addDatatransferProgressListener(this)
-            operation.addDatatransferProgressListener(downloadBinder as FileDownloaderBinder?)
+            operation.addDatatransferProgressListener(downloadBinder as FileDownloaderBinder)
             val putResult = pendingDownloads.putIfAbsent(
                 user?.accountName,
                 file.remotePath,
                 operation
             )
 
-            val downloadKey = putResult.first
-            requestedDownloads.add(downloadKey)
-            sendBroadcastNewDownload(operation, putResult.second)
+            if (putResult != null) {
+                val downloadKey = putResult.first
+                requestedDownloads.add(downloadKey)
+                sendBroadcastNewDownload(operation, putResult.second)
+            }
+
         } catch (e: IllegalArgumentException) {
             Log_OC.e(TAG, "Not enough information provided in intent: " + e.message)
         }
@@ -207,12 +211,14 @@ class FilesDownloadWorker(
 
     private fun startDownloadForEachRequest(requestDownloads: AbstractList<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
     }
 
     private fun downloadFile(downloadKey: String) {

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

@@ -30,7 +30,7 @@ public interface ComponentsGetter {
 
     /**
      * To be invoked when the parent activity is fully created to get a reference
-     * to the FileDownloader service API.
+     * to the FileDownloadWorker.
      */
     public FilesDownloadWorker.FileDownloaderBinder getFileDownloaderBinder();
 

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

@@ -94,6 +94,7 @@ import com.owncloud.android.lib.resources.files.RestoreFileVersionRemoteOperatio
 import com.owncloud.android.lib.resources.files.SearchRemoteOperation;
 import com.owncloud.android.operations.CopyFileOperation;
 import com.owncloud.android.operations.CreateFolderOperation;
+import com.owncloud.android.operations.DownloadType;
 import com.owncloud.android.operations.MoveFileOperation;
 import com.owncloud.android.operations.RefreshFolderOperation;
 import com.owncloud.android.operations.RemoveFileOperation;
@@ -1957,7 +1958,7 @@ public class FileDisplayActivity extends FileActivity
     private void requestForDownload(OCFile file, String downloadBehaviour, String packageName, String activityName) {
         final User currentUser = getUser().orElseThrow(RuntimeException::new);
         if (!mDownloaderBinder.isDownloading(currentUser, mWaitingToPreview)) {
-            new FilesDownloadHelper().downloadFile(currentUser, file, downloadBehaviour, null, activityName, packageName, null);
+            new FilesDownloadHelper().downloadFile(currentUser, file, downloadBehaviour, DownloadType.DOWNLOAD, activityName, packageName, null);
         }
     }