@@ -76,10 +76,12 @@ public static interface OnCategoriesSaveHandler {
76
76
77
77
// LHS guarantees ordered insertions, allowing for prioritized method A results
78
78
private final Set <String > results = new LinkedHashSet <String >();
79
- private final ArrayList <String > titleCatItems = new ArrayList <String >();
80
79
PrefixUpdater prefixUpdaterSub ;
81
80
MethodAUpdater methodAUpdaterSub ;
82
81
82
+ private final ArrayList <String > titleCatItems = new ArrayList <String >();
83
+ final CountDownLatch mergeLatch = new CountDownLatch (2 );
84
+
83
85
private ContentProviderClient client ;
84
86
85
87
protected final static int SEARCH_CATS_LIMIT = 25 ;
@@ -135,6 +137,7 @@ protected ArrayList<String> titleCatQuery() {
135
137
protected void onPostExecute (ArrayList <String > result ) {
136
138
super .onPostExecute (result );
137
139
titleCatItems .addAll (result );
140
+ mergeLatch .countDown ();
138
141
}
139
142
};
140
143
Utils .executeAsyncTask (titleCategoriesSub );
@@ -169,6 +172,7 @@ protected ArrayList<String> recentCatQuery() {
169
172
throw new RuntimeException (e );
170
173
}
171
174
175
+ mergeLatch .countDown ();
172
176
return items ;
173
177
}
174
178
@@ -177,6 +181,7 @@ protected ArrayList<String> recentCatQuery() {
177
181
* @return a list containing merged categories
178
182
*/
179
183
protected ArrayList <String > mergeItems () {
184
+
180
185
Set <String > mergedItems = new LinkedHashSet <String >();
181
186
182
187
if (MwVolleyApi .GpsCatExists .getGpsCatExists ()) {
@@ -192,6 +197,11 @@ protected ArrayList<String> mergeItems() {
192
197
193
198
//Needs to be an ArrayList and not a List unless we want to modify a big portion of preexisting code
194
199
ArrayList <String > mergedItemsList = new ArrayList <String >(mergedItems );
200
+ try {
201
+ mergeLatch .await ();
202
+ } catch (InterruptedException e ) {
203
+ Log .e (TAG , "Interrupted Exception: " , e );
204
+ }
195
205
return mergedItemsList ;
196
206
}
197
207
0 commit comments