diff --git a/mobile/android/base/db/BrowserDB.java b/mobile/android/base/db/BrowserDB.java index 34b9eea76c7..ce994fa04b3 100644 --- a/mobile/android/base/db/BrowserDB.java +++ b/mobile/android/base/db/BrowserDB.java @@ -21,7 +21,6 @@ import android.content.ContentValues; import android.content.Context; import android.database.ContentObserver; import android.database.Cursor; -import android.graphics.Color; import android.graphics.drawable.BitmapDrawable; /** @@ -253,21 +252,4 @@ public class BrowserDB { public static void setEnableContentProviders(boolean enableContentProviders) { sAreContentProvidersEnabled = enableContentProviders; } - - public static boolean hasSuggestedImageUrl(String url) { - return sSuggestedSites.contains(url); - } - - public static String getSuggestedImageUrlForUrl(String url) { - return sSuggestedSites.getImageUrlForUrl(url); - } - - public static int getSuggestedBackgroundColorForUrl(String url) { - final String bgColor = sSuggestedSites.getBackgroundColorForUrl(url); - if (bgColor != null) { - return Color.parseColor(bgColor); - } - - return 0; - } } diff --git a/mobile/android/base/db/SuggestedSites.java b/mobile/android/base/db/SuggestedSites.java index 1ba87658326..bc0af77e660 100644 --- a/mobile/android/base/db/SuggestedSites.java +++ b/mobile/android/base/db/SuggestedSites.java @@ -496,20 +496,6 @@ public class SuggestedSites { return cursor; } - public boolean contains(String url) { - return (getSiteForUrl(url) != null); - } - - public String getImageUrlForUrl(String url) { - final Site site = getSiteForUrl(url); - return (site != null ? site.imageUrl : null); - } - - public String getBackgroundColorForUrl(String url) { - final Site site = getSiteForUrl(url); - return (site != null ? site.bgColor : null); - } - private Set loadBlacklist() { Log.d(LOGTAG, "Loading blacklisted suggested sites from SharedPreferences."); final Set blacklist = new HashSet(); diff --git a/mobile/android/base/home/TopSitesPanel.java b/mobile/android/base/home/TopSitesPanel.java index 26ea3f154b5..02f1af9301f 100644 --- a/mobile/android/base/home/TopSitesPanel.java +++ b/mobile/android/base/home/TopSitesPanel.java @@ -525,15 +525,12 @@ public class TopSitesPanel extends HomeFragment { return; } - // Make sure we query suggested images without the user-entered wrapper. - final String decodedUrl = StringUtils.decodeUserEnteredUrl(url); - // Suggested images have precedence over thumbnails, no need to wait // for them to be loaded. See: CursorLoaderCallbacks.onLoadFinished() - final String imageUrl = BrowserDB.getSuggestedImageUrlForUrl(decodedUrl); + final String imageUrl = cursor.getString(cursor.getColumnIndexOrThrow(TopSites.IMAGEURL)); if (!TextUtils.isEmpty(imageUrl)) { - final int bgColor = BrowserDB.getSuggestedBackgroundColorForUrl(decodedUrl); - view.displayThumbnail(imageUrl, bgColor); + final String bgColor = cursor.getString(cursor.getColumnIndexOrThrow(TopSites.BGCOLOR)); + view.displayThumbnail(imageUrl, Color.parseColor(bgColor)); return; } @@ -624,10 +621,11 @@ public class TopSitesPanel extends HomeFragment { int i = 1; do { final String url = c.getString(col); + final String imageUrl = c.getString(c.getColumnIndexOrThrow(TopSites.IMAGEURL)); // Only try to fetch thumbnails for non-empty URLs that // don't have an associated suggested image URL. - if (TextUtils.isEmpty(url) || BrowserDB.hasSuggestedImageUrl(url)) { + if (TextUtils.isEmpty(url) || TextUtils.isEmpty(imageUrl)) { continue; } diff --git a/mobile/android/tests/browser/junit3/src/TestSuggestedSites.java b/mobile/android/tests/browser/junit3/src/TestSuggestedSites.java index aa459795217..8688502f044 100644 --- a/mobile/android/tests/browser/junit3/src/TestSuggestedSites.java +++ b/mobile/android/tests/browser/junit3/src/TestSuggestedSites.java @@ -253,6 +253,12 @@ public class TestSuggestedSites extends BrowserTestCase { String title = c.getString(c.getColumnIndexOrThrow(BrowserContract.SuggestedSites.TITLE)); assertEquals("title" + position, title); + + String imageUrl = c.getString(c.getColumnIndexOrThrow(BrowserContract.SuggestedSites.IMAGEURL)); + assertEquals("imageUrl" + position, imageUrl); + + String bgColor = c.getString(c.getColumnIndexOrThrow(BrowserContract.SuggestedSites.BGCOLOR)); + assertEquals("bgColor" + position, bgColor); } c.close(); @@ -339,40 +345,6 @@ public class TestSuggestedSites extends BrowserTestCase { c.close(); } - public void testImageUrlAndBgColor() { - final int count = 3; - resources.setSuggestedSitesResource(generateSites(count)); - - SuggestedSites suggestedSites = new SuggestedSites(context); - - // Suggested sites hasn't been loaded yet. - for (int i = 0; i < count; i++) { - String url = "url" + i; - assertFalse(suggestedSites.contains(url)); - assertNull(suggestedSites.getImageUrlForUrl(url)); - assertNull(suggestedSites.getBackgroundColorForUrl(url)); - } - - Cursor c = suggestedSites.get(DEFAULT_LIMIT); - c.moveToPosition(-1); - - // We should have cached results after the get() call. - while (c.moveToNext()) { - String url = c.getString(c.getColumnIndexOrThrow(BrowserContract.SuggestedSites.URL)); - assertTrue(suggestedSites.contains(url)); - assertEquals("imageUrl" + c.getPosition(), - suggestedSites.getImageUrlForUrl(url)); - assertEquals("bgColor" + c.getPosition(), - suggestedSites.getBackgroundColorForUrl(url)); - } - c.close(); - - // No valid values for unknown URLs. - assertFalse(suggestedSites.contains("foo")); - assertNull(suggestedSites.getImageUrlForUrl("foo")); - assertNull(suggestedSites.getBackgroundColorForUrl("foo")); - } - public void testLocaleChanges() { resources.setSuggestedSitesResource(generateSites(3));