@Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { // Adjust the item position to account for the parent folder row that is inserted // at the top of the list when viewing the contents of a folder. final BookmarksListAdapter adapter = getBookmarksListAdapter(); if (adapter.isShowingChildFolder()) { position--; } return super.onItemLongClick(parent, view, position, id); }
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); final Activity activity = getActivity(); // Setup the list adapter. mListAdapter = new BookmarksListAdapter(activity, null, mSavedParentStack); mListAdapter.setOnRefreshFolderListener( new OnRefreshFolderListener() { @Override public void onRefreshFolder(FolderInfo folderInfo, RefreshType refreshType) { // Restart the loader with folder as the argument. Bundle bundle = new Bundle(); bundle.putParcelable(BOOKMARKS_FOLDER_INFO, folderInfo); bundle.putParcelable(BOOKMARKS_REFRESH_TYPE, refreshType); getLoaderManager().restartLoader(LOADER_ID_BOOKMARKS_LIST, bundle, mLoaderCallbacks); } }); mList.setAdapter(mListAdapter); // Create callbacks before the initial loader is started. mLoaderCallbacks = new CursorLoaderCallbacks(); loadIfVisible(); }
@Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); // Reattach the fragment, forcing a reinflation of its view. // We use commitAllowingStateLoss() instead of commit() here to avoid // an IllegalStateException. If the phone is rotated while Fennec // is in the background, onConfigurationChanged() is fired. // onConfigurationChanged() is called before onResume(), so // using commit() would throw an IllegalStateException since it can't // 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).commitAllowingStateLoss(); } }
@Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { final ListView list = (ListView) parent; final int headerCount = list.getHeaderViewsCount(); if (position < headerCount) { // The click is on a header, don't do anything. return; } // Absolute position for the adapter. position -= headerCount; final BookmarksListAdapter adapter = getBookmarksListAdapter(); if (adapter.isShowingChildFolder()) { if (position == 0) { // If we tap on an opened folder, move back to parent folder. adapter.moveToParentFolder(); return; } // Accounting for the folder view. position--; } final Cursor cursor = adapter.getCursor(); if (cursor == null) { return; } 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 = adapter.getFolderTitle(parent.getContext(), cursor); adapter.moveToChildFolder(folderId, folderTitle); } else { // Otherwise, just open the URL final String url = cursor.getString(cursor.getColumnIndexOrThrow(URLColumns.URL)); // This item is a TwoLinePageRow, so we allow switch-to-tab. getOnUrlOpenListener() .onUrlOpen(url, EnumSet.of(OnUrlOpenListener.Flags.ALLOW_SWITCH_TO_TAB)); } }