X-Git-Url: https://gitweb.stoutner.com/?a=blobdiff_plain;ds=sidebyside;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Factivities%2FBookmarksActivity.java;h=481ab8e316ef9cb4a255230772cf8c687acf31b1;hb=0e0e9f5c67bdc06877cbd19254fef6fc6cb69f2d;hp=689773cf715aba0d312cd940bd5c26122f172ca4;hpb=3dddbcd4bd22d5bd24dd76c8a215446cee829b98;p=PrivacyBrowserAndroid.git diff --git a/app/src/main/java/com/stoutner/privacybrowser/activities/BookmarksActivity.java b/app/src/main/java/com/stoutner/privacybrowser/activities/BookmarksActivity.java index 689773cf..481ab8e3 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/BookmarksActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/BookmarksActivity.java @@ -1,5 +1,5 @@ /* - * Copyright © 2016-2020 Soren Stoutner . + * Copyright © 2016-2021 Soren Stoutner . * * This file is part of Privacy Browser . * @@ -71,15 +71,9 @@ import java.util.ArrayList; public class BookmarksActivity extends AppCompatActivity implements CreateBookmarkDialog.CreateBookmarkListener, CreateBookmarkFolderDialog.CreateBookmarkFolderListener, EditBookmarkDialog.EditBookmarkListener, EditBookmarkFolderDialog.EditBookmarkFolderListener, MoveToFolderDialog.MoveToFolderListener { - // `currentFolder` is public static so it can be accessed from `MoveToFolderDialog` and `BookmarksDatabaseViewActivity`. - // It is used in `onCreate`, `onOptionsItemSelected()`, `onBackPressed()`, `onCreateBookmark()`, `onCreateBookmarkFolder()`, `onSaveBookmark()`, `onSaveBookmarkFolder()`, `onMoveToFolder()`, - // and `loadFolder()`. + // `currentFolder` is public static so it can be accessed from `BookmarksDatabaseViewActivity`. public static String currentFolder; - // `checkedItemIds` is public static so it can be accessed from `MoveToFolderDialog`. It is also used in `onCreate()`, `onSaveBookmark()`, `onSaveBookmarkFolder()`, `onMoveToFolder()`, - // and `updateMoveIcons()`. - public static long[] checkedItemIds; - // `restartFromBookmarksDatabaseViewActivity` is public static so it can be accessed from `BookmarksDatabaseViewActivity`. It is also used in `onRestart()`. public static boolean restartFromBookmarksDatabaseViewActivity; @@ -315,7 +309,7 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma // Initialize the selected bookmark position. int selectedBookmarkPosition = 0; - // Get a handle for the menu item ID. + // Get the menu item ID. int menuItemId = menuItem.getItemId(); // Run the commands according to the selected action item. @@ -420,11 +414,8 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma // Update the enabled status of the move icons. updateMoveIcons(); } else if (menuItemId == R.id.move_to_folder) { // Move to folder. - // Store the checked item IDs for use by the alert dialog. - checkedItemIds = bookmarksListView.getCheckedItemIds(); - // Instantiate the move to folder alert dialog. - DialogFragment moveToFolderDialog = new MoveToFolderDialog(); + DialogFragment moveToFolderDialog = MoveToFolderDialog.moveBookmarks(currentFolder, bookmarksListView.getCheckedItemIds()); // Show the move to folder alert dialog. moveToFolderDialog.show(getSupportFragmentManager(), getResources().getString(R.string.move_to_folder)); @@ -769,20 +760,20 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma assert dialog != null; // Get handles for the views in the dialog fragment. - EditText createFolderNameEditText = dialog.findViewById(R.id.create_folder_name_edittext); - RadioButton defaultFolderIconRadioButton = dialog.findViewById(R.id.create_folder_default_icon_radiobutton); - ImageView folderIconImageView = dialog.findViewById(R.id.create_folder_default_icon); + EditText folderNameEditText = dialog.findViewById(R.id.folder_name_edittext); + RadioButton defaultIconRadioButton = dialog.findViewById(R.id.default_icon_radiobutton); + ImageView defaultIconImageView = dialog.findViewById(R.id.default_icon_imageview); // Get new folder name string. - String folderNameString = createFolderNameEditText.getText().toString(); + String folderNameString = folderNameEditText.getText().toString(); // Create a folder icon bitmap. Bitmap folderIconBitmap; // Set the folder icon bitmap according to the dialog. - if (defaultFolderIconRadioButton.isChecked()) { // Use the default folder icon. + if (defaultIconRadioButton.isChecked()) { // Use the default folder icon. // Get the default folder icon drawable. - Drawable folderIconDrawable = folderIconImageView.getDrawable(); + Drawable folderIconDrawable = defaultIconImageView.getDrawable(); // Convert the folder icon drawable to a bitmap drawable. BitmapDrawable folderIconBitmapDrawable = (BitmapDrawable) folderIconDrawable; @@ -815,7 +806,7 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma // Update the bookmarks cursor with the current contents of this folder. bookmarksCursor = bookmarksDatabaseHelper.getBookmarksByDisplayOrder(currentFolder); - // Update the `ListView`. + // Update the list view. bookmarksCursorAdapter.changeCursor(bookmarksCursor); // Scroll to the new folder. @@ -830,17 +821,17 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma // Remove the incorrect lint warning below that the dialog might be null. assert dialog != null; - // Get handles for the views from `dialogFragment`. - EditText editBookmarkNameEditText = dialog.findViewById(R.id.edit_bookmark_name_edittext); - EditText editBookmarkUrlEditText = dialog.findViewById(R.id.edit_bookmark_url_edittext); - RadioButton currentBookmarkIconRadioButton = dialog.findViewById(R.id.edit_bookmark_current_icon_radiobutton); + // Get handles for the views from the dialog fragment. + EditText bookmarkNameEditText = dialog.findViewById(R.id.bookmark_name_edittext); + EditText bookmarkUrlEditText = dialog.findViewById(R.id.bookmark_url_edittext); + RadioButton currentIconRadioButton = dialog.findViewById(R.id.current_icon_radiobutton); // Store the bookmark strings. - String bookmarkNameString = editBookmarkNameEditText.getText().toString(); - String bookmarkUrlString = editBookmarkUrlEditText.getText().toString(); + String bookmarkNameString = bookmarkNameEditText.getText().toString(); + String bookmarkUrlString = bookmarkUrlEditText.getText().toString(); // 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); } else { // Update the bookmark using the WebView favorite icon. // Create a favorite icon byte array output stream. @@ -870,18 +861,18 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma } @Override - public void onSaveBookmarkFolder(DialogFragment dialogFragment, int selectedFolderDatabaseId, Bitmap favoriteIconBitmap) { + public void onSaveBookmarkFolder(DialogFragment dialogFragment, int selectedFolderDatabaseId, @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 `dialogFragment`. - RadioButton currentFolderIconRadioButton = 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 editFolderNameEditText = dialog.findViewById(R.id.edit_folder_name_edittext); + // Get handles for the views from the dialog fragment. + RadioButton currentFolderIconRadioButton = dialog.findViewById(R.id.current_icon_radiobutton); + RadioButton defaultFolderIconRadioButton = dialog.findViewById(R.id.default_icon_radiobutton); + ImageView defaultFolderIconImageView = dialog.findViewById(R.id.default_icon_imageview); + EditText editFolderNameEditText = dialog.findViewById(R.id.folder_name_edittext); // Get the new folder name. String newFolderNameString = editFolderNameEditText.getText().toString();