From d78dbf88dd17ba1661639a0bfa62a0bca5f6df04 Mon Sep 17 00:00:00 2001 From: Brandon Maxwell Date: Mon, 9 Nov 2015 13:24:57 -0800 Subject: Show blank screen when adding new blocked number -Changed BlockedListSearchFragment to save queryString in the super class, rather than duplicating logic ~ Changed BlockedListSearchFragment to show a blank screen when the user initially clicks on the 'Add number' button Bug:25568357 Change-Id: I649294ebb4ee6e96be67ee27039ac6543644f763 --- .../dialer/list/BlockedListSearchFragment.java | 48 +++++++++------------- 1 file changed, 19 insertions(+), 29 deletions(-) (limited to 'src') diff --git a/src/com/android/dialer/list/BlockedListSearchFragment.java b/src/com/android/dialer/list/BlockedListSearchFragment.java index bddd3d49d..717cf9e46 100644 --- a/src/com/android/dialer/list/BlockedListSearchFragment.java +++ b/src/com/android/dialer/list/BlockedListSearchFragment.java @@ -31,7 +31,6 @@ import android.widget.Toast; import com.android.contacts.common.GeoUtil; import com.android.contacts.common.list.ContactEntryListAdapter; -import com.android.contacts.common.list.ContactListItemView; import com.android.contacts.common.util.ContactDisplayUtils; import com.android.dialer.R; import com.android.dialer.database.FilteredNumberAsyncQueryHandler; @@ -48,22 +47,18 @@ public class BlockedListSearchFragment extends RegularSearchFragment private FilteredNumberAsyncQueryHandler mFilteredNumberAsyncQueryHandler; private EditText mSearchView; - private String mSearchQuery; private final TextWatcher mPhoneSearchQueryTextListener = new TextWatcher() { @Override - public void beforeTextChanged(CharSequence s, int start, int count, int after) { - } + public void beforeTextChanged(CharSequence s, int start, int count, int after) {} @Override public void onTextChanged(CharSequence s, int start, int before, int count) { - mSearchQuery = s.toString(); - setQueryString(mSearchQuery, false); + setQueryString(s.toString(), false); } @Override - public void afterTextChanged(Editable s) { - } + public void afterTextChanged(Editable s) {} }; private final SearchEditTextLayout.Callback mSearchLayoutCallback = @@ -82,14 +77,17 @@ public class BlockedListSearchFragment extends RegularSearchFragment public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - // Show list of all phone numbers when search query is empty. - setShowEmptyListForNullQuery(false); - + setShowEmptyListForNullQuery(true); + /* + * Pass in the empty string here so ContactEntryListFragment#setQueryString interprets it as + * an empty search query, rather than as an uninitalized value. In the latter case, the + * adapter returned by #createListAdapter is used, which populates the view with contacts. + * Passing in the empty string forces ContactEntryListFragment to interpret it as an empty + * query, which results in showing an empty view + */ + setQueryString(getQueryString() == null ? "" : getQueryString(), false); mFilteredNumberAsyncQueryHandler = new FilteredNumberAsyncQueryHandler( getContext().getContentResolver()); - if (savedInstanceState != null) { - mSearchQuery = savedInstanceState.getString(KEY_SEARCH_QUERY); - } } @Override @@ -115,8 +113,8 @@ public class BlockedListSearchFragment extends RegularSearchFragment searchEditTextLayout.findViewById(R.id.search_box_expanded) .setBackgroundColor(getContext().getResources().getColor(android.R.color.white)); - if (!TextUtils.isEmpty(mSearchQuery)) { - mSearchView.setText(mSearchQuery); + if (!TextUtils.isEmpty(getQueryString())) { + mSearchView.setText(getQueryString()); } // TODO: Don't set custom text size; use default search text size. @@ -124,22 +122,18 @@ public class BlockedListSearchFragment extends RegularSearchFragment getResources().getDimension(R.dimen.blocked_number_search_text_size)); } - @Override - public void onSaveInstanceState(Bundle outState) { - super.onSaveInstanceState(outState); - outState.putString(KEY_SEARCH_QUERY, getAdapter().getQueryString()); - } - @Override protected ContactEntryListAdapter createListAdapter() { BlockedListSearchAdapter adapter = new BlockedListSearchAdapter(getActivity()); adapter.setDisplayPhotos(true); // Don't show SIP addresses. adapter.setUseCallableUri(false); - adapter.setQueryString(mSearchQuery); + // Keep in sync with the queryString set in #onCreate + adapter.setQueryString(getQueryString() == null ? "" : getQueryString()); return adapter; } + @Override public void onItemClick(AdapterView parent, View view, int position, long id) { super.onItemClick(parent, view, position, id); @@ -152,7 +146,7 @@ public class BlockedListSearchFragment extends RegularSearchFragment case DialerPhoneNumberListAdapter.SHORTCUT_INVALID: // Handles click on a search result, either contact or nearby places result. number = adapter.getPhoneNumber(adapterPosition); - blockContactNumber(adapter, (ContactListItemView) view, number, blockId); + blockContactNumber(number, blockId); break; case DialerPhoneNumberListAdapter.SHORTCUT_BLOCK_NUMBER: // Handles click on 'Block number' shortcut to add the user query as a number. @@ -217,11 +211,7 @@ public class BlockedListSearchFragment extends RegularSearchFragment getAdapter().notifyDataSetChanged(); } - private void blockContactNumber( - final BlockedListSearchAdapter adapter, - final ContactListItemView view, - final String number, - final Integer blockId) { + private void blockContactNumber(final String number, final Integer blockId) { if (blockId != null) { Toast.makeText(getContext(), ContactDisplayUtils.getTtsSpannedPhoneNumber( getResources(), R.string.alreadyBlocked, number), -- cgit v1.2.3