Skip to content

Commit bb7ab62

Browse files
ashishkumar468neslihanturan
authored andcommitted
Fix commons-app#2915 Refractor feature Review (commons-app#2916)
* BugFix commons-app#2915 * Refractor ReviewActivity and ReviewImageFragment and the related layout files, to properly use the scrollview * Use ButterKnife for ViewBindings in ReviewImageFragment * updated resource id names to follow underscore notation in xml * Use menu item instead of ImageView over toolbar in ReviewActivity * use tools:replace instead of android:text for dummy texts * merge nested if's [Codacy review] * updated string review_category_yes_button_text, use textAllCaps in yes and no button in ReviewFragment * updated other strings to use non bold letters
1 parent 37e9eae commit bb7ab62

File tree

6 files changed

+223
-200
lines changed

6 files changed

+223
-200
lines changed

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

+45-23
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,21 @@
44
import android.content.Context;
55
import android.content.Intent;
66
import android.os.Bundle;
7+
import android.view.Menu;
8+
import android.view.MenuInflater;
9+
import android.view.MenuItem;
10+
import android.view.MotionEvent;
711
import android.view.View;
812
import android.widget.Button;
9-
import android.widget.ImageView;
1013
import android.widget.ProgressBar;
1114
import android.widget.TextView;
12-
13-
import com.facebook.drawee.view.SimpleDraweeView;
14-
import com.google.android.material.navigation.NavigationView;
15-
import com.viewpagerindicator.CirclePageIndicator;
16-
17-
import java.util.ArrayList;
18-
19-
import javax.inject.Inject;
20-
2115
import androidx.appcompat.widget.Toolbar;
2216
import androidx.drawerlayout.widget.DrawerLayout;
2317
import butterknife.BindView;
2418
import butterknife.ButterKnife;
19+
import com.facebook.drawee.view.SimpleDraweeView;
20+
import com.google.android.material.navigation.NavigationView;
21+
import com.viewpagerindicator.CirclePageIndicator;
2522
import fr.free.nrw.commons.Media;
2623
import fr.free.nrw.commons.R;
2724
import fr.free.nrw.commons.auth.AuthenticatedActivity;
@@ -32,31 +29,29 @@
3229
import io.reactivex.android.schedulers.AndroidSchedulers;
3330
import io.reactivex.disposables.CompositeDisposable;
3431
import io.reactivex.schedulers.Schedulers;
32+
import java.util.ArrayList;
33+
import javax.inject.Inject;
3534

3635
public class ReviewActivity extends AuthenticatedActivity {
3736

38-
@BindView(R.id.reviewPagerIndicator)
37+
@BindView(R.id.pager_indicator_review)
3938
public CirclePageIndicator pagerIndicator;
4039
@BindView(R.id.toolbar)
4140
Toolbar toolbar;
4241
@BindView(R.id.navigation_view)
4342
NavigationView navigationView;
4443
@BindView(R.id.drawer_layout)
4544
DrawerLayout drawerLayout;
46-
@BindView(R.id.reviewPager)
45+
@BindView(R.id.view_pager_review)
4746
ReviewViewPager reviewPager;
4847
@BindView(R.id.skip_image)
49-
Button skip_image_button;
50-
@BindView(R.id.imageView)
48+
Button btnSkipImage;
49+
@BindView(R.id.review_image_view)
5150
SimpleDraweeView simpleDraweeView;
52-
@BindView(R.id.progressBar)
51+
@BindView(R.id.pb_review_image)
5352
ProgressBar progressBar;
54-
@BindView(R.id.imageCaption)
53+
@BindView(R.id.tv_image_caption)
5554
TextView imageCaption;
56-
@BindView(R.id.skip_image_info)
57-
ImageView skipImageInfo;
58-
@BindView(R.id.review_image_info)
59-
ImageView reviewImageInfo;
6055
public ReviewPagerAdapter reviewPagerAdapter;
6156
public ReviewController reviewController;
6257
@Inject
@@ -96,6 +91,7 @@ protected void onCreate(Bundle savedInstanceState) {
9691
super.onCreate(savedInstanceState);
9792
setContentView(R.layout.activity_review);
9893
ButterKnife.bind(this);
94+
setSupportActionBar(toolbar);
9995
initDrawer();
10096

10197
reviewController = new ReviewController(deleteHelper, this);
@@ -108,9 +104,17 @@ protected void onCreate(Bundle savedInstanceState) {
108104

109105
runRandomizer(); //Run randomizer whenever everything is ready so that a first random image will be added
110106

111-
skip_image_button.setOnClickListener(view -> runRandomizer());
112-
skipImageInfo.setOnClickListener(view -> showSkipImageInfo());
113-
reviewImageInfo.setOnClickListener(view -> showReviewImageInfo());
107+
btnSkipImage.setOnClickListener(view -> runRandomizer());
108+
109+
btnSkipImage.setOnTouchListener((view, event) -> {
110+
if (event.getAction() == MotionEvent.ACTION_UP && event.getRawX() >= (
111+
btnSkipImage.getRight() - btnSkipImage
112+
.getCompoundDrawables()[2].getBounds().width())) {
113+
showSkipImageInfo();
114+
return true;
115+
}
116+
return false;
117+
});
114118
}
115119

116120
@SuppressLint("CheckResult")
@@ -187,4 +191,22 @@ public void showReviewImageInfo() {
187191
null,
188192
null);
189193
}
194+
195+
196+
@Override
197+
public boolean onCreateOptionsMenu(Menu menu) {
198+
MenuInflater inflater = getMenuInflater();
199+
inflater.inflate(R.menu.menu_review_activty, menu);
200+
return super.onCreateOptionsMenu(menu);
201+
}
202+
203+
@Override
204+
public boolean onOptionsItemSelected(MenuItem item) {
205+
switch (item.getItemId()) {
206+
case R.id.menu_image_info:
207+
showReviewImageInfo();
208+
return true;
209+
}
210+
return super.onOptionsItemSelected(item);
211+
}
190212
}

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

+23-20
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@
1010
import android.widget.Button;
1111
import android.widget.ProgressBar;
1212
import android.widget.TextView;
13-
14-
import org.wikipedia.dataclient.mwapi.MwQueryPage;
15-
13+
import butterknife.BindView;
14+
import butterknife.ButterKnife;
15+
import butterknife.OnClick;
1616
import fr.free.nrw.commons.R;
1717
import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
18+
import org.wikipedia.dataclient.mwapi.MwQueryPage;
1819

1920
public class ReviewImageFragment extends CommonsDaggerSupportFragment {
2021

@@ -27,16 +28,18 @@ public class ReviewImageFragment extends CommonsDaggerSupportFragment {
2728
private String fileName;
2829
private String catString;
2930

30-
private View textViewQuestionContext;
31-
private View textViewQuestion;
32-
33-
private Button yesButton;
34-
private Button noButton;
35-
36-
3731
public ProgressBar progressBar;
3832
private MwQueryPage.Revision revision;
3933

34+
@BindView(R.id.tv_review_question)
35+
TextView textViewQuestion;
36+
@BindView(R.id.tv_review_question_context)
37+
TextView textViewQuestionContext;
38+
@BindView(R.id.button_yes)
39+
Button yesButton;
40+
@BindView(R.id.button_no)
41+
Button noButton;
42+
4043

4144
public void update(int position, String fileName) {
4245
this.position = position;
@@ -50,9 +53,9 @@ public void updateCategories(Iterable<String> categories) {
5053
if (catString != null && !catString.equals("") && textViewQuestionContext != null) {
5154
catString = "<b>" + catString + "</b>";
5255
String stringToConvertHtml = String.format(getResources().getString(R.string.review_category_explanation), catString);
53-
((TextView) textViewQuestionContext).setText(Html.fromHtml(stringToConvertHtml));
56+
textViewQuestionContext.setText(Html.fromHtml(stringToConvertHtml));
5457
} else if (textViewQuestionContext != null) {
55-
((TextView) textViewQuestionContext).setText(getResources().getString(R.string.review_no_category));
58+
textViewQuestionContext.setText(getResources().getString(R.string.review_no_category));
5659
}
5760
}
5861
}
@@ -68,10 +71,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
6871
position = getArguments().getInt("position");
6972
View layoutView = inflater.inflate(R.layout.fragment_review_image, container,
7073
false);
71-
textViewQuestion = layoutView.findViewById(R.id.reviewQuestion);
72-
textViewQuestionContext = layoutView.findViewById(R.id.reviewQuestionContext);
73-
yesButton = layoutView.findViewById(R.id.yesButton);
74-
noButton = layoutView.findViewById(R.id.noButton);
74+
ButterKnife.bind(this,layoutView);
7575

7676
String question, explanation, yesButtonText, noButtonText;
7777
switch (position) {
@@ -118,10 +118,8 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
118118
noButtonText = "no";
119119
}
120120

121-
noButton.setOnClickListener(view -> getReviewActivity().swipeToNext());
122-
123-
((TextView) textViewQuestion).setText(question);
124-
((TextView) textViewQuestionContext).setText(explanation);
121+
textViewQuestion.setText(question);
122+
textViewQuestionContext.setText(explanation);
125123
yesButton.setText(yesButtonText);
126124
noButton.setText(noButtonText);
127125

@@ -132,6 +130,11 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
132130
return layoutView;
133131
}
134132

133+
@OnClick(R.id.button_no)
134+
public void onNoButtonClicked() {
135+
getReviewActivity().swipeToNext();
136+
}
137+
135138
private ReviewActivity getReviewActivity() {
136139
return (ReviewActivity) requireActivity();
137140
}

0 commit comments

Comments
 (0)