Add ReviewController class

This commit is contained in:
neslihanturan 2018-05-19 19:17:16 +03:00 committed by maskara
parent 67310be7b5
commit 6fa26af61c
13 changed files with 385 additions and 34 deletions

View file

@ -17,6 +17,8 @@ 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.ReviewLicenceViolationFragment;
import fr.free.nrw.commons.review.ReviewOutOfContextFragment; import fr.free.nrw.commons.review.ReviewOutOfContextFragment;
import fr.free.nrw.commons.settings.SettingsFragment; import fr.free.nrw.commons.settings.SettingsFragment;
@ -72,4 +74,11 @@ public abstract class FragmentBuilderModule {
@ContributesAndroidInjector @ContributesAndroidInjector
abstract ReviewOutOfContextFragment bindReviewOutOfContextFragment(); abstract ReviewOutOfContextFragment bindReviewOutOfContextFragment();
@ContributesAndroidInjector
abstract ReviewLicenceViolationFragment bindReviewLicenceViolationFragment();
@ContributesAndroidInjector
abstract ReviewCategoryMissuseFragment bindReviewCategoryMissuseFragment();
} }

View file

@ -1097,8 +1097,8 @@ public class ApacheHttpClientMediaWikiApi implements MediaWikiApi {
return isoFormat.format(date); return isoFormat.format(date);
} }
public MediaResult getRecentRandomImage() throws IOException { public Media getRecentRandomImage() throws IOException {
MediaResult media = null; Media media = null;
int tries = 0; int tries = 0;
Random r = new Random(); Random r = new Random();
@ -1128,7 +1128,11 @@ public class ApacheHttpClientMediaWikiApi implements MediaWikiApi {
NodeList childNodes = recentChangesNode.getDocument().getChildNodes(); NodeList childNodes = recentChangesNode.getDocument().getChildNodes();
String imageTitle = RecentChangesImageUtils.findImageInRecentChanges(childNodes); String imageTitle = RecentChangesImageUtils.findImageInRecentChanges(childNodes);
if (imageTitle != null) { if (imageTitle != null) {
media = fetchMediaByFilename(imageTitle); boolean deletionStatus = pageExists("Commons:Deletion_requests/" + imageTitle);
if (!deletionStatus) {
media = new Media(imageTitle);
//media = fetchMediaByFilename(fileName);
}
} }
} }
} }

View file

@ -113,5 +113,5 @@ public interface MediaWikiApi {
} }
@Nullable @Nullable
MediaResult getRecentRandomImage() throws IOException; Media getRecentRandomImage() throws IOException;
} }

View file

@ -21,8 +21,11 @@ import javax.inject.Inject;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import fr.free.nrw.commons.Media;
import fr.free.nrw.commons.R; import fr.free.nrw.commons.R;
import fr.free.nrw.commons.Utils;
import fr.free.nrw.commons.auth.AuthenticatedActivity; import fr.free.nrw.commons.auth.AuthenticatedActivity;
import fr.free.nrw.commons.mwapi.MediaResult;
import fr.free.nrw.commons.mwapi.MediaWikiApi; import fr.free.nrw.commons.mwapi.MediaWikiApi;
import io.reactivex.Observable; import io.reactivex.Observable;
import io.reactivex.schedulers.Schedulers; import io.reactivex.schedulers.Schedulers;
@ -43,12 +46,13 @@ public class ReviewActivity extends AuthenticatedActivity {
@BindView(R.id.reviewPager) @BindView(R.id.reviewPager)
ViewPager pager; ViewPager pager;
@Inject @Inject MediaWikiApi mwApi;
MediaWikiApi mwApi;
public static final int MAX_NUM = 4;
private ReviewPagerAdapter reviewPagerAdapter; private ReviewPagerAdapter reviewPagerAdapter;
//private ReviewCallback reviewCallback;
private ReviewController reviewController;
@Override @Override
protected void onAuthCookieAcquired(String authCookie) { protected void onAuthCookieAcquired(String authCookie) {
@ -66,9 +70,11 @@ public class ReviewActivity extends AuthenticatedActivity {
ButterKnife.bind(this); ButterKnife.bind(this);
initDrawer(); initDrawer();
reviewController = new ReviewController();
reviewPagerAdapter = new ReviewPagerAdapter(getSupportFragmentManager()); reviewPagerAdapter = new ReviewPagerAdapter(getSupportFragmentManager());
pager.setAdapter(reviewPagerAdapter); pager.setAdapter(reviewPagerAdapter);
//pager.setAdapter(adapter);
reviewPagerAdapter.getItem(0); reviewPagerAdapter.getItem(0);
} }
@ -85,8 +91,14 @@ public class ReviewActivity extends AuthenticatedActivity {
if (id == R.id.action_review_randomizer) { if (id == R.id.action_review_randomizer) {
Observable.fromCallable(() -> { Observable.fromCallable(() -> {
try { try {
Media result = mwApi.getRecentRandomImage();
reviewController.onImageRefreshed(result.getFilename()); //file name is updated
reviewPagerAdapter.getItem(0); //new fragment with this new filename created
Log.d("review", mwApi.getRecentRandomImage().getWikiSource()); //String thumBaseUrl = Utils.makeThumbBaseUrl(result.getFilename());
//reviewPagerAdapter.currentThumbBasedUrl = thumBaseUrl;
//Log.d("review", result.getWikiSource());
} catch (IOException e) { } catch (IOException e) {
Log.d("review", e.toString()); Log.d("review", e.toString());
@ -120,21 +132,14 @@ public class ReviewActivity extends AuthenticatedActivity {
Intent reviewActivity = new Intent(context, ReviewActivity.class); Intent reviewActivity = new Intent(context, ReviewActivity.class);
context.startActivity(reviewActivity); context.startActivity(reviewActivity);
} }
/*
@Override interface ReviewCallback {
public void onYesClicked() { void onImageRefreshed(String itemTitle);
Log.d("deneme","onYesClicked"); void onQuestionChanged();
void onSurveyFinished();
void onImproperImageReported();
void onLicenceViolationReported();
void oWrongCategoryReported();
void onThankSent();
} }
@Override
public void onNoClicked() {
Log.d("deneme","onNoClicked");
}
@Override
public void onNotSureClicked() {
Log.d("deneme","onNotSureClicked");
}*/
} }

View file

@ -0,0 +1,58 @@
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;
static ReviewCategoryMissuseFragment init(int val, String fileName) {
ReviewCategoryMissuseFragment fragment = new ReviewCategoryMissuseFragment();
// Supply val input as an argument.
Bundle args = new Bundle();
args.putInt("val", val);
args.putString("fileName", fileName);
fragment.setArguments(args);
return fragment;
}
@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);
View textView = layoutView.findViewById(R.id.testingText);
if (fileName!= null) {
SimpleDraweeView simpleDraweeView = layoutView.findViewById(R.id.imageView);
simpleDraweeView.setImageURI(Utils.makeThumbBaseUrl(fileName));
}
((TextView) textView).setText("Fragment #" + position);
Log.d("deneme","Fragment #" + position);
return layoutView;
}
}

View file

@ -0,0 +1,44 @@
package fr.free.nrw.commons.review;
/**
* Created by root on 19.05.2018.
*/
public class ReviewController implements ReviewActivity.ReviewCallback {
public static String fileName;
@Override
public void onImageRefreshed(String fileName) {
this.fileName = fileName;
}
@Override
public void onQuestionChanged() {
}
@Override
public void onSurveyFinished() {
}
@Override
public void onImproperImageReported() {
}
@Override
public void onLicenceViolationReported() {
}
@Override
public void oWrongCategoryReported() {
}
@Override
public void onThankSent() {
}
}

View file

@ -0,0 +1,58 @@
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;
static ReviewLicenceViolationFragment init(int val, String fileName) {
ReviewLicenceViolationFragment fragment = new ReviewLicenceViolationFragment();
// Supply val input as an argument.
Bundle args = new Bundle();
args.putInt("val", val);
args.putString("fileName", fileName);
fragment.setArguments(args);
return fragment;
}
@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);
View textView = layoutView.findViewById(R.id.testingText);
if (fileName!= null) {
SimpleDraweeView simpleDraweeView = layoutView.findViewById(R.id.imageView);
simpleDraweeView.setImageURI(Utils.makeThumbBaseUrl(fileName));
}
((TextView) textView).setText("Fragment #" + position);
Log.d("deneme","Fragment #" + position);
return layoutView;
}
}

View file

@ -7,7 +7,10 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.TextView; import android.widget.TextView;
import com.facebook.drawee.view.SimpleDraweeView;
import fr.free.nrw.commons.R; import fr.free.nrw.commons.R;
import fr.free.nrw.commons.Utils;
import fr.free.nrw.commons.di.CommonsDaggerSupportFragment; import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
/** /**
@ -17,30 +20,46 @@ import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
public class ReviewOutOfContextFragment extends CommonsDaggerSupportFragment { public class ReviewOutOfContextFragment extends CommonsDaggerSupportFragment {
int position; int position;
String fileName;
static ReviewOutOfContextFragment init(int val) { static ReviewOutOfContextFragment init(int val, String fileName) {
ReviewOutOfContextFragment truitonFrag = new ReviewOutOfContextFragment(); ReviewOutOfContextFragment fragment = new ReviewOutOfContextFragment();
// Supply val input as an argument. // Supply val input as an argument.
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putInt("val", val); args.putInt("val", val);
truitonFrag.setArguments(args); args.putString("fileName", fileName);
return truitonFrag; fragment.setArguments(args);
if (fileName != null) {
//updateFragment(val, file);
} }
return fragment;
}
@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; 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.out_of_context_question_layout, container, View layoutView = inflater.inflate(R.layout.review_out_of_context, container,
false); false);
View textView = layoutView.findViewById(R.id.testingText); View textView = layoutView.findViewById(R.id.testingText);
if (fileName!= null) {
SimpleDraweeView simpleDraweeView = layoutView.findViewById(R.id.imageView);
simpleDraweeView.setImageURI(Utils.makeThumbBaseUrl(fileName));
}
((TextView) textView).setText("Fragment #" + position); ((TextView) textView).setText("Fragment #" + position);
Log.d("deneme","Fragment #" + position); Log.d("deneme","Fragment #" + position);
return layoutView; return layoutView;
} }
} }

View file

@ -10,6 +10,9 @@ import android.support.v4.app.FragmentStatePagerAdapter;
*/ */
public class ReviewPagerAdapter extends FragmentStatePagerAdapter { public class ReviewPagerAdapter extends FragmentStatePagerAdapter {
private int currentPosition;
ReviewOutOfContextFragment reviewOutOfContextFragment;
public ReviewPagerAdapter(FragmentManager fm) { public ReviewPagerAdapter(FragmentManager fm) {
super(fm); super(fm);
@ -24,11 +27,15 @@ public class ReviewPagerAdapter extends FragmentStatePagerAdapter {
public Fragment getItem(int position) { public Fragment getItem(int position) {
switch (position) { switch (position) {
case 0: // Fragment # 0 - This will show image case 0: // Fragment # 0 - This will show image
return ReviewOutOfContextFragment.init(position); currentPosition = 0;
return ReviewOutOfContextFragment.init(position, ReviewController.fileName);
case 1: // Fragment # 1 - This will show image case 1: // Fragment # 1 - This will show image
return ReviewOutOfContextFragment.init(position); currentPosition = 1;
return ReviewLicenceViolationFragment.init(position, ReviewController.fileName);
default:// Fragment # 2-9 - Will show list default:// Fragment # 2-9 - Will show list
return ReviewOutOfContextFragment.init(position); currentPosition = 2;
return ReviewCategoryMissuseFragment.init(position, ReviewController.fileName);
} }
} }
} }

View file

@ -0,0 +1,26 @@
package fr.free.nrw.commons.utils;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Created by root on 19.05.2018.
*/
public class MediaDataExtractorUtil {
public static ArrayList<String> extractCategories(String source) {
ArrayList<String> categories = new ArrayList<>();
Pattern regex = Pattern.compile("\\[\\[\\s*Category\\s*:([^]]*)\\s*\\]\\]", Pattern.CASE_INSENSITIVE);
Matcher matcher = regex.matcher(source);
while (matcher.find()) {
String cat = matcher.group(1).trim();
categories.add(cat);
}
return categories;
}
}

View file

@ -8,7 +8,8 @@
android:background="@color/main_background_light" android:background="@color/main_background_light"
> >
<ImageView <com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/imageView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="0dp"
android:layout_weight="3" android:layout_weight="3"

View file

@ -0,0 +1,60 @@
<?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

@ -0,0 +1,60 @@
<?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>