mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-29 22:03:55 +01:00
Review category issues (#4897)
* Ask for category only if exists in Peer Review * Minor Fixes * Fixed wrong categories issue * Added comments * Added comments * Minor Changes * Added test * Tests * Tests * Tests
This commit is contained in:
parent
7bc78f67ff
commit
103e2d546e
9 changed files with 171 additions and 13 deletions
|
|
@ -71,6 +71,11 @@ public class ReviewActivity extends BaseActivity {
|
|||
*/
|
||||
private ReviewImageFragment reviewImageFragment;
|
||||
|
||||
/**
|
||||
* Flag to check whether there are any non-hidden categories in the File
|
||||
*/
|
||||
private boolean hasNonHiddenCategories = false;
|
||||
|
||||
final String SAVED_MEDIA = "saved_media";
|
||||
private Media media;
|
||||
|
||||
|
|
@ -153,19 +158,37 @@ public class ReviewActivity extends BaseActivity {
|
|||
|
||||
@SuppressLint("CheckResult")
|
||||
public boolean runRandomizer() {
|
||||
hasNonHiddenCategories = false;
|
||||
progressBar.setVisibility(View.VISIBLE);
|
||||
reviewPager.setCurrentItem(0);
|
||||
compositeDisposable.add(reviewHelper.getRandomMedia()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(media -> {
|
||||
reviewImageFragment = getInstanceOfReviewImageFragment();
|
||||
reviewImageFragment.disableButtons();
|
||||
updateImage(media);
|
||||
// Finds non-hidden categories from Media instance
|
||||
findNonHiddenCategories(media);
|
||||
}));
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds non-hidden categories and updates current image
|
||||
*/
|
||||
private void findNonHiddenCategories(Media media) {
|
||||
for(String key : media.getCategoriesHiddenStatus().keySet()) {
|
||||
Boolean value = media.getCategoriesHiddenStatus().get(key);
|
||||
// If non-hidden category is found then set hasNonHiddenCategories to true
|
||||
// so that category review cannot be skipped
|
||||
if(!value) {
|
||||
hasNonHiddenCategories = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
reviewImageFragment = getInstanceOfReviewImageFragment();
|
||||
reviewImageFragment.disableButtons();
|
||||
updateImage(media);
|
||||
}
|
||||
|
||||
@SuppressLint("CheckResult")
|
||||
private void updateImage(Media media) {
|
||||
this.media = media;
|
||||
|
|
@ -195,8 +218,16 @@ public class ReviewActivity extends BaseActivity {
|
|||
|
||||
public void swipeToNext() {
|
||||
int nextPos = reviewPager.getCurrentItem() + 1;
|
||||
// If currently at category fragment, then check whether the media has any non-hidden category
|
||||
if (nextPos <= 3) {
|
||||
reviewPager.setCurrentItem(nextPos);
|
||||
if (nextPos == 2) {
|
||||
// The media has no non-hidden category. Such media are already flagged by server-side bots, so no need to review manually.
|
||||
if (!hasNonHiddenCategories) {
|
||||
swipeToNext();
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
runRandomizer();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ import butterknife.OnClick;
|
|||
import fr.free.nrw.commons.Media;
|
||||
import fr.free.nrw.commons.R;
|
||||
import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ReviewImageFragment extends CommonsDaggerSupportFragment {
|
||||
|
||||
|
|
@ -52,8 +54,20 @@ public class ReviewImageFragment extends CommonsDaggerSupportFragment {
|
|||
|
||||
private String updateCategoriesQuestion() {
|
||||
Media media = getReviewActivity().getMedia();
|
||||
if (media != null && media.getCategories() != null && isAdded()) {
|
||||
String catString = TextUtils.join(", ", media.getCategories());
|
||||
if (media != null && media.getCategoriesHiddenStatus() != null && isAdded()) {
|
||||
// Filter category name attribute from all categories
|
||||
List<String> categories = new ArrayList<>();
|
||||
for(String key : media.getCategoriesHiddenStatus().keySet()) {
|
||||
String value = String.valueOf(key);
|
||||
// Each category returned has a format like "Category:<some-category-name>"
|
||||
// so remove the prefix "Category:"
|
||||
int index = key.indexOf("Category:");
|
||||
if(index == 0) {
|
||||
value = key.substring(9);
|
||||
}
|
||||
categories.add(value);
|
||||
}
|
||||
String catString = TextUtils.join(", ", categories);
|
||||
if (catString != null && !catString.equals("") && textViewQuestionContext != null) {
|
||||
catString = "<b>" + catString + "</b>";
|
||||
String stringToConvertHtml = String.format(getResources().getString(R.string.review_category_explanation), catString);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue