Bug 833942 - Add 'remove' to about:home topsites r=mfinkle
authorWes Johnston <wjohnston@mozilla.com>
Wed, 30 Jan 2013 10:20:35 -0500
changeset 130249 d612985bf5ca09a52c76798dc17bed068f3c7101
parent 130248 fd83646a2d152624598a9a475b48773c1c0da847
child 130250 7faec6303aa9a53705172ed679732dac65047487
push id2323
push userbbajaj@mozilla.com
push dateMon, 01 Apr 2013 19:47:02 +0000
treeherdermozilla-beta@7712be144d91 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs833942
milestone21.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 833942 - Add 'remove' to about:home topsites r=mfinkle
mobile/android/base/AboutHomeContent.java
mobile/android/base/BrowserApp.java
mobile/android/base/db/BrowserDB.java
mobile/android/base/db/LocalBrowserDB.java
mobile/android/base/locales/en-US/android_strings.dtd
mobile/android/base/resources/menu/abouthome_topsites_contextmenu.xml
mobile/android/base/strings.xml.in
--- a/mobile/android/base/AboutHomeContent.java
+++ b/mobile/android/base/AboutHomeContent.java
@@ -74,16 +74,21 @@ public class AboutHomeContent extends Sc
                                          LightweightTheme.OnChangeListener {
     private static final String LOGTAG = "GeckoAboutHome";
 
     private static final int NUMBER_OF_REMOTE_TABS = 5;
 
     private static int mNumberOfTopSites;
     private static int mNumberOfCols;
 
+    public static enum UnpinFlags {
+        REMOVE_PIN,
+        REMOVE_HISTORY
+    }
+
     static enum UpdateFlags {
         TOP_SITES,
         PREVIOUS_TABS,
         RECOMMENDED_ADDONS,
         REMOTE_TABS;
 
         public static final EnumSet<UpdateFlags> ALL = EnumSet.allOf(UpdateFlags.class);
     }
@@ -205,21 +210,23 @@ public class AboutHomeContent extends Sc
                 MenuInflater inflater = mActivity.getMenuInflater();
                 inflater.inflate(R.menu.abouthome_topsites_contextmenu, menu);
 
                 // If nothing is pinned at all, hide both clear items
                 // We can assume that the adapter count and view count are the same in this case because our grid view
                 // force all items to be visible all the time
                 View view = mTopSitesGrid.getChildAt(info.position);
                 TopSitesViewHolder holder = (TopSitesViewHolder) view.getTag();
-                if (holder.isPinned()) {
+                if (TextUtils.isEmpty(holder.getUrl())) {
+                    menu.findItem(R.id.abouthome_topsites_pin).setVisible(false);
+                    menu.findItem(R.id.abouthome_topsites_unpin).setVisible(false);
+                    menu.findItem(R.id.abouthome_topsites_remove).setVisible(false);
+                } else if (holder.isPinned()) {
                     menu.findItem(R.id.abouthome_topsites_pin).setVisible(false);
                 } else {
-                    if (TextUtils.isEmpty(holder.getUrl()))
-                        menu.findItem(R.id.abouthome_topsites_pin).setVisible(false);
                     menu.findItem(R.id.abouthome_topsites_unpin).setVisible(false);
                 }
             }
         });
 
         mPromoBox = (AboutHomePromoBox) findViewById(R.id.promo_box);
         mAddons = (AboutHomeSection) findViewById(R.id.recommended_addons);
         mLastTabs = (AboutHomeSection) findViewById(R.id.last_tabs);
@@ -1008,28 +1015,31 @@ public class AboutHomeContent extends Sc
     private void clearThumbnail(TopSitesViewHolder holder) {
         holder.setTitle("");
         holder.setUrl("");
         holder.thumbnailView.setImageResource(R.drawable.abouthome_thumbnail_add);
         holder.thumbnailView.setScaleType(ImageView.ScaleType.FIT_CENTER);
         holder.setPinned(false);
     }
 
