mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 12:53:55 +01:00
Add ReviewController class
This commit is contained in:
parent
67310be7b5
commit
6fa26af61c
13 changed files with 385 additions and 34 deletions
|
|
@ -17,6 +17,8 @@ import fr.free.nrw.commons.nearby.NearbyFragment;
|
|||
import fr.free.nrw.commons.nearby.NearbyListFragment;
|
||||
import fr.free.nrw.commons.nearby.NearbyMapFragment;
|
||||
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.settings.SettingsFragment;
|
||||
|
||||
|
|
@ -72,4 +74,11 @@ public abstract class FragmentBuilderModule {
|
|||
@ContributesAndroidInjector
|
||||
abstract ReviewOutOfContextFragment bindReviewOutOfContextFragment();
|
||||
|
||||
@ContributesAndroidInjector
|
||||
abstract ReviewLicenceViolationFragment bindReviewLicenceViolationFragment();
|
||||
|
||||
|
||||
@ContributesAndroidInjector
|
||||
abstract ReviewCategoryMissuseFragment bindReviewCategoryMissuseFragment();
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1097,8 +1097,8 @@ public class ApacheHttpClientMediaWikiApi implements MediaWikiApi {
|
|||
return isoFormat.format(date);
|
||||
}
|
||||
|
||||
public MediaResult getRecentRandomImage() throws IOException {
|
||||
MediaResult media = null;
|
||||
public Media getRecentRandomImage() throws IOException {
|
||||
Media media = null;
|
||||
int tries = 0;
|
||||
Random r = new Random();
|
||||
|
||||
|
|
@ -1128,7 +1128,11 @@ public class ApacheHttpClientMediaWikiApi implements MediaWikiApi {
|
|||
NodeList childNodes = recentChangesNode.getDocument().getChildNodes();
|
||||
String imageTitle = RecentChangesImageUtils.findImageInRecentChanges(childNodes);
|
||||
if (imageTitle != null) {
|
||||
media = fetchMediaByFilename(imageTitle);
|
||||
boolean deletionStatus = pageExists("Commons:Deletion_requests/" + imageTitle);
|
||||
if (!deletionStatus) {
|
||||
media = new Media(imageTitle);
|
||||
//media = fetchMediaByFilename(fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -113,5 +113,5 @@ public interface MediaWikiApi {
|
|||
}
|
||||
|
||||
@Nullable
|
||||
MediaResult getRecentRandomImage() throws IOException;
|
||||
Media getRecentRandomImage() throws IOException;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,8 +21,11 @@ import javax.inject.Inject;
|
|||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import fr.free.nrw.commons.Media;
|
||||
import fr.free.nrw.commons.R;
|
||||
import fr.free.nrw.commons.Utils;
|
||||
import fr.free.nrw.commons.auth.AuthenticatedActivity;
|
||||
import fr.free.nrw.commons.mwapi.MediaResult;
|
||||
import fr.free.nrw.commons.mwapi.MediaWikiApi;
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
|
@ -43,12 +46,13 @@ public class ReviewActivity extends AuthenticatedActivity {
|
|||
@BindView(R.id.reviewPager)
|
||||
ViewPager pager;
|
||||
|
||||
@Inject
|
||||
MediaWikiApi mwApi;
|
||||
@Inject MediaWikiApi mwApi;
|
||||
|
||||
public static final int MAX_NUM = 4;
|
||||
private ReviewPagerAdapter reviewPagerAdapter;
|
||||
|
||||
//private ReviewCallback reviewCallback;
|
||||
private ReviewController reviewController;
|
||||
|
||||
@Override
|
||||
protected void onAuthCookieAcquired(String authCookie) {
|
||||
|
||||
|
|
@ -66,9 +70,11 @@ public class ReviewActivity extends AuthenticatedActivity {
|
|||
ButterKnife.bind(this);
|
||||
initDrawer();
|
||||
|
||||
reviewController = new ReviewController();
|
||||
|
||||
|
||||
reviewPagerAdapter = new ReviewPagerAdapter(getSupportFragmentManager());
|
||||
pager.setAdapter(reviewPagerAdapter);
|
||||
//pager.setAdapter(adapter);
|
||||
reviewPagerAdapter.getItem(0);
|
||||
}
|
||||
|
||||
|
|
@ -85,8 +91,14 @@ public class ReviewActivity extends AuthenticatedActivity {
|
|||
if (id == R.id.action_review_randomizer) {
|
||||
Observable.fromCallable(() -> {
|
||||
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) {
|
||||
Log.d("review", e.toString());
|
||||
|
|
@ -120,21 +132,14 @@ public class ReviewActivity extends AuthenticatedActivity {
|
|||
Intent reviewActivity = new Intent(context, ReviewActivity.class);
|
||||
context.startActivity(reviewActivity);
|
||||
}
|
||||
/*
|
||||
@Override
|
||||
public void onYesClicked() {
|
||||
Log.d("deneme","onYesClicked");
|
||||
|
||||
interface ReviewCallback {
|
||||
void onImageRefreshed(String itemTitle);
|
||||
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");
|
||||
|
||||
}*/
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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() {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -7,7 +7,10 @@ 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;
|
||||
|
||||
/**
|
||||
|
|
@ -17,30 +20,46 @@ import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
|
|||
public class ReviewOutOfContextFragment extends CommonsDaggerSupportFragment {
|
||||
|
||||
int position;
|
||||
String fileName;
|
||||
|
||||
static ReviewOutOfContextFragment init(int val) {
|
||||
ReviewOutOfContextFragment truitonFrag = new ReviewOutOfContextFragment();
|
||||
static ReviewOutOfContextFragment init(int val, String fileName) {
|
||||
ReviewOutOfContextFragment fragment = new ReviewOutOfContextFragment();
|
||||
// Supply val input as an argument.
|
||||
Bundle args = new Bundle();
|
||||
args.putInt("val", val);
|
||||
truitonFrag.setArguments(args);
|
||||
return truitonFrag;
|
||||
args.putString("fileName", fileName);
|
||||
fragment.setArguments(args);
|
||||
if (fileName != null) {
|
||||
//updateFragment(val, file);
|
||||
}
|
||||
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.out_of_context_question_layout, container,
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,9 @@ import android.support.v4.app.FragmentStatePagerAdapter;
|
|||
*/
|
||||
|
||||
public class ReviewPagerAdapter extends FragmentStatePagerAdapter {
|
||||
private int currentPosition;
|
||||
ReviewOutOfContextFragment reviewOutOfContextFragment;
|
||||
|
||||
|
||||
public ReviewPagerAdapter(FragmentManager fm) {
|
||||
super(fm);
|
||||
|
|
@ -24,11 +27,15 @@ public class ReviewPagerAdapter extends FragmentStatePagerAdapter {
|
|||
public Fragment getItem(int position) {
|
||||
switch (position) {
|
||||
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
|
||||
return ReviewOutOfContextFragment.init(position);
|
||||
currentPosition = 1;
|
||||
return ReviewLicenceViolationFragment.init(position, ReviewController.fileName);
|
||||
default:// Fragment # 2-9 - Will show list
|
||||
return ReviewOutOfContextFragment.init(position);
|
||||
currentPosition = 2;
|
||||
return ReviewCategoryMissuseFragment.init(position, ReviewController.fileName);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -8,7 +8,8 @@
|
|||
android:background="@color/main_background_light"
|
||||
>
|
||||
|
||||
<ImageView
|
||||
<com.facebook.drawee.view.SimpleDraweeView
|
||||
android:id="@+id/imageView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="3"
|
||||
60
app/src/main/res/layout/review_licence_violation.xml
Normal file
60
app/src/main/res/layout/review_licence_violation.xml
Normal 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>
|
||||
60
app/src/main/res/layout/review_out_of_context.xml
Normal file
60
app/src/main/res/layout/review_out_of_context.xml
Normal 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>
|
||||
Loading…
Add table
Add a link
Reference in a new issue