From 218fff34d5a6b0a7191c9a3bba403945144528c1 Mon Sep 17 00:00:00 2001 From: calderwoodra Date: Tue, 19 Sep 2017 11:20:31 -0700 Subject: Removed zero suggest from dialpad search in new search fragment. Zero suggest in dialpad search clutters the UI and we shouldn't show and search results until the user has input something into the dialpad. Additionally, this change ensures the fab stays hidden through device rotation in regular search. Bug: 65858825 Test: implemented PiperOrigin-RevId: 169270161 Change-Id: Ia08ce56ffd02f74ea9e4d9d8a1efc3726fcc66d9 --- .../searchfragment/list/NewSearchFragment.java | 20 +++++++++++++++++--- .../dialer/searchfragment/list/SearchAdapter.java | 14 ++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) (limited to 'java/com/android/dialer/searchfragment') diff --git a/java/com/android/dialer/searchfragment/list/NewSearchFragment.java b/java/com/android/dialer/searchfragment/list/NewSearchFragment.java index 036d53fb5..3cf8fb5b9 100644 --- a/java/com/android/dialer/searchfragment/list/NewSearchFragment.java +++ b/java/com/android/dialer/searchfragment/list/NewSearchFragment.java @@ -73,6 +73,8 @@ public final class NewSearchFragment extends Fragment // updates so they are bundled together private static final int ENRICHED_CALLING_CAPABILITIES_UPDATED_DELAY = 400; + private static final String KEY_SHOW_ZERO_SUGGEST = "use_zero_suggest"; + @VisibleForTesting public static final int READ_CONTACTS_PERMISSION_REQUEST_CODE = 1; private static final int CONTACTS_LOADER_ID = 0; @@ -99,6 +101,14 @@ public final class NewSearchFragment extends Fragment private Runnable updatePositionRunnable; + public static NewSearchFragment newInstance(boolean showZeroSuggest) { + NewSearchFragment fragment = new NewSearchFragment(); + Bundle args = new Bundle(); + args.putBoolean(KEY_SHOW_ZERO_SUGGEST, showZeroSuggest); + fragment.setArguments(args); + return fragment; + } + @Nullable @Override public View onCreateView( @@ -107,6 +117,7 @@ public final class NewSearchFragment extends Fragment adapter = new SearchAdapter(getActivity(), new SearchCursorManager()); adapter.setCallInitiationType(callInitiationType); adapter.setSearchActions(getActions()); + adapter.setZeroSuggestVisible(getArguments().getBoolean(KEY_SHOW_ZERO_SUGGEST)); emptyContentView = view.findViewById(R.id.empty_view); recyclerView = view.findViewById(R.id.recycler_view); recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); @@ -212,6 +223,7 @@ public final class NewSearchFragment extends Fragment adapter.setQuery(query); adapter.setCallInitiationType(callInitiationType); adapter.setSearchActions(getActions()); + adapter.setZeroSuggestVisible(isRegularSearch()); loadNearbyPlacesCursor(); loadRemoteContactsCursors(); } @@ -354,9 +366,7 @@ public final class NewSearchFragment extends Fragment * the list of supported actions, see {@link SearchActionViewHolder.Action}. */ private List getActions() { - if (TextUtils.isEmpty(query) - || query.length() == 1 - || callInitiationType == CallInitiationType.Type.REGULAR_SEARCH) { + if (TextUtils.isEmpty(query) || query.length() == 1 || isRegularSearch()) { return Collections.emptyList(); } @@ -369,4 +379,8 @@ public final class NewSearchFragment extends Fragment } return actions; } + + private boolean isRegularSearch() { + return callInitiationType == CallInitiationType.Type.REGULAR_SEARCH; + } } diff --git a/java/com/android/dialer/searchfragment/list/SearchAdapter.java b/java/com/android/dialer/searchfragment/list/SearchAdapter.java index 3bfdd98f3..d4b5cf29d 100644 --- a/java/com/android/dialer/searchfragment/list/SearchAdapter.java +++ b/java/com/android/dialer/searchfragment/list/SearchAdapter.java @@ -21,6 +21,7 @@ import android.content.Intent; import android.support.annotation.VisibleForTesting; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView.ViewHolder; +import android.text.TextUtils; import android.view.LayoutInflater; import android.view.ViewGroup; import com.android.dialer.callcomposer.CallComposerActivity; @@ -50,6 +51,7 @@ public final class SearchAdapter extends RecyclerView.Adapter private final SearchCursorManager searchCursorManager; private final Activity activity; + private boolean showZeroSuggest; private String query; private CallInitiationType.Type callInitiationType = CallInitiationType.Type.UNKNOWN_INITIATION; @@ -124,9 +126,21 @@ public final class SearchAdapter extends RecyclerView.Adapter @Override public int getItemCount() { + if (TextUtils.isEmpty(query) && !showZeroSuggest) { + return 0; + } return searchCursorManager.getCount(); } + /** + * @param visible If true and query is empty, the adapter won't show any list elements. + * @see #setQuery(String) + * @see #getItemCount() + */ + public void setZeroSuggestVisible(boolean visible) { + showZeroSuggest = visible; + } + public void setQuery(String query) { this.query = query; if (searchCursorManager.setQuery(query)) { -- cgit v1.2.3