Re-use same class for all review fragments (#1537)

And try to add pager indicator
This commit is contained in:
Elliott Eggleston 2018-05-19 13:22:51 -05:00 committed by maskara
parent e5db79e652
commit 3be184edbe
12 changed files with 80 additions and 299 deletions

View file

@ -17,9 +17,7 @@ import fr.free.nrw.commons.nearby.NearbyFragment;
import fr.free.nrw.commons.nearby.NearbyListFragment; import fr.free.nrw.commons.nearby.NearbyListFragment;
import fr.free.nrw.commons.nearby.NearbyMapFragment; import fr.free.nrw.commons.nearby.NearbyMapFragment;
import fr.free.nrw.commons.nearby.NoPermissionsFragment; import fr.free.nrw.commons.nearby.NoPermissionsFragment;
import fr.free.nrw.commons.review.ReviewCategoryMissuseFragment; import fr.free.nrw.commons.review.ReviewImageFragment;
import fr.free.nrw.commons.review.ReviewLicenceViolationFragment;
import fr.free.nrw.commons.review.ReviewOutOfContextFragment;
import fr.free.nrw.commons.settings.SettingsFragment; import fr.free.nrw.commons.settings.SettingsFragment;
@Module @Module
@ -72,13 +70,6 @@ public abstract class FragmentBuilderModule {
abstract BookmarkLocationsFragment bindBookmarkLocationListFragment(); abstract BookmarkLocationsFragment bindBookmarkLocationListFragment();
@ContributesAndroidInjector @ContributesAndroidInjector
abstract ReviewOutOfContextFragment bindReviewOutOfContextFragment(); abstract ReviewImageFragment bindReviewOutOfContextFragment();
@ContributesAndroidInjector
abstract ReviewLicenceViolationFragment bindReviewLicenceViolationFragment();
@ContributesAndroidInjector
abstract ReviewCategoryMissuseFragment bindReviewCategoryMissuseFragment();
} }

View file

@ -15,6 +15,8 @@ import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import com.viewpagerindicator.CirclePageIndicator;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
@ -55,6 +57,9 @@ public class ReviewActivity extends AuthenticatedActivity {
//private ReviewCallback reviewCallback; //private ReviewCallback reviewCallback;
private ReviewController reviewController; private ReviewController reviewController;
@BindView(R.id.reviewPagerIndicator)
public CirclePageIndicator pagerIndicator;
@Override @Override
protected void onAuthCookieAcquired(String authCookie) { protected void onAuthCookieAcquired(String authCookie) {
@ -78,6 +83,7 @@ public class ReviewActivity extends AuthenticatedActivity {
reviewPagerAdapter = new ReviewPagerAdapter(getSupportFragmentManager()); reviewPagerAdapter = new ReviewPagerAdapter(getSupportFragmentManager());
pager.setAdapter(reviewPagerAdapter); pager.setAdapter(reviewPagerAdapter);
reviewPagerAdapter.getItem(0); reviewPagerAdapter.getItem(0);
pagerIndicator.setViewPager(pager);
} }
@Override @Override
@ -116,9 +122,9 @@ public class ReviewActivity extends AuthenticatedActivity {
} }
private void updateImage(Media result) { private void updateImage(Media result) {
reviewController.onImageRefreshed(result.getFilename()); //file name is updated reviewController.onImageRefreshed(result.getFilename()); //file name is updated
reviewPagerAdapter.getItem(0); //new fragment with this new filename created reviewPagerAdapter.updateFilename();
pager.setCurrentItem(0);
} }

View file

@ -1,59 +0,0 @@
package fr.free.nrw.commons.review;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
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;
/**
* Created by root on 19.05.2018.
*/
public class ReviewCategoryMissuseFragment extends CommonsDaggerSupportFragment {
int position;
String fileName;
private View textView;
private SimpleDraweeView simpleDraweeView;
public void update(int position, String fileName) {
this.position = position;
this.fileName = fileName;
if (simpleDraweeView!=null) {
simpleDraweeView.setImageURI(Utils.makeThumbBaseUrl(fileName));
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//position = getArguments() != null ? getArguments().getInt("val") : 1;
//fileName = getArguments() != null ? getArguments().getString("fileName") : "";
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View layoutView = inflater.inflate(R.layout.review_out_of_context, container,
false);
textView = layoutView.findViewById(R.id.testingText);
simpleDraweeView = layoutView.findViewById(R.id.imageView);
if (fileName!= null) {
simpleDraweeView.setImageURI(Utils.makeThumbBaseUrl(fileName));
}
((TextView) textView).setText("Fragment #" + position);
Log.d("deneme","Fragment #" + position);
return layoutView;
}
}

View file

@ -9,7 +9,7 @@ public class ReviewController implements ReviewActivity.ReviewCallback {
@Override @Override
public void onImageRefreshed(String fileName) { public void onImageRefreshed(String fileName) {
this.fileName = fileName; ReviewController.fileName = fileName;
} }
@Override @Override

View file

@ -1,7 +1,6 @@
package fr.free.nrw.commons.review; package fr.free.nrw.commons.review;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -17,7 +16,11 @@ import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
* Created by root on 19.05.2018. * Created by root on 19.05.2018.
*/ */
public class ReviewOutOfContextFragment extends CommonsDaggerSupportFragment { public class ReviewImageFragment extends CommonsDaggerSupportFragment {
public static final int SPAM = 0;
public static final int COPYRIGHT = 1;
public static final int CATEGORY = 2;
private int position; private int position;
private String fileName; private String fileName;
@ -36,24 +39,31 @@ public class ReviewOutOfContextFragment extends CommonsDaggerSupportFragment {
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
//position = getArguments() != null ? getArguments().getInt("val") : 1;
//fileName = getArguments() != null ? getArguments().getString("fileName") : " ";
} }
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
View layoutView = inflater.inflate(R.layout.review_out_of_context, container, position = getArguments().getInt("position");
View layoutView = inflater.inflate(R.layout.fragment_review_image, container,
false); false);
textView = layoutView.findViewById(R.id.testingText); textView = layoutView.findViewById(R.id.reviewQuestion);
String question;
simpleDraweeView = layoutView.findViewById(R.id.imageView); switch(position) {
if (fileName!= null) { case COPYRIGHT:
simpleDraweeView.setImageURI(Utils.makeThumbBaseUrl(fileName)); question = getString(R.string.review_copyright);
break;
case CATEGORY:
question = getString(R.string.review_category);
break;
case SPAM:
question = getString(R.string.review_spam);
break;
default:
question = "How did we get here?";
} }
((TextView) textView).setText(question);
((TextView) textView).setText("Fragment #" + position); simpleDraweeView = layoutView.findViewById(R.id.imageView);
Log.d("deneme","Fragment #" + position);
return layoutView; return layoutView;
} }

View file

@ -1,59 +0,0 @@
package fr.free.nrw.commons.review;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
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;
/**
* Created by nes on 19.05.2018.
*/
public class ReviewLicenceViolationFragment extends CommonsDaggerSupportFragment {
int position;
String fileName;
private View textView;
private SimpleDraweeView simpleDraweeView;
public void update(int position, String fileName) {
this.position = position;
this.fileName = fileName;
if (simpleDraweeView!=null) {
simpleDraweeView.setImageURI(Utils.makeThumbBaseUrl(fileName));
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//position = getArguments() != null ? getArguments().getInt("val") : 1;
//fileName = getArguments() != null ? getArguments().getString("fileName") : "";
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View layoutView = inflater.inflate(R.layout.review_out_of_context, container,
false);
textView = layoutView.findViewById(R.id.testingText);
simpleDraweeView = layoutView.findViewById(R.id.imageView);
if (fileName!= null) {
simpleDraweeView.setImageURI(Utils.makeThumbBaseUrl(fileName));
}
((TextView) textView).setText("Fragment #" + position);
Log.d("deneme","Fragment #" + position);
return layoutView;
}
}

View file

@ -11,16 +11,16 @@ import android.support.v4.app.FragmentStatePagerAdapter;
public class ReviewPagerAdapter extends FragmentStatePagerAdapter { public class ReviewPagerAdapter extends FragmentStatePagerAdapter {
private int currentPosition; private int currentPosition;
ReviewOutOfContextFragment reviewOutOfContextFragment; ReviewImageFragment[] reviewImageFragments;
ReviewLicenceViolationFragment reviewLicenceViolationFragment;
ReviewCategoryMissuseFragment reviewCategoryMissuseFragment;
public ReviewPagerAdapter(FragmentManager fm) { public ReviewPagerAdapter(FragmentManager fm) {
super(fm); super(fm);
reviewOutOfContextFragment = new ReviewOutOfContextFragment(); reviewImageFragments = new ReviewImageFragment[] {
reviewLicenceViolationFragment = new ReviewLicenceViolationFragment(); new ReviewImageFragment(),
reviewCategoryMissuseFragment = new ReviewCategoryMissuseFragment(); new ReviewImageFragment(),
new ReviewImageFragment()
};
} }
@Override @Override
@ -28,22 +28,19 @@ public class ReviewPagerAdapter extends FragmentStatePagerAdapter {
return 3; return 3;
} }
@Override public void updateFilename() {
public Fragment getItem(int position) { for (int i = 0; i < getCount(); i++) {
switch (position) { ReviewImageFragment fragment = reviewImageFragments[i];
case 0: // Fragment # 0 - This will show image fragment.update(i, ReviewController.fileName);
currentPosition = 0;
reviewOutOfContextFragment.update(currentPosition, ReviewController.fileName);
return reviewOutOfContextFragment;
case 1: // Fragment # 1 - This will show image
currentPosition = 1;
reviewLicenceViolationFragment.update(currentPosition, ReviewController.fileName);
return reviewLicenceViolationFragment;
default:// Fragment # 2-9 - Will show list
currentPosition = 2;
reviewCategoryMissuseFragment.update(currentPosition, ReviewController.fileName);
return reviewCategoryMissuseFragment;
} }
} }
@Override
public Fragment getItem(int position) {
Bundle bundle = new Bundle();
bundle.putInt("position", position);
reviewImageFragments[position].setArguments(bundle);
return reviewImageFragments[position];
}
} }

View file

@ -23,18 +23,29 @@
</include> </include>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_below="@id/toolbar" android:layout_below="@id/toolbar"
android:background="@color/primaryColor"> android:background="@color/primaryColor"
android:orientation="vertical">
<android.support.v4.view.ViewPager <android.support.v4.view.ViewPager
android:id="@+id/reviewPager" android:id="@+id/reviewPager"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:fadingEdge="none" /> android:fadingEdge="none" />
</FrameLayout>
<com.viewpagerindicator.CirclePageIndicator
android:id="@+id/reviewPagerIndicator"
android:layout_height="@dimen/half_standard_height"
android:layout_width="match_parent"
android:layout_gravity="bottom"
android:padding="5dp"
/>
</LinearLayout>

View file

@ -6,6 +6,7 @@
android:weightSum="5" android:weightSum="5"
android:orientation="vertical" android:orientation="vertical"
android:background="@color/main_background_light" android:background="@color/main_background_light"
android:gravity="center_horizontal"
> >
<com.facebook.drawee.view.SimpleDraweeView <com.facebook.drawee.view.SimpleDraweeView
@ -16,17 +17,20 @@
android:src="@drawable/commons_logo_large" android:src="@drawable/commons_logo_large"
/> />
<TextView <TextView
android:id="@+id/testingText" android:id="@+id/reviewQuestion"
android:layout_width="match_parent" android:layout_width="match_parent"
android:textColor="@android:color/black" android:textColor="@android:color/black"
android:layout_height="0dp" android:layout_height="0dp"
android:layout_weight="0.7" android:layout_weight="0.7"
android:textAlignment="center"
android:text="testing1" android:text="testing1"
/> />
<TextView <TextView
android:id="@+id/reviewQuestionContext"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="0dp"
android:layout_weight="0.7" android:layout_weight="0.7"
android:textAlignment="center"
android:text="testing2" android:text="testing2"
/> />
@ -34,26 +38,22 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="0dp"
android:layout_weight="0.6" android:layout_weight="0.6"
android:weightSum="3" android:weightSum="2"
android:orientation="horizontal"> android:orientation="horizontal">
<Button <Button
android:id="@+id/yesButton" android:id="@+id/yesButton"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1"/> android:layout_weight="1"
android:text="@string/yes"/>
<Button <Button
android:id="@+id/noButton" android:id="@+id/noButton"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1"/> android:layout_weight="1"
android:text="@string/no"/>
<Button
android:id="@+id/notSureButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout> </LinearLayout>

View file

@ -1,60 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="5"
android:orientation="vertical"
android:background="@color/main_background_light"
>
<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:src="@drawable/commons_logo_large"
/>
<TextView
android:id="@+id/testingText"
android:layout_width="match_parent"
android:textColor="@android:color/black"
android:layout_height="0dp"
android:layout_weight="0.7"
android:text="testing1"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.7"
android:text="testing2"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.6"
android:weightSum="3"
android:orientation="horizontal">
<Button
android:id="@+id/yesButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<Button
android:id="@+id/noButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<Button
android:id="@+id/notSureButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>

View file

@ -1,60 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="5"
android:orientation="vertical"
android:background="@color/main_background_light"
>
<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:src="@drawable/commons_logo_large"
/>
<TextView
android:id="@+id/testingText"
android:layout_width="match_parent"
android:textColor="@android:color/black"
android:layout_height="0dp"
android:layout_weight="0.7"
android:text="testing1"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.7"
android:text="testing2"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.6"
android:weightSum="3"
android:orientation="horizontal">
<Button
android:id="@+id/yesButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<Button
android:id="@+id/noButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<Button
android:id="@+id/notSureButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>

View file

@ -452,4 +452,8 @@ Upload your first media by touching the camera or gallery icon above.</string>
<string name="this_function_needs_network_connection">This function requires network connection, please check your connection settings.</string> <string name="this_function_needs_network_connection">This function requires network connection, please check your connection settings.</string>
<string name="bad_token_error_proposed_solution">Upload failed due to issues with edit token. Please try logging out and in again. </string> <string name="bad_token_error_proposed_solution">Upload failed due to issues with edit token. Please try logging out and in again. </string>
<string name="review_copyright">Is this a copyright violation?</string>
<string name="review_category">Is this mis-categorized?</string>
<string name="review_spam">Is this spam?</string>
</resources> </resources>