From: Soren Stoutner Date: Wed, 16 May 2018 21:24:57 +0000 (-0700) Subject: Fix loading of bookmarks from the Bookmarks Activity. https://redmine.stoutner.com... X-Git-Tag: v2.10~2 X-Git-Url: https://gitweb.stoutner.com/?a=commitdiff_plain;h=897b2d7f61a0492f228e3c172d7c6a76e3c5f3ac;p=PrivacyBrowserAndroid.git Fix loading of bookmarks from the Bookmarks Activity. https://redmine.stoutner.com/issues/282 --- 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 763f6385..2f6738cd 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/BookmarksActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/BookmarksActivity.java @@ -153,21 +153,24 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma // Convert the id from long to int to match the format of the bookmarks database. int databaseID = (int) id; - // Get the bookmark `Cursor` for this ID and move it to the first row. + // Get the bookmark cursor for this ID and move it to the first row. Cursor bookmarkCursor = bookmarksDatabaseHelper.getBookmarkCursor(databaseID); bookmarkCursor.moveToFirst(); // Act upon the bookmark according to the type. if (bookmarkCursor.getInt(bookmarkCursor.getColumnIndex(BookmarksDatabaseHelper.IS_FOLDER)) == 1) { // The selected bookmark is a folder. - // Update `currentFolder`. + // Update the current folder. currentFolder = bookmarkCursor.getString(bookmarkCursor.getColumnIndex(BookmarksDatabaseHelper.BOOKMARK_NAME)); // Load the new folder. loadFolder(); } else { // The selected bookmark is not a folder. - // Get the bookmark URL and assign it to `formattedUrlString`. `mainWebView` will automatically reload when `BookmarksActivity` closes. + // Get the bookmark URL and assign it to `formattedUrlString`. MainWebViewActivity.formattedUrlString = bookmarkCursor.getString(bookmarkCursor.getColumnIndex(BookmarksDatabaseHelper.BOOKMARK_URL)); + // Set `MainWebViewActivity` to load the new URL on restart. + MainWebViewActivity.loadUrlOnRestart = true; + // Update the bookmarks folder for the bookmarks drawer in `MainWebViewActivity`. MainWebViewActivity.currentBookmarksFolder = currentFolder; diff --git a/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java b/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java index 968e897c..e76e3e8f 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java @@ -184,7 +184,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook // `reloadOnRestart` is public static so it can be accessed from `SettingsFragment`. It is also used in `onRestart()` public static boolean reloadOnRestart; - // `reloadUrlOnRestart` is public static so it can be accessed from `SettingsFragment`. It is also used in `onRestart()`. + // `reloadUrlOnRestart` is public static so it can be accessed from `SettingsFragment` and `BookmarksActivity`. It is also used in `onRestart()`. public static boolean loadUrlOnRestart; // `restartFromBookmarksActivity` is public static so it can be accessed from `BookmarksActivity`. It is also used in `onRestart()`. @@ -213,7 +213,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook public static Date pinnedDomainSslStartDate; public static Date pinnedDomainSslEndDate; - // The user agent constants are public static so they can be accessed from `SettingsActivity` and `DomainsActivity`. + // The user agent constants are public static so they can be accessed from `SettingsFragment`, `DomainsActivity`, and `DomainSettingsFragment`. public final static int UNRECOGNIZED_USER_AGENT = -1; public final static int SETTINGS_WEBVIEW_DEFAULT_USER_AGENT = 1; public final static int SETTINGS_CUSTOM_USER_AGENT = 12; @@ -221,6 +221,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook public final static int DOMAINS_WEBVIEW_DEFAULT_USER_AGENT = 2; public final static int DOMAINS_CUSTOM_USER_AGENT = 13; + // `appBar` is used in `onCreate()`, `onOptionsItemSelected()`, `closeFindOnPage()`, and `applyAppSettings()`. private ActionBar appBar; @@ -576,14 +577,14 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook startActivity(bookmarksIntent); }); - // Set the create new bookmark folder FAB to display the `AlertDialog`. + // Set the create new bookmark folder FAB to display an alert dialog. createBookmarkFolderFab.setOnClickListener(v -> { // Show the `CreateBookmarkFolderDialog` `AlertDialog` and name the instance `@string/create_folder`. AppCompatDialogFragment createBookmarkFolderDialog = new CreateBookmarkFolderDialog(); createBookmarkFolderDialog.show(getSupportFragmentManager(), getResources().getString(R.string.create_folder)); }); - // Set the create new bookmark FAB to display the `AlertDialog`. + // Set the create new bookmark FAB to display an alert dialog. createBookmarkFab.setOnClickListener(view -> { // Show the `CreateBookmarkDialog` `AlertDialog` and name the instance `@string/create_bookmark`. AppCompatDialogFragment createBookmarkDialog = new CreateBookmarkDialog(); @@ -766,7 +767,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook // Convert the id from long to int to match the format of the bookmarks database. int databaseID = (int) id; - // Get the bookmark `Cursor` for this ID and move it to the first row. + // Get the bookmark cursor for this ID and move it to the first row. Cursor bookmarkCursor = bookmarksDatabaseHelper.getBookmarkCursor(databaseID); bookmarkCursor.moveToFirst(); @@ -3715,7 +3716,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook } private void loadBookmarksFolder() { - // Update `bookmarksCursor` with the contents of the bookmarks database for the current folder. + // Update the bookmarks cursor with the contents of the bookmarks database for the current folder. bookmarksCursor = bookmarksDatabaseHelper.getAllBookmarksCursorByDisplayOrder(currentBookmarksFolder); // Populate the bookmarks cursor adapter. `this` specifies the `Context`. `false` disables `autoRequery`. @@ -3732,7 +3733,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook ImageView bookmarkFavoriteIcon = view.findViewById(R.id.bookmark_favorite_icon); TextView bookmarkNameTextView = view.findViewById(R.id.bookmark_name); - // Get the favorite icon byte array from the `Cursor`. + // Get the favorite icon byte array from the cursor. byte[] favoriteIconByteArray = cursor.getBlob(cursor.getColumnIndex(BookmarksDatabaseHelper.FAVORITE_ICON)); // Convert the byte array to a `Bitmap` beginning at the first byte and ending at the last.