From df06af5411002174c6aeb653ca7790f202284de6 Mon Sep 17 00:00:00 2001 From: calderwoodra Date: Mon, 18 Sep 2017 14:26:14 -0700 Subject: Now persist state through configuration changes in Search. This CL adds logic to persist the search query and call initiation type through configuration changes like device rotation. list of bugs: https://docs.google.com/document/d/1GajzkAqXXRqbj_-qeYeDxIKr0fPsSZC3nXhRkIQg5tE/edit#heading=h.bopot1qivvxg Bug: 65751247 Test: NSFT PiperOrigin-RevId: 169146766 Change-Id: I7a68c01d5698c07a362ad621642a9138fd9a9aaa --- .../dialer/searchfragment/list/NewSearchFragment.java | 18 +++++++++++++++++- .../dialer/searchfragment/list/SearchAdapter.java | 7 +++++-- 2 files changed, 22 insertions(+), 3 deletions(-) (limited to 'java') diff --git a/java/com/android/dialer/searchfragment/list/NewSearchFragment.java b/java/com/android/dialer/searchfragment/list/NewSearchFragment.java index 2527b87ee..036d53fb5 100644 --- a/java/com/android/dialer/searchfragment/list/NewSearchFragment.java +++ b/java/com/android/dialer/searchfragment/list/NewSearchFragment.java @@ -80,6 +80,9 @@ public final class NewSearchFragment extends Fragment private static final int REMOTE_DIRECTORIES_LOADER_ID = 2; private static final int REMOTE_CONTACTS_LOADER_ID = 3; + private static final String KEY_QUERY = "key_query"; + private static final String KEY_CALL_INITIATION_TYPE = "key_call_initiation_type"; + private EmptyContentView emptyContentView; private RecyclerView recyclerView; private SearchAdapter adapter; @@ -99,7 +102,7 @@ public final class NewSearchFragment extends Fragment @Nullable @Override public View onCreateView( - LayoutInflater inflater, @Nullable ViewGroup parent, @Nullable Bundle bundle) { + LayoutInflater inflater, @Nullable ViewGroup parent, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_search, parent, false); adapter = new SearchAdapter(getActivity(), new SearchCursorManager()); adapter.setCallInitiationType(callInitiationType); @@ -119,12 +122,25 @@ public final class NewSearchFragment extends Fragment initLoaders(); } + if (savedInstanceState != null) { + setQuery( + savedInstanceState.getString(KEY_QUERY), + CallInitiationType.Type.forNumber(savedInstanceState.getInt(KEY_CALL_INITIATION_TYPE))); + } + if (updatePositionRunnable != null) { ViewUtil.doOnPreDraw(view, false, updatePositionRunnable); } return view; } + @Override + public void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + outState.putInt(KEY_CALL_INITIATION_TYPE, callInitiationType.getNumber()); + outState.putString(KEY_QUERY, query); + } + private void initLoaders() { getLoaderManager().initLoader(CONTACTS_LOADER_ID, null, this); loadRemoteDirectoriesCursor(); diff --git a/java/com/android/dialer/searchfragment/list/SearchAdapter.java b/java/com/android/dialer/searchfragment/list/SearchAdapter.java index 61055a0c1..3bfdd98f3 100644 --- a/java/com/android/dialer/searchfragment/list/SearchAdapter.java +++ b/java/com/android/dialer/searchfragment/list/SearchAdapter.java @@ -111,8 +111,11 @@ public final class SearchAdapter extends RecyclerView.Adapter } public void setContactsCursor(SearchCursor cursor) { - searchCursorManager.setContactsCursor(cursor); - notifyDataSetChanged(); + if (searchCursorManager.setContactsCursor(cursor)) { + // Since this is a new contacts cursor, we need to reapply the filter. + searchCursorManager.setQuery(query); + notifyDataSetChanged(); + } } void clear() { -- cgit v1.2.3