2323
2424import org .json .JSONArray ;
2525import org .json .JSONException ;
26+ import org .wordpress .android .Constants ;
2627import org .wordpress .android .R ;
2728import org .wordpress .android .WordPress ;
2829import org .wordpress .android .models .FeatureSet ;
@@ -56,7 +57,7 @@ public class PostUploadService extends Service {
5657 private static Post currentUploadingPost = null ;
5758 private UploadPostTask currentTask = null ;
5859 private FeatureSet mFeatureSet ;
59-
60+
6061 public static void addPostToUpload (Post currentPost ) {
6162 synchronized (listOfPosts ) {
6263 listOfPosts .add (currentPost );
@@ -127,18 +128,16 @@ public static boolean isUploading(Post post) {
127128 }
128129
129130 private class UploadPostTask extends AsyncTask <Post , Boolean , Boolean > {
130-
131131 private Post post ;
132- String error = "" ;
133- boolean mediaError = false ;
132+ private String mErrorMessage = "" ;
133+ private boolean mIsMediaError = false ;
134+ private boolean mErrorUnavailableVideoPress = false ;
134135 private int featuredImageID = -1 ;
135-
136136 private int notificationID ;
137137 private Notification n ;
138138
139139 @ Override
140140 protected void onPostExecute (Boolean postUploadedSuccessfully ) {
141-
142141 if (postUploadedSuccessfully ) {
143142 WordPress .postUploaded ();
144143 nm .cancel (notificationID );
@@ -152,15 +151,20 @@ protected void onPostExecute(Boolean postUploadedSuccessfully) {
152151 notificationIntent .setAction ("android.intent.action.MAIN" );
153152 notificationIntent .addCategory ("android.intent.category.LAUNCHER" );
154153 notificationIntent .setData ((Uri .parse ("custom://wordpressNotificationIntent" + post .getBlogID ())));
155- notificationIntent .putExtra ("errorMessage" , error );
154+ notificationIntent .putExtra ("errorMessage" , mErrorMessage );
155+ if (mErrorUnavailableVideoPress ) {
156+ notificationIntent .putExtra ("errorInfoTitle" , getString (R .string .learn_more ));
157+ notificationIntent .putExtra ("errorInfoLink" , Constants .videoPressURL );
158+ }
156159 notificationIntent .addFlags (Intent .FLAG_ACTIVITY_NEW_TASK );
157- PendingIntent pendingIntent = PendingIntent .getActivity (context , 0 , notificationIntent , PendingIntent .FLAG_UPDATE_CURRENT );
160+ PendingIntent pendingIntent = PendingIntent .getActivity (context , 0 ,
161+ notificationIntent , PendingIntent .FLAG_UPDATE_CURRENT );
158162 n .flags |= Notification .FLAG_AUTO_CANCEL ;
159163 String errorText = context .getResources ().getText (R .string .upload_failed ).toString ();
160- if (mediaError )
164+ if (mIsMediaError )
161165 errorText = context .getResources ().getText (R .string .media ) + " " + context .getResources ().getText (R .string .error );
162- n .setLatestEventInfo (context , (mediaError ) ? errorText : context .getResources ().getText (R .string .upload_failed ),
163- (mediaError ) ? error : postOrPage + " " + errorText + ": " + error , pendingIntent );
166+ n .setLatestEventInfo (context , (mIsMediaError ) ? errorText : context .getResources ().getText (R .string .upload_failed ),
167+ (mIsMediaError ) ? mErrorMessage : postOrPage + " " + errorText + ": " + mErrorMessage , pendingIntent );
164168
165169 nm .notify (notificationID , n ); // needs a unique id
166170 }
@@ -170,7 +174,7 @@ protected void onPostExecute(Boolean postUploadedSuccessfully) {
170174
171175 @ Override
172176 protected Boolean doInBackground (Post ... posts ) {
173-
177+ mErrorUnavailableVideoPress = false ;
174178 post = posts [0 ];
175179
176180 // add the uploader to the notification bar
@@ -250,7 +254,7 @@ protected Boolean doInBackground(Post... posts) {
250254 descriptionContent = descriptionContent .replace (tag , "" );
251255 else
252256 moreContent = moreContent .replace (tag , "" );
253- mediaError = true ;
257+ mIsMediaError = true ;
254258 }
255259 }
256260 }
@@ -260,7 +264,7 @@ protected Boolean doInBackground(Post... posts) {
260264 }
261265
262266 // If media file upload failed, let's stop here and prompt the user
263- if (mediaError )
267+ if (mIsMediaError )
264268 return false ;
265269
266270 JSONArray categoriesJsonArray = post .getJSONCategories ();
@@ -394,11 +398,11 @@ protected Boolean doInBackground(Post... posts) {
394398 post .update ();
395399 return true ;
396400 } catch (final XMLRPCException e ) {
397- error = String .format (context .getResources ().getText (R .string .error_upload ).toString (), post .isPage () ? context
401+ mErrorMessage = String .format (context .getResources ().getText (R .string .error_upload ).toString (), post .isPage () ? context
398402 .getResources ().getText (R .string .page ).toString () : context .getResources ().getText (R .string .post ).toString ())
399403 + " " + cleanXMLRPCErrorMessage (e .getMessage ());
400- mediaError = false ;
401- Log .i ("WP" , error );
404+ mIsMediaError = false ;
405+ Log .i ("WP" , mErrorMessage );
402406 }
403407
404408 return false ;
@@ -432,8 +436,8 @@ public String uploadMediaFile(MediaFile mf) {
432436 try {
433437 context .openFileOutput (tempFileName , Context .MODE_PRIVATE );
434438 } catch (FileNotFoundException e ) {
435- error = getResources ().getString (R .string .file_error_create );
436- mediaError = true ;
439+ mErrorMessage = getResources ().getString (R .string .file_error_create );
440+ mIsMediaError = true ;
437441 return null ;
438442 }
439443
@@ -496,7 +500,7 @@ public String uploadMediaFile(MediaFile mf) {
496500 }
497501
498502 if (fVideo == null ) {
499- error = context .getResources ().getString (R .string .error_media_upload ) + "." ;
503+ mErrorMessage = context .getResources ().getString (R .string .error_media_upload ) + "." ;
500504 return null ;
501505 }
502506
@@ -530,7 +534,8 @@ public String uploadMediaFile(MediaFile mf) {
530534 }
531535 content = content + resultURL ;
532536 } else {
533- error = getString (R .string .media_no_video_message );
537+ mErrorMessage = getString (R .string .media_no_video_message );
538+ mErrorUnavailableVideoPress = true ;
534539 return null ;
535540 }
536541 } // end video
@@ -584,8 +589,8 @@ public String uploadMediaFile(MediaFile mf) {
584589
585590 // check if the file exists
586591 if (jpeg == null ) {
587- error = context .getString (R .string .file_not_found );
588- mediaError = true ;
592+ mErrorMessage = context .getString (R .string .file_not_found );
593+ mIsMediaError = true ;
589594 return null ;
590595 }
591596
@@ -620,8 +625,8 @@ public String uploadMediaFile(MediaFile mf) {
620625 try {
621626 bytes = new byte [(int ) jpeg .length ()];
622627 } catch (OutOfMemoryError er ) {
623- error = context .getString (R .string .out_of_memory );
624- mediaError = true ;
628+ mErrorMessage = context .getString (R .string .out_of_memory );
629+ mIsMediaError = true ;
625630 return null ;
626631 }
627632
@@ -648,8 +653,8 @@ public String uploadMediaFile(MediaFile mf) {
648653 finalBytes = ih2 .createThumbnail (bytes , width , orientation , false );
649654
650655 if (finalBytes == null ) {
651- error = context .getString (R .string .out_of_memory );
652- mediaError = true ;
656+ mErrorMessage = context .getString (R .string .out_of_memory );
657+ mIsMediaError = true ;
653658 return null ;
654659 }
655660
@@ -728,24 +733,23 @@ public String uploadMediaFile(MediaFile mf) {
728733
729734
730735 private String uploadPicture (Map <String , Object > pictureParams , MediaFile mf ) {
731-
732736 XMLRPCClient client = new XMLRPCClient (post .getBlog ().getUrl (), post .getBlog ().getHttpuser (), post .getBlog ().getHttppassword ());
733737
734738 // create temp file for media upload
735739 String tempFileName = "wp-" + System .currentTimeMillis ();
736740 try {
737741 context .openFileOutput (tempFileName , Context .MODE_PRIVATE );
738742 } catch (FileNotFoundException e ) {
739- mediaError = true ;
740- error = context .getString (R .string .file_not_found );
743+ mIsMediaError = true ;
744+ mErrorMessage = context .getString (R .string .file_not_found );
741745 return null ;
742746 }
743747
744748 File tempFile = context .getFileStreamPath (tempFileName );
745749 Object [] params = { 1 , post .getBlog ().getUsername (), post .getBlog ().getPassword (), pictureParams };
746750 Object result = uploadFileHelper (client , params , tempFile );
747751 if (result == null ) {
748- mediaError = true ;
752+ mIsMediaError = true ;
749753 return null ;
750754 }
751755
@@ -772,7 +776,7 @@ private Object uploadFileHelper(XMLRPCClient client, Object[] params, File tempF
772776 try {
773777 result = client .call ("wp.uploadFile" , params , tempFile );
774778 } catch (XMLRPCException e ) {
775- error = context .getResources ().getString (R .string .error_media_upload ) + ": " + cleanXMLRPCErrorMessage (e .getMessage ());
779+ mErrorMessage = context .getResources ().getString (R .string .error_media_upload ) + ": " + cleanXMLRPCErrorMessage (e .getMessage ());
776780 return null ;
777781 }
778782 return result ;
0 commit comments