Bug 721354 - Factor out code to load top sites in AboutHomeContent (r=blassey)

This commit is contained in:
Lucas Rocha 2012-01-27 10:08:21 +00:00
parent 8f355cae4b
commit 53ba5c4415

View File

@ -241,42 +241,46 @@ public class AboutHomeContent extends ScrollView {
return NUMBER_OF_COLS_PORTRAIT;
}
private void loadTopSites(Activity activity) {
if (mCursor != null)
activity.stopManagingCursor(mCursor);
// Ensure we initialize GeckoApp's startup mode in
// background thread before we use it when updating
// the top sites section layout in main thread.
final GeckoApp.StartupMode startupMode = GeckoApp.mAppContext.getStartupMode();
// The isSyncSetup method should not be called on
// UI thread as it touches disk to access a sqlite DB.
final boolean syncIsSetup = isSyncSetup();
ContentResolver resolver = GeckoApp.mAppContext.getContentResolver();
mCursor = BrowserDB.getTopSites(resolver, NUMBER_OF_TOP_SITES_PORTRAIT);
activity.startManagingCursor(mCursor);
mTopSitesAdapter = new TopSitesCursorAdapter(activity,
R.layout.abouthome_topsite_item,
mCursor,
new String[] { URLColumns.TITLE,
URLColumns.THUMBNAIL },
new int[] { R.id.title, R.id.thumbnail });
GeckoApp.mAppContext.mMainHandler.post(new Runnable() {
public void run() {
mTopSitesGrid.setNumColumns(getNumberOfColumns());
mTopSitesGrid.setAdapter(mTopSitesAdapter);
mTopSitesAdapter.setViewBinder(new TopSitesViewBinder());
updateLayout(startupMode, syncIsSetup);
}
});
}
void init(final Activity activity) {
GeckoAppShell.getHandler().post(new Runnable() {
public void run() {
if (mCursor != null)
activity.stopManagingCursor(mCursor);
// Ensure we initialize GeckoApp's startup mode in
// background thread before we use it when updating
// the top sites section layout in main thread.
final GeckoApp.StartupMode startupMode = GeckoApp.mAppContext.getStartupMode();
// The isSyncSetup method should not be called on
// UI thread as it touches disk to access a sqlite DB.
final boolean syncIsSetup = isSyncSetup();
ContentResolver resolver = GeckoApp.mAppContext.getContentResolver();
mCursor = BrowserDB.getTopSites(resolver, NUMBER_OF_TOP_SITES_PORTRAIT);
activity.startManagingCursor(mCursor);
mTopSitesAdapter = new TopSitesCursorAdapter(activity,
R.layout.abouthome_topsite_item,
mCursor,
new String[] { URLColumns.TITLE,
URLColumns.THUMBNAIL },
new int[] { R.id.title, R.id.thumbnail });
GeckoApp.mAppContext.mMainHandler.post(new Runnable() {
public void run() {
mTopSitesGrid.setNumColumns(getNumberOfColumns());
mTopSitesGrid.setAdapter(mTopSitesAdapter);
mTopSitesAdapter.setViewBinder(new TopSitesViewBinder());
updateLayout(startupMode, syncIsSetup);
}
});
loadTopSites(activity);
GeckoAppShell.getHandler().post(new Runnable() {
public void run() {