Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
516caf3
Don't show like counts
mikejohnstn Nov 16, 2013
753b8a6
Small code style changes
mikejohnstn Nov 16, 2013
98b2b59
Consts for control bar magic numbers
mikejohnstn Nov 16, 2013
19fdfe3
Add comment button, reorder control buttons, remove borders
mikejohnstn Nov 16, 2013
3ef7e5b
Fix reblog form not showing up
mikejohnstn Nov 17, 2013
12a9b79
Code formatting cleanup
mikejohnstn Nov 17, 2013
1612a96
Move author view to the top of the cell
mikejohnstn Nov 17, 2013
60ff10f
New title font and padding
mikejohnstn Nov 17, 2013
4ec8ab0
Render a horizontal line and update padding
mikejohnstn Nov 17, 2013
5dbbe42
Make images display full-width
mikejohnstn Nov 17, 2013
856f2ba
Prettier height handling
mikejohnstn Nov 17, 2013
08fc38e
Add follow button, move time label
mikejohnstn Nov 17, 2013
2f18ffc
Change color of follow icons
mikejohnstn Nov 17, 2013
f1e96d3
Improve alignment of time and buttons
mikejohnstn Nov 17, 2013
74734ad
New colors for Reader buttons
mikejohnstn Nov 17, 2013
25775a5
Add tag button (sample text for now)
mikejohnstn Nov 17, 2013
cc7ae0c
Move short date formatting to a category, and use it in main Reader list
mikejohnstn Nov 17, 2013
bfc46bd
Adjust image height ratio and make it a const
mikejohnstn Nov 17, 2013
3ba885a
Refactor cells to decouple actions for better MVC separation
mikejohnstn Nov 17, 2013
0641c6e
Better variable names
mikejohnstn Nov 17, 2013
f403cff
Hook up follow button
mikejohnstn Nov 17, 2013
38124e0
Add clock icon to timestamp
mikejohnstn Nov 17, 2013
e92f761
Add title border when there's no image
mikejohnstn Nov 17, 2013
2b98cdd
Support UILabel attributedText size suggestion
mikejohnstn Nov 17, 2013
09c564e
Custom line heights for title and summary
mikejohnstn Nov 17, 2013
9d85d42
Store primaryTag and tags in ReaderPost objects
mikejohnstn Nov 18, 2013
fbbd143
Tapping a tag lets you browse that tag's posts
mikejohnstn Nov 18, 2013
07d119d
Fallback logic for displaying blog/display/author name
mikejohnstn Nov 18, 2013
74fcaba
Made site/blog ID handling more robust to handle tag endpoint
mikejohnstn Nov 18, 2013
3b5d039
Aesthetic tweaks: line heights, padding
mikejohnstn Nov 18, 2013
282a33f
Clamp summary height and remove padding offset
mikejohnstn Nov 18, 2013
d838f58
Keep comment button hidden unless wpcom
mikejohnstn Nov 18, 2013
8c7e830
Fix a small padding problem
mikejohnstn Nov 18, 2013
233c601
Handle an empty topics list
mikejohnstn Nov 19, 2013
60ee080
Remove unused code
mikejohnstn Nov 19, 2013
812b3d3
Fix top table margin on first load
mikejohnstn Nov 19, 2013
96c521f
Cleaned up defines and consts
mikejohnstn Nov 19, 2013
ab258b7
Fix black bar beneath reblog form
mikejohnstn Nov 19, 2013
5d16a83
Merge branch 'develop' into feature/485-new-reader
mikejohnstn Nov 19, 2013
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions WordPress/Classes/NSDate+StringFormatting.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// NSDate+StringFormatting.h
// WordPress
//
// Created by Michael Johnston on 11/17/13.
// Copyright (c) 2013 WordPress. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface NSDate (StringFormatting)

- (NSString *)shortString;

@end
30 changes: 30 additions & 0 deletions WordPress/Classes/NSDate+StringFormatting.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// NSDate+StringFormatting.m
// WordPress
//
// Created by Michael Johnston on 11/17/13.
// Copyright (c) 2013 WordPress. All rights reserved.
//

#import "NSDate+StringFormatting.h"

@implementation NSDate (StringFormatting)

- (NSString *)shortString {
NSString *shortString;
NSTimeInterval diff = [[NSDate date] timeIntervalSince1970] - [self timeIntervalSince1970];

if(diff < 60) {
shortString = [NSString stringWithFormat:@"%is", (int)diff];
} else if(diff < 3600) {
shortString = [NSString stringWithFormat:@"%im", (int)floor(diff / 60)];
} else if (diff < 86400) {
shortString = [NSString stringWithFormat:@"%ih", (int)floor(diff / 3600)];
} else {
shortString = [NSString stringWithFormat:@"%id", (int)floor(diff / 86400)];
Copy link
Member

Choose a reason for hiding this comment

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

This needs translation support

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This code was already in the app. I just moved it to a category. I've added #583 to localize this and ensure it makes sense for all supported languages.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's a pretty good rule of thumb that if you see 86400 in code, it's not the best way to calculate duration in days. Where you'll run into problems is with people using other than a Gregorian calendar or when daylight saving and leap years/seconds come into play.

I'd suggest using NSDateComponents (this code is typed from memory and may not be compilable) -

NSCalendar *calendar = [NSCalendar currentCalendar];
NSUInteger unitFlags = NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;

NSDateComponents *components = [gregorian components:unitFlags fromDate:startDate toDate:endDate options:0];

// then

NSInteger days = [components day];
NSInteger hours = [components hour];
//etc

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't write this (just moved it), but yeah, to do it 100% right, someone will need to research if this rendering of dates even makes sense in all the languages we support. It's a bigger task that I think we should defer to #583 (this code already exists in the production app).

Copy link
Contributor

Choose a reason for hiding this comment

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

Whoops I didn't see #583 👍

}

return shortString;
}

@end
2 changes: 0 additions & 2 deletions WordPress/Classes/ReaderComment.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,4 @@
+ (void)createOrUpdateWithDictionary:(NSDictionary *)dict forPost:(ReaderPost *)post withContext:(NSManagedObjectContext *)context;


- (NSString *)shortDate;

@end
20 changes: 0 additions & 20 deletions WordPress/Classes/ReaderComment.m
Original file line number Diff line number Diff line change
Expand Up @@ -185,24 +185,4 @@ - (void)updateFromDictionary:(NSDictionary *)dict {

}


- (NSString *)shortDate {

NSString *str;
NSTimeInterval diff = [[NSDate date] timeIntervalSince1970] - [self.dateCreated timeIntervalSince1970];

if(diff < 60) {
str = [NSString stringWithFormat:@"%is", (int)diff];
} else if(diff < 3600) {
str = [NSString stringWithFormat:@"%im", (int)floor(diff / 60)];
} else if (diff < 86400) {
str = [NSString stringWithFormat:@"%ih", (int)floor(diff / 3600)];
} else {
str = [NSString stringWithFormat:@"%id", (int)floor(diff / 86400)];
}

return str;

}

@end
3 changes: 2 additions & 1 deletion WordPress/Classes/ReaderCommentTableViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#import "UIImageView+Gravatar.h"
#import "WordPressAppDelegate.h"
#import "WPWebViewController.h"
#import "NSDate+StringFormatting.h"

