Skip to content

Commit cbab7dd

Browse files
vanshikaaroradomdomegg
authored andcommitted
Resolves Reloading of image on moving to next question in peer review (commons-app#2709)
1 parent f7e6b20 commit cbab7dd

File tree

5 files changed

+114
-143
lines changed

5 files changed

+114
-143
lines changed

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

+34-29
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
package fr.free.nrw.commons.review;
22

3+
import android.annotation.SuppressLint;
34
import android.content.Context;
45
import android.content.Intent;
56
import android.os.Bundle;
67
import android.view.View;
78
import android.widget.Button;
89
import android.widget.ProgressBar;
10+
import android.widget.TextView;
911

12+
import com.facebook.drawee.view.SimpleDraweeView;
1013
import com.google.android.material.navigation.NavigationView;
1114
import com.viewpagerindicator.CirclePageIndicator;
1215

@@ -20,6 +23,7 @@
2023
import butterknife.ButterKnife;
2124
import fr.free.nrw.commons.Media;
2225
import fr.free.nrw.commons.R;
26+
import fr.free.nrw.commons.Utils;
2327
import fr.free.nrw.commons.auth.AuthenticatedActivity;
2428
import fr.free.nrw.commons.mwapi.MediaResult;
2529
import fr.free.nrw.commons.mwapi.MediaWikiApi;
@@ -33,30 +37,41 @@
3337

3438
public class ReviewActivity extends AuthenticatedActivity {
3539

40+
public ReviewPagerAdapter reviewPagerAdapter;
41+
public ReviewController reviewController;
42+
@BindView(R.id.reviewPagerIndicator)
43+
public CirclePageIndicator pagerIndicator;
3644
@BindView(R.id.toolbar)
3745
Toolbar toolbar;
3846
@BindView(R.id.navigation_view)
3947
NavigationView navigationView;
4048
@BindView(R.id.drawer_layout)
4149
DrawerLayout drawerLayout;
42-
4350
@BindView(R.id.reviewPager)
4451
ReviewViewPager reviewPager;
45-
4652
@BindView(R.id.skip_image)
4753
Button skip_image_button;
54+
@BindView(R.id.imageView)
55+
SimpleDraweeView simpleDraweeView;
56+
@BindView(R.id.progressBar)
57+
ProgressBar progressBar;
58+
@BindView(R.id.imageCaption)
59+
TextView imageCaption;
60+
@Inject
61+
MediaWikiApi mwApi;
4862

49-
@Inject MediaWikiApi mwApi;
63+
/**
64+
* Consumers should be simply using this method to use this activity.
65+
*
66+
* @param context
67+
* @param title Page title
68+
*/
69+
public static void startYourself(Context context, String title) {
70+
Intent reviewActivity = new Intent(context, ReviewActivity.class);
71+
context.startActivity(reviewActivity);
72+
}
5073
@Inject
5174
ReviewHelper reviewHelper;
52-
53-
public ReviewPagerAdapter reviewPagerAdapter;
54-
55-
public ReviewController reviewController;
56-
57-
@BindView(R.id.reviewPagerIndicator)
58-
public CirclePageIndicator pagerIndicator;
59-
6075
private CompositeDisposable compositeDisposable = new CompositeDisposable();
6176

6277

@@ -82,20 +97,16 @@ protected void onCreate(Bundle savedInstanceState) {
8297
reviewPager.setAdapter(reviewPagerAdapter);
8398
reviewPagerAdapter.getItem(0);
8499
pagerIndicator.setViewPager(reviewPager);
100+
progressBar.setVisibility(View.VISIBLE);
85101

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

88104
skip_image_button.setOnClickListener(view -> runRandomizer());
89105
}
90106

91-
92-
107+
@SuppressLint("CheckResult")
93108
public boolean runRandomizer() {
94-
ProgressBar progressBar = reviewPagerAdapter.reviewImageFragments[reviewPager.getCurrentItem()].progressBar;
95-
if (progressBar != null) {
96-
progressBar.setVisibility(View.VISIBLE);
97-
}
98-
109+
progressBar.setVisibility(View.VISIBLE);
99110
reviewPager.setCurrentItem(0);
100111
compositeDisposable.add(reviewHelper.getRandomMedia()
101112
.map(Media::getFilename)
@@ -105,18 +116,22 @@ public boolean runRandomizer() {
105116
return true;
106117
}
107118

119+
@SuppressLint("CheckResult")
108120
private void updateImage(String fileName) {
109121
if (fileName.length() == 0) {
110122
ViewUtil.showShortSnackbar(drawerLayout, R.string.error_review);
111123
return;
112124
}
125+
simpleDraweeView.setImageURI(Utils.makeThumbBaseUrl(fileName));
113126
reviewController.onImageRefreshed(fileName); //file name is updated
114127
compositeDisposable.add(reviewHelper.getFirstRevisionOfFile("File:" + fileName)
115128
.subscribeOn(Schedulers.io())
116129
.observeOn(AndroidSchedulers.mainThread())
117130
.subscribe(revision -> {
118131
reviewController.firstRevision = revision;
119-
reviewPagerAdapter.updateFileInformation(fileName, revision);
132+
reviewPagerAdapter.updateFileInformation(fileName);
133+
((TextView) imageCaption).setText(fileName + " is uploaded by: " + revision.getUser());
134+
progressBar.setVisibility(View.GONE);
120135
}));
121136
reviewPager.setCurrentItem(0);
122137
compositeDisposable.add(Observable.fromCallable(() -> {
@@ -148,14 +163,4 @@ public void swipeToNext() {
148163
runRandomizer();
149164
}
150165
}
151-
152-
/**
153-
* Consumers should be simply using this method to use this activity.
154-
* @param context
155-
* @param title Page title
156-
*/
157-
public static void startYourself(Context context, String title) {
158-
Intent reviewActivity = new Intent(context, ReviewActivity.class);
159-
context.startActivity(reviewActivity);
160-
}
161166
}

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

+4-32
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@
1111
import android.widget.ProgressBar;
1212
import android.widget.TextView;
1313

14-
import com.facebook.drawee.view.SimpleDraweeView;
15-
1614
import fr.free.nrw.commons.R;
17-
import fr.free.nrw.commons.Utils;
1815
import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
1916
import fr.free.nrw.commons.media.model.MwQueryPage;
2017

@@ -30,28 +27,20 @@ public class ReviewImageFragment extends CommonsDaggerSupportFragment {
3027
private String catString;
3128

3229
private View textViewQuestionContext;
33-
private View imageCaption;
3430
private View textViewQuestion;
35-
private SimpleDraweeView simpleDraweeView;
3631

3732
private Button yesButton;
3833
private Button noButton;
3934

35+
4036
public ProgressBar progressBar;
4137
private MwQueryPage.Revision revision;
4238

4339

44-
public void update(int position, String fileName, MwQueryPage.Revision revision) {
40+
public void update(int position, String fileName) {
4541
this.position = position;
4642
this.fileName = fileName;
47-
this.revision = revision;
48-
49-
fillImageCaption();
5043

51-
if (simpleDraweeView != null) {
52-
simpleDraweeView.setImageURI(Utils.makeThumbBaseUrl(fileName));
53-
progressBar.setVisibility(View.GONE);
54-
}
5544
}
5645

5746
public void updateCategories(Iterable<String> categories) {
@@ -78,15 +67,11 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
7867
position = getArguments().getInt("position");
7968
View layoutView = inflater.inflate(R.layout.fragment_review_image, container,
8069
false);
81-
progressBar = layoutView.findViewById(R.id.progressBar);
8270
textViewQuestion = layoutView.findViewById(R.id.reviewQuestion);
8371
textViewQuestionContext = layoutView.findViewById(R.id.reviewQuestionContext);
84-
imageCaption = layoutView.findViewById(R.id.imageCaption);
8572
yesButton = layoutView.findViewById(R.id.yesButton);
8673
noButton = layoutView.findViewById(R.id.noButton);
8774

88-
fillImageCaption();
89-
9075
String question, explanation, yesButtonText, noButtonText;
9176
switch (position) {
9277
case COPYRIGHT:
@@ -125,7 +110,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
125110
getReviewActivity().swipeToNext();
126111
});
127112
break;
128-
default :
113+
default:
129114
question = "How did we get here?";
130115
explanation = "No idea.";
131116
yesButtonText = "yes";
@@ -139,26 +124,13 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
139124
yesButton.setText(yesButtonText);
140125
noButton.setText(noButtonText);
141126

142-
if(position==CATEGORY){
127+
if (position == CATEGORY) {
143128
updateCategories(ReviewController.categories);
144129
}
145130

146-
simpleDraweeView = layoutView.findViewById(R.id.imageView);
147-
148-
if (fileName != null) {
149-
simpleDraweeView.setImageURI(Utils.makeThumbBaseUrl(fileName));
150-
progressBar.setVisibility(View.GONE);
151-
}
152131
return layoutView;
153132
}
154-
155133
private ReviewActivity getReviewActivity() {
156134
return (ReviewActivity) requireActivity();
157135
}
158-
159-
private void fillImageCaption() {
160-
if (imageCaption != null && fileName != null && revision != null) {
161-
((TextView) imageCaption).setText(fileName + " is uploaded by: " + revision.getUser());
162-
}
163-
}
164136
}

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

+7-7
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ public class ReviewPagerAdapter extends FragmentStatePagerAdapter {
1313

1414
public ReviewPagerAdapter(FragmentManager fm) {
1515
super(fm);
16-
reviewImageFragments = new ReviewImageFragment[] {
17-
new ReviewImageFragment(),
18-
new ReviewImageFragment(),
19-
new ReviewImageFragment(),
20-
new ReviewImageFragment()
16+
reviewImageFragments = new ReviewImageFragment[]{
17+
new ReviewImageFragment(),
18+
new ReviewImageFragment(),
19+
new ReviewImageFragment(),
20+
new ReviewImageFragment()
2121
};
2222
}
2323

@@ -26,10 +26,10 @@ public int getCount() {
2626
return reviewImageFragments.length;
2727
}
2828

29-
public void updateFileInformation(String fileName, MwQueryPage.Revision revision) {
29+
public void updateFileInformation(String fileName) {
3030
for (int i = 0; i < getCount(); i++) {
3131
ReviewImageFragment fragment = reviewImageFragments[i];
32-
fragment.update(i, fileName, revision);
32+
fragment.update(i, fileName);
3333
}
3434
}
3535

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

+51-11
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
android:layout_width="match_parent"
1414
android:layout_height="match_parent">
1515

16-
<include layout="@layout/toolbar"/>
16+
<include layout="@layout/toolbar" />
1717

1818
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
1919
android:layout_width="match_parent"
@@ -26,31 +26,71 @@
2626
android:id="@+id/skip_image"
2727
android:layout_width="match_parent"
2828
android:layout_height="0dp"
29+
android:layout_weight="1"
30+
android:background="@android:color/transparent"
2931
android:text="SKIP THIS IMAGE"
3032
android:textColor="@color/button_blue_dark"
31-
android:background="@android:color/transparent"
32-
android:layout_weight="1"
33-
android:textStyle="bold"/>
33+
android:textStyle="bold" />
34+
35+
<RelativeLayout
36+
android:layout_width="match_parent"
37+
android:layout_height="300dp"
38+
android:layout_marginTop="5dp">
39+
40+
<com.facebook.drawee.view.SimpleDraweeView
41+
android:id="@+id/imageView"
42+
android:layout_width="match_parent"
43+
android:layout_height="match_parent"
44+
android:layout_alignParentTop="true"
45+
android:layout_marginTop="0dp"
46+
android:src="@drawable/commons_logo_large" />
47+
48+
<RelativeLayout
49+
android:id="@+id/uploadOverlay"
50+
android:layout_width="match_parent"
51+
android:layout_height="wrap_content"
52+
android:layout_alignParentBottom="true"
53+
android:layout_gravity="center|bottom"
54+
android:background="#77000000"
55+
android:gravity="center"
56+
android:padding="@dimen/tiny_gap">
57+
58+
<TextView
59+
android:id="@+id/imageCaption"
60+
style="?android:textAppearanceMedium"
61+
android:layout_width="wrap_content"
62+
android:layout_height="wrap_content"
63+
android:textColor="#FFFFFFFF" />
64+
65+
</RelativeLayout>
66+
67+
<ProgressBar
68+
android:id="@+id/progressBar"
69+
android:layout_width="wrap_content"
70+
android:layout_height="wrap_content"
71+
android:layout_centerInParent="true"
72+
android:visibility="gone" />
73+
74+
</RelativeLayout>
3475

3576

3677
<fr.free.nrw.commons.review.ReviewViewPager
3778
android:id="@+id/reviewPager"
3879
android:layout_width="match_parent"
3980
android:layout_height="0dp"
40-
android:fadingEdge="none"
41-
android:layout_weight="13.5"/>
81+
android:layout_weight="13.5"
82+
android:fadingEdge="none" />
4283

4384

4485
<com.viewpagerindicator.CirclePageIndicator
4586
android:id="@+id/reviewPagerIndicator"
46-
android:layout_height="0dp"
4787
android:layout_width="match_parent"
88+
android:layout_height="0dp"
4889
android:layout_gravity="center"
49-
android:foregroundGravity="center_vertical"
50-
android:elevation="1dp"
51-
android:background="?attr/colorPrimaryDark"
5290
android:layout_weight="0.5"
53-
/>
91+
android:background="?attr/colorPrimaryDark"
92+
android:elevation="1dp"
93+
android:foregroundGravity="center_vertical" />
5494

5595
</LinearLayout>
5696

0 commit comments

Comments
 (0)