mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Ensure caption is shown on every review fragment
This commit is contained in:
parent
1183476bca
commit
83f4407ed3
6 changed files with 141 additions and 128 deletions
|
|
@ -618,7 +618,8 @@ public class ApacheHttpClientMediaWikiApi implements MediaWikiApi {
|
|||
.get();
|
||||
return new Revision(
|
||||
res.getString("/api/query/pages/page/revisions/rev/@revid"),
|
||||
res.getString("/api/query/pages/page/revisions/rev/@user"));
|
||||
res.getString("/api/query/pages/page/revisions/rev/@user"),
|
||||
filename);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,15 @@
|
|||
package fr.free.nrw.commons.mwapi;
|
||||
|
||||
public class Revision {
|
||||
public String revisionId;
|
||||
public String username;
|
||||
import fr.free.nrw.commons.PageTitle;
|
||||
|
||||
public Revision(String revisionId, String username) {
|
||||
public class Revision {
|
||||
public final String revisionId;
|
||||
public final String username;
|
||||
public final PageTitle pageTitle;
|
||||
|
||||
public Revision(String revisionId, String username, String pageTitle) {
|
||||
this.revisionId = revisionId;
|
||||
this.username = username;
|
||||
this.pageTitle = new PageTitle(pageTitle);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,22 +5,16 @@ import android.content.Intent;
|
|||
import android.os.Bundle;
|
||||
|
||||
import android.support.design.widget.NavigationView;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.widget.ProgressBar;
|
||||
|
||||
import com.viewpagerindicator.CirclePageIndicator;
|
||||
|
||||
import org.mediawiki.api.MWApi;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
|
@ -140,7 +134,13 @@ public class ReviewActivity extends AuthenticatedActivity {
|
|||
return;
|
||||
}
|
||||
reviewController.onImageRefreshed(fileName); //file name is updated
|
||||
reviewPagerAdapter.updateFilename();
|
||||
mwApi.firstRevisionOfFile("File:" + fileName)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(revision -> {
|
||||
reviewController.firstRevision = revision;
|
||||
reviewPagerAdapter.updateFileInformation(fileName, revision);
|
||||
});
|
||||
reviewPager.setCurrentItem(0);
|
||||
Observable.fromCallable(() -> {
|
||||
MediaResult media = mwApi.fetchMediaByFilename("File:" + fileName);
|
||||
|
|
@ -150,12 +150,6 @@ public class ReviewActivity extends AuthenticatedActivity {
|
|||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(this::updateCategories, this::categoryFetchError);
|
||||
|
||||
mwApi.firstRevisionOfFile("File:" + fileName).subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(revision -> {
|
||||
ReviewController.firstRevision = revision;
|
||||
((ReviewImageFragment)reviewPagerAdapter.getItem(reviewPager.getCurrentItem())).updateImageCaption();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package fr.free.nrw.commons.review;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.view.ViewPager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -17,12 +18,14 @@ import io.reactivex.schedulers.Schedulers;
|
|||
*/
|
||||
|
||||
public class ReviewController {
|
||||
public static String fileName;
|
||||
public static Revision firstRevision; // TODO: maybe we can expand this class to include fileName
|
||||
private String fileName;
|
||||
@Nullable
|
||||
public Revision firstRevision; // TODO: maybe we can expand this class to include fileName
|
||||
protected static ArrayList<String> categories;
|
||||
ReviewPagerAdapter reviewPagerAdapter;
|
||||
ViewPager viewPager;
|
||||
ReviewActivity reviewActivity;
|
||||
|
||||
private ReviewPagerAdapter reviewPagerAdapter;
|
||||
private ViewPager viewPager;
|
||||
private ReviewActivity reviewActivity;
|
||||
|
||||
ReviewController(Context context) {
|
||||
reviewActivity = (ReviewActivity)context;
|
||||
|
|
@ -31,7 +34,7 @@ public class ReviewController {
|
|||
}
|
||||
|
||||
public void onImageRefreshed(String fileName) {
|
||||
ReviewController.fileName = fileName;
|
||||
this.fileName = fileName;
|
||||
ReviewController.categories = new ArrayList<>();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import com.facebook.drawee.view.SimpleDraweeView;
|
|||
import fr.free.nrw.commons.R;
|
||||
import fr.free.nrw.commons.Utils;
|
||||
import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
|
||||
import fr.free.nrw.commons.mwapi.Revision;
|
||||
|
||||
/**
|
||||
* Created by root on 19.05.2018.
|
||||
|
|
@ -22,119 +23,128 @@ import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
|
|||
|
||||
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;
|
||||
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 int position;
|
||||
private String fileName;
|
||||
private String catString;
|
||||
|
||||
private View textViewQuestionContext;
|
||||
private View imageCaption;
|
||||
private View textViewQuestion;
|
||||
private SimpleDraweeView simpleDraweeView;
|
||||
private View textViewQuestionContext;
|
||||
private View imageCaption;
|
||||
private View textViewQuestion;
|
||||
private SimpleDraweeView simpleDraweeView;
|
||||
|
||||
private Button yesButton;
|
||||
private Button noButton;
|
||||
private Button yesButton;
|
||||
private Button noButton;
|
||||
|
||||
public ProgressBar progressBar;
|
||||
public ProgressBar progressBar;
|
||||
private Revision revision;
|
||||
|
||||
|
||||
public void update(int position, String fileName) {
|
||||
this.position = position;
|
||||
this.fileName = fileName;
|
||||
public void update(int position, String fileName, Revision revision) {
|
||||
this.position = position;
|
||||
this.fileName = fileName;
|
||||
this.revision = revision;
|
||||
|
||||
if (simpleDraweeView!=null) {
|
||||
simpleDraweeView.setImageURI(Utils.makeThumbBaseUrl(fileName));
|
||||
progressBar.setVisibility(View.GONE);
|
||||
fillImageCaption();
|
||||
|
||||
if (simpleDraweeView != null) {
|
||||
simpleDraweeView.setImageURI(Utils.makeThumbBaseUrl(fileName));
|
||||
progressBar.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateCategories(Iterable<String> categories) {
|
||||
if (categories != null && isAdded()) {
|
||||
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);
|
||||
((TextView) textViewQuestionContext).setText(Html.fromHtml(stringToConvertHtml));
|
||||
} else if (textViewQuestionContext != null) {
|
||||
((TextView) textViewQuestionContext).setText(getResources().getString(R.string.review_no_category));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void updateCategories(Iterable<String> categories) {
|
||||
if (categories!=null && isAdded()) {
|
||||
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);
|
||||
((TextView) textViewQuestionContext).setText(Html.fromHtml(stringToConvertHtml));
|
||||
} else if (textViewQuestionContext != null) {
|
||||
((TextView)textViewQuestionContext).setText(getResources().getString(R.string.review_no_category));
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
position = getArguments().getInt("position");
|
||||
View layoutView = inflater.inflate(R.layout.fragment_review_image, container,
|
||||
false);
|
||||
progressBar = layoutView.findViewById(R.id.progressBar);
|
||||
textViewQuestion = layoutView.findViewById(R.id.reviewQuestion);
|
||||
textViewQuestionContext = layoutView.findViewById(R.id.reviewQuestionContext);
|
||||
imageCaption = layoutView.findViewById(R.id.imageCaption);
|
||||
yesButton = layoutView.findViewById(R.id.yesButton);
|
||||
noButton = layoutView.findViewById(R.id.noButton);
|
||||
|
||||
fillImageCaption();
|
||||
|
||||
String question, explanation;
|
||||
switch (position) {
|
||||
case COPYRIGHT:
|
||||
question = getString(R.string.review_copyright);
|
||||
explanation = getString(R.string.review_copyright_explanation);
|
||||
yesButton.setOnClickListener(view -> {
|
||||
((ReviewActivity) getActivity()).reviewController.reportPossibleCopyRightViolation();
|
||||
});
|
||||
break;
|
||||
case CATEGORY:
|
||||
question = getString(R.string.review_category);
|
||||
explanation = getString(R.string.review_no_category);
|
||||
updateCategories(ReviewController.categories);
|
||||
yesButton.setOnClickListener(view -> {
|
||||
((ReviewActivity) getActivity()).reviewController.reportWrongCategory();
|
||||
});
|
||||
break;
|
||||
case SPAM:
|
||||
question = getString(R.string.review_spam);
|
||||
explanation = getString(R.string.review_spam_explanation);
|
||||
yesButton.setOnClickListener(view -> {
|
||||
((ReviewActivity) getActivity()).reviewController.reportSpam();
|
||||
});
|
||||
break;
|
||||
case THANKS:
|
||||
question = getString(R.string.review_thanks);
|
||||
explanation = getString(R.string.review_thanks_explanation, ((ReviewActivity) getActivity()).reviewController.firstRevision.username);
|
||||
yesButton.setOnClickListener(view -> {
|
||||
((ReviewActivity) getActivity()).reviewController.sendThanks();
|
||||
});
|
||||
break;
|
||||
default:
|
||||
question = "How did we get here?";
|
||||
explanation = "No idea.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
noButton.setOnClickListener(view -> {
|
||||
((ReviewActivity) getActivity()).reviewController.swipeToNext();
|
||||
});
|
||||
|
||||
((TextView) textViewQuestion).setText(question);
|
||||
((TextView) textViewQuestionContext).setText(explanation);
|
||||
|
||||
simpleDraweeView = layoutView.findViewById(R.id.imageView);
|
||||
|
||||
if (fileName != null) {
|
||||
simpleDraweeView.setImageURI(Utils.makeThumbBaseUrl(fileName));
|
||||
progressBar.setVisibility(View.GONE);
|
||||
}
|
||||
return layoutView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
position = getArguments().getInt("position");
|
||||
View layoutView = inflater.inflate(R.layout.fragment_review_image, container,
|
||||
false);
|
||||
progressBar = layoutView.findViewById(R.id.progressBar);
|
||||
textViewQuestion = layoutView.findViewById(R.id.reviewQuestion);
|
||||
textViewQuestionContext = layoutView.findViewById(R.id.reviewQuestionContext);
|
||||
imageCaption = layoutView.findViewById(R.id.imageCaption);
|
||||
yesButton = layoutView.findViewById(R.id.yesButton);
|
||||
noButton = layoutView.findViewById(R.id.noButton);
|
||||
String question, explanation;
|
||||
switch(position) {
|
||||
case COPYRIGHT:
|
||||
question = getString(R.string.review_copyright);
|
||||
explanation = getString(R.string.review_copyright_explanation);
|
||||
yesButton.setOnClickListener(view -> {
|
||||
((ReviewActivity)getActivity()).reviewController.reportPossibleCopyRightViolation();
|
||||
});
|
||||
break;
|
||||
case CATEGORY:
|
||||
question = getString(R.string.review_category);
|
||||
explanation = getString(R.string.review_no_category);
|
||||
updateCategories(ReviewController.categories);
|
||||
yesButton.setOnClickListener(view -> {
|
||||
((ReviewActivity)getActivity()).reviewController.reportWrongCategory();
|
||||
});
|
||||
break;
|
||||
case SPAM:
|
||||
question = getString(R.string.review_spam);
|
||||
explanation = getString(R.string.review_spam_explanation);
|
||||
yesButton.setOnClickListener(view -> {
|
||||
((ReviewActivity)getActivity()).reviewController.reportSpam();
|
||||
});
|
||||
break;
|
||||
case THANKS:
|
||||
question = getString(R.string.review_thanks);
|
||||
explanation = getString(R.string.review_thanks_explanation);
|
||||
yesButton.setOnClickListener(view -> {
|
||||
((ReviewActivity)getActivity()).reviewController.sendThanks();
|
||||
});
|
||||
break;
|
||||
default:
|
||||
question = "How did we get here?";
|
||||
explanation = "No idea.";
|
||||
}
|
||||
|
||||
noButton.setOnClickListener(view -> {
|
||||
((ReviewActivity)getActivity()).reviewController.swipeToNext();
|
||||
});
|
||||
|
||||
((TextView) textViewQuestion).setText(question);
|
||||
((TextView) textViewQuestionContext).setText(explanation);
|
||||
|
||||
simpleDraweeView = layoutView.findViewById(R.id.imageView);
|
||||
|
||||
if (fileName != null) {
|
||||
simpleDraweeView.setImageURI(Utils.makeThumbBaseUrl(fileName));
|
||||
progressBar.setVisibility(View.GONE);
|
||||
}
|
||||
return layoutView;
|
||||
}
|
||||
|
||||
public void updateImageCaption() {
|
||||
((TextView)imageCaption).setText(fileName+" is uploaded by: "+ReviewController.firstRevision.username);
|
||||
private void fillImageCaption() {
|
||||
if (imageCaption != null && fileName != null && revision != null) {
|
||||
((TextView) imageCaption).setText(fileName + " is uploaded by: " + revision.username);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,12 +5,13 @@ import android.support.v4.app.Fragment;
|
|||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentStatePagerAdapter;
|
||||
|
||||
import fr.free.nrw.commons.mwapi.Revision;
|
||||
|
||||
/**
|
||||
* Created by nes on 19.05.2018.
|
||||
*/
|
||||
|
||||
public class ReviewPagerAdapter extends FragmentStatePagerAdapter {
|
||||
private int currentPosition;
|
||||
ReviewImageFragment[] reviewImageFragments;
|
||||
|
||||
|
||||
|
|
@ -26,13 +27,13 @@ public class ReviewPagerAdapter extends FragmentStatePagerAdapter {
|
|||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return 4;
|
||||
return reviewImageFragments.length;
|
||||
}
|
||||
|
||||
public void updateFilename() {
|
||||
public void updateFileInformation(String fileName, Revision revision) {
|
||||
for (int i = 0; i < getCount(); i++) {
|
||||
ReviewImageFragment fragment = reviewImageFragments[i];
|
||||
fragment.update(i, ReviewController.fileName);
|
||||
fragment.update(i, fileName, revision);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue