]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/commitdiff
Disable the move bookmark to folder button until a folder is selected. https://redmi...
authorSoren Stoutner <soren@stoutner.com>
Fri, 22 Sep 2017 17:43:24 +0000 (10:43 -0700)
committerSoren Stoutner <soren@stoutner.com>
Fri, 22 Sep 2017 17:43:24 +0000 (10:43 -0700)
app/src/main/java/com/stoutner/privacybrowser/activities/BookmarksActivity.java
app/src/main/java/com/stoutner/privacybrowser/dialogs/MoveToFolderDialog.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 efdb06a72e03e4f2c2e69dc8639f7d0e3e2aa7f1..a178d49aa77016ace5c45b8b101e4f45d3301da2 100644 (file)
@@ -626,44 +626,35 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma
         EditText createFolderNameEditText = (EditText) dialogFragment.getDialog().findViewById(R.id.create_folder_name_edittext);
         String folderNameString = createFolderNameEditText.getText().toString();
 
-        // Check to see if the folder already exists.
-        Cursor bookmarkFolderCursor = bookmarksDatabaseHelper.getFolderCursor(folderNameString);
-        int existingFoldersWithNewName = bookmarkFolderCursor.getCount();
-        bookmarkFolderCursor.close();
-        if (folderNameString.isEmpty() || (existingFoldersWithNewName > 0)) {
-            String cannotCreateFolder = getResources().getString(R.string.cannot_create_folder) + " \"" + folderNameString + "\"";
-            Snackbar.make(findViewById(R.id.bookmarks_coordinatorlayout), cannotCreateFolder, Snackbar.LENGTH_INDEFINITE).show();
-        } else {  // Create the folder.
-            // Get the new folder icon `Bitmap`.
-            RadioButton defaultFolderIconRadioButton = (RadioButton) dialogFragment.getDialog().findViewById(R.id.create_folder_default_icon_radiobutton);
-            Bitmap folderIconBitmap;
-            if (defaultFolderIconRadioButton.isChecked()) {
-                // Get the default folder icon `ImageView` from the `Dialog` and convert it to a `Bitmap`.
-                ImageView folderIconImageView = (ImageView) dialogFragment.getDialog().findViewById(R.id.create_folder_default_icon);
-                Drawable folderIconDrawable = folderIconImageView.getDrawable();
-                BitmapDrawable folderIconBitmapDrawable = (BitmapDrawable) folderIconDrawable;
-                folderIconBitmap = folderIconBitmapDrawable.getBitmap();
-            } else {  // Assign `favoriteIcon` from the `WebView`.
-                folderIconBitmap = MainWebViewActivity.favoriteIconBitmap;
-            }
+        // Get the new folder icon `Bitmap`.
+        RadioButton defaultFolderIconRadioButton = (RadioButton) dialogFragment.getDialog().findViewById(R.id.create_folder_default_icon_radiobutton);
+        Bitmap folderIconBitmap;
+        if (defaultFolderIconRadioButton.isChecked()) {
+            // Get the default folder icon `ImageView` from the `Dialog` and convert it to a `Bitmap`.
+            ImageView folderIconImageView = (ImageView) dialogFragment.getDialog().findViewById(R.id.create_folder_default_icon);
+            Drawable folderIconDrawable = folderIconImageView.getDrawable();
+            BitmapDrawable folderIconBitmapDrawable = (BitmapDrawable) folderIconDrawable;
+            folderIconBitmap = folderIconBitmapDrawable.getBitmap();
+        } else {  // Assign `favoriteIcon` from the `WebView`.
+            folderIconBitmap = MainWebViewActivity.favoriteIconBitmap;
+        }
 
-            // Convert `folderIconBitmap` to a byte array.  `0` is for lossless compression (the only option for a PNG).
-            ByteArrayOutputStream folderIconByteArrayOutputStream = new ByteArrayOutputStream();
-            folderIconBitmap.compress(Bitmap.CompressFormat.PNG, 0, folderIconByteArrayOutputStream);
-            byte[] folderIconByteArray = folderIconByteArrayOutputStream.toByteArray();
+        // Convert `folderIconBitmap` to a byte array.  `0` is for lossless compression (the only option for a PNG).
+        ByteArrayOutputStream folderIconByteArrayOutputStream = new ByteArrayOutputStream();
+        folderIconBitmap.compress(Bitmap.CompressFormat.PNG, 0, folderIconByteArrayOutputStream);
+        byte[] folderIconByteArray = folderIconByteArrayOutputStream.toByteArray();
 
-            // Move all the bookmarks down one in the display order.
-            for (int i = 0; i < bookmarksListView.getCount(); i++) {
-                int databaseId = (int) bookmarksListView.getItemIdAtPosition(i);
-                bookmarksDatabaseHelper.updateBookmarkDisplayOrder(databaseId, i + 1);
-            }
+        // Move all the bookmarks down one in the display order.
+        for (int i = 0; i < bookmarksListView.getCount(); i++) {
+            int databaseId = (int) bookmarksListView.getItemIdAtPosition(i);
+            bookmarksDatabaseHelper.updateBookmarkDisplayOrder(databaseId, i + 1);
+        }
 
-            // Create the folder, placing it at the top of the ListView
-            bookmarksDatabaseHelper.createFolder(folderNameString, 0, currentFolder, folderIconByteArray);
+        // Create the folder, placing it at the top of the ListView
+        bookmarksDatabaseHelper.createFolder(folderNameString, 0, currentFolder, folderIconByteArray);
 
-            // Refresh the ListView.
-            updateBookmarksListView(currentFolder);
-        }
+        // Refresh the ListView.
+        updateBookmarksListView(currentFolder);
     }
 
     @Override
index 6eb09a31aa1134ff0c853331b5469f331e3bd70e..8ced87d3871c03771e0cccdcd6ddcd0dc68bd1e9 100644 (file)
@@ -35,10 +35,12 @@ import android.graphics.drawable.Drawable;
 import android.os.Bundle;
 import android.support.annotation.NonNull;
 import android.support.v4.content.ContextCompat;
-// We have to use `AppCompatDialogFragment` instead of `DialogFragment` or an error is produced on API <=22.
+// `AppCompatDialogFragment` must be used instead of `DialogFragment` or an error is produced on API <=22.
 import android.support.v7.app.AppCompatDialogFragment;
 import android.view.View;
 import android.view.ViewGroup;
+import android.widget.AdapterView;
+import android.widget.Button;
 import android.widget.CursorAdapter;
 import android.widget.ImageView;
 import android.widget.ListView;
@@ -115,9 +117,15 @@ public class MoveToFolderDialog extends AppCompatDialogFragment {
         // Create an `AlertDialog` from the `AlertDialog.Builder`.
         final AlertDialog alertDialog = dialogBuilder.create();
 
-        // We need to show the `AlertDialog` before we can modify items in the layout.
+        // Show the `AlertDialog` so the items in the layout can be modified.
         alertDialog.show();
 
+        // Get a handle for the positive button.
+        final Button moveButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
+
+        // Initially disable the positive button.
+        moveButton.setEnabled(false);
+
         // Initialize the `Cursor` and `CursorAdapter` variables.
         Cursor foldersCursor;
         CursorAdapter foldersCursorAdapter;
@@ -251,6 +259,15 @@ public class MoveToFolderDialog extends AppCompatDialogFragment {
         ListView foldersListView = (ListView) alertDialog.findViewById(R.id.move_to_folder_listview);
         foldersListView.setAdapter(foldersCursorAdapter);
 
+        // Enable the move button when a folder is selected.
+        foldersListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
+            @Override
+            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
+                // Enable the move button.
+                moveButton.setEnabled(true);
+            }
+        });
+
         // `onCreateDialog` requires the return of an `AlertDialog`.
         return alertDialog;
     }
index bb9bcfe6233cf14e6e193b9a81e0d8c0cc53a5b9..b81e5d92f43650219b51a391de10dacabd45e52f 100644 (file)
     <string name="folder_name">Name des Ordners</string>
     <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_create_folder">Kann diesen Ordner nicht erstellen, da der Name bereits existiert:</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>
index 3bd410c5fb2ac15c6aab61acec018316918679b1..c832ded30ef1c3c8f098be1b0127f660b75f5791 100644 (file)
     <string name="folder_name">Nombre de carpeta</string>
     <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_create_folder">No se creó la carpeta porque el nombre no fue único:</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>
index 5755086adeb1cb9184b94e7ca584fe23c8ca1ec6..e0a6c198c8fa355fde21e8ae58312f3c18be28fa 100644 (file)
     <string name="folder_name">Nome Cartella</string>
     <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_create_folder">Non è possibile creare la cartella perché già esistente:</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>
index 815abe877f07acd78e51a834a1d3f30a527b78cc..75511e64de6020d92d0e9a2d82659cb55f8ea9b1 100644 (file)
     <string name="folder_name">Folder name</string>
     <string name="bookmark_url">Bookmark URL</string>
     <string name="folder_names_must_be_unique">Folder names must be unique</string>
-    <string name="cannot_create_folder">Cannot create the folder because the name is not 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>