Bug 1400825 - Show option for removing suggested sites from top sites. r=mcomella
authorSebastian Kaspari <s.kaspari@gmail.com>
Fri, 22 Sep 2017 19:59:08 +0200
changeset 382554 10241c6a7b3a72cfd1310d985d9868da28306724
parent 382553 5bfa23832767e42835f4c144fcbd4a351b7feca2
child 382555 a54290a32fd6978e9f89ab4efd823e936258ba84
push id51906
push usermichael.l.comella@gmail.com
push dateFri, 22 Sep 2017 22:48:27 +0000
treeherderautoland@a54290a32fd6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmcomella
bugs1400825
milestone58.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1400825 - Show option for removing suggested sites from top sites. r=mcomella MozReview-Commit-ID: LyAqnlMfQvr
mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/menu/ActivityStreamContextMenu.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
@@ -15,17 +15,19 @@ import org.mozilla.gecko.GeckoApplicatio
 import org.mozilla.gecko.IntentHelper;
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.Telemetry;
 import org.mozilla.gecko.TelemetryContract;
 import org.mozilla.gecko.activitystream.ActivityStreamTelemetry;
 import org.mozilla.gecko.activitystream.homepanel.model.WebpageModel;
 import org.mozilla.gecko.activitystream.homepanel.topstories.PocketStoriesLoader;
 import org.mozilla.gecko.annotation.RobocopTarget;
+import org.mozilla.gecko.db.BrowserContract;
 import org.mozilla.gecko.db.BrowserDB;
+import org.mozilla.gecko.db.SuggestedSites;
 import org.mozilla.gecko.home.HomePager;
 import org.mozilla.gecko.reader.SavedReaderViewHelper;
 import org.mozilla.gecko.util.Clipboard;
 import org.mozilla.gecko.util.HardwareUtils;
 import org.mozilla.gecko.util.ThreadUtils;
 import org.mozilla.gecko.util.UIAsyncTask;
 
 import java.util.EnumSet;
@@ -85,21 +87,20 @@ public abstract class ActivityStreamCont
             bookmarkItem.setIcon(R.drawable.as_bookmark_filled);
         }
 
         final MenuItem pinItem = getItemByID(R.id.pin);
         if (Boolean.TRUE.equals(item.isPinned())) {
             pinItem.setTitle(R.string.contextmenu_top_sites_unpin);
         }
 
-        // Disable "dismiss" for topsites and topstories until we have decided on its behaviour
-        // (currently "dismiss" adds the URL to a highlights-specific blocklist, which the topsites
-        // query has no knowledge of).
-        if (mode == MenuMode.TOPSITE || mode == MenuMode.TOPSTORY) {
-            final MenuItem dismissItem = getItemByID(R.id.dismiss);
+        // Disable "dismiss" for topsites and topstories here. Later when we know whether this item
+        // has history we might re-enable this item (See AsyncTask below).
+        final MenuItem dismissItem = getItemByID(R.id.dismiss);
+        if (mode == MenuMode.TOPSTORY || mode == MenuMode.TOPSITE) {
             dismissItem.setVisible(false);
         }
 
         if (item.isBookmarked() == null) {
             // Disable the bookmark item until we know its bookmark state
             bookmarkItem.setEnabled(false);
 
             (new UIAsyncTask.WithoutParams<Boolean>(ThreadUtils.getBackgroundHandler()) {
@@ -138,18 +139,18 @@ public abstract class ActivityStreamCont
                     }
 
                     item.updatePinned(hasPin);
                     pinItem.setEnabled(true);
                 }
             }).execute();
         }
 
+        final MenuItem deleteHistoryItem = getItemByID(R.id.delete);
         // Only show the "remove from history" item if a page actually has history
-        final MenuItem deleteHistoryItem = getItemByID(R.id.delete);
         deleteHistoryItem.setVisible(false);
 
         (new UIAsyncTask.WithoutParams<Boolean>(ThreadUtils.getBackgroundHandler()) {
             @Override
             protected Boolean doInBackground() {
                 final WebpageModel item = ActivityStreamContextMenu.this.item;
 
                 final Cursor cursor = BrowserDB.from(context).getHistoryForURL(context.getContentResolver(), item.getUrl());
@@ -163,16 +164,22 @@ public abstract class ActivityStreamCont
                 } finally {
                     cursor.close();
                 }
             }
 
             @Override
             protected void onPostExecute(Boolean hasHistory) {
                 deleteHistoryItem.setVisible(hasHistory);
+
+                if (!hasHistory && mode == MenuMode.TOPSITE) {
+                    // For top sites items without history (suggested items) we show the dismiss
+                    // item. This will allow users to remove a suggested site.
+                    dismissItem.setVisible(true);
+                }
             }
         }).execute();
     }
 
 
     @Override
     public boolean onNavigationItemSelected(MenuItem menuItem) {
         final int menuItemId = menuItem.getItemId();
@@ -279,18 +286,22 @@ public abstract class ActivityStreamCont
                 onUrlOpenInBackgroundListener.onUrlOpenInBackgroundWithReferrer(item.getUrl(), referrerUri,
                         EnumSet.of(HomePager.OnUrlOpenInBackgroundListener.Flags.PRIVATE));
                 break;
 
             case R.id.dismiss:
                 ThreadUtils.postToBackgroundThread(new Runnable() {
                     @Override
                     public void run() {
-                        BrowserDB.from(context)
-                                .blockActivityStreamSite(context.getContentResolver(), item.getUrl());
+                        BrowserDB db = BrowserDB.from(context);
+                        if (db.hideSuggestedSite(item.getUrl())) {
+                            context.getContentResolver().notifyChange(BrowserContract.SuggestedSites.CONTENT_URI, null);
+                        } else {
+                            db.blockActivityStreamSite(context.getContentResolver(), item.getUrl());
+                        }
                     }
                 });
                 break;
 
             case R.id.delete:
                 ThreadUtils.postToBackgroundThread(new Runnable() {
                     @Override
                     public void run() {