From bd007fdc197fb46ccf58ab61351fde997c2d9835 Mon Sep 17 00:00:00 2001 From: Lucas Rocha Date: Fri, 26 Jul 2013 12:46:28 +0100 Subject: [PATCH] Bug 889621 - Lazy load all fragments in about:home (r=sriram) --- mobile/android/base/home/BookmarksPage.java | 13 ++++++++----- mobile/android/base/home/BrowserSearch.java | 9 ++++++--- mobile/android/base/home/HistoryPage.java | 5 ++++- mobile/android/base/home/HomeFragment.java | 18 +++++++++++++++++- mobile/android/base/home/LastTabsPage.java | 5 ++++- mobile/android/base/home/ReadingListPage.java | 5 ++++- mobile/android/base/home/VisitedPage.java | 5 ++++- 7 files changed, 47 insertions(+), 13 deletions(-) diff --git a/mobile/android/base/home/BookmarksPage.java b/mobile/android/base/home/BookmarksPage.java index bf7410c6af8..521c8f54616 100644 --- a/mobile/android/base/home/BookmarksPage.java +++ b/mobile/android/base/home/BookmarksPage.java @@ -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. */ diff --git a/mobile/android/base/home/BrowserSearch.java b/mobile/android/base/home/BrowserSearch.java index cca4176fc7f..058885ccbe0 100644 --- a/mobile/android/base/home/BrowserSearch.java +++ b/mobile/android/base/home/BrowserSearch.java @@ -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; diff --git a/mobile/android/base/home/HistoryPage.java b/mobile/android/base/home/HistoryPage.java index fbabba4ec8b..8dc494f14ac 100644 --- a/mobile/android/base/home/HistoryPage.java +++ b/mobile/android/base/home/HistoryPage.java @@ -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); } diff --git a/mobile/android/base/home/HomeFragment.java b/mobile/android/base/home/HomeFragment.java index 9e150f05833..296bab150d3 100644 --- a/mobile/android/base/home/HomeFragment.java +++ b/mobile/android/base/home/HomeFragment.java @@ -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(); + } } diff --git a/mobile/android/base/home/LastTabsPage.java b/mobile/android/base/home/LastTabsPage.java index c9d59aa0d80..a95bb54784d 100644 --- a/mobile/android/base/home/LastTabsPage.java +++ b/mobile/android/base/home/LastTabsPage.java @@ -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); } diff --git a/mobile/android/base/home/ReadingListPage.java b/mobile/android/base/home/ReadingListPage.java index decbe24e898..9c133ffbaf2 100644 --- a/mobile/android/base/home/ReadingListPage.java +++ b/mobile/android/base/home/ReadingListPage.java @@ -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); } diff --git a/mobile/android/base/home/VisitedPage.java b/mobile/android/base/home/VisitedPage.java index 69deb27f1f1..691fcb3bd6e 100644 --- a/mobile/android/base/home/VisitedPage.java +++ b/mobile/android/base/home/VisitedPage.java @@ -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); }