Improved error messages in gallery for images that can not be loaded
[pub/Android/ownCloud.git] / src / com / owncloud / android / syncadapter / FileSyncAdapter.java
index e977e41..f66980c 100644 (file)
@@ -20,7 +20,10 @@ package com.owncloud.android.syncadapter;
 \r
 import java.io.IOException;\r
 import java.net.UnknownHostException;\r
+import java.util.ArrayList;\r
+import java.util.HashMap;\r
 import java.util.List;\r
+import java.util.Map;\r
 \r
 import org.apache.jackrabbit.webdav.DavException;\r
 \r
@@ -32,7 +35,7 @@ import com.owncloud.android.operations.RemoteOperationResult;
 import com.owncloud.android.operations.SynchronizeFolderOperation;\r
 import com.owncloud.android.operations.UpdateOCVersionOperation;\r
 import com.owncloud.android.operations.RemoteOperationResult.ResultCode;\r
-\r
+import com.owncloud.android.ui.activity.ErrorsWhileCopyingHandlerActivity;\r
 import android.accounts.Account;\r
 import android.app.Notification;\r
 import android.app.NotificationManager;\r
@@ -68,6 +71,8 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
     private SyncResult mSyncResult;\r
     private int mConflictsFound;\r
     private int mFailsInFavouritesFound;\r
+    private Map<String, String> mForgottenLocalFiles;\r
+\r
     \r
     public FileSyncAdapter(Context context, boolean autoInitialize) {\r
         super(context, autoInitialize);\r
@@ -87,6 +92,7 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
         mLastFailedResult = null;\r
         mConflictsFound = 0;\r
         mFailsInFavouritesFound = 0;\r
+        mForgottenLocalFiles = new HashMap<String, String>();\r
         mSyncResult = syncResult;\r
         mSyncResult.fullSyncRequested = false;\r
         mSyncResult.delayUntil = 60*60*24; // sync after 24h\r
@@ -128,9 +134,14 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
                 /// notify the user about the failure of MANUAL synchronization\r
                 notifyFailedSynchronization();\r
                 \r
-            } else if (mConflictsFound > 0 || mFailsInFavouritesFound > 0) {\r
+            }\r
+            if (mConflictsFound > 0 || mFailsInFavouritesFound > 0) {\r
                 notifyFailsInFavourites();\r
             }\r
+            if (mForgottenLocalFiles.size() > 0) {\r
+                notifyForgottenLocalFiles();\r
+                \r
+            }\r
             sendStickyBroadcast(false, null, mLastFailedResult);        // message to signal the end to the UI\r
         }\r
         \r
@@ -195,6 +206,9 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
                 mConflictsFound += synchFolderOp.getConflictsFound();\r
                 mFailsInFavouritesFound += synchFolderOp.getFailsInFavouritesFound();\r
             }\r
+            if (synchFolderOp.getForgottenLocalFiles().size() > 0) {\r
+                mForgottenLocalFiles.putAll(synchFolderOp.getForgottenLocalFiles());\r
+            }\r
             // synchronize children folders \r
             List<OCFile> children = synchFolderOp.getChildren();\r
             fetchChildren(children);    // beware of the 'hidden' recursion here!\r
@@ -288,7 +302,7 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
 \r
 \r
     /**\r
-     * Notifies the user about conflicts and strange fails when trying to synchronize the contents of favourite files.\r
+     * Notifies the user about conflicts and strange fails when trying to synchronize the contents of kept-in-sync files.\r
      * \r
      * By now, we won't consider a failed synchronization.\r
      */\r
@@ -317,4 +331,39 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
         } \r
     }\r
 \r
+    \r
+    /**\r
+     * Notifies the user about local copies of files out of the ownCloud local directory that were 'forgotten' because \r
+     * copying them inside the ownCloud local directory was not possible.\r
+     * \r
+     * We don't want links to files out of the ownCloud local directory (foreign files) anymore. It's easy to have \r
+     * synchronization problems if a local file is linked to more than one remote file.\r
+     * \r
+     * We won't consider a synchronization as failed when foreign files can not be copied to the ownCloud local directory.\r
+     */\r
+    private void notifyForgottenLocalFiles() {\r
+        Notification notification = new Notification(R.drawable.icon, getContext().getString(R.string.sync_foreign_files_forgotten_ticker), System.currentTimeMillis());\r
+        notification.flags |= Notification.FLAG_AUTO_CANCEL;\r
+\r
+        /// includes a pending intent in the notification showing a more detailed explanation\r
+        Intent explanationIntent = new Intent(getContext(), ErrorsWhileCopyingHandlerActivity.class);\r
+        explanationIntent.putExtra(ErrorsWhileCopyingHandlerActivity.EXTRA_ACCOUNT, getAccount());\r
+        ArrayList<String> remotePaths = new ArrayList<String>();\r
+        ArrayList<String> localPaths = new ArrayList<String>();\r
+        remotePaths.addAll(mForgottenLocalFiles.keySet());\r
+        localPaths.addAll(mForgottenLocalFiles.values());\r
+        explanationIntent.putExtra(ErrorsWhileCopyingHandlerActivity.EXTRA_LOCAL_PATHS, localPaths);\r
+        explanationIntent.putExtra(ErrorsWhileCopyingHandlerActivity.EXTRA_REMOTE_PATHS, remotePaths);  \r
+        explanationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);\r
+        \r
+        notification.contentIntent = PendingIntent.getActivity(getContext().getApplicationContext(), (int)System.currentTimeMillis(), explanationIntent, 0);\r
+        notification.setLatestEventInfo(getContext().getApplicationContext(), \r
+                                        getContext().getString(R.string.sync_foreign_files_forgotten_ticker), \r
+                                        String.format(getContext().getString(R.string.sync_foreign_files_forgotten_content), mForgottenLocalFiles.size(), getContext().getString(R.string.app_name)), \r
+                                        notification.contentIntent);\r
+        ((NotificationManager) getContext().getSystemService(Context.NOTIFICATION_SERVICE)).notify(R.string.sync_foreign_files_forgotten_ticker, notification);\r
+        \r
+    }\r
+    \r
+    \r
 }\r