#define RCTVCVerticalPadding 5.0f
#define RCTVCIndentationWidth 10.0f
Expand Down Expand Up @@ -197,7 +198,7 @@ - (void)configureCell:(ReaderComment *)comment {

[self.contentView addSubview:self.cellImageView];

_dateLabel.text = [comment shortDate];
_dateLabel.text = [comment.dateCreated shortString];
_authorLabel.text = comment.author;
[self.cellImageView setImageWithURL:[NSURL URLWithString:comment.authorAvatarURL] placeholderImage:[UIImage imageNamed:@"blavatar-wpcom.png"]];

Expand Down
6 changes: 6 additions & 0 deletions WordPress/Classes/ReaderPost.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ extern NSString *const ReaderExtrasArrayKey;
@property (nonatomic, strong) NSString *summary;
@property (nonatomic, strong) NSMutableSet *comments;
@property (nonatomic, readonly, strong) NSURL *featuredImageURL;
@property (nonatomic, strong) NSString *primaryTagName;
@property (nonatomic, strong) NSString *primaryTagSlug;
@property (nonatomic, strong) NSString *tags;


/**
An array of dictionaries representing available REST API endpoints to retrieve posts for the Reader.
Expand Down Expand Up @@ -111,6 +115,7 @@ extern NSString *const ReaderExtrasArrayKey;

- (NSString *)prettyDateString;

- (BOOL)isFollowable;

- (BOOL)isFreshlyPressed;

Expand All @@ -129,6 +134,7 @@ extern NSString *const ReaderExtrasArrayKey;

- (NSDictionary *)getStoredComment;

- (NSString *)authorString;

- (NSString *)avatar;

Expand Down
48 changes: 47 additions & 1 deletion WordPress/Classes/ReaderPost.m
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ @implementation ReaderPost
@dynamic storedComment;
@dynamic summary;
@dynamic comments;
@dynamic primaryTagName;
@dynamic primaryTagSlug;
@dynamic tags;

+ (void)load {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleLogoutNotification:) name:WordPressComApiDidLogoutNotification object:nil];
Expand Down Expand Up @@ -209,6 +212,12 @@ + (void)createOrUpdateWithDictionary:(NSDictionary *)dict forEndpoint:(NSString
NSNumber *blogSiteID = [dict numberForKey:@"site_id"];
NSNumber *siteID = [dict numberForKey:@"blog_id"];
NSNumber *postID = [dict numberForKey:@"ID"];

// Some endpoints (e.g. tags) use different case
if (siteID == nil) {
siteID = [dict numberForKey:@"site_ID"];
blogSiteID = [dict numberForKey:@"site_ID"];
}

// following, likes and topics endpoints
if ([dict valueForKey:@"blog_site_id"] != nil) {
Expand Down Expand Up @@ -282,7 +291,6 @@ - (void)updateFromDictionary:(NSDictionary *)dict {
self.dateSynced = [NSDate date];
}


- (void)updateFromRESTDictionary:(NSDictionary *)dict {
// REST api. Freshly Pressed, sites/site/posts

Expand Down Expand Up @@ -351,6 +359,16 @@ - (void)updateFromRESTDictionary:(NSDictionary *)dict {
self.blogURL = [NSString stringWithFormat:@"%@://%@/", url.scheme, url.host];

self.summary = [self createSummary:self.content makePlainText:YES];

NSDictionary *tagsDict = [dict objectForKey:@"tags"];
NSArray *tagsList = [NSArray arrayWithArray:[tagsDict allKeys]];
self.tags = [tagsList componentsJoinedByString:@", "];

if ([tagsDict count] > 0) {
NSDictionary *tagDict = [[tagsDict allValues] objectAtIndex:0];
self.primaryTagSlug = tagDict[@"slug"];
self.primaryTagName = tagDict[@"name"];
}
}


Expand Down Expand Up @@ -423,6 +441,22 @@ - (void)updateFromReaderDictionary:(NSDictionary *)dict {
img = [img stringByDecodingXMLCharacters];
self.postAvatar = [self parseImageSrcFromHTML:img];
}

NSDictionary *tagsDict = [dict objectForKey:@"topics"];

if ([tagsDict count] > 0) {
NSArray *tagsList = [NSArray arrayWithArray:[tagsDict allValues]];
self.tags = [tagsList componentsJoinedByString:@", "];
}

NSDictionary *primaryTagDict = [dict objectForKey:@"primary_tag"];
if ([primaryTagDict isKindOfClass:[NSDictionary class]]) {
self.primaryTagName = primaryTagDict[@"name"];
self.primaryTagSlug = primaryTagDict[@"slug"];
} else if ([tagsDict count] > 0) {
self.primaryTagSlug = [[tagsDict allKeys] objectAtIndex:0];
self.primaryTagName = [tagsDict objectForKey:self.primaryTagSlug];
}
}


Expand Down Expand Up @@ -606,6 +640,9 @@ - (NSString *)prettyDateString {
return [formatter stringFromDate:date];
}

- (BOOL)isFollowable {
return self.siteID != nil;
}

- (BOOL)isFreshlyPressed {
return ([self.endpoint rangeOfString:@"freshly-pressed"].location != NSNotFound)? YES : NO;
Expand Down Expand Up @@ -643,6 +680,15 @@ - (NSDictionary *)getStoredComment {
return @{@"commentID":commentID, @"comment":commentText};
}

- (NSString *)authorString {
if ([self.blogName length] > 0) {
return self.blogName;
} else if ([self.authorDisplayName length] > 0) {
return self.authorDisplayName;
} else {
return self.author;
}
}

- (NSString *)avatar {
return (self.postAvatar == nil) ? self.authorAvatarURL : self.postAvatar;
Expand Down
14 changes: 13 additions & 1 deletion WordPress/Classes/ReaderPostTableViewCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,22 @@
@property (nonatomic, strong) UIImageView *avatarImageView;

+ (CGFloat)cellHeightForPost:(ReaderPost *)post withWidth:(CGFloat)width;
+ (ReaderPostTableViewCell *)cellForSubview:(UIView *)subview;

- (void)configureCell:(ReaderPost *)post;
- (void)setReblogTarget:(id)target action:(SEL)selector;
- (void)setFeaturedImage:(UIImage *)image;
- (void)setAvatar:(UIImage *)avatar;

@property (nonatomic, strong) ReaderPost *post;
@property (nonatomic, strong) UIButton *followButton;
@property (nonatomic, strong) UIButton *tagButton;
@property (nonatomic, strong) UIButton *likeButton;
@property (nonatomic, strong) UIButton *reblogButton;
@property (nonatomic, strong) UIButton *commentButton;
@property (nonatomic, strong) UIButton *timeButton;

extern CGFloat const RPTVCMaxImageHeightPercentage;

- (void)updateControlBar;

@end
Loading