OSDN Git Service

Merge "CMFM: Remove orphan bookmarks" into cm-11.0
authorJorge Ruesga <jorge@ruesga.com>
Fri, 15 Nov 2013 22:56:24 +0000 (22:56 +0000)
committerGerrit Code Review <gerrit@cyanogenmod.org>
Fri, 15 Nov 2013 22:56:24 +0000 (22:56 +0000)
src/com/cyanogenmod/filemanager/preferences/Bookmarks.java
src/com/cyanogenmod/filemanager/ui/policy/CopyMoveActionPolicy.java
src/com/cyanogenmod/filemanager/ui/policy/DeleteActionPolicy.java

index 998b715..0c76a23 100644 (file)
@@ -152,6 +152,33 @@ public class Bookmarks {
     }
 
     /**
+     * Method that remove all orphan bookmarks derived from "path"
+     *
+     * @param ctx The current context
+     * @param path The path to check
+     */
+    public static void deleteOrphanBookmarks(Context ctx, String path) {
+        ContentResolver cr = ctx.getContentResolver();
+        Cursor cursor = Bookmarks.getAllBookmarks(cr);
+        try {
+            if (cursor != null && cursor.moveToFirst()) {
+                do {
+                    Bookmark bm = new Bookmark(cursor);
+                    if (bm.mPath.startsWith(path)) {
+                        removeBookmark(ctx, bm);
+                    }
+                } while (cursor.moveToNext());
+            }
+        } finally {
+            try {
+                if (cursor != null) {
+                    cursor.close();
+                }
+            } catch (Exception e) {/**NON BLOCK**/}
+        }
+    }
+
+    /**
      * Method that create the {@link ContentValues} from the bookmark
      *
      * @param bookmark The bookmark
index 1f583e9..c2923f3 100644 (file)
@@ -28,6 +28,7 @@ import com.cyanogenmod.filemanager.console.RelaunchableException;
 import com.cyanogenmod.filemanager.listeners.OnRequestRefreshListener;
 import com.cyanogenmod.filemanager.listeners.OnSelectionListener;
 import com.cyanogenmod.filemanager.model.FileSystemObject;
+import com.cyanogenmod.filemanager.preferences.Bookmarks;
 import com.cyanogenmod.filemanager.util.CommandHelper;
 import com.cyanogenmod.filemanager.util.DialogHelper;
 import com.cyanogenmod.filemanager.util.ExceptionUtil;
@@ -302,6 +303,13 @@ public final class CopyMoveActionPolicy extends ActionsPolicy {
 
             @Override
             public void onSuccess() {
+                // Remove orphan bookmark paths
+                if (files != null) {
+                    for (LinkedResource linkedFiles : files) {
+                        Bookmarks.deleteOrphanBookmarks(ctx, linkedFiles.mSrc.getAbsolutePath());
+                    }
+                }
+
                 //Operation complete. Refresh
                 if (this.mOnRequestRefreshListener != null) {
                   // The reference is not the same, so refresh the complete navigation view
index 039f4fe..843afe2 100644 (file)
@@ -28,6 +28,7 @@ import com.cyanogenmod.filemanager.console.RelaunchableException;
 import com.cyanogenmod.filemanager.listeners.OnRequestRefreshListener;
 import com.cyanogenmod.filemanager.listeners.OnSelectionListener;
 import com.cyanogenmod.filemanager.model.FileSystemObject;
+import com.cyanogenmod.filemanager.preferences.Bookmarks;
 import com.cyanogenmod.filemanager.ui.widgets.FlingerListView.OnItemFlingerResponder;
 import com.cyanogenmod.filemanager.util.CommandHelper;
 import com.cyanogenmod.filemanager.util.DialogHelper;
@@ -192,6 +193,13 @@ public final class DeleteActionPolicy extends ActionsPolicy {
                     onItemFlingerResponder.accept();
                 }
 
+                // Remove orphan bookmark paths
+                if (files != null) {
+                    for (FileSystemObject fso : files) {
+                        Bookmarks.deleteOrphanBookmarks(ctx, fso.getFullPath());
+                    }
+                }
+
                 // Refresh
                 if (this.mOnRequestRefreshListener != null) {
                     // The reference is not the same, so refresh the complete navigation view
@@ -232,7 +240,6 @@ public final class DeleteActionPolicy extends ActionsPolicy {
              * @param ctx The current context
              * @param fso The file or folder to be deleted
              */
-            @SuppressWarnings("hiding")
             private void doOperation(
                     final Context ctx, final FileSystemObject fso) throws Throwable {
                 try {