diff options
author | Nick Bradbury <nick.bradbury@gmail.com> | 2015-02-24 10:38:35 -0500 |
---|---|---|
committer | Nick Bradbury <nick.bradbury@gmail.com> | 2015-02-24 10:38:35 -0500 |
commit | 4f368a435a1749faa5cd7695bd95d2c52b571bd5 (patch) | |
tree | bdcafd6b7d80c462fe732bd2eeff14a98580070e /WordPress/src/main/java/org/wordpress | |
parent | 0e806aa5184f37025f1164980a8682099d92aeb0 (diff) | |
parent | 6e14f88188d08eedb3bb359138760f4e1493b485 (diff) | |
download | gradle-perf-android-medium-4f368a435a1749faa5cd7695bd95d2c52b571bd5.tar.gz |
Merge branch 'develop' of https://github.com/wordpress-mobile/WordPress-Android into feature/reader-services
Conflicts:
WordPress/src/main/java/org/wordpress/android/ui/reader/actions/ReaderCommentActions.java
WordPress/src/main/java/org/wordpress/android/ui/reader/actions/ReaderPostActions.java
Diffstat (limited to 'WordPress/src/main/java/org/wordpress')
8 files changed, 115 insertions, 63 deletions
diff --git a/WordPress/src/main/java/org/wordpress/android/models/ReaderPost.java b/WordPress/src/main/java/org/wordpress/android/models/ReaderPost.java index 2673b1f05..9dcc95788 100644 --- a/WordPress/src/main/java/org/wordpress/android/models/ReaderPost.java +++ b/WordPress/src/main/java/org/wordpress/android/models/ReaderPost.java @@ -85,18 +85,25 @@ public class ReaderPost { post.shortUrl = JSONUtil.getString(json, "short_URL"); post.setBlogUrl(JSONUtil.getString(json, "site_URL")); - post.numReplies = json.optInt("comment_count"); post.numLikes = json.optInt("like_count"); post.isLikedByCurrentUser = JSONUtil.getBool(json, "i_like"); post.isFollowedByCurrentUser = JSONUtil.getBool(json, "is_following"); post.isRebloggedByCurrentUser = JSONUtil.getBool(json, "is_reblogged"); - post.isCommentsOpen = JSONUtil.getBool(json, "comments_open"); post.isExternal = JSONUtil.getBool(json, "is_external"); post.isPrivate = JSONUtil.getBool(json, "site_is_private"); post.isLikesEnabled = JSONUtil.getBool(json, "likes_enabled"); post.isSharingEnabled = JSONUtil.getBool(json, "sharing_enabled"); + JSONObject jsonDiscussion = json.optJSONObject("discussion"); + if (jsonDiscussion != null) { + post.isCommentsOpen = JSONUtil.getBool(jsonDiscussion, "comments_open"); + post.numReplies = jsonDiscussion.optInt("comment_count"); + } else { + post.isCommentsOpen = JSONUtil.getBool(json, "comments_open"); + post.numReplies = json.optInt("comment_count"); + } + // parse the author section assignAuthorFromJson(post, json.optJSONObject("author")); diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/PostUploadService.java b/WordPress/src/main/java/org/wordpress/android/ui/posts/PostUploadService.java index 73e94c5b8..536c26bed 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/PostUploadService.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/PostUploadService.java @@ -17,6 +17,7 @@ import android.preference.PreferenceManager; import android.provider.MediaStore.Images; import android.provider.MediaStore.Video; import android.support.v4.app.NotificationCompat; +import android.support.v4.app.NotificationCompat.Builder; import android.support.v4.content.IntentCompat; import android.text.TextUtils; import android.webkit.MimeTypeMap; @@ -52,6 +53,7 @@ import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; import java.util.Date; import java.util.HashMap; import java.util.List; @@ -88,15 +90,27 @@ public class PostUploadService extends Service { } @Override - public void onStart(Intent intent, int startId) { + public void onDestroy() { + super.onDestroy(); + // Cancel current task, it will reset post from "uploading" to "local draft" + if (mCurrentTask != null) { + AppLog.d(T.POSTS, "cancelling current upload task"); + mCurrentTask.cancel(true); + } + } + + @Override + public int onStartCommand(Intent intent, int flags, int startId) { synchronized (mPostsList) { if (mPostsList.size() == 0 || mContext == null) { - this.stopSelf(); - return; + stopSelf(); + return START_NOT_STICKY; } } uploadNextPost(); + // We want this service to continue running until it is explicitly stopped, so return sticky. + return START_STICKY; } private FeatureSet synchronousGetFeatureSet() { @@ -120,7 +134,7 @@ public class PostUploadService extends Service { mCurrentTask = new UploadPostTask(); mCurrentTask.execute(mCurrentUploadingPost); } else { - this.stopSelf(); + stopSelf(); } } } @@ -134,11 +148,6 @@ public class PostUploadService extends Service { uploadNextPost(); } - public static boolean isUploading(Post post) { - return mCurrentUploadingPost != null && mCurrentUploadingPost.equals(post) || - mPostsList.size() > 0 && mPostsList.contains(post); - } - private class UploadPostTask extends AsyncTask<Post, Boolean, Boolean> { private Post mPost; private Blog mBlog; @@ -165,13 +174,22 @@ public class PostUploadService extends Service { WordPress.wpDB.deleteMediaFilesForPost(mPost); } else { WordPress.postUploadFailed(mPost.getLocalTableBlogId()); - mPostUploadNotifier.updateNotificationWithError(mErrorMessage, mIsMediaError, mPost.isPage(), mErrorUnavailableVideoPress); + mPostUploadNotifier.updateNotificationWithError(mErrorMessage, mIsMediaError, mPost.isPage(), + mErrorUnavailableVideoPress); } postUploaded(); } @Override + protected void onCancelled(Boolean aBoolean) { + super.onCancelled(aBoolean); + mPostUploadNotifier.updateNotificationWithError(mErrorMessage, mIsMediaError, mPost.isPage(), + mErrorUnavailableVideoPress); + WordPress.postUploadFailed(mPost.getLocalTableBlogId()); + } + + @Override protected Boolean doInBackground(Post... posts) { mErrorUnavailableVideoPress = false; mPost = posts[0]; @@ -478,6 +496,8 @@ public class PostUploadService extends Service { } private String uploadImage(MediaFile mediaFile) { + AppLog.d(T.POSTS, "uploadImage: " + mediaFile.getFilePath()); + if (mediaFile.getFilePath() == null) { return null; } @@ -594,7 +614,8 @@ public class PostUploadService extends Service { } String fullSizeUrl = null; - // Upload the full size picture if "Original Size" is selected in settings, or if 'link to full size' is checked. + // Upload the full size picture if "Original Size" is selected in settings, + // or if 'link to full size' is checked. if (!shouldUploadResizedVersion || mBlog.isFullSizeImage()) { Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("name", fileName); @@ -632,7 +653,8 @@ public class PostUploadService extends Service { String mimeType = "", xRes = "", yRes = ""; if (videoUri.toString().contains("content:")) { - String[] projection = new String[]{Video.Media._ID, Video.Media.DATA, Video.Media.MIME_TYPE, Video.Media.RESOLUTION}; + String[] projection = new String[]{Video.Media._ID, Video.Media.DATA, Video.Media.MIME_TYPE, + Video.Media.RESOLUTION}; Cursor cur = mContext.getContentResolver().query(videoUri, projection, null, null, null); if (cur != null && cur.moveToFirst()) { @@ -729,15 +751,14 @@ public class PostUploadService extends Service { private void setUploadPostErrorMessage(Exception e) { - mErrorMessage = String.format(mContext.getResources().getText(R.string.error_upload).toString(), mPost.isPage() ? mContext - .getResources().getText(R.string.page).toString() : mContext.getResources().getText(R.string.post).toString()) - + " " + e.getMessage(); + mErrorMessage = String.format(mContext.getResources().getText(R.string.error_upload).toString(), + mPost.isPage() ? mContext.getResources().getText(R.string.page).toString() : + mContext.getResources().getText(R.string.post).toString()) + " " + e.getMessage(); mIsMediaError = false; AppLog.e(T.EDITOR, mErrorMessage, e); } private String uploadImageFile(Map<String, Object> pictureParams, MediaFile mf, Blog blog) { - // create temporary upload file File tempFile; try { @@ -775,14 +796,17 @@ public class PostUploadService extends Service { } private Object uploadFileHelper(Object[] params, final File tempFile) { + AppLog.d(T.POSTS, "uploadFileHelper: " + Arrays.toString(params)); + // Create listener for tracking upload progress in the notification if (mClient instanceof XMLRPCClient) { XMLRPCClient xmlrpcClient = (XMLRPCClient) mClient; xmlrpcClient.setOnBytesUploadedListener(new XMLRPCClient.OnBytesUploadedListener() { @Override public void onBytesUploaded(long uploadedBytes) { - if (tempFile.length() == 0) return; - + if (tempFile.length() == 0) { + return; + } float percentage = (uploadedBytes * 100) / tempFile.length(); mPostUploadNotifier.updateNotificationProgress(percentage); } @@ -805,8 +829,9 @@ public class PostUploadService extends Service { return null; } finally { // remove the temporary upload file now that we're done with it - if (tempFile != null && tempFile.exists()) + if (tempFile != null && tempFile.exists()) { tempFile.delete(); + } } } } @@ -821,31 +846,34 @@ public class PostUploadService extends Service { private final NotificationCompat.Builder mNotificationBuilder; private final int mNotificationId; + private int mNotificationErrorId = 0; private int mTotalMediaItems; private int mCurrentMediaItem; private float mItemProgressSize; public PostUploadNotifier(Post post) { // add the uploader to the notification bar - mNotificationManager = (NotificationManager) SystemServiceFactory.get(mContext, Context.NOTIFICATION_SERVICE); + mNotificationManager = (NotificationManager) SystemServiceFactory.get(mContext, + Context.NOTIFICATION_SERVICE); - mNotificationBuilder = - new NotificationCompat.Builder(getApplicationContext()) - .setSmallIcon(android.R.drawable.stat_sys_upload); + mNotificationBuilder = new NotificationCompat.Builder(getApplicationContext()); + mNotificationBuilder.setSmallIcon(android.R.drawable.stat_sys_upload); Intent notificationIntent = new Intent(mContext, post.isPage() ? PagesActivity.class : PostsActivity.class); - notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP - | Intent.FLAG_ACTIVITY_NEW_TASK + notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK | IntentCompat.FLAG_ACTIVITY_CLEAR_TASK); notificationIntent.setAction(Intent.ACTION_MAIN); notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER); - notificationIntent.setData((Uri.parse("custom://wordpressNotificationIntent" + post.getLocalTableBlogId()))); + notificationIntent.setData((Uri.parse("custom://wordpressNotificationIntent" + + post.getLocalTableBlogId()))); notificationIntent.putExtra(PostsActivity.EXTRA_VIEW_PAGES, post.isPage()); - PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); + PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, notificationIntent, + PendingIntent.FLAG_UPDATE_CURRENT); mNotificationBuilder.setContentIntent(pendingIntent); mNotificationId = (new Random()).nextInt() + post.getLocalTableBlogId(); + startForeground(mNotificationId, mNotificationBuilder.build()); } @@ -873,9 +901,13 @@ public class PostUploadService extends Service { mNotificationManager.cancel(mNotificationId); } - public void updateNotificationWithError(String mErrorMessage, boolean isMediaError, boolean isPage, boolean isVideoPressError) { - String postOrPage = (String) (isPage ? mContext.getResources().getText(R.string.page_id) : mContext.getResources() - .getText(R.string.post_id)); + public void updateNotificationWithError(String mErrorMessage, boolean isMediaError, boolean isPage, + boolean isVideoPressError) { + AppLog.d(T.POSTS, "updateNotificationWithError: " + mErrorMessage); + + Builder notificationBuilder = new NotificationCompat.Builder(getApplicationContext()); + String postOrPage = (String) (isPage ? mContext.getResources().getText(R.string.page_id) + : mContext.getResources().getText(R.string.post_id)); Intent notificationIntent = new Intent(mContext, isPage ? PagesActivity.class : PostsActivity.class); notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK @@ -894,20 +926,27 @@ public class PostUploadService extends Service { 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); + errorText = mContext.getResources().getText(R.string.media) + " " + + mContext.getResources().getText(R.string.error); } - mNotificationBuilder.setSmallIcon(android.R.drawable.stat_notify_error); - mNotificationBuilder.setContentTitle((isMediaError) ? errorText : mContext.getResources().getText(R.string.upload_failed)); - mNotificationBuilder.setContentText((isMediaError) ? mErrorMessage : postOrPage + " " + errorText + ": " + mErrorMessage); - mNotificationBuilder.setContentIntent(pendingIntent); - mNotificationBuilder.setAutoCancel(true); - - mNotificationManager.notify(mNotificationId, mNotificationBuilder.build()); + notificationBuilder.setSmallIcon(android.R.drawable.stat_notify_error); + notificationBuilder.setContentTitle((isMediaError) ? errorText : + mContext.getResources().getText(R.string.upload_failed)); + notificationBuilder.setContentText((isMediaError) ? mErrorMessage : postOrPage + " " + errorText + + ": " + mErrorMessage); + notificationBuilder.setContentIntent(pendingIntent); + notificationBuilder.setAutoCancel(true); + if (mNotificationErrorId == 0) { + mNotificationErrorId = mNotificationId + (new Random()).nextInt(); + } + mNotificationManager.notify(mNotificationErrorId, notificationBuilder.build()); } public void updateNotificationProgress(float progress) { - if (mTotalMediaItems == 0) return; + if (mTotalMediaItems == 0) { + return; + } // Simple way to show progress of entire post upload // Would be better if we could get total bytes for all media items. @@ -933,7 +972,8 @@ public class PostUploadService extends Service { public void setCurrentMediaItem(int currentItem) { mCurrentMediaItem = currentItem; - mNotificationBuilder.setContentText(String.format(getString(R.string.uploading_total), mCurrentMediaItem, mTotalMediaItems)); + mNotificationBuilder.setContentText(String.format(getString(R.string.uploading_total), mCurrentMediaItem, + mTotalMediaItems)); } } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/actions/ReaderBlogActions.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/actions/ReaderBlogActions.java index 28e32eeb1..38837acbe 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/actions/ReaderBlogActions.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/actions/ReaderBlogActions.java @@ -54,7 +54,7 @@ public class ReaderBlogActions { } final String actionName = (isAskingToFollow ? "follow" : "unfollow"); - final String path = "/sites/" + blogId + "/follows/" + (isAskingToFollow ? "new" : "mine/delete"); + final String path = "sites/" + blogId + "/follows/" + (isAskingToFollow ? "new" : "mine/delete"); com.wordpress.rest.RestRequest.Listener listener = new RestRequest.Listener() { @Override @@ -82,7 +82,7 @@ public class ReaderBlogActions { } } }; - WordPress.getRestClientUtils().post(path, listener, errorListener); + WordPress.getRestClientUtilsV1_1().post(path, listener, errorListener); return true; } @@ -170,7 +170,7 @@ public class ReaderBlogActions { } final String actionName = (isAskingToFollow ? "follow" : "unfollow"); - final String path = "/read/following/mine/" + final String path = "read/following/mine/" + (isAskingToFollow ? "new" : "delete") + "?url=" + UrlUtils.urlEncode(feedUrl); @@ -200,7 +200,7 @@ public class ReaderBlogActions { } } }; - WordPress.getRestClientUtils().post(path, listener, errorListener); + WordPress.getRestClientUtilsV1_1().post(path, listener, errorListener); return true; } @@ -307,9 +307,9 @@ public class ReaderBlogActions { }; if (hasBlogId) { - WordPress.getRestClientUtilsV1_1().get("/sites/" + blogId, listener, errorListener); + WordPress.getRestClientUtilsV1_1().get("sites/" + blogId, listener, errorListener); } else { - WordPress.getRestClientUtilsV1_1().get("/sites/" + UrlUtils.urlEncode(UrlUtils.getDomainFromUrl(blogUrl)), listener, errorListener); + WordPress.getRestClientUtilsV1_1().get("sites/" + UrlUtils.urlEncode(UrlUtils.getDomainFromUrl(blogUrl)), listener, errorListener); } } public static void updateFeedInfo(long feedId, String feedUrl, final UpdateBlogInfoListener infoListener) { @@ -330,9 +330,9 @@ public class ReaderBlogActions { }; String path; if (feedId != 0) { - path = "/read/feed/" + feedId; + path = "read/feed/" + feedId; } else { - path = "/read/feed/" + UrlUtils.urlEncode(feedUrl); + path = "read/feed/" + UrlUtils.urlEncode(feedUrl); } WordPress.getRestClientUtilsV1_1().get(path, listener, errorListener); } @@ -431,8 +431,8 @@ public class ReaderBlogActions { }; AppLog.i(T.READER, "blocking blog " + blogId); - String path = "/me/block/sites/" + Long.toString(blogId) + "/new"; - WordPress.getRestClientUtils().post(path, listener, errorListener); + String path = "me/block/sites/" + Long.toString(blogId) + "/new"; + WordPress.getRestClientUtilsV1_1().post(path, listener, errorListener); return blockResult; } @@ -466,7 +466,7 @@ public class ReaderBlogActions { }; AppLog.i(T.READER, "unblocking blog " + blockResult.blogId); - String path = "/me/block/sites/" + Long.toString(blockResult.blogId) + "/delete"; - WordPress.getRestClientUtils().post(path, listener, errorListener); + String path = "me/block/sites/" + Long.toString(blockResult.blogId) + "/delete"; + WordPress.getRestClientUtilsV1_1().post(path, listener, errorListener); } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/actions/ReaderTagActions.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/actions/ReaderTagActions.java index 5a204cd74..22f9c8aad 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/actions/ReaderTagActions.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/actions/ReaderTagActions.java @@ -112,7 +112,7 @@ public class ReaderTagActions { } } }; - WordPress.getRestClientUtils().post(path, listener, errorListener); + WordPress.getRestClientUtilsV1_1().post(path, listener, errorListener); return true; } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/actions/ReaderUserActions.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/actions/ReaderUserActions.java index e22fbb807..93cf20fcf 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/actions/ReaderUserActions.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/actions/ReaderUserActions.java @@ -36,7 +36,7 @@ public class ReaderUserActions { } }; - WordPress.getRestClientUtils().get("me", listener, errorListener); + WordPress.getRestClientUtilsV1_1().get("me", listener, errorListener); } /* diff --git a/WordPress/src/main/java/org/wordpress/android/ui/reader/services/ReaderUpdateService.java b/WordPress/src/main/java/org/wordpress/android/ui/reader/services/ReaderUpdateService.java index b6c0f62e2..c7ca3548e 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/reader/services/ReaderUpdateService.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/reader/services/ReaderUpdateService.java @@ -130,7 +130,7 @@ public class ReaderUpdateService extends Service { } }; AppLog.d(AppLog.T.READER, "reader service > updating tags"); - WordPress.getRestClientUtils().get("read/menu", null, null, listener, errorListener); + WordPress.getRestClientUtilsV1_1().get("read/menu", null, null, listener, errorListener); } private void handleUpdateTagsResponse(final JSONObject jsonObject) { @@ -240,7 +240,7 @@ public class ReaderUpdateService extends Service { AppLog.d(AppLog.T.READER, "reader service > updating followed blogs"); // request using ?meta=site,feed to get extra info - WordPress.getRestClientUtils().get("/read/following/mine?meta=site%2Cfeed", listener, errorListener); + WordPress.getRestClientUtilsV1_1().get("read/following/mine?meta=site%2Cfeed", listener, errorListener); } private void handleFollowedBlogsResponse(final JSONObject jsonObject) { new Thread() { @@ -279,10 +279,10 @@ public class ReaderUpdateService extends Service { }; AppLog.d(AppLog.T.READER, "reader service > updating recommended blogs"); - String path = "/read/recommendations/mine/" - + "?source=mobile" - + "&number=" + Integer.toString(ReaderConstants.READER_MAX_RECOMMENDED_TO_REQUEST); - WordPress.getRestClientUtils().get(path, listener, errorListener); + String path = "read/recommendations/mine/" + + "?source=mobile" + + "&number=" + Integer.toString(ReaderConstants.READER_MAX_RECOMMENDED_TO_REQUEST); + WordPress.getRestClientUtilsV1_1().get(path, listener, errorListener); } private void handleRecommendedBlogsResponse(final JSONObject jsonObject) { new Thread() { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/StatsReferrersFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/stats/StatsReferrersFragment.java index 62cf4271b..a3761cc8d 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/StatsReferrersFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/StatsReferrersFragment.java @@ -205,7 +205,6 @@ public class StatsReferrersFragment extends StatsAbstractListFragment { WPNetworkImageView.ImageType.BLAVATAR); holder.networkImageView.setVisibility(View.VISIBLE); - holder.chevronImageView.setVisibility(View.VISIBLE); if (children == 0) { holder.showLinkIcon(); } else { diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stats/StatsUIHelper.java b/WordPress/src/main/java/org/wordpress/android/ui/stats/StatsUIHelper.java index d358a75a0..367c8a5fc 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stats/StatsUIHelper.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/stats/StatsUIHelper.java @@ -157,10 +157,16 @@ public class StatsUIHelper { mLinearLayout.addView(groupView); } + // groupView is recycled, we need to reset it to the original state. + ViewGroup childContainer = (ViewGroup) groupView.findViewById(R.id.layout_child_container); + if (childContainer != null) { + childContainer.setVisibility(View.GONE); + } // Remove any other prev animations set on the chevron final ImageView chevron = (ImageView) groupView.findViewById(R.id.stats_list_cell_chevron); if (chevron != null) { chevron.clearAnimation(); + chevron.setImageResource(R.drawable.stats_chevron_right); } // add children if this group is expanded |