From 57834588829578af14b02e6038a67f2010a073d2 Mon Sep 17 00:00:00 2001 From: Wes Johnston Date: Wed, 30 Jan 2013 10:20:35 -0500 Subject: [PATCH] Bug 833942 - Add 'remove' to about:home topsites r=mfinkle --- mobile/android/base/AboutHomeContent.java | 26 +++++++++++++------ mobile/android/base/BrowserApp.java | 7 ++++- mobile/android/base/db/BrowserDB.java | 6 +++++ mobile/android/base/db/LocalBrowserDB.java | 6 +++++ .../base/locales/en-US/android_strings.dtd | 1 + .../menu/abouthome_topsites_contextmenu.xml | 2 ++ mobile/android/base/strings.xml.in | 1 + 7 files changed, 40 insertions(+), 9 deletions(-) diff --git a/mobile/android/base/AboutHomeContent.java b/mobile/android/base/AboutHomeContent.java index fc4608b69fd..c61a6072d6e 100644 --- a/mobile/android/base/AboutHomeContent.java +++ b/mobile/android/base/AboutHomeContent.java @@ -79,6 +79,11 @@ public class AboutHomeContent extends ScrollView private static int mNumberOfTopSites; private static int mNumberOfCols; + public static enum UnpinFlags { + REMOVE_PIN, + REMOVE_HISTORY + } + static enum UpdateFlags { TOP_SITES, PREVIOUS_TABS, @@ -210,11 +215,13 @@ public class AboutHomeContent extends ScrollView // 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); } } @@ -1013,18 +1020,21 @@ public class AboutHomeContent extends ScrollView 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(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(); diff --git a/mobile/android/base/BrowserApp.java b/mobile/android/base/BrowserApp.java index 204db390307..604ff2bdfa1 100644 --- a/mobile/android/base/BrowserApp.java +++ b/mobile/android/base/BrowserApp.java @@ -1050,12 +1050,17 @@ abstract public class BrowserApp extends GeckoApp 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); } diff --git a/mobile/android/base/db/BrowserDB.java b/mobile/android/base/db/BrowserDB.java index f954a560c35..ad7aa5d8396 100644 --- a/mobile/android/base/db/BrowserDB.java +++ b/mobile/android/base/db/BrowserDB.java @@ -57,6 +57,8 @@ public class BrowserDB { 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); @@ -169,6 +171,10 @@ public class BrowserDB { 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); } diff --git a/mobile/android/base/db/LocalBrowserDB.java b/mobile/android/base/db/LocalBrowserDB.java index a36fb45484d..ebeee097482 100644 --- a/mobile/android/base/db/LocalBrowserDB.java +++ b/mobile/android/base/db/LocalBrowserDB.java @@ -339,6 +339,12 @@ public class LocalBrowserDB implements BrowserDB.BrowserDBIface { 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); } diff --git a/mobile/android/base/locales/en-US/android_strings.dtd b/mobile/android/base/locales/en-US/android_strings.dtd index d7383168b40..814027b0203 100644 --- a/mobile/android/base/locales/en-US/android_strings.dtd +++ b/mobile/android/base/locales/en-US/android_strings.dtd @@ -203,6 +203,7 @@ size. --> +