2525import org .json .JSONException ;
2626import org .wordpress .android .R ;
2727import org .wordpress .android .WordPress ;
28+ import org .wordpress .android .models .FeatureSet ;
2829import org .wordpress .android .models .MediaFile ;
2930import org .wordpress .android .models .Post ;
3031import org .wordpress .android .ui .posts .PagesActivity ;
3132import org .wordpress .android .ui .posts .PostsActivity ;
33+ import org .xmlrpc .android .ApiHelper ;
3234import org .xmlrpc .android .XMLRPCClient ;
3335import org .xmlrpc .android .XMLRPCException ;
3436
@@ -53,6 +55,7 @@ public class PostUploadService extends Service {
5355 private static NotificationManager nm ;
5456 private static Post currentUploadingPost = null ;
5557 private UploadPostTask currentTask = null ;
58+ private FeatureSet mFeatureSet ;
5659
5760 public static void addPostToUpload (Post currentPost ) {
5861 synchronized (listOfPosts ) {
@@ -82,6 +85,16 @@ public void onStart(Intent intent, int startId) {
8285 uploadNextPost ();
8386 }
8487
88+ private FeatureSet synchronousGetFeatureSet () {
89+ if (WordPress .getCurrentBlog () == null || !WordPress .getCurrentBlog ().isDotcomFlag ())
90+ return null ;
91+ ApiHelper .GetFeatures task = new ApiHelper .GetFeatures ();
92+ List <Object > apiArgs = new ArrayList <Object >();
93+ apiArgs .add (WordPress .getCurrentBlog ());
94+ mFeatureSet = task .doSynchronously (apiArgs );
95+ return mFeatureSet ;
96+ }
97+
8598 private void uploadNextPost (){
8699 synchronized (listOfPosts ) {
87100 if ( currentTask == null ) { //make sure nothing is running
@@ -497,30 +510,29 @@ public String uploadMediaFile(MediaFile mf) {
497510 m .put ("bits" , mf );
498511 m .put ("overwrite" , true );
499512
500- Object [] params = { 1 , post .getBlog ().getUsername (), post .getBlog ().getPassword (), m };
501-
502- Object result = null ;
503-
504- try {
505- result = (Object ) client .call ("wp.uploadFile" , params , tempFile );
506- } catch (XMLRPCException e ) {
507- error = context .getResources ().getString (R .string .error_media_upload ) + ": " + cleanXMLRPCErrorMessage (e .getMessage ());
508- return null ;
509- }
510-
511- Map <?, ?> contentHash = (HashMap <?, ?>) result ;
512-
513- String resultURL = contentHash .get ("url" ).toString ();
514- if (contentHash .containsKey ("videopress_shortcode" )) {
515- resultURL = contentHash .get ("videopress_shortcode" ).toString () + "\n " ;
513+ Object [] params = { 1 , post .getBlog ().getUsername (),
514+ post .getBlog ().getPassword (), m };
515+
516+ FeatureSet featureSet = synchronousGetFeatureSet ();
517+ boolean selfHosted = WordPress .currentBlog != null &&
518+ !WordPress .currentBlog .isDotcomFlag ();
519+ boolean isVideoEnabled = selfHosted ||
520+ (featureSet != null && mFeatureSet .isVideopressEnabled ());
521+ if (isVideoEnabled ) {
522+ Object result = uploadFileHelper (client , params , tempFile );
523+ Map <?, ?> contentHash = (HashMap <?, ?>) result ;
524+ String resultURL = contentHash .get ("url" ).toString ();
525+ if (contentHash .containsKey ("videopress_shortcode" )) {
526+ resultURL = contentHash .get ("videopress_shortcode" ).toString () + "\n " ;
527+ } else {
528+ resultURL = String .format ("<video width=\" %s\" height=\" %s\" controls=\" controls\" ><source src=\" %s\" type=\" %s\" /><a href=\" %s\" >Click to view video</a>.</video>" ,
529+ xRes , yRes , resultURL , mimeType , resultURL );
530+ }
531+ content = content + resultURL ;
516532 } else {
517- resultURL = String
518- .format ("<video width=\" %s\" height=\" %s\" controls=\" controls\" ><source src=\" %s\" type=\" %s\" /><a href=\" %s\" >Click to view video</a>.</video>" ,
519- xRes , yRes , resultURL , mimeType , resultURL );
533+ error = getString (R .string .media_no_video_message );
534+ return null ;
520535 }
521-
522- content = content + resultURL ;
523-
524536 } // end video
525537 else {
526538
@@ -730,22 +742,15 @@ private String uploadPicture(Map<String, Object> pictureParams, MediaFile mf) {
730742 }
731743
732744 File tempFile = context .getFileStreamPath (tempFileName );
733-
734745 Object [] params = { 1 , post .getBlog ().getUsername (), post .getBlog ().getPassword (), pictureParams };
735-
736- Object result = null ;
737-
738- try {
739- result = (Object ) client .call ("wp.uploadFile" , params , tempFile );
740- } catch (XMLRPCException e ) {
741- error = context .getResources ().getString (R .string .error_media_upload ) + ": " + cleanXMLRPCErrorMessage (e .getMessage ());
746+ Object result = uploadFileHelper (client , params , tempFile );
747+ if (result == null ) {
742748 mediaError = true ;
743749 return null ;
744750 }
745-
751+
746752 Map <?, ?> contentHash = (HashMap <?, ?>) result ;
747-
748- String pictureURL = contentHash .get ("url" ).toString ();
753+ String pictureURL = contentHash .get ("url" ).toString ();
749754
750755 if (mf .isFeatured ()) {
751756 try {
@@ -761,8 +766,20 @@ private String uploadPicture(Map<String, Object> pictureParams, MediaFile mf) {
761766
762767 return pictureURL ;
763768 }
769+
770+ private Object uploadFileHelper (XMLRPCClient client , Object [] params , File tempFile ) {
771+ final Object result ;
772+ try {
773+ result = client .call ("wp.uploadFile" , params , tempFile );
774+ } catch (XMLRPCException e ) {
775+ error = context .getResources ().getString (R .string .error_media_upload ) + ": " + cleanXMLRPCErrorMessage (e .getMessage ());
776+ return null ;
777+ }
778+ return result ;
779+ }
764780 }
765-
781+
782+
766783 public String cleanXMLRPCErrorMessage (String message ) {
767784 if (message != null ) {
768785 if (message .indexOf (": " ) > -1 )
0 commit comments