mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 04:43:54 +01:00
Move try blocks to single block in DeleteTask
This commit is contained in:
parent
a449870d8b
commit
60f7e6aba8
1 changed files with 28 additions and 37 deletions
|
|
@ -23,7 +23,7 @@ import timber.log.Timber;
|
||||||
import static android.support.v4.content.ContextCompat.startActivity;
|
import static android.support.v4.content.ContextCompat.startActivity;
|
||||||
import static android.widget.Toast.LENGTH_SHORT;
|
import static android.widget.Toast.LENGTH_SHORT;
|
||||||
|
|
||||||
public class DeleteTask extends AsyncTask<Void, Void, Boolean> {
|
public class DeleteTask extends AsyncTask<Void, Integer, Boolean> {
|
||||||
|
|
||||||
@Inject MediaWikiApi mwApi;
|
@Inject MediaWikiApi mwApi;
|
||||||
@Inject SessionManager sessionManager;
|
@Inject SessionManager sessionManager;
|
||||||
|
|
@ -55,17 +55,6 @@ public class DeleteTask extends AsyncTask<Void, Void, Boolean> {
|
||||||
authCookie = sessionManager.getAuthCookie();
|
authCookie = sessionManager.getAuthCookie();
|
||||||
mwApi.setAuthCookie(authCookie);
|
mwApi.setAuthCookie(authCookie);
|
||||||
|
|
||||||
try {
|
|
||||||
editToken = mwApi.getEditToken();
|
|
||||||
}
|
|
||||||
catch (Exception e){
|
|
||||||
Timber.d(e.getMessage());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (editToken.equals("+\\")) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Calendar calendar = Calendar.getInstance();
|
Calendar calendar = Calendar.getInstance();
|
||||||
String fileDeleteString = "{{delete|reason=" + reason +
|
String fileDeleteString = "{{delete|reason=" + reason +
|
||||||
"|subpage=" +media.getFilename() +
|
"|subpage=" +media.getFilename() +
|
||||||
|
|
@ -73,43 +62,38 @@ public class DeleteTask extends AsyncTask<Void, Void, Boolean> {
|
||||||
"|month=" + calendar.getDisplayName(Calendar.MONTH,Calendar.LONG, Locale.getDefault()) +
|
"|month=" + calendar.getDisplayName(Calendar.MONTH,Calendar.LONG, Locale.getDefault()) +
|
||||||
"|year=" + calendar.get(Calendar.YEAR) +
|
"|year=" + calendar.get(Calendar.YEAR) +
|
||||||
"}}";
|
"}}";
|
||||||
try{
|
|
||||||
mwApi.prependEdit(editToken,fileDeleteString+"\n",
|
|
||||||
media.getFilename(),summary);
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
Timber.d(e.getMessage());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
String subpageString = "=== [[:" + media.getFilename() + "]] ===\n" +
|
String subpageString = "=== [[:" + media.getFilename() + "]] ===\n" +
|
||||||
reason +
|
reason +
|
||||||
" ~~~~";
|
" ~~~~";
|
||||||
try{
|
|
||||||
mwApi.edit(editToken,subpageString+"\n",
|
|
||||||
"Commons:Deletion_requests/"+media.getFilename(),summary);
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
Timber.d(e.getMessage());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
String logPageString = "\n{{Commons:Deletion requests/" + media.getFilename() +
|
String logPageString = "\n{{Commons:Deletion requests/" + media.getFilename() +
|
||||||
"}}\n";
|
"}}\n";
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
|
||||||
String date = sdf.format(calendar.getTime());
|
String date = sdf.format(calendar.getTime());
|
||||||
try{
|
|
||||||
mwApi.appendEdit(editToken,logPageString+"\n",
|
|
||||||
"Commons:Deletion_requests/"+date,summary);
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
Timber.d(e.getMessage());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
String userPageString = "\n{{subst:idw|" + media.getFilename() +
|
String userPageString = "\n{{subst:idw|" + media.getFilename() +
|
||||||
"}} ~~~~";
|
"}} ~~~~";
|
||||||
try{
|
|
||||||
|
try {
|
||||||
|
editToken = mwApi.getEditToken();
|
||||||
|
if (editToken.equals("+\\")) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
publishProgress(1);
|
||||||
|
|
||||||
|
mwApi.prependEdit(editToken,fileDeleteString+"\n",
|
||||||
|
media.getFilename(),summary);
|
||||||
|
publishProgress(2);
|
||||||
|
|
||||||
|
mwApi.edit(editToken,subpageString+"\n",
|
||||||
|
"Commons:Deletion_requests/"+media.getFilename(),summary);
|
||||||
|
publishProgress(3);
|
||||||
|
|
||||||
|
mwApi.appendEdit(editToken,logPageString+"\n",
|
||||||
|
"Commons:Deletion_requests/"+date,summary);
|
||||||
|
publishProgress(4);
|
||||||
|
|
||||||
mwApi.appendEdit(editToken,userPageString+"\n",
|
mwApi.appendEdit(editToken,userPageString+"\n",
|
||||||
"User_Talk:"+sessionManager.getCurrentAccount().name,summary);
|
"User_Talk:"+sessionManager.getCurrentAccount().name,summary);
|
||||||
}
|
}
|
||||||
|
|
@ -120,10 +104,16 @@ public class DeleteTask extends AsyncTask<Void, Void, Boolean> {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onProgressUpdate (Integer... values){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(Boolean result) {
|
protected void onPostExecute(Boolean result) {
|
||||||
String message = "";
|
String message = "";
|
||||||
String title = "";
|
String title = "";
|
||||||
|
|
||||||
if (result){
|
if (result){
|
||||||
title = "Success";
|
title = "Success";
|
||||||
message = "Successfully nominated " + media.getDisplayTitle() + " deletion.\n" +
|
message = "Successfully nominated " + media.getDisplayTitle() + " deletion.\n" +
|
||||||
|
|
@ -133,6 +123,7 @@ public class DeleteTask extends AsyncTask<Void, Void, Boolean> {
|
||||||
title = "Failed";
|
title = "Failed";
|
||||||
message = "Could not request deletion. Something went wrong.";
|
message = "Could not request deletion. Something went wrong.";
|
||||||
}
|
}
|
||||||
|
|
||||||
AlertDialog alert;
|
AlertDialog alert;
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||||
builder.setTitle(title);
|
builder.setTitle(title);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue