Fixed bug: when a file is checked as 'keep in sync' and the immediate synchronization...
[pub/Android/ownCloud.git] / src / com / owncloud / android / files / services / FileObserverService.java
index effa520..cfd5fec 100644 (file)
@@ -27,6 +27,8 @@ import com.owncloud.android.datamodel.OCFile;
 import com.owncloud.android.db.ProviderMeta.ProviderTableMeta;
 import com.owncloud.android.files.OwnCloudFileObserver;
 import com.owncloud.android.files.OwnCloudFileObserver.FileObserverStatusListener;
+import com.owncloud.android.operations.RemoteOperationResult;
+import com.owncloud.android.operations.RemoteOperationResult.ResultCode;
 import com.owncloud.android.ui.activity.ConflictsResolveActivity;
 import com.owncloud.android.utils.FileStorageUtils;
 
@@ -154,10 +156,6 @@ public class FileObserverService extends Service implements FileObserverStatusLi
      * Registers the local copy of a remote file to be observed for local changes,
      * an automatically updated in the ownCloud server.
      *
-     * If there is no local copy of the remote file, a request to download it is send
-     * to the FileDownloader service. The observation is delayed until the download
-     * is finished.
-     * 
      * @param file      Object representing a remote file which local copy must be observed.
      * @param account   OwnCloud account containing file.
      */
@@ -214,11 +212,6 @@ public class FileObserverService extends Service implements FileObserverStatusLi
             DownloadCompletedReceiver receiver = new DownloadCompletedReceiver(localPath, observer);
             registerReceiver(receiver, new IntentFilter(FileDownloader.DOWNLOAD_FINISH_MESSAGE));
 
-            Intent i = new Intent(this, FileDownloader.class);
-            i.putExtra(FileDownloader.EXTRA_ACCOUNT, account);
-            i.putExtra(FileDownloader.EXTRA_FILE, file);
-            startService(i);
-            
         } else {
             observer.startWatching();
             Log.d(TAG, "Started watching " + localPath);
@@ -302,10 +295,9 @@ public class FileObserverService extends Service implements FileObserverStatusLi
     }
 
     @Override
-    public void OnObservedFileStatusUpdate(String localPath, String remotePath, Account account, Status status) {
-        switch (status) {
-            case CONFLICT:
-            {
+    public void onObservedFileStatusUpdate(String localPath, String remotePath, Account account, RemoteOperationResult result) {
+        if (!result.isSuccess()) {
+            if (result.getCode() == ResultCode.SYNC_CONFLICT) {
                 // ISSUE 5: if the user is not running the app (this is a service!), this can be very intrusive; a notification should be preferred
                 Intent i = new Intent(getApplicationContext(), ConflictsResolveActivity.class);
                 i.setFlags(i.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK);
@@ -313,14 +305,11 @@ public class FileObserverService extends Service implements FileObserverStatusLi
                 i.putExtra("localpath", localPath);
                 i.putExtra("account", account);
                 startActivity(i);
-                break;
+                
+            } else {
+                // TODO send notification to the notification bar?
             }
-            case SENDING_TO_UPLOADER:
-            case INCORRECT_MASK:
-                break;
-            default:
-                Log.wtf(TAG, "Unhandled status " + status);
-        }
+        } // else, nothing else to do; now it's duty of FileUploader service 
     }
 
     private class DownloadCompletedReceiver extends BroadcastReceiver {