Bug 925068: Bookmarks folders are lost on rotation. [r=lucasr]

--HG--
extra : rebase_source : 0337903f40ba0ead258d66730e9dc10622b5673c
This commit is contained in:
Sriram Ramasubramanian 2013-10-18 17:30:10 -07:00
Родитель 81739c1942
Коммит 8fa109e309
2 изменённых файлов: 26 добавлений и 6 удалений

Просмотреть файл

@ -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<Pair<Integer, String>> parentStack) {
// Initializing with a null cursor.
super(context, cursor, VIEW_TYPES, LAYOUT_TYPES);
mParentStack = new LinkedList<Pair<Integer, String>>();
if (parentStack == null) {
mParentStack = new LinkedList<Pair<Integer, String>>();
// Add the root folder to the stack
Pair<Integer, String> rootFolder = new Pair<Integer, String>(Bookmarks.FIXED_ROOT_ID, "");
mParentStack.addFirst(rootFolder);
// Add the root folder to the stack
Pair<Integer, String> rootFolder = new Pair<Integer, String>(Bookmarks.FIXED_ROOT_ID, "");
mParentStack.addFirst(rootFolder);
} else {
mParentStack = new LinkedList<Pair<Integer, String>>(parentStack);
}
}
public List<Pair<Integer, String>> getParentStack() {
return Collections.unmodifiableList(mParentStack);
}
// Refresh the current folder by executing a new task.

Просмотреть файл

@ -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<Pair<Integer, String>> 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)