X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserAndroid.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Factivities%2FBookmarksDatabaseViewActivity.java;h=91afa6d64120a2d15d1bbba2b53083b4e7ae22bc;hp=d56c5a2a87303bddca432103530e98e26705902b;hb=1b27ac6f2b7c046945fc97e2aff9adbde8a152ce;hpb=3dff6df834d582f932795c72f6bdcf6f655ac593 diff --git a/app/src/main/java/com/stoutner/privacybrowser/activities/BookmarksDatabaseViewActivity.java b/app/src/main/java/com/stoutner/privacybrowser/activities/BookmarksDatabaseViewActivity.java index d56c5a2a..91afa6d6 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/BookmarksDatabaseViewActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/BookmarksDatabaseViewActivity.java @@ -1,20 +1,20 @@ /* - * Copyright © 2016-2020 Soren Stoutner . + * Copyright © 2016-2022 Soren Stoutner . * - * This file is part of Privacy Browser . + * This file is part of Privacy Browser Android . * - * Privacy Browser is free software: you can redistribute it and/or modify + * Privacy Browser Android is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * - * Privacy Browser is distributed in the hope that it will be useful, + * Privacy Browser Android is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with Privacy Browser. If not, see . + * along with Privacy Browser Android. If not, see . */ package com.stoutner.privacybrowser.activities; @@ -41,6 +41,7 @@ import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; +import android.view.Window; import android.view.WindowManager; import android.widget.AbsListView; import android.widget.AdapterView; @@ -97,8 +98,9 @@ public class BookmarksDatabaseViewActivity extends AppCompatActivity implements // Get a handle for the shared preferences. SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); - // Get the screenshot preference. - boolean allowScreenshots = sharedPreferences.getBoolean("allow_screenshots", false); + // Get the preferences. + boolean allowScreenshots = sharedPreferences.getBoolean(getString(R.string.allow_screenshots_key), false); + boolean bottomAppBar = sharedPreferences.getBoolean(getString(R.string.bottom_app_bar_key), false); // Disable screenshots if not allowed. if (!allowScreenshots) { @@ -123,8 +125,17 @@ public class BookmarksDatabaseViewActivity extends AppCompatActivity implements // Convert the favorite icon byte array to a bitmap and store it in a class variable. Bitmap favoriteIconBitmap = BitmapFactory.decodeByteArray(favoriteIconByteArray, 0, favoriteIconByteArray.length); - // Set the content view. - setContentView(R.layout.bookmarks_databaseview_coordinatorlayout); + // Set the view according to the theme. + if (bottomAppBar) { + // Set the content view. + setContentView(R.layout.bookmarks_databaseview_bottom_appbar); + } else { + // `Window.FEATURE_ACTION_MODE_OVERLAY` makes the contextual action mode cover the support action bar. It must be requested before the content is set. + supportRequestWindowFeature(Window.FEATURE_ACTION_MODE_OVERLAY); + + // Set the content view. + setContentView(R.layout.bookmarks_databaseview_top_appbar); + } // Get a handle for the toolbar. Toolbar toolbar = findViewById(R.id.bookmarks_databaseview_toolbar); @@ -192,7 +203,7 @@ public class BookmarksDatabaseViewActivity extends AppCompatActivity implements // Get the folder icon byte array from the cursor. - byte[] folderIconByteArray = cursor.getBlob(cursor.getColumnIndex(BookmarksDatabaseHelper.FAVORITE_ICON)); + byte[] folderIconByteArray = cursor.getBlob(cursor.getColumnIndexOrThrow(BookmarksDatabaseHelper.FAVORITE_ICON)); // Convert the byte array to a bitmap beginning at the first byte and ending at the last. Bitmap folderIconBitmap = BitmapFactory.decodeByteArray(folderIconByteArray, 0, folderIconByteArray.length); @@ -212,7 +223,7 @@ public class BookmarksDatabaseViewActivity extends AppCompatActivity implements } // Set the text view to display the folder name. - spinnerItemTextView.setText(cursor.getString(cursor.getColumnIndex(BookmarksDatabaseHelper.BOOKMARK_NAME))); + spinnerItemTextView.setText(cursor.getString(cursor.getColumnIndexOrThrow(BookmarksDatabaseHelper.BOOKMARK_NAME))); } }; @@ -282,15 +293,15 @@ public class BookmarksDatabaseViewActivity extends AppCompatActivity implements @Override public void bindView(View view, Context context, Cursor cursor) { - boolean isFolder = (cursor.getInt(cursor.getColumnIndex(BookmarksDatabaseHelper.IS_FOLDER)) == 1); + boolean isFolder = (cursor.getInt(cursor.getColumnIndexOrThrow(BookmarksDatabaseHelper.IS_FOLDER)) == 1); // Get the database ID from the `Cursor` and display it in `bookmarkDatabaseIdTextView`. - int bookmarkDatabaseId = cursor.getInt(cursor.getColumnIndex(BookmarksDatabaseHelper._ID)); + int bookmarkDatabaseId = cursor.getInt(cursor.getColumnIndexOrThrow(BookmarksDatabaseHelper._ID)); TextView bookmarkDatabaseIdTextView = view.findViewById(R.id.bookmarks_databaseview_database_id); bookmarkDatabaseIdTextView.setText(String.valueOf(bookmarkDatabaseId)); // Get the favorite icon byte array from the `Cursor`. - byte[] favoriteIconByteArray = cursor.getBlob(cursor.getColumnIndex(BookmarksDatabaseHelper.FAVORITE_ICON)); + byte[] favoriteIconByteArray = cursor.getBlob(cursor.getColumnIndexOrThrow(BookmarksDatabaseHelper.FAVORITE_ICON)); // Convert the byte array to a `Bitmap` beginning at the beginning at the first byte and ending at the last. Bitmap favoriteIconBitmap = BitmapFactory.decodeByteArray(favoriteIconByteArray, 0, favoriteIconByteArray.length); // Display the bitmap in `bookmarkFavoriteIcon`. @@ -298,7 +309,7 @@ public class BookmarksDatabaseViewActivity extends AppCompatActivity implements bookmarkFavoriteIcon.setImageBitmap(favoriteIconBitmap); // Get the bookmark name from the `Cursor` and display it in `bookmarkNameTextView`. - String bookmarkNameString = cursor.getString(cursor.getColumnIndex(BookmarksDatabaseHelper.BOOKMARK_NAME)); + String bookmarkNameString = cursor.getString(cursor.getColumnIndexOrThrow(BookmarksDatabaseHelper.BOOKMARK_NAME)); TextView bookmarkNameTextView = view.findViewById(R.id.bookmarks_databaseview_bookmark_name); bookmarkNameTextView.setText(bookmarkNameString); @@ -311,7 +322,7 @@ public class BookmarksDatabaseViewActivity extends AppCompatActivity implements } // Get the bookmark URL form the `Cursor` and display it in `bookmarkUrlTextView`. - String bookmarkUrlString = cursor.getString(cursor.getColumnIndex(BookmarksDatabaseHelper.BOOKMARK_URL)); + String bookmarkUrlString = cursor.getString(cursor.getColumnIndexOrThrow(BookmarksDatabaseHelper.BOOKMARK_URL)); TextView bookmarkUrlTextView = view.findViewById(R.id.bookmarks_databaseview_bookmark_url); bookmarkUrlTextView.setText(bookmarkUrlString); @@ -323,12 +334,12 @@ public class BookmarksDatabaseViewActivity extends AppCompatActivity implements } // Get the display order from the `Cursor` and display it in `bookmarkDisplayOrderTextView`. - int bookmarkDisplayOrder = cursor.getInt(cursor.getColumnIndex(BookmarksDatabaseHelper.DISPLAY_ORDER)); + int bookmarkDisplayOrder = cursor.getInt(cursor.getColumnIndexOrThrow(BookmarksDatabaseHelper.DISPLAY_ORDER)); TextView bookmarkDisplayOrderTextView = view.findViewById(R.id.bookmarks_databaseview_display_order); bookmarkDisplayOrderTextView.setText(String.valueOf(bookmarkDisplayOrder)); // Get the parent folder from the `Cursor` and display it in `bookmarkParentFolder`. - String bookmarkParentFolder = cursor.getString(cursor.getColumnIndex(BookmarksDatabaseHelper.PARENT_FOLDER)); + String bookmarkParentFolder = cursor.getString(cursor.getColumnIndexOrThrow(BookmarksDatabaseHelper.PARENT_FOLDER)); ImageView parentFolderImageView = view.findViewById(R.id.bookmarks_databaseview_parent_folder_icon); TextView bookmarkParentFolderTextView = view.findViewById(R.id.bookmarks_databaseview_parent_folder); @@ -366,7 +377,7 @@ public class BookmarksDatabaseViewActivity extends AppCompatActivity implements // Show the edit bookmark or edit bookmark folder dialog. if (bookmarksDatabaseHelper.isFolder(databaseId)) { // Save the current folder name, which is used in `onSaveBookmarkFolder()`. - oldFolderNameString = bookmarksCursor.getString(bookmarksCursor.getColumnIndex(BookmarksDatabaseHelper.BOOKMARK_NAME)); + oldFolderNameString = bookmarksCursor.getString(bookmarksCursor.getColumnIndexOrThrow(BookmarksDatabaseHelper.BOOKMARK_NAME)); // Show the edit bookmark folder dialog. DialogFragment editBookmarkFolderDatabaseViewDialog = EditBookmarkFolderDatabaseViewDialog.folderDatabaseId(databaseId, favoriteIconBitmap); @@ -431,14 +442,8 @@ public class BookmarksDatabaseViewActivity extends AppCompatActivity implements // Update the action mode subtitle according to the number of selected bookmarks. mode.setSubtitle(getString(R.string.selected) + " " + numberOfSelectedBookmarks); - // Update the visibility of the the select all menu. - if (bookmarksListView.getCheckedItemCount() == bookmarksListView.getCount()) { // All of the bookmarks are checked. - // Hide the select all menu item. - selectAllMenuItem.setVisible(false); - } else { // Not all of the bookmarks are checked. - // Show the select all menu item. - selectAllMenuItem.setVisible(true); - } + // Only show the select all menu item if all of the bookmarks are not already selected. + selectAllMenuItem.setVisible(bookmarksListView.getCheckedItemCount() != bookmarksListView.getCount()); // Convert the database ID to an int. int databaseId = (int) id; @@ -467,7 +472,7 @@ public class BookmarksDatabaseViewActivity extends AppCompatActivity implements // Get the position of the folder in the bookmarks cursor. while ((folderPosition < 0) && (bookmarksCursor.getPosition() < bookmarksCursor.getCount())) { // Check if the folder database ID matches the bookmark database ID. - if (folderDatabaseId == bookmarksCursor.getInt((bookmarksCursor.getColumnIndex(BookmarksDatabaseHelper._ID)))) { + if (folderDatabaseId == bookmarksCursor.getInt(bookmarksCursor.getColumnIndexOrThrow(BookmarksDatabaseHelper._ID))) { // Get the folder position. folderPosition = bookmarksCursor.getPosition(); @@ -490,106 +495,106 @@ public class BookmarksDatabaseViewActivity extends AppCompatActivity implements } @Override - public boolean onActionItemClicked(ActionMode mode, MenuItem item) { - switch (item.getItemId()) { - case R.id.select_all: - // Get the total number of bookmarks. - int numberOfBookmarks = bookmarksListView.getCount(); - - // Select them all. - for (int i = 0; i < numberOfBookmarks; i++) { - bookmarksListView.setItemChecked(i, true); - } - break; - - case R.id.delete: - // Set the deleting bookmarks flag, which prevents the delete menu item from being enabled until the current process finishes. - deletingBookmarks = true; - - // Get an array of the selected row IDs. - long[] selectedBookmarksIdsLongArray = bookmarksListView.getCheckedItemIds(); - - // Get an array of checked bookmarks. `.clone()` makes a copy that won't change if the list view is reloaded, which is needed for re-selecting the bookmarks on undelete. - SparseBooleanArray selectedBookmarksPositionsSparseBooleanArray = bookmarksListView.getCheckedItemPositions().clone(); - - // Update the bookmarks cursor with the current contents of the bookmarks database except for the specified database IDs. - switch (currentFolderDatabaseId) { - // Get a cursor with all the folders. - case ALL_FOLDERS_DATABASE_ID: - if (sortByDisplayOrder) { - bookmarksCursor = bookmarksDatabaseHelper.getAllBookmarksByDisplayOrderExcept(selectedBookmarksIdsLongArray); - } else { - bookmarksCursor = bookmarksDatabaseHelper.getAllBookmarksExcept(selectedBookmarksIdsLongArray); - } - break; - - // Get a cursor for the home folder. - case HOME_FOLDER_DATABASE_ID: - if (sortByDisplayOrder) { - bookmarksCursor = bookmarksDatabaseHelper.getBookmarksByDisplayOrderExcept(selectedBookmarksIdsLongArray, ""); - } else { - bookmarksCursor = bookmarksDatabaseHelper.getBookmarksExcept(selectedBookmarksIdsLongArray, ""); - } - break; - - // Display the selected folder. - default: - // Get a cursor for the selected folder. - if (sortByDisplayOrder) { - bookmarksCursor = bookmarksDatabaseHelper.getBookmarksByDisplayOrderExcept(selectedBookmarksIdsLongArray, currentFolderName); - } else { - bookmarksCursor = bookmarksDatabaseHelper.getBookmarksExcept(selectedBookmarksIdsLongArray, currentFolderName); - } - } + public boolean onActionItemClicked(ActionMode mode, MenuItem menuItem) { + // Get a the menu item ID. + int menuItemId = menuItem.getItemId(); + + // Run the command that corresponds to the selected menu item. + if (menuItemId == R.id.select_all) { // Select all the bookmarks. + // Get the total number of bookmarks. + int numberOfBookmarks = bookmarksListView.getCount(); + + // Select them all. + for (int i = 0; i < numberOfBookmarks; i++) { + bookmarksListView.setItemChecked(i, true); + } + } else if (menuItemId == R.id.delete) { // Delete the selected bookmarks. + // Set the deleting bookmarks flag, which prevents the delete menu item from being enabled until the current process finishes. + deletingBookmarks = true; + + // Get an array of the selected row IDs. + long[] selectedBookmarksIdsLongArray = bookmarksListView.getCheckedItemIds(); + + // Get an array of checked bookmarks. `.clone()` makes a copy that won't change if the list view is reloaded, which is needed for re-selecting the bookmarks on undelete. + SparseBooleanArray selectedBookmarksPositionsSparseBooleanArray = bookmarksListView.getCheckedItemPositions().clone(); + + // Update the bookmarks cursor with the current contents of the bookmarks database except for the specified database IDs. + switch (currentFolderDatabaseId) { + // Get a cursor with all the folders. + case ALL_FOLDERS_DATABASE_ID: + if (sortByDisplayOrder) { + bookmarksCursor = bookmarksDatabaseHelper.getAllBookmarksByDisplayOrderExcept(selectedBookmarksIdsLongArray); + } else { + bookmarksCursor = bookmarksDatabaseHelper.getAllBookmarksExcept(selectedBookmarksIdsLongArray); + } + break; + + // Get a cursor for the home folder. + case HOME_FOLDER_DATABASE_ID: + if (sortByDisplayOrder) { + bookmarksCursor = bookmarksDatabaseHelper.getBookmarksByDisplayOrderExcept(selectedBookmarksIdsLongArray, ""); + } else { + bookmarksCursor = bookmarksDatabaseHelper.getBookmarksExcept(selectedBookmarksIdsLongArray, ""); + } + break; + + // Display the selected folder. + default: + // Get a cursor for the selected folder. + if (sortByDisplayOrder) { + bookmarksCursor = bookmarksDatabaseHelper.getBookmarksByDisplayOrderExcept(selectedBookmarksIdsLongArray, currentFolderName); + } else { + bookmarksCursor = bookmarksDatabaseHelper.getBookmarksExcept(selectedBookmarksIdsLongArray, currentFolderName); + } + } - // Update the list view. - bookmarksCursorAdapter.changeCursor(bookmarksCursor); - - // Create a Snackbar with the number of deleted bookmarks. - bookmarksDeletedSnackbar = Snackbar.make(findViewById(R.id.bookmarks_databaseview_coordinatorlayout), - getString(R.string.bookmarks_deleted) + " " + selectedBookmarksIdsLongArray.length, Snackbar.LENGTH_LONG) - .setAction(R.string.undo, view -> { - // Do nothing because everything will be handled by `onDismissed()` below. - }) - .addCallback(new Snackbar.Callback() { - @SuppressLint("SwitchIntDef") // Ignore the lint warning about not handling the other possible events as they are covered by `default:`. - @Override - public void onDismissed(Snackbar snackbar, int event) { - if (event == Snackbar.Callback.DISMISS_EVENT_ACTION) { // The user pushed the undo button. - // Update the bookmarks list view with the current contents of the bookmarks database, including the "deleted bookmarks. - updateBookmarksListView(); - - // Re-select the previously selected bookmarks. - for (int i = 0; i < selectedBookmarksPositionsSparseBooleanArray.size(); i++) { - bookmarksListView.setItemChecked(selectedBookmarksPositionsSparseBooleanArray.keyAt(i), true); - } - } else { // The Snackbar was dismissed without the undo button being pushed. - // Delete each selected bookmark. - for (long databaseIdLong : selectedBookmarksIdsLongArray) { - // Convert `databaseIdLong` to an int. - int databaseIdInt = (int) databaseIdLong; - - // Delete the selected bookmark. - bookmarksDatabaseHelper.deleteBookmark(databaseIdInt); - } + // Update the list view. + bookmarksCursorAdapter.changeCursor(bookmarksCursor); + + // Create a Snackbar with the number of deleted bookmarks. + bookmarksDeletedSnackbar = Snackbar.make(findViewById(R.id.bookmarks_databaseview_coordinatorlayout), + getString(R.string.bookmarks_deleted) + " " + selectedBookmarksIdsLongArray.length, Snackbar.LENGTH_LONG) + .setAction(R.string.undo, view -> { + // Do nothing because everything will be handled by `onDismissed()` below. + }) + .addCallback(new Snackbar.Callback() { + @SuppressLint("SwitchIntDef") // Ignore the lint warning about not handling the other possible events as they are covered by `default:`. + @Override + public void onDismissed(Snackbar snackbar, int event) { + if (event == Snackbar.Callback.DISMISS_EVENT_ACTION) { // The user pushed the undo button. + // Update the bookmarks list view with the current contents of the bookmarks database, including the "deleted bookmarks. + updateBookmarksListView(); + + // Re-select the previously selected bookmarks. + for (int i = 0; i < selectedBookmarksPositionsSparseBooleanArray.size(); i++) { + bookmarksListView.setItemChecked(selectedBookmarksPositionsSparseBooleanArray.keyAt(i), true); } + } else { // The Snackbar was dismissed without the undo button being pushed. + // Delete each selected bookmark. + for (long databaseIdLong : selectedBookmarksIdsLongArray) { + // Convert `databaseIdLong` to an int. + int databaseIdInt = (int) databaseIdLong; + + // Delete the selected bookmark. + bookmarksDatabaseHelper.deleteBookmark(databaseIdInt); + } + } - // Reset the deleting bookmarks flag. - deletingBookmarks = false; + // Reset the deleting bookmarks flag. + deletingBookmarks = false; - // Enable the delete menu item. - deleteMenuItem.setEnabled(true); + // Enable the delete menu item. + deleteMenuItem.setEnabled(true); - // Close the activity if back has been pressed. - if (closeActivityAfterDismissingSnackbar) { - onBackPressed(); - } + // Close the activity if back has been pressed. + if (closeActivityAfterDismissingSnackbar) { + onBackPressed(); } - }); + } + }); - // Show the Snackbar. - bookmarksDeletedSnackbar.show(); - break; + // Show the Snackbar. + bookmarksDeletedSnackbar.show(); } // Consume the click. @@ -608,19 +613,12 @@ public class BookmarksDatabaseViewActivity extends AppCompatActivity implements // Inflate the menu. getMenuInflater().inflate(R.menu.bookmarks_databaseview_options_menu, menu); - // Get the current theme status. - int currentThemeStatus = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK; - // Get a handle for the sort menu item. MenuItem sortMenuItem = menu.findItem(R.id.sort); // Change the sort menu item icon if the listview is sorted by display order, which restores the state after a restart. if (sortByDisplayOrder) { - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { - sortMenuItem.setIcon(R.drawable.sort_selected_day); - } else { - sortMenuItem.setIcon(R.drawable.sort_selected_night); - } + sortMenuItem.setIcon(R.drawable.sort_selected); } // Success. @@ -629,53 +627,40 @@ public class BookmarksDatabaseViewActivity extends AppCompatActivity implements @Override public boolean onOptionsItemSelected(MenuItem menuItem) { - // Get the ID of the menu item that was selected. + // Get the menu item ID. int menuItemId = menuItem.getItemId(); // Run the command that corresponds to the selected menu item. - switch (menuItemId) { - case android.R.id.home: // The home arrow is identified as `android.R.id.home`, not just `R.id.home`. - // Exit the activity. - onBackPressed(); - break; - - case R.id.sort: - // Update the sort by display order tracker. - sortByDisplayOrder = !sortByDisplayOrder; - - // Get a handle for the bookmarks list view. - ListView bookmarksListView = findViewById(R.id.bookmarks_databaseview_listview); - - // Get the current theme status. - int currentThemeStatus = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK; - - // Update the icon and display a snackbar. - if (sortByDisplayOrder) { // Sort by display order. - // Update the icon according to the theme. - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { - menuItem.setIcon(R.drawable.sort_selected_day); - } else { - menuItem.setIcon(R.drawable.sort_selected_night); - } - - // Display a Snackbar indicating the current sort type. - Snackbar.make(bookmarksListView, R.string.sorted_by_display_order, Snackbar.LENGTH_SHORT).show(); - } else { // Sort by database id. - // Update the icon according to the theme. - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { - menuItem.setIcon(R.drawable.sort_day); - } else { - menuItem.setIcon(R.drawable.sort_night); - } - - // Display a Snackbar indicating the current sort type. - Snackbar.make(bookmarksListView, R.string.sorted_by_database_id, Snackbar.LENGTH_SHORT).show(); - } + if (menuItemId == android.R.id.home) { // Go Home. The home arrow is identified as `android.R.id.home`, not just `R.id.home`. + // Exit the activity. + onBackPressed(); + } else if (menuItemId == R.id.sort) { // Toggle the sort mode. + // Update the sort by display order tracker. + sortByDisplayOrder = !sortByDisplayOrder; + + // Get a handle for the bookmarks list view. + ListView bookmarksListView = findViewById(R.id.bookmarks_databaseview_listview); + + // Update the icon and display a snackbar. + if (sortByDisplayOrder) { // Sort by display order. + // Update the icon. + menuItem.setIcon(R.drawable.sort_selected); + + // Display a Snackbar indicating the current sort type. + Snackbar.make(bookmarksListView, R.string.sorted_by_display_order, Snackbar.LENGTH_SHORT).show(); + } else { // Sort by database id. + // Update the icon. + menuItem.setIcon(R.drawable.sort); + + // Display a Snackbar indicating the current sort type. + Snackbar.make(bookmarksListView, R.string.sorted_by_database_id, Snackbar.LENGTH_SHORT).show(); + } - // Update the list view. - updateBookmarksListView(); - break; + // Update the list view. + updateBookmarksListView(); } + + // Consume the event. return true; } @@ -769,7 +754,7 @@ public class BookmarksDatabaseViewActivity extends AppCompatActivity implements while (folderCursor.getPosition() < folderCursor.getCount()) { // Get the bookmark database ID. - int bookmarkId = folderCursor.getInt(folderCursor.getColumnIndex(BookmarksDatabaseHelper._ID)); + int bookmarkId = folderCursor.getInt(folderCursor.getColumnIndexOrThrow(BookmarksDatabaseHelper._ID)); // Move the bookmarks cursor to the first position. bookmarksCursor.moveToFirst(); @@ -780,7 +765,7 @@ public class BookmarksDatabaseViewActivity extends AppCompatActivity implements // Get the position of this bookmark in the bookmarks cursor. while ((bookmarkPosition < 0) && (bookmarksCursor.getPosition() < bookmarksCursor.getCount())) { // Check if the bookmark IDs match. - if (bookmarkId == bookmarksCursor.getInt(bookmarksCursor.getColumnIndex(BookmarksDatabaseHelper._ID))) { + if (bookmarkId == bookmarksCursor.getInt(bookmarksCursor.getColumnIndexOrThrow(BookmarksDatabaseHelper._ID))) { // Get the bookmark position. bookmarkPosition = bookmarksCursor.getPosition(); @@ -811,15 +796,15 @@ public class BookmarksDatabaseViewActivity extends AppCompatActivity implements assert dialog != null; // Get handles for the views from dialog fragment. - RadioButton currentBookmarkIconRadioButton = dialog.findViewById(R.id.edit_bookmark_current_icon_radiobutton); - EditText editBookmarkNameEditText = dialog.findViewById(R.id.edit_bookmark_name_edittext); - EditText editBookmarkUrlEditText = dialog.findViewById(R.id.edit_bookmark_url_edittext); - Spinner folderSpinner = dialog.findViewById(R.id.edit_bookmark_folder_spinner); - EditText displayOrderEditText = dialog.findViewById(R.id.edit_bookmark_display_order_edittext); + RadioButton currentIconRadioButton = dialog.findViewById(R.id.current_icon_radiobutton); + EditText bookmarkNameEditText = dialog.findViewById(R.id.bookmark_name_edittext); + EditText bookmarkUrlEditText = dialog.findViewById(R.id.bookmark_url_edittext); + Spinner folderSpinner = dialog.findViewById(R.id.bookmark_folder_spinner); + EditText displayOrderEditText = dialog.findViewById(R.id.bookmark_display_order_edittext); // Extract the bookmark information. - String bookmarkNameString = editBookmarkNameEditText.getText().toString(); - String bookmarkUrlString = editBookmarkUrlEditText.getText().toString(); + String bookmarkNameString = bookmarkNameEditText.getText().toString(); + String bookmarkUrlString = bookmarkUrlEditText.getText().toString(); int folderDatabaseId = (int) folderSpinner.getSelectedItemId(); int displayOrderInt = Integer.parseInt(displayOrderEditText.getText().toString()); @@ -834,7 +819,7 @@ public class BookmarksDatabaseViewActivity extends AppCompatActivity implements } // Update the bookmark. - if (currentBookmarkIconRadioButton.isChecked()) { // Update the bookmark without changing the favorite icon. + if (currentIconRadioButton.isChecked()) { // Update the bookmark without changing the favorite icon. bookmarksDatabaseHelper.updateBookmark(selectedBookmarkDatabaseId, bookmarkNameString, bookmarkUrlString, parentFolderNameString, displayOrderInt); } else { // Update the bookmark using the `WebView` favorite icon. // Create a favorite icon byte array output stream. @@ -863,15 +848,15 @@ public class BookmarksDatabaseViewActivity extends AppCompatActivity implements assert dialog != null; // Get handles for the views from dialog fragment. - RadioButton currentBookmarkIconRadioButton = dialog.findViewById(R.id.edit_folder_current_icon_radiobutton); - RadioButton defaultFolderIconRadioButton = dialog.findViewById(R.id.edit_folder_default_icon_radiobutton); - ImageView defaultFolderIconImageView = dialog.findViewById(R.id.edit_folder_default_icon_imageview); - EditText editBookmarkNameEditText = dialog.findViewById(R.id.edit_folder_name_edittext); - Spinner parentFolderSpinner = dialog.findViewById(R.id.edit_folder_parent_folder_spinner); - EditText displayOrderEditText = dialog.findViewById(R.id.edit_folder_display_order_edittext); + RadioButton currentIconRadioButton = dialog.findViewById(R.id.current_icon_radiobutton); + RadioButton defaultIconRadioButton = dialog.findViewById(R.id.default_icon_radiobutton); + ImageView defaultIconImageView = dialog.findViewById(R.id.default_icon_imageview); + EditText folderNameEditText = dialog.findViewById(R.id.folder_name_edittext); + Spinner parentFolderSpinner = dialog.findViewById(R.id.parent_folder_spinner); + EditText displayOrderEditText = dialog.findViewById(R.id.display_order_edittext); // Extract the folder information. - String newFolderNameString = editBookmarkNameEditText.getText().toString(); + String newFolderNameString = folderNameEditText.getText().toString(); int parentFolderDatabaseId = (int) parentFolderSpinner.getSelectedItemId(); int displayOrderInt = Integer.parseInt(displayOrderEditText.getText().toString()); @@ -886,16 +871,16 @@ public class BookmarksDatabaseViewActivity extends AppCompatActivity implements } // Update the folder. - if (currentBookmarkIconRadioButton.isChecked()) { // Update the folder without changing the favorite icon. + if (currentIconRadioButton.isChecked()) { // Update the folder without changing the favorite icon. bookmarksDatabaseHelper.updateFolder(selectedBookmarkDatabaseId, oldFolderNameString, newFolderNameString, parentFolderNameString, displayOrderInt); } else { // Update the folder and the icon. // Create the new folder icon Bitmap. Bitmap folderIconBitmap; // Populate the new folder icon bitmap. - if (defaultFolderIconRadioButton.isChecked()) { + if (defaultIconRadioButton.isChecked()) { // Get the default folder icon drawable. - Drawable folderIconDrawable = defaultFolderIconImageView.getDrawable(); + Drawable folderIconDrawable = defaultIconImageView.getDrawable(); // Convert the folder icon drawable to a bitmap drawable. BitmapDrawable folderIconBitmapDrawable = (BitmapDrawable) folderIconDrawable;