Workaround to show hidden accents in options menu
[pub/Android/ownCloud.git] / src / com / owncloud / android / syncadapter / FileSyncAdapter.java
index ea833d4..e977e41 100644 (file)
@@ -28,15 +28,10 @@ import com.owncloud.android.R;
 import com.owncloud.android.datamodel.DataStorageManager;\r
 import com.owncloud.android.datamodel.FileDataStorageManager;\r
 import com.owncloud.android.datamodel.OCFile;\r
-//<<<<<<< HEAD
 import com.owncloud.android.operations.RemoteOperationResult;\r
 import com.owncloud.android.operations.SynchronizeFolderOperation;\r
 import com.owncloud.android.operations.UpdateOCVersionOperation;\r
-/*=======
-import com.owncloud.android.files.services.FileDownloader;\r
-import com.owncloud.android.files.services.FileObserverService;\r
-import com.owncloud.android.utils.OwnCloudVersion;\r
->>>>>>> origin/master*/
+import com.owncloud.android.operations.RemoteOperationResult.ResultCode;\r
 \r
 import android.accounts.Account;\r
 import android.app.Notification;\r
@@ -71,6 +66,8 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
     private int mFailedResultsCounter;    \r
     private RemoteOperationResult mLastFailedResult;\r
     private SyncResult mSyncResult;\r
+    private int mConflictsFound;\r
+    private int mFailsInFavouritesFound;\r
     \r
     public FileSyncAdapter(Context context, boolean autoInitialize) {\r
         super(context, autoInitialize);\r
@@ -88,6 +85,8 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
         mIsManualSync = extras.getBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, false);\r
         mFailedResultsCounter = 0;\r
         mLastFailedResult = null;\r
+        mConflictsFound = 0;\r
+        mFailsInFavouritesFound = 0;\r
         mSyncResult = syncResult;\r
         mSyncResult.fullSyncRequested = false;\r
         mSyncResult.delayUntil = 60*60*24; // sync after 24h\r
@@ -128,13 +127,15 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
                 \r
                 /// notify the user about the failure of MANUAL synchronization\r
                 notifyFailedSynchronization();\r
+                \r
+            } else if (mConflictsFound > 0 || mFailsInFavouritesFound > 0) {\r
+                notifyFailsInFavourites();\r
             }\r
             sendStickyBroadcast(false, null, mLastFailedResult);        // message to signal the end to the UI\r
         }\r
         \r
     }\r
-    \r
-    \r
+\r
     \r
     /**\r
      * Called by system SyncManager when a synchronization is required to be cancelled.\r
@@ -188,12 +189,16 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
         // synchronized folder -> notice to UI - ALWAYS, although !result.isSuccess\r
         sendStickyBroadcast(true, remotePath, null);\r
         \r
-        if (result.isSuccess()) {\r
+        if (result.isSuccess() || result.getCode() == ResultCode.SYNC_CONFLICT) {\r
+            \r
+            if (result.getCode() == ResultCode.SYNC_CONFLICT) {\r
+                mConflictsFound += synchFolderOp.getConflictsFound();\r
+                mFailsInFavouritesFound += synchFolderOp.getFailsInFavouritesFound();\r
+            }\r
             // synchronize children folders \r
             List<OCFile> children = synchFolderOp.getChildren();\r
             fetchChildren(children);    // beware of the 'hidden' recursion here!\r
             \r
-//<<<<<<< HEAD
         } else {\r
             if (result.getCode() == RemoteOperationResult.ResultCode.UNAUTHORIZED) {\r
                 mSyncResult.stats.numAuthExceptions++;\r
@@ -203,33 +208,6 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
                 \r
             } else if (result.getException() instanceof IOException) { \r
                 mSyncResult.stats.numIoExceptions++;\r
-/*=======
-                // insertion or update of files\r
-                List<OCFile> updatedFiles = new Vector<OCFile>(resp.getResponses().length - 1);\r
-                for (int i = 1; i < resp.getResponses().length; ++i) {\r
-                    WebdavEntry we = new WebdavEntry(resp.getResponses()[i], getUri().getPath());\r
-                    OCFile file = fillOCFile(we);\r
-                    file.setParentId(parentId);\r
-                    if (getStorageManager().getFileByPath(file.getRemotePath()) != null &&\r
-                            getStorageManager().getFileByPath(file.getRemotePath()).keepInSync() &&\r
-                            file.getModificationTimestamp() > getStorageManager().getFileByPath(file.getRemotePath())\r
-                                                                         .getModificationTimestamp()) {\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
-                        getContext().startService(intent);\r
-                    }\r
-                    if (getStorageManager().getFileByPath(file.getRemotePath()) != null)\r
-                        file.setKeepInSync(getStorageManager().getFileByPath(file.getRemotePath()).keepInSync());\r
->>>>>>> origin/master*/
-                \r
             }\r
             mFailedResultsCounter++;\r
             mLastFailedResult = result;\r
@@ -308,6 +286,35 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
         ((NotificationManager) getContext().getSystemService(Context.NOTIFICATION_SERVICE)).notify(R.string.sync_fail_ticker, notification);\r
     }\r
 \r
-    \r
+\r
+    /**\r
+     * Notifies the user about conflicts and strange fails when trying to synchronize the contents of favourite files.\r
+     * \r
+     * By now, we won't consider a failed synchronization.\r
+     */\r
+    private void notifyFailsInFavourites() {\r
+        if (mFailedResultsCounter > 0) {\r
+            Notification notification = new Notification(R.drawable.icon, getContext().getString(R.string.sync_fail_in_favourites_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(), (int)System.currentTimeMillis(), new Intent(), 0);\r
+            notification.setLatestEventInfo(getContext().getApplicationContext(), \r
+                                            getContext().getString(R.string.sync_fail_in_favourites_ticker), \r
+                                            String.format(getContext().getString(R.string.sync_fail_in_favourites_content), mFailedResultsCounter + mConflictsFound, mConflictsFound), \r
+                                            notification.contentIntent);\r
+            ((NotificationManager) getContext().getSystemService(Context.NOTIFICATION_SERVICE)).notify(R.string.sync_fail_in_favourites_ticker, notification);\r
+            \r
+        } else {\r
+            Notification notification = new Notification(R.drawable.icon, getContext().getString(R.string.sync_conflicts_in_favourites_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(), (int)System.currentTimeMillis(), new Intent(), 0);\r
+            notification.setLatestEventInfo(getContext().getApplicationContext(), \r
+                                            getContext().getString(R.string.sync_conflicts_in_favourites_ticker), \r
+                                            String.format(getContext().getString(R.string.sync_conflicts_in_favourites_content), mConflictsFound), \r
+                                            notification.contentIntent);\r
+            ((NotificationManager) getContext().getSystemService(Context.NOTIFICATION_SERVICE)).notify(R.string.sync_conflicts_in_favourites_ticker, notification);\r
+        } \r
+    }\r
 \r
 }\r