Browse Source

create instance before loops

Signed-off-by: alperozturk <alper_ozturk@proton.me>
alperozturk 5 months ago
parent
commit
0f827f5bad

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

@@ -57,6 +57,9 @@ class FilesExportWork(
     }
 
     private fun exportFiles(fileIDs: LongArray): Int {
+        val fileDownloadHelper = FileDownloadHelper.instance()
+        val fileExportUtil = FileExportUtils()
+
         var successfulExports = 0
         fileIDs
             .asSequence()
@@ -70,13 +73,23 @@ class FilesExportWork(
 
                 if (ocFile.isDown) {
                     try {
-                        exportFile(ocFile)
+                        fileExportUtil.exportFile(
+                            ocFile.fileName,
+                            ocFile.mimeType,
+                            contentResolver,
+                            ocFile,
+                            null
+                        )
                     } catch (e: IllegalStateException) {
                         Log_OC.e(TAG, "Error exporting file", e)
                         showErrorNotification(successfulExports)
                     }
                 } else {
-                    downloadFile(ocFile)
+                    fileDownloadHelper.downloadFile(
+                        user,
+                        ocFile,
+                        downloadType = DownloadType.EXPORT
+                    )
                 }
 
                 successfulExports++
@@ -84,25 +97,6 @@ class FilesExportWork(
         return successfulExports
     }
 
-    @Throws(IllegalStateException::class)
-    private fun exportFile(ocFile: OCFile) {
-        FileExportUtils().exportFile(
-            ocFile.fileName,
-            ocFile.mimeType,
-            contentResolver,
-            ocFile,
-            null
-        )
-    }
-
-    private fun downloadFile(ocFile: OCFile) {
-        FileDownloadHelper.instance().downloadFile(
-            user,
-            ocFile,
-            downloadType = DownloadType.EXPORT
-        )
-    }
-
     private fun showErrorNotification(successfulExports: Int) {
         val message = if (successfulExports == 0) {
             appContext.resources.getQuantityString(R.plurals.export_failed, successfulExports, successfulExports)

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

@@ -397,8 +397,10 @@ public class FileMenuFilter {
     }
 
     private boolean anyFileDownloading() {
+        final var fileDownloadHelper = FileDownloadHelper.Companion.instance();
+
         for (OCFile file : files) {
-            if (FileDownloadHelper.Companion.instance().isDownloading(user, file)) {
+            if (fileDownloadHelper.isDownloading(user, file)) {
                 return true;
             }
         }

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

@@ -441,7 +441,8 @@ public class SynchronizeFolderOperation extends SyncOperation {
     }
 
     private void startDirectDownloads() {
-        mFilesForDirectDownload.forEach(file -> FileDownloadHelper.Companion.instance().downloadFile(user, file));
+        final var fileDownloadHelper = FileDownloadHelper.Companion.instance();
+        mFilesForDirectDownload.forEach(file -> fileDownloadHelper.downloadFile(user, file));
     }
 
     /**

+ 2 - 1
app/src/main/java/com/owncloud/android/ui/adapter/OCFileListDelegate.kt

@@ -335,10 +335,11 @@ class OCFileListDelegate(
 
     private fun showLocalFileIndicator(file: OCFile, gridViewHolder: ListViewHolder) {
         val operationsServiceBinder = transferServiceGetter.operationsServiceBinder
+        val fileDownloadHelper = FileDownloadHelper.instance()
 
         val icon: Int? = when {
             operationsServiceBinder?.isSynchronizing(user, file) == true ||
-                FileDownloadHelper.instance().isDownloading(user, file) ||
+                fileDownloadHelper.isDownloading(user, file) ||
                 fileUploadHelper.isUploading(user, file) -> {
                 // synchronizing, downloading or uploading
                 R.drawable.ic_synchronizing

+ 4 - 2
app/src/main/java/com/owncloud/android/ui/preview/PreviewMediaActivity.kt

@@ -653,13 +653,15 @@ class PreviewMediaActivity :
         packageName: String? = null,
         activityName: String? = null
     ) {
-        if (FileDownloadHelper.instance().isDownloading(user, file)) {
+        val fileDownloadHelper = FileDownloadHelper.instance()
+
+        if (fileDownloadHelper.isDownloading(user, file)) {
             return
         }
 
         user?.let { user ->
             file?.let { file ->
-                FileDownloadHelper.instance().downloadFile(
+                fileDownloadHelper.downloadFile(
                     user,
                     file,
                     downloadBehavior ?: "",