зеркало из https://github.com/mozilla/gecko-dev.git
Bug 927371 - Remove performEmptySearch from SearchLoader (r=sriram)
This commit is contained in:
Родитель
26aa2a1462
Коммит
b31e473437
|
@ -321,7 +321,7 @@ public class BrowserSearch extends HomeFragment
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void load() {
|
protected void load() {
|
||||||
SearchLoader.init(getLoaderManager(), LOADER_ID_SEARCH, mCursorLoaderCallbacks, mSearchTerm, false);
|
SearchLoader.init(getLoaderManager(), LOADER_ID_SEARCH, mCursorLoaderCallbacks, mSearchTerm);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleAutocomplete(String searchTerm, Cursor c) {
|
private void handleAutocomplete(String searchTerm, Cursor c) {
|
||||||
|
@ -612,7 +612,7 @@ public class BrowserSearch extends HomeFragment
|
||||||
mAdapter.notifyDataSetChanged();
|
mAdapter.notifyDataSetChanged();
|
||||||
|
|
||||||
// Restart loaders with the new search term
|
// Restart loaders with the new search term
|
||||||
SearchLoader.restart(getLoaderManager(), LOADER_ID_SEARCH, mCursorLoaderCallbacks, mSearchTerm, false);
|
SearchLoader.restart(getLoaderManager(), LOADER_ID_SEARCH, mCursorLoaderCallbacks, mSearchTerm);
|
||||||
filterSuggestions();
|
filterSuggestions();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,44 +22,34 @@ class SearchLoader {
|
||||||
// Key for search terms
|
// Key for search terms
|
||||||
private static final String KEY_SEARCH_TERM = "search_term";
|
private static final String KEY_SEARCH_TERM = "search_term";
|
||||||
|
|
||||||
// Key for performing empty search
|
|
||||||
private static final String KEY_PERFORM_EMPTY_SEARCH = "perform_empty_search";
|
|
||||||
|
|
||||||
private SearchLoader() {
|
private SearchLoader() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Loader<Cursor> createInstance(Context context, Bundle args) {
|
public static Loader<Cursor> createInstance(Context context, Bundle args) {
|
||||||
if (args != null) {
|
if (args != null) {
|
||||||
final String searchTerm = args.getString(KEY_SEARCH_TERM);
|
final String searchTerm = args.getString(KEY_SEARCH_TERM);
|
||||||
final boolean performEmptySearch = args.getBoolean(KEY_PERFORM_EMPTY_SEARCH, false);
|
return new SearchCursorLoader(context, searchTerm);
|
||||||
return new SearchCursorLoader(context, searchTerm, performEmptySearch);
|
|
||||||
} else {
|
} else {
|
||||||
return new SearchCursorLoader(context, "", false);
|
return new SearchCursorLoader(context, "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Bundle createArgs(String searchTerm, boolean performEmptySearch) {
|
private static Bundle createArgs(String searchTerm) {
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
args.putString(SearchLoader.KEY_SEARCH_TERM, searchTerm);
|
args.putString(SearchLoader.KEY_SEARCH_TERM, searchTerm);
|
||||||
args.putBoolean(SearchLoader.KEY_PERFORM_EMPTY_SEARCH, performEmptySearch);
|
|
||||||
|
|
||||||
return args;
|
return args;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void init(LoaderManager manager, int loaderId,
|
public static void init(LoaderManager manager, int loaderId,
|
||||||
LoaderCallbacks<Cursor> callbacks, String searchTerm, boolean performEmptySearch) {
|
LoaderCallbacks<Cursor> callbacks, String searchTerm) {
|
||||||
Bundle args = createArgs(searchTerm, performEmptySearch);
|
final Bundle args = createArgs(searchTerm);
|
||||||
manager.initLoader(loaderId, args, callbacks);
|
manager.initLoader(loaderId, args, callbacks);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void restart(LoaderManager manager, int loaderId,
|
public static void restart(LoaderManager manager, int loaderId,
|
||||||
LoaderCallbacks<Cursor> callbacks, String searchTerm) {
|
LoaderCallbacks<Cursor> callbacks, String searchTerm) {
|
||||||
restart(manager, loaderId, callbacks, searchTerm, true);
|
final Bundle args = createArgs(searchTerm);
|
||||||
}
|
|
||||||
|
|
||||||
public static void restart(LoaderManager manager, int loaderId,
|
|
||||||
LoaderCallbacks<Cursor> callbacks, String searchTerm, boolean performEmptySearch) {
|
|
||||||
Bundle args = createArgs(searchTerm, performEmptySearch);
|
|
||||||
manager.restartLoader(loaderId, args, callbacks);
|
manager.restartLoader(loaderId, args, callbacks);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,21 +60,13 @@ class SearchLoader {
|
||||||
// The target search term associated with the loader
|
// The target search term associated with the loader
|
||||||
private final String mSearchTerm;
|
private final String mSearchTerm;
|
||||||
|
|
||||||
// An empty search on the DB
|
public SearchCursorLoader(Context context, String searchTerm) {
|
||||||
private final boolean mPerformEmptySearch;
|
|
||||||
|
|
||||||
public SearchCursorLoader(Context context, String searchTerm, boolean performEmptySearch) {
|
|
||||||
super(context);
|
super(context);
|
||||||
mSearchTerm = searchTerm;
|
mSearchTerm = searchTerm;
|
||||||
mPerformEmptySearch = performEmptySearch;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Cursor loadCursor() {
|
public Cursor loadCursor() {
|
||||||
if (!mPerformEmptySearch && TextUtils.isEmpty(mSearchTerm)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return BrowserDB.filter(getContext().getContentResolver(), mSearchTerm, SEARCH_LIMIT);
|
return BrowserDB.filter(getContext().getContentResolver(), mSearchTerm, SEARCH_LIMIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче