Skip to content

Feature/reader full post refresh related posts#4626

Merged
hypest merged 46 commits intofeature/reader-full-post-refresh-masterfrom
feature/reader-full-post-refresh-related-posts
Oct 13, 2016
Merged

Feature/reader full post refresh related posts#4626
hypest merged 46 commits intofeature/reader-full-post-refresh-masterfrom
feature/reader-full-post-refresh-related-posts

Conversation

@nbradbury
Copy link
Copy Markdown
Contributor

@nbradbury nbradbury commented Oct 9, 2016

This is the third in a slew of PRs which tackles the full post refresh (#4581). This PR deals with upgrading the related posts shown below every wp.com post in the reader post detail.

Previously we showed a single "related reading" section, now we show two related posts from the same site as the current post ("local" related posts), followed by two related posts from across wp.com ("global" related posts).

The before & after pics below illustrate the changes.
before-and-after-sm

Copy link
Copy Markdown
Contributor

@hypest hypest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noticed that the images on the related posts are vertically stressed. I could attach a screenshot if you want but, the issue is visible on the shot on the PR description as well.

Copy link
Copy Markdown
Contributor

@hypest hypest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On my network connection, Related posts take a few seconds to load and there is nothing to indicate that there's a background attempt in loading them.

May I suggest making the headers ("MORE IN ..." and "MORE ON WORDPRESS.COM" always visible and add some form of indicator that filling in those sections is still undergoing (e.g. a progress indicator)? Thanks!

@nbradbury
Copy link
Copy Markdown
Contributor Author

Noticed that the images on the related posts are vertically stressed. I could attach a screenshot if you want but, the issue is visible on the shot on the PR description as well.

Bah, you're right and I meant to mention that. If it's okay with you, I'd like to open a separate issue for this. The fix is likely a bit convoluted and this PR is already fairly large.

@nbradbury
Copy link
Copy Markdown
Contributor Author

May I suggest making the headers ("MORE IN ..." and "MORE ON WORDPRESS.COM" always visible and add some form of indicator that filling in those sections is still undergoing (e.g. a progress indicator)?

I don't think we want the headers visible since there are cases when one (or, rarely, both) won't have related posts. So we only want to show them when we know they have related posts, which doesn't happen until after the call completes.

I'm ambivalent about the progress indicator. I don't think it's really needed but it's simple enough to add. Just let me know if you feel that would necessary.

@hypest
Copy link
Copy Markdown
Contributor

hypest commented Oct 12, 2016

If it's okay with you, I'd like to open a separate issue for this. The fix is likely a bit convoluted and this PR is already fairly large.

@nbradbury sure, WFM!

@hypest
Copy link
Copy Markdown
Contributor

hypest commented Oct 12, 2016

I don't think we want the headers visible since there are cases when one (or, rarely, both) won't have related posts. So we only want to show them when we know they have related posts, which doesn't happen until after the call completes.

I'm ambivalent about the progress indicator. I don't think it's really needed but it's simple enough to add. Just let me know if you feel that would necessary.

I see. I can see that needing a bit of effort that could be delivered with a subsequent PR so, I'd say let's just make this a ticket instead. Besides, the same happens with the "Liked by" section (invisible until response arrives) so, perhaps we can include that section as well in the same ticket.

Copy link
Copy Markdown
Contributor

@hypest hypest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @nbradbury , I've left some more comments, most of which are non-blocking. I'd like to hear your opinion on them though before moving on. Thanks!

ReaderRelatedPost post = new ReaderRelatedPost();

post.mPostId = json.optLong("ID");
post.mSiteId = json.optLong("site_ID");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, are ID and site_ID really optional on the server side?

If not, I would prefer us to use getLong and handle the errors instead.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've favored using the various optXxx methods throughout the reader, but I'm certainly open to alternatives. How would you suggest I handle the errors?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, I'd say to drop the specific related post json and return null. Caller will need to check for the null accordingly. WDYT?

}

ReaderRelatedPostList posts = new ReaderRelatedPostList();
JSONArray jsonPosts = json.optJSONArray("posts");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This made me pause a bit, wondering why would we need to dive deeper into the json object to get the data we need for this function.

May I suggest removing the need for this knowledge (of where the list is contained into the json structure) and pass the JSONArray directly as the function parameter? The caller (handleRelatedPostsResponse, which is a network response handler in this case) can validate the json and offer the list directly. Let me know what you think!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Changed in e57687f.


private void initView(Context context) {
inflate(context, R.layout.reader_related_posts_view, this);
mFeaturedImageWidth = DisplayUtils.dpToPx(getContext(), getResources().getDimensionPixelSize(R.dimen.reader_related_post_image_width));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we reconcile the 2 Contexts used in these lines? I mean, there is one passed as a parameter and one got via getContext() so, can we instead use only one or the other? Thanks!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops! Good catch - fixed in 8521709.

mClickListener = listener;
}

public void showRelatedPosts(ReaderRelatedPostList posts, String siteName, boolean isGlobal) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function seems to expect posts being not null so, we might as well denote it with an annotation like in other places in the PR, what do you think?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in eb101af.


public void showRelatedPosts(ReaderRelatedPostList posts, String siteName, boolean isGlobal) {
mRelatedPostList = posts;
if (mRelatedPostList.size() == 0) return;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting exit from the function.

I'm wondering, for completeness sake's would it be better to clean up any elements that might already be in the View's layout? Like, if showRelatedPosts() is called again basically but with an empty list. What do you think?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes total sense - added in 185662b.


<LinearLayout
<RelativeLayout
android:id="@+id/layout_related_post_site_header"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is more like a comment just to put it out there: It seems that the header click acts as a click on the related post itself and opens the post. It felt counter-intuitive the first couple of times I tried it. I was expecting it to go to the site (in Reader) instead. Apart from the smaller size overall, the header looks like the relevant headers elsewhere, and there the click opens the site.

This is not a blocking comment though.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wrestled with this one. I agree it would be more consistent to show the site when the header is clicked, but at the same time it's very easy to tap the header when you intended to tap the post (something that actually happens to me already in the list view, but that's another story!). So in the end I decided not to make the header tappable.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. I think this is a good comment (augmented by your hands-on feedback as well) that we prolly should raise it at the design review phase as well. This is, again, a case where the design for the web (where a mouse will be used to accurately click on the various sections) is not suitable for the mobile where (big) fingers demand ample spacing.

@hypest
Copy link
Copy Markdown
Contributor

hypest commented Oct 12, 2016

Another small note, not a blocking one as well: the Follow button doesn't provide any hints of its function. It is familiar from the rest of the app but still. On Calypso web, the button has a tooltip appearing on mouse-over which of course is not directly translatable to the mobile.

@nbradbury
Copy link
Copy Markdown
Contributor Author

nbradbury commented Oct 12, 2016

Another small note, not a blocking one as well: the Follow button doesn't provide any hints of its function. It is familiar from the rest of the app but still. On Calypso web, the button has a tooltip appearing on mouse-over which of course is not directly translatable to the mobile.

Yes, that bothered me as well. I originally had the follow/following text on that button, but again it complicated the tap target. It was easy to tap the follow text when you meant to tap the post, especially on smaller screens, so I dropped the follow text (which matches the mobile web design, too).

I think the purpose of that button is obvious enough, though, since as you mention it's shown in so many other places.

@nbradbury
Copy link
Copy Markdown
Contributor Author

Thanks for reviewing this one @hypest - ready for round two!

Copy link
Copy Markdown
Contributor

@hypest hypest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @nbradbury , thanks for the extra commits! I've left some new comments that probably require changes so, have a look. Thanks!


private void initView(Context context) {
inflate(context, R.layout.reader_related_posts_view, this);
mFeaturedImageWidth = DisplayUtils.dpToPx(context, getResources().getDimensionPixelSize(R.dimen.reader_related_post_image_width));
Copy link
Copy Markdown
Contributor

@hypest hypest Oct 13, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I the same vein as the previous comment in this function, perhaps we better use the provided context to retrieve the Resources. So, something like context.getResources(). WDYT?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 10be46e

ReaderRelatedPost post = new ReaderRelatedPost();

post.mPostId = json.optLong("ID");
post.mSiteId = json.optLong("site_ID");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, I'd say to drop the specific related post json and return null. Caller will need to check for the null accordingly. WDYT?

public static ReaderRelatedPostList fromJsonPosts(@NonNull JSONArray jsonPosts) {
ReaderRelatedPostList posts = new ReaderRelatedPostList();
for (int i = 0; i < jsonPosts.length(); i++) {
posts.add(ReaderRelatedPost.fromJson(jsonPosts.optJSONObject(i)));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't notice that on my first pass but, it seems ReaderRelatedPost.fromJson() is not expecting null as a parameter but jsonPosts.optJSONObject can return one. We prolly need to null check the parameter first, or change the function to accept null, right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's possible for optJSONObject() to return null here, since we're looping through the array of objects. But for future use null-checking makes sense - added in 69c0909.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAICT, optJSONObject() can return null if the array item is not a JSONObject and JSONArray can indeed hold a mix of any kind of json types. The null check you added will do the job so, 👍

@hypest
Copy link
Copy Markdown
Contributor

hypest commented Oct 13, 2016

Yes, that bothered me as well. I originally had the follow/following text on that button, but again it complicated the tap target. It was easy to tap the follow text when you meant to tap the post, especially on smaller screens, so I dropped the follow text (which matches the mobile web design, too).

I think the purpose of that button is obvious enough, though, since as you mention it's shown in so many other places.

Hopefully we can bring this up at the design review phase as well. Thanks!

@nbradbury
Copy link
Copy Markdown
Contributor Author

In this case, I'd say to drop the specific related post json and return null. Caller will need to check for the null accordingly.

Addressed in 419aa41. Ready for round 3!

@hypest
Copy link
Copy Markdown
Contributor

hypest commented Oct 13, 2016

LGTM @nbradbury , thanks for the changes! I'll merge this as soon as Travis has its pass. Thanks!

@hypest hypest merged commit 01b30aa into feature/reader-full-post-refresh-master Oct 13, 2016
@hypest hypest deleted the feature/reader-full-post-refresh-related-posts branch October 13, 2016 12:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants