Browse Source

update other binder functions for use with file upload worker -> working progress bar

Signed-off-by: Jonas Mayer <jonas.a.mayer@gmx.net>
Jonas Mayer 1 year ago
parent
commit
f65601f69f

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

@@ -56,6 +56,7 @@ import com.owncloud.android.ui.activity.ConflictsResolveActivity
 import com.owncloud.android.ui.activity.UploadListActivity
 import com.owncloud.android.ui.notifications.NotificationUtils
 import com.owncloud.android.utils.ErrorMessageAdapter
+import com.owncloud.android.utils.FilesUploadHelper
 import com.owncloud.android.utils.theme.ViewThemeUtils
 import java.io.File
 import java.security.SecureRandom
@@ -77,7 +78,7 @@ class FilesUploadWorker(
     private val notificationManager: NotificationManager =
         context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
     private val fileUploaderDelegate = FileUploaderDelegate()
-    private var currentUploadFileOperation: UploadFileOperation? = null
+
 
     override fun doWork(): Result {
         val accountName = inputData.getString(ACCOUNT)
@@ -379,7 +380,7 @@ class FilesUploadWorker(
             val text = String.format(context.getString(R.string.uploader_upload_in_progress_content), percent, fileName)
             notificationBuilder.setContentText(text)
             notificationManager.notify(FOREGROUND_SERVICE_ID, notificationBuilder.build())
-            //FilesUploadHelper.onTransferProgress(,progressRate,totalTransferredSoFar,totalToTransfer,fileAbsoluteName)
+            FilesUploadHelper.onTransferProgress(currentUploadFileOperation?.user?.accountName,currentUploadFileOperation?.remotePath,progressRate,totalTransferredSoFar,totalToTransfer,fileAbsoluteName)
         }
         lastPercent = percent
 
@@ -396,5 +397,6 @@ class FilesUploadWorker(
         private const val FOREGROUND_SERVICE_ID: Int = 412
         private const val MAX_PROGRESS: Int = 100
         const val ACCOUNT = "data_account"
+        var currentUploadFileOperation: UploadFileOperation? = null
     }
 }

+ 28 - 7
app/src/main/java/com/owncloud/android/files/services/FileUploader.java

@@ -1228,6 +1228,7 @@ public class FileUploader extends Service
         }
 
         public void clearListeners() {
+            FilesUploadHelper.Progress.getMBoundListeners().clear();
             mBoundListeners.clear();
         }
 
@@ -1247,16 +1248,36 @@ public class FileUploader extends Service
             if (user == null || file == null) {
                 return false;
             }
-
-            return mPendingUploads.contains(user.getAccountName(), file.getRemotePath());
+            if (useFilesUploadWorker(getApplicationContext())){
+                // Not same as for service because upload list is "created" on the spot in the worker and not available here
+                /*** TODO: LEADS TO PERFORMANCE ISSUES -> Find better way
+                 *   OCUpload upload = mUploadsStorageManager.getUploadByRemotePath(file.getRemotePath());
+                 *   if (upload == null){
+                 *       return false;
+                 *   }
+                 *   return upload.getUploadStatus() == UploadStatus.UPLOAD_IN_PROGRESS;
+                 */
+                return false;
+            }else{
+                return mPendingUploads.contains(user.getAccountName(), file.getRemotePath());
+            }
         }
 
         public boolean isUploadingNow(OCUpload upload) {
-            return upload != null &&
-                mCurrentAccount != null &&
-                mCurrentUpload != null &&
-                upload.getAccountName().equals(mCurrentAccount.name) &&
-                upload.getRemotePath().equals(mCurrentUpload.getRemotePath());
+            if (useFilesUploadWorker(getApplicationContext())){
+                UploadFileOperation currentUploadFileOperation = FilesUploadWorker.Companion.getCurrentUploadFileOperation();
+                if (currentUploadFileOperation == null || currentUploadFileOperation.getUser() == null) return false;
+                return upload != null &&
+                    currentUploadFileOperation.getUser().getAccountName() != null &&
+                    upload.getAccountName().equals(currentUploadFileOperation.getUser().getAccountName()) &&
+                    upload.getRemotePath().equals(currentUploadFileOperation.getRemotePath());
+            }else {
+                return upload != null &&
+                    mCurrentAccount != null &&
+                    mCurrentUpload != null &&
+                    upload.getAccountName().equals(mCurrentAccount.name) &&
+                    upload.getRemotePath().equals(mCurrentUpload.getRemotePath());
+            }
         }
 
         /**

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

@@ -328,6 +328,7 @@ public class UploadListActivity extends FileActivity {
                     mUploaderBinder = (FileUploaderBinder) service;
                     Log_OC.d(TAG, "UploadListActivity connected to Upload service. component: " +
                             component + " service: " + service);
+                    uploadListAdapter.loadUploadItemsFromDb();
                 } else {
                     Log_OC.d(TAG, "mUploaderBinder already set. mUploaderBinder: " +
                             mUploaderBinder + " service:" + service);

+ 3 - 1
app/src/main/java/com/owncloud/android/utils/FilesUploadHelper.kt

@@ -136,7 +136,9 @@ class FilesUploadHelper {
     companion object Progress{
         val mBoundListeners = HashMap<String, OnDatatransferProgressListener>()
 
-        fun onTransferProgress(accountName : String, remotePath : String, progressRate: Long, totalTransferredSoFar: Long, totalToTransfer: Long, fileName: String?) {
+        fun onTransferProgress(accountName : String?, remotePath : String?, progressRate: Long, totalTransferredSoFar: Long, totalToTransfer: Long, fileName: String?) {
+            if (accountName == null || remotePath == null) return
+
             val key: String =
                 FileUploaderBinder.buildRemoteName(accountName,remotePath)
             val boundListener = mBoundListeners[key]