From ce74fab07cf450576412faa3edb875fdaa670ebe Mon Sep 17 00:00:00 2001 From: Lucas Rocha Date: Thu, 29 May 2014 13:04:36 +0100 Subject: [PATCH] Bug 1009587 - Part 5: Don't try to load thumbnails for blank urls (r=mfinkle) --- mobile/android/base/home/TopSitesPanel.java | 26 +++++++++++++-------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/mobile/android/base/home/TopSitesPanel.java b/mobile/android/base/home/TopSitesPanel.java index cb75c30a89dc..a7d426d50752 100644 --- a/mobile/android/base/home/TopSitesPanel.java +++ b/mobile/android/base/home/TopSitesPanel.java @@ -419,6 +419,16 @@ public class TopSitesPanel extends HomeFragment { mList.setHeaderDividersEnabled(c != null && c.getCount() > mMaxGridEntries); } + private void updateUiWithThumbnails(Map thumbnails) { + if (mGridAdapter != null) { + mGridAdapter.updateThumbnails(thumbnails); + } + + // Once thumbnails have finished loading, the UI is ready. Reset + // Gecko to normal priority. + ThreadUtils.resetGeckoPriority(); + } + private static class TopSitesLoader extends SimpleCursorLoader { // Max number of search results private static final int SEARCH_LIMIT = 30; @@ -638,9 +648,9 @@ public class TopSitesPanel extends HomeFragment { do { 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)) { + // 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)) { continue; } @@ -648,6 +658,8 @@ public class TopSitesPanel extends HomeFragment { } while (i++ < mMaxGridEntries && c.moveToNext()); if (urls.isEmpty()) { + // Short-circuit empty results to the UI. + updateUiWithThumbnails(new HashMap()); return; } @@ -785,13 +797,7 @@ public class TopSitesPanel extends HomeFragment { @Override public void onLoadFinished(Loader> loader, Map thumbnails) { - if (mGridAdapter != null) { - mGridAdapter.updateThumbnails(thumbnails); - } - - // Once thumbnails have finished loading, the UI is ready. Reset - // Gecko to normal priority. - ThreadUtils.resetGeckoPriority(); + updateUiWithThumbnails(thumbnails); } @Override