mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 22:01:30 +00:00
Bug 1009587 - Part 4: Use suggested thumbnail on top sites whenever it's available (r=mfinkle)
This commit is contained in:
parent
46bae56365
commit
65163d79c8
@ -428,9 +428,6 @@ public class BrowserContract {
|
||||
public static final String HISTORY_ID = "history_id";
|
||||
public static final String DISPLAY = "display";
|
||||
|
||||
public static final String IMAGE_URL = "image_url";
|
||||
public static final String BG_COLOR = "bg_color";
|
||||
|
||||
public static final String TYPE = "type";
|
||||
}
|
||||
|
||||
@ -439,8 +436,5 @@ public class BrowserContract {
|
||||
private SuggestedSites() {}
|
||||
|
||||
public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "suggestedsites");
|
||||
|
||||
public static final String IMAGE_URL = "image_url";
|
||||
public static final String BG_COLOR = "bg_color";
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ import android.content.ContentValues;
|
||||
import android.database.ContentObserver;
|
||||
import android.database.Cursor;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.Color;
|
||||
|
||||
public class BrowserDB {
|
||||
private static boolean sAreContentProvidersEnabled = true;
|
||||
@ -385,4 +386,21 @@ 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;
|
||||
}
|
||||
}
|
||||
|
@ -54,9 +54,7 @@ public class SuggestedSites {
|
||||
private static final String[] COLUMNS = new String[] {
|
||||
BrowserContract.SuggestedSites._ID,
|
||||
BrowserContract.SuggestedSites.URL,
|
||||
BrowserContract.SuggestedSites.TITLE,
|
||||
BrowserContract.SuggestedSites.IMAGE_URL,
|
||||
BrowserContract.SuggestedSites.BG_COLOR
|
||||
BrowserContract.SuggestedSites.TITLE
|
||||
};
|
||||
|
||||
private static final String JSON_KEY_URL = "url";
|
||||
@ -214,8 +212,6 @@ public class SuggestedSites {
|
||||
row.add(-1);
|
||||
row.add(site.url);
|
||||
row.add(site.title);
|
||||
row.add(site.imageUrl);
|
||||
row.add(site.bgColor);
|
||||
}
|
||||
|
||||
cursor.setNotificationUri(context.getContentResolver(),
|
||||
|
@ -41,8 +41,6 @@ public class TopSitesCursorWrapper implements Cursor {
|
||||
TopSites.BOOKMARK_ID,
|
||||
TopSites.HISTORY_ID,
|
||||
TopSites.DISPLAY,
|
||||
TopSites.IMAGE_URL,
|
||||
TopSites.BG_COLOR,
|
||||
TopSites.TYPE
|
||||
};
|
||||
|
||||
|
@ -533,12 +533,6 @@ public class TopSitesPanel extends HomeFragment {
|
||||
// fetches.
|
||||
final boolean updated = view.updateState(title, url, type, thumbnail);
|
||||
|
||||
// If thumbnails are still being loaded, don't try to load favicons
|
||||
// just yet. If we sent in a thumbnail, we're done now.
|
||||
if (mThumbnails == null || thumbnail != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Thumbnails are delivered late, so we can't short-circuit any
|
||||
// sooner than this. But we can avoid a duplicate favicon
|
||||
// fetch...
|
||||
@ -547,11 +541,18 @@ public class TopSitesPanel extends HomeFragment {
|
||||
return;
|
||||
}
|
||||
|
||||
final int imageUrlIndex = cursor.getColumnIndex(TopSites.IMAGE_URL);
|
||||
if (!cursor.isNull(imageUrlIndex)) {
|
||||
String imageUrl = cursor.getString(imageUrlIndex);
|
||||
String bgColor = cursor.getString(cursor.getColumnIndex(TopSites.BG_COLOR));
|
||||
view.displayThumbnail(imageUrl, Color.parseColor(bgColor));
|
||||
// Suggested images have precedence over thumbnails, no need to wait
|
||||
// for them to be loaded. See: CursorLoaderCallbacks.onLoadFinished()
|
||||
final String imageUrl = BrowserDB.getSuggestedImageUrlForUrl(url);
|
||||
if (!TextUtils.isEmpty(imageUrl)) {
|
||||
final int bgColor = BrowserDB.getSuggestedBackgroundColorForUrl(url);
|
||||
view.displayThumbnail(imageUrl, bgColor);
|
||||
return;
|
||||
}
|
||||
|
||||
// If thumbnails are still being loaded, don't try to load favicons
|
||||
// just yet. If we sent in a thumbnail, we're done now.
|
||||
if (mThumbnails == null || thumbnail != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -635,7 +636,15 @@ public class TopSitesPanel extends HomeFragment {
|
||||
final ArrayList<String> urls = new ArrayList<String>();
|
||||
int i = 1;
|
||||
do {
|
||||
urls.add(c.getString(col));
|
||||
final String url = c.getString(col);
|
||||
|
||||
// Only try to fetch thumbnails for URLs that don't have an
|
||||
// associated suggested image URL.
|
||||
if (BrowserDB.hasSuggestedImageUrl(url)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
urls.add(url);
|
||||
} while (i++ < mMaxGridEntries && c.moveToNext());
|
||||
|
||||
if (urls.isEmpty()) {
|
||||
|
@ -161,12 +161,6 @@ 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.IMAGE_URL));
|
||||
assertEquals("imageUrl" + position, imageUrl);
|
||||
|
||||
String bgColor = c.getString(c.getColumnIndexOrThrow(BrowserContract.SuggestedSites.BG_COLOR));
|
||||
assertEquals("bgColor" + position, bgColor);
|
||||
}
|
||||
|
||||
c.close();
|
||||
|
@ -33,9 +33,7 @@ public class TestTopSitesCursorWrapper extends BrowserTestCase {
|
||||
|
||||
private String[] SUGGESTED_SITES_COLUMNS = new String[] { SuggestedSites._ID,
|
||||
SuggestedSites.URL,
|
||||
SuggestedSites.TITLE,
|
||||
SuggestedSites.IMAGE_URL,
|
||||
SuggestedSites.BG_COLOR };
|
||||
SuggestedSites.TITLE };
|
||||
|
||||
private final int MIN_COUNT = 6;
|
||||
|
||||
@ -87,8 +85,6 @@ public class TestTopSitesCursorWrapper extends BrowserTestCase {
|
||||
row.add(-1);
|
||||
row.add(SUGGESTED_PREFIX + "url" + i);
|
||||
row.add(SUGGESTED_PREFIX + "title" + i);
|
||||
row.add(SUGGESTED_PREFIX + "imageUrl" + i);
|
||||
row.add(SUGGESTED_PREFIX + "bgColor" + i);
|
||||
}
|
||||
|
||||
return c;
|
||||
@ -231,32 +227,24 @@ public class TestTopSitesCursorWrapper extends BrowserTestCase {
|
||||
assertTrue(c.isNull(c.getColumnIndex(TopSites.DISPLAY)));
|
||||
assertTrue(c.isNull(c.getColumnIndex(TopSites.BOOKMARK_ID)));
|
||||
assertTrue(c.isNull(c.getColumnIndex(TopSites.HISTORY_ID)));
|
||||
assertTrue(c.isNull(c.getColumnIndex(TopSites.IMAGE_URL)));
|
||||
assertTrue(c.isNull(c.getColumnIndex(TopSites.BG_COLOR)));
|
||||
} else if (rowType == TopSites.TYPE_PINNED) {
|
||||
assertFalse(c.isNull(c.getColumnIndex(TopSites.URL)));
|
||||
assertFalse(c.isNull(c.getColumnIndex(TopSites.TITLE)));
|
||||
assertTrue(c.isNull(c.getColumnIndex(TopSites.DISPLAY)));
|
||||
assertTrue(c.isNull(c.getColumnIndex(TopSites.BOOKMARK_ID)));
|
||||
assertTrue(c.isNull(c.getColumnIndex(TopSites.HISTORY_ID)));
|
||||
assertTrue(c.isNull(c.getColumnIndex(TopSites.IMAGE_URL)));
|
||||
assertTrue(c.isNull(c.getColumnIndex(TopSites.BG_COLOR)));
|
||||
} else if (rowType == TopSites.TYPE_TOP) {
|
||||
assertFalse(c.isNull(c.getColumnIndex(TopSites.URL)));
|
||||
assertFalse(c.isNull(c.getColumnIndex(TopSites.TITLE)));
|
||||
assertFalse(c.isNull(c.getColumnIndex(TopSites.DISPLAY)));
|
||||
assertFalse(c.isNull(c.getColumnIndex(TopSites.BOOKMARK_ID)));
|
||||
assertFalse(c.isNull(c.getColumnIndex(TopSites.HISTORY_ID)));
|
||||
assertTrue(c.isNull(c.getColumnIndex(TopSites.IMAGE_URL)));
|
||||
assertTrue(c.isNull(c.getColumnIndex(TopSites.BG_COLOR)));
|
||||
} else if (rowType == TopSites.TYPE_SUGGESTED) {
|
||||
assertFalse(c.isNull(c.getColumnIndex(TopSites.URL)));
|
||||
assertFalse(c.isNull(c.getColumnIndex(TopSites.TITLE)));
|
||||
assertTrue(c.isNull(c.getColumnIndex(TopSites.DISPLAY)));
|
||||
assertTrue(c.isNull(c.getColumnIndex(TopSites.BOOKMARK_ID)));
|
||||
assertTrue(c.isNull(c.getColumnIndex(TopSites.HISTORY_ID)));
|
||||
assertFalse(c.isNull(c.getColumnIndex(TopSites.IMAGE_URL)));
|
||||
assertFalse(c.isNull(c.getColumnIndex(TopSites.BG_COLOR)));
|
||||
} else {
|
||||
fail("Invalid row type found in the cursor");
|
||||
}
|
||||
@ -297,7 +285,7 @@ public class TestTopSitesCursorWrapper extends BrowserTestCase {
|
||||
Integer[] pinnedPositions = new Integer[] { 0, 1, 4 };
|
||||
TopSitesCursorWrapper c = createTopSitesCursorWrapper(2, pinnedPositions, 3);
|
||||
|
||||
assertEquals(9, c.getColumnCount());
|
||||
assertEquals(7, c.getColumnCount());
|
||||
|
||||
String[] columnNames = c.getColumnNames();
|
||||
assertEquals(columnNames.length, c.getColumnCount());
|
||||
|
@ -43,7 +43,7 @@ browser.suggestedsites.list.0=mozilla
|
||||
browser.suggestedsites.list.1=fxmarketplace
|
||||
|
||||
browser.suggestedsites.mozilla.title=Mozilla
|
||||
browser.suggestedsites.mozilla.url=https://mozilla.org/en-US/
|
||||
browser.suggestedsites.mozilla.url=https://www.mozilla.org/en-US/
|
||||
browser.suggestedsites.mozilla.bgcolor=#c13832
|
||||
|
||||
browser.suggestedsites.fxmarketplace.title=Firefox Marketplace
|
||||
|
Loading…
Reference in New Issue
Block a user