diff options
Diffstat (limited to 'java/com/android/dialer/searchfragment/list')
3 files changed, 31 insertions, 32 deletions
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"/> |