mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Check status before nominating for deletion
This commit is contained in:
parent
9a27f9c332
commit
e42c6feba4
8 changed files with 101 additions and 50 deletions
|
|
@ -43,6 +43,7 @@ public class Media implements Parcelable {
|
|||
protected String license;
|
||||
protected String creator;
|
||||
protected ArrayList<String> categories; // as loaded at runtime?
|
||||
protected boolean requestedDeletion;
|
||||
private Map<String, String> descriptions; // multilingual descriptions as loaded
|
||||
private HashMap<String, Object> tags = new HashMap<>();
|
||||
private @Nullable LatLng coordinates;
|
||||
|
|
@ -416,4 +417,12 @@ public class Media implements Parcelable {
|
|||
parcel.writeStringList(categories);
|
||||
parcel.writeMap(descriptions);
|
||||
}
|
||||
|
||||
public void setRequestedDeletion(){
|
||||
requestedDeletion = true;
|
||||
}
|
||||
|
||||
public boolean getRequestedDeletion(){
|
||||
return requestedDeletion;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ import timber.log.Timber;
|
|||
public class MediaDataExtractor {
|
||||
private final MediaWikiApi mediaWikiApi;
|
||||
private boolean fetched;
|
||||
private boolean deletionStatus;
|
||||
private ArrayList<String> categories;
|
||||
private Map<String, String> descriptions;
|
||||
private String license;
|
||||
|
|
@ -59,6 +60,14 @@ public class MediaDataExtractor {
|
|||
throw new IllegalStateException("Tried to call MediaDataExtractor.fetch() again.");
|
||||
}
|
||||
|
||||
try{
|
||||
Timber.d("Nominated for deletion: " + mediaWikiApi.pageExists("Commons:Deletion_requests/"+filename));
|
||||
deletionStatus = mediaWikiApi.pageExists("Commons:Deletion_requests/"+filename);
|
||||
}
|
||||
catch (Exception e){
|
||||
Timber.d(e.getMessage());
|
||||
}
|
||||
|
||||
MediaResult result = mediaWikiApi.fetchMediaByFilename(filename);
|
||||
|
||||
// In-page category links are extracted from source, as XML doesn't cover [[links]]
|
||||
|
|
@ -296,6 +305,9 @@ public class MediaDataExtractor {
|
|||
if (license != null) {
|
||||
media.setLicense(license);
|
||||
}
|
||||
if (deletionStatus){
|
||||
media.setRequestedDeletion();
|
||||
}
|
||||
|
||||
// add author, date, etc fields
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ import android.content.Context;
|
|||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.AsyncTask;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Locale;
|
||||
|
|
@ -19,12 +21,9 @@ import fr.free.nrw.commons.mwapi.MediaWikiApi;
|
|||
import timber.log.Timber;
|
||||
|
||||
import static android.support.v4.content.ContextCompat.startActivity;
|
||||
import static android.widget.Toast.LENGTH_SHORT;
|
||||
|
||||
public class DeleteTask extends AsyncTask<Void, Void, Integer> {
|
||||
|
||||
private static final int SUCCESS = 0;
|
||||
private static final int FAILED = -1;
|
||||
private static final int ALREADY_DELETED = -2;
|
||||
public class DeleteTask extends AsyncTask<Void, Void, Boolean> {
|
||||
|
||||
@Inject MediaWikiApi mwApi;
|
||||
@Inject SessionManager sessionManager;
|
||||
|
|
@ -48,7 +47,7 @@ public class DeleteTask extends AsyncTask<Void, Void, Integer> {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected Integer doInBackground(Void ...voids) {
|
||||
protected Boolean doInBackground(Void ...voids) {
|
||||
String editToken;
|
||||
String authCookie;
|
||||
String summary = "Nominating " + media.getFilename() +" for deletion.";
|
||||
|
|
@ -56,25 +55,15 @@ public class DeleteTask extends AsyncTask<Void, Void, Integer> {
|
|||
authCookie = sessionManager.getAuthCookie();
|
||||
mwApi.setAuthCookie(authCookie);
|
||||
|
||||
try{
|
||||
if (mwApi.pageExists("Commons:Deletion_requests/"+media.getFilename())){
|
||||
return ALREADY_DELETED;
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
Timber.d(e.getMessage());
|
||||
return FAILED;
|
||||
}
|
||||
|
||||
try {
|
||||
editToken = mwApi.getEditToken();
|
||||
}
|
||||
catch (Exception e){
|
||||
Timber.d(e.getMessage());
|
||||
return FAILED;
|
||||
return false;
|
||||
}
|
||||
if (editToken.equals("+\\")) {
|
||||
return FAILED;
|
||||
return false;
|
||||
}
|
||||
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
|
|
@ -90,7 +79,7 @@ public class DeleteTask extends AsyncTask<Void, Void, Integer> {
|
|||
}
|
||||
catch (Exception e) {
|
||||
Timber.d(e.getMessage());
|
||||
return FAILED;
|
||||
return false;
|
||||
}
|
||||
|
||||
String subpageString = "=== [[:" + media.getFilename() + "]] ===\n" +
|
||||
|
|
@ -102,7 +91,7 @@ public class DeleteTask extends AsyncTask<Void, Void, Integer> {
|
|||
}
|
||||
catch (Exception e) {
|
||||
Timber.d(e.getMessage());
|
||||
return FAILED;
|
||||
return false;
|
||||
}
|
||||
|
||||
String logPageString = "\n{{Commons:Deletion requests/" + media.getFilename() +
|
||||
|
|
@ -115,7 +104,7 @@ public class DeleteTask extends AsyncTask<Void, Void, Integer> {
|
|||
}
|
||||
catch (Exception e) {
|
||||
Timber.d(e.getMessage());
|
||||
return FAILED;
|
||||
return false;
|
||||
}
|
||||
|
||||
String userPageString = "\n{{subst:idw|" + media.getFilename() +
|
||||
|
|
@ -126,30 +115,23 @@ public class DeleteTask extends AsyncTask<Void, Void, Integer> {
|
|||
}
|
||||
catch (Exception e) {
|
||||
Timber.d(e.getMessage());
|
||||
return FAILED;
|
||||
return false;
|
||||
}
|
||||
return SUCCESS;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Integer result) {
|
||||
protected void onPostExecute(Boolean result) {
|
||||
String message = "";
|
||||
String title = "";
|
||||
switch (result){
|
||||
case SUCCESS:
|
||||
title = "Success";
|
||||
message = "Successfully nominated " + media.getDisplayTitle() + " deletion.\n" +
|
||||
"Check the webpage for more details";
|
||||
break;
|
||||
case FAILED:
|
||||
title = "Failed";
|
||||
message = "Could not request deletion. Something went wrong.";
|
||||
break;
|
||||
case ALREADY_DELETED:
|
||||
title = "Already Nominated";
|
||||
message = media.getDisplayTitle() + " has already been nominated for deletion.\n" +
|
||||
"Check the webpage for more details";
|
||||
break;
|
||||
if (result){
|
||||
title = "Success";
|
||||
message = "Successfully nominated " + media.getDisplayTitle() + " deletion.\n" +
|
||||
"Check the webpage for more details";
|
||||
}
|
||||
else {
|
||||
title = "Failed";
|
||||
message = "Could not request deletion. Something went wrong.";
|
||||
}
|
||||
AlertDialog alert;
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||
|
|
@ -165,7 +147,12 @@ public class DeleteTask extends AsyncTask<Void, Void, Integer> {
|
|||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
Intent browserIntent = new Intent(Intent.ACTION_VIEW, media.getFilePageTitle().getMobileUri());
|
||||
startActivity(context,browserIntent,null);
|
||||
if (browserIntent.resolveActivity(context.getPackageManager()) != null) {
|
||||
startActivity(context,browserIntent,null);
|
||||
} else {
|
||||
Toast toast = Toast.makeText(context, R.string.no_web_browser, LENGTH_SHORT);
|
||||
toast.show();
|
||||
}
|
||||
}
|
||||
});
|
||||
alert = builder.create();
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ import android.view.LayoutInflater;
|
|||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
|
|
@ -42,6 +41,7 @@ import fr.free.nrw.commons.R;
|
|||
import fr.free.nrw.commons.delete.DeleteTask;
|
||||
import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
|
||||
import fr.free.nrw.commons.location.LatLng;
|
||||
import fr.free.nrw.commons.mwapi.MediaWikiApi;
|
||||
import fr.free.nrw.commons.ui.widget.CompatTextView;
|
||||
import timber.log.Timber;
|
||||
|
||||
|
|
@ -69,6 +69,9 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment {
|
|||
|
||||
@Inject
|
||||
Provider<MediaDataExtractor> mediaDataExtractorProvider;
|
||||
@Inject
|
||||
MediaWikiApi mwApi;
|
||||
|
||||
|
||||
private MediaWikiImageView image;
|
||||
private MediaDetailSpacer spacer;
|
||||
|
|
@ -79,6 +82,7 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment {
|
|||
private TextView license;
|
||||
private TextView coordinates;
|
||||
private TextView uploadedDate;
|
||||
private TextView nominatedforDeletion;
|
||||
private LinearLayout categoryContainer;
|
||||
private Button delete;
|
||||
private ScrollView scrollView;
|
||||
|
|
@ -133,6 +137,7 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment {
|
|||
license = (TextView) view.findViewById(R.id.mediaDetailLicense);
|
||||
coordinates = (TextView) view.findViewById(R.id.mediaDetailCoordinates);
|
||||
uploadedDate = (TextView) view.findViewById(R.id.mediaDetailuploadeddate);
|
||||
nominatedforDeletion = (TextView) view.findViewById(R.id.nominatedDeletionBanner);
|
||||
delete = (Button) view.findViewById(R.id.nominateDeletion);
|
||||
categoryContainer = (LinearLayout) view.findViewById(R.id.mediaDetailCategoryContainer);
|
||||
|
||||
|
|
@ -231,7 +236,6 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment {
|
|||
|
||||
if (success) {
|
||||
extractor.fill(media);
|
||||
|
||||
setTextFields(media);
|
||||
setOnClickListeners(media);
|
||||
} else {
|
||||
|
|
@ -284,21 +288,22 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment {
|
|||
}
|
||||
rebuildCatList();
|
||||
|
||||
delete.setVisibility(View.VISIBLE);
|
||||
checkDeletion(media);
|
||||
}
|
||||
|
||||
private void setOnClickListeners(final Media media) {
|
||||
if (licenseLink(media) != null) {
|
||||
license.setOnClickListener(v -> openWebBrowser(licenseLink(media)));
|
||||
} else {
|
||||
} else {
|
||||
Toast toast = Toast.makeText(getContext(), getString(R.string.null_url), Toast.LENGTH_SHORT);
|
||||
toast.show();
|
||||
}
|
||||
}
|
||||
if (media.getCoordinates() != null) {
|
||||
coordinates.setOnClickListener(v -> openMap(media.getCoordinates()));
|
||||
}
|
||||
if (delete.getVisibility()==View.VISIBLE){
|
||||
if (delete.getVisibility() == View.VISIBLE) {
|
||||
delete.setOnClickListener(v -> {
|
||||
delete.setEnabled(false);
|
||||
AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
|
||||
alert.setMessage("Why should this file be deleted?");
|
||||
final EditText input = new EditText(getActivity());
|
||||
|
|
@ -343,6 +348,11 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment {
|
|||
d.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
|
||||
});
|
||||
}
|
||||
if (nominatedforDeletion.getVisibility() == View.VISIBLE){
|
||||
nominatedforDeletion.setOnClickListener(v -> {
|
||||
openWebBrowser(media.getFilePageTitle().getMobileUri().toString());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void rebuildCatList() {
|
||||
|
|
@ -366,7 +376,7 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment {
|
|||
viewIntent.setAction(Intent.ACTION_VIEW);
|
||||
viewIntent.setData(new PageTitle(selectedCategoryTitle).getCanonicalUri());
|
||||
//check if web browser available
|
||||
if(viewIntent.resolveActivity(getActivity().getPackageManager()) != null){
|
||||
if (viewIntent.resolveActivity(getActivity().getPackageManager()) != null) {
|
||||
startActivity(viewIntent);
|
||||
} else {
|
||||
Toast toast = Toast.makeText(getContext(), getString(R.string.no_web_browser), LENGTH_SHORT);
|
||||
|
|
@ -434,6 +444,16 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment {
|
|||
return media.getCoordinates().getPrettyCoordinateString();
|
||||
}
|
||||
|
||||
private void checkDeletion(Media media){
|
||||
if (media.getRequestedDeletion()){
|
||||
delete.setVisibility(View.GONE);
|
||||
nominatedforDeletion.setVisibility(View.VISIBLE);
|
||||
}
|
||||
else{
|
||||
delete.setVisibility(View.VISIBLE);
|
||||
nominatedforDeletion.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
private @Nullable
|
||||
String licenseLink(Media media) {
|
||||
|
|
|
|||
7
app/src/main/res/drawable/bg_delete_button.xml
Normal file
7
app/src/main/res/drawable/bg_delete_button.xml
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<solid android:color="@color/deleteButtonColor"/>
|
||||
<corners android:radius="3dp" />
|
||||
<stroke android:width="5px" android:color="@color/deleteBackgroundColor" />
|
||||
</shape>
|
||||
|
|
@ -251,10 +251,24 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/small_gap" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/nominatedDeletionBanner"
|
||||
android:background="@color/deleteBackgroundColor"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="@dimen/tiny_gap"
|
||||
android:gravity="center"
|
||||
android:text="@string/nominated_for_deletion"
|
||||
android:textColor="@color/primaryTextColor"
|
||||
android:padding="@dimen/standard_gap"
|
||||
android:textSize="@dimen/normal_text"
|
||||
android:textStyle="bold"
|
||||
android:visibility="gone"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/nominateDeletion"
|
||||
style="?android:attr/buttonBarButtonStyle"
|
||||
android:textColor="@color/deleteTextColor"
|
||||
android:textColor="@color/primaryTextColor"
|
||||
android:background="@drawable/bg_delete_button"
|
||||
android:layout_margin="@dimen/standard_gap"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
|
|||
|
|
@ -15,7 +15,8 @@
|
|||
<color name="primaryTextColor">#ffffff</color>
|
||||
<color name="secondaryTextColor">#000000</color>
|
||||
|
||||
<color name="deleteTextColor">#d50000</color>
|
||||
<color name="deleteBackgroundColor">#90960a0a</color>
|
||||
<color name="deleteButtonColor">#44000000</color>
|
||||
|
||||
<!-- Some colours are same for dark/light themes. They are written two times in case
|
||||
we want to change light ones later.
|
||||
|
|
|
|||
|
|
@ -231,6 +231,7 @@
|
|||
<string name="no_web_browser">No web browser found to open URL</string>
|
||||
<string name="null_url">Error! URL not found</string>
|
||||
<string name="nominate_deletion">Nominate for Deletion</string>
|
||||
<string name="nominated_for_deletion">This image has been nominated for deletion.\n\n<u>See webpage for details</u></string>
|
||||
<string name="view_browser">View in Browser</string>
|
||||
|
||||
<string name="nearby_location_has_not_changed">Location has not changed.</string>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue