Bug 892500/905286 - Use FaviconsLoader in LastTabsPage (r=sriram)

This commit is contained in:
Lucas Rocha 2013-08-17 01:47:42 +01:00
parent 745ebac996
commit 92239912c9

View File

@ -19,6 +19,7 @@ import android.database.Cursor;
import android.database.MatrixCursor;
import android.database.MatrixCursor.RowBuilder;
import android.os.Bundle;
import android.support.v4.app.LoaderManager;
import android.support.v4.app.LoaderManager.LoaderCallbacks;
import android.support.v4.content.Loader;
import android.support.v4.widget.CursorAdapter;
@ -140,12 +141,14 @@ public class LastTabsPage extends HomeFragment {
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
final Activity activity = getActivity();
// Intialize adapter
mAdapter = new LastTabsAdapter(getActivity());
mAdapter = new LastTabsAdapter(activity);
mList.setAdapter(mAdapter);
// Create callbacks before the initial loader is started
mCursorLoaderCallbacks = new CursorLoaderCallbacks();
mCursorLoaderCallbacks = new CursorLoaderCallbacks(activity, getLoaderManager());
loadIfVisible();
}
@ -217,8 +220,7 @@ public class LastTabsPage extends HomeFragment {
final MatrixCursor c = new MatrixCursor(new String[] { Combined._ID,
Combined.URL,
Combined.TITLE,
Combined.FAVICON });
Combined.TITLE });
new SessionParser() {
@Override
@ -236,10 +238,6 @@ public class LastTabsPage extends HomeFragment {
final String title = tab.getTitle();
row.add(title);
final ContentResolver cr = context.getContentResolver();
final byte[] favicon = BrowserDB.getFaviconBytesForUrl(cr, url);
row.add(favicon);
}
}.parse(jsonString);
@ -263,21 +261,43 @@ public class LastTabsPage extends HomeFragment {
}
}
private class CursorLoaderCallbacks implements LoaderCallbacks<Cursor> {
private class CursorLoaderCallbacks extends HomeCursorLoaderCallbacks {
public CursorLoaderCallbacks(Context context, LoaderManager loaderManager) {
super(context, loaderManager);
}
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
return new LastTabsCursorLoader(getActivity());
if (id == LOADER_ID_LAST_TABS) {
return new LastTabsCursorLoader(getActivity());
} else {
return super.onCreateLoader(id, args);
}
}
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor c) {
mAdapter.swapCursor(c);
updateUiFromCursor(c);
if (loader.getId() == LOADER_ID_LAST_TABS) {
mAdapter.swapCursor(c);
updateUiFromCursor(c);
loadFavicons(c);
} else {
super.onLoadFinished(loader, c);
}
}
@Override
public void onLoaderReset(Loader<Cursor> loader) {
mAdapter.swapCursor(null);
if (loader.getId() == LOADER_ID_LAST_TABS) {
mAdapter.swapCursor(null);
} else {
super.onLoaderReset(loader);
}
}
@Override
public void onFaviconsLoaded() {
mAdapter.notifyDataSetChanged();
}
}
}