- // Check to see if the new folder name is unique.
- Cursor bookmarkFolderCursor = bookmarksDatabaseHelper.getFolderCursor(newFolderNameString);
- int existingFoldersWithNewName = bookmarkFolderCursor.getCount();
- bookmarkFolderCursor.close();
- if ( ((existingFoldersWithNewName == 0) || newFolderNameString.equals(oldFolderNameString)) && !newFolderNameString.isEmpty()) {
- // Get a long array with the the database ID of the selected folder and convert it to an `int`.
- long[] selectedFolderLongArray = bookmarksListView.getCheckedItemIds();
- int selectedFolderDatabaseId = (int) selectedFolderLongArray[0];
-
- // Get the `RadioButtons` from the `Dialog`.
- RadioButton currentFolderIconRadioButton = (RadioButton) dialogFragment.getDialog().findViewById(R.id.edit_folder_current_icon_radiobutton);
- RadioButton defaultFolderIconRadioButton = (RadioButton) dialogFragment.getDialog().findViewById(R.id.edit_folder_default_icon_radiobutton);
-
- // Check if the favorite icon has changed.
- if (currentFolderIconRadioButton.isChecked()) {
- // Update the folder name if it has changed without modifying the favorite icon.
- if (!newFolderNameString.equals(oldFolderNameString)) {
- bookmarksDatabaseHelper.updateFolder(selectedFolderDatabaseId, oldFolderNameString, newFolderNameString);
-
- // Refresh the `ListView`. `setSelection` scrolls to the position of the folder that was edited.
- updateBookmarksListView(currentFolder);
- bookmarksListView.setSelection(selectedBookmarkPosition);
- }
- } else { // Update the folder icon.
- // Get the new folder icon `Bitmap`.
- Bitmap folderIconBitmap;
- if (defaultFolderIconRadioButton.isChecked()) {
- // Get the default folder icon `ImageView` from the `Drawable` and convert it to a `Bitmap`.
- ImageView folderIconImageView = (ImageView) dialogFragment.getDialog().findViewById(R.id.edit_folder_default_icon);
- Drawable folderIconDrawable = folderIconImageView.getDrawable();
- BitmapDrawable folderIconBitmapDrawable = (BitmapDrawable) folderIconDrawable;
- folderIconBitmap = folderIconBitmapDrawable.getBitmap();
- } else { // Get the web page icon `ImageView` from the `Dialog`.
- folderIconBitmap = MainWebViewActivity.favoriteIconBitmap;
- }
+ // Check if the favorite icon has changed.
+ if (currentFolderIconRadioButton.isChecked()) { // Only the name has changed.
+ // Update the name in the database.
+ bookmarksDatabaseHelper.updateFolder(selectedFolderDatabaseId, oldFolderNameString, newFolderNameString);
+ } else if (!currentFolderIconRadioButton.isChecked() && newFolderNameString.equals(oldFolderNameString)) { // Only the icon has changed.
+ // Create the new folder icon Bitmap.
+ Bitmap folderIconBitmap;
+
+ // Populate the new folder icon bitmap.
+ if (defaultFolderIconRadioButton.isChecked()) {
+ // Get the default folder icon drawable.
+ Drawable folderIconDrawable = defaultFolderIconImageView.getDrawable();
+
+ // Convert the folder icon drawable to a bitmap drawable.
+ BitmapDrawable folderIconBitmapDrawable = (BitmapDrawable) folderIconDrawable;
+
+ // Convert the folder icon bitmap drawable to a bitmap.
+ folderIconBitmap = folderIconBitmapDrawable.getBitmap();
+ } else { // Use the WebView favorite icon.
+ // Copy the favorite icon bitmap to the folder icon bitmap.
+ folderIconBitmap = favoriteIconBitmap;
+ }
+
+ // Create a folder icon byte array output stream.
+ ByteArrayOutputStream newFolderIconByteArrayOutputStream = new ByteArrayOutputStream();
+
+ // Convert the folder icon bitmap to a byte array. `0` is for lossless compression (the only option for a PNG).
+ folderIconBitmap.compress(Bitmap.CompressFormat.PNG, 0, newFolderIconByteArrayOutputStream);