+
+ // Set the create new bookmark FAB to display the `AlertDialog`.
+ createBookmarkFab.setOnClickListener(view -> {
+ // Remove the incorrect lint warning below.
+ assert currentUrl != null;
+ assert currentTitle != null;
+
+ // Instantiate the create bookmark dialog.
+ DialogFragment createBookmarkDialog = CreateBookmarkDialog.createBookmark(currentUrl, currentTitle, favoriteIconBitmap);
+
+ // Display the create bookmark dialog.
+ createBookmarkDialog.show(getSupportFragmentManager(), getResources().getString(R.string.create_bookmark));
+ });
+
+ // Restore the state if the app has been restarted.
+ if (savedInstanceState != null) {
+ // Update the bookmarks list view after it has loaded.
+ bookmarksListView.post(() -> {
+ // Get the checked bookmarks array list.
+ ArrayList<Integer> checkedBookmarksArrayList = savedInstanceState.getIntegerArrayList(CHECKED_BOOKMARKS_ARRAY_LIST);
+
+ // Check each previously checked bookmark in the list view. When the minimum API >= 24 a `forEach()` command can be used instead.
+ if (checkedBookmarksArrayList != null) {
+ for (int i = 0; i < checkedBookmarksArrayList.size(); i++) {
+ bookmarksListView.setItemChecked(checkedBookmarksArrayList.get(i), true);
+ }
+ }
+ });
+ }
+ }
+
+ @Override
+ public void onRestart() {
+ // Run the default commands.
+ super.onRestart();
+
+ // Update the list view if returning from the bookmarks database view activity.
+ if (restartFromBookmarksDatabaseViewActivity) {
+ // Load the current folder in the list view.
+ loadFolder();
+
+ // Reset `restartFromBookmarksDatabaseViewActivity`.
+ restartFromBookmarksDatabaseViewActivity = false;
+ }
+ }
+
+ @Override
+ public void onSaveInstanceState(@NonNull Bundle savedInstanceState) {
+ // Run the default commands.
+ super.onSaveInstanceState(savedInstanceState);
+
+ // Get the array of the checked items.
+ SparseBooleanArray checkedBookmarksSparseBooleanArray = bookmarksListView.getCheckedItemPositions();
+
+ // Create a checked items array list.
+ ArrayList<Integer> checkedBookmarksArrayList = new ArrayList<>();
+
+ // Add each checked bookmark position to the array list.
+ for (int i = 0; i < checkedBookmarksSparseBooleanArray.size(); i++) {
+ // Check to see if the bookmark is currently checked. Bookmarks that have previously been checked but currently aren't will be populated in the sparse boolean array, but will return false.
+ if (checkedBookmarksSparseBooleanArray.valueAt(i)) {
+ // Add the bookmark position to the checked bookmarks array list.
+ checkedBookmarksArrayList.add(checkedBookmarksSparseBooleanArray.keyAt(i));
+ }
+ }
+
+ // Store the checked items array list in the saved instance state.
+ savedInstanceState.putIntegerArrayList(CHECKED_BOOKMARKS_ARRAY_LIST, checkedBookmarksArrayList);