Skip to content

Commit fc20178

Browse files
committed
Add latch to wait for title results
1 parent 5254f7a commit fc20178

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

app/src/main/java/fr/free/nrw/commons/category/CategorizationFragment.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,12 @@ public static interface OnCategoriesSaveHandler {
7676

7777
// LHS guarantees ordered insertions, allowing for prioritized method A results
7878
private final Set<String> results = new LinkedHashSet<String>();
79-
private final ArrayList<String> titleCatItems = new ArrayList<String>();
8079
PrefixUpdater prefixUpdaterSub;
8180
MethodAUpdater methodAUpdaterSub;
8281

82+
private final ArrayList<String> titleCatItems = new ArrayList<String>();
83+
final CountDownLatch mergeLatch = new CountDownLatch(2);
84+
8385
private ContentProviderClient client;
8486

8587
protected final static int SEARCH_CATS_LIMIT = 25;
@@ -135,6 +137,7 @@ protected ArrayList<String> titleCatQuery() {
135137
protected void onPostExecute(ArrayList<String> result) {
136138
super.onPostExecute(result);
137139
titleCatItems.addAll(result);
140+
mergeLatch.countDown();
138141
}
139142
};
140143
Utils.executeAsyncTask(titleCategoriesSub);
@@ -169,6 +172,7 @@ protected ArrayList<String> recentCatQuery() {
169172
throw new RuntimeException(e);
170173
}
171174

175+
mergeLatch.countDown();
172176
return items;
173177
}
174178

@@ -177,6 +181,7 @@ protected ArrayList<String> recentCatQuery() {
177181
* @return a list containing merged categories
178182
*/
179183
protected ArrayList<String> mergeItems() {
184+
180185
Set<String> mergedItems = new LinkedHashSet<String>();
181186

182187
if (MwVolleyApi.GpsCatExists.getGpsCatExists()) {
@@ -192,6 +197,11 @@ protected ArrayList<String> mergeItems() {
192197

193198
//Needs to be an ArrayList and not a List unless we want to modify a big portion of preexisting code
194199
ArrayList<String> mergedItemsList = new ArrayList<String>(mergedItems);
200+
try {
201+
mergeLatch.await();
202+
} catch (InterruptedException e) {
203+
Log.e(TAG, "Interrupted Exception: ", e);
204+
}
195205
return mergedItemsList;
196206
}
197207

0 commit comments

Comments
 (0)