Bug 1401179 - Add snackbar for bookmark add/remove actions on newtab. r=mcomella, a=sledru
authorChenxia Liu <liuche@mozilla.com>
Fri, 22 Sep 2017 18:08:07 -0700
changeset 431841 fd78928b00d87444d1aefe942d0489e8682e0981
parent 431840 3fa652b178a23dd826594355a18d008f0b976bf1
child 431842 4d33cf91c8bd34351510604e5032b610fa4afa02
push id7821
push userryanvm@gmail.com
push dateMon, 25 Sep 2017 14:09:06 +0000
treeherdermozilla-beta@fd78928b00d8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmcomella, sledru
bugs1401179
milestone57.0
Bug 1401179 - Add snackbar for bookmark add/remove actions on newtab. r=mcomella, a=sledru MozReview-Commit-ID: 7DzoyDSWmVq
mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/menu/ActivityStreamContextMenu.java
mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/menu/BottomSheetContextMenu.java
mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/menu/PopupContextMenu.java
--- a/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/menu/ActivityStreamContextMenu.java
+++ b/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/menu/ActivityStreamContextMenu.java
@@ -2,17 +2,19 @@
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 package org.mozilla.gecko.activitystream.homepanel.menu;
 
 import android.content.Context;
 import android.content.Intent;
 import android.database.Cursor;
+import android.support.annotation.NonNull;
 import android.support.design.widget.NavigationView;
+import android.support.design.widget.Snackbar;
 import android.view.MenuItem;
 import android.view.View;
 
 import org.mozilla.gecko.GeckoApplication;
 import org.mozilla.gecko.IntentHelper;
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.Telemetry;
 import org.mozilla.gecko.TelemetryContract;
@@ -39,37 +41,40 @@ public abstract class ActivityStreamCont
     public enum MenuMode {
         HIGHLIGHT,
         TOPSITE,
         TOPSTORY
     }
 
     private final Context context;
     private final WebpageModel item;
+    @NonNull private final View snackbarAnchor;
 
     private final ActivityStreamTelemetry.Extras.Builder telemetryExtraBuilder;
 
     private final HomePager.OnUrlOpenListener onUrlOpenListener;
     private final HomePager.OnUrlOpenInBackgroundListener onUrlOpenInBackgroundListener;
 
     public abstract MenuItem getItemByID(int id);
 
     public abstract void show();
 
     public abstract void dismiss();
 
     private final MenuMode mode;
 
     /* package-private */ ActivityStreamContextMenu(final Context context,
+                                                    final View snackbarAnchor,
                                                     final ActivityStreamTelemetry.Extras.Builder telemetryExtraBuilder,
                                                     final MenuMode mode,
                                                     final WebpageModel item,
                                                     HomePager.OnUrlOpenListener onUrlOpenListener,
                                                     HomePager.OnUrlOpenInBackgroundListener onUrlOpenInBackgroundListener) {
         this.context = context;
+        this.snackbarAnchor = snackbarAnchor;
         this.item = item;
         this.telemetryExtraBuilder = telemetryExtraBuilder;
 
         this.mode = mode;
 
         this.onUrlOpenListener = onUrlOpenListener;
         this.onUrlOpenInBackgroundListener = onUrlOpenInBackgroundListener;
     }
@@ -230,20 +235,25 @@ public abstract class ActivityStreamCont
 
                 ThreadUtils.postToBackgroundThread(new Runnable() {
                     @Override
                     public void run() {
                         final BrowserDB db = BrowserDB.from(context);
 
                         if (item.isBookmarked()) {
                             db.removeBookmarksWithURL(context.getContentResolver(), item.getUrl());
+
+                            // See bug 1402521 for adding "options" to the snackbar.
+                            Snackbar.make(ActivityStreamContextMenu.this.snackbarAnchor, R.string.bookmark_removed, Snackbar.LENGTH_LONG).show();
                         } else {
                             // We only store raw URLs in history (and bookmarks), hence we won't ever show about:reader
                             // URLs in AS topsites or highlights. Therefore we don't need to do any special about:reader handling here.
                             db.addBookmark(context.getContentResolver(), item.getTitle(), item.getUrl());
+
+                            Snackbar.make(ActivityStreamContextMenu.this.snackbarAnchor, R.string.bookmark_added, Snackbar.LENGTH_LONG).show();
                         }
                         item.onStateCommitted();
                     }
                 });
                 break;
 
             case R.id.pin:
                 // While isPinned is nullable, behaviour of postInit - disabling 'pin' item
@@ -336,16 +346,17 @@ public abstract class ActivityStreamCont
                                                       final boolean shouldOverrideIconWithImageProvider,
                                                       HomePager.OnUrlOpenListener onUrlOpenListener,
                                                       HomePager.OnUrlOpenInBackgroundListener onUrlOpenInBackgroundListener,
                                                       final int tilesWidth, final int tilesHeight) {
         final ActivityStreamContextMenu menu;
 
         if (!HardwareUtils.isTablet()) {
             menu = new BottomSheetContextMenu(context,
+                    anchor,
                     telemetryExtraBuilder, menuMode,
                     item, shouldOverrideIconWithImageProvider, onUrlOpenListener, onUrlOpenInBackgroundListener,
                     tilesWidth, tilesHeight);
         } else {
             menu = new PopupContextMenu(context,
                     anchor,
                     telemetryExtraBuilder, menuMode,
                     item, onUrlOpenListener, onUrlOpenInBackgroundListener);
--- a/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/menu/BottomSheetContextMenu.java
+++ b/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/menu/BottomSheetContextMenu.java
@@ -42,25 +42,27 @@ import java.net.URISyntaxException;
 
     private final View content;
     private final View activityView;
 
     /** A reference, that represents the page domain, that allows a return value from an async task. */
     private String[] pageDomainTextReference = new String[] { "" };
 
     public BottomSheetContextMenu(final Context context,
+                                  final View anchor,
                                   final ActivityStreamTelemetry.Extras.Builder telemetryExtraBuilder,
                                   final MenuMode mode,
                                   final WebpageModel item,
                                   final boolean shouldOverrideIconWithImageProvider,
                                   HomePager.OnUrlOpenListener onUrlOpenListener,
                                   HomePager.OnUrlOpenInBackgroundListener onUrlOpenInBackgroundListener,
                                   final int tilesWidth, final int tilesHeight) {
 
         super(context,
+                anchor,
                 telemetryExtraBuilder,
                 mode,
                 item,
                 onUrlOpenListener,
                 onUrlOpenInBackgroundListener);
 
         // The View encompassing the activity area
         this.activityView = ((Activity) context).findViewById(android.R.id.content);
--- a/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/menu/PopupContextMenu.java
+++ b/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/menu/PopupContextMenu.java
@@ -31,16 +31,17 @@ import org.mozilla.gecko.activitystream.
     public PopupContextMenu(final Context context,
                             View anchor,
                             final ActivityStreamTelemetry.Extras.Builder telemetryExtraBuilder,
                             final MenuMode mode,
                             final WebpageModel item,
                             HomePager.OnUrlOpenListener onUrlOpenListener,
                             HomePager.OnUrlOpenInBackgroundListener onUrlOpenInBackgroundListener) {
         super(context,
+                anchor,
                 telemetryExtraBuilder,
                 mode,
                 item,
                 onUrlOpenListener,
                 onUrlOpenInBackgroundListener);
 
         this.anchor = anchor;