| Index: chrome/android/java/src/org/chromium/chrome/browser/bookmarks/BookmarkManager.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/bookmarks/BookmarkManager.java b/chrome/android/java/src/org/chromium/chrome/browser/bookmarks/BookmarkManager.java
|
| index 2ac93fbb8153af21fdb33597ba24c467f67fc8e8..833188b58325d9a149055ffc88d78418b91526c7 100644
|
| --- a/chrome/android/java/src/org/chromium/chrome/browser/bookmarks/BookmarkManager.java
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/bookmarks/BookmarkManager.java
|
| @@ -7,14 +7,13 @@ package org.chromium.chrome.browser.bookmarks;
|
| import android.app.Activity;
|
| import android.app.ActivityManager;
|
| import android.content.Context;
|
| +import android.support.v4.view.GravityCompat;
|
| import android.support.v4.widget.DrawerLayout;
|
| import android.support.v7.widget.RecyclerView;
|
| import android.support.v7.widget.Toolbar;
|
| import android.text.TextUtils;
|
| -import android.view.Gravity;
|
| import android.view.View;
|
| import android.view.ViewGroup;
|
| -import android.widget.ViewSwitcher;
|
|
|
| import org.chromium.base.ApiCompatibilityUtils;
|
| import org.chromium.base.ContextUtils;
|
| @@ -29,6 +28,7 @@ import org.chromium.chrome.browser.partnerbookmarks.PartnerBookmarksShim;
|
| import org.chromium.chrome.browser.profiles.Profile;
|
| import org.chromium.chrome.browser.snackbar.SnackbarManager.SnackbarManageable;
|
| import org.chromium.chrome.browser.widget.selection.SelectableListLayout;
|
| +import org.chromium.chrome.browser.widget.selection.SelectableListToolbar.SearchDelegate;
|
| import org.chromium.chrome.browser.widget.selection.SelectionDelegate;
|
| import org.chromium.components.bookmarks.BookmarkId;
|
|
|
| @@ -39,9 +39,15 @@ import java.util.Stack;
|
| * views and shared logics between tablet and phone. For tablet/phone specific logics, see
|
| * {@link BookmarkActivity} (phone) and {@link BookmarkPage} (tablet).
|
| */
|
| -public class BookmarkManager implements BookmarkDelegate {
|
| +public class BookmarkManager implements BookmarkDelegate, SearchDelegate {
|
| private static final int FAVICON_MAX_CACHE_SIZE_BYTES = 10 * 1024 * 1024; // 10MB
|
|
|
| + /**
|
| + * This shared preference used to be used to save a list of recent searches. That feature
|
| + * has been removed, so this string is now used solely to clear the shared preference.
|
| + */
|
| + private static final String PREF_SEARCH_HISTORY = "bookmark_search_history";
|
| +
|
| private Activity mActivity;
|
| private ViewGroup mMainView;
|
| private BookmarkModel mBookmarkModel;
|
| @@ -53,8 +59,6 @@ public class BookmarkManager implements BookmarkDelegate {
|
| private RecyclerView mRecyclerView;
|
| private BookmarkItemsAdapter mAdapter;
|
| private BookmarkActionBar mToolbar;
|
| - private BookmarkSearchView mSearchView;
|
| - private ViewSwitcher mViewSwitcher;
|
| private DrawerLayout mDrawer;
|
| private BookmarkDrawerListView mDrawerListView;
|
| private SelectionDelegate<BookmarkId> mSelectionDelegate;
|
| @@ -102,7 +106,6 @@ public class BookmarkManager implements BookmarkDelegate {
|
| private final Runnable mModelLoadedRunnable = new Runnable() {
|
| @Override
|
| public void run() {
|
| - mSearchView.onBookmarkDelegateInitialized(BookmarkManager.this);
|
| mDrawerListView.onBookmarkDelegateInitialized(BookmarkManager.this);
|
| mAdapter.onBookmarkDelegateInitialized(BookmarkManager.this);
|
| mToolbar.onBookmarkDelegateInitialized(BookmarkManager.this);
|
| @@ -144,8 +147,7 @@ public class BookmarkManager implements BookmarkDelegate {
|
| mSelectableListLayout.initializeEmptyView(
|
| ApiCompatibilityUtils.getDrawable(
|
| mActivity.getResources(), R.drawable.bookmark_logo_large),
|
| - R.string.bookmarks_folder_empty,
|
| - 0 /* Bookmarks search is not yet controlled by the SelectableListLayout. */);
|
| + R.string.bookmarks_folder_empty, R.string.bookmark_no_result);
|
|
|
| mAdapter = new BookmarkItemsAdapter(activity);
|
|
|
| @@ -154,11 +156,11 @@ public class BookmarkManager implements BookmarkDelegate {
|
| mToolbar = (BookmarkActionBar) mSelectableListLayout.initializeToolbar(
|
| R.layout.bookmark_action_bar, mSelectionDelegate, 0, mDrawer,
|
| R.id.normal_menu_group, R.id.selection_mode_menu_group, null, true, null);
|
| + mToolbar.initializeSearchView(
|
| + this, R.string.bookmark_action_bar_search, R.id.search_menu_id);
|
|
|
| - mViewSwitcher = (ViewSwitcher) mMainView.findViewById(R.id.bookmark_view_switcher);
|
| mUndoController = new BookmarkUndoController(activity, mBookmarkModel,
|
| ((SnackbarManageable) activity).getSnackbarManager());
|
| - mSearchView = (BookmarkSearchView) getView().findViewById(R.id.bookmark_search_view);
|
| mBookmarkModel.addObserver(mBookmarkModelObserver);
|
| initializeToLoadingState();
|
| mBookmarkModel.runAfterBookmarkModelLoaded(mModelLoadedRunnable);
|
| @@ -179,6 +181,10 @@ public class BookmarkManager implements BookmarkDelegate {
|
| if (!isDialogUi) {
|
| RecordUserAction.record("MobileBookmarkManagerPageOpen");
|
| }
|
| +
|
| + // TODO(twellington): Remove this when Chrome version 59 is a distant memory and users
|
| + // are unlikely to have the old PREF_SEARCH_HISTORY in shared preferences.
|
| + ContextUtils.getAppSharedPreferences().edit().remove(PREF_SEARCH_HISTORY).apply();
|
| }
|
|
|
| /**
|
| @@ -207,8 +213,8 @@ public class BookmarkManager implements BookmarkDelegate {
|
| */
|
| public boolean onBackPressed() {
|
| if (doesDrawerExist()) {
|
| - if (mDrawer.isDrawerVisible(Gravity.START)) {
|
| - mDrawer.closeDrawer(Gravity.START);
|
| + if (mDrawer.isDrawerVisible(GravityCompat.START)) {
|
| + mDrawer.closeDrawer(GravityCompat.START);
|
| return true;
|
| }
|
| }
|
| @@ -347,7 +353,7 @@ public class BookmarkManager implements BookmarkDelegate {
|
|
|
| @Override
|
| public void openFolder(BookmarkId folder) {
|
| - closeSearchUI();
|
| + mToolbar.hideSearchView();
|
| setState(BookmarkUIState.createFolderState(folder, mBookmarkModel));
|
| mRecyclerView.scrollToPosition(0);
|
| }
|
| @@ -369,6 +375,9 @@ public class BookmarkManager implements BookmarkDelegate {
|
| // UIObservers, which means that there will be no observers at the time. Do nothing.
|
| assert mUIObservers.isEmpty();
|
| break;
|
| + case BookmarkUIState.STATE_SEARCHING:
|
| + observer.onSearchStateSet();
|
| + break;
|
| default:
|
| assert false : "State not valid";
|
| break;
|
| @@ -384,7 +393,7 @@ public class BookmarkManager implements BookmarkDelegate {
|
| public void closeDrawer() {
|
| if (!doesDrawerExist()) return;
|
|
|
| - mDrawer.closeDrawer(Gravity.START);
|
| + mDrawer.closeDrawer(GravityCompat.START);
|
| }
|
|
|
| @Override
|
| @@ -403,14 +412,22 @@ public class BookmarkManager implements BookmarkDelegate {
|
|
|
| @Override
|
| public void openSearchUI() {
|
| - // Give search view focus, because it needs to handle back key event.
|
| - mViewSwitcher.showNext();
|
| + mSelectableListLayout.onStartSearch();
|
| + mToolbar.showSearchView();
|
| + setState(BookmarkUIState.createSearchState());
|
| }
|
|
|
| @Override
|
| public void closeSearchUI() {
|
| - if (mSearchView.getVisibility() != View.VISIBLE) return;
|
| - mViewSwitcher.showPrevious();
|
| + mSelectableListLayout.onEndSearch();
|
| +
|
| + // Pop the search state off the stack.
|
| + mStateStack.pop();
|
| +
|
| + // Set the state back to the folder that was previously being viewed. Listeners, including
|
| + // the BookmarkItemsAdapter, will be notified of the change and the list of bookmarks will
|
| + // be updated.
|
| + setState(mStateStack.pop());
|
| }
|
|
|
| @Override
|
| @@ -438,4 +455,16 @@ public class BookmarkManager implements BookmarkDelegate {
|
| public LargeIconBridge getLargeIconBridge() {
|
| return mLargeIconBridge;
|
| }
|
| +
|
| + // SearchDelegate overrides
|
| +
|
| + @Override
|
| + public void onSearchTextChanged(String query) {
|
| + mAdapter.search(query);
|
| + }
|
| +
|
| + @Override
|
| + public void onEndSearch() {
|
| + closeSearchUI();
|
| + }
|
| }
|
|
|