]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/commitdiff
Persist the current bookmarks folder on restart. https://redmine.stoutner.com/issues/806
authorSoren Stoutner <soren@stoutner.com>
Fri, 15 Jul 2022 23:40:46 +0000 (16:40 -0700)
committerSoren Stoutner <soren@stoutner.com>
Fri, 15 Jul 2022 23:40:46 +0000 (16:40 -0700)
app/src/main/java/com/stoutner/privacybrowser/activities/BookmarksActivity.java
app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java

index 932f01d3b95850cafe912afd581f6a60426bd9dd..905a98d004df241e1e8c129df5bf7ef296ce0d93 100644 (file)
@@ -71,15 +71,13 @@ import java.util.ArrayList;
 public class BookmarksActivity extends AppCompatActivity implements CreateBookmarkDialog.CreateBookmarkListener, CreateBookmarkFolderDialog.CreateBookmarkFolderListener, EditBookmarkDialog.EditBookmarkListener,
         EditBookmarkFolderDialog.EditBookmarkFolderListener, MoveToFolderDialog.MoveToFolderListener {
 
 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;
     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;
 
     public static boolean restartFromBookmarksDatabaseViewActivity;
 
-
     // Define the saved instance state constants.
     private final String CHECKED_BOOKMARKS_ARRAY_LIST = "checked_bookmarks_array_list";
     // 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;
 
     // Define the class menu items.
     private MenuItem moveBookmarkUpMenuItem;
@@ -189,9 +187,6 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma
         // Initialize the database helper.
         bookmarksDatabaseHelper = new BookmarksDatabaseHelper(this);
 
         // Initialize the database helper.
         bookmarksDatabaseHelper = new BookmarksDatabaseHelper(this);
 
-        // Load the home folder.
-        loadFolder();
-
         // Set a listener so that tapping a list item loads the URL or folder.
         bookmarksListView.setOnItemClickListener((parent, view, position, id) -> {
             // Convert the id from long to int to match the format of the bookmarks database.
         // Set a listener so that tapping a list item loads the URL or folder.
         bookmarksListView.setOnItemClickListener((parent, view, position, id) -> {
             // Convert the id from long to int to match the format of the bookmarks database.
@@ -614,6 +609,9 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma
 
         // Restore the state if the app has been restarted.
         if (savedInstanceState != null) {
 
         // 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.
             // Update the bookmarks list view after it has loaded.
             bookmarksListView.post(() -> {
                 // Get the checked bookmarks array list.
@@ -627,6 +625,9 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma
                 }
             });
         }
                 }
             });
         }
+
+        // Load the home folder.
+        loadFolder();
     }
 
     @Override
     }
 
     @Override
@@ -664,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);
     }
 
         savedInstanceState.putIntegerArrayList(CHECKED_BOOKMARKS_ARRAY_LIST, checkedBookmarksArrayList);
     }
 
index e54b06874012b660e9785aec2c652127f856262f..c2d169b40b7ee0d0ebdad343e352b672d3d469ab 100644 (file)
@@ -197,7 +197,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook
     public static String proxyMode = ProxyHelper.NONE;
 
     // Declare the public static variables.
     public static String proxyMode = ProxyHelper.NONE;
 
     // Declare the public static variables.
-    public static String currentBookmarksFolder;
+    public static String currentBookmarksFolder = "";
     public static boolean restartFromBookmarksActivity;
     public static WebViewPagerAdapter webViewPagerAdapter;
 
     public static boolean restartFromBookmarksActivity;
     public static WebViewPagerAdapter webViewPagerAdapter;
 
@@ -3379,12 +3379,10 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook
         drawerLayout.setDrawerTitle(GravityCompat.START, getString(R.string.navigation_drawer));
         drawerLayout.setDrawerTitle(GravityCompat.END, getString(R.string.bookmarks));
 
         drawerLayout.setDrawerTitle(GravityCompat.START, getString(R.string.navigation_drawer));
         drawerLayout.setDrawerTitle(GravityCompat.END, getString(R.string.bookmarks));
 
-        // Initialize `currentBookmarksFolder`.  `""` is the home folder in the database.
-        currentBookmarksFolder = "";
-
-        // Load the home folder, which is `""` in the database.
+        // Load the bookmarks folder.
         loadBookmarksFolder();
 
         loadBookmarksFolder();
 
+        // Handle clicks on bookmarks.
         bookmarksListView.setOnItemClickListener((parent, view, position, id) -> {
             // Convert the id from long to int to match the format of the bookmarks database.
             int databaseId = (int) id;
         bookmarksListView.setOnItemClickListener((parent, view, position, id) -> {
             // Convert the id from long to int to match the format of the bookmarks database.
             int databaseId = (int) id;