mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 12:53:55 +01:00
Improve code readability
This commit is contained in:
parent
0443f65c4a
commit
ef1fc0c9d9
3 changed files with 32 additions and 14 deletions
|
|
@ -234,8 +234,8 @@ public class CategorizationFragment extends Fragment {
|
||||||
|
|
||||||
private Observable<CategoryItem> gpsCategories() {
|
private Observable<CategoryItem> gpsCategories() {
|
||||||
return Observable.fromIterable(
|
return Observable.fromIterable(
|
||||||
MwVolleyApi.GpsCatExists.getGpsCatExists() ?
|
MwVolleyApi.GpsCatExists.getGpsCatExists()
|
||||||
MwVolleyApi.getGpsCat() : new ArrayList<>())
|
? MwVolleyApi.getGpsCat() : new ArrayList<>())
|
||||||
.map(name -> new CategoryItem(name, false));
|
.map(name -> new CategoryItem(name, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -266,7 +266,7 @@ public class CategorizationFragment extends Fragment {
|
||||||
.map(name -> new CategoryItem(name, false));
|
.map(name -> new CategoryItem(name, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
//otherwise if user has typed something in that isn't in cache, search API for matching categories
|
//otherwise, search API for matching categories
|
||||||
return CommonsApplication.getInstance().getMWApi()
|
return CommonsApplication.getInstance().getMWApi()
|
||||||
.allCategories(term, SEARCH_CATS_LIMIT)
|
.allCategories(term, SEARCH_CATS_LIMIT)
|
||||||
.map(name -> new CategoryItem(name, false));
|
.map(name -> new CategoryItem(name, false));
|
||||||
|
|
@ -283,7 +283,7 @@ public class CategorizationFragment extends Fragment {
|
||||||
.map(s -> new CategoryItem(s, false));
|
.map(s -> new CategoryItem(s, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean containsYear(String items) {
|
private boolean containsYear(String item) {
|
||||||
//Check for current and previous year to exclude these categories from removal
|
//Check for current and previous year to exclude these categories from removal
|
||||||
Calendar now = Calendar.getInstance();
|
Calendar now = Calendar.getInstance();
|
||||||
int year = now.get(Calendar.YEAR);
|
int year = now.get(Calendar.YEAR);
|
||||||
|
|
@ -293,11 +293,11 @@ public class CategorizationFragment extends Fragment {
|
||||||
String prevYearInString = String.valueOf(prevYear);
|
String prevYearInString = String.valueOf(prevYear);
|
||||||
Timber.d("Previous year: %s", prevYearInString);
|
Timber.d("Previous year: %s", prevYearInString);
|
||||||
|
|
||||||
//Check if s contains a 4-digit word anywhere within the string (.* is wildcard)
|
//Check if item contains a 4-digit word anywhere within the string (.* is wildcard)
|
||||||
//And that s does not equal the current year or previous year
|
//And that item does not equal the current year or previous year
|
||||||
//And if it is an irrelevant category such as Media_needing_categories_as_of_16_June_2017(Issue #750)
|
//And if it is an irrelevant category such as Media_needing_categories_as_of_16_June_2017(Issue #750)
|
||||||
return ((items.matches(".*(19|20)\\d{2}.*") && !items.contains(yearInString) && !items.contains(prevYearInString))
|
return ((item.matches(".*(19|20)\\d{2}.*") && !item.contains(yearInString) && !item.contains(prevYearInString))
|
||||||
|| items.matches("(.*)needing(.*)") || items.matches("(.*)taken on(.*)"));
|
|| item.matches("(.*)needing(.*)") || item.matches("(.*)taken on(.*)"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateCategoryCount(CategoryItem item, ContentProviderClient client) {
|
private void updateCategoryCount(CategoryItem item, ContentProviderClient client) {
|
||||||
|
|
@ -324,6 +324,9 @@ public class CategorizationFragment extends Fragment {
|
||||||
return selectedCategories.size();
|
return selectedCategories.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show dialog asking for confirmation to leave without saving categories.
|
||||||
|
*/
|
||||||
public void showBackButtonDialog() {
|
public void showBackButtonDialog() {
|
||||||
new AlertDialog.Builder(getActivity())
|
new AlertDialog.Builder(getActivity())
|
||||||
.setMessage("Are you sure you want to go back? The image will not "
|
.setMessage("Are you sure you want to go back? The image will not "
|
||||||
|
|
|
||||||
|
|
@ -54,8 +54,12 @@ class CategoryItem implements Parcelable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) {
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
return true;
|
||||||
|
}
|
||||||
|
if (o == null || getClass() != o.getClass()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
CategoryItem that = (CategoryItem) o;
|
CategoryItem that = (CategoryItem) o;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,12 @@ public class Category {
|
||||||
touch();
|
touch();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Database/content-provider stuff
|
//region Database/content-provider stuff
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Persist category.
|
||||||
|
* @param client ContentProviderClient to handle DB connection
|
||||||
|
*/
|
||||||
public void save(ContentProviderClient client) {
|
public void save(ContentProviderClient client) {
|
||||||
try {
|
try {
|
||||||
if (contentUri == null) {
|
if (contentUri == null) {
|
||||||
|
|
@ -78,7 +83,7 @@ public class Category {
|
||||||
return cv;
|
return cv;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Category fromCursor(Cursor cursor) {
|
private static Category fromCursor(Cursor cursor) {
|
||||||
// Hardcoding column positions!
|
// Hardcoding column positions!
|
||||||
Category c = new Category();
|
Category c = new Category();
|
||||||
c.contentUri = CategoryContentProvider.uriForId(cursor.getInt(0));
|
c.contentUri = CategoryContentProvider.uriForId(cursor.getInt(0));
|
||||||
|
|
@ -88,6 +93,12 @@ public class Category {
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find persisted category in database, based on its name.
|
||||||
|
* @param client ContentProviderClient to handle DB connection
|
||||||
|
* @param name Category's name
|
||||||
|
* @return category from database, or null if not found
|
||||||
|
*/
|
||||||
public static @Nullable Category find(ContentProviderClient client, String name) {
|
public static @Nullable Category find(ContentProviderClient client, String name) {
|
||||||
Cursor cursor = null;
|
Cursor cursor = null;
|
||||||
try {
|
try {
|
||||||
|
|
@ -112,8 +123,7 @@ public class Category {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves recently-used categories
|
* Retrieve recently-used categories, ordered by descending date.
|
||||||
*
|
|
||||||
* @return a list containing recent categories
|
* @return a list containing recent categories
|
||||||
*/
|
*/
|
||||||
public static @NonNull ArrayList<String> recentCategories(ContentProviderClient client, int limit) {
|
public static @NonNull ArrayList<String> recentCategories(ContentProviderClient client, int limit) {
|
||||||
|
|
@ -198,4 +208,5 @@ public class Category {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//endregion
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue