]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blobdiff - app/src/main/java/com/stoutner/privacybrowser/BookmarksActivity.java
Remove lint errors in non-java files. Fix download dialog when download size is...
[PrivacyBrowserAndroid.git] / app / src / main / java / com / stoutner / privacybrowser / BookmarksActivity.java
index f39dae6ea2cdd1ffaa761f54b27687e2b175a1d8..65d1cfddb7e9110b515bc4786fc4e9d7b90c40d7 100644 (file)
@@ -56,22 +56,27 @@ import java.io.ByteArrayOutputStream;
 public class BookmarksActivity extends AppCompatActivity implements CreateBookmark.CreateBookmarkListener,
         CreateBookmarkFolder.CreateBookmarkFolderListener, EditBookmark.EditBookmarkListener,
         EditBookmarkFolder.EditBookmarkFolderListener, MoveToFolder.MoveToFolderListener {
+
     // `bookmarksDatabaseHandler` is public static so it can be accessed from `EditBookmark` and `MoveToFolder`.  It is also used in `onCreate()`,
     // `onCreateBookmarkCreate()`, `updateBookmarksListView()`, and `updateBookmarksListViewExcept()`.
     public static BookmarksDatabaseHandler bookmarksDatabaseHandler;
 
-    // `bookmarksListView` is public static so it can be accessed from `EditBookmark`.
-    // It is also used in `onCreate()`, `updateBookmarksListView()`, and `updateBookmarksListViewExcept()`.
-    public static ListView bookmarksListView;
-
     // `currentFolder` is public static so it can be accessed from `MoveToFolder`.
     // It is used in `onCreate`, `onOptionsItemSelected()`, `onCreateBookmarkCreate`, `onCreateBookmarkFolderCreate`, and `onEditBookmarkSave`.
     public static String currentFolder;
 
+    // `checkedItemIds` is public static so it can be accessed from `EditBookmark`, `EditBookmarkFolder`, and `MoveToFolder`.
+    // It is also used in `onActionItemClicked`.
+    public static long[] checkedItemIds;
+
+
+    // `bookmarksListView` is used in `onCreate()`, `updateBookmarksListView()`, and `updateBookmarksListViewExcept()`.
+    private ListView bookmarksListView;
+
     // `contextualActionMode` is used in `onCreate()` and `onEditBookmarkSave()`.
     private ActionMode contextualActionMode;
 
-    // `selectedBookmarkPosition` is used in `onCreate()` and `onEditBookarkSave()`.
+    // `selectedBookmarkPosition` is used in `onCreate()` and `onEditBookmarkSave()`.
     private int selectedBookmarkPosition;
 
     // `appBar` is used in `onCreate()` and `updateBookmarksListView()`.
@@ -131,11 +136,9 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma
                     // Reload the ListView with `currentFolder`.
                     updateBookmarksListView(currentFolder);
                 } else {  // Load the URL into `mainWebView`.
-                    // Get the bookmark URL and assign it to formattedUrlString.
+                    // Get the bookmark URL and assign it to formattedUrlString.  `mainWebView` will automatically reload when `BookmarksActivity` closes.
                     MainWebViewActivity.formattedUrlString = bookmarkCursor.getString(bookmarkCursor.getColumnIndex(BookmarksDatabaseHandler.BOOKMARK_URL));
 
-                    //  Load formattedUrlString and return to the main activity.
-                    MainWebViewActivity.mainWebView.loadUrl(MainWebViewActivity.formattedUrlString, MainWebViewActivity.customHeaders);
                     NavUtils.navigateUpFromSameTask(bookmarksActivity);
                 }
 
@@ -338,6 +341,9 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma
                         break;
 
                     case R.id.move_to_folder:
+                        // Store `checkedItemIds` for use by the `AlertDialog`.
+                        checkedItemIds = bookmarksListView.getCheckedItemIds();
+
                         // Show the `MoveToFolder` `AlertDialog` and name the instance `@string/move_to_folder
                         DialogFragment moveToFolderDialog = new MoveToFolder();
                         moveToFolderDialog.show(getFragmentManager(), getResources().getString(R.string.move_to_folder));
@@ -356,6 +362,9 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma
                         bookmarksCursor.moveToPosition(selectedBookmarkPosition);
                         boolean isFolder = (bookmarksCursor.getInt(bookmarksCursor.getColumnIndex(BookmarksDatabaseHandler.IS_FOLDER)) == 1);
 
+                        // Store `checkedItemIds` for use by the `AlertDialog`.
+                        checkedItemIds = bookmarksListView.getCheckedItemIds();
+
                         if (isFolder) {
                             // Save the current folder name.
                             oldFolderNameString = bookmarksCursor.getString(bookmarksCursor.getColumnIndex(BookmarksDatabaseHandler.BOOKMARK_NAME));
@@ -407,6 +416,7 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma
                                 .setCallback(new Snackbar.Callback() {
                                     @Override
                                     public void onDismissed(Snackbar snackbar, int event) {
+                                        // Android Studio wants to see entries for every possible `Snackbar.Callback` even if they aren't used.
                                         switch (event) {
                                             // The user pushed the "Undo" button.
                                             case Snackbar.Callback.DISMISS_EVENT_ACTION:
@@ -418,6 +428,18 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma
 
                                                 break;
 
+                                            case Snackbar.Callback.DISMISS_EVENT_CONSECUTIVE:
+                                                // Do nothing and let the default behavior run.
+
+                                            case Snackbar.Callback.DISMISS_EVENT_MANUAL:
+                                                // Do nothing and let the default behavior run.
+
+                                            case Snackbar.Callback.DISMISS_EVENT_SWIPE:
+                                                // Do nothing and let the default behavior run.
+
+                                            case Snackbar.Callback.DISMISS_EVENT_TIMEOUT:
+                                                // Do nothing and let the default behavior run.
+
                                             // The Snackbar was dismissed without the "Undo" button being pushed.
                                             default:
                                                 // Delete each selected row.
@@ -462,7 +484,6 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma
 
         // Set a FloatingActionButton for creating new bookmarks.
         FloatingActionButton createBookmarkFAB = (FloatingActionButton) findViewById(R.id.create_bookmark_fab);
-        assert createBookmarkFAB != null;
         createBookmarkFAB.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View view) {
@@ -568,7 +589,7 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma
             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_radiobuttion);
+            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`.
@@ -695,11 +716,6 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma
         contextualActionMode.finish();
     }
 
-    @Override
-    public void onCancelMoveToFolder(DialogFragment dialogFragment) {
-        // Do nothing because the user selected `Cancel`.
-    }
-
     @Override
     public void onMoveToFolder(DialogFragment dialogFragment) {
         // Get the new folder database id.
@@ -773,7 +789,7 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma
 
                 // Make the font bold for folders.
                 if (cursor.getInt(cursor.getColumnIndex(BookmarksDatabaseHandler.IS_FOLDER)) == 1) {
-                    // The first argument is `null` because we don't want to chage the font.
+                    // The first argument is `null` because we don't want to change the font.
                     bookmarkNameTextView.setTypeface(null, Typeface.BOLD);
                 } else {  // Reset the font to default.
                     bookmarkNameTextView.setTypeface(Typeface.DEFAULT);
@@ -824,7 +840,7 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma
 
                 // Make the font bold for folders.
                 if (cursor.getInt(cursor.getColumnIndex(BookmarksDatabaseHandler.IS_FOLDER)) == 1) {
-                    // The first argument is `null` because we don't want to chage the font.
+                    // The first argument is `null` because we don't want to change the font.
                     bookmarkNameTextView.setTypeface(null, Typeface.BOLD);
                 } else {  // Reset the font to default.
                     bookmarkNameTextView.setTypeface(Typeface.DEFAULT);