diff --git a/mobile/android/base/home/BookmarksListAdapter.java b/mobile/android/base/home/BookmarksListAdapter.java index bf2018a29d1b..ff8b4c0a700e 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 7b647d1c1e2f..46db3c07212d 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)