2323import static android .support .v4 .content .ContextCompat .startActivity ;
2424import static android .widget .Toast .LENGTH_SHORT ;
2525
26- public class DeleteTask extends AsyncTask <Void , Void , Boolean > {
26+ public class DeleteTask extends AsyncTask <Void , Integer , Boolean > {
2727
2828 @ Inject MediaWikiApi mwApi ;
2929 @ Inject SessionManager sessionManager ;
@@ -55,61 +55,45 @@ protected Boolean doInBackground(Void ...voids) {
5555 authCookie = sessionManager .getAuthCookie ();
5656 mwApi .setAuthCookie (authCookie );
5757
58- try {
59- editToken = mwApi .getEditToken ();
60- }
61- catch (Exception e ){
62- Timber .d (e .getMessage ());
63- return false ;
64- }
65- if (editToken .equals ("+\\ " )) {
66- return false ;
67- }
68-
6958 Calendar calendar = Calendar .getInstance ();
7059 String fileDeleteString = "{{delete|reason=" + reason +
7160 "|subpage=" +media .getFilename () +
7261 "|day=" + calendar .get (Calendar .DAY_OF_MONTH ) +
7362 "|month=" + calendar .getDisplayName (Calendar .MONTH ,Calendar .LONG , Locale .getDefault ()) +
7463 "|year=" + calendar .get (Calendar .YEAR ) +
7564 "}}" ;
76- try {
77- mwApi .prependEdit (editToken ,fileDeleteString +"\n " ,
78- media .getFilename (),summary );
79- }
80- catch (Exception e ) {
81- Timber .d (e .getMessage ());
82- return false ;
83- }
8465
8566 String subpageString = "=== [[:" + media .getFilename () + "]] ===\n " +
8667 reason +
8768 " ~~~~" ;
88- try {
89- mwApi .edit (editToken ,subpageString +"\n " ,
90- "Commons:Deletion_requests/" +media .getFilename (),summary );
91- }
92- catch (Exception e ) {
93- Timber .d (e .getMessage ());
94- return false ;
95- }
9669
9770 String logPageString = "\n {{Commons:Deletion requests/" + media .getFilename () +
9871 "}}\n " ;
9972 SimpleDateFormat sdf = new SimpleDateFormat ("yyyy/MM/dd" );
10073 String date = sdf .format (calendar .getTime ());
101- try {
102- mwApi .appendEdit (editToken ,logPageString +"\n " ,
103- "Commons:Deletion_requests/" +date ,summary );
104- }
105- catch (Exception e ) {
106- Timber .d (e .getMessage ());
107- return false ;
108- }
10974
11075 String userPageString = "\n {{subst:idw|" + media .getFilename () +
11176 "}} ~~~~" ;
112- try {
77+
78+ try {
79+ editToken = mwApi .getEditToken ();
80+ if (editToken .equals ("+\\ " )) {
81+ return false ;
82+ }
83+ publishProgress (1 );
84+
85+ mwApi .prependEdit (editToken ,fileDeleteString +"\n " ,
86+ media .getFilename (),summary );
87+ publishProgress (2 );
88+
89+ mwApi .edit (editToken ,subpageString +"\n " ,
90+ "Commons:Deletion_requests/" +media .getFilename (),summary );
91+ publishProgress (3 );
92+
93+ mwApi .appendEdit (editToken ,logPageString +"\n " ,
94+ "Commons:Deletion_requests/" +date ,summary );
95+ publishProgress (4 );
96+
11397 mwApi .appendEdit (editToken ,userPageString +"\n " ,
11498 "User_Talk:" +sessionManager .getCurrentAccount ().name ,summary );
11599 }
@@ -120,10 +104,16 @@ protected Boolean doInBackground(Void ...voids) {
120104 return true ;
121105 }
122106
107+ @ Override
108+ protected void onProgressUpdate (Integer ... values ){
109+
110+ }
111+
123112 @ Override
124113 protected void onPostExecute (Boolean result ) {
125114 String message = "" ;
126115 String title = "" ;
116+
127117 if (result ){
128118 title = "Success" ;
129119 message = "Successfully nominated " + media .getDisplayTitle () + " deletion.\n " +
@@ -133,6 +123,7 @@ protected void onPostExecute(Boolean result) {
133123 title = "Failed" ;
134124 message = "Could not request deletion. Something went wrong." ;
135125 }
126+
136127 AlertDialog alert ;
137128 AlertDialog .Builder builder = new AlertDialog .Builder (context );
138129 builder .setTitle (title );
0 commit comments