Bug 1312467 - Hide some items for TopSites context menu r=sebastian
authorAndrzej Hunt <ahunt@mozilla.com>
Mon, 31 Oct 2016 15:42:44 +0100
changeset 346984 a9f1a369aa956e40bca3f7fe5fcbd2138dd6f044
parent 346983 9f65ac29fa2447c4a590dd025753ff133279b404
child 346985 9274f4f0ebdca3552c5cf860cfc2b95f86907ccc
push id10298
push userraliiev@mozilla.com
push dateMon, 14 Nov 2016 12:33:03 +0000
treeherdermozilla-aurora@7e29173b1641 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssebastian
bugs1312467
milestone52.0a1
Bug 1312467 - Hide some items for TopSites context menu r=sebastian MozReview-Commit-ID: JHEr4IraLQB
mobile/android/base/java/org/mozilla/gecko/home/activitystream/StreamItem.java
mobile/android/base/java/org/mozilla/gecko/home/activitystream/menu/ActivityStreamContextMenu.java
mobile/android/base/java/org/mozilla/gecko/home/activitystream/topsites/TopSitesCard.java
mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/testActivityStreamContextMenu.java
--- a/mobile/android/base/java/org/mozilla/gecko/home/activitystream/StreamItem.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/activitystream/StreamItem.java
@@ -103,17 +103,19 @@ public abstract class StreamItem extends
             menuButton.setImageDrawable(
                     DrawableUtil.tintDrawable(menuButton.getContext(), R.drawable.menu, Color.LTGRAY));
 
             TouchTargetUtil.ensureTargetHitArea(menuButton, itemView);
 
             menuButton.setOnClickListener(new View.OnClickListener() {
                 @Override
                 public void onClick(View v) {
-                    ActivityStreamContextMenu.show(v.getContext(), title, url, onUrlOpenListener, onUrlOpenInBackgroundListener, vIconView.getWidth(), vIconView.getHeight());
+                    ActivityStreamContextMenu.show(v.getContext(), ActivityStreamContextMenu.MenuMode.HIGHLIGHT,
+                            title, url, onUrlOpenListener, onUrlOpenInBackgroundListener,
+                            vIconView.getWidth(), vIconView.getHeight());
                 }
             });
         }
 
         public void bind(Cursor cursor, int tilesWidth, int tilesHeight) {
 
             final long time = cursor.getLong(cursor.getColumnIndexOrThrow(BrowserContract.Highlights.DATE));
             final String ago = DateUtils.getRelativeTimeSpanString(time, System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS, 0).toString();
--- a/mobile/android/base/java/org/mozilla/gecko/home/activitystream/menu/ActivityStreamContextMenu.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/activitystream/menu/ActivityStreamContextMenu.java
@@ -34,27 +34,35 @@ import org.mozilla.gecko.widget.FaviconV
 
 import java.util.EnumSet;
 
 import static org.mozilla.gecko.activitystream.ActivityStream.extractLabel;
 
 public class ActivityStreamContextMenu
     extends BottomSheetDialog
         implements NavigationView.OnNavigationItemSelectedListener {
+
+    public enum MenuMode {
+        HIGHLIGHT,
+        TOPSITE
+    }
+
     final Context context;
 
     final String title;
     final String url;
 
     final HomePager.OnUrlOpenListener onUrlOpenListener;
     final HomePager.OnUrlOpenInBackgroundListener onUrlOpenInBackgroundListener;
 
     boolean isAlreadyBookmarked = false;
 
-    private ActivityStreamContextMenu(final Context context, final String title, @NonNull final String url,
+    private ActivityStreamContextMenu(final Context context,
+                                      final MenuMode mode,
+                                      final String title, @NonNull final String url,
                                       HomePager.OnUrlOpenListener onUrlOpenListener,
                                       HomePager.OnUrlOpenInBackgroundListener onUrlOpenInBackgroundListener,
                                       final int tilesWidth, final int tilesHeight) {
         super(context);
 
         this.context = context;
 
         this.title = title;
@@ -87,16 +95,24 @@ public class ActivityStreamContextMenu
                     public void onIconResponse(IconResponse response) {
                         faviconView.updateImage(response);
                     }
                 });
 
         NavigationView navigationView = (NavigationView) findViewById(R.id.menu);
         navigationView.setNavigationItemSelectedListener(this);
 
+        // Disable "dismiss" for topsites until we have decided on its behaviour for topsites
+        // (currently "dismiss" adds the URL to a highlights-specific blocklist, which the topsites
+        // query has no knowledge of).
+        if (mode == MenuMode.TOPSITE) {
+            final MenuItem dismissItem = navigationView.getMenu().findItem(R.id.dismiss);
+            dismissItem.setVisible(false);
+        }
+
         // Disable the bookmark item until we know its bookmark state
         final MenuItem bookmarkItem = navigationView.getMenu().findItem(R.id.bookmark);
         bookmarkItem.setEnabled(false);
 
         (new UIAsyncTask.WithoutParams<Void>(ThreadUtils.getBackgroundHandler()) {
             @Override
             protected Void doInBackground() {
                 isAlreadyBookmarked = BrowserDB.from(context).isBookmark(context.getContentResolver(), url);
@@ -144,21 +160,25 @@ public class ActivityStreamContextMenu
                 }
             }
         }).execute();
 
         BottomSheetBehavior<View> bsBehaviour = BottomSheetBehavior.from((View) content.getParent());
         bsBehaviour.setPeekHeight(context.getResources().getDimensionPixelSize(R.dimen.activity_stream_contextmenu_peek_height));
     }
 
