summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcalderwoodra <calderwoodra@google.com>2018-03-29 22:56:09 +0000
committerandroid-build-merger <android-build-merger@google.com>2018-03-29 22:56:09 +0000
commit320bd32edf23e2cbcfde86806a47e214a7e8391b (patch)
treebe6dde42cb20f92c2e122f997406599449b32a89
parentdb0f8b54b641af6d8ec7fb02a65845055512287a (diff)
parent6745f43a15bd280f011e0bd81957e672ba0a78cb (diff)
Merge "Fixed a few issues in search with new nav."
am: 6745f43a15 Change-Id: I411b7425441557ddbfbe9b5fabd4bb296d2609b4
-rw-r--r--assets/quantum/res/drawable/quantum_ic_arrow_back_vd_theme_24.xml3
-rw-r--r--java/com/android/dialer/app/DialtactsActivity.java2
-rw-r--r--java/com/android/dialer/main/impl/MainSearchController.java27
-rw-r--r--java/com/android/dialer/searchfragment/list/NewSearchFragment.java48
-rw-r--r--java/com/android/dialer/searchfragment/list/SearchAdapter.java13
-rw-r--r--java/com/android/dialer/searchfragment/list/res/layout/search_action_layout.xml2
6 files changed, 52 insertions, 43 deletions
diff --git a/assets/quantum/res/drawable/quantum_ic_arrow_back_vd_theme_24.xml b/assets/quantum/res/drawable/quantum_ic_arrow_back_vd_theme_24.xml
index 3a85b7dd3..12db78d99 100644
--- a/assets/quantum/res/drawable/quantum_ic_arrow_back_vd_theme_24.xml
+++ b/assets/quantum/res/drawable/quantum_ic_arrow_back_vd_theme_24.xml
@@ -18,7 +18,8 @@
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0"
- android:tint="?attr/colorControlNormal">
+ android:tint="?attr/colorControlNormal"
+ android:autoMirrored="true">
<path
android:fillColor="@android:color/white"
android:pathData="M20,11H7.83l5.59,-5.59L12,4l-8,8 8,8 1.41,-1.41L7.83,13H20v-2z"/>
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
* <p>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<ViewHolder> {
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<ViewHolder> {
@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"/>