-    public void unpinSite() {
+    public void unpinSite(final UnpinFlags flags) {
         final int position = mTopSitesGrid.getSelectedPosition();
-        View v = mTopSitesGrid.getChildAt(position);
-        TopSitesViewHolder holder = (TopSitesViewHolder) v.getTag();
-
+        final View v = mTopSitesGrid.getChildAt(position);
+        final TopSitesViewHolder holder = (TopSitesViewHolder) v.getTag();
+        final String url = holder.getUrl();
         // Quickly update the view so that there isn't as much lag between the request and response
         clearThumbnail(holder);
         (new GeckoAsyncTask<Void, Void, Void>(GeckoApp.mAppContext, GeckoAppShell.getHandler()) {
             @Override
             public Void doInBackground(Void... params) {
-                ContentResolver resolver = mActivity.getContentResolver();
+                final ContentResolver resolver = mActivity.getContentResolver();
                 BrowserDB.unpinSite(resolver, position);
+                if (flags == UnpinFlags.REMOVE_HISTORY) {
+                    BrowserDB.removeHistoryEntry(resolver, url);
+                }
                 return null;
             }
         }).execute();
     }
 
     public void pinSite() {
         final int position = mTopSitesGrid.getSelectedPosition();
         View v = mTopSitesGrid.getChildAt(position);
--- a/mobile/android/base/BrowserApp.java
+++ b/mobile/android/base/BrowserApp.java
@@ -1045,22 +1045,27 @@ abstract public class BrowserApp extends
     @Override
     public boolean onContextItemSelected(MenuItem item) {
         switch (item.getItemId()) {
             case R.id.abouthome_topsites_edit:
                 mAboutHomeContent.editSite();
                 return true;
 
             case R.id.abouthome_topsites_unpin:
-                mAboutHomeContent.unpinSite();
+                mAboutHomeContent.unpinSite(AboutHomeContent.UnpinFlags.REMOVE_PIN);
                 return true;
 
             case R.id.abouthome_topsites_pin:
                 mAboutHomeContent.pinSite();
                 return true;
+
+            case R.id.abouthome_topsites_remove:
+                mAboutHomeContent.unpinSite(AboutHomeContent.UnpinFlags.REMOVE_HISTORY);
+                return true;
+
         }
         return super.onContextItemSelected(item);
     }
 
     @Override
     public boolean onOptionsItemSelected(MenuItem item) {
         Tab tab = null;
         Intent intent = null;
--- a/mobile/android/base/db/BrowserDB.java
+++ b/mobile/android/base/db/BrowserDB.java
@@ -52,16 +52,18 @@ public class BrowserDB {
         public Cursor getAllVisitedHistory(ContentResolver cr);
 
         public Cursor getRecentHistory(ContentResolver cr, int limit);
 
         public void expireHistory(ContentResolver cr, ExpirePriority priority);
 
         public void removeHistoryEntry(ContentResolver cr, int id);
 
+        public void removeHistoryEntry(ContentResolver cr, String url);
+
         public void clearHistory(ContentResolver cr);
 
         public Cursor getBookmarksInFolder(ContentResolver cr, long folderId);
 
         public boolean isBookmark(ContentResolver cr, String uri);
 
         public boolean isReadingListItem(ContentResolver cr, String uri);
 
@@ -164,16 +166,20 @@ public class BrowserDB {
             priority = ExpirePriority.NORMAL;
         sDb.expireHistory(cr, priority);
     }
 
     public static void removeHistoryEntry(ContentResolver cr, int id) {
         sDb.removeHistoryEntry(cr, id);
     }
 
+    public static void removeHistoryEntry(ContentResolver cr, String url) {
+        sDb.removeHistoryEntry(cr, url);
+    }
+
     public static void clearHistory(ContentResolver cr) {
         sDb.clearHistory(cr);
     }
 
     public static Cursor getBookmarksInFolder(ContentResolver cr, long folderId) {
         return sDb.getBookmarksInFolder(cr, folderId);
     }
 
--- a/mobile/android/base/db/LocalBrowserDB.java
+++ b/mobile/android/base/db/LocalBrowserDB.java
@@ -334,16 +334,22 @@ public class LocalBrowserDB implements B
     }
 
     public void removeHistoryEntry(ContentResolver cr, int id) {
         cr.delete(mHistoryUriWithProfile,
                   History._ID + " = ?",
                   new String[] { String.valueOf(id) });
     }
 
+    public void removeHistoryEntry(ContentResolver cr, String url) {
+        int deleted = cr.delete(mHistoryUriWithProfile,
+                  History.URL + " = ?",
+                  new String[] { url });
+    }
+
     public void clearHistory(ContentResolver cr) {
         cr.delete(mHistoryUriWithProfile, null, null);
     }
 
     public Cursor getBookmarksInFolder(ContentResolver cr, long folderId) {
         Cursor c = null;
         boolean addDesktopFolder = false;
         boolean addReadingListFolder = false;
--- a/mobile/android/base/locales/en-US/android_strings.dtd
+++ b/mobile/android/base/locales/en-US/android_strings.dtd
@@ -198,16 +198,17 @@ size. -->
 <!ENTITY abouthome_addons_title "Add-ons for your &brandShortName;">
 <!ENTITY abouthome_addons_browse "Browse all &brandShortName; add-ons">
 <!ENTITY abouthome_last_tabs_title "Your tabs from last time">
 <!ENTITY abouthome_last_tabs_open "Open all tabs from last time">
 <!ENTITY abouthome_top_sites_title "Top sites">
 <!ENTITY abouthome_topsites_edit "Edit">
 <!ENTITY abouthome_topsites_pin "Pin Site">
 <!ENTITY abouthome_topsites_unpin "Unpin Site">
+<!ENTITY abouthome_topsites_remove "Remove">
 
 <!-- Localization note (abouthome_about_sync3, abouthome_about_apps2): The
      chevron (ex: "»"; unicode= U+00BB) is used as an arrow to show that
      clicking this text in the promotions box will perform some action. Note
      that a non-breaking space (unicode= U+00A0) should be used between this
      character and the remainder of the string to prevent word wrap. -->
 <!ENTITY abouthome_about_sync3 "Set up Firefox Sync to access bookmarks, history and tabs from your other devices&#x00A0;»">
 <!ENTITY abouthome_about_apps3 "Get apps from the Firefox Marketplace and discover the best the Web has to offer&#x00A0;»">
--- a/mobile/android/base/resources/menu/abouthome_topsites_contextmenu.xml
+++ b/mobile/android/base/resources/menu/abouthome_topsites_contextmenu.xml
@@ -9,9 +9,11 @@
           android:title="@string/abouthome_topsites_edit"/>
 
     <item android:id="@+id/abouthome_topsites_pin"
           android:title="@string/abouthome_topsites_pin"/>
 
     <item android:id="@+id/abouthome_topsites_unpin"
           android:title="@string/abouthome_topsites_unpin"/>
 
+    <item android:id="@+id/abouthome_topsites_remove"
+          android:title="@string/abouthome_topsites_remove"/>
 </menu>
--- a/mobile/android/base/strings.xml.in
+++ b/mobile/android/base/strings.xml.in
@@ -200,16 +200,17 @@
   <string name="abouthome_about_sync">&abouthome_about_sync3;</string>
   <string name="abouthome_about_apps">&abouthome_about_apps3;</string>
   <string name="abouthome_sync_bold_name">&abouthome_sync_bold_name;</string>
   <string name="abouthome_apps_bold_name">&abouthome_apps_bold_name2;</string>
   
   <string name="abouthome_topsites_edit">&abouthome_topsites_edit;</string>
   <string name="abouthome_topsites_pin">&abouthome_topsites_pin;</string>
   <string name="abouthome_topsites_unpin">&abouthome_topsites_unpin;</string>
+  <string name="abouthome_topsites_remove">&abouthome_topsites_remove;</string>
 
   <string name="filepicker_title">&filepicker_title;</string>
   <string name="filepicker_audio_title">&filepicker_audio_title;</string>
   <string name="filepicker_image_title">&filepicker_image_title;</string>
   <string name="filepicker_video_title">&filepicker_video_title;</string>
 
   <!-- Default bookmarks. Use bookmarks titles shared with XUL from mobile's
        profile/bookmarks.inc. Don't expose the URLs to L10N. -->