Bug 1073257 - Get imageurl and bgcolor from cursor

This commit is contained in:
Brian Nicholson 2014-09-26 11:34:39 -07:00
parent ba1902adf3
commit 4a47ae9d7a
4 changed files with 11 additions and 73 deletions

View File

@ -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;
}
}

View File

@ -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<String> loadBlacklist() {
Log.d(LOGTAG, "Loading blacklisted suggested sites from SharedPreferences.");
final Set<String> blacklist = new HashSet<String>();

View File

@ -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;
}

View File

@ -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));