Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f8a247d9 authored by Jorge Ruesga's avatar Jorge Ruesga
Browse files

CMFM: Remove orphan bookmarks



Change-Id: I921499b5ab8ef58a558bb95fbc6a8b8b5f08ac68
Signed-off-by: default avatarJorge Ruesga <jorge@ruesga.com>
parent d60e42f5
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
@@ -151,6 +151,33 @@ public class Bookmarks {
        return bookmark;
    }

    /**
     * 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
     *
+8 −0
Original line number Diff line number Diff line
@@ -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
+8 −1
Original line number Diff line number Diff line
@@ -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 {