Bug 1400825 - Show option for removing suggested sites from top sites. r? draft
authorSebastian Kaspari <s.kaspari@gmail.com>
Fri, 22 Sep 2017 19:59:08 +0200
changeset 669207 557adde670827887c705837c3094f209212b38d5
parent 669023 2cd3752963fc8f24f7c202687eab55e83222f608
child 732890 4469cbefa2675ed17746edb3576168d8f1d63817
push id81252
push userbmo:s.kaspari@gmail.com
push dateFri, 22 Sep 2017 18:08:32 +0000
bugs1400825
milestone58.0a1
Bug 1400825 - Show option for removing suggested sites from top sites. r? 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() {