diff --git a/launcher/src/main/java/com/italankin/lnch/feature/settings/preferencesearch/PreferenceSearchFragment.java b/launcher/src/main/java/com/italankin/lnch/feature/settings/preferencesearch/PreferenceSearchFragment.java index f826f4b8..c0f38dbd 100644 --- a/launcher/src/main/java/com/italankin/lnch/feature/settings/preferencesearch/PreferenceSearchFragment.java +++ b/launcher/src/main/java/com/italankin/lnch/feature/settings/preferencesearch/PreferenceSearchFragment.java @@ -38,12 +38,16 @@ public static PreferenceSearchFragment newInstance(String requestKey) { return fragment; } + private static final String STATE_QUERY = "query"; + @InjectPresenter PreferenceSearchPresenter presenter; private LceLayout lce; private CompositeAdapter adapter; + private String currentQuery; + @ProvidePresenter PreferenceSearchPresenter providePresenter() { return LauncherApp.daggerService.presenters().preferenceSearch(); @@ -53,6 +57,7 @@ PreferenceSearchPresenter providePresenter() { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setHasOptionsMenu(true); + currentQuery = savedInstanceState != null ? savedInstanceState.getString(STATE_QUERY) : null; } @Override @@ -84,17 +89,18 @@ public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflat MenuItem actionSearchItem = menu.findItem(R.id.action_search); SearchView searchView = new SearchView( new ContextThemeWrapper(requireContext(), R.style.AppTheme_Preferences_PreferenceSearch)); + searchView.setQuery(currentQuery, false); actionSearchItem.setActionView(searchView); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { - presenter.search(query); + presenter.search(currentQuery = query); return true; } @Override public boolean onQueryTextChange(String newText) { - presenter.search(newText); + presenter.search(currentQuery = newText); return true; } }); @@ -115,6 +121,12 @@ public boolean onMenuItemActionCollapse(MenuItem item) { actionSearchItem.expandActionView(); } + @Override + public void onSaveInstanceState(@NonNull Bundle outState) { + super.onSaveInstanceState(outState); + outState.putString(currentQuery, STATE_QUERY); + } + @Override public void onSearchResults(List items) { adapter.setDataset(items);