Two way synchronization for files
[pub/Android/ownCloud.git] / src / com / owncloud / android / syncadapter / FileSyncAdapter.java
index 7f4cf61..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
@@ -149,7 +150,7 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
                 Notification notification = new Notification(R.drawable.icon, getContext().getString(R.string.sync_fail_ticker), System.currentTimeMillis());\r
                 notification.flags |= Notification.FLAG_AUTO_CANCEL;\r
                 // TODO put something smart in the contentIntent below\r
-                notification.contentIntent = PendingIntent.getActivity(getContext().getApplicationContext(), 0, new Intent(), PendingIntent.FLAG_UPDATE_CURRENT);\r
+                notification.contentIntent = PendingIntent.getActivity(getContext().getApplicationContext(), (int)System.currentTimeMillis(), new Intent(), 0);\r
                 notification.setLatestEventInfo(getContext().getApplicationContext(), \r
                                                 getContext().getString(R.string.sync_fail_ticker), \r
                                                 String.format(getContext().getString(R.string.sync_fail_content), account.name), \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