Removed all hardcoded strings in DeleteHelper.

This commit is contained in:
Pavel 2019-07-02 16:09:20 +03:00
parent 41766461c1
commit 5e1a8f961a
2 changed files with 65 additions and 39 deletions

View file

@ -59,8 +59,9 @@ public class DeleteHelper {
* @return
*/
public Single<Boolean> makeDeletion(Context context, Media media, String reason) {
viewUtil.showShortToast(context, "Trying to nominate " + media.getDisplayTitle() + " for deletion");
return Single.fromCallable(() -> delete(media, reason))
viewUtil.showShortToast(context, context.getResources().getString(R.string.delete_helper_make_deletion_toast_1)
+ media.getDisplayTitle() + context.getResources().getString(R.string.delete_helper_make_deletion_toast_2));
return Single.fromCallable(() -> delete(context, media, reason))
.flatMap(result -> Single.fromCallable(() ->
showDeletionNotification(context, media, result)));
}
@ -71,32 +72,33 @@ public class DeleteHelper {
* @param reason
* @return
*/
private boolean delete(Media media, String reason) {
private boolean delete(Context context, Media media, String reason) {
String editToken;
String authCookie;
String summary = "Nominating " + media.getFilename() + " for deletion.";
String summary = context.getResources().getString(R.string.delete_helper_delete_summary_1)
+ media.getFilename() + context.getResources().getString(R.string.delete_helper_delete_summary_2);
authCookie = sessionManager.getAuthCookie();
mwApi.setAuthCookie(authCookie);
Calendar calendar = Calendar.getInstance();
String fileDeleteString = "{{delete|reason=" + reason +
"|subpage=" + media.getFilename() +
"|day=" + calendar.get(Calendar.DAY_OF_MONTH) +
"|month=" + calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.getDefault()) +
"|year=" + calendar.get(Calendar.YEAR) +
String fileDeleteString = context.getResources().getString(R.string.delete_helper_delete_file_delete_string_1) + reason +
context.getResources().getString(R.string.delete_helper_delete_file_delete_string_2) + media.getFilename() +
context.getResources().getString(R.string.delete_helper_delete_file_delete_string_3) + calendar.get(Calendar.DAY_OF_MONTH) +
context.getResources().getString(R.string.delete_helper_delete_file_delete_string_4) + calendar.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.getDefault()) +
context.getResources().getString(R.string.delete_helper_delete_file_delete_string_5) + calendar.get(Calendar.YEAR) +
"}}";
String subpageString = "=== [[:" + media.getFilename() + "]] ===\n" +
reason +
" ~~~~";
String logPageString = "\n{{Commons:Deletion requests/" + media.getFilename() +
String logPageString = "\n" + context.getResources().getString(R.string.delete_helper_delete_log_page_string) + media.getFilename() +
"}}\n";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd", Locale.getDefault());
String date = sdf.format(calendar.getTime());
String userPageString = "\n{{subst:idw|" + media.getFilename() +
String userPageString = "\n" + context.getResources().getString(R.string.delete_helper_delete_user_page_string) + media.getFilename() +
"}} ~~~~";
try {
@ -109,11 +111,11 @@ public class DeleteHelper {
mwApi.prependEdit(editToken, fileDeleteString + "\n",
media.getFilename(), summary);
mwApi.edit(editToken, subpageString + "\n",
"Commons:Deletion_requests/" + media.getFilename(), summary);
context.getResources().getString(R.string.delete_helper_delete_try_commons) + media.getFilename(), summary);
mwApi.appendEdit(editToken, logPageString + "\n",
"Commons:Deletion_requests/" + date, summary);
context.getResources().getString(R.string.delete_helper_delete_try_commons) + date, summary);
mwApi.appendEdit(editToken, userPageString + "\n",
"User_Talk:" + media.getCreator(), summary);
context.getResources().getString(R.string.delete_helper_delete_try_talk) + media.getCreator(), summary);
} catch (Exception e) {
Timber.e(e);
return false;
@ -123,17 +125,18 @@ public class DeleteHelper {
private boolean showDeletionNotification(Context context, Media media, boolean result) {
String message;
String title = "Nominating for Deletion";
String title = context.getResources().getString(R.string.delete_helper_show_deletion_notification_title);
if (result) {
title += ": Success";
message = "Successfully nominated " + media.getDisplayTitle() + " deletion.";
title += context.getResources().getString(R.string.delete_helper_show_deletion_notification_title_if);
message = context.getResources().getString(R.string.delete_helper_show_deletion_notification_message_if_1)
+ media.getDisplayTitle() + context.getResources().getString(R.string.delete_helper_show_deletion_notification_message_if_2);
} else {
title += ": Failed";
message = "Could not request deletion.";
title += context.getResources().getString(R.string.delete_helper_show_deletion_notification_title_else);
message = context.getResources().getString(R.string.delete_helper_show_deletion_notification_message_else);
}
String urlForDelete = BuildConfig.COMMONS_URL + "/wiki/Commons:Deletion_requests/" + media.getFilename();
String urlForDelete = BuildConfig.COMMONS_URL + context.getResources().getString(R.string.delete_helper_show_deletion_notification_url_for_delete) + media.getFilename();
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(urlForDelete));
notificationHelper.showNotification(context, title, message, NOTIFICATION_DELETE, browserIntent);
return result;
@ -162,15 +165,15 @@ public class DeleteHelper {
if (problem == ReviewController.DeleteReason.SPAM) {
reasonList[0] = context.getResources().getString(R.string.delete_reason_spam_selfie);
reasonList[1] = context.getResources().getString(R.string.delete_reason_spam_blurry);
reasonList[2] = context.getResources().getString(R.string.delete_reason_spam_nonsense);
reasonList[3] = context.getResources().getString(R.string.delete_reason_spam_other);
reasonList[0] = context.getResources().getString(R.string.delete_helper_ask_reason_and_execute_reason_spam_selfie);
reasonList[1] = context.getResources().getString(R.string.delete_helper_ask_reason_and_execute_reason_spam_blurry);
reasonList[2] = context.getResources().getString(R.string.delete_helper_ask_reason_and_execute_reason_spam_nonsense);
reasonList[3] = context.getResources().getString(R.string.delete_helper_ask_reason_and_execute_reason_spam_other);
} else if (problem == ReviewController.DeleteReason.COPYRIGHT_VIOLATION) {
reasonList[0] = context.getResources().getString(R.string.delete_reason_copyright_pressphoto);
reasonList[1] = context.getResources().getString(R.string.delete_reason_copyright_internetphoto);
reasonList[2] = context.getResources().getString(R.string.delete_reason_copyright_logo);
reasonList[3] = context.getResources().getString(R.string.delete_reason_copyright_other);
reasonList[0] = context.getResources().getString(R.string.delete_helper_ask_reason_and_execute_reason_copyright_press_photo);
reasonList[1] = context.getResources().getString(R.string.delete_helper_ask_reason_and_execute_reason_copyright_internet_photo);
reasonList[2] = context.getResources().getString(R.string.delete_helper_ask_reason_and_execute_reason_copyright_logo);
reasonList[3] = context.getResources().getString(R.string.delete_helper_ask_reason_and_execute_reason_copyright_other);
}
alert.setMultiChoiceItems(reasonList, checkedItems, (dialogInterface, position, isChecked) -> {
@ -181,9 +184,9 @@ public class DeleteHelper {
}
});
alert.setPositiveButton("OK", (dialogInterface, i) -> {
alert.setPositiveButton(context.getResources().getString(R.string.delete_helper_ask_reason_and_execute_alert_set_positive_button), (dialogInterface, i) -> {
String reason = "Because it is ";
String reason = context.getResources().getString(R.string.delete_helper_ask_reason_and_execute_alert_set_positive_button_reason);
for (int j = 0; j < mUserReason.size(); j++) {
reason = reason + reasonList[mUserReason.get(j)];
if (j != mUserReason.size() - 1) {
@ -203,7 +206,7 @@ public class DeleteHelper {
});
});
alert.setNegativeButton("Cancel", (dialog, which) -> reviewCallback.onFailure());
alert.setNegativeButton(context.getResources().getString(R.string.delete_helper_ask_reason_and_execute_alert_set_negative_button), (dialog, which) -> reviewCallback.onFailure());
AlertDialog d = alert.create();
d.show();
}

View file

@ -560,12 +560,35 @@ Upload your first media by tapping on the add button.</string>
<string name="dialog_box_text_nomination">Why should %1$s be deleted?</string>
<string name="review_is_uploaded_by">%1$s is uploaded by: %2$s</string>
<string name="default_description_language">Default description language</string>
<string name="delete_reason_spam_selfie">A selfie</string>
<string name="delete_reason_spam_blurry">Blurry</string>
<string name="delete_reason_spam_nonsense">Nonsense</string>
<string name="delete_reason_spam_other">Other</string>
<string name="delete_reason_copyright_pressphoto">Press photo</string>
<string name="delete_reason_copyright_internetphoto">Random photo from internet</string>
<string name="delete_reason_copyright_logo">Logo</string>
<string name="delete_reason_copyright_other">Other</string>
<string name="delete_helper_make_deletion_toast_1">Trying to nominate\u0020</string>
<string name="delete_helper_make_deletion_toast_2">\u0020for deletion </string>
<string name="delete_helper_delete_summary_1">Nominating\u0020</string>
<string name="delete_helper_delete_summary_2">\u0020for deletion.</string>
<string name="delete_helper_delete_file_delete_string_1">{{delete|reason=</string>
<string name="delete_helper_delete_file_delete_string_2">|subpage=</string>
<string name="delete_helper_delete_file_delete_string_3">|day=</string>
<string name="delete_helper_delete_file_delete_string_4">|month=</string>
<string name="delete_helper_delete_file_delete_string_5">|year=</string>
<string name="delete_helper_delete_log_page_string">{{Commons:Deletion requests/</string>
<string name="delete_helper_delete_user_page_string">{{subst:idw|</string>
<string name="delete_helper_delete_try_commons">Commons:Deletion_requests/</string>
<string name="delete_helper_delete_try_talk">User_Talk:</string>
<string name="delete_helper_show_deletion_notification_title">Nominating for Deletion</string>
<string name="delete_helper_show_deletion_notification_title_if">: Success</string>
<string name="delete_helper_show_deletion_notification_message_if_1">Successfully nominated\u0020</string>
<string name="delete_helper_show_deletion_notification_message_if_2">: deletion.</string>
<string name="delete_helper_show_deletion_notification_title_else">: Failed</string>
<string name="delete_helper_show_deletion_notification_message_else">Could not request deletion.</string>
<string name="delete_helper_show_deletion_notification_url_for_delete">/wiki/Commons:Deletion_requests/</string>
<string name="delete_helper_ask_reason_and_execute_reason_spam_selfie">A selfie</string>
<string name="delete_helper_ask_reason_and_execute_reason_spam_blurry">Blurry</string>
<string name="delete_helper_ask_reason_and_execute_reason_spam_nonsense">Nonsense</string>
<string name="delete_helper_ask_reason_and_execute_reason_spam_other">Other</string>
<string name="delete_helper_ask_reason_and_execute_reason_copyright_press_photo">Press photo</string>
<string name="delete_helper_ask_reason_and_execute_reason_copyright_internet_photo">Random photo from internet</string>
<string name="delete_helper_ask_reason_and_execute_reason_copyright_logo">Logo</string>
<string name="delete_helper_ask_reason_and_execute_reason_copyright_other">Other</string>
<string name="delete_helper_ask_reason_and_execute_alert_set_positive_button">Ok</string>
<string name="delete_helper_ask_reason_and_execute_alert_set_positive_button_reason">Because it is\u0020</string>
<string name="delete_helper_ask_reason_and_execute_alert_set_negative_button">Cancel</string>
</resources>