]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/commitdiff
Hide the move to folder menu item if no folders exist. https://redmine.stoutner...
authorSoren Stoutner <soren@stoutner.com>
Fri, 22 Sep 2017 18:43:02 +0000 (11:43 -0700)
committerSoren Stoutner <soren@stoutner.com>
Fri, 22 Sep 2017 18:43:02 +0000 (11:43 -0700)
app/src/main/java/com/stoutner/privacybrowser/activities/BookmarksActivity.java
app/src/main/java/com/stoutner/privacybrowser/helpers/BookmarksDatabaseHelper.java
app/src/main/res/values-de/strings.xml
app/src/main/res/values-es/strings.xml
app/src/main/res/values-it/strings.xml
app/src/main/res/values/strings.xml

index a178d49aa77016ace5c45b8b101e4f45d3301da2..4536001b1554b4f586ac7468f5600a8a9d879358 100644 (file)
@@ -203,7 +203,17 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma
 
             @Override
             public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
-                return false;
+                // Get a handle for the move to folder menu item.
+                MenuItem moveToFolderMenuItem = menu.findItem(R.id.move_to_folder);
+
+                // Get a `Cursor` with all of the folders.
+                Cursor folderCursor = bookmarksDatabaseHelper.getAllFoldersCursor();
+
+                // Enable the move to folder menu item if at least one folder exists.
+                moveToFolderMenuItem.setVisible(folderCursor.getCount() > 0);
+
+                // `return true` indicates that the menu has been updated.
+                return true;
             }
 
             @Override
@@ -759,39 +769,35 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma
         ListView folderListView = (ListView) dialogFragment.getDialog().findViewById(R.id.move_to_folder_listview);
         long[] newFolderLongArray = folderListView.getCheckedItemIds();
 
-        if (newFolderLongArray.length == 0) {  // No new folder was selected.
-            Snackbar.make(findViewById(R.id.bookmarks_coordinatorlayout), getString(R.string.cannot_move_bookmarks), Snackbar.LENGTH_INDEFINITE).show();
-        } else {  // Move the selected bookmarks.
-            // Get the new folder database ID.
-            int newFolderDatabaseId = (int) newFolderLongArray[0];
-
-            // Instantiate `newFolderName`.
-            String newFolderName;
-
-            if (newFolderDatabaseId == 0) {
-                // The new folder is the home folder, represented as `""` in the database.
-                newFolderName = "";
-            } else {
-                // Get the new folder name from the database.
-                newFolderName = bookmarksDatabaseHelper.getFolderName(newFolderDatabaseId);
-            }
+        // Get the new folder database ID.
+        int newFolderDatabaseId = (int) newFolderLongArray[0];
 
-            // Get a long array with the the database ID of the selected bookmarks.
-            long[] selectedBookmarksLongArray = bookmarksListView.getCheckedItemIds();
-            for (long databaseIdLong : selectedBookmarksLongArray) {
-                // Get `databaseIdInt` for each selected bookmark.
-                int databaseIdInt = (int) databaseIdLong;
+        // Instantiate `newFolderName`.
+        String newFolderName;
 
-                // Move the selected bookmark to the new folder.
-                bookmarksDatabaseHelper.moveToFolder(databaseIdInt, newFolderName);
-            }
+        if (newFolderDatabaseId == 0) {
+            // The new folder is the home folder, represented as `""` in the database.
+            newFolderName = "";
+        } else {
+            // Get the new folder name from the database.
+            newFolderName = bookmarksDatabaseHelper.getFolderName(newFolderDatabaseId);
+        }
 
-            // Refresh the `ListView`.
-            updateBookmarksListView(currentFolder);
+        // Get a long array with the the database ID of the selected bookmarks.
+        long[] selectedBookmarksLongArray = bookmarksListView.getCheckedItemIds();
+        for (long databaseIdLong : selectedBookmarksLongArray) {
+            // Get `databaseIdInt` for each selected bookmark.
+            int databaseIdInt = (int) databaseIdLong;
 
-            // Close the contextual app bar.
-            contextualActionMode.finish();
+            // Move the selected bookmark to the new folder.
+            bookmarksDatabaseHelper.moveToFolder(databaseIdInt, newFolderName);
         }
+
+        // Refresh the `ListView`.
+        updateBookmarksListView(currentFolder);
+
+        // Close the contextual app bar.
+        contextualActionMode.finish();
     }
 
     private void updateBookmarksListView(String folderName) {
index 0cd2b683e9efb25237096a30b1a0c3d329dd4075..55cc346bd7e73f09790638df6cd071e3fe104518 100644 (file)
@@ -216,6 +216,19 @@ public class BookmarksDatabaseHelper extends SQLiteOpenHelper {
         return parentFolder;
     }
 
+    public Cursor getAllFoldersCursor() {
+        // Get a readable database handle.
+        SQLiteDatabase bookmarksDatabase = this.getReadableDatabase();
+
+        // Prepare the SQL statement to get the `Cursor` for all the folders.
+        final String GET_ALL_FOLDERS = "SELECT * FROM " + BOOKMARKS_TABLE +
+                " WHERE " + IS_FOLDER + " = " + 1;
+
+        // Return the results as a `Cursor`.  The second argument is `null` because there are no `selectionArgs`.
+        // We can't close the `Cursor` because we need to use it in the parent activity.
+        return bookmarksDatabase.rawQuery(GET_ALL_FOLDERS, null);
+    }
+
     public Cursor getAllBookmarksCursor() {
         // Get a readable database handle.
         SQLiteDatabase bookmarksDatabase = this.getReadableDatabase();
index b81e5d92f43650219b51a391de10dacabd45e52f..2fcf842e1c4f431bdd1ada8e2a88b52ad02e78a0 100644 (file)
     <string name="bookmark_url">URL für das Lesezeichen</string>
     <string name="folder_names_must_be_unique">Ordnernamen müssen einmalig sein</string>
     <string name="cannot_save_folder">Kann diesen Ordner nicht umbenennen, da der neue Name bereits existiert:</string>
-    <string name="cannot_move_bookmarks">Kann die markierten Lesezeichen nicht verschieben, da kein neuer Ordner ausgewählt wurde.</string>
     <string name="edit_bookmark">Lesezeichen Bearbeiten</string>
     <string name="edit_folder">Ordner Bearbeiten</string>
     <string name="move_to_folder">In Ordner verschieben</string>
index c832ded30ef1c3c8f098be1b0127f660b75f5791..894bd333cd781c8c2b5b06f6fe94d7bf39027e65 100644 (file)
     <string name="bookmark_url">Marcador URL</string>
     <string name="folder_names_must_be_unique">Los nombres de carpetas deben ser únicos</string>
     <string name="cannot_save_folder">No se guardó la carpeta porque el nuevo nombre no fue único:</string>
-    <string name="cannot_move_bookmarks">No se movió los marcadores selectionados porque ninguna carpeta nueva fue seleccionada.</string>
     <string name="edit_bookmark">Editar marcador</string>
     <string name="edit_folder">Editar carpeta</string>
     <string name="move_to_folder">Mover a carpeta</string>
index e0a6c198c8fa355fde21e8ae58312f3c18be28fa..7fdaa3e21669e34a6dd5abff92509d581160fd93 100644 (file)
     <string name="bookmark_url">URL Segnalibro</string>
     <string name="folder_names_must_be_unique">I nomi delle cartelle devono essere unici</string>
     <string name="cannot_save_folder">Non è possibile salvare la cartella perché già esistente:</string>
-    <string name="cannot_move_bookmarks">Non è possibile spostare il segnalibro, nessuna cartella selezionata.</string>
     <string name="edit_bookmark">Modifica Segnalibro</string>
     <string name="edit_folder">Modifica Cartella</string>
     <string name="move_to_folder">Sposta nella Cartella</string>
index 75511e64de6020d92d0e9a2d82659cb55f8ea9b1..863b96701af73632f2b02b3f96d52e850bc1df8e 100644 (file)
     <string name="bookmark_url">Bookmark URL</string>
     <string name="folder_names_must_be_unique">Folder names must be unique</string>
     <string name="cannot_save_folder">Cannot save the folder because the new name is not unique:</string>
-    <string name="cannot_move_bookmarks">Cannot move the selected bookmarks because no new folder was selected.</string>
     <string name="edit_bookmark">Edit Bookmark</string>
     <string name="edit_folder">Edit Folder</string>
     <string name="move_to_folder">Move to Folder</string>