Bug 889621 - Lazy load all fragments in about:home (r=sriram)

This commit is contained in:
Lucas Rocha 2013-07-26 12:46:28 +01:00
parent 1e4abd2b5a
commit bd007fdc19
7 changed files with 47 additions and 13 deletions

View File

@ -152,11 +152,7 @@ public class BookmarksPage extends HomeFragment {
// Create callbacks before the initial loader is started.
mLoaderCallbacks = new CursorLoaderCallbacks();
mThumbnailsLoaderCallbacks = new ThumbnailsLoaderCallbacks();
// Reconnect to the loader only if present.
final LoaderManager manager = getLoaderManager();
manager.initLoader(BOOKMARKS_LIST_LOADER_ID, null, mLoaderCallbacks);
manager.initLoader(TOP_BOOKMARKS_LOADER_ID, null, mLoaderCallbacks);
loadIfVisible();
}
@Override
@ -291,6 +287,13 @@ public class BookmarksPage extends HomeFragment {
return false;
}
@Override
protected void load() {
final LoaderManager manager = getLoaderManager();
manager.initLoader(BOOKMARKS_LIST_LOADER_ID, null, mLoaderCallbacks);
manager.initLoader(TOP_BOOKMARKS_LOADER_ID, null, mLoaderCallbacks);
}
/**
* Listener for pinning bookmarks.
*/

View File

@ -246,9 +246,7 @@ public class BrowserSearch extends HomeFragment
// Create callbacks before the initial loader is started
mCursorLoaderCallbacks = new CursorLoaderCallbacks();
// Reconnect to the loader only if present
getLoaderManager().initLoader(SEARCH_LOADER_ID, null, mCursorLoaderCallbacks);
loadIfVisible();
}
@Override
@ -263,6 +261,11 @@ public class BrowserSearch extends HomeFragment
}
}
@Override
protected void load() {
getLoaderManager().initLoader(SEARCH_LOADER_ID, null, mCursorLoaderCallbacks);
}
private void handleAutocomplete(String searchTerm, Cursor c) {
if (TextUtils.isEmpty(mSearchTerm) || c == null || mAutocompleteHandler == null) {
return;

View File

@ -150,8 +150,11 @@ public class HistoryPage extends HomeFragment {
// Create callbacks before the initial loader is started
mCursorLoaderCallbacks = new CursorLoaderCallbacks();
loadIfVisible();
}
// Reconnect to the loader only if present
@Override
protected void load() {
getLoaderManager().initLoader(HISTORY_LOADER_ID, null, mCursorLoaderCallbacks);
}

View File

@ -36,7 +36,7 @@ import android.widget.Toast;
* HomeFragment is an empty fragment that can be added to the HomePager.
* Subclasses can add their own views.
*/
class HomeFragment extends Fragment {
abstract class HomeFragment extends Fragment {
// Log Tag.
private static final String LOGTAG="GeckoHomeFragment";
@ -184,4 +184,20 @@ class HomeFragment extends Fragment {
}
return false;
}
@Override
public void setUserVisibleHint (boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);
loadIfVisible();
}
protected abstract void load();
protected void loadIfVisible() {
if (!isVisible() || !getUserVisibleHint()) {
return;
}
load();
}
}

View File

@ -145,8 +145,11 @@ public class LastTabsPage extends HomeFragment {
// Create callbacks before the initial loader is started
mCursorLoaderCallbacks = new CursorLoaderCallbacks();
loadIfVisible();
}
// Reconnect to the loader only if present
@Override
protected void load() {
getLoaderManager().initLoader(LAST_TABS_LOADER_ID, null, mCursorLoaderCallbacks);
}

View File

@ -108,8 +108,11 @@ public class ReadingListPage extends HomeFragment {
// Create callbacks before the initial loader is started.
mCursorLoaderCallbacks = new CursorLoaderCallbacks();
loadIfVisible();
}
// Reconnect to the loader only if it's present.
@Override
protected void load() {
getLoaderManager().initLoader(READING_LIST_LOADER_ID, null, mCursorLoaderCallbacks);
}

View File

@ -142,8 +142,11 @@ public class VisitedPage extends HomeFragment {
// Create callbacks before the initial loader is started
mCursorLoaderCallbacks = new CursorLoaderCallbacks();
loadIfVisible();
}
// Reconnect to the loader only if present
@Override
protected void load() {
getLoaderManager().initLoader(FRECENCY_LOADER_ID, null, mCursorLoaderCallbacks);
}