Show all contacts when search query is empty.
This updates the search behavior and the add-to-favorite flow behavior
when the search query is empty.
Fixes: 140582247
Test: manually
Change-Id: I755989dc2f7bd4f347cc6fb982ec670ef962e0d3
diff --git a/src/com/android/car/dialer/ui/search/ContactResultsViewModel.java b/src/com/android/car/dialer/ui/search/ContactResultsViewModel.java
index 4710dc3..8773791 100644
--- a/src/com/android/car/dialer/ui/search/ContactResultsViewModel.java
+++ b/src/com/android/car/dialer/ui/search/ContactResultsViewModel.java
@@ -83,6 +83,8 @@
private final Context mContext;
private final SearchQueryParamProvider mSearchQueryParamProvider;
private final ObservableAsyncQuery mObservableAsyncQuery;
+ private final LiveData<String> mSearchQueryLiveData;
+ private final LiveData<List<Contact>> mContactListLiveData;
private final SharedPreferencesLiveData mSharedPreferencesLiveData;
private final Comparator<Contact> mFirstNameComparator =
(o1, o2) -> o1.compareByDisplayName(o2);
@@ -97,8 +99,10 @@
mObservableAsyncQuery = new ObservableAsyncQuery(mSearchQueryParamProvider,
context.getContentResolver(), this::onQueryFinished);
- addSource(InMemoryPhoneBook.get().getContactsLiveData(), this::onContactsChange);
- addSource(searchQueryLiveData, this::onSearchQueryChanged);
+ mContactListLiveData = InMemoryPhoneBook.get().getContactsLiveData();
+ addSource(mContactListLiveData, this::onContactsChange);
+ mSearchQueryLiveData = searchQueryLiveData;
+ addSource(mSearchQueryLiveData, this::onSearchQueryChanged);
mSharedPreferencesLiveData = sharedPreferencesLiveData;
addSource(mSharedPreferencesLiveData, this::onSortOrderChanged);
@@ -109,14 +113,15 @@
mObservableAsyncQuery.stopQuery();
setValue(Collections.emptyList());
} else {
- mObservableAsyncQuery.startQuery();
+ onSearchQueryChanged(mSearchQueryLiveData.getValue());
}
}
private void onSearchQueryChanged(String searchQuery) {
if (TextUtils.isEmpty(searchQuery)) {
mObservableAsyncQuery.stopQuery();
- setValue(Collections.emptyList());
+ List<Contact> contacts = mContactListLiveData.getValue();
+ setValue(contacts == null ? Collections.emptyList() : contacts);
} else {
mObservableAsyncQuery.startQuery();
}