X-Git-Url: https://gitweb.stoutner.com/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Factivities%2FBookmarks.java;h=5c059ec0820b3e5300a9530e0ded035e3c6a968f;hb=5f42cf731a90231386ea4757c6a8964a48da042e;hp=78cb806e6c17085bb865a7f35f5dcb631a1e6e37;hpb=3bd71cebfddb14b7adcbb39c5ab98f9ce90f8d9d;p=PrivacyBrowserAndroid.git diff --git a/app/src/main/java/com/stoutner/privacybrowser/activities/Bookmarks.java b/app/src/main/java/com/stoutner/privacybrowser/activities/Bookmarks.java index 78cb806e..5c059ec0 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/Bookmarks.java +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/Bookmarks.java @@ -107,12 +107,11 @@ public class Bookmarks extends AppCompatActivity implements CreateBookmark.Creat // Display the home arrow on `SupportActionBar`. appBar = getSupportActionBar(); - assert appBar != null;// This assert removes the incorrect warning in Android Studio on the following line that appBar might be null. + assert appBar != null;// This assert removes the incorrect warning in Android Studio on the following line that `appBar` might be null. appBar.setDisplayHomeAsUpEnabled(true); - // Initialize the database handler and the ListView. - // `this` specifies the context. The two `null`s do not specify the database name or a `CursorFactory`. + // Initialize the database handler and the ListView. `this` specifies the context. The two `null`s do not specify the database name or a `CursorFactory`. // The `0` is to specify a database version, but that is set instead using a constant in `BookmarksDatabaseHelper`. bookmarksDatabaseHelper = new BookmarksDatabaseHelper(this, null, null, 0); bookmarksListView = (ListView) findViewById(R.id.bookmarks_listview); @@ -123,8 +122,7 @@ public class Bookmarks extends AppCompatActivity implements CreateBookmark.Creat // Display the bookmarks in the ListView. updateBookmarksListView(currentFolder); - // 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. + // 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. final Activity bookmarksActivity = this; bookmarksListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override @@ -523,13 +521,13 @@ public class Bookmarks extends AppCompatActivity implements CreateBookmark.Creat switch (menuItemId) { case android.R.id.home: - // Exit Bookmarks if currently at the home folder. - if (currentFolder.isEmpty()) { + if (currentFolder.isEmpty()) { // Exit Bookmarks if currently in the home folder. NavUtils.navigateUpFromSameTask(this); } else { // Navigate up one folder. // Place the former parent folder in `currentFolder`. currentFolder = bookmarksDatabaseHelper.getParentFolder(currentFolder); + // Exit Bookmarks if currently in the home folder. updateBookmarksListView(currentFolder); } break; @@ -557,6 +555,19 @@ public class Bookmarks extends AppCompatActivity implements CreateBookmark.Creat return true; } + @Override + public void onBackPressed() { + if (currentFolder.isEmpty()) { // Exit Bookmarks if currently in the home folder. + super.onBackPressed(); + } else { // Navigate up one folder. + // Place the former parent folder in `currentFolder`. + currentFolder = bookmarksDatabaseHelper.getParentFolder(currentFolder); + + // Reload the `ListView`. + updateBookmarksListView(currentFolder); + } + } + @Override public void onCreateBookmark(AppCompatDialogFragment dialogFragment) { // Get the `EditText`s from the `createBookmarkDialogFragment` and extract the strings.