Make everyting work

This commit is contained in:
neslihanturan 2018-05-20 12:18:10 +03:00 committed by maskara
parent d20cc99378
commit b1ec15a447
6 changed files with 85 additions and 29 deletions

View file

@ -27,6 +27,7 @@ import fr.free.nrw.commons.R;
import fr.free.nrw.commons.auth.SessionManager;
import fr.free.nrw.commons.di.ApplicationlessInjection;
import fr.free.nrw.commons.mwapi.MediaWikiApi;
import fr.free.nrw.commons.review.ReviewActivity;
import timber.log.Timber;
import static android.support.v4.app.NotificationCompat.DEFAULT_ALL;
@ -194,6 +195,8 @@ public class DeleteTask extends AsyncTask<Void, Integer, Boolean> {
alert.setPositiveButton(R.string.ok, (dialog, whichButton) -> {
String reason = input.getText().toString();
((ReviewActivity)context).reviewController.swipeToNext();
DeleteTask deleteTask = new DeleteTask(context, media, reason);
deleteTask.execute();
});

View file

@ -5,22 +5,29 @@ import android.support.v4.view.ViewPager;
import java.util.ArrayList;
import javax.inject.Inject;
import fr.free.nrw.commons.Media;
import fr.free.nrw.commons.R;
import fr.free.nrw.commons.delete.DeleteTask;
/**
* Created by root on 19.05.2018.
* Created by nes on 19.05.2018.
*/
public class ReviewController implements ReviewActivity.ReviewCallback {
public class ReviewController {
public static String fileName;
protected static ArrayList<String> categories;
ReviewPagerAdapter reviewPagerAdapter;
ViewPager viewPager;
ReviewActivity reviewActivity;
ReviewController(Context context) {
reviewPagerAdapter = ((ReviewActivity)context).reviewPagerAdapter;
reviewActivity = (ReviewActivity)context;
reviewPagerAdapter = reviewActivity.reviewPagerAdapter;
viewPager = ((ReviewActivity)context).pager;
}
@Override
public void onImageRefreshed(String fileName) {
ReviewController.fileName = fileName;
ReviewController.categories = new ArrayList<>();
@ -30,33 +37,37 @@ public class ReviewController implements ReviewActivity.ReviewCallback {
ReviewController.categories = categories;
}
@Override
public void onQuestionChanged() {
public void swipeToNext() {
int nextPos = viewPager.getCurrentItem()+1;
if (nextPos <= 3) {
viewPager.setCurrentItem(nextPos);
} else {
reviewPagerAdapter.getItem(0);
reviewActivity.runRandomizer();
}
}
@Override
public void onSurveyFinished() {
public void reportSpam() {
DeleteTask.askReasonAndExecute(new Media(fileName),
reviewActivity,
reviewActivity.getResources().getString(R.string.review_spam_report_question),
reviewActivity.getResources().getString(R.string.review_spam_report_default_answer));
}
@Override
public void onImproperImageReported() {
public void reportPossibleCopyRightViolation() {
DeleteTask.askReasonAndExecute(new Media(fileName),
reviewActivity,
reviewActivity.getResources().getString(R.string.review_c_violation_report_question),
reviewActivity.getResources().getString(R.string.review_c_violation_report_default_answer));
}
@Override
public void onLicenceViolationReported() {
public void reportWrongCategory() {
new CheckCategoryTask(reviewActivity, new Media(fileName)).execute();
swipeToNext();
}
@Override
public void onWrongCategoryReported() {
}
@Override
public void onThankSent() {
public void sendThanks() {
new SendThankTask(reviewActivity, new Media(fileName));
swipeToNext();
}
}

View file

@ -8,6 +8,7 @@ import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.TableLayout;
@ -20,6 +21,7 @@ import java.util.ArrayList;
import fr.free.nrw.commons.R;
import fr.free.nrw.commons.Utils;
import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
import fr.free.nrw.commons.utils.ViewUtil;
/**
* Created by root on 19.05.2018.
@ -30,15 +32,22 @@ public class ReviewImageFragment extends CommonsDaggerSupportFragment {
public static final int SPAM = 0;
public static final int COPYRIGHT = 1;
public static final int CATEGORY = 2;
public static final int THANKS = 3;
private int position;
private String fileName;
private String catString;
private View textViewQuestionContext;
private View textViewQuestion;
private SimpleDraweeView simpleDraweeView;
private Button yesButton;
private Button noButton;
public ProgressBar progressBar;
public void update(int position, String fileName) {
this.position = position;
this.fileName = fileName;
@ -74,24 +83,46 @@ public class ReviewImageFragment extends CommonsDaggerSupportFragment {
View layoutView = inflater.inflate(R.layout.fragment_review_image, container,
false);
progressBar = layoutView.findViewById(R.id.progressBar);
View textView = layoutView.findViewById(R.id.reviewQuestion);
textViewQuestion = layoutView.findViewById(R.id.reviewQuestion);
textViewQuestionContext = layoutView.findViewById(R.id.reviewQuestionContext);
yesButton = layoutView.findViewById(R.id.yesButton);
noButton = layoutView.findViewById(R.id.noButton);
String question;
switch(position) {
case COPYRIGHT:
question = getString(R.string.review_copyright);
yesButton.setOnClickListener(view -> {
((ReviewActivity)getActivity()).reviewController.reportPossibleCopyRightViolation();
});
break;
case CATEGORY:
question = getString(R.string.review_category);
updateCategories(ReviewController.categories);
yesButton.setOnClickListener(view -> {
((ReviewActivity)getActivity()).reviewController.reportWrongCategory();
});
break;
case SPAM:
question = getString(R.string.review_spam);
yesButton.setOnClickListener(view -> {
((ReviewActivity)getActivity()).reviewController.reportSpam();
});
break;
case THANKS:
question = getString(R.string.review_thanks);
yesButton.setOnClickListener(view -> {
((ReviewActivity)getActivity()).reviewController.sendThanks();
});
break;
default:
question = "How did we get here?";
}
((TextView) textView).setText(question);
noButton.setOnClickListener(view -> {
((ReviewActivity)getActivity()).reviewController.swipeToNext();
});
((TextView) textViewQuestion).setText(question);
simpleDraweeView = layoutView.findViewById(R.id.imageView);
if (fileName != null) {

View file

@ -25,7 +25,7 @@ public class ReviewPagerAdapter extends FragmentStatePagerAdapter {
@Override
public int getCount() {
return 3;
return 4;
}
public void updateFilename() {

View file

@ -7,6 +7,8 @@ import android.support.v4.app.NotificationCompat;
import android.view.Gravity;
import android.widget.Toast;
import java.io.IOException;
import javax.inject.Inject;
import fr.free.nrw.commons.Media;
@ -45,10 +47,14 @@ public class SendThankTask extends AsyncTask<Void, Integer, Boolean> {
private Media media;
private String revision;
public SendThankTask(Context context, Media media, String revision){
public SendThankTask(Context context, Media media){
this.context = context;
this.media = media;
this.revision = revision;
try {
this.revision = mwApi.firstRevisionOfFile(media.getFilename());
} catch (IOException e) {
e.printStackTrace();
}
}
@Override

View file

@ -480,7 +480,12 @@ Upload your first media by touching the camera or gallery icon above.</string>
<string name="review_copyright">Is this a copyright violation?</string>
<string name="review_category">Is this mis-categorized?</string>
<string name="review_spam">Is this spam?</string>
<string name="review_thanks">Would you like to thank to contributor?</string>
<string name="review_no_category">This image is uncategorized</string>
<string name="review_category_explanation">This image is under %1$s categories.</string>
<string name="review_spam_report_question">Why do you think this is out of scope?</string>
<string name="review_spam_report_default_answer">Because it is a selfie, very blurry or has nonsense etc.</string>
<string name="review_c_violation_report_question">Why do you think this is copyright violation?</string>
<string name="review_c_violation_report_default_answer">Because it looks like a press photo, a random photo from internet, a famous brand logo etc.</string>
</resources>