Browse Source

Add listener to let FileUploader know about a rename

Juan Carlos González Cabrero 9 years ago
parent
commit
cbf619be77

+ 11 - 1
src/com/owncloud/android/files/services/FileUploader.java

@@ -89,7 +89,7 @@ import java.util.Vector;
  * However, Intent keys (e.g., KEY_WIFI_ONLY) are obeyed.
  */
 public class FileUploader extends Service
-        implements OnDatatransferProgressListener, OnAccountsUpdateListener {
+        implements OnDatatransferProgressListener, OnAccountsUpdateListener, UploadFileOperation.OnRenameListener {
 
     private static final String TAG = FileUploader.class.getSimpleName();
 
@@ -183,6 +183,12 @@ public class FileUploader extends Service
         return FileUploader.class.getName() + UPLOAD_FINISH_MESSAGE;
     }
 
+    @Override
+    public void onRenameUpload() {
+        mUploadsStorageManager.updateDatabaseUploadStart(mCurrentUpload);
+        sendBroadcastUploadStarted(mCurrentUpload);
+    }
+
 
     /**
      * Helper class providing methods to ease requesting commands to {@link FileUploader} .
@@ -492,6 +498,8 @@ public class FileUploader extends Service
                     newUpload.addDatatransferProgressListener(this);
                     newUpload.addDatatransferProgressListener((FileUploaderBinder) mBinder);
 
+                    newUpload.addRenameUploadListener(this);
+
                     // Save upload in database
                     OCUpload ocUpload = new OCUpload(files[i], account);
                     ocUpload.setFileSize(files[i].getFileLength());
@@ -555,6 +563,8 @@ public class FileUploader extends Service
             newUpload.addDatatransferProgressListener(this);
             newUpload.addDatatransferProgressListener((FileUploaderBinder) mBinder);
 
+            newUpload.addRenameUploadListener(this);
+
             Pair<String, String> putResult = mPendingUploads.putIfAbsent(
                     account.name,
                     upload.getRemotePath(),

+ 10 - 3
src/com/owncloud/android/operations/UploadFileOperation.java

@@ -26,7 +26,6 @@ import android.net.Uri;
 
 import com.owncloud.android.datamodel.FileDataStorageManager;
 import com.owncloud.android.datamodel.OCFile;
-import com.owncloud.android.datamodel.UploadsStorageManager;
 import com.owncloud.android.db.OCUpload;
 import com.owncloud.android.files.services.FileUploader;
 import com.owncloud.android.lib.common.OwnCloudClient;
@@ -154,6 +153,7 @@ public class UploadFileOperation extends SyncOperation {
      */
     private String mOriginalStoragePath = null;
     private Set<OnDatatransferProgressListener> mDataTransferListeners = new HashSet<OnDatatransferProgressListener>();
+    private OnRenameListener mRenameUploadListener;
 
     private final AtomicBoolean mCancellationRequested = new AtomicBoolean(false);
     private final AtomicBoolean mUploadStarted = new AtomicBoolean(false);
@@ -327,6 +327,10 @@ public class UploadFileOperation extends SyncOperation {
         }
     }
 
+    public void addRenameUploadListener (OnRenameListener listener) {
+        mRenameUploadListener = listener;
+    }
+
     @Override
     protected RemoteOperationResult run(OwnCloudClient client) {
         mCancellationRequested.set(false);
@@ -365,8 +369,7 @@ public class UploadFileOperation extends SyncOperation {
                     Log_OC.d(TAG, "File renamed as " + remotePath);
                 }
                 mRemotePath = remotePath;
-                UploadsStorageManager usm = new UploadsStorageManager(mContext.getContentResolver());
-                usm.updateDatabaseUploadStart(this);
+                mRenameUploadListener.onRenameUpload();
             }
 
             if (mCancellationRequested.get()) {
@@ -816,5 +819,9 @@ public class UploadFileOperation extends SyncOperation {
         file.setRemoteId(remoteFile.getRemoteId());
     }
 
+    public interface OnRenameListener {
+
+        void onRenameUpload();
+    }
 
 }