mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 12:53:55 +01:00
* updated addCategory()method * update addCategory()method * add unit test for none category * add comments to addCategory()method * update comments * update comments for addCategory()method
This commit is contained in:
parent
79086fe942
commit
b2a901b9b3
2 changed files with 46 additions and 7 deletions
|
|
@ -62,16 +62,27 @@ public class CategoryEditHelper {
|
|||
final String wikiText) {
|
||||
Timber.d("thread is category adding %s", Thread.currentThread().getName());
|
||||
String summary = "Adding categories";
|
||||
|
||||
final StringBuilder buffer = new StringBuilder();
|
||||
|
||||
final String wikiTextWithoutCategory
|
||||
= wikiText.substring(0, wikiText.indexOf("[[Category"));
|
||||
|
||||
if (categories != null && categories.size() != 0) {
|
||||
final String wikiTextWithoutCategory;
|
||||
//If the picture was uploaded without a category, the wikitext will contain "Uncategorized" instead of "[[Category"
|
||||
if (wikiText.contains("Uncategorized")) {
|
||||
wikiTextWithoutCategory = wikiText.substring(0, wikiText.indexOf("Uncategorized"));
|
||||
} else if (wikiText.contains("[[Category")) {
|
||||
wikiTextWithoutCategory = wikiText.substring(0, wikiText.indexOf("[[Category"));
|
||||
} else {
|
||||
wikiTextWithoutCategory = "";
|
||||
}
|
||||
if (categories != null && !categories.isEmpty()) {
|
||||
//If the categories list is empty, when reading the categories of a picture,
|
||||
// the code will add "None selected" to categories list in order to see in picture's categories with "None selected".
|
||||
// So that after selected some category,"None selected" should be removed from list
|
||||
for (int i = 0; i < categories.size(); i++) {
|
||||
buffer.append("[[Category:").append(categories.get(i)).append("]]\n");
|
||||
if (!categories.get(i).equals("None selected")//Not to add "None selected" as category to wikiText
|
||||
|| !wikiText.contains("Uncategorized")) {
|
||||
buffer.append("[[Category:").append(categories.get(i)).append("]]\n");
|
||||
}
|
||||
}
|
||||
categories.remove("None selected");
|
||||
} else {
|
||||
buffer.append("{{subst:unc}}");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue