Two way synchronization for files
[pub/Android/ownCloud.git] / src / com / owncloud / android / syncadapter / FileSyncAdapter.java
index 5b398c0..8c9a153 100644 (file)
@@ -34,6 +34,7 @@ import com.owncloud.android.authenticator.AccountAuthenticator;
 import com.owncloud.android.datamodel.FileDataStorageManager;\r
 import com.owncloud.android.datamodel.OCFile;\r
 import com.owncloud.android.files.services.FileDownloader;\r
+import com.owncloud.android.files.services.FileObserverService;\r
 import com.owncloud.android.utils.OwnCloudVersion;\r
 \r
 import android.accounts.Account;\r
@@ -211,7 +212,13 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
                             getStorageManager().getFileByPath(file.getRemotePath()).keepInSync() &&\r
                             file.getModificationTimestamp() > getStorageManager().getFileByPath(file.getRemotePath())\r
                                                                          .getModificationTimestamp()) {\r
-                        Intent intent = new Intent(this.getContext(), FileDownloader.class);\r
+                        // first disable observer so we won't get file upload right after download\r
+                        Log.d(TAG, "Disabling observation of remote file" + file.getRemotePath());\r
+                        Intent intent = new Intent(getContext(), FileObserverService.class);\r
+                        intent.putExtra(FileObserverService.KEY_FILE_CMD, FileObserverService.CMD_ADD_DOWNLOADING_FILE);\r
+                        intent.putExtra(FileObserverService.KEY_CMD_ARG, file.getRemotePath());\r
+                        getContext().startService(intent);\r
+                        intent = new Intent(this.getContext(), FileDownloader.class);\r
                         intent.putExtra(FileDownloader.EXTRA_ACCOUNT, getAccount());\r
                         intent.putExtra(FileDownloader.EXTRA_FILE, file);\r
                         file.setKeepInSync(true);\r