mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 04:43:54 +01:00
Add similar method to MethodAUpdater
This commit is contained in:
parent
4c3ca2fd41
commit
b7fef046d3
2 changed files with 26 additions and 4 deletions
|
|
@ -10,6 +10,7 @@ import org.mediawiki.api.MWApi;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
import fr.free.nrw.commons.CommonsApplication;
|
import fr.free.nrw.commons.CommonsApplication;
|
||||||
|
|
||||||
|
|
@ -38,11 +39,34 @@ public class MethodAUpdater extends AsyncTask<Void, Void, ArrayList<String>> {
|
||||||
catFragment.categoriesSkip.setVisibility(View.GONE);
|
catFragment.categoriesSkip.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ArrayList<String> filterYears(ArrayList<String> items) {
|
||||||
|
|
||||||
|
Iterator<String> iterator;
|
||||||
|
|
||||||
|
//Copy to Iterator to prevent ConcurrentModificationException when removing item
|
||||||
|
for(iterator = items.iterator(); iterator.hasNext();) {
|
||||||
|
String s = iterator.next();
|
||||||
|
|
||||||
|
//Check if s contains a 4-digit word anywhere within the string (.* is wildcard)
|
||||||
|
if(s.matches(".*(19|20)\\d{2}.*")) {
|
||||||
|
Log.d(TAG, "Filtering out year " + s);
|
||||||
|
iterator.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.d(TAG, "Items: " + items.toString());
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ArrayList<String> doInBackground(Void... voids) {
|
protected ArrayList<String> doInBackground(Void... voids) {
|
||||||
//If user hasn't typed anything in yet, get GPS and recent items
|
//If user hasn't typed anything in yet, get GPS and recent items
|
||||||
if(TextUtils.isEmpty(filter)) {
|
if(TextUtils.isEmpty(filter)) {
|
||||||
return catFragment.mergeItems();
|
ArrayList<String> mergedItems = new ArrayList<String>(catFragment.mergeItems());
|
||||||
|
Log.d(TAG, "Merged items, waiting for filter");
|
||||||
|
ArrayList<String> filteredItems = new ArrayList<String>(filterYears(mergedItems));
|
||||||
|
return filteredItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
//if user types in something that is in cache, return cached category
|
//if user types in something that is in cache, return cached category
|
||||||
|
|
|
||||||
|
|
@ -31,8 +31,6 @@ public class PrefixUpdater extends AsyncTask<Void, Void, ArrayList<String>> {
|
||||||
private static final String TAG = PrefixUpdater.class.getName();
|
private static final String TAG = PrefixUpdater.class.getName();
|
||||||
private CategorizationFragment catFragment;
|
private CategorizationFragment catFragment;
|
||||||
|
|
||||||
ArrayList<String> filteredItems = new ArrayList<> ();
|
|
||||||
|
|
||||||
public PrefixUpdater(CategorizationFragment catFragment) {
|
public PrefixUpdater(CategorizationFragment catFragment) {
|
||||||
this.catFragment = catFragment;
|
this.catFragment = catFragment;
|
||||||
}
|
}
|
||||||
|
|
@ -47,7 +45,7 @@ public class PrefixUpdater extends AsyncTask<Void, Void, ArrayList<String>> {
|
||||||
catFragment.categoriesSkip.setVisibility(View.GONE);
|
catFragment.categoriesSkip.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ArrayList<String> filterYears(ArrayList<String> items) {
|
private ArrayList<String> filterYears(ArrayList<String> items) {
|
||||||
|
|
||||||
Iterator<String> iterator;
|
Iterator<String> iterator;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue