]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blob - app/src/main/java/com/stoutner/privacybrowser/activities/BookmarksActivity.java
Reselect the previously selected bookmarks on undelete. https://redmine.stoutner...
[PrivacyBrowserAndroid.git] / app / src / main / java / com / stoutner / privacybrowser / activities / BookmarksActivity.java
1 /*
2  * Copyright © 2016-2017 Soren Stoutner <soren@stoutner.com>.
3  *
4  * This file is part of Privacy Browser <https://www.stoutner.com/privacy-browser>.
5  *
6  * Privacy Browser is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Privacy Browser is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Privacy Browser.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 package com.stoutner.privacybrowser.activities;
21
22 import android.app.Activity;
23 import android.content.Context;
24 import android.content.Intent;
25 import android.database.Cursor;
26 import android.graphics.Bitmap;
27 import android.graphics.BitmapFactory;
28 import android.graphics.Typeface;
29 import android.graphics.drawable.BitmapDrawable;
30 import android.graphics.drawable.Drawable;
31 import android.os.Bundle;
32 import android.support.design.widget.FloatingActionButton;
33 import android.support.design.widget.Snackbar;
34 import android.support.v4.app.NavUtils;
35 import android.support.v7.app.ActionBar;
36 import android.support.v7.app.AppCompatActivity;
37 import android.support.v7.app.AppCompatDialogFragment;
38 import android.support.v7.widget.Toolbar;
39 import android.util.SparseBooleanArray;
40 import android.view.ActionMode;
41 import android.view.Menu;
42 import android.view.MenuItem;
43 import android.view.View;
44 import android.view.ViewGroup;
45 import android.widget.AbsListView;
46 import android.widget.AdapterView;
47 import android.widget.CursorAdapter;
48 import android.widget.EditText;
49 import android.widget.ImageView;
50 import android.widget.ListView;
51 import android.widget.RadioButton;
52 import android.widget.TextView;
53
54 import com.stoutner.privacybrowser.dialogs.CreateBookmarkDialog;
55 import com.stoutner.privacybrowser.dialogs.CreateBookmarkFolderDialog;
56 import com.stoutner.privacybrowser.dialogs.EditBookmarkDialog;
57 import com.stoutner.privacybrowser.dialogs.EditBookmarkFolderDialog;
58 import com.stoutner.privacybrowser.dialogs.MoveToFolderDialog;
59 import com.stoutner.privacybrowser.R;
60 import com.stoutner.privacybrowser.helpers.BookmarksDatabaseHelper;
61
62 import java.io.ByteArrayOutputStream;
63
64 public class BookmarksActivity extends AppCompatActivity implements CreateBookmarkDialog.CreateBookmarkListener, CreateBookmarkFolderDialog.CreateBookmarkFolderListener, EditBookmarkDialog.EditBookmarkListener, EditBookmarkFolderDialog.EditBookmarkFolderListener,
65         MoveToFolderDialog.MoveToFolderListener {
66
67     // `bookmarksDatabaseHelper` is public static so it can be accessed from `CreateBookmarkFolderDialog`, `EditBookmarkDialog`, `EditBookmarkFolderDialog` and `MoveToFolderDialog`.  It is also used in `onCreate()`,
68     // `onCreateBookmarkCreate()`, `updateBookmarksListView()`, and `updateBookmarksListViewExcept()`.
69     public static BookmarksDatabaseHelper bookmarksDatabaseHelper;
70
71     // `currentFolder` is public static so it can be accessed from `MoveToFolderDialog`.
72     // It is used in `onCreate`, `onOptionsItemSelected()`, `onCreateBookmarkCreate`, `onCreateBookmarkFolderCreate`, and `onEditBookmarkSave`.
73     public static String currentFolder;
74
75     // `checkedItemIds` is public static so it can be accessed from `EditBookmarkDialog`, `EditBookmarkFolderDialog`, and `MoveToFolderDialog`.
76     // It is also used in `onActionItemClicked`.
77     public static long[] checkedItemIds;
78
79
80     // `bookmarksListView` is used in `onCreate()`, `updateBookmarksListView()`, and `updateBookmarksListViewExcept()`.
81     private ListView bookmarksListView;
82
83     // `contextualActionMode` is used in `onCreate()` and `onEditBookmarkSave()`.
84     private ActionMode contextualActionMode;
85
86     // `bookmarkListViewPosition` is used in `onCreate()`, `onSaveEditBookmark()`, and `onSaveEditBookmarkFolder()`.
87     private int bookmarksListViewPosition;
88
89     // `appBar` is used in `onCreate()` and `updateBookmarksListView()`.
90     private ActionBar appBar;
91
92     // `bookmarksCursor` is used in `onCreate()`, `updateBookmarksListView()`, and `updateBookmarksListViewExcept()`.
93     private Cursor bookmarksCursor;
94
95     // `oldFolderName` is used in `onCreate()` and `onEditBookmarkFolderSave()`.
96     private String oldFolderNameString;
97
98     @Override
99     protected void onCreate(Bundle savedInstanceState) {
100         // Set the activity theme.
101         if (MainWebViewActivity.darkTheme) {
102             setTheme(R.style.PrivacyBrowserDark_SecondaryActivity);
103         } else {
104             setTheme(R.style.PrivacyBrowserLight_SecondaryActivity);
105         }
106
107         // Run the default commands.
108         super.onCreate(savedInstanceState);
109
110         // Set the content view.
111         setContentView(R.layout.bookmarks_coordinatorlayout);
112
113         // Use the `SupportActionBar` from `android.support.v7.app.ActionBar` until the minimum API is >= 21.
114         final Toolbar bookmarksAppBar = (Toolbar) findViewById(R.id.bookmarks_toolbar);
115         setSupportActionBar(bookmarksAppBar);
116
117         // Display the home arrow on `SupportActionBar`.
118         appBar = getSupportActionBar();
119         assert appBar != null;// This assert removes the incorrect warning in Android Studio on the following line that `appBar` might be null.
120         appBar.setDisplayHomeAsUpEnabled(true);
121
122
123         // Initialize the database helper and the `ListView`.  `this` specifies the context.  The two `nulls` do not specify the database name or a `CursorFactory`.
124         // The `0` specifies a database version, but that is ignored and set instead using a constant in `BookmarksDatabaseHelper`.
125         bookmarksDatabaseHelper = new BookmarksDatabaseHelper(this, null, null, 0);
126         bookmarksListView = (ListView) findViewById(R.id.bookmarks_listview);
127
128         // Set currentFolder to the home folder, which is `""` in the database.
129         currentFolder = "";
130
131         // Display the bookmarks in the ListView.
132         updateBookmarksListView(currentFolder);
133
134         // Set a listener so that tapping a list item loads the URL.  We need to store the activity in a variable so that we can return to the parent activity after loading the URL.
135         final Activity bookmarksActivity = this;
136         bookmarksListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
137             @Override
138             public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
139                 // Convert the id from long to int to match the format of the bookmarks database.
140                 int databaseID = (int) id;
141
142                 // Get the bookmark `Cursor` for this ID and move it to the first row.
143                 Cursor bookmarkCursor = bookmarksDatabaseHelper.getBookmarkCursor(databaseID);
144                 bookmarkCursor.moveToFirst();
145
146                 // If the bookmark is a folder load its contents into the ListView.
147                 if (bookmarkCursor.getInt(bookmarkCursor.getColumnIndex(BookmarksDatabaseHelper.IS_FOLDER)) == 1) {
148                     // Update `currentFolder`.
149                     currentFolder = bookmarkCursor.getString(bookmarkCursor.getColumnIndex(BookmarksDatabaseHelper.BOOKMARK_NAME));
150
151                     // Reload the ListView with `currentFolder`.
152                     updateBookmarksListView(currentFolder);
153                 } else {  // Load the URL into `mainWebView`.
154                     // Get the bookmark URL and assign it to formattedUrlString.  `mainWebView` will automatically reload when `BookmarksActivity` closes.
155                     MainWebViewActivity.formattedUrlString = bookmarkCursor.getString(bookmarkCursor.getColumnIndex(BookmarksDatabaseHelper.BOOKMARK_URL));
156
157                     NavUtils.navigateUpFromSameTask(bookmarksActivity);
158                 }
159
160                 // Close the `Cursor`.
161                 bookmarkCursor.close();
162             }
163         });
164
165         // `MultiChoiceModeListener` handles long clicks.
166         bookmarksListView.setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() {
167             // `moveBookmarkUpMenuItem` is used in `onCreateActionMode()` and `onItemCheckedStateChanged`.
168             MenuItem moveBookmarkUpMenuItem;
169
170             // `moveBookmarkDownMenuItem` is used in `onCreateActionMode()` and `onItemCheckedStateChanged`.
171             MenuItem moveBookmarkDownMenuItem;
172
173             // `editBookmarkMenuItem` is used in `onCreateActionMode()` and `onItemCheckedStateChanged`.
174             MenuItem editBookmarkMenuItem;
175
176             // `selectAllBookmarks` is used in `onCreateActionMode()` and `onItemCheckedStateChanges`.
177             MenuItem selectAllBookmarksMenuItem;
178
179             @Override
180             public boolean onCreateActionMode(ActionMode mode, Menu menu) {
181                 // Inflate the menu for the contextual app bar and set the title.
182                 getMenuInflater().inflate(R.menu.bookmarks_context_menu, menu);
183
184                 // Set the title.
185                 if (currentFolder.isEmpty()) {
186                     // Use `R.string.bookmarks` if we are in the home folder.
187                     mode.setTitle(R.string.bookmarks);
188                 } else {  // Use the current folder name as the title.
189                     mode.setTitle(currentFolder);
190                 }
191
192                 // Get a handle for MenuItems we need to selectively disable.
193                 moveBookmarkUpMenuItem = menu.findItem(R.id.move_bookmark_up);
194                 moveBookmarkDownMenuItem = menu.findItem(R.id.move_bookmark_down);
195                 editBookmarkMenuItem = menu.findItem(R.id.edit_bookmark);
196                 selectAllBookmarksMenuItem = menu.findItem(R.id.context_menu_select_all_bookmarks);
197
198                 // Store `contextualActionMode` so we can close it programatically.
199                 contextualActionMode = mode;
200
201                 return true;
202             }
203
204             @Override
205             public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
206                 // Get a handle for the move to folder menu item.
207                 MenuItem moveToFolderMenuItem = menu.findItem(R.id.move_to_folder);
208
209                 // Get a `Cursor` with all of the folders.
210                 Cursor folderCursor = bookmarksDatabaseHelper.getAllFoldersCursor();
211
212                 // Enable the move to folder menu item if at least one folder exists.
213                 moveToFolderMenuItem.setVisible(folderCursor.getCount() > 0);
214
215                 // `return true` indicates that the menu has been updated.
216                 return true;
217             }
218
219             @Override
220             public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
221                 // Get an array of the selected bookmarks.
222                 long[] selectedBookmarksLongArray = bookmarksListView.getCheckedItemIds();
223
224                 // Calculate the number of selected bookmarks.
225                 int numberOfSelectedBookmarks = selectedBookmarksLongArray.length;
226
227                 // Adjust the `mode` and the menu for the number of selected bookmarks.
228                 if (numberOfSelectedBookmarks == 0) {
229                     mode.finish();
230                 } else if (numberOfSelectedBookmarks == 1) {
231                     // List the number of selected bookmarks in the subtitle.
232                     mode.setSubtitle(getString(R.string.one_selected));
233
234                     // Show the `Move Up`, `Move Down`, and  `Edit` options.
235                     moveBookmarkUpMenuItem.setVisible(true);
236                     moveBookmarkDownMenuItem.setVisible(true);
237                     editBookmarkMenuItem.setVisible(true);
238
239                     // Get the database IDs for the bookmarks.
240                     int selectedBookmarkDatabaseId = (int) selectedBookmarksLongArray[0];
241                     int firstBookmarkDatabaseId = (int) bookmarksListView.getItemIdAtPosition(0);
242                     // bookmarksListView is 0 indexed.
243                     int lastBookmarkDatabaseId = (int) bookmarksListView.getItemIdAtPosition(bookmarksListView.getCount() - 1);
244
245                     // Disable `moveBookmarkUpMenuItem` if the selected bookmark is at the top of the ListView.
246                     if (selectedBookmarkDatabaseId == firstBookmarkDatabaseId) {
247                         moveBookmarkUpMenuItem.setEnabled(false);
248                         moveBookmarkUpMenuItem.setIcon(R.drawable.move_up_disabled);
249                     } else {  // Otherwise enable `moveBookmarkUpMenuItem`.
250                         moveBookmarkUpMenuItem.setEnabled(true);
251
252                         // Set the icon according to the theme.
253                         if (MainWebViewActivity.darkTheme) {
254                             moveBookmarkUpMenuItem.setIcon(R.drawable.move_up_enabled_dark);
255                         } else {
256                             moveBookmarkUpMenuItem.setIcon(R.drawable.move_up_enabled_light);
257                         }
258                     }
259
260                     // Disable `moveBookmarkDownMenuItem` if the selected bookmark is at the bottom of the ListView.
261                     if (selectedBookmarkDatabaseId == lastBookmarkDatabaseId) {
262                         moveBookmarkDownMenuItem.setEnabled(false);
263                         moveBookmarkDownMenuItem.setIcon(R.drawable.move_down_disabled);
264                     } else {  // Otherwise enable `moveBookmarkDownMenuItem`.
265                         moveBookmarkDownMenuItem.setEnabled(true);
266
267                         // Set the icon according to the theme.
268                         if (MainWebViewActivity.darkTheme) {
269                             moveBookmarkDownMenuItem.setIcon(R.drawable.move_down_enabled_dark);
270                         } else {
271                             moveBookmarkDownMenuItem.setIcon(R.drawable.move_down_enabled_light);
272                         }
273                     }
274                 } else {  // More than one bookmark is selected.
275                     // List the number of selected bookmarks in the subtitle.
276                     mode.setSubtitle(numberOfSelectedBookmarks + " " + getString(R.string.selected));
277
278                     // Hide non-applicable `MenuItems`.
279                     moveBookmarkUpMenuItem.setVisible(false);
280                     moveBookmarkDownMenuItem.setVisible(false);
281                     editBookmarkMenuItem.setVisible(false);
282                 }
283
284                 // Do not show `Select All` if all the bookmarks are already checked.
285                 if (bookmarksListView.getCheckedItemIds().length == bookmarksListView.getCount()) {
286                     selectAllBookmarksMenuItem.setVisible(false);
287                 } else {
288                     selectAllBookmarksMenuItem.setVisible(true);
289                 }
290             }
291
292             @Override
293             public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
294                 // Get the menu item ID.
295                 int menuItemId = item.getItemId();
296
297                 // Instantiate the common variables.
298                 int numberOfBookmarks;
299                 int selectedBookmarkPosition;
300                 int selectedBookmarkNewPosition;
301                 final SparseBooleanArray selectedBookmarksPositionsSparseBooleanArray;
302
303                 switch (menuItemId) {
304                     case R.id.move_bookmark_up:
305                         // Get the array of checked bookmarks.
306                         selectedBookmarksPositionsSparseBooleanArray = bookmarksListView.getCheckedItemPositions();
307
308                         // Store the position of the selected bookmark.
309                         selectedBookmarkPosition = selectedBookmarksPositionsSparseBooleanArray.keyAt(0);
310
311                         // Initialize `selectedBookmarkNewPosition`.
312                         selectedBookmarkNewPosition = 0;
313
314                         // Iterate through the bookmarks.
315                         for (int i = 0; i < bookmarksListView.getCount(); i++) {
316                             // Get the database ID for the current bookmark.
317                             int currentBookmarkDatabaseId = (int) bookmarksListView.getItemIdAtPosition(i);
318
319                             // Update the display order for the current bookmark.
320                             if (i == selectedBookmarkPosition) {  // The current bookmark is the selected bookmark.
321                                 // Move the current bookmark up one.
322                                 bookmarksDatabaseHelper.updateDisplayOrder(currentBookmarkDatabaseId, i - 1);
323                                 selectedBookmarkNewPosition = i - 1;
324                             } else if ((i + 1) == selectedBookmarkPosition){  // The current bookmark is immediately above the selected bookmark.
325                                 // Move the current bookmark down one.
326                                 bookmarksDatabaseHelper.updateDisplayOrder(currentBookmarkDatabaseId, i + 1);
327                             } else {  // The current bookmark is not changing positions.
328                                 // Move `bookmarksCursor` to the current bookmark position.
329                                 bookmarksCursor.moveToPosition(i);
330
331                                 // Update the display order only if it is not correct in the database.
332                                 if (bookmarksCursor.getInt(bookmarksCursor.getColumnIndex(BookmarksDatabaseHelper.DISPLAY_ORDER)) != i) {
333                                     bookmarksDatabaseHelper.updateDisplayOrder(currentBookmarkDatabaseId, i);
334                                 }
335                             }
336                         }
337
338                         // Refresh the ListView.
339                         updateBookmarksListView(currentFolder);
340
341                         // Select the previously selected bookmark in the new location.
342                         bookmarksListView.setItemChecked(selectedBookmarkNewPosition, true);
343
344                         // Scroll `bookmarksListView` to five items above `selectedBookmarkNewPosition`.
345                         bookmarksListView.setSelection(selectedBookmarkNewPosition - 5);
346
347                         break;
348
349                     case R.id.move_bookmark_down:
350                         // Get the array of checked bookmarks.
351                         selectedBookmarksPositionsSparseBooleanArray = bookmarksListView.getCheckedItemPositions();
352
353                         // Store the position of the selected bookmark.
354                         selectedBookmarkPosition = selectedBookmarksPositionsSparseBooleanArray.keyAt(0);
355
356                         // Initialize `selectedBookmarkNewPosition`.
357                         selectedBookmarkNewPosition = 0;
358
359                         // Iterate through the bookmarks.
360                         for (int i = 0; i <bookmarksListView.getCount(); i++) {
361                             // Get the database ID for the current bookmark.
362                             int currentBookmarkDatabaseId = (int) bookmarksListView.getItemIdAtPosition(i);
363
364                             // Update the display order for the current bookmark.
365                             if (i == selectedBookmarkPosition) {  // The current bookmark is the selected bookmark.
366                                 // Move the current bookmark down one.
367                                 bookmarksDatabaseHelper.updateDisplayOrder(currentBookmarkDatabaseId, i + 1);
368                                 selectedBookmarkNewPosition = i + 1;
369                             } else if ((i - 1) == selectedBookmarkPosition) {  // The current bookmark is immediately below the selected bookmark.
370                                 // Move the bookmark below the selected bookmark up one.
371                                 bookmarksDatabaseHelper.updateDisplayOrder(currentBookmarkDatabaseId, i - 1);
372                             } else {  // The current bookmark is not changing positions.
373                                 // Move `bookmarksCursor` to the current bookmark position.
374                                 bookmarksCursor.moveToPosition(i);
375
376                                 // Update the display order only if it is not correct in the database.
377                                 if (bookmarksCursor.getInt(bookmarksCursor.getColumnIndex(BookmarksDatabaseHelper.DISPLAY_ORDER)) != i) {
378                                     bookmarksDatabaseHelper.updateDisplayOrder(currentBookmarkDatabaseId, i);
379                                 }
380                             }
381                         }
382
383                         // Refresh the ListView.
384                         updateBookmarksListView(currentFolder);
385
386                         // Select the previously selected bookmark in the new location.
387                         bookmarksListView.setItemChecked(selectedBookmarkNewPosition, true);
388
389                         // Scroll `bookmarksListView` to five items above `selectedBookmarkNewPosition`.
390                         bookmarksListView.setSelection(selectedBookmarkNewPosition - 5);
391                         break;
392
393                     case R.id.move_to_folder:
394                         // Store `checkedItemIds` for use by the `AlertDialog`.
395                         checkedItemIds = bookmarksListView.getCheckedItemIds();
396
397                         // Show the `MoveToFolderDialog` `AlertDialog` and name the instance `@string/move_to_folder
398                         AppCompatDialogFragment moveToFolderDialog = new MoveToFolderDialog();
399                         moveToFolderDialog.show(getSupportFragmentManager(), getResources().getString(R.string.move_to_folder));
400                         break;
401
402                     case R.id.edit_bookmark:
403                         // Store the scroll position of the bookmarks `ListView`.
404                         bookmarksListViewPosition = bookmarksListView.getFirstVisiblePosition();
405
406                         // Get the array of checked bookmarks.
407                         selectedBookmarksPositionsSparseBooleanArray = bookmarksListView.getCheckedItemPositions();
408
409                         // Get the position of the selected bookmark.
410                         selectedBookmarkPosition = selectedBookmarksPositionsSparseBooleanArray.keyAt(0);
411
412                         // Move to the selected database ID and find out if it is a folder.
413                         bookmarksCursor.moveToPosition(selectedBookmarkPosition);
414                         boolean isFolder = (bookmarksCursor.getInt(bookmarksCursor.getColumnIndex(BookmarksDatabaseHelper.IS_FOLDER)) == 1);
415
416                         // Store `checkedItemIds` for use by the `AlertDialog`.
417                         checkedItemIds = bookmarksListView.getCheckedItemIds();
418
419                         if (isFolder) {
420                             // Save the current folder name.
421                             oldFolderNameString = bookmarksCursor.getString(bookmarksCursor.getColumnIndex(BookmarksDatabaseHelper.BOOKMARK_NAME));
422
423                             // Show the `EditBookmarkFolderDialog` `AlertDialog` and name the instance `@string/edit_folder`.
424                             AppCompatDialogFragment editFolderDialog = new EditBookmarkFolderDialog();
425                             editFolderDialog.show(getSupportFragmentManager(), getResources().getString(R.string.edit_folder));
426                         } else {
427                             // Show the `EditBookmarkDialog` `AlertDialog` and name the instance `@string/edit_bookmark`.
428                             AppCompatDialogFragment editBookmarkDialog = new EditBookmarkDialog();
429                             editBookmarkDialog.show(getSupportFragmentManager(), getResources().getString(R.string.edit_bookmark));
430                         }
431                         break;
432
433                     case R.id.delete_bookmark:
434                         // Get an array of the selected rows IDs.
435                         final long[] selectedBookmarksIdsLongArray = bookmarksListView.getCheckedItemIds();
436
437                         // Get the array of checked bookmarks.  `.clone()` makes a copy that won't change if `bookmarksListView` is reloaded, which is needed for re-selecting the bookmarks on undelete.
438                         selectedBookmarksPositionsSparseBooleanArray = bookmarksListView.getCheckedItemPositions().clone();
439
440                         // Store the current scroll position for the purpose of restoring it on undelete.
441                         final int scrollPositionBeforeDelete = bookmarksListView.getFirstVisiblePosition();
442
443                         // Store the scroll position of the bookmarks `ListView`.
444                         bookmarksListViewPosition = bookmarksListView.getFirstVisiblePosition();
445
446                         // Display the bookmarks except for those that are going to be deleted.
447                         updateBookmarksListViewExcept(selectedBookmarksIdsLongArray, currentFolder);
448
449                         // Restore the scroll position.
450                         bookmarksListView.setSelection(bookmarksListViewPosition);
451
452                         // Create `snackbarMessage`.
453                         String snackbarMessage;
454
455                         // Determine how many items are in the array and prepare an appropriate Snackbar message.
456                         if (selectedBookmarksIdsLongArray.length == 1) {
457                             snackbarMessage = getString(R.string.one_bookmark_deleted);
458                         } else {
459                             snackbarMessage = selectedBookmarksIdsLongArray.length + " " + getString(R.string.bookmarks_deleted);
460                         }
461
462                         // Show a SnackBar.
463                         Snackbar.make(findViewById(R.id.bookmarks_coordinatorlayout), snackbarMessage, Snackbar.LENGTH_LONG)
464                                 .setAction(R.string.undo, new View.OnClickListener() {
465                                     @Override
466                                     public void onClick(View view) {
467                                         // Do nothing because everything will be handled by `onDismissed()` below.
468                                     }
469                                 })
470                                 .addCallback(new Snackbar.Callback() {
471                                     @Override
472                                     public void onDismissed(Snackbar snackbar, int event) {
473                                         switch (event) {
474                                             // The user pushed the `Undo` button.
475                                             case Snackbar.Callback.DISMISS_EVENT_ACTION:
476                                                 // Refresh the ListView to show the rows again.
477                                                 updateBookmarksListView(currentFolder);
478
479                                                 // Select the previously selected bookmarks.
480                                                 for (int i = 0; i < selectedBookmarksPositionsSparseBooleanArray.size(); i++) {
481                                                     bookmarksListView.setItemChecked(selectedBookmarksPositionsSparseBooleanArray.keyAt(i), true);
482                                                 }
483
484                                                 // Restore the scroll position.
485                                                 bookmarksListView.setSelection(scrollPositionBeforeDelete);
486                                                 break;
487
488                                             // The `Snackbar` was dismissed without the `Undo` button being pushed.
489                                             default:
490                                                 // Delete each selected row.
491                                                 for (long databaseIdLong : selectedBookmarksIdsLongArray) {
492                                                     // Convert `databaseIdLong` to an int.
493                                                     int databaseIdInt = (int) databaseIdLong;
494
495                                                     if (bookmarksDatabaseHelper.isFolder(databaseIdInt)) {
496                                                         deleteBookmarkFolderContents(databaseIdInt);
497                                                     }
498
499                                                     // Delete `databaseIdInt`.
500                                                     bookmarksDatabaseHelper.deleteBookmark(databaseIdInt);
501                                                 }
502
503                                                 // Update the display order.
504                                                 for (int i = 0; i < bookmarksListView.getCount(); i++) {
505                                                     // Get the database ID for the current bookmark.
506                                                     int currentBookmarkDatabaseId = (int) bookmarksListView.getItemIdAtPosition(i);
507
508                                                     // Move `bookmarksCursor` to the current bookmark position.
509                                                     bookmarksCursor.moveToPosition(i);
510
511                                                     // Update the display order only if it is not correct in the database.
512                                                     if (bookmarksCursor.getInt(bookmarksCursor.getColumnIndex(BookmarksDatabaseHelper.DISPLAY_ORDER)) != i) {
513                                                         bookmarksDatabaseHelper.updateDisplayOrder(currentBookmarkDatabaseId, i);
514                                                     }
515                                                 }
516                                                 break;
517                                         }
518                                     }
519                                 })
520                                 .show();
521
522                         // Close the contextual app bar.
523                         mode.finish();
524                         break;
525
526                     case R.id.context_menu_select_all_bookmarks:
527                         numberOfBookmarks = bookmarksListView.getCount();
528
529                         for (int i = 0; i < numberOfBookmarks; i++) {
530                             bookmarksListView.setItemChecked(i, true);
531                         }
532                         break;
533                 }
534                 // Consume the click.
535                 return true;
536             }
537
538             @Override
539             public void onDestroyActionMode(ActionMode mode) {
540
541             }
542         });
543
544         // Get handles for the `FloatingActionButtons.
545         FloatingActionButton createBookmarkFolderFab = (FloatingActionButton) findViewById(R.id.create_bookmark_folder_fab);
546         FloatingActionButton createBookmarkFab = (FloatingActionButton) findViewById(R.id.create_bookmark_fab);
547
548         // Set the create new bookmark folder FAB to display the dialog box.
549         createBookmarkFolderFab.setOnClickListener(new View.OnClickListener() {
550             @Override
551             public void onClick(View v) {
552                 // Show the `CreateBookmarkFolderDialog` `AlertDialog` and name the instance `@string/create_folder`.
553                 AppCompatDialogFragment createBookmarkFolderDialog = new CreateBookmarkFolderDialog();
554                 createBookmarkFolderDialog.show(getSupportFragmentManager(), getResources().getString(R.string.create_folder));
555             }
556         });
557
558         // Set the create new bookmark FAB to display the dialog box.
559         createBookmarkFab.setOnClickListener(new View.OnClickListener() {
560             @Override
561             public void onClick(View view) {
562                 // Show the `CreateBookmarkDialog` `AlertDialog` and name the instance `@string/create_bookmark`.
563                 AppCompatDialogFragment createBookmarkDialog = new CreateBookmarkDialog();
564                 createBookmarkDialog.show(getSupportFragmentManager(), getResources().getString(R.string.create_bookmark));
565             }
566         });
567     }
568
569     @Override
570     public boolean onCreateOptionsMenu(Menu menu) {
571         // Inflate the menu.
572         getMenuInflater().inflate(R.menu.bookmarks_options_menu, menu);
573
574         // Success.
575         return true;
576     }
577
578     @Override
579     public boolean onOptionsItemSelected(MenuItem menuItem) {
580         // Get the ID of the `MenuItem` that was selected.
581         int menuItemId = menuItem.getItemId();
582
583         switch (menuItemId) {
584             case android.R.id.home:  // The home arrow is identified as `android.R.id.home`, not just `R.id.home`.
585                 if (currentFolder.isEmpty()) {  // Exit BookmarksActivity if currently in the home folder.
586                     NavUtils.navigateUpFromSameTask(this);
587                 } else {  // Navigate up one folder.
588                     // Place the former parent folder in `currentFolder`.
589                     currentFolder = bookmarksDatabaseHelper.getParentFolder(currentFolder);
590
591                     // Update `bookmarksListView`.
592                     updateBookmarksListView(currentFolder);
593                 }
594                 break;
595
596             case R.id.options_menu_select_all_bookmarks:
597                 int numberOfBookmarks = bookmarksListView.getCount();
598
599                 for (int i = 0; i < numberOfBookmarks; i++) {
600                     bookmarksListView.setItemChecked(i, true);
601                 }
602                 break;
603
604             case R.id.bookmarks_database_view:
605                 // Launch `BookmarksDatabaseViewActivity`.
606                 Intent bookmarksDatabaseViewIntent = new Intent(this, BookmarksDatabaseViewActivity.class);
607                 startActivity(bookmarksDatabaseViewIntent);
608                 break;
609         }
610         return true;
611     }
612
613     @Override
614     public void onBackPressed() {
615         if (currentFolder.isEmpty()) {  // Exit BookmarksActivity if currently in the home folder.
616             super.onBackPressed();
617         } else {  // Navigate up one folder.
618             // Place the former parent folder in `currentFolder`.
619             currentFolder = bookmarksDatabaseHelper.getParentFolder(currentFolder);
620
621             // Reload the `ListView`.
622             updateBookmarksListView(currentFolder);
623         }
624     }
625
626     @Override
627     public void onCreateBookmark(AppCompatDialogFragment dialogFragment) {
628         // Get the `EditTexts` from the `dialogFragment`.
629         EditText createBookmarkNameEditText = (EditText) dialogFragment.getDialog().findViewById(R.id.create_bookmark_name_edittext);
630         EditText createBookmarkUrlEditText = (EditText) dialogFragment.getDialog().findViewById(R.id.create_bookmark_url_edittext);
631
632         // Extract the strings from the `EditTexts`.
633         String bookmarkNameString = createBookmarkNameEditText.getText().toString();
634         String bookmarkUrlString = createBookmarkUrlEditText.getText().toString();
635
636         // Convert the favoriteIcon Bitmap to a byte array.
637         ByteArrayOutputStream favoriteIconByteArrayOutputStream = new ByteArrayOutputStream();
638         // `0` is for lossless compression (the only option for a PNG).
639         MainWebViewActivity.favoriteIconBitmap.compress(Bitmap.CompressFormat.PNG, 0, favoriteIconByteArrayOutputStream);
640         byte[] favoriteIconByteArray = favoriteIconByteArrayOutputStream.toByteArray();
641
642         // Display the new bookmark below the current items in the (0 indexed) list.
643         int newBookmarkDisplayOrder = bookmarksListView.getCount();
644
645         // Create the bookmark.
646         bookmarksDatabaseHelper.createBookmark(bookmarkNameString, bookmarkUrlString, newBookmarkDisplayOrder, currentFolder, favoriteIconByteArray);
647
648         // Refresh the `ListView`.  `setSelection` scrolls to the bottom of the list.
649         updateBookmarksListView(currentFolder);
650         bookmarksListView.setSelection(newBookmarkDisplayOrder);
651     }
652
653     @Override
654     public void onCreateBookmarkFolder(AppCompatDialogFragment dialogFragment) {
655         // Get `create_folder_name_edit_text` and extract the string.
656         EditText createFolderNameEditText = (EditText) dialogFragment.getDialog().findViewById(R.id.create_folder_name_edittext);
657         String folderNameString = createFolderNameEditText.getText().toString();
658
659         // Get the new folder icon `Bitmap`.
660         RadioButton defaultFolderIconRadioButton = (RadioButton) dialogFragment.getDialog().findViewById(R.id.create_folder_default_icon_radiobutton);
661         Bitmap folderIconBitmap;
662         if (defaultFolderIconRadioButton.isChecked()) {
663             // Get the default folder icon `ImageView` from the `Dialog` and convert it to a `Bitmap`.
664             ImageView folderIconImageView = (ImageView) dialogFragment.getDialog().findViewById(R.id.create_folder_default_icon);
665             Drawable folderIconDrawable = folderIconImageView.getDrawable();
666             BitmapDrawable folderIconBitmapDrawable = (BitmapDrawable) folderIconDrawable;
667             folderIconBitmap = folderIconBitmapDrawable.getBitmap();
668         } else {  // Assign `favoriteIcon` from the `WebView`.
669             folderIconBitmap = MainWebViewActivity.favoriteIconBitmap;
670         }
671
672         // Convert `folderIconBitmap` to a byte array.  `0` is for lossless compression (the only option for a PNG).
673         ByteArrayOutputStream folderIconByteArrayOutputStream = new ByteArrayOutputStream();
674         folderIconBitmap.compress(Bitmap.CompressFormat.PNG, 0, folderIconByteArrayOutputStream);
675         byte[] folderIconByteArray = folderIconByteArrayOutputStream.toByteArray();
676
677         // Move all the bookmarks down one in the display order.
678         for (int i = 0; i < bookmarksListView.getCount(); i++) {
679             int databaseId = (int) bookmarksListView.getItemIdAtPosition(i);
680             bookmarksDatabaseHelper.updateDisplayOrder(databaseId, i + 1);
681         }
682
683         // Create the folder, placing it at the top of the ListView
684         bookmarksDatabaseHelper.createFolder(folderNameString, 0, currentFolder, folderIconByteArray);
685
686         // Refresh the ListView.
687         updateBookmarksListView(currentFolder);
688     }
689
690     @Override
691     public void onSaveEditBookmark(AppCompatDialogFragment dialogFragment) {
692         // Get a long array with the the databaseId of the selected bookmark and convert it to an `int`.
693         long[] selectedBookmarksLongArray = bookmarksListView.getCheckedItemIds();
694         int selectedBookmarkDatabaseId = (int) selectedBookmarksLongArray[0];
695
696         // Get the `EditText`s from the `editBookmarkDialogFragment` and extract the strings.
697         EditText editBookmarkNameEditText = (EditText) dialogFragment.getDialog().findViewById(R.id.edit_bookmark_name_edittext);
698         String bookmarkNameString = editBookmarkNameEditText.getText().toString();
699         EditText editBookmarkUrlEditText = (EditText) dialogFragment.getDialog().findViewById(R.id.edit_bookmark_url_edittext);
700         String bookmarkUrlString = editBookmarkUrlEditText.getText().toString();
701
702         // Get `edit_bookmark_current_icon_radiobutton`.
703         RadioButton currentBookmarkIconRadioButton = (RadioButton) dialogFragment.getDialog().findViewById(R.id.edit_bookmark_current_icon_radiobutton);
704
705         if (currentBookmarkIconRadioButton.isChecked()) {  // Update the bookmark without changing the favorite icon.
706             bookmarksDatabaseHelper.updateBookmark(selectedBookmarkDatabaseId, bookmarkNameString, bookmarkUrlString);
707         } else {  // Update the bookmark using the `WebView` favorite icon.
708             ByteArrayOutputStream newFavoriteIconByteArrayOutputStream = new ByteArrayOutputStream();
709             MainWebViewActivity.favoriteIconBitmap.compress(Bitmap.CompressFormat.PNG, 0, newFavoriteIconByteArrayOutputStream);
710             byte[] newFavoriteIconByteArray = newFavoriteIconByteArrayOutputStream.toByteArray();
711
712             //  Update the bookmark and the favorite icon.
713             bookmarksDatabaseHelper.updateBookmark(selectedBookmarkDatabaseId, bookmarkNameString, bookmarkUrlString, newFavoriteIconByteArray);
714         }
715
716         // Close the contextual action mode.
717         contextualActionMode.finish();
718
719         // Refresh the `ListView`.  `setSelection` scrolls to the previous `ListView` position.
720         updateBookmarksListView(currentFolder);
721         bookmarksListView.setSelection(bookmarksListViewPosition);
722     }
723
724     @Override
725     public void onSaveEditBookmarkFolder(AppCompatDialogFragment dialogFragment) {
726         // Get the new folder name.
727         EditText editFolderNameEditText = (EditText) dialogFragment.getDialog().findViewById(R.id.edit_folder_name_edittext);
728         String newFolderNameString = editFolderNameEditText.getText().toString();
729
730         // Get a long array with the the database ID of the selected folder and convert it to an `int`.
731         long[] selectedFolderLongArray = bookmarksListView.getCheckedItemIds();
732         int selectedFolderDatabaseId = (int) selectedFolderLongArray[0];
733
734         // Get the `RadioButtons` from the `Dialog`.
735         RadioButton currentFolderIconRadioButton = (RadioButton) dialogFragment.getDialog().findViewById(R.id.edit_folder_current_icon_radiobutton);
736         RadioButton defaultFolderIconRadioButton = (RadioButton) dialogFragment.getDialog().findViewById(R.id.edit_folder_default_icon_radiobutton);
737
738         // Check if the favorite icon has changed.
739         if (currentFolderIconRadioButton.isChecked()) {  // Only the name has changed.
740             // Update the name in the database.
741             bookmarksDatabaseHelper.updateFolder(selectedFolderDatabaseId, oldFolderNameString, newFolderNameString);
742         } else if (!currentFolderIconRadioButton.isChecked() && newFolderNameString.equals(oldFolderNameString)) {  // Only the icon has changed.
743             // Get the new folder icon `Bitmap`.
744             Bitmap folderIconBitmap;
745             if (defaultFolderIconRadioButton.isChecked()) {
746                 // Get the default folder icon `ImageView` from the `Drawable` and convert it to a `Bitmap`.
747                 ImageView folderIconImageView = (ImageView) dialogFragment.getDialog().findViewById(R.id.edit_folder_default_icon);
748                 Drawable folderIconDrawable = folderIconImageView.getDrawable();
749                 BitmapDrawable folderIconBitmapDrawable = (BitmapDrawable) folderIconDrawable;
750                 folderIconBitmap = folderIconBitmapDrawable.getBitmap();
751             } else {  // Get the web page icon `ImageView` from the `Dialog`.
752                 folderIconBitmap = MainWebViewActivity.favoriteIconBitmap;
753             }
754
755             // Convert the folder `Bitmap` to a byte array.  `0` is for lossless compression (the only option for a PNG).
756             ByteArrayOutputStream folderIconByteArrayOutputStream = new ByteArrayOutputStream();
757             folderIconBitmap.compress(Bitmap.CompressFormat.PNG, 0, folderIconByteArrayOutputStream);
758             byte[] folderIconByteArray = folderIconByteArrayOutputStream.toByteArray();
759
760             // Update the folder icon in the database.
761             bookmarksDatabaseHelper.updateFolder(selectedFolderDatabaseId, folderIconByteArray);
762         } else {  // The folder icon and the name have changed.
763             // Get the new folder icon `Bitmap`.
764             Bitmap folderIconBitmap;
765             if (defaultFolderIconRadioButton.isChecked()) {
766                 // Get the default folder icon `ImageView` from the `Drawable` and convert it to a `Bitmap`.
767                 ImageView folderIconImageView = (ImageView) dialogFragment.getDialog().findViewById(R.id.edit_folder_default_icon);
768                 Drawable folderIconDrawable = folderIconImageView.getDrawable();
769                 BitmapDrawable folderIconBitmapDrawable = (BitmapDrawable) folderIconDrawable;
770                 folderIconBitmap = folderIconBitmapDrawable.getBitmap();
771             } else {  // Get the web page icon `ImageView` from the `Dialog`.
772                 folderIconBitmap = MainWebViewActivity.favoriteIconBitmap;
773             }
774
775             // Convert the folder `Bitmap` to a byte array.  `0` is for lossless compression (the only option for a PNG).
776             ByteArrayOutputStream folderIconByteArrayOutputStream = new ByteArrayOutputStream();
777             folderIconBitmap.compress(Bitmap.CompressFormat.PNG, 0, folderIconByteArrayOutputStream);
778             byte[] folderIconByteArray = folderIconByteArrayOutputStream.toByteArray();
779
780             // Update the folder name and icon in the database.
781             bookmarksDatabaseHelper.updateFolder(selectedFolderDatabaseId, oldFolderNameString, newFolderNameString, folderIconByteArray);
782         }
783
784         // Refresh the `ListView`.  `setSelection` scrolls to the previous `ListView` position.
785         updateBookmarksListView(currentFolder);
786         bookmarksListView.setSelection(bookmarksListViewPosition);
787
788         // Close the contextual action mode.
789         contextualActionMode.finish();
790     }
791
792     @Override
793     public void onMoveToFolder(AppCompatDialogFragment dialogFragment) {
794         // Get the new folder database id.
795         ListView folderListView = (ListView) dialogFragment.getDialog().findViewById(R.id.move_to_folder_listview);
796         long[] newFolderLongArray = folderListView.getCheckedItemIds();
797
798         // Get the new folder database ID.
799         int newFolderDatabaseId = (int) newFolderLongArray[0];
800
801         // Instantiate `newFolderName`.
802         String newFolderName;
803
804         if (newFolderDatabaseId == 0) {
805             // The new folder is the home folder, represented as `""` in the database.
806             newFolderName = "";
807         } else {
808             // Get the new folder name from the database.
809             newFolderName = bookmarksDatabaseHelper.getFolderName(newFolderDatabaseId);
810         }
811
812         // Get a long array with the the database ID of the selected bookmarks.
813         long[] selectedBookmarksLongArray = bookmarksListView.getCheckedItemIds();
814         for (long databaseIdLong : selectedBookmarksLongArray) {
815             // Get `databaseIdInt` for each selected bookmark.
816             int databaseIdInt = (int) databaseIdLong;
817
818             // Move the selected bookmark to the new folder.
819             bookmarksDatabaseHelper.moveToFolder(databaseIdInt, newFolderName);
820         }
821
822         // Refresh the `ListView`.
823         updateBookmarksListView(currentFolder);
824
825         // Close the contextual app bar.
826         contextualActionMode.finish();
827     }
828
829     private void updateBookmarksListView(String folderName) {
830         // Get a `Cursor` with the current contents of the bookmarks database.
831         bookmarksCursor = bookmarksDatabaseHelper.getAllBookmarksCursorByDisplayOrder(folderName);
832
833         // Setup `bookmarksCursorAdapter` with `this` context.  `false` disables `autoRequery`.
834         CursorAdapter bookmarksCursorAdapter = new CursorAdapter(this, bookmarksCursor, false) {
835             @Override
836             public View newView(Context context, Cursor cursor, ViewGroup parent) {
837                 // Inflate the individual item layout.  `false` does not attach it to the root.
838                 return getLayoutInflater().inflate(R.layout.bookmarks_item_linearlayout, parent, false);
839             }
840
841             @Override
842             public void bindView(View view, Context context, Cursor cursor) {
843                 // Get the favorite icon byte array from the `Cursor`.
844                 byte[] favoriteIconByteArray = cursor.getBlob(cursor.getColumnIndex(BookmarksDatabaseHelper.FAVORITE_ICON));
845
846                 // Convert the byte array to a `Bitmap` beginning at the first byte and ending at the last.
847                 Bitmap favoriteIconBitmap = BitmapFactory.decodeByteArray(favoriteIconByteArray, 0, favoriteIconByteArray.length);
848
849                 // Display the bitmap in `bookmarkFavoriteIcon`.
850                 ImageView bookmarkFavoriteIcon = (ImageView) view.findViewById(R.id.bookmark_favorite_icon);
851                 bookmarkFavoriteIcon.setImageBitmap(favoriteIconBitmap);
852
853
854                 // Get the bookmark name from the cursor and display it in `bookmarkNameTextView`.
855                 String bookmarkNameString = cursor.getString(cursor.getColumnIndex(BookmarksDatabaseHelper.BOOKMARK_NAME));
856                 TextView bookmarkNameTextView = (TextView) view.findViewById(R.id.bookmark_name);
857                 bookmarkNameTextView.setText(bookmarkNameString);
858
859                 // Make the font bold for folders.
860                 if (cursor.getInt(cursor.getColumnIndex(BookmarksDatabaseHelper.IS_FOLDER)) == 1) {
861                     bookmarkNameTextView.setTypeface(Typeface.DEFAULT_BOLD);
862                 } else {  // Reset the font to default for normal bookmarks.
863                     bookmarkNameTextView.setTypeface(Typeface.DEFAULT);
864                 }
865             }
866         };
867
868         // Update the ListView.
869         bookmarksListView.setAdapter(bookmarksCursorAdapter);
870
871         // Set the AppBar title.
872         if (currentFolder.isEmpty()) {
873             appBar.setTitle(R.string.bookmarks);
874         } else {
875             appBar.setTitle(currentFolder);
876         }
877     }
878
879     private void updateBookmarksListViewExcept(long[] exceptIdLongArray, String folderName) {
880         // Get a `Cursor` with the current contents of the bookmarks database except for the specified database IDs.
881         bookmarksCursor = bookmarksDatabaseHelper.getBookmarksCursorExcept(exceptIdLongArray, folderName);
882
883         // Setup `bookmarksCursorAdapter` with `this` context.  `false` disables autoRequery.
884         CursorAdapter bookmarksCursorAdapter = new CursorAdapter(this, bookmarksCursor, false) {
885             @Override
886             public View newView(Context context, Cursor cursor, ViewGroup parent) {
887                 // Inflate the individual item layout.  `false` does not attach it to the root.
888                 return getLayoutInflater().inflate(R.layout.bookmarks_item_linearlayout, parent, false);
889             }
890
891             @Override
892             public void bindView(View view, Context context, Cursor cursor) {
893                 // Get the favorite icon byte array from the cursor.
894                 byte[] favoriteIconByteArray = cursor.getBlob(cursor.getColumnIndex(BookmarksDatabaseHelper.FAVORITE_ICON));
895
896                 // Convert the byte array to a Bitmap beginning at the first byte and ending at the last.
897                 Bitmap favoriteIconBitmap = BitmapFactory.decodeByteArray(favoriteIconByteArray, 0, favoriteIconByteArray.length);
898
899                 // Display the bitmap in `bookmarkFavoriteIcon`.
900                 ImageView bookmarkFavoriteIcon = (ImageView) view.findViewById(R.id.bookmark_favorite_icon);
901                 bookmarkFavoriteIcon.setImageBitmap(favoriteIconBitmap);
902
903
904                 // Get the bookmark name from the cursor and display it in `bookmarkNameTextView`.
905                 String bookmarkNameString = cursor.getString(cursor.getColumnIndex(BookmarksDatabaseHelper.BOOKMARK_NAME));
906                 TextView bookmarkNameTextView = (TextView) view.findViewById(R.id.bookmark_name);
907                 bookmarkNameTextView.setText(bookmarkNameString);
908
909                 // Make the font bold for folders.
910                 if (cursor.getInt(cursor.getColumnIndex(BookmarksDatabaseHelper.IS_FOLDER)) == 1) {
911                     // The first argument is `null` because we don't want to change the font.
912                     bookmarkNameTextView.setTypeface(null, Typeface.BOLD);
913                 } else {  // Reset the font to default.
914                     bookmarkNameTextView.setTypeface(Typeface.DEFAULT);
915                 }
916             }
917         };
918
919         // Update the `ListView`.
920         bookmarksListView.setAdapter(bookmarksCursorAdapter);
921     }
922
923     private void deleteBookmarkFolderContents(int databaseId) {
924         // Get the name of the folder.
925         String folderName = bookmarksDatabaseHelper.getFolderName(databaseId);
926
927         // Get the contents of the folder.
928         Cursor folderCursor = bookmarksDatabaseHelper.getAllBookmarksCursorByDisplayOrder(folderName);
929
930         for (int i = 0; i < folderCursor.getCount(); i++) {
931             // Move `folderCursor` to the current row.
932             folderCursor.moveToPosition(i);
933
934             // Get the database ID of the item.
935             int itemDatabaseId = folderCursor.getInt(folderCursor.getColumnIndex(BookmarksDatabaseHelper._ID));
936
937             // If this is a folder, delete the contents first.
938             if (bookmarksDatabaseHelper.isFolder(itemDatabaseId)) {
939                 deleteBookmarkFolderContents(itemDatabaseId);
940             }
941
942             bookmarksDatabaseHelper.deleteBookmark(itemDatabaseId);
943         }
944     }
945 }