Fixed searchClickBackTest for MoviesActivity tests
This commit is contained in:
parent
d634d9455e
commit
9999f37869
|
@ -75,6 +75,7 @@ public abstract class AbstractCursorListFragment extends AbstractListFragment
|
||||||
private boolean supportsSearch;
|
private boolean supportsSearch;
|
||||||
|
|
||||||
private SearchView searchView;
|
private SearchView searchView;
|
||||||
|
private boolean isPaused;
|
||||||
|
|
||||||
abstract protected void onListItemClicked(View view);
|
abstract protected void onListItemClicked(View view);
|
||||||
abstract protected CursorLoader createCursorLoader();
|
abstract protected CursorLoader createCursorLoader();
|
||||||
|
@ -99,7 +100,6 @@ public abstract class AbstractCursorListFragment extends AbstractListFragment
|
||||||
@Override
|
@Override
|
||||||
public void onActivityCreated (Bundle savedInstanceState) {
|
public void onActivityCreated (Bundle savedInstanceState) {
|
||||||
super.onActivityCreated(savedInstanceState);
|
super.onActivityCreated(savedInstanceState);
|
||||||
|
|
||||||
getLoaderManager().initLoader(LOADER, null, this);
|
getLoaderManager().initLoader(LOADER, null, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,12 +113,14 @@ public abstract class AbstractCursorListFragment extends AbstractListFragment
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
bus.register(this);
|
bus.register(this);
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
isPaused = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPause() {
|
public void onPause() {
|
||||||
bus.unregister(this);
|
bus.unregister(this);
|
||||||
super.onPause();
|
super.onPause();
|
||||||
|
isPaused = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -283,6 +285,13 @@ public abstract class AbstractCursorListFragment extends AbstractListFragment
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When this fragment is paused, onQueryTextChange is called with an empty string.
|
||||||
|
* This causes problems restoring the list fragment when returning.
|
||||||
|
*/
|
||||||
|
if (isPaused)
|
||||||
|
return true;
|
||||||
|
|
||||||
searchFilter = newText;
|
searchFilter = newText;
|
||||||
|
|
||||||
restartLoader();
|
restartLoader();
|
||||||
|
@ -310,7 +319,6 @@ public abstract class AbstractCursorListFragment extends AbstractListFragment
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
@Override
|
@Override
|
||||||
public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor cursor) {
|
public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor cursor) {
|
||||||
loaderLoading = false;
|
|
||||||
((RecyclerViewCursorAdapter) getAdapter()).swapCursor(cursor);
|
((RecyclerViewCursorAdapter) getAdapter()).swapCursor(cursor);
|
||||||
if (TextUtils.isEmpty(searchFilter)) {
|
if (TextUtils.isEmpty(searchFilter)) {
|
||||||
// To prevent the empty text from appearing on the first load, set it now
|
// To prevent the empty text from appearing on the first load, set it now
|
||||||
|
@ -353,7 +361,7 @@ public abstract class AbstractCursorListFragment extends AbstractListFragment
|
||||||
searchView = (SearchView) MenuItemCompat.getActionView(searchMenuItem);
|
searchView = (SearchView) MenuItemCompat.getActionView(searchMenuItem);
|
||||||
searchView.setOnQueryTextListener(this);
|
searchView.setOnQueryTextListener(this);
|
||||||
searchView.setQueryHint(getString(R.string.action_search));
|
searchView.setQueryHint(getString(R.string.action_search));
|
||||||
if ((savedSearchFilter != null) && (!TextUtils.isEmpty(savedSearchFilter))){
|
if (!TextUtils.isEmpty(savedSearchFilter)) {
|
||||||
searchMenuItem.expandActionView();
|
searchMenuItem.expandActionView();
|
||||||
searchView.setQuery(savedSearchFilter, false);
|
searchView.setQuery(savedSearchFilter, false);
|
||||||
//noinspection RestrictedApi
|
//noinspection RestrictedApi
|
||||||
|
|
Loading…
Reference in New Issue