mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 04:43:54 +01:00
[WIP] category check
This commit is contained in:
parent
3be184edbe
commit
14c871abca
5 changed files with 212 additions and 22 deletions
|
|
@ -58,7 +58,7 @@ public class DeleteTask extends AsyncTask<Void, Integer, Boolean> {
|
|||
CommonsApplication.NOTIFICATION_CHANNEL_ID_ALL);
|
||||
Toast toast = new Toast(context);
|
||||
toast.setGravity(Gravity.CENTER,0,0);
|
||||
toast = Toast.makeText(context,"Trying to nominate "+media.getDisplayTitle()+ " for deletion",Toast.LENGTH_SHORT);
|
||||
toast = Toast.makeText(context,"Trying to nominate "+media.getDisplayTitle()+ " for deletion", Toast.LENGTH_SHORT);
|
||||
toast.show();
|
||||
}
|
||||
|
||||
|
|
@ -68,7 +68,7 @@ public class DeleteTask extends AsyncTask<Void, Integer, Boolean> {
|
|||
|
||||
String editToken;
|
||||
String authCookie;
|
||||
String summary = "Nominating " + media.getFilename() +" for deletion.";
|
||||
String summary = context.getString(R.string.nominating_file_for_deletion, media.getFilename());
|
||||
|
||||
authCookie = sessionManager.getAuthCookie();
|
||||
mwApi.setAuthCookie(authCookie);
|
||||
|
|
@ -127,29 +127,21 @@ public class DeleteTask extends AsyncTask<Void, Integer, Boolean> {
|
|||
protected void onProgressUpdate (Integer... values){
|
||||
super.onProgressUpdate(values);
|
||||
|
||||
int[] messages = new int[]{
|
||||
R.string.getting_edit_token,
|
||||
R.string.nominate_for_deletion_edit_file_page,
|
||||
R.string.nominate_for_deletion_create_deletion_request,
|
||||
R.string.nominate_for_deletion_edit_deletion_request_log,
|
||||
R.string.nominate_for_deletion_notify_user,
|
||||
R.string.nominate_for_deletion_done
|
||||
};
|
||||
|
||||
String message = "";
|
||||
switch (values[0]){
|
||||
case 0:
|
||||
message = "Getting token";
|
||||
break;
|
||||
case 1:
|
||||
message = "Adding delete message to file";
|
||||
break;
|
||||
case 2:
|
||||
message = "Creating Delete requests sub-page";
|
||||
break;
|
||||
case 3:
|
||||
message = "Adding file to Delete requests log";
|
||||
break;
|
||||
case 4:
|
||||
message = "Notifying User on Talk page";
|
||||
break;
|
||||
case 5:
|
||||
message = "Done";
|
||||
break;
|
||||
if (0 < values[0] && values[0] < messages.length) {
|
||||
message = context.getString(messages[values[0]]);
|
||||
}
|
||||
|
||||
notificationBuilder.setContentTitle("Nominating "+media.getDisplayTitle()+" for deletion")
|
||||
notificationBuilder.setContentTitle(context.getString(R.string.nominating_file_for_deletion, media.getFilename()))
|
||||
.setStyle(new NotificationCompat.BigTextStyle()
|
||||
.bigText(message))
|
||||
.setSmallIcon(R.drawable.ic_launcher)
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ import fr.free.nrw.commons.auth.LoginActivity;
|
|||
import fr.free.nrw.commons.contributions.ContributionsSyncAdapter;
|
||||
import fr.free.nrw.commons.delete.DeleteTask;
|
||||
import fr.free.nrw.commons.modifications.ModificationsSyncAdapter;
|
||||
import fr.free.nrw.commons.review.CheckCategoryTask;
|
||||
import fr.free.nrw.commons.settings.SettingsFragment;
|
||||
import fr.free.nrw.commons.nearby.PlaceRenderer;
|
||||
import fr.free.nrw.commons.settings.SettingsFragment;
|
||||
import fr.free.nrw.commons.upload.FileProcessor;
|
||||
|
|
@ -42,6 +44,8 @@ public interface CommonsApplicationComponent extends AndroidInjector<Application
|
|||
|
||||
void inject(DeleteTask deleteTask);
|
||||
|
||||
void inject(CheckCategoryTask checkCategoryTask);
|
||||
|
||||
void inject(SettingsFragment fragment);
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@ import fr.free.nrw.commons.delete.ReasonBuilder;
|
|||
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.review.CheckCategoryTask;
|
||||
import fr.free.nrw.commons.ui.widget.CompatTextView;
|
||||
import timber.log.Timber;
|
||||
|
||||
|
|
@ -422,6 +423,55 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment {
|
|||
if(isDeleted) {
|
||||
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
|
||||
}
|
||||
//Reviewer correct me if i have misunderstood something over here
|
||||
//But how does this if (delete.getVisibility() == View.VISIBLE) {
|
||||
// enableDeleteButton(true); makes sense ?
|
||||
AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
|
||||
alert.setMessage("Why should this file be deleted?");
|
||||
final EditText input = new EditText(getActivity());
|
||||
alert.setView(input);
|
||||
input.requestFocus();
|
||||
alert.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int whichButton) {
|
||||
String reason = input.getText().toString();
|
||||
// TODO: RESTORE THIS IMMEDIATELY AFTER TESTING
|
||||
DeleteTask deleteTask = new DeleteTask(getActivity(), media, reason);
|
||||
//CheckCategoryTask deleteTask = new CheckCategoryTask(getActivity(), media);
|
||||
|
||||
deleteTask.execute();
|
||||
enableDeleteButton(false);
|
||||
}
|
||||
});
|
||||
alert.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int whichButton) {
|
||||
}
|
||||
});
|
||||
AlertDialog d = alert.create();
|
||||
input.addTextChangedListener(new TextWatcher() {
|
||||
private void handleText() {
|
||||
final Button okButton = d.getButton(AlertDialog.BUTTON_POSITIVE);
|
||||
if (input.getText().length() == 0) {
|
||||
okButton.setEnabled(false);
|
||||
} else {
|
||||
okButton.setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable arg0) {
|
||||
handleText();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
}
|
||||
});
|
||||
d.show();
|
||||
d.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
|
||||
}
|
||||
|
||||
@OnClick(R.id.seeMore)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,127 @@
|
|||
package fr.free.nrw.commons.review;
|
||||
|
||||
import android.app.NotificationManager;
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.view.Gravity;
|
||||
import android.widget.Toast;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import fr.free.nrw.commons.Media;
|
||||
import fr.free.nrw.commons.R;
|
||||
import fr.free.nrw.commons.auth.SessionManager;
|
||||
import fr.free.nrw.commons.di.ApplicationlessInjection;
|
||||
import fr.free.nrw.commons.mwapi.MediaWikiApi;
|
||||
import timber.log.Timber;
|
||||
|
||||
import static android.support.v4.app.NotificationCompat.DEFAULT_ALL;
|
||||
import static android.support.v4.app.NotificationCompat.PRIORITY_HIGH;
|
||||
|
||||
public class CheckCategoryTask extends AsyncTask<Void, Integer, Boolean> {
|
||||
|
||||
@Inject
|
||||
MediaWikiApi mwApi;
|
||||
@Inject
|
||||
SessionManager sessionManager;
|
||||
|
||||
public static final int NOTIFICATION_CHECK_CATEGORY = 1;
|
||||
|
||||
private NotificationManager notificationManager;
|
||||
private NotificationCompat.Builder notificationBuilder;
|
||||
private Context context;
|
||||
private Media media;
|
||||
|
||||
public CheckCategoryTask(Context context, Media media){
|
||||
this.context = context;
|
||||
this.media = media;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPreExecute(){
|
||||
ApplicationlessInjection
|
||||
.getInstance(context.getApplicationContext())
|
||||
.getCommonsApplicationComponent()
|
||||
.inject(this);
|
||||
|
||||
notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
notificationBuilder = new NotificationCompat.Builder(context);
|
||||
Toast toast = new Toast(context);
|
||||
toast.setGravity(Gravity.CENTER,0,0);
|
||||
toast = Toast.makeText(context, context.getString(R.string.check_category_toast, media.getDisplayTitle()), Toast.LENGTH_SHORT);
|
||||
toast.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean doInBackground(Void ...voids) {
|
||||
publishProgress(0);
|
||||
|
||||
String editToken;
|
||||
String authCookie;
|
||||
String summary = context.getString(R.string.check_category_edit_summary);
|
||||
|
||||
authCookie = sessionManager.getAuthCookie();
|
||||
mwApi.setAuthCookie(authCookie);
|
||||
|
||||
try {
|
||||
editToken = mwApi.getEditToken();
|
||||
if (editToken.equals("+\\")) {
|
||||
return false;
|
||||
}
|
||||
publishProgress(1);
|
||||
|
||||
mwApi.appendEdit(editToken, "\n{{subst:chc}}\n", media.getFilename(),summary);
|
||||
publishProgress(2);
|
||||
}
|
||||
catch (Exception e) {
|
||||
Timber.d(e.getMessage());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onProgressUpdate (Integer... values){
|
||||
super.onProgressUpdate(values);
|
||||
|
||||
int[] messages = new int[]{R.string.getting_edit_token, R.string.check_category_adding_template};
|
||||
String message = "";
|
||||
if (0 < values[0] && values[0] < messages.length) {
|
||||
message = context.getString(messages[values[0]]);
|
||||
}
|
||||
|
||||
notificationBuilder.setContentTitle(context.getString(R.string.check_category_notification_title))
|
||||
.setStyle(new NotificationCompat.BigTextStyle()
|
||||
.bigText(message))
|
||||
.setSmallIcon(R.drawable.ic_launcher)
|
||||
.setProgress(messages.length, values[0], false)
|
||||
.setOngoing(true);
|
||||
notificationManager.notify(NOTIFICATION_CHECK_CATEGORY, notificationBuilder.build());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Boolean result) {
|
||||
String message = "";
|
||||
String title = "";
|
||||
|
||||
if (result){
|
||||
title = context.getString(R.string.check_category_success_title);
|
||||
message = context.getString(R.string.check_category_success_message, media.getDisplayTitle());
|
||||
}
|
||||
else {
|
||||
title = context.getString(R.string.check_category_failure_title);
|
||||
message = context.getString(R.string.check_category_failure_message, media.getDisplayTitle());
|
||||
}
|
||||
|
||||
notificationBuilder.setDefaults(DEFAULT_ALL)
|
||||
.setContentTitle(title)
|
||||
.setStyle(new NotificationCompat.BigTextStyle()
|
||||
.bigText(message))
|
||||
.setSmallIcon(R.drawable.ic_launcher)
|
||||
.setProgress(0,0,false)
|
||||
.setOngoing(false)
|
||||
.setPriority(PRIORITY_HIGH);
|
||||
notificationManager.notify(NOTIFICATION_CHECK_CATEGORY, notificationBuilder.build());
|
||||
}
|
||||
}
|
||||
|
|
@ -259,6 +259,9 @@
|
|||
<string name="nominate_deletion">Nominate for Deletion</string>
|
||||
<string name="nominated_for_deletion">This image has been nominated for deletion.</string>
|
||||
<string name="nominated_see_more"><![CDATA[<u>See webpage for details</u>]]></string>
|
||||
<string name="nominating_file_for_deletion">Nominating %1$s for deletion.</string>
|
||||
<string name="nominating_for_deletion_status">Nominating file for deletion: %1$s</string>
|
||||
<string name="nominated_see_more"><u>See webpage for details</u></string>
|
||||
<string name="view_browser">View in Browser</string>
|
||||
<string name="skip_login">Skip</string>
|
||||
<string name="navigation_item_login">Log in</string>
|
||||
|
|
@ -451,6 +454,20 @@ 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="bad_token_error_proposed_solution">Upload failed due to issues with edit token. Please try logging out and in again. </string>
|
||||
<string name="getting_edit_token">Getting token for editing</string>
|
||||
<string name="check_category_adding_template">Adding template for category check</string>
|
||||
<string name="check_category_notification_title">Requesting category check for %1$s</string>
|
||||
<string name="check_category_edit_summary">Requesting category check</string>
|
||||
<string name="check_category_success_title">Requesting category check: Success</string>
|
||||
<string name="check_category_failure_title">Requesting category check: Failed</string>
|
||||
<string name="check_category_success_message">Successfully requested category check for %1$s</string>
|
||||
<string name="check_category_failure_message">Could not request category check for %1$s</string>
|
||||
<string name="check_category_toast">Requesting category check for %1%s</string>
|
||||
<string name="nominate_for_deletion_edit_file_page">Adding delete message to file</string>
|
||||
<string name="nominate_for_deletion_done">Done</string>
|
||||
<string name="nominate_for_deletion_notify_user">Notifying User on Talk page</string>
|
||||
<string name="nominate_for_deletion_edit_deletion_request_log">Adding file to Delete requests log</string>
|
||||
<string name="nominate_for_deletion_create_deletion_request">Creating Delete requests subpage</string>
|
||||
|
||||
<string name="review_copyright">Is this a copyright violation?</string>
|
||||
<string name="review_category">Is this mis-categorized?</string>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue