Getting results but only from either method

This commit is contained in:
misaochan 2016-01-24 20:35:12 +13:00
parent 0203a9cdec
commit a51f4252bb

View file

@ -46,14 +46,15 @@ public class CategorizationFragment extends SherlockFragment{
TextView categoriesSkip; TextView categoriesSkip;
CategoriesAdapter categoriesAdapter; CategoriesAdapter categoriesAdapter;
PrefixUpdater lastUpdater = null;
MethodAUpdater methodAUpdater = null;
ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(2); ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(2);
private OnCategoriesSaveHandler onCategoriesSaveHandler; private OnCategoriesSaveHandler onCategoriesSaveHandler;
protected HashMap<String, ArrayList<String>> categoriesCache; protected HashMap<String, ArrayList<String>> categoriesCache;
private final Set<String> results = new LinkedHashSet<String>(); private final Set<String> results = new LinkedHashSet<String>();
PrefixUpdaterSub prefixUpdaterSub = null;
MethodAUpdaterSub methodAUpdaterSub = null;
private ContentProviderClient client; private ContentProviderClient client;
@ -110,6 +111,7 @@ public class CategorizationFragment extends SherlockFragment{
Category cat = Category.fromCursor(cursor); Category cat = Category.fromCursor(cursor);
items.add(cat.getName()); items.add(cat.getName());
} }
cursor.close();
if (MwVolleyApi.GpsCatExists.getGpsCatExists() == true){ if (MwVolleyApi.GpsCatExists.getGpsCatExists() == true){
//Log.d(TAG, "GPS cats found in CategorizationFragment.java" + MwVolleyApi.getGpsCat().toString()); //Log.d(TAG, "GPS cats found in CategorizationFragment.java" + MwVolleyApi.getGpsCat().toString());
@ -145,17 +147,10 @@ public class CategorizationFragment extends SherlockFragment{
} }
} }
//TODO: This will set items twice in Adapter. Need to be able to 'add' items to adapter instead? Need to convert LinkedHashSet to ArrayList first?
//TODO: Maybe DON'T call this Adapter method. Instead make an add(items) method that will build up the LinkedHashSet. Then move this whole thing to bottom
categoriesAdapter.setItems(items); categoriesAdapter.setItems(items);
categoriesAdapter.notifyDataSetInvalidated(); categoriesAdapter.notifyDataSetInvalidated();
categoriesSearchInProgress.setVisibility(View.GONE); categoriesSearchInProgress.setVisibility(View.GONE);
/*
itemSet.addAll(items);
Log.d(TAG, "Item Set" + itemSet.toString());
*/
if (categories.size() == 0) { if (categories.size() == 0) {
if(TextUtils.isEmpty(filter)) { if(TextUtils.isEmpty(filter)) {
// If we found no recent cats, show the skip message! // If we found no recent cats, show the skip message!
@ -335,11 +330,6 @@ public class CategorizationFragment extends SherlockFragment{
return rootView; return rootView;
} }
private void startUpdatingCategoryList() {
final CountDownLatch latch = new CountDownLatch(1); final CountDownLatch latch = new CountDownLatch(1);
class PrefixUpdaterSub extends PrefixUpdater { class PrefixUpdaterSub extends PrefixUpdater {
@ -357,6 +347,7 @@ public class CategorizationFragment extends SherlockFragment{
} }
catch (InterruptedException e) { catch (InterruptedException e) {
Log.w(TAG, e); Log.w(TAG, e);
Thread.currentThread().interrupt();
} }
return result; return result;
} }
@ -366,6 +357,7 @@ public class CategorizationFragment extends SherlockFragment{
super.onPostExecute(result); super.onPostExecute(result);
results.addAll(result); results.addAll(result);
Log.d(TAG, "Prefix result: " + result);
categoriesAdapter.notifyDataSetChanged(); categoriesAdapter.notifyDataSetChanged();
} }
} }
@ -379,30 +371,33 @@ public class CategorizationFragment extends SherlockFragment{
@Override @Override
protected void onPostExecute(ArrayList<String> result) { protected void onPostExecute(ArrayList<String> result) {
results.clear();
super.onPostExecute(result); super.onPostExecute(result);
results.clear();
results.addAll(result); results.addAll(result);
Log.d(TAG, "Method A result: " + result);
categoriesAdapter.notifyDataSetChanged(); categoriesAdapter.notifyDataSetChanged();
latch.countDown(); latch.countDown();
} }
} }
if (lastUpdater != null) { private void startUpdatingCategoryList() {
lastUpdater.cancel(true);
if (prefixUpdaterSub != null) {
prefixUpdaterSub.cancel(true);
} }
if (methodAUpdater != null) { if (methodAUpdaterSub != null) {
methodAUpdater.cancel(true); methodAUpdaterSub.cancel(true);
} }
prefixUpdaterSub = new PrefixUpdaterSub();
PrefixUpdaterSub prefixUpdaterSub = new PrefixUpdaterSub(); methodAUpdaterSub = new MethodAUpdaterSub();
MethodAUpdaterSub methodAUpdaterSub = new MethodAUpdaterSub();
Utils.executeAsyncTask(prefixUpdaterSub); Utils.executeAsyncTask(prefixUpdaterSub);
Utils.executeAsyncTask(methodAUpdaterSub); Utils.executeAsyncTask(methodAUpdaterSub);
Log.d(TAG, "Final results: " + results);
} }