- private fun prepareFinish() {
- // 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.
- if ((bookmarksDeletedSnackbar != null) && bookmarksDeletedSnackbar!!.isShown) { // Close the bookmarks deleted snackbar before going home.
- // Set the close flag.
- closeActivityAfterDismissingSnackbar = true
-
- // Dismiss the snackbar.
- bookmarksDeletedSnackbar!!.dismiss()
- } else { // Go home immediately.
- // Update the current folder in the bookmarks activity.
- 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.
- BookmarksActivity.restartFromBookmarksDatabaseViewActivity = true
-
- // Exit the bookmarks database view activity.
- finish()
- }
- }
-
- private fun updateBookmarksListView() {
- // Populate the bookmarks list view based on the spinner selection.
- bookmarksCursor = when (currentFolderDatabaseId) {
- // Get all the bookmarks.
- ALL_FOLDERS_DATABASE_ID ->
- if (sortByDisplayOrder)
- bookmarksDatabaseHelper.allBookmarksByDisplayOrder
- else
- bookmarksDatabaseHelper.allBookmarks
-
- // Get the bookmarks in the current folder.
- HOME_FOLDER_DATABASE_ID ->
- if (sortByDisplayOrder)
- bookmarksDatabaseHelper.getBookmarksByDisplayOrder("")
- else
- bookmarksDatabaseHelper.getBookmarks("")
-
- // Get the bookmarks in the specified folder.
- else ->
- if (sortByDisplayOrder)
- bookmarksDatabaseHelper.getBookmarksByDisplayOrder(currentFolderName)
- else
- bookmarksDatabaseHelper.getBookmarks(currentFolderName)
- }
-
- // Update the cursor adapter if it isn't null, which happens when the activity is restarted.
- if (bookmarksCursorAdapter != null) {
- bookmarksCursorAdapter!!.changeCursor(bookmarksCursor)
- }
- }
-
- private fun selectAllBookmarksInFolder(folderId: Int) {
- // Get the folder name.
- val folderName = bookmarksDatabaseHelper.getFolderName(folderId)
-
- // Get a cursor with the contents of the folder.
- val folderCursor = bookmarksDatabaseHelper.getBookmarks(folderName)
-
- // Move to the beginning of the cursor.
- folderCursor.moveToFirst()
-
- while (folderCursor.position < folderCursor.count) {
- // Get the bookmark database ID.
- val bookmarkId = folderCursor.getInt(folderCursor.getColumnIndexOrThrow(BookmarksDatabaseHelper.ID))
-
- // Move the bookmarks cursor to the first position.
- bookmarksCursor.moveToFirst()
-
- // Initialize the bookmark position variable.
- var bookmarkPosition = -1
-
- // Get the position of this bookmark in the bookmarks cursor.
- while ((bookmarkPosition < 0) && (bookmarksCursor.position < bookmarksCursor.count)) {
- // Check if the bookmark IDs match.
- if (bookmarkId == bookmarksCursor.getInt(bookmarksCursor.getColumnIndexOrThrow(BookmarksDatabaseHelper.ID))) {
- // Get the bookmark position.
- bookmarkPosition = bookmarksCursor.position
-
- // If this bookmark is a folder, select all the bookmarks inside it.
- if (bookmarksDatabaseHelper.isFolder(bookmarkId))
- selectAllBookmarksInFolder(bookmarkId)
-
- // Select the bookmark.
- bookmarksListView.setItemChecked(bookmarkPosition, true)
- }
-
- // Increment the bookmarks cursor position.
- bookmarksCursor.moveToNext()
- }
-
- // Move to the next position.
- folderCursor.moveToNext()
- }
- }
-
- override fun onSaveBookmark(dialogFragment: DialogFragment, selectedBookmarkDatabaseId: Int, favoriteIconBitmap: Bitmap) {