Bug 906718 - Pressing BACK should move the user up in the bookmark folder hierarchy. r=sriram

This commit is contained in:
Margaret Leibovic 2013-08-21 11:33:43 -07:00
parent 9a243a50e9
commit 2716baa06c
2 changed files with 33 additions and 12 deletions

View File

@ -60,13 +60,18 @@ class BookmarksListAdapter extends MultiTypeCursorAdapter {
/**
* Moves to parent folder, if one exists.
*
* @return Whether the adapter successfully moved to a parent folder.
*/
public void moveToParentFolder() {
public boolean moveToParentFolder() {
// If we're already at the root, we can't move to a parent folder
if (mParentStack.size() != 1) {
mParentStack.removeFirst();
refreshCurrentFolder();
if (mParentStack.size() == 1) {
return false;
}
mParentStack.removeFirst();
refreshCurrentFolder();
return true;
}
/**

View File

@ -13,6 +13,7 @@ import org.mozilla.gecko.home.HomePager.OnUrlOpenListener;
import android.content.Context;
import android.database.Cursor;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
@ -56,6 +57,17 @@ public class BookmarksListView extends HomeListView
super.onAttachedToWindow();
setOnItemClickListener(this);
setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
// If the user hit the BACK key, try to move to the parent folder.
if (keyCode == KeyEvent.KEYCODE_BACK) {
return getBookmarksListAdapter().moveToParentFolder();
}
return false;
}
});
}
@Override
@ -101,14 +113,7 @@ public class BookmarksListView extends HomeListView
// Absolute position for the adapter.
position -= headerCount;
BookmarksListAdapter adapter;
ListAdapter listAdapter = getAdapter();
if (listAdapter instanceof HeaderViewListAdapter) {
adapter = (BookmarksListAdapter) ((HeaderViewListAdapter) listAdapter).getWrappedAdapter();
} else {
adapter = (BookmarksListAdapter) listAdapter;
}
final BookmarksListAdapter adapter = getBookmarksListAdapter();
if (adapter.isShowingChildFolder()) {
if (position == 0) {
// If we tap on an opened folder, move back to parent folder.
@ -141,4 +146,15 @@ public class BookmarksListView extends HomeListView
getOnUrlOpenListener().onUrlOpen(url, EnumSet.of(OnUrlOpenListener.Flags.ALLOW_SWITCH_TO_TAB));
}
}
private BookmarksListAdapter getBookmarksListAdapter() {
BookmarksListAdapter adapter;
ListAdapter listAdapter = getAdapter();
if (listAdapter instanceof HeaderViewListAdapter) {
adapter = (BookmarksListAdapter) ((HeaderViewListAdapter) listAdapter).getWrappedAdapter();
} else {
adapter = (BookmarksListAdapter) listAdapter;
}
return adapter;
}
}