Skip to content

Commit cbc85d1

Browse files
committed
New _Learn More_ button added to the error dialog saying _You should install VideoPress to upload video to your WP.com blog_ in PostsActivity
1 parent eb29fb1 commit cbc85d1

File tree

4 files changed

+86
-68
lines changed

4 files changed

+86
-68
lines changed

res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
<string name="please_wait_refresh_done">Please wait, loading items.</string>
108108
<string name="please_wait_uploading_done">Please wait, uploading item.</string>
109109
<string name="info">Info</string>
110+
<string name="learn_more">Learn More</string>
110111

111112
<!-- Media Gallery Action Bar -->
112113
<string name="media_add_popup_title">Add to media library</string>

src/org/wordpress/android/Constants.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ public class Constants {
1313

1414
public static String wpcomXMLRPCURL = "https://wordpress.com/xmlrpc.php";
1515
public static String wpcomLoginURL = "https://wordpress.com/wp-login.php";
16-
16+
17+
public static String videoPressURL = "http://videopress.com";
18+
1719
public static int QUICK_POST_PHOTO_CAMERA = 0;
1820
public static int QUICK_POST_PHOTO_LIBRARY = 1;
1921
public static int QUICK_POST_VIDEO_CAMERA = 2;

src/org/wordpress/android/ui/posts/PostsActivity.java

Lines changed: 46 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
11
package org.wordpress.android.ui.posts;
22

3-
import java.io.BufferedReader;
4-
import java.io.InputStreamReader;
5-
import java.net.HttpURLConnection;
6-
import java.net.URL;
7-
import java.util.Iterator;
8-
import java.util.HashMap;
9-
import java.util.Map;
10-
113
import android.app.AlertDialog;
124
import android.app.Dialog;
135
import android.app.ProgressDialog;
146
import android.content.DialogInterface;
157
import android.content.Intent;
168
import android.content.SharedPreferences;
9+
import android.net.Uri;
1710
import android.os.AsyncTask;
1811
import android.os.Bundle;
1912
import android.preference.PreferenceManager;
@@ -26,23 +19,30 @@
2619
import com.actionbarsherlock.view.MenuInflater;
2720
import com.actionbarsherlock.view.MenuItem;
2821

29-
import org.xmlrpc.android.ApiHelper;
30-
import org.xmlrpc.android.XMLRPCClient;
31-
import org.xmlrpc.android.XMLRPCException;
32-
3322
import org.wordpress.android.R;
3423
import org.wordpress.android.WordPress;
35-
import org.wordpress.passcodelock.AppLockManager;
3624
import org.wordpress.android.models.Post;
3725
import org.wordpress.android.ui.MenuDrawerItem;
3826
import org.wordpress.android.ui.WPActionBarActivity;
3927
import org.wordpress.android.ui.comments.AddCommentActivity;
40-
import org.wordpress.android.ui.posts.ViewPostFragment.OnDetailPostActionListener;
28+
import org.wordpress.android.ui.notifications.NotificationsActivity;
4129
import org.wordpress.android.ui.posts.PostsListFragment.OnPostActionListener;
4230
import org.wordpress.android.ui.posts.PostsListFragment.OnPostSelectedListener;
4331
import org.wordpress.android.ui.posts.PostsListFragment.OnRefreshListener;
32+
import org.wordpress.android.ui.posts.ViewPostFragment.OnDetailPostActionListener;
4433
import org.wordpress.android.util.WPAlertDialogFragment.OnDialogConfirmListener;
45-
import org.wordpress.android.ui.notifications.NotificationsActivity;
34+
import org.wordpress.passcodelock.AppLockManager;
35+
import org.xmlrpc.android.ApiHelper;
36+
import org.xmlrpc.android.XMLRPCClient;
37+
import org.xmlrpc.android.XMLRPCException;
38+
39+
import java.io.BufferedReader;
40+
import java.io.InputStreamReader;
41+
import java.net.HttpURLConnection;
42+
import java.net.URL;
43+
import java.util.HashMap;
44+
import java.util.Iterator;
45+
import java.util.Map;
4646

4747
public class PostsActivity extends WPActionBarActivity implements OnPostSelectedListener,
4848
OnRefreshListener, OnPostActionListener, OnDetailPostActionListener, OnDialogConfirmListener {
@@ -75,6 +75,7 @@ public void onCreate(Bundle savedInstanceState) {
7575
startNotificationsActivity(extras);
7676
return;
7777
}
78+
showErrorDialogIfNeeded(extras);
7879

7980
// Restore last selection on app creation
8081
if (WordPress.shouldRestoreSelectedActivity && WordPress.getCurrentBlog() != null
@@ -123,9 +124,7 @@ public void onFailure() {
123124

124125
if (extras != null) {
125126
isPage = extras.getBoolean("viewPages");
126-
String errorMessage = extras.getString("errorMessage");
127-
if (errorMessage != null)
128-
showPostUploadErrorAlert(errorMessage);
127+
showErrorDialogIfNeeded(extras);
129128
}
130129

131130
if (isPage)
@@ -151,20 +150,25 @@ public void OnPostUploaded() {
151150
popPostDetail();
152151
}
153152

154-
private void showPostUploadErrorAlert(String errorMessage) {
155-
156-
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(
157-
PostsActivity.this);
158-
dialogBuilder.setTitle(getResources().getText(
159-
R.string.error));
153+
private void showPostUploadErrorAlert(String errorMessage, String infoTitle,
154+
final String infoLink) {
155+
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(PostsActivity.this);
156+
dialogBuilder.setTitle(getResources().getText(R.string.error));
160157
dialogBuilder.setMessage(errorMessage);
161158
dialogBuilder.setPositiveButton("OK",
162159
new DialogInterface.OnClickListener() {
163-
public void onClick(DialogInterface dialog,
164-
int whichButton) {
160+
public void onClick(DialogInterface dialog, int whichButton) {
165161
// Just close the window.
166162
}
167163
});
164+
if (infoTitle != null && infoLink != null) {
165+
dialogBuilder.setNeutralButton(infoTitle,
166+
new DialogInterface.OnClickListener() {
167+
public void onClick(DialogInterface dialog, int whichButton) {
168+
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(infoLink)));
169+
}
170+
});
171+
}
168172
dialogBuilder.setCancelable(true);
169173
if (!isFinishing())
170174
dialogBuilder.create().show();
@@ -181,12 +185,19 @@ protected void onNewIntent(Intent intent) {
181185
startNotificationsActivity(extras);
182186
return;
183187
}
184-
185-
String errorMessage = extras.getString("errorMessage");
186-
if (errorMessage != null)
187-
showPostUploadErrorAlert(errorMessage);
188188
}
189-
189+
}
190+
191+
private void showErrorDialogIfNeeded(Bundle extras) {
192+
if (extras == null) {
193+
return ;
194+
}
195+
String errorMessage = extras.getString("errorMessage");
196+
String errorInfoTitle = extras.getString("errorInfoTitle");
197+
String errorInfoLink = extras.getString("errorInfoLink");
198+
if (errorMessage != null) {
199+
showPostUploadErrorAlert(errorMessage, errorInfoTitle, errorInfoLink);
200+
}
190201
}
191202

192203
private void startNotificationsActivity(Bundle extras) {
@@ -345,7 +356,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
345356
if (!returnText.equals("CANCEL")) {
346357
// Add comment to the server if user didn't cancel.
347358
final String postID = extras.getString("postID");
348-
new PostsActivity.addCommentTask().execute(postID, returnText);
359+
new addCommentTask().execute(postID, returnText);
349360
}
350361
}
351362
}
@@ -709,7 +720,7 @@ protected String doInBackground(Post... params) {
709720
}
710721

711722
private void refreshComments() {
712-
new PostsActivity.refreshCommentsTask().execute();
723+
new refreshCommentsTask().execute();
713724
}
714725

715726
private String getShortlinkTagHref(String urlString) {
@@ -813,7 +824,7 @@ public void onClick(DialogInterface dialog,
813824
new DialogInterface.OnClickListener() {
814825
public void onClick(DialogInterface dialog,
815826
int whichButton) {
816-
new PostsActivity.deletePostTask().execute(post);
827+
new deletePostTask().execute(post);
817828
}
818829
});
819830
dialogBuilder.setNegativeButton(
@@ -832,7 +843,7 @@ public void onClick(DialogInterface dialog,
832843

833844
}
834845
} else if (action == POST_SHARE) {
835-
new PostsActivity.shareURLTask().execute(post);
846+
new shareURLTask().execute(post);
836847
} else if (action == POST_CLEAR) {
837848
FragmentManager fm = getSupportFragmentManager();
838849
ViewPostFragment f = (ViewPostFragment) fm

src/org/wordpress/android/util/PostUploadService.java

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import org.json.JSONArray;
2525
import org.json.JSONException;
26+
import org.wordpress.android.Constants;
2627
import org.wordpress.android.R;
2728
import org.wordpress.android.WordPress;
2829
import 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

Comments
 (0)