From 52521fc0adcd58a25846c53921f2ccd2b3ceb49d Mon Sep 17 00:00:00 2001 From: Sriram Ramasubramanian Date: Fri, 18 Oct 2013 17:30:10 -0700 Subject: [PATCH] Bug 925068: Bookmarks folders are lost on rotation. [r=lucasr] --HG-- extra : rebase_source : 0337903f40ba0ead258d66730e9dc10622b5673c --- .../base/home/BookmarksListAdapter.java | 20 ++++++++++++++----- mobile/android/base/home/BookmarksPage.java | 12 ++++++++++- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/mobile/android/base/home/BookmarksListAdapter.java b/mobile/android/base/home/BookmarksListAdapter.java index bf2018a29d1..ff8b4c0a700 100644 --- a/mobile/android/base/home/BookmarksListAdapter.java +++ b/mobile/android/base/home/BookmarksListAdapter.java @@ -14,6 +14,8 @@ import android.database.Cursor; import android.util.Pair; import android.view.View; +import java.util.Collections; +import java.util.List; import java.util.LinkedList; /** @@ -40,15 +42,23 @@ class BookmarksListAdapter extends MultiTypeCursorAdapter { // Refresh folder listener. private OnRefreshFolderListener mListener; - public BookmarksListAdapter(Context context, Cursor cursor) { + public BookmarksListAdapter(Context context, Cursor cursor, List> parentStack) { // Initializing with a null cursor. super(context, cursor, VIEW_TYPES, LAYOUT_TYPES); - mParentStack = new LinkedList>(); + if (parentStack == null) { + mParentStack = new LinkedList>(); - // Add the root folder to the stack - Pair rootFolder = new Pair(Bookmarks.FIXED_ROOT_ID, ""); - mParentStack.addFirst(rootFolder); + // Add the root folder to the stack + Pair rootFolder = new Pair(Bookmarks.FIXED_ROOT_ID, ""); + mParentStack.addFirst(rootFolder); + } else { + mParentStack = new LinkedList>(parentStack); + } + } + + public List> getParentStack() { + return Collections.unmodifiableList(mParentStack); } // Refresh the current folder by executing a new task. diff --git a/mobile/android/base/home/BookmarksPage.java b/mobile/android/base/home/BookmarksPage.java index 7b647d1c1e2..46db3c07212 100644 --- a/mobile/android/base/home/BookmarksPage.java +++ b/mobile/android/base/home/BookmarksPage.java @@ -18,6 +18,7 @@ import android.database.Cursor; import android.os.Bundle; import android.support.v4.app.LoaderManager.LoaderCallbacks; import android.support.v4.content.Loader; +import android.util.Pair; import android.view.LayoutInflater; import android.view.View; import android.view.ViewStub; @@ -25,6 +26,8 @@ import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; +import java.util.List; + /** * A page in about:home that displays a ListView of bookmarks. */ @@ -43,6 +46,9 @@ public class BookmarksPage extends HomeFragment { // Adapter for list of bookmarks. private BookmarksListAdapter mListAdapter; + // Adapter's parent stack. + private List> mSavedParentStack; + // Reference to the View to display when there are no results. private View mEmptyView; @@ -83,7 +89,7 @@ public class BookmarksPage extends HomeFragment { final Activity activity = getActivity(); // Setup the list adapter. - mListAdapter = new BookmarksListAdapter(activity, null); + mListAdapter = new BookmarksListAdapter(activity, null, mSavedParentStack); mListAdapter.setOnRefreshFolderListener(new OnRefreshFolderListener() { @Override public void onRefreshFolder(int folderId) { @@ -125,6 +131,10 @@ public class BookmarksPage extends HomeFragment { // be used between the Activity's onSaveInstanceState() and // onResume(). if (isVisible()) { + // The parent stack is saved just so that the folder state can be + // restored on rotation. + mSavedParentStack = mListAdapter.getParentStack(); + getFragmentManager().beginTransaction() .detach(this) .attach(this)