Эх сурвалжийг харах

implement isUploading for Upload Worker

Signed-off-by: Jonas Mayer <jonas.a.mayer@gmx.net>
Jonas Mayer 1 жил өмнө
parent
commit
8e141506ec

+ 18 - 0
app/src/main/java/com/owncloud/android/datamodel/UploadsStorageManager.java

@@ -345,6 +345,24 @@ public class UploadsStorageManager extends Observable {
         return getUploads(null, (String[]) null);
     }
 
+    public OCUpload getUploadByRemotePath(String remotePath){
+        OCUpload result = null;
+        Cursor cursor = getDB().query(
+            ProviderTableMeta.CONTENT_URI_UPLOADS,
+            null,
+            ProviderTableMeta.UPLOADS_REMOTE_PATH + "=?",
+            new String[]{remotePath},
+            ProviderTableMeta.UPLOADS_REMOTE_PATH+ " ASC");
+
+        if (cursor != null) {
+            if (cursor.moveToFirst()) {
+                result = createOCUploadFromCursor(cursor);
+            }
+        }
+        Log_OC.d(TAG, "Retrieve job " + result + " for remote path " + remotePath);
+        return result;
+    }
+
     public @Nullable
     OCUpload getUploadById(long id) {
         OCUpload result = null;

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

@@ -1250,14 +1250,13 @@ public class FileUploader extends Service
             }
             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;
+
+                 OCUpload upload = mUploadsStorageManager.getUploadByRemotePath(file.getRemotePath());
+                 if (upload == null){
+                     return false;
+                 }
+                 return upload.getUploadStatus() == UploadStatus.UPLOAD_IN_PROGRESS;
+
             }else{
                 return mPendingUploads.contains(user.getAccountName(), file.getRemotePath());
             }