From 2517706323daa685779d37c56b4883334a2cb34d Mon Sep 17 00:00:00 2001 From: calderwoodra Date: Thu, 29 Mar 2018 13:58:54 -0700 Subject: Fixed a few issues in search with new nav. - back arrow in search now flips in RTL mode http://screen/1eccBLDqPp0 - search text no longer overlaps icons http://screen/Mq0omQEuZez - keyboard now always closes on pause - location permission is no longer visible in dialpad search Bug: 73088433,74784637,76117373,76440832,76441216 Test: keyboard and rtl tested manually, added test for location permission PiperOrigin-RevId: 190981686 Change-Id: Ia121d410c158df0de9cd731ab280a6d8e9b300d9 --- java/com/android/dialer/app/DialtactsActivity.java | 2 +- .../dialer/main/impl/MainSearchController.java | 27 ++++++++---- .../searchfragment/list/NewSearchFragment.java | 48 ++++++++++++++-------- .../dialer/searchfragment/list/SearchAdapter.java | 13 ------ .../list/res/layout/search_action_layout.xml | 2 +- 5 files changed, 50 insertions(+), 42 deletions(-) (limited to 'java/com/android') diff --git a/java/com/android/dialer/app/DialtactsActivity.java b/java/com/android/dialer/app/DialtactsActivity.java index 9057cd9f9..c819fecba 100644 --- a/java/com/android/dialer/app/DialtactsActivity.java +++ b/java/com/android/dialer/app/DialtactsActivity.java @@ -1130,7 +1130,7 @@ public class DialtactsActivity extends TransactionSafeActivity NewSearchFragment fragment = (NewSearchFragment) getFragmentManager().findFragmentByTag(tag); if (fragment == null) { - fragment = NewSearchFragment.newInstance(!isDialpadShown()); + fragment = NewSearchFragment.newInstance(); transaction.add(R.id.dialtacts_frame, fragment, tag); } else { transaction.show(fragment); diff --git a/java/com/android/dialer/main/impl/MainSearchController.java b/java/com/android/dialer/main/impl/MainSearchController.java index c2ff0512a..7b4bc3569 100644 --- a/java/com/android/dialer/main/impl/MainSearchController.java +++ b/java/com/android/dialer/main/impl/MainSearchController.java @@ -149,25 +149,24 @@ public class MainSearchController implements SearchBarListener { // Show Search if (searchFragment == null) { - // TODO(a bug): zero suggest results aren't actually shown but this enabled the nearby - // places promo to be shown. - searchFragment = NewSearchFragment.newInstance(/* showZeroSuggest=*/ true); + searchFragment = NewSearchFragment.newInstance(); transaction.add(R.id.search_fragment_container, searchFragment, SEARCH_FRAGMENT_TAG); transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); } else if (!isSearchVisible()) { transaction.show(searchFragment); } - searchFragment.setQuery("", CallInitiationType.Type.DIALPAD); // Show Dialpad if (getDialpadFragment() == null) { DialpadFragment dialpadFragment = new DialpadFragment(); dialpadFragment.setStartedFromNewIntent(fromNewIntent); transaction.add(R.id.dialpad_fragment_container, dialpadFragment, DIALPAD_FRAGMENT_TAG); + searchFragment.setQuery("", CallInitiationType.Type.DIALPAD); } else { DialpadFragment dialpadFragment = getDialpadFragment(); dialpadFragment.setStartedFromNewIntent(fromNewIntent); transaction.show(dialpadFragment); + searchFragment.setQuery(dialpadFragment.getQuery(), CallInitiationType.Type.DIALPAD); } transaction.commit(); @@ -258,7 +257,7 @@ public class MainSearchController implements SearchBarListener { } else { Logger.get(activity) .logImpression(DialerImpression.Type.MAIN_TOUCH_SEARCH_LIST_TO_HIDE_KEYBOARD); - toolbar.hideKeyboard(); + closeKeyboard(); } } } @@ -348,6 +347,14 @@ public class MainSearchController implements SearchBarListener { return isSearchVisible(); } + /** Closes the keyboard if necessary. */ + private void closeKeyboard() { + NewSearchFragment fragment = getSearchFragment(); + if (fragment != null && fragment.isAdded()) { + toolbar.hideKeyboard(); + } + } + /** * Opens search in regular/search bar search mode. * @@ -376,9 +383,7 @@ public class MainSearchController implements SearchBarListener { // Show Search if (searchFragment == null) { - // TODO(a bug): zero suggest results aren't actually shown but this enabled the nearby - // places promo to be shown. - searchFragment = NewSearchFragment.newInstance(true); + searchFragment = NewSearchFragment.newInstance(); transaction.add(R.id.search_fragment_container, searchFragment, SEARCH_FRAGMENT_TAG); transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); } else if (!isSearchVisible()) { @@ -446,6 +451,9 @@ public class MainSearchController implements SearchBarListener { @Override public void onActivityPause() { + LogUtil.enterBlock("MainSearchController.onActivityPause"); + closeKeyboard(); + if (closeSearchOnPause) { closeSearchOnPause = false; if (isInSearch()) { @@ -462,7 +470,7 @@ public class MainSearchController implements SearchBarListener { closeSearchOnPause = !requestingPermission; // Always hide the keyboard when the user leaves dialer (including permission requests) - toolbar.hideKeyboard(); + closeKeyboard(); } } @@ -473,6 +481,7 @@ public class MainSearchController implements SearchBarListener { @Override public void requestingPermission() { + LogUtil.enterBlock("MainSearchController.requestingPermission"); requestingPermission = true; } diff --git a/java/com/android/dialer/searchfragment/list/NewSearchFragment.java b/java/com/android/dialer/searchfragment/list/NewSearchFragment.java index 505f1c6b1..51befe822 100644 --- a/java/com/android/dialer/searchfragment/list/NewSearchFragment.java +++ b/java/com/android/dialer/searchfragment/list/NewSearchFragment.java @@ -67,7 +67,6 @@ import com.android.dialer.searchfragment.directories.DirectoriesCursorLoader.Dir import com.android.dialer.searchfragment.directories.DirectoryContactsCursorLoader; import com.android.dialer.searchfragment.list.SearchActionViewHolder.Action; import com.android.dialer.searchfragment.nearbyplaces.NearbyPlacesCursorLoader; -import com.android.dialer.storage.StorageComponent; import com.android.dialer.util.CallUtil; import com.android.dialer.util.DialerUtils; import com.android.dialer.util.PermissionsUtil; @@ -94,7 +93,6 @@ 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"; private static final String KEY_LOCATION_PROMPT_DISMISSED = "search_location_prompt_dismissed"; @VisibleForTesting public static final int READ_CONTACTS_PERMISSION_REQUEST_CODE = 1; @@ -134,12 +132,8 @@ 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; + public static NewSearchFragment newInstance() { + return new NewSearchFragment(); } @Nullable @@ -150,7 +144,7 @@ public final class NewSearchFragment extends Fragment adapter = new SearchAdapter(getContext(), new SearchCursorManager(), this); adapter.setQuery(query, rawNumber); adapter.setSearchActions(getActions()); - adapter.setZeroSuggestVisible(getArguments().getBoolean(KEY_SHOW_ZERO_SUGGEST)); + showLocationPermission(); emptyContentView = view.findViewById(R.id.empty_view); recyclerView = view.findViewById(R.id.recycler_view); recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); @@ -265,13 +259,31 @@ public final class NewSearchFragment extends Fragment if (adapter != null) { adapter.setQuery(query, rawNumber); adapter.setSearchActions(getActions()); - adapter.setZeroSuggestVisible(isRegularSearch()); + showLocationPermission(); loadCp2ContactsCursor(); loadNearbyPlacesCursor(); loadDirectoryContactsCursors(); } } + /** Returns true if the location permission was shown. */ + private boolean showLocationPermission() { + if (adapter == null) { + return false; + } + + if (PermissionsUtil.hasLocationPermissions(getContext()) + || hasBeenDismissed() + || !isRegularSearch()) { + adapter.hideLocationPermissionRequest(); + return false; + } + + adapter.showLocationPermissionRequest( + v -> requestLocationPermission(), v -> dismissLocationPermission()); + return true; + } + /** Translate the search fragment and resize it to fit on the screen. */ public void animatePosition(int start, int end, int duration) { // Called before the view is ready, prepare a runnable to run in onCreateView @@ -382,16 +394,16 @@ public final class NewSearchFragment extends Fragment *

Should not be called before finishing loading info about all directories (local and remote). */ private void loadNearbyPlacesCursor() { - if (!PermissionsUtil.hasLocationPermissions(getContext()) - && !StorageComponent.get(getContext()) - .unencryptedSharedPrefs() - .getBoolean(KEY_LOCATION_PROMPT_DISMISSED, false)) { - if (adapter != null && isRegularSearch() && !hasBeenDismissed()) { - adapter.showLocationPermissionRequest( - v -> requestLocationPermission(), v -> dismissLocationPermission()); - } + // If we're requesting the location permission, don't load nearby places cursor. + if (showLocationPermission()) { return; } + + // If the user dismissed the prompt without granting us the permission, don't load the cursor. + if (!PermissionsUtil.hasLocationPermissions(getContext())) { + return; + } + // Cancel existing load if one exists. ThreadUtil.getUiThreadHandler().removeCallbacks(loadNearbyPlacesRunnable); diff --git a/java/com/android/dialer/searchfragment/list/SearchAdapter.java b/java/com/android/dialer/searchfragment/list/SearchAdapter.java index 805eaf524..74b60c603 100644 --- a/java/com/android/dialer/searchfragment/list/SearchAdapter.java +++ b/java/com/android/dialer/searchfragment/list/SearchAdapter.java @@ -42,7 +42,6 @@ public final class SearchAdapter extends RecyclerView.Adapter { private final SearchCursorManager searchCursorManager; private final Context context; - private boolean showZeroSuggest; private String query; // Raw query number from dialpad, which may contain special character such as "+". This is used // for actions to add contact or send sms. @@ -138,21 +137,9 @@ 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, String) - * @see #getItemCount() - */ - public void setZeroSuggestVisible(boolean visible) { - showZeroSuggest = visible; - } - public void setQuery(String query, @Nullable String rawNumber) { this.query = query; this.rawNumber = rawNumber; diff --git a/java/com/android/dialer/searchfragment/list/res/layout/search_action_layout.xml b/java/com/android/dialer/searchfragment/list/res/layout/search_action_layout.xml index 99d0fbf0c..8b366fe8a 100644 --- a/java/com/android/dialer/searchfragment/list/res/layout/search_action_layout.xml +++ b/java/com/android/dialer/searchfragment/list/res/layout/search_action_layout.xml @@ -24,7 +24,7 @@ android:layout_width="48dp" android:layout_height="48dp" android:layout_marginStart="8dp" - android:layout_gravity="center_vertical" + android:layout_gravity="center_vertical|start" android:padding="12dp" android:tint="@color/dialer_theme_color"/> -- cgit v1.2.3