Bug 866150 - Revert TopSitesView cleaup changes from bug 865060. r=bnicholson

This commit is contained in:
Margaret Leibovic 2013-04-29 17:18:26 -07:00
parent 1c937d07c6
commit 9d69f0a406

View File

@ -194,43 +194,46 @@ public class TopSitesView extends GridView {
}
public void loadTopSites() {
final ContentResolver resolver = mContext.getContentResolver();
final Cursor oldCursor = (mTopSitesAdapter != null) ? mTopSitesAdapter.getCursor() : null;
new UiAsyncTask<Void, Void, Cursor>(ThreadUtils.getBackgroundHandler()) {
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
protected Cursor doInBackground(Void... params) {
return BrowserDB.getTopSites(resolver, mNumberOfTopSites);
public void run() {
final ContentResolver resolver = mContext.getContentResolver();
// Swap in the new cursor.
final Cursor oldCursor = (mTopSitesAdapter != null) ? mTopSitesAdapter.getCursor() : null;
final Cursor newCursor = BrowserDB.getTopSites(resolver, mNumberOfTopSites);
post(new Runnable() {
@Override
public void run() {
if (mTopSitesAdapter == null) {
mTopSitesAdapter = new TopSitesCursorAdapter(mContext,
R.layout.abouthome_topsite_item,
newCursor,
new String[] { URLColumns.TITLE },
new int[] { R.id.title });
setAdapter(mTopSitesAdapter);
} else {
mTopSitesAdapter.changeCursor(newCursor);
}
if (mTopSitesAdapter.getCount() > 0)
loadTopSitesThumbnails(resolver);
// Free the old Cursor in the right thread now.
if (oldCursor != null && !oldCursor.isClosed())
oldCursor.close();
// Even if AboutHome isn't necessarily entirely loaded if we
// get here, for phones this is the part the user initially sees,
// so it's the one we will care about for now.
if (mLoadCompleteListener != null)
mLoadCompleteListener.onAboutHomeLoadComplete();
}
});
}
@Override
protected void onPostExecute(Cursor newCursor) {
if (mTopSitesAdapter == null) {
mTopSitesAdapter = new TopSitesCursorAdapter(mContext,
R.layout.abouthome_topsite_item,
newCursor,
new String[] { URLColumns.TITLE },
new int[] { R.id.title });
setAdapter(mTopSitesAdapter);
} else {
mTopSitesAdapter.changeCursor(newCursor);
}
if (mTopSitesAdapter.getCount() > 0)
loadTopSitesThumbnails(resolver);
// Free the old Cursor in the right thread now.
if (oldCursor != null && !oldCursor.isClosed())
oldCursor.close();
// Even if AboutHome isn't necessarily entirely loaded if we
// get here, for phones this is the part the user initially sees,
// so it's the one we will care about for now.
if (mLoadCompleteListener != null)
mLoadCompleteListener.onAboutHomeLoadComplete();
}
}.execute();
});
}
@Override
@ -328,23 +331,18 @@ public class TopSitesView extends GridView {
}
private void loadTopSitesThumbnails(final ContentResolver cr) {
final List<String> urls = getTopSitesUrls();
if (urls.size() == 0)
return;
(new UiAsyncTask<Void, Void, Map<String, Bitmap> >(ThreadUtils.getBackgroundHandler()) {
@Override
public Map<String, Bitmap> doInBackground(Void... params) {
final List<String> urls = getTopSitesUrls();
if (urls.size() == 0) {
return null;
}
return getThumbnailsFromCursor(BrowserDB.getThumbnailsForUrls(cr, urls));
}
@Override
public void onPostExecute(Map<String, Bitmap> thumbnails) {
if (thumbnails == null) {
return;
}
// If we're waiting for a layout to happen, the GridView may be
// stale, so store the pending thumbnails here. They will be
// shown on the next layout pass.