OSDN Git Service

Bookmarks: check to see if a bookmark exists before adding it
authorStephen Bird <sbird@cyngn.com>
Mon, 24 Aug 2015 22:07:33 +0000 (15:07 -0700)
committerStephen Bird <sbird@cyngn.com>
Mon, 24 Aug 2015 22:09:00 +0000 (15:09 -0700)
Previously, this would result in multiple bookmarks
of the same location

Ticket: QRDL-989
Change-Id: I0f19045bc7a6d5fa98c9ef4ee1a8ccda9c501eb1

res/values/strings.xml
src/com/cyanogenmod/filemanager/ui/dialogs/ActionsDialog.java
src/com/cyanogenmod/filemanager/ui/policy/BookmarksActionPolicy.java

index 0898014..75d91ec 100644 (file)
     <string name="bookmarks_button_remove_bookmark_cd">Remove the bookmark.</string>
     <!-- Bookmarks - Bookmarks - Actions - Bookmark successfully added -->
     <string name="bookmarks_msgs_add_success">The bookmark was added successfully.</string>
+    <!-- Bookmarks - Bookmarks - Actions - Bookmark already exists -->
+    <string name="bookmarks_msgs_add_exists">The bookmark was already exists.</string>
 
     <!-- Initial directory dialog title -->
     <string name="initial_directory_dialog_title">Initial folder</string>
index 44bfedd..ecc7ce2 100644 (file)
@@ -400,7 +400,7 @@ public class ActionsDialog implements OnItemClickListener, OnItemLongClickListen
             case R.id.mnu_actions_add_to_bookmarks_current_folder:
                 Bookmark bookmark = BookmarksActionPolicy.addToBookmarks(
                         this.mContext, this.mFso);
-                if (mBackRef != null) {
+                if (mBackRef != null && bookmark != null) {
                     // tell NavigationActivity's drawer to add the bookmark
                     mBackRef.addBookmark(bookmark);
                 }
index ce3fe2e..483d8ab 100644 (file)
@@ -40,6 +40,15 @@ public final class BookmarksActionPolicy extends ActionsPolicy {
      */
     public static Bookmark addToBookmarks(final Context ctx, final FileSystemObject fso) {
         try {
+            // Check if the bookmark exists already
+            if (Bookmarks.getBookmark(ctx.getContentResolver(), fso.getFullPath()) != null) {
+                DialogHelper.showToast(
+                        ctx,
+                        R.string.bookmarks_msgs_add_exists,
+                        Toast.LENGTH_SHORT);
+                return null;
+            }
+
             // Create the bookmark
             Bookmark bookmark =
                     new Bookmark(BOOKMARK_TYPE.USER_DEFINED, fso.getName(), fso.getFullPath());