X-Git-Url: https://gitweb.stoutner.com/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Factivities%2FBookmarksActivity.java;h=cdd9049813c3bd9c6ec4665cc244057450b37e54;hb=65531f439c8cb610d0e3e0f1e4127dc4d8a006d5;hp=b6f9bc617c1902ae8f069ceb42d587bd7fd8792f;hpb=61a76e491469916f2f30aebb47b98cda7cceb557;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 b6f9bc61..cdd90498 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/BookmarksActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/BookmarksActivity.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2017 Soren Stoutner . + * Copyright © 2016-2017 Soren Stoutner . * * This file is part of Privacy Browser . * @@ -97,7 +97,17 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma @Override protected void onCreate(Bundle savedInstanceState) { + // Set the activity theme. + if (MainWebViewActivity.darkTheme) { + setTheme(R.style.PrivacyBrowserDark_SecondaryActivity); + } else { + setTheme(R.style.PrivacyBrowserLight_SecondaryActivity); + } + + // Run the default commands. super.onCreate(savedInstanceState); + + // Set the content view. setContentView(R.layout.bookmarks_coordinatorlayout); // We need to use the `SupportActionBar` from `android.support.v7.app.ActionBar` until the minimum API is >= 21. @@ -185,7 +195,7 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma editBookmarkMenuItem = menu.findItem(R.id.edit_bookmark); selectAllBookmarksMenuItem = menu.findItem(R.id.context_menu_select_all_bookmarks); - // Get a handle for `contextualActionMode` so we can close it programatically. + // Store `contextualActionMode` so we can close it programatically. contextualActionMode = mode; return true; @@ -225,19 +235,31 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma // Disable `moveBookmarkUpMenuItem` if the selected bookmark is at the top of the ListView. if (selectedBookmarkDatabaseId == firstBookmarkDatabaseId) { moveBookmarkUpMenuItem.setEnabled(false); - moveBookmarkUpMenuItem.setIcon(R.drawable.move_bookmark_up_disabled); + moveBookmarkUpMenuItem.setIcon(R.drawable.move_up_disabled); } else { // Otherwise enable `moveBookmarkUpMenuItem`. moveBookmarkUpMenuItem.setEnabled(true); - moveBookmarkUpMenuItem.setIcon(R.drawable.move_bookmark_up_enabled); + + // Set the icon according to the theme. + if (MainWebViewActivity.darkTheme) { + moveBookmarkUpMenuItem.setIcon(R.drawable.move_up_enabled_dark); + } else { + moveBookmarkUpMenuItem.setIcon(R.drawable.move_up_enabled_light); + } } // Disable `moveBookmarkDownMenuItem` if the selected bookmark is at the bottom of the ListView. if (selectedBookmarkDatabaseId == lastBookmarkDatabaseId) { moveBookmarkDownMenuItem.setEnabled(false); - moveBookmarkDownMenuItem.setIcon(R.drawable.move_bookmark_down_disabled); + moveBookmarkDownMenuItem.setIcon(R.drawable.move_down_disabled); } else { // Otherwise enable `moveBookmarkDownMenuItem`. moveBookmarkDownMenuItem.setEnabled(true); - moveBookmarkDownMenuItem.setIcon(R.drawable.move_bookmark_down_enabled); + + // Set the icon according to the theme. + if (MainWebViewActivity.darkTheme) { + moveBookmarkDownMenuItem.setIcon(R.drawable.move_down_enabled_dark); + } else { + moveBookmarkDownMenuItem.setIcon(R.drawable.move_down_enabled_light); + } } } else { // More than one bookmark is selected. // List the number of selected bookmarks in the subtitle. @@ -405,6 +427,7 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma // Scroll to where the deleted bookmark was located. bookmarksListView.setSelection(selectedBookmarkPosition - 5); + // Initialize `snackbarMessage`. String snackbarMessage; // Determine how many items are in the array and prepare an appropriate Snackbar message. @@ -425,31 +448,17 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma .addCallback(new Snackbar.Callback() { @Override public void onDismissed(Snackbar snackbar, int event) { - // Android Studio wants to see entries for every possible `Snackbar.Callback` even if they aren't used. switch (event) { - // The user pushed the "Undo" button. + // The user pushed the `Undo` button. case Snackbar.Callback.DISMISS_EVENT_ACTION: // Refresh the ListView to show the rows again. updateBookmarksListView(currentFolder); // Scroll to where the deleted bookmark was located. bookmarksListView.setSelection(selectedBookmarkPosition - 5); - break; - case Snackbar.Callback.DISMISS_EVENT_CONSECUTIVE: - // Do nothing and let the default behavior run. - - case Snackbar.Callback.DISMISS_EVENT_MANUAL: - // Do nothing and let the default behavior run. - - case Snackbar.Callback.DISMISS_EVENT_SWIPE: - // Do nothing and let the default behavior run. - - case Snackbar.Callback.DISMISS_EVENT_TIMEOUT: - // Do nothing and let the default behavior run. - - // The Snackbar was dismissed without the "Undo" button being pushed. + // The `Snackbar` was dismissed without the `Undo` button being pushed. default: // Delete each selected row. for (long databaseIdLong : selectedBookmarksLongArray) { @@ -505,32 +514,27 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma @Override public boolean onCreateOptionsMenu(Menu menu) { - //Inflate the menu. + // Inflate the menu. getMenuInflater().inflate(R.menu.bookmarks_options_menu, menu); - return true; - } - - @Override - public boolean onPrepareOptionsMenu(Menu menu) { - super.onPrepareOptionsMenu(menu); - + // Success. return true; } @Override public boolean onOptionsItemSelected(MenuItem menuItem) { + // Get the ID of the `MenuItem` that was selected. int menuItemId = menuItem.getItemId(); switch (menuItemId) { - case android.R.id.home: + case android.R.id.home: // The home arrow is identified as `android.R.id.home`, not just `R.id.home`. if (currentFolder.isEmpty()) { // Exit BookmarksActivity 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 BookmarksActivity if currently in the home folder. + // Update `bookmarksListView`. updateBookmarksListView(currentFolder); } break; @@ -584,7 +588,7 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma // Convert the favoriteIcon Bitmap to a byte array. ByteArrayOutputStream favoriteIconByteArrayOutputStream = new ByteArrayOutputStream(); // `0` is for lossless compression (the only option for a PNG). - MainWebViewActivity.favoriteIcon.compress(Bitmap.CompressFormat.PNG, 0, favoriteIconByteArrayOutputStream); + MainWebViewActivity.favoriteIconBitmap.compress(Bitmap.CompressFormat.PNG, 0, favoriteIconByteArrayOutputStream); byte[] favoriteIconByteArray = favoriteIconByteArrayOutputStream.toByteArray(); // Display the new bookmark below the current items in the (0 indexed) list. @@ -622,7 +626,7 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma BitmapDrawable folderIconBitmapDrawable = (BitmapDrawable) folderIconDrawable; folderIconBitmap = folderIconBitmapDrawable.getBitmap(); } else { // Assign `favoriteIcon` from the `WebView`. - folderIconBitmap = MainWebViewActivity.favoriteIcon; + folderIconBitmap = MainWebViewActivity.favoriteIconBitmap; } // Convert `folderIconBitmap` to a byte array. `0` is for lossless compression (the only option for a PNG). @@ -663,7 +667,7 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma bookmarksDatabaseHelper.updateBookmark(selectedBookmarkDatabaseId, bookmarkNameString, bookmarkUrlString); } else { // Update the bookmark using the `WebView` favorite icon. ByteArrayOutputStream newFavoriteIconByteArrayOutputStream = new ByteArrayOutputStream(); - MainWebViewActivity.favoriteIcon.compress(Bitmap.CompressFormat.PNG, 0, newFavoriteIconByteArrayOutputStream); + MainWebViewActivity.favoriteIconBitmap.compress(Bitmap.CompressFormat.PNG, 0, newFavoriteIconByteArrayOutputStream); byte[] newFavoriteIconByteArray = newFavoriteIconByteArrayOutputStream.toByteArray(); // Update the bookmark and the favorite icon. @@ -717,7 +721,7 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma BitmapDrawable folderIconBitmapDrawable = (BitmapDrawable) folderIconDrawable; folderIconBitmap = folderIconBitmapDrawable.getBitmap(); } else { // Get the web page icon `ImageView` from the `Dialog`. - folderIconBitmap = MainWebViewActivity.favoriteIcon; + folderIconBitmap = MainWebViewActivity.favoriteIconBitmap; } // Convert the folder `Bitmap` to a byte array. `0` is for lossless compression (the only option for a PNG).