author | Lucas Rocha <lucasr@mozilla.com> |
Fri, 14 Jun 2013 17:35:12 +0100 | |
changeset 156247 | 621adb50d7eb3111415f7a9cc9473d53b5216314 |
parent 156246 | 1298900196328e9b950e5d1ac1f102307d4dad23 |
child 156248 | 9da587767f315bca064af24045ac2e2ef1b8d89d |
push id | 2961 |
push user | lsblakk@mozilla.com |
push date | Mon, 28 Oct 2013 21:59:28 +0000 |
treeherder | mozilla-beta@73ef4f13486f [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | sriram |
bugs | 881780 |
milestone | 24.0a1 |
first release with | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
last release without | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
--- a/mobile/android/base/home/BookmarksPage.java +++ b/mobile/android/base/home/BookmarksPage.java @@ -28,17 +28,17 @@ import android.widget.AdapterView; import android.widget.ListView; import android.widget.SimpleCursorAdapter; import java.util.LinkedList; /** * A page in about:home that displays a ListView of bookmarks. */ -public class BookmarksPage extends HomeFragment { +public class BookmarksPage extends HomeFragment implements AdapterView.OnItemClickListener { public static final String LOGTAG = "GeckoBookmarksPage"; private int mFolderId = Bookmarks.FIXED_ROOT_ID; private String mFolderTitle = ""; private BookmarksListAdapter mCursorAdapter = null; private BookmarksQueryTask mQueryTask = null; @@ -108,18 +108,17 @@ public class BookmarksPage extends HomeF // Folder title view, is always in open state. mFolderView = (BookmarkFolderView) LayoutInflater.from(getActivity()).inflate(R.layout.bookmark_folder_row, null); mFolderView.open(); // We need to add the header before we set the adapter, hence make it null refreshListWithCursor(null); - EventHandlers eventHandlers = new EventHandlers(); - mList.setOnItemClickListener(eventHandlers); + mList.setOnItemClickListener(this); mList.setOnKeyListener(GamepadUtils.getListItemClickDispatcher()); registerForContextMenu(mList); mQueryTask = new BookmarksQueryTask(); mQueryTask.execute(); } @@ -145,16 +144,54 @@ public class BookmarksPage extends HomeF if (isVisible()) { getFragmentManager().beginTransaction() .detach(this) .attach(this) .commitAllowingStateLoss(); } } + @Override + public void onItemClick(AdapterView<?> parent, View view, int position, long id) { + final ListView list = (ListView) parent; + final int headerCount = list.getHeaderViewsCount(); + + // If we tap on the header view, move back to parent folder. + if (headerCount == 1 && position == 0) { + mCursorAdapter.moveToParentFolder(); + return; + } + + final Cursor cursor = mCursorAdapter.getCursor(); + if (cursor == null) { + return; + } + + // The header view takes up a spot in the list + if (headerCount == 1) { + position--; + } + + cursor.moveToPosition(position); + + int type = cursor.getInt(cursor.getColumnIndexOrThrow(Bookmarks.TYPE)); + if (type == Bookmarks.TYPE_FOLDER) { + // If we're clicking on a folder, update adapter to move to that folder + final int folderId = cursor.getInt(cursor.getColumnIndexOrThrow(Bookmarks._ID)); + final String folderTitle = mCursorAdapter.getFolderTitle(position); + mCursorAdapter.moveToChildFolder(folderId, folderTitle); + } else { + // Otherwise, just open the URL + final String url = cursor.getString(cursor.getColumnIndexOrThrow(URLColumns.URL)); + if (mUrlOpenListener != null) { + mUrlOpenListener.onUrlOpen(url); + } + } + } + private void refreshListWithCursor(Cursor cursor) { // We need to add the header before we set the adapter, hence making it null. mList.setAdapter(null); // Add a header view based on the root folder. if (mFolderId == Bookmarks.FIXED_ROOT_ID) { if (mList.getHeaderViewsCount() == 1) { mList.removeHeaderView(mFolderView); @@ -171,59 +208,16 @@ public class BookmarksPage extends HomeF mCursorAdapter.changeCursor(cursor); mList.setAdapter(mCursorAdapter); // Reset the task. mQueryTask = null; } /** - * Internal class to handle different event listeners on the ListView. - */ - private class EventHandlers implements AdapterView.OnItemClickListener { - @Override - public void onItemClick(AdapterView<?> parent, View view, int position, long id) { - final ListView list = (ListView) parent; - final int headerCount = list.getHeaderViewsCount(); - - // If we tap on the header view, move back to parent folder. - if (headerCount == 1 && position == 0) { - mCursorAdapter.moveToParentFolder(); - return; - } - - Cursor cursor = mCursorAdapter.getCursor(); - if (cursor == null) { - return; - } - - // The header view takes up a spot in the list - if (headerCount == 1) { - position--; - } - - cursor.moveToPosition(position); - - int type = cursor.getInt(cursor.getColumnIndexOrThrow(Bookmarks.TYPE)); - if (type == Bookmarks.TYPE_FOLDER) { - // If we're clicking on a folder, update adapter to move to that folder - int folderId = cursor.getInt(cursor.getColumnIndexOrThrow(Bookmarks._ID)); - String folderTitle = mCursorAdapter.getFolderTitle(position); - mCursorAdapter.moveToChildFolder(folderId, folderTitle); - } else { - // Otherwise, just open the URL - String url = cursor.getString(cursor.getColumnIndexOrThrow(URLColumns.URL)); - if (mUrlOpenListener != null) { - mUrlOpenListener.onUrlOpen(url); - } - } - } - } - - /** * Adapter to back the ListView with a list of bookmarks. */ private class BookmarksListAdapter extends SimpleCursorAdapter { private static final int VIEW_TYPE_ITEM = 0; private static final int VIEW_TYPE_FOLDER = 1; private static final int VIEW_TYPE_COUNT = 2;