Skip to content

Commit f2fae5f

Browse files
yashk2000Vivek Maskara
authored and
Vivek Maskara
committed
Disabled review buttons while an image is being loaded (#3185)
* Disabled review buttons while an image is being loaded * Added javadocs for the new methods
1 parent 5e8f3fa commit f2fae5f

File tree

4 files changed

+56
-1
lines changed

4 files changed

+56
-1
lines changed

app/src/main/java/fr/free/nrw/commons/review/ReviewActivity.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,10 @@ protected void onCreate(Bundle savedInstanceState) {
120120
runRandomizer(); //Run randomizer whenever everything is ready so that a first random image will be added
121121
}
122122

123-
btnSkipImage.setOnClickListener(view -> runRandomizer());
123+
btnSkipImage.setOnClickListener(view -> {
124+
reviewPagerAdapter.disableButtons();
125+
runRandomizer();
126+
});
124127

125128
btnSkipImage.setOnTouchListener((view, event) -> {
126129
if (event.getAction() == MotionEvent.ACTION_UP && event.getRawX() >= (
@@ -142,6 +145,7 @@ public boolean runRandomizer() {
142145
.observeOn(AndroidSchedulers.mainThread())
143146
.subscribe(media -> {
144147
if (media != null) {
148+
reviewPagerAdapter.disableButtons();
145149
updateImage(media);
146150
}
147151
}));
@@ -169,6 +173,7 @@ private void updateImage(Media media) {
169173
String caption = String.format(getString(R.string.review_is_uploaded_by), fileName, revision.getUser());
170174
imageCaption.setText(caption);
171175
progressBar.setVisibility(View.GONE);
176+
reviewPagerAdapter.enableButtons();
172177
}));
173178
reviewPager.setCurrentItem(0);
174179
}

app/src/main/java/fr/free/nrw/commons/review/ReviewImageFragment.java

+26
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
8181
.reviewController.reportSpam(requireActivity(), getReviewCallback()));
8282
break;
8383
case COPYRIGHT:
84+
enableButtons();
8485
question = getString(R.string.review_copyright);
8586
explanation = getString(R.string.review_copyright_explanation);
8687
yesButtonText = getString(R.string.review_copyright_yes_button_text);
@@ -90,6 +91,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
9091
.reportPossibleCopyRightViolation(requireActivity(), getReviewCallback()));
9192
break;
9293
case CATEGORY:
94+
enableButtons();
9395
question = getString(R.string.review_category);
9496
explanation = updateCategoriesQuestion();
9597
yesButtonText = getString(R.string.review_category_yes_button_text);
@@ -102,6 +104,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
102104
});
103105
break;
104106
case THANKS:
107+
enableButtons();
105108
question = getString(R.string.review_thanks);
106109
explanation = getString(R.string.review_thanks_explanation, getReviewActivity().reviewController.firstRevision.getUser());
107110
yesButtonText = getString(R.string.review_thanks_yes_button_text);
@@ -114,6 +117,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
114117
});
115118
break;
116119
default:
120+
enableButtons();
117121
question = "How did we get here?";
118122
explanation = "No idea.";
119123
yesButtonText = "yes";
@@ -142,6 +146,28 @@ public void onFailure() {
142146
};
143147
}
144148

149+
/**
150+
* This function is called when an image has
151+
* been loaded to enable the review buttons.
152+
*/
153+
public void enableButtons() {
154+
yesButton.setEnabled(true);
155+
yesButton.setAlpha(1);
156+
noButton.setEnabled(true);
157+
noButton.setAlpha(1);
158+
}
159+
160+
/**
161+
* This function is called when an image is being loaded
162+
* to disable the review buttons
163+
*/
164+
public void disableButtons() {
165+
yesButton.setEnabled(false);
166+
yesButton.setAlpha(0.5f);
167+
noButton.setEnabled(false);
168+
noButton.setAlpha(0.5f);
169+
}
170+
145171
@OnClick(R.id.button_no)
146172
void onNoButtonClicked() {
147173
getReviewActivity().swipeToNext();

app/src/main/java/fr/free/nrw/commons/review/ReviewPagerAdapter.java

+20
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,26 @@ void updateFileInformation() {
3434
}
3535
}
3636

37+
/**
38+
* This function is called when an image has
39+
* been loaded to enable the review buttons.
40+
*/
41+
public void enableButtons() {
42+
if (reviewImageFragments != null){
43+
reviewImageFragments[0].enableButtons();
44+
}
45+
}
46+
47+
/**
48+
* This function is called when an image is being loaded
49+
* to disable the review buttons
50+
*/
51+
public void disableButtons() {
52+
if (reviewImageFragments != null){
53+
reviewImageFragments[0].disableButtons();
54+
}
55+
}
56+
3757
@Override
3858
public Fragment getItem(int position) {
3959
Bundle bundle = new Bundle();

app/src/main/res/layout/fragment_review_image.xml

+4
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@
5858
android:layout_margin="@dimen/activity_margin_horizontal"
5959
android:background="@android:color/transparent"
6060
android:text="@string/yes"
61+
android:enabled="false"
62+
android:alpha="0.5"
6163
android:textAllCaps="true"
6264
android:textAlignment="center"
6365
android:textColor="@color/yes_button_color"/>
@@ -68,6 +70,8 @@
6870
android:layout_width="0dp"
6971
android:layout_height="48dp"
7072
android:layout_weight="1"
73+
android:enabled="false"
74+
android:alpha="0.5"
7175
android:layout_margin="@dimen/activity_margin_horizontal"
7276
android:background="@android:color/transparent"
7377
android:text="@string/no"

0 commit comments

Comments
 (0)