From: Soren Stoutner Date: Tue, 12 Jul 2016 18:48:13 +0000 (-0700) Subject: Add the ability to select all bookmarks. X-Git-Tag: v1.8~4 X-Git-Url: https://gitweb.stoutner.com/?a=commitdiff_plain;h=bf644cc5270aca79529a87f19cbd04d3f5313f32;p=PrivacyBrowserAndroid.git Add the ability to select all bookmarks. --- diff --git a/app/build.gradle b/app/build.gradle index 9b770e4e..8b0f695b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -54,6 +54,6 @@ android { dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:design:23.4.0' - // Only compile com.google.android.gms:play-services-ads for the free version. - freeCompile 'com.google.android.gms:play-services-ads:9.2.0' + // Only compile `com.google.android.gms:play-services-ads` for the free flavor. + freeCompile 'com.google.android.gms:play-services-ads:9.2.1' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 246393e9..17fb93ab 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -49,7 +49,6 @@ @@ -86,7 +85,7 @@ diff --git a/app/src/main/assets/about_licenses.html b/app/src/main/assets/about_licenses.html index 6ff69285..bb6fa1a2 100644 --- a/app/src/main/assets/about_licenses.html +++ b/app/src/main/assets/about_licenses.html @@ -80,6 +80,8 @@

ic_edit.

ic_download.

+ +

ic_select_all


GNU General Public License

diff --git a/app/src/main/assets/images/ic_select_all.png b/app/src/main/assets/images/ic_select_all.png new file mode 100644 index 00000000..92aab4e2 Binary files /dev/null and b/app/src/main/assets/images/ic_select_all.png differ diff --git a/app/src/main/java/com/stoutner/privacybrowser/BookmarksActivity.java b/app/src/main/java/com/stoutner/privacybrowser/BookmarksActivity.java index 108dcc04..b6e67c89 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/BookmarksActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/BookmarksActivity.java @@ -108,14 +108,18 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma // `editBookmarkMenuItem` is used in `onCreateActionMode()` and `onItemCheckedStateChanged`. MenuItem editBookmarkMenuItem; + // `selectAllBookmarks` is used in `onCreateActionMode()` and `onItemCheckedStateChanges`. + MenuItem selectAllBookmarks; + @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { // Inflate the menu for the contextual app bar and set the title. getMenuInflater().inflate(R.menu.bookmarks_context_menu, menu); mode.setTitle(R.string.bookmarks); - // Get a handle for `R.id.edit_bookmark`. + // Get a handle for `R.id.edit_bookmark` and `R.id.select_all_bookmarks`. editBookmarkMenuItem = menu.findItem(R.id.edit_bookmark); + selectAllBookmarks = menu.findItem(R.id.context_menu_select_all_bookmarks); return true; } @@ -137,11 +141,18 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma mode.setSubtitle(numberOfSelectedBookmarks + " " + getString(R.string.selected)); // Show the `Edit` option only if 1 bookmark is selected. - if (numberOfSelectedBookmarks == 1) { + if (numberOfSelectedBookmarks < 2) { editBookmarkMenuItem.setVisible(true); } else { editBookmarkMenuItem.setVisible(false); } + + // Do not show `Select All` if all the bookmarks are already checked. + if (bookmarksListView.getCheckedItemIds().length == bookmarksListView.getCount()) { + selectAllBookmarks.setVisible(false); + } else { + selectAllBookmarks.setVisible(true); + } } @Override @@ -210,6 +221,14 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma // Close the contextual app bar. mode.finish(); break; + + case R.id.context_menu_select_all_bookmarks: + int numberOfBookmarks = bookmarksListView.getCount(); + + for (int i = 0; i < numberOfBookmarks; i++) { + bookmarksListView.setItemChecked(i, true); + } + break; } // Consume the click. return true; @@ -234,6 +253,41 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma }); } + @Override + public boolean onCreateOptionsMenu(Menu menu) { + //Inflate the menu. + getMenuInflater().inflate(R.menu.bookmarks_options_menu, menu); + + return true; + } + + @Override + public boolean onPrepareOptionsMenu(Menu menu) { + super.onPrepareOptionsMenu(menu); + + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem menuItem) { + int menuItemId = menuItem.getItemId(); + + switch (menuItemId) { + case android.R.id.home: + NavUtils.navigateUpFromSameTask(this); + break; + + case R.id.options_menu_select_all_bookmarks: + int numberOfBookmarks = bookmarksListView.getCount(); + + for (int i = 0; i < numberOfBookmarks; i++) { + bookmarksListView.setItemChecked(i, true); + } + break; + } + return true; + } + @Override public void onCreateBookmarkCancel(DialogFragment createBookmarkDialogFragment) { // Do nothing because the user selected `Cancel`. diff --git a/app/src/main/java/com/stoutner/privacybrowser/CreateBookmark.java b/app/src/main/java/com/stoutner/privacybrowser/CreateBookmark.java index 64714358..c5acd035 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/CreateBookmark.java +++ b/app/src/main/java/com/stoutner/privacybrowser/CreateBookmark.java @@ -62,7 +62,7 @@ public class CreateBookmark extends DialogFragment { Drawable favoriteIconDrawable = new BitmapDrawable(getResources(), MainWebViewActivity.favoriteIcon); // Use `AlertDialog.Builder` to create the `AlertDialog`. The style formats the color of the button text. - AlertDialog.Builder createBookmarkDialogBuilder = new AlertDialog.Builder(getActivity(), R.style.PrivacyBrowser_AlertDialog); + AlertDialog.Builder createBookmarkDialogBuilder = new AlertDialog.Builder(getActivity(), R.style.LightAlertDialog); createBookmarkDialogBuilder.setTitle(R.string.create_bookmark); createBookmarkDialogBuilder.setIcon(favoriteIconDrawable); // The parent view is `null` because it will be assigned by `AlertDialog`. diff --git a/app/src/main/java/com/stoutner/privacybrowser/CreateHomeScreenShortcut.java b/app/src/main/java/com/stoutner/privacybrowser/CreateHomeScreenShortcut.java index ea225ca3..71e84ab3 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/CreateHomeScreenShortcut.java +++ b/app/src/main/java/com/stoutner/privacybrowser/CreateHomeScreenShortcut.java @@ -64,7 +64,7 @@ public class CreateHomeScreenShortcut extends DialogFragment { LayoutInflater customDialogInflater = getActivity().getLayoutInflater(); // Use AlertDialog.Builder to create the AlertDialog. The style formats the color of the button text. - AlertDialog.Builder createHomeScreenShorcutDialogBuilder = new AlertDialog.Builder(getActivity(), R.style.PrivacyBrowser_AlertDialog); + AlertDialog.Builder createHomeScreenShorcutDialogBuilder = new AlertDialog.Builder(getActivity(), R.style.LightAlertDialog); createHomeScreenShorcutDialogBuilder.setTitle(R.string.create_shortcut); createHomeScreenShorcutDialogBuilder.setIcon(favoriteIconDrawable); // The parent view is "null" because it will be assigned by AlertDialog. diff --git a/app/src/main/java/com/stoutner/privacybrowser/EditBookmark.java b/app/src/main/java/com/stoutner/privacybrowser/EditBookmark.java index 27d522b8..8eee58d6 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/EditBookmark.java +++ b/app/src/main/java/com/stoutner/privacybrowser/EditBookmark.java @@ -77,7 +77,7 @@ public class EditBookmark extends DialogFragment { Drawable favoriteIconDrawable = new BitmapDrawable(getResources(), favoriteIconBitmap); // Use `AlertDialog.Builder` to create the `AlertDialog`. The style formats the color of the button text. - AlertDialog.Builder editBookmarkDialogBuilder = new AlertDialog.Builder(getActivity(), R.style.PrivacyBrowser_AlertDialog); + AlertDialog.Builder editBookmarkDialogBuilder = new AlertDialog.Builder(getActivity(), R.style.LightAlertDialog); editBookmarkDialogBuilder.setTitle(R.string.edit_bookmark); editBookmarkDialogBuilder.setIcon(favoriteIconDrawable); // The parent view is `null` because it will be assigned by `AlertDialog`. diff --git a/app/src/main/res/drawable/select_all.xml b/app/src/main/res/drawable/select_all.xml new file mode 100644 index 00000000..24205a5b --- /dev/null +++ b/app/src/main/res/drawable/select_all.xml @@ -0,0 +1,14 @@ + + + + + + diff --git a/app/src/main/res/layout/about_coordinatorlayout.xml b/app/src/main/res/layout/about_coordinatorlayout.xml index 46fe2497..a0d221e6 100644 --- a/app/src/main/res/layout/about_coordinatorlayout.xml +++ b/app/src/main/res/layout/about_coordinatorlayout.xml @@ -41,7 +41,7 @@ android:layout_height="wrap_content" android:layout_width="match_parent" android:background="@color/blue" - android:theme="@style/PrivacyBrowser.AppBarOverlay" > + android:theme="@style/AppBarOverlay" > + android:theme="@style/DarkAppBar" + app:popupTheme="@style/LightPopupOverlay" /> + android:theme="@style/AppBarOverlay" > + android:theme="@style/DarkAppBar" + app:popupTheme="@style/LightPopupOverlay" /> + android:theme="@style/DarkAppBar" + app:popupTheme="@style/LightPopupOverlay" /> + android:theme="@style/AppBarOverlay" > + app:popupTheme="@style/LightPopupOverlay" /> diff --git a/app/src/main/res/menu/bookmarks_context_menu.xml b/app/src/main/res/menu/bookmarks_context_menu.xml index 6b2fc748..98b790ad 100644 --- a/app/src/main/res/menu/bookmarks_context_menu.xml +++ b/app/src/main/res/menu/bookmarks_context_menu.xml @@ -35,4 +35,11 @@ android:orderInCategory="20" android:icon="@drawable/delete" app:showAsAction="ifRoom" /> + + \ No newline at end of file diff --git a/app/src/main/res/menu/bookmarks_options_menu.xml b/app/src/main/res/menu/bookmarks_options_menu.xml new file mode 100644 index 00000000..856594ce --- /dev/null +++ b/app/src/main/res/menu/bookmarks_options_menu.xml @@ -0,0 +1,31 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/menu/menu_bookmarks_options.xml b/app/src/main/res/menu/menu_bookmarks_options.xml deleted file mode 100644 index 97d6487b..00000000 --- a/app/src/main/res/menu/menu_bookmarks_options.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5b5ad90d..69424458 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -82,6 +82,7 @@ Selected Edit Delete + Select All 1 Bookmark Deleted Bookmarks Deleted Undo diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 0b1697e7..25ca3a0d 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -26,35 +26,31 @@ @color/blue - - - - \ No newline at end of file