Bug 938141 - Avoid showing favicons before the thumbnails are loaded (r=rnewman)

This commit is contained in:
Lucas Rocha 2013-11-22 14:35:27 +00:00
Родитель 926ef6a763
Коммит f79900bf50
2 изменённых файлов: 32 добавлений и 3 удалений

Просмотреть файл

@ -48,6 +48,9 @@ public class TopSitesGridItemView extends RelativeLayout {
// Pinned state.
private boolean mIsPinned = false;
// Dirty state.
private boolean mIsDirty = false;
// Empty state.
private boolean mIsEmpty = true;
private int mLoadId = Favicons.NOT_LOADING;
@ -146,6 +149,10 @@ public class TopSitesGridItemView extends RelativeLayout {
displayThumbnail(R.drawable.top_site_add);
}
public void markAsDirty() {
mIsDirty = true;
}
/**
* Updates the title, URL, and pinned state of this view.
*
@ -184,6 +191,12 @@ public class TopSitesGridItemView extends RelativeLayout {
changed = true;
}
// The dirty state forces the state update to return true
// so that the adapter loads favicons once the thumbnails
// are loaded in TopSitesPage/TopSitesGridAdapter.
changed = (changed || mIsDirty);
mIsDirty = false;
return changed;
}

Просмотреть файл

@ -558,6 +558,17 @@ public class TopSitesPage extends HomeFragment {
*/
public void updateThumbnails(Map<String, Bitmap> thumbnails) {
mThumbnails = thumbnails;
final int count = mGrid.getChildCount();
for (int i = 0; i < count; i++) {
TopSitesGridItemView gridItem = (TopSitesGridItemView) mGrid.getChildAt(i);
// All the views have already got their initial state at this point.
// This will force each view to load favicons for the missing
// thumbnails if necessary.
gridItem.markAsDirty();
}
notifyDataSetChanged();
}
@ -578,7 +589,11 @@ public class TopSitesPage extends HomeFragment {
// If there is no url, then show "add bookmark".
if (TextUtils.isEmpty(url)) {
view.blankOut();
// Wait until thumbnails are loaded before showing anything.
if (mThumbnails != null) {
view.blankOut();
}
return;
}
@ -589,8 +604,9 @@ public class TopSitesPage extends HomeFragment {
// fetches.
final boolean updated = view.updateState(title, url, pinned, thumbnail);
// If we sent in a thumbnail, we're done now.
if (thumbnail != null) {
// 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;
}