Add comments and copy entire method to MethodAUpdater

This commit is contained in:
misaochan 2016-10-27 17:03:06 +13:00
parent 03b3f70ca8
commit 4ce2354cd6
2 changed files with 28 additions and 2 deletions

View file

@ -10,6 +10,7 @@ import org.mediawiki.api.MWApi;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Iterator;
import fr.free.nrw.commons.CommonsApplication;
@ -39,16 +40,34 @@ public class MethodAUpdater extends AsyncTask<Void, Void, ArrayList<String>> {
catFragment.categoriesSkip.setVisibility(View.GONE);
}
/**
* Remove categories that contain a year in them (starting with 19__ or 20__), except for this year
* and previous year
* Rationale: https://github.com/commons-app/apps-android-commons/issues/47
* @param items Unfiltered list of categories
* @return Filtered category list
*/
private ArrayList<String> filterYears(ArrayList<String> items) {
Iterator<String> iterator;
//Check for current and previous year to exclude these categories from removal
Calendar now = Calendar.getInstance();
int year = now.get(Calendar.YEAR);
String yearInString = String.valueOf(year);
Log.d(TAG, "Year: " + yearInString);
int prevYear = year - 1;
String prevYearInString = String.valueOf(prevYear);
Log.d(TAG, "Previous year: " + prevYearInString);
//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}.*")) {
//And that s does not equal the current year or previous year
if(s.matches(".*(19|20)\\d{2}.*") && !s.contains(yearInString) && !s.contains(prevYearInString)) {
Log.d(TAG, "Filtering out year " + s);
iterator.remove();
}
@ -58,7 +77,6 @@ public class MethodAUpdater extends AsyncTask<Void, Void, ArrayList<String>> {
return items;
}
@Override
protected ArrayList<String> doInBackground(Void... voids) {
//If user hasn't typed anything in yet, get GPS and recent items

View file

@ -46,10 +46,18 @@ public class PrefixUpdater extends AsyncTask<Void, Void, ArrayList<String>> {
catFragment.categoriesSkip.setVisibility(View.GONE);
}
/**
* Remove categories that contain a year in them (starting with 19__ or 20__), except for this year
* and previous year
* Rationale: https://github.com/commons-app/apps-android-commons/issues/47
* @param items Unfiltered list of categories
* @return Filtered category list
*/
private ArrayList<String> filterYears(ArrayList<String> items) {
Iterator<String> iterator;
//Check for current and previous year to exclude these categories from removal
Calendar now = Calendar.getInstance();
int year = now.get(Calendar.YEAR);
String yearInString = String.valueOf(year);