X-Git-Url: https://gitweb.stoutner.com/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Factivities%2FBookmarksActivity.java;h=905a98d004df241e1e8c129df5bf7ef296ce0d93;hb=c45c0fa64109c47bdc35328d0e31a65c685bdc22;hp=cea440a4239b0eb78f9bbf60c2ea856240e49a5c;hpb=1b27ac6f2b7c046945fc97e2aff9adbde8a152ce;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 cea440a4..905a98d0 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/BookmarksActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/BookmarksActivity.java @@ -71,15 +71,13 @@ 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 `BookmarksDatabaseViewActivity`. + // Declare the public static variables, which are accessed from the bookmarks database view activity. public static String currentFolder; - - // `restartFromBookmarksDatabaseViewActivity` is public static so it can be accessed from `BookmarksDatabaseViewActivity`. It is also used in `onRestart()`. public static boolean restartFromBookmarksDatabaseViewActivity; - // Define the saved instance state constants. private final String CHECKED_BOOKMARKS_ARRAY_LIST = "checked_bookmarks_array_list"; + private final String CURRENT_FOLDER = "current_folder"; // Define the class menu items. private MenuItem moveBookmarkUpMenuItem; @@ -132,9 +130,6 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE); } - // Set the theme. - setTheme(R.style.PrivacyBrowser); - // Run the default commands. super.onCreate(savedInstanceState); @@ -189,12 +184,8 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma // Display the home arrow on the app bar. appBar.setDisplayHomeAsUpEnabled(true); - // Initialize the database helper. `this` specifies the context. The two `nulls` do not specify the database name or a `CursorFactory`. - // The `0` specifies a database version, but that is ignored and set instead using a constant in `BookmarksDatabaseHelper`. - bookmarksDatabaseHelper = new BookmarksDatabaseHelper(this, null, null, 0); - - // Load the home folder. - loadFolder(); + // Initialize the database helper. + bookmarksDatabaseHelper = new BookmarksDatabaseHelper(this); // Set a listener so that tapping a list item loads the URL or folder. bookmarksListView.setOnItemClickListener((parent, view, position, id) -> { @@ -451,7 +442,7 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma boolean isFolder = (bookmarksCursor.getInt(bookmarksCursor.getColumnIndexOrThrow(BookmarksDatabaseHelper.IS_FOLDER)) == 1); // Get the selected bookmark database ID. - int databaseId = bookmarksCursor.getInt(bookmarksCursor.getColumnIndexOrThrow(BookmarksDatabaseHelper._ID)); + int databaseId = bookmarksCursor.getInt(bookmarksCursor.getColumnIndexOrThrow(BookmarksDatabaseHelper.ID)); // Show the edit bookmark or edit bookmark folder dialog. if (isFolder) { @@ -618,6 +609,9 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma // Restore the state if the app has been restarted. if (savedInstanceState != null) { + // Restore the current folder. + currentFolder = savedInstanceState.getString(CURRENT_FOLDER); + // Update the bookmarks list view after it has loaded. bookmarksListView.post(() -> { // Get the checked bookmarks array list. @@ -631,6 +625,9 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma } }); } + + // Load the home folder. + loadFolder(); } @Override @@ -668,7 +665,8 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma } } - // Store the checked items array list in the saved instance state. + // Store the variables in the saved instance state. + savedInstanceState.putString(CURRENT_FOLDER, currentFolder); savedInstanceState.putIntegerArrayList(CHECKED_BOOKMARKS_ARRAY_LIST, checkedBookmarksArrayList); } @@ -1055,7 +1053,7 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma folderCursor.moveToPosition(i); // Get the database ID of the item. - int itemDatabaseId = folderCursor.getInt(folderCursor.getColumnIndexOrThrow(BookmarksDatabaseHelper._ID)); + int itemDatabaseId = folderCursor.getInt(folderCursor.getColumnIndexOrThrow(BookmarksDatabaseHelper.ID)); // If this is a folder, recursively count the contents first. if (bookmarksDatabaseHelper.isFolder(itemDatabaseId)) { @@ -1084,7 +1082,7 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma folderCursor.moveToPosition(i); // Get the database ID of the item. - int itemDatabaseId = folderCursor.getInt(folderCursor.getColumnIndexOrThrow(BookmarksDatabaseHelper._ID)); + int itemDatabaseId = folderCursor.getInt(folderCursor.getColumnIndexOrThrow(BookmarksDatabaseHelper.ID)); // If this is a folder, recursively delete the contents first. if (bookmarksDatabaseHelper.isFolder(itemDatabaseId)) {