-    public static ActivityStreamContextMenu show(Context context, final String title, @NonNull  final String url,
+    public static ActivityStreamContextMenu show(Context context,
+                            final MenuMode menuMode,
+                            final String title, @NonNull  final String url,
                             HomePager.OnUrlOpenListener onUrlOpenListener,
                             HomePager.OnUrlOpenInBackgroundListener onUrlOpenInBackgroundListener,
                             final int tilesWidth, final int tilesHeight) {
-        final ActivityStreamContextMenu menu = new ActivityStreamContextMenu(context, title, url,
+        final ActivityStreamContextMenu menu = new ActivityStreamContextMenu(context,
+                menuMode,
+                title, url,
                 onUrlOpenListener, onUrlOpenInBackgroundListener,
                 tilesWidth, tilesHeight);
         menu.show();
 
         return menu;
     }
 
     @Override
--- a/mobile/android/base/java/org/mozilla/gecko/home/activitystream/topsites/TopSitesCard.java
+++ b/mobile/android/base/java/org/mozilla/gecko/home/activitystream/topsites/TopSitesCard.java
@@ -82,14 +82,16 @@ class TopSitesCard extends RecyclerView.
                 DrawableUtil.tintDrawable(menuButton.getContext(), R.drawable.menu, tintColor));
     }
 
     @Override
     public void onClick(View clickedView) {
         if (clickedView == itemView) {
             onUrlOpenListener.onUrlOpen(url, EnumSet.noneOf(HomePager.OnUrlOpenListener.Flags.class));
         } else if (clickedView == menuButton) {
-            ActivityStreamContextMenu.show(clickedView.getContext(), title.getText().toString(), url,
+            ActivityStreamContextMenu.show(clickedView.getContext(),
+                    ActivityStreamContextMenu.MenuMode.TOPSITE,
+                    title.getText().toString(), url,
                     onUrlOpenListener, onUrlOpenInBackgroundListener,
                     faviconView.getWidth(), faviconView.getHeight());
         }
     }
 }
--- a/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/testActivityStreamContextMenu.java
+++ b/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/testActivityStreamContextMenu.java
@@ -43,17 +43,17 @@ public class testActivityStreamContextMe
         testMenuForUrl(testURL, false, true);
     }
 
     /**
      * Test that the menu shows the expected menu items for a given URL, and that these items have
      * the correct state.
      */
     private void testMenuForUrl(final String url, final boolean isBookmarked, final boolean isVisited) {
-        final ActivityStreamContextMenu menu = ActivityStreamContextMenu.show(getActivity(), "foobar", url, null, null, 100, 100);
+        final ActivityStreamContextMenu menu = ActivityStreamContextMenu.show(getActivity(), ActivityStreamContextMenu.MenuMode.HIGHLIGHT, "foobar", url, null, null, 100, 100);
 
         waitForContextMenu(menu);
 
         final View wrapper = menu.findViewById(R.id.info_wrapper);
         mAsserter.is(wrapper.getVisibility(), View.VISIBLE, "menu should be visible");
 
         NavigationView nv = (NavigationView) menu.findViewById(R.id.menu);