Skip to content

Commit

Permalink
Merge pull request #6420 from wordpress-mobile/issue/6386-async-desig…
Browse files Browse the repository at this point in the history
…n-tweaks

Async media: Design and copy updates
  • Loading branch information
mzorz authored Jul 31, 2017
2 parents 449f514 + d416da0 commit 9a138f8
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ protected void onPostExecute(Boolean pushActionWasDispatched) {
// This block only runs if the PUSH_POST action was never dispatched - if it was dispatched, any error
// will be handled in OnPostChanged instead of here
mPostUploadNotifier.cancelNotification(mPost);
mPostUploadNotifier.updateNotificationError(mPost, mSite, mErrorMessage, mIsMediaError);
mPostUploadNotifier.updateNotificationError(mPost, mSite, mErrorMessage);
finishUpload();
}
}
Expand Down Expand Up @@ -561,8 +561,8 @@ public void onPostUploaded(OnPostUploaded event) {
+ event.error.message);
Context context = WordPress.getContext();
String errorMessage = UploadUtils.getErrorMessageFromPostError(context, event.post, event.error);
String notificationMessage = UploadUtils.getErrorMessage(context, event.post, errorMessage);
mPostUploadNotifier.updateNotificationError(event.post, site, notificationMessage, false);
String notificationMessage = UploadUtils.getErrorMessage(context, event.post, errorMessage, false);
mPostUploadNotifier.updateNotificationError(event.post, site, notificationMessage);
mPostUploadNotifier.cancelNotification(event.post);
sFirstPublishPosts.remove(event.post.getId());
} else {
Expand Down Expand Up @@ -610,9 +610,10 @@ private void handleMediaUploadCompletedLegacy(OnMediaUploaded event) {
SiteModel site = mSiteStore.getSiteByLocalId(sCurrentUploadingPost.getLocalSiteId());
Context context = WordPress.getContext();
String errorMessage = UploadUtils.getErrorMessageFromMediaError(context, event.media, event.error);
String notificationMessage = UploadUtils.getErrorMessage(context, sCurrentUploadingPost, errorMessage);
String notificationMessage =
UploadUtils.getErrorMessage(context, sCurrentUploadingPost, errorMessage, true);
mPostUploadNotifier.cancelNotification(sCurrentUploadingPost);
mPostUploadNotifier.updateNotificationError(sCurrentUploadingPost, site, notificationMessage, true);
mPostUploadNotifier.updateNotificationError(sCurrentUploadingPost, site, notificationMessage);
sFirstPublishPosts.remove(sCurrentUploadingPost.getId());
finishUpload();
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,26 @@ void updateNotificationSuccess(PostModel post, SiteModel site, boolean isFirstTi
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(mContext.getApplicationContext());
String notificationTitle;
String notificationMessage;

String postTitle = TextUtils.isEmpty(post.getTitle()) ? mContext.getString(R.string.untitled) : post.getTitle();

if (PostStatus.DRAFT.equals(PostStatus.fromPost(post))) {
notificationTitle = (String) mContext.getResources().getText(R.string.draft_uploaded);
notificationTitle = mContext.getString(R.string.draft_uploaded);
notificationMessage = String.format(mContext.getString(R.string.post_draft_param), postTitle);
} else if (PostStatus.SCHEDULED.equals(PostStatus.fromPost(post))) {
notificationTitle = mContext.getString(post.isPage() ? R.string.page_scheduled : R.string.post_scheduled);
notificationMessage = String.format(mContext.getString(R.string.post_scheduled_param), postTitle);
} else {
if (post.isPage()) {
notificationTitle = (String) mContext.getResources().getText(
notificationTitle = mContext.getString(
isFirstTimePublish ? R.string.page_published : R.string.page_updated);
} else {
notificationTitle = (String) mContext.getResources().getText(
notificationTitle = mContext.getString(
isFirstTimePublish ? R.string.post_published : R.string.post_updated);
}
notificationMessage = String.format(mContext.getString(
isFirstTimePublish ? R.string.post_published_param : R.string.post_updated_param), postTitle);
}

notificationBuilder.setSmallIcon(android.R.drawable.stat_sys_upload_done);
Expand All @@ -127,10 +137,9 @@ void updateNotificationSuccess(PostModel post, SiteModel site, boolean isFirstTi
} else {
notificationBuilder.setLargeIcon(notificationData.latestIcon);
}
String message = post.getTitle();
notificationBuilder.setContentTitle(notificationTitle);
notificationBuilder.setContentText(message);
notificationBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(message));
notificationBuilder.setContentText(notificationMessage);
notificationBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(notificationMessage));
notificationBuilder.setAutoCancel(true);

long notificationId = getNotificationIdForPost(post);
Expand Down Expand Up @@ -166,12 +175,11 @@ private long getNotificationIdForPost(PostModel post) {
return post.getLocalSiteId() + remotePostId;
}

void updateNotificationError(PostModel post, SiteModel site, String errorMessage, boolean isMediaError) {
void updateNotificationError(PostModel post, SiteModel site, String errorMessage) {
AppLog.d(AppLog.T.POSTS, "updateNotificationError: " + errorMessage);

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(mContext.getApplicationContext());
String postOrPage = (String) (post.isPage() ? mContext.getResources().getText(R.string.page_id)
: mContext.getResources().getText(R.string.post_id));
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(mContext.getApplicationContext());

long notificationId = getNotificationIdForPost(post);
// Tap notification intent (open the post list)
Expand All @@ -187,18 +195,10 @@ void updateNotificationError(PostModel post, SiteModel site, String errorMessage
(int)notificationId,
notificationIntent, PendingIntent.FLAG_ONE_SHOT);

String errorText = mContext.getResources().getText(R.string.upload_failed).toString();
if (isMediaError) {
errorText = mContext.getResources().getText(R.string.media) + " "
+ mContext.getResources().getText(R.string.error);
}

String message = (isMediaError) ? errorMessage : postOrPage + " " + errorText + ": " + errorMessage;
notificationBuilder.setSmallIcon(android.R.drawable.stat_notify_error);
notificationBuilder.setContentTitle((isMediaError) ? errorText :
mContext.getResources().getText(R.string.upload_failed));
notificationBuilder.setContentText(message);
notificationBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(message));
notificationBuilder.setContentTitle(mContext.getString(R.string.upload_failed));
notificationBuilder.setContentText(errorMessage);
notificationBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(errorMessage));
notificationBuilder.setContentIntent(pendingIntent);
notificationBuilder.setAutoCancel(true);

Expand Down Expand Up @@ -256,6 +256,6 @@ void setCurrentMediaItem(PostModel post, int currentItem) {

private String buildNotificationTitleForPost(PostModel post) {
String postTitle = TextUtils.isEmpty(post.getTitle()) ? mContext.getString(R.string.untitled) : post.getTitle();
return String.format(mContext.getString(R.string.posting_post), postTitle);
return String.format(mContext.getString(R.string.uploading_post), postTitle);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -524,8 +524,8 @@ private void cancelPostUploadMatchingMedia(MediaModel media, String mediaErrorMe
SiteModel site = mSiteStore.getSiteByLocalId(postToCancel.getLocalSiteId());
mPostUploadNotifier.cancelNotification(postToCancel);
if (showErrorNotification) {
String message = UploadUtils.getErrorMessage(this, postToCancel, mediaErrorMessage);
mPostUploadNotifier.updateNotificationError(postToCancel, site, message, true);
String message = UploadUtils.getErrorMessage(this, postToCancel, mediaErrorMessage, true);
mPostUploadNotifier.updateNotificationError(postToCancel, site, message);
}

mPostUploadHandler.unregisterPostForAnalyticsTracking(postToCancel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ public class UploadUtils {
/**
* Returns a post-type specific error message string.
*/
static @NonNull String getErrorMessage(Context context, PostModel post, String specificMessage) {
static @NonNull String getErrorMessage(Context context, PostModel post, String errorMessage, boolean isMediaError) {
String baseErrorString = context.getString(
isMediaError ? R.string.error_upload_post_media_params : R.string.error_upload_post_params);
String postType = context.getString(post.isPage() ? R.string.page : R.string.post).toLowerCase();
return String.format(context.getText(R.string.error_upload_params).toString(), postType, specificMessage);
return String.format(baseErrorString, postType, errorMessage);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public void onCancel(DialogInterface dialog) {
case TIMEOUT:
return context.getString(R.string.media_error_timeout);
case CONNECTION_ERROR:
return context.getString(R.string.connection_error);
return context.getString(R.string.connection_to_server_lost);
case EXCEEDS_FILESIZE_LIMIT:
return context.getString(R.string.media_error_exceeds_php_filesize);
case EXCEEDS_MEMORY_LIMIT:
Expand Down
2 changes: 1 addition & 1 deletion WordPress/src/main/res/layout/post_cardview.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
android:id="@+id/image_status"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_gravity="bottom"
android:layout_gravity="center"
android:layout_marginRight="@dimen/margin_small"
tools:src="@drawable/ic_gridicons_cloud_upload"
/>
Expand Down
22 changes: 16 additions & 6 deletions WordPress/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
<string name="edit_post">Edit post</string>
<string name="add_comment">Add comment</string>
<string name="connection_error">Connection error</string>
<string name="connection_to_server_lost">The connection to the server was lost</string>
<string name="category_refresh_error">Category refresh error</string>
<string name="incorrect_credentials">Incorrect username or password.</string>
<string name="cancel_edit">Cancel edit</string>
Expand All @@ -84,7 +85,7 @@
<string name="sign_in_wpcom">Log in to WordPress.com</string>
<string name="upload">Upload</string>
<string name="learn_more">Learn more</string>
<string name="posting_post">Posting \"%s\"</string>
<string name="uploading_post">Uploading \"%s\"</string>
<string name="language">Language</string>
<string name="interface_language">Interface Language</string>
<string name="signout">Log out</string>
Expand Down Expand Up @@ -267,12 +268,20 @@
<item>@string/filter_trashed_posts</item>
</string-array>

<!-- post uploads -->
<string name="post_published_param">\"%s\" has been published!</string>
<string name="post_updated_param">\"%s\" has been updated!</string>
<string name="post_scheduled_param">\"%s\" has been scheduled!</string>
<string name="post_draft_param">\"%s\" has been saved as a draft!</string>

<!-- post view -->
<string name="post_id">Post</string>
<string name="upload_failed">Upload failed</string>
<string name="draft_uploaded">Draft uploaded</string>
<string name="post_published">Post published</string>
<string name="page_published">Page published</string>
<string name="post_scheduled">Post scheduled</string>
<string name="page_scheduled">Page scheduled</string>
<string name="post_updated">Post updated</string>
<string name="page_updated">Page updated</string>
<string name="caption">Caption (optional)</string>
Expand Down Expand Up @@ -400,7 +409,7 @@
<string name="view_in_browser">View in browser</string>
<string name="preview">Preview</string>
<string name="update_verb">Update</string>
<string name="sending_content">Uploading %s content</string>
<string name="sending_content">Uploading %s content</string>
<string name="uploading_total">Uploading %1$d of %2$d</string>
<string name="uploading_post_media">Uploading media…</string>

Expand Down Expand Up @@ -954,7 +963,7 @@
<string name="editor_draft_saved_locally">Draft saved on device</string>
<string name="editor_scheduled_post_saved_online">Post scheduled</string>
<string name="editor_post_saved_locally_failed_media">The post has failed media uploads and has been saved locally</string>
<string name="editor_uploading_post">Your post is being sent online</string>
<string name="editor_uploading_post">Your post is uploading</string>
<string name="visual_editor_enabled">Visual Editor enabled</string>
<string name="visual_editor_disabled">Visual Editor disabled</string>
<string name="aztec_editor_enabled" translatable="false">Aztec Editor enabled</string>
Expand Down Expand Up @@ -1142,7 +1151,8 @@
<string name="error_edit_comment">An error occurred while editing the comment</string>
<string name="error_publish_empty_post">Can\'t publish an empty post</string>
<string name="error_publish_no_network">Device is offline. Changes saved locally.</string>
<string name="error_upload_params">Error while uploading the %1$s: %2$s</string>
<string name="error_upload_post_params">There was an error uploading this %1$s: %2$s.</string>
<string name="error_upload_post_media_params">There was an error uploading the media in this %1$s: %2$s.</string>
<string name="error_media_insufficient_fs_permissions">Read permission denied on device media</string>
<string name="error_media_not_found">Media could not be found</string>
<string name="error_media_unauthorized">You don\'t have permission to view or edit media</string>
Expand All @@ -1152,7 +1162,7 @@
<string name="error_media_load">Unable to load media</string>
<string name="error_media_save">Unable to save media</string>
<string name="error_media_canceled">Uploading media were canceled</string>
<string name="error_media_recover">Media upload failed. Edit the post to retry.</string>
<string name="error_media_recover">We were unable to upload this post\'s media. Please edit the post to try again.</string>
<string name="error_blog_hidden">This blog is hidden and couldn\'t be loaded. Enable it again in settings and try again.</string>
<string name="fatal_db_error">An error occurred while creating the app database. Try reinstalling the app.</string>
<string name="error_copy_to_clipboard">An error occurred while copying text to clipboard</string>
Expand All @@ -1173,7 +1183,7 @@
<string name="error_fetch_site_after_creation">Site has been created, you might need to refresh your sites in the site picker.</string>

<!-- Post Error -->
<string name="error_unknown_post">Unknown post, local copy of this post may be out of sync with the server</string>
<string name="error_unknown_post">Could not find the post on the server</string>
<string name="error_unknown_post_type">Unknown post format</string>

<!-- Image Descriptions for Accessibility -->
Expand Down

0 comments on commit 9a138f8

Please sign in to comment.