/*
- * Copyright © 2016-2019 Soren Stoutner <soren@stoutner.com>.
+ * Copyright © 2016-2020 Soren Stoutner <soren@stoutner.com>.
*
* This file is part of Privacy Browser <https://www.stoutner.com/privacy-browser>.
*
package com.stoutner.privacybrowser.activities;
import android.annotation.SuppressLint;
+import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
+import android.content.res.Configuration;
import android.database.Cursor;
import android.database.MatrixCursor;
import android.database.MergeCursor;
import android.widget.Spinner;
import android.widget.TextView;
+import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar; // The AndroidX toolbar must be used until the minimum API is >= 21.
public class BookmarksDatabaseViewActivity extends AppCompatActivity implements EditBookmarkDatabaseViewDialog.EditBookmarkDatabaseViewListener,
EditBookmarkFolderDatabaseViewDialog.EditBookmarkFolderDatabaseViewListener {
- // Instantiate the constants.
+ // Define the class constants.
private static final int ALL_FOLDERS_DATABASE_ID = -2;
- private static final int HOME_FOLDER_DATABASE_ID = -1;
+ public static final int HOME_FOLDER_DATABASE_ID = -1;
- // `bookmarksDatabaseHelper` is used in `onCreate()`, `updateBookmarksListView()`, `selectAllBookmarksInFolder()`, and `onDestroy()`.
- private BookmarksDatabaseHelper bookmarksDatabaseHelper;
-
- // `bookmarksCursor` is used in `onCreate()`, `updateBookmarksListView()`, `onSaveBookmark()`, `onSaveBookmarkFolder()`, and `onDestroy()`.
- private Cursor bookmarksCursor;
-
- // `bookmarksCursorAdapter` is used in `onCreate()`, `selectAllBookmarksInFolder()`, and `updateBookmarksListView()`.
- private CursorAdapter bookmarksCursorAdapter;
+ // Define the saved instance state constants.
+ private final String CURRENT_FOLDER_DATABASE_ID = "current_folder_database_id";
+ private final String CURRENT_FOLDER_NAME = "current_folder_name";
+ private final String SORT_BY_DISPLAY_ORDER = "sort_by_display_order";
- // `oldFolderNameString` is used in `onCreate()` and `onSaveBookmarkFolder()`.
- private String oldFolderNameString;
-
- // `currentFolderDatabaseId` is used in `onCreate()`, `updateBookmarksListView()`, `onSaveBookmark()`, and `onSaveBookmarkFolder()`.
+ // Define the class variables.
private int currentFolderDatabaseId;
-
- // `currentFolder` is used in `onCreate()`, `onSaveBookmark()`, and `onSaveBookmarkFolder()`.
private String currentFolderName;
-
- // `sortByDisplayOrder` is used in `onCreate()`, `onOptionsItemSelected()`, and `updateBookmarksListView()`.
private boolean sortByDisplayOrder;
-
- // `bookmarksDeletedSnackbar` is used in `onCreate()`, `onOptionsItemSelected()`, and `onBackPressed()`.
+ private BookmarksDatabaseHelper bookmarksDatabaseHelper;
+ private Cursor bookmarksCursor;
+ private CursorAdapter bookmarksCursorAdapter;
+ private String oldFolderNameString;
private Snackbar bookmarksDeletedSnackbar;
-
- // `closeActivityAfterDismissingSnackbar` is used in `onCreate()`, `onOptionsItemSelected()`, and `onBackPressed()`.
private boolean closeActivityAfterDismissingSnackbar;
@Override
// Get a handle for the shared preferences.
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
- // Get the theme and screenshot preferences.
- boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false);
+ // Get the screenshot preference.
boolean allowScreenshots = sharedPreferences.getBoolean("allow_screenshots", false);
// Disable screenshots if not allowed.
}
// Set the activity theme.
- if (darkTheme) {
- setTheme(R.style.PrivacyBrowserDark_SecondaryActivity);
- } else {
- setTheme(R.style.PrivacyBrowserLight_SecondaryActivity);
- }
+ setTheme(R.style.PrivacyBrowser);
// Run the default commands.
super.onCreate(savedInstanceState);
// Set the content view.
setContentView(R.layout.bookmarks_databaseview_coordinatorlayout);
- // The AndroidX toolbar must be used until the minimum API is >= 21.
+ // Get a handle for the toolbar.
Toolbar toolbar = findViewById(R.id.bookmarks_databaseview_toolbar);
+
+ // Set the support action bar.
setSupportActionBar(toolbar);
// Get a handle for the action bar.
// Get a cursor with the list of all the folders.
Cursor foldersCursor = bookmarksDatabaseHelper.getAllFolders();
- // Combine `matrixCursor` and `foldersCursor`.
+ // Combine the matrix cursor and the folders cursor.
MergeCursor foldersMergeCursor = new MergeCursor(new Cursor[]{matrixCursor, foldersCursor});
// Get the default folder bitmap. `ContextCompat` must be used until the minimum API >= 21.
Drawable defaultFolderDrawable = ContextCompat.getDrawable(getApplicationContext(), R.drawable.folder_blue_bitmap);
- // Cast the default folder drawable to a `BitmapDrawable`.
+ // Cast the default folder drawable to a bitmap drawable.
BitmapDrawable defaultFolderBitmapDrawable = (BitmapDrawable) defaultFolderDrawable;
// Remove the incorrect lint warning that `.getBitmap()` might be null.
assert defaultFolderBitmapDrawable != null;
- // Convert the default folder `BitmapDrawable` to a bitmap.
+ // Convert the default folder bitmap drawable to a bitmap.
Bitmap defaultFolderBitmap = defaultFolderBitmapDrawable.getBitmap();
Spinner folderSpinner = findViewById(R.id.spinner);
folderSpinner.setAdapter(foldersCursorAdapter);
- // Handle taps on the spinner dropdown.
- folderSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
- @Override
- public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
- // Store the current folder database ID.
- currentFolderDatabaseId = (int) id;
+ // Wait to set the on item selected listener until the spinner has been inflated. Otherwise the activity will crash on restart.
+ folderSpinner.post(() -> {
+ // Handle taps on the spinner dropdown.
+ folderSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
+ @Override
+ public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
+ // Store the current folder database ID.
+ currentFolderDatabaseId = (int) id;
- // Get a handle for the selected view.
- TextView selectedFolderTextView = findViewById(R.id.spinner_item_textview);
+ // Get a handle for the selected view.
+ TextView selectedFolderTextView = findViewById(R.id.spinner_item_textview);
- // Store the current folder name.
- currentFolderName = selectedFolderTextView.getText().toString();
+ // Store the current folder name.
+ currentFolderName = selectedFolderTextView.getText().toString();
- // Update the list view.
- updateBookmarksListView();
- }
+ // Update the list view.
+ updateBookmarksListView();
+ }
- @Override
- public void onNothingSelected(AdapterView<?> parent) {
- // Do nothing.
- }
+ @Override
+ public void onNothingSelected(AdapterView<?> parent) {
+ // Do nothing.
+ }
+ });
});
- // Get a handle for the bookmarks `ListView`.
+
+ // Get a handle for the bookmarks listview.
ListView bookmarksListView = findViewById(R.id.bookmarks_databaseview_listview);
- // Get a `Cursor` with the current contents of the bookmarks database.
- bookmarksCursor = bookmarksDatabaseHelper.getAllBookmarks();
+ // Check to see if the activity was restarted.
+ if (savedInstanceState == null) { // The activity was not restarted.
+ // Set the default current folder database ID.
+ currentFolderDatabaseId = ALL_FOLDERS_DATABASE_ID;
+ } else { // The activity was restarted.
+ // Restore the class variables from the saved instance state.
+ currentFolderDatabaseId = savedInstanceState.getInt(CURRENT_FOLDER_DATABASE_ID);
+ currentFolderName = savedInstanceState.getString(CURRENT_FOLDER_NAME);
+ sortByDisplayOrder = savedInstanceState.getBoolean(SORT_BY_DISPLAY_ORDER);
+
+ // Update the spinner if the home folder is selected. Android handles this by default for the main cursor but not the matrix cursor.
+ if (currentFolderDatabaseId == HOME_FOLDER_DATABASE_ID) {
+ folderSpinner.setSelection(1);
+ }
+ }
+
+ // Update the bookmarks listview.
+ updateBookmarksListView();
// Setup a `CursorAdapter` with `this` context. `false` disables autoRequery.
bookmarksCursorAdapter = new CursorAdapter(this, bookmarksCursor, false) {
parentFolderImageView.setImageDrawable(ContextCompat.getDrawable(getApplicationContext(), R.drawable.folder_dark_blue));
bookmarkParentFolderTextView.setText(bookmarkParentFolder);
+ // Get the current theme status.
+ int currentThemeStatus = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
+
// Set the text color according to the theme.
- if (darkTheme) {
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+ // This color is a little darker than the default night mode text. But the effect is rather nice.
bookmarkParentFolderTextView.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.gray_300));
} else {
bookmarkParentFolderTextView.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.black));
// Update the ListView.
bookmarksListView.setAdapter(bookmarksCursorAdapter);
- // Set the current folder database ID.
- currentFolderDatabaseId = ALL_FOLDERS_DATABASE_ID;
-
// Set a listener to edit a bookmark when it is tapped.
bookmarksListView.setOnItemClickListener((AdapterView<?> parent, View view, int position, long id) -> {
// Convert the database ID to an int.
// Disable the delete menu item if a delete is pending.
deleteMenuItem.setEnabled(!deletingBookmarks);
+ // Get the number of currently selected bookmarks.
+ int numberOfSelectedBookmarks = bookmarksListView.getCheckedItemCount();
+
+ // Set the action mode subtitle according to the number of selected bookmarks. This must be set here or it will be missing if the activity is restarted.
+ mode.setSubtitle(getString(R.string.selected) + " " + numberOfSelectedBookmarks);
+
+ // Do not show the select all menu item if all the bookmarks are already checked.
+ if (bookmarksListView.getCheckedItemCount() == bookmarksListView.getCount()) {
+ selectAllMenuItem.setVisible(false);
+ }
+
// Make it so.
return true;
}
// Calculate the number of selected bookmarks.
int numberOfSelectedBookmarks = bookmarksListView.getCheckedItemCount();
- // Adjust the ActionMode according to the number of selected bookmarks.
- mode.setSubtitle(getString(R.string.selected) + " " + numberOfSelectedBookmarks);
-
- // Do not show the select all menu item if all the bookmarks are already checked.
- if (bookmarksListView.getCheckedItemCount() == bookmarksListView.getCount()) {
- selectAllMenuItem.setVisible(false);
- } else {
- selectAllMenuItem.setVisible(true);
- }
+ // Only run the commands if at least one bookmark is selected. Otherwise, a context menu with 0 selected bookmarks is briefly displayed.
+ if (numberOfSelectedBookmarks > 0) {
+ // 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);
+ }
- // Convert the database ID to an int.
- int databaseId = (int) id;
+ // Convert the database ID to an int.
+ int databaseId = (int) id;
- // If a folder was selected, also select all the contents.
- if (checked && bookmarksDatabaseHelper.isFolder(databaseId)) {
- selectAllBookmarksInFolder(databaseId);
- }
+ // If a folder was selected, also select all the contents.
+ if (checked && bookmarksDatabaseHelper.isFolder(databaseId)) {
+ selectAllBookmarksInFolder(databaseId);
+ }
- // Do not allow a bookmark to be deselected if the folder is selected.
- if (!checked) {
- // Get the folder name.
- String folderName = bookmarksDatabaseHelper.getParentFolderName((int) id);
+ // Do not allow a bookmark to be deselected if the folder is selected.
+ if (!checked) {
+ // Get the folder name.
+ String folderName = bookmarksDatabaseHelper.getParentFolderName((int) id);
- // If the bookmark is not in the root folder, check to see if the folder is selected.
- if (!folderName.isEmpty()) {
- // Get the database ID of the folder.
- int folderDatabaseId = bookmarksDatabaseHelper.getFolderDatabaseId(folderName);
+ // If the bookmark is not in the root folder, check to see if the folder is selected.
+ if (!folderName.isEmpty()) {
+ // Get the database ID of the folder.
+ int folderDatabaseId = bookmarksDatabaseHelper.getFolderDatabaseId(folderName);
- // Move the bookmarks cursor to the first position.
- bookmarksCursor.moveToFirst();
+ // Move the bookmarks cursor to the first position.
+ bookmarksCursor.moveToFirst();
- // Initialize the folder position variable.
- int folderPosition = -1;
+ // Initialize the folder position variable.
+ int folderPosition = -1;
- // 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)))) {
- // Get the folder position.
- folderPosition = bookmarksCursor.getPosition();
+ // 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)))) {
+ // Get the folder position.
+ folderPosition = bookmarksCursor.getPosition();
- // Check if the folder is selected.
- if (bookmarksListView.isItemChecked(folderPosition)) {
- // Reselect the bookmark.
- bookmarksListView.setItemChecked(position, true);
+ // Check if the folder is selected.
+ if (bookmarksListView.isItemChecked(folderPosition)) {
+ // Reselect the bookmark.
+ bookmarksListView.setItemChecked(position, true);
- // Display a snackbar explaining why the bookmark cannot be deselected.
- Snackbar.make(bookmarksListView, R.string.cannot_deselect_bookmark, Snackbar.LENGTH_LONG).show();
+ // Display a snackbar explaining why the bookmark cannot be deselected.
+ Snackbar.make(bookmarksListView, R.string.cannot_deselect_bookmark, Snackbar.LENGTH_LONG).show();
+ }
}
- }
- // Increment the bookmarks cursor.
- bookmarksCursor.moveToNext();
+ // Increment the bookmarks cursor.
+ bookmarksCursor.moveToNext();
+ }
}
}
}
// Update the list view.
bookmarksCursorAdapter.changeCursor(bookmarksCursor);
- // Show a Snackbar with the number of deleted bookmarks.
+ // 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 -> {
@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) {
- switch (event) {
- // The user pushed the `Undo` button.
- case Snackbar.Callback.DISMISS_EVENT_ACTION:
- // 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);
- }
- break;
-
- // The Snackbar was dismissed without the `Undo` button being pushed.
- default:
- // Delete each selected bookmark.
- for (long databaseIdLong : selectedBookmarksIdsLongArray) {
- // Convert `databaseIdLong` to an int.
- int databaseIdInt = (int) databaseIdLong;
-
- // Delete the selected bookmark.
- bookmarksDatabaseHelper.deleteBookmark(databaseIdInt);
- }
+ 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.
// 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);
+ }
+ }
+
// Success.
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem menuItem) {
- // Get a handle for the shared preferences.
- SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
-
- // Get the theme preferences.
- boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false);
-
// Get the ID of the menu item that was selected.
int menuItemId = menuItem.getItemId();
onBackPressed();
break;
- case R.id.options_menu_sort:
+ case R.id.sort:
// Update the sort by display order tracker.
sortByDisplayOrder = !sortByDisplayOrder;
- // Get a handle for the bookmarks `ListView`.
+ // 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 (darkTheme) {
- menuItem.setIcon(R.drawable.sort_selected_dark);
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
+ menuItem.setIcon(R.drawable.sort_selected_day);
} else {
- menuItem.setIcon(R.drawable.sort_selected_light);
+ 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 (darkTheme) {
- menuItem.setIcon(R.drawable.sort_dark);
+ if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) {
+ menuItem.setIcon(R.drawable.sort_day);
} else {
- menuItem.setIcon(R.drawable.sort_light);
+ menuItem.setIcon(R.drawable.sort_night);
}
// Display a Snackbar indicating the current sort type.
return true;
}
+ @Override
+ public void onSaveInstanceState (@NonNull Bundle savedInstanceState) {
+ // Run the default commands.
+ super.onSaveInstanceState(savedInstanceState);
+
+ // Store the class variables in the bundle.
+ savedInstanceState.putInt(CURRENT_FOLDER_DATABASE_ID, currentFolderDatabaseId);
+ savedInstanceState.putString(CURRENT_FOLDER_NAME, currentFolderName);
+ savedInstanceState.putBoolean(SORT_BY_DISPLAY_ORDER, sortByDisplayOrder);
+ }
+
@Override
public void onBackPressed() {
// Check to see if a snackbar is currently displayed. If so, it must be closed before existing so that a pending delete is completed before reloading the list view in the bookmarks activity.
bookmarksDeletedSnackbar.dismiss();
} else { // Go home immediately.
// Update the current folder in the bookmarks activity.
- switch (currentFolderDatabaseId) {
- case ALL_FOLDERS_DATABASE_ID:
- // Load the home folder.
- BookmarksActivity.currentFolder = "";
- break;
-
- case HOME_FOLDER_DATABASE_ID:
- // Load the home folder.
- BookmarksActivity.currentFolder = "";
- break;
-
- default:
- // Load the current folder.
- BookmarksActivity.currentFolder = currentFolderName;
+ if ((currentFolderDatabaseId == ALL_FOLDERS_DATABASE_ID) || (currentFolderDatabaseId == HOME_FOLDER_DATABASE_ID)) { // All folders or the the home folder are currently displayed.
+ // Load the home folder.
+ BookmarksActivity.currentFolder = "";
+ } else { // A subfolder is currently displayed.
+ // Load the current folder.
+ BookmarksActivity.currentFolder = currentFolderName;
}
// Reload the bookmarks list view when returning to the bookmarks activity.
}
}
- // Update the list view.
- bookmarksCursorAdapter.changeCursor(bookmarksCursor);
+ // Update the cursor adapter if it isn't null, which happens when the activity is restarted.
+ if (bookmarksCursorAdapter != null) {
+ bookmarksCursorAdapter.changeCursor(bookmarksCursor);
+ }
}
private void selectAllBookmarksInFolder(int folderId) {
}
@Override
- public void onSaveBookmark(DialogFragment dialogFragment, int selectedBookmarkDatabaseId, Bitmap favoriteIconBitmap) {
+ public void onSaveBookmark(DialogFragment dialogFragment, int selectedBookmarkDatabaseId, @NonNull Bitmap favoriteIconBitmap) {
+ // Get the dialog from the dialog fragment.
+ Dialog dialog = dialogFragment.getDialog();
+
+ // Remove the incorrect lint warning below that the dialog might be null.
+ assert dialog != null;
+
// Get handles for the views from dialog fragment.
- RadioButton currentBookmarkIconRadioButton = dialogFragment.getDialog().findViewById(R.id.edit_bookmark_current_icon_radiobutton);
- EditText editBookmarkNameEditText = dialogFragment.getDialog().findViewById(R.id.edit_bookmark_name_edittext);
- EditText editBookmarkUrlEditText = dialogFragment.getDialog().findViewById(R.id.edit_bookmark_url_edittext);
- Spinner folderSpinner = dialogFragment.getDialog().findViewById(R.id.edit_bookmark_folder_spinner);
- EditText displayOrderEditText = dialogFragment.getDialog().findViewById(R.id.edit_bookmark_display_order_edittext);
+ 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);
// Extract the bookmark information.
String bookmarkNameString = editBookmarkNameEditText.getText().toString();
String bookmarkUrlString = editBookmarkUrlEditText.getText().toString();
int folderDatabaseId = (int) folderSpinner.getSelectedItemId();
- int displayOrderInt = Integer.valueOf(displayOrderEditText.getText().toString());
+ int displayOrderInt = Integer.parseInt(displayOrderEditText.getText().toString());
// Instantiate the parent folder name `String`.
String parentFolderNameString;
// Set the parent folder name.
- if (folderDatabaseId == EditBookmarkDatabaseViewDialog.HOME_FOLDER_DATABASE_ID) { // The home folder is selected. Use `""`.
+ if (folderDatabaseId == HOME_FOLDER_DATABASE_ID) { // The home folder is selected. Use `""`.
parentFolderNameString = "";
} else { // Get the parent folder name from the database.
parentFolderNameString = bookmarksDatabaseHelper.getFolderName(folderDatabaseId);
}
@Override
- public void onSaveBookmarkFolder(DialogFragment dialogFragment, int selectedBookmarkDatabaseId, Bitmap favoriteIconBitmap) {
+ public void onSaveBookmarkFolder(DialogFragment dialogFragment, int selectedBookmarkDatabaseId, @NonNull Bitmap favoriteIconBitmap) {
+ // Get the dialog from the dialog fragment.
+ Dialog dialog = dialogFragment.getDialog();
+
+ // Remove the incorrect lint warning below that the dialog might be null.
+ assert dialog != null;
+
// Get handles for the views from dialog fragment.
- RadioButton currentBookmarkIconRadioButton = dialogFragment.getDialog().findViewById(R.id.edit_folder_current_icon_radiobutton);
- RadioButton defaultFolderIconRadioButton = dialogFragment.getDialog().findViewById(R.id.edit_folder_default_icon_radiobutton);
- ImageView defaultFolderIconImageView = dialogFragment.getDialog().findViewById(R.id.edit_folder_default_icon_imageview);
- EditText editBookmarkNameEditText = dialogFragment.getDialog().findViewById(R.id.edit_folder_name_edittext);
- Spinner parentFolderSpinner = dialogFragment.getDialog().findViewById(R.id.edit_folder_parent_folder_spinner);
- EditText displayOrderEditText = dialogFragment.getDialog().findViewById(R.id.edit_folder_display_order_edittext);
+ 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);
// Extract the folder information.
String newFolderNameString = editBookmarkNameEditText.getText().toString();
int parentFolderDatabaseId = (int) parentFolderSpinner.getSelectedItemId();
- int displayOrderInt = Integer.valueOf(displayOrderEditText.getText().toString());
+ int displayOrderInt = Integer.parseInt(displayOrderEditText.getText().toString());
// Instantiate the parent folder name `String`.
String parentFolderNameString;
// Set the parent folder name.
- if (parentFolderDatabaseId == EditBookmarkFolderDatabaseViewDialog.HOME_FOLDER_DATABASE_ID) { // The home folder is selected. Use `""`.
+ if (parentFolderDatabaseId == HOME_FOLDER_DATABASE_ID) { // The home folder is selected. Use `""`.
parentFolderNameString = "";
} else { // Get the parent folder name from the database.
parentFolderNameString = bookmarksDatabaseHelper.getFolderName(parentFolderDatabaseId);