From bb7ab62b34d5ba88353eae9ab185629dac764fa7 Mon Sep 17 00:00:00 2001 From: Ashish Kumar Date: Wed, 24 Apr 2019 18:22:12 +0530 Subject: [PATCH] Fix #2915 Refractor feature Review (#2916) * BugFix #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 --- .../nrw/commons/review/ReviewActivity.java | 68 +++++--- .../commons/review/ReviewImageFragment.java | 43 ++--- app/src/main/res/layout/activity_review.xml | 160 ++++++++---------- .../main/res/layout/fragment_review_image.xml | 122 +++++++------ app/src/main/res/menu/menu_review_activty.xml | 9 + app/src/main/res/values/strings.xml | 17 +- 6 files changed, 221 insertions(+), 198 deletions(-) create mode 100644 app/src/main/res/menu/menu_review_activty.xml diff --git a/app/src/main/java/fr/free/nrw/commons/review/ReviewActivity.java b/app/src/main/java/fr/free/nrw/commons/review/ReviewActivity.java index 918f03048..13d945190 100644 --- a/app/src/main/java/fr/free/nrw/commons/review/ReviewActivity.java +++ b/app/src/main/java/fr/free/nrw/commons/review/ReviewActivity.java @@ -4,24 +4,21 @@ import android.annotation.SuppressLint; import android.content.Context; import android.content.Intent; import android.os.Bundle; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; +import android.view.MotionEvent; import android.view.View; import android.widget.Button; -import android.widget.ImageView; import android.widget.ProgressBar; import android.widget.TextView; - -import com.facebook.drawee.view.SimpleDraweeView; -import com.google.android.material.navigation.NavigationView; -import com.viewpagerindicator.CirclePageIndicator; - -import java.util.ArrayList; - -import javax.inject.Inject; - import androidx.appcompat.widget.Toolbar; import androidx.drawerlayout.widget.DrawerLayout; import butterknife.BindView; import butterknife.ButterKnife; +import com.facebook.drawee.view.SimpleDraweeView; +import com.google.android.material.navigation.NavigationView; +import com.viewpagerindicator.CirclePageIndicator; import fr.free.nrw.commons.Media; import fr.free.nrw.commons.R; import fr.free.nrw.commons.auth.AuthenticatedActivity; @@ -32,10 +29,12 @@ import fr.free.nrw.commons.utils.ViewUtil; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.CompositeDisposable; import io.reactivex.schedulers.Schedulers; +import java.util.ArrayList; +import javax.inject.Inject; public class ReviewActivity extends AuthenticatedActivity { - @BindView(R.id.reviewPagerIndicator) + @BindView(R.id.pager_indicator_review) public CirclePageIndicator pagerIndicator; @BindView(R.id.toolbar) Toolbar toolbar; @@ -43,20 +42,16 @@ public class ReviewActivity extends AuthenticatedActivity { NavigationView navigationView; @BindView(R.id.drawer_layout) DrawerLayout drawerLayout; - @BindView(R.id.reviewPager) + @BindView(R.id.view_pager_review) ReviewViewPager reviewPager; @BindView(R.id.skip_image) - Button skip_image_button; - @BindView(R.id.imageView) + Button btnSkipImage; + @BindView(R.id.review_image_view) SimpleDraweeView simpleDraweeView; - @BindView(R.id.progressBar) + @BindView(R.id.pb_review_image) ProgressBar progressBar; - @BindView(R.id.imageCaption) + @BindView(R.id.tv_image_caption) TextView imageCaption; - @BindView(R.id.skip_image_info) - ImageView skipImageInfo; - @BindView(R.id.review_image_info) - ImageView reviewImageInfo; public ReviewPagerAdapter reviewPagerAdapter; public ReviewController reviewController; @Inject @@ -96,6 +91,7 @@ public class ReviewActivity extends AuthenticatedActivity { super.onCreate(savedInstanceState); setContentView(R.layout.activity_review); ButterKnife.bind(this); + setSupportActionBar(toolbar); initDrawer(); reviewController = new ReviewController(deleteHelper, this); @@ -108,9 +104,17 @@ public class ReviewActivity extends AuthenticatedActivity { runRandomizer(); //Run randomizer whenever everything is ready so that a first random image will be added - skip_image_button.setOnClickListener(view -> runRandomizer()); - skipImageInfo.setOnClickListener(view -> showSkipImageInfo()); - reviewImageInfo.setOnClickListener(view -> showReviewImageInfo()); + btnSkipImage.setOnClickListener(view -> runRandomizer()); + + btnSkipImage.setOnTouchListener((view, event) -> { + if (event.getAction() == MotionEvent.ACTION_UP && event.getRawX() >= ( + btnSkipImage.getRight() - btnSkipImage + .getCompoundDrawables()[2].getBounds().width())) { + showSkipImageInfo(); + return true; + } + return false; + }); } @SuppressLint("CheckResult") @@ -187,4 +191,22 @@ public class ReviewActivity extends AuthenticatedActivity { null, null); } + + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + MenuInflater inflater = getMenuInflater(); + inflater.inflate(R.menu.menu_review_activty, menu); + return super.onCreateOptionsMenu(menu); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.menu_image_info: + showReviewImageInfo(); + return true; + } + return super.onOptionsItemSelected(item); + } } diff --git a/app/src/main/java/fr/free/nrw/commons/review/ReviewImageFragment.java b/app/src/main/java/fr/free/nrw/commons/review/ReviewImageFragment.java index 3ec22cdd3..5f4e16d29 100644 --- a/app/src/main/java/fr/free/nrw/commons/review/ReviewImageFragment.java +++ b/app/src/main/java/fr/free/nrw/commons/review/ReviewImageFragment.java @@ -10,11 +10,12 @@ import android.view.ViewGroup; import android.widget.Button; import android.widget.ProgressBar; import android.widget.TextView; - -import org.wikipedia.dataclient.mwapi.MwQueryPage; - +import butterknife.BindView; +import butterknife.ButterKnife; +import butterknife.OnClick; import fr.free.nrw.commons.R; import fr.free.nrw.commons.di.CommonsDaggerSupportFragment; +import org.wikipedia.dataclient.mwapi.MwQueryPage; public class ReviewImageFragment extends CommonsDaggerSupportFragment { @@ -27,16 +28,18 @@ public class ReviewImageFragment extends CommonsDaggerSupportFragment { private String fileName; private String catString; - private View textViewQuestionContext; - private View textViewQuestion; - - private Button yesButton; - private Button noButton; - - public ProgressBar progressBar; private MwQueryPage.Revision revision; + @BindView(R.id.tv_review_question) + TextView textViewQuestion; + @BindView(R.id.tv_review_question_context) + TextView textViewQuestionContext; + @BindView(R.id.button_yes) + Button yesButton; + @BindView(R.id.button_no) + Button noButton; + public void update(int position, String fileName) { this.position = position; @@ -50,9 +53,9 @@ public class ReviewImageFragment extends CommonsDaggerSupportFragment { if (catString != null && !catString.equals("") && textViewQuestionContext != null) { catString = "" + catString + ""; String stringToConvertHtml = String.format(getResources().getString(R.string.review_category_explanation), catString); - ((TextView) textViewQuestionContext).setText(Html.fromHtml(stringToConvertHtml)); + textViewQuestionContext.setText(Html.fromHtml(stringToConvertHtml)); } else if (textViewQuestionContext != null) { - ((TextView) textViewQuestionContext).setText(getResources().getString(R.string.review_no_category)); + textViewQuestionContext.setText(getResources().getString(R.string.review_no_category)); } } } @@ -68,10 +71,7 @@ public class ReviewImageFragment extends CommonsDaggerSupportFragment { position = getArguments().getInt("position"); View layoutView = inflater.inflate(R.layout.fragment_review_image, container, false); - textViewQuestion = layoutView.findViewById(R.id.reviewQuestion); - textViewQuestionContext = layoutView.findViewById(R.id.reviewQuestionContext); - yesButton = layoutView.findViewById(R.id.yesButton); - noButton = layoutView.findViewById(R.id.noButton); + ButterKnife.bind(this,layoutView); String question, explanation, yesButtonText, noButtonText; switch (position) { @@ -118,10 +118,8 @@ public class ReviewImageFragment extends CommonsDaggerSupportFragment { noButtonText = "no"; } - noButton.setOnClickListener(view -> getReviewActivity().swipeToNext()); - - ((TextView) textViewQuestion).setText(question); - ((TextView) textViewQuestionContext).setText(explanation); + textViewQuestion.setText(question); + textViewQuestionContext.setText(explanation); yesButton.setText(yesButtonText); noButton.setText(noButtonText); @@ -132,6 +130,11 @@ public class ReviewImageFragment extends CommonsDaggerSupportFragment { return layoutView; } + @OnClick(R.id.button_no) + public void onNoButtonClicked() { + getReviewActivity().swipeToNext(); + } + private ReviewActivity getReviewActivity() { return (ReviewActivity) requireActivity(); } diff --git a/app/src/main/res/layout/activity_review.xml b/app/src/main/res/layout/activity_review.xml index 51064b10c..579677559 100644 --- a/app/src/main/res/layout/activity_review.xml +++ b/app/src/main/res/layout/activity_review.xml @@ -1,80 +1,56 @@ + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" + android:id="@+id/drawer_layout" + android:layout_width="match_parent" + android:layout_height="match_parent"> - - + android:layout_height="match_parent" + android:orientation="vertical"> - - + -