Browse Source

re-use fileDownloadHelper

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
tobiasKaminsky 7 months ago
parent
commit
6fced1952b

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

@@ -301,6 +301,8 @@ public class SynchronizeFileOperation extends SyncOperation {
     }
 
     private void requestForDownload(OCFile file) {
+        final var fileDownloadHelper = FileDownloadHelper.Companion.instance();
+        
         if (syncInBackgroundWorker) {
             Log_OC.d("InternalTwoWaySyncWork", "download file: " + file.getFileName());
 
@@ -313,7 +315,7 @@ public class SynchronizeFileOperation extends SyncOperation {
                 String filename = file.getFileName();
                 if (filename != null) {
                     if (result.isSuccess()) {
-                        new FileDownloadHelper().saveFile(file, operation, getStorageManager());
+                        fileDownloadHelper.saveFile(file, operation, getStorageManager());
                         Log_OC.d(TAG, "requestForDownload completed for: " + file.getFileName());
                     } else {
                         Log_OC.d(TAG, "requestForDownload failed for: " + file.getFileName());
@@ -323,7 +325,7 @@ public class SynchronizeFileOperation extends SyncOperation {
                 Log_OC.d(TAG, "Exception caught at requestForDownload" + e);
             }
         } else {
-            FileDownloadHelper.Companion.instance().downloadFile(mUser, file);
+            fileDownloadHelper.downloadFile(mUser, file);
         }
     }
 

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

@@ -446,6 +446,8 @@ public class SynchronizeFolderOperation extends SyncOperation {
     }
 
     private void startDirectDownloads() {
+        final var fileDownloadHelper = FileDownloadHelper.Companion.instance();
+        
         if (syncInBackgroundWorker) {
             try {
                 for (OCFile file: mFilesForDirectDownload) {
@@ -468,7 +470,7 @@ public class SynchronizeFolderOperation extends SyncOperation {
                     }
 
                     if (result.isSuccess()) {
-                        new FileDownloadHelper().saveFile(file, operation, getStorageManager());
+                        fileDownloadHelper.saveFile(file, operation, getStorageManager());
                         Log_OC.d(TAG, "startDirectDownloads completed for: " + file.getFileName());
                     } else {
                         Log_OC.d(TAG, "startDirectDownloads failed for: " + file.getFileName());
@@ -478,7 +480,6 @@ public class SynchronizeFolderOperation extends SyncOperation {
                 Log_OC.d(TAG, "Exception caught at startDirectDownloads" + e);
             }
         } else {
-            final var fileDownloadHelper = FileDownloadHelper.Companion.instance();
             mFilesForDirectDownload.forEach(file -> fileDownloadHelper.downloadFile(user, file));
         }
     }