Search adapter shouldnt spawn new worker threads if current ones havent finished

This commit is contained in:
Anthony Restaino 2015-01-29 21:57:39 -05:00
parent 04c4d202b2
commit 35c585b3f4

View File

@ -33,6 +33,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
private SharedPreferences mPreferences; private SharedPreferences mPreferences;
private boolean mUseGoogle = true; private boolean mUseGoogle = true;
private Context mContext; private Context mContext;
private boolean mIsExecuting = false;
private boolean mIncognito; private boolean mIncognito;
private BookmarkManager mBookmarkManager; private BookmarkManager mBookmarkManager;
private static final String ENCODING = "ISO-8859-1"; private static final String ENCODING = "ISO-8859-1";
@ -167,7 +168,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
if (query == null) { if (query == null) {
return results; return results;
} }
if (mUseGoogle && !mIncognito) { if (mUseGoogle && !mIncognito && !mIsExecuting) {
new RetrieveSearchSuggestions().execute(query); new RetrieveSearchSuggestions().execute(query);
} }
@ -222,6 +223,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
@Override @Override
protected List<HistoryItem> doInBackground(String... arg0) { protected List<HistoryItem> doInBackground(String... arg0) {
mIsExecuting = true;
if (!isNetworkConnected(mContext)) { if (!isNetworkConnected(mContext)) {
return new ArrayList<HistoryItem>(); return new ArrayList<HistoryItem>();
} }
@ -282,6 +284,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
mFilteredList = getSuggestions(); mFilteredList = getSuggestions();
notifyDataSetChanged(); notifyDataSetChanged();
} }
mIsExecuting = false;
} }
} }