diff --git a/EBPhotoPagesController/EBCaptionView.m b/EBPhotoPagesController/EBCaptionView.m index 1f27f0c..b7e6ad6 100644 --- a/EBPhotoPagesController/EBCaptionView.m +++ b/EBPhotoPagesController/EBCaptionView.m @@ -11,6 +11,7 @@ #import "EBCaptionView.h" +#import "EBConfig.h" #import const NSInteger MaximumNumberOfCaptionLines = 1000000; @@ -304,9 +305,15 @@ - (UILabel *)newCaptionLabel [label setNumberOfLines:MaximumNumberOfCaptionLines]; [label setBackgroundColor:[UIColor clearColor]]; [label setTextColor:[UIColor whiteColor]]; - [label setFont:[UIFont fontWithName:@"HelveticaNeue-Light" size:15]]; + + if ([[EBConfig sharedConfig] bodyFont] != nil) { + [label setFont:[[EBConfig sharedConfig] bodyFont]]; + } else { + [label setFont:[UIFont fontWithName:@"HelveticaNeue-Light" size:15]]; + } + [label setShadowColor:[UIColor colorWithWhite:0 alpha:0.5]]; [label setShadowOffset:CGSizeMake(0, 1)]; return label; } -@end \ No newline at end of file +@end diff --git a/EBPhotoPagesController/EBCommentCell.m b/EBPhotoPagesController/EBCommentCell.m index 6e49cc3..d1138cf 100644 --- a/EBPhotoPagesController/EBCommentCell.m +++ b/EBPhotoPagesController/EBCommentCell.m @@ -10,8 +10,9 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ - +#import "EBConfig.h" #import "EBCommentCell.h" +#import "NSDate+TimeAgo.h" @implementation EBCommentCell @@ -81,7 +82,12 @@ - (void)loadAuthorNameButton { UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; - [button.titleLabel setFont:[UIFont fontWithName:@"HelveticaNeue-Medium" size:12]]; + if ([[EBConfig sharedConfig] commentTitleFont] != nil) { + [button.titleLabel setFont:[[EBConfig sharedConfig] commentTitleFont]]; + } else { + [button.titleLabel setFont:[UIFont fontWithName:@"HelveticaNeue-Medium" size:12]]; + } + [button.titleLabel setTextColor:[UIColor colorWithWhite:0.8 alpha:1]]; [button.titleLabel setShadowColor:[UIColor colorWithWhite:0 alpha:0.5]]; [button.titleLabel setShadowOffset:CGSizeMake(0, 1)]; @@ -102,7 +108,13 @@ - (void)loadCommentTextLabel UILabel *textLabel = [UILabel new]; [textLabel setBackgroundColor:[UIColor redColor]]; [textLabel setAutoresizingMask:UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth]; - [textLabel setFont:[UIFont fontWithName:@"HelveticaNeue-Light" size:16]]; + + if ([[EBConfig sharedConfig] bodyFont] != nil) { + [textLabel setFont:[[EBConfig sharedConfig] bodyFont]]; + } else { + [textLabel setFont:[UIFont fontWithName:@"HelveticaNeue-Light" size:16]]; + } + [textLabel setTextColor:[UIColor whiteColor]]; [textLabel setShadowColor:[UIColor colorWithWhite:0 alpha:0.5]]; [textLabel setShadowOffset:CGSizeMake(0, 1)]; @@ -120,7 +132,13 @@ - (void)loadDateLabel UILabel *dateLabel = [UILabel new]; [dateLabel setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin]; - [dateLabel setFont:[UIFont fontWithName:@"HelveticaNeue-Medium" size:12]]; + + if ([[EBConfig sharedConfig] commentTitleFont] != nil) { + [dateLabel setFont:[[EBConfig sharedConfig] commentTitleFont]]; + } else { + [dateLabel setFont:[UIFont fontWithName:@"HelveticaNeue-Medium" size:12]]; + } + [dateLabel setTextColor:[UIColor colorWithWhite:0.8 alpha:1]]; [dateLabel setShadowColor:[UIColor colorWithWhite:0 alpha:0.5]]; [dateLabel setShadowOffset:CGSizeMake(0, 1)]; @@ -131,6 +149,22 @@ - (void)loadDateLabel [self setDateLabel:dateLabel]; [self addSubview:dateLabel]; } + + - (void)downloadImageWithURL:(NSURL *)url completionBlock:(void (^)(BOOL succeeded, UIImage *image))completionBlock + { + NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; + [NSURLConnection sendAsynchronousRequest:request + queue:[NSOperationQueue mainQueue] + completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { + if ( !error ) + { + UIImage *image = [[UIImage alloc] initWithData:data]; + completionBlock(YES,image); + } else{ + completionBlock(NO,nil); + } + }]; + } - (void)setComment:(id)comment @@ -147,7 +181,16 @@ - (void)setComment:(id)comment } if([comment respondsToSelector:@selector(authorAvatar)]){ - [self.authorAvatar setImage:[comment authorAvatar]]; + if (comment.authorAvatar != nil) { + [self.authorAvatar setImage:[comment authorAvatar]]; + } + + if (comment.authorAvatarURL != nil) { + [self downloadImageWithURL:comment.authorAvatarURL completionBlock:^(BOOL succeeded, UIImage *image) { + [self.authorAvatar setImage:image]; + }]; + } + [self.authorAvatar.layer setMasksToBounds:YES]; [self.authorAvatar.layer setRasterizationScale:[UIScreen mainScreen].scale]; [self.authorAvatar.layer setShouldRasterize:YES]; @@ -167,9 +210,19 @@ - (void)setComment:(id)comment if([comment respondsToSelector:@selector(postDate)]){ NSDate *postDate = [comment postDate]; - NSDateFormatter *dateFormatter = [self dateFormatter]; - NSString *dateString = [dateFormatter stringFromDate:postDate]; - [self.dateLabel setText:dateString]; + + if ([[EBConfig sharedConfig] dateFormatter] != nil) { + NSString *dateString = [[[EBConfig sharedConfig] dateFormatter] stringFromDate:postDate]; + [self.dateLabel setText:dateString]; + } else { + NSDateFormatter *dateFormatter = [self dateFormatter]; + NSString *dateString = [dateFormatter stringFromDate:postDate]; + [self.dateLabel setText:dateString]; + } + + if ([[EBConfig sharedConfig] shouldUseRelativeTimeFormatting] == YES) { + [self.dateLabel setText:[postDate relativeDateString]]; + } } } diff --git a/EBPhotoPagesController/EBCommentsView.m b/EBPhotoPagesController/EBCommentsView.m index 5b89dcb..8cf59d7 100644 --- a/EBPhotoPagesController/EBCommentsView.m +++ b/EBPhotoPagesController/EBCommentsView.m @@ -14,6 +14,7 @@ #import "EBCommentsView.h" #import #import "EBCommentsTableView.h" +#import "EBConfig.h" @interface EBCommentsView () @property (weak, readwrite) EBCommentsTableView *tableView; @@ -98,7 +99,13 @@ - (void)loadCommentTextView UITextView *textView = [[UITextView alloc] initWithFrame:textViewFrame]; [textView setBackgroundColor:[UIColor clearColor]]; - [textView setFont:[UIFont fontWithName:@"HelveticaNeue-Light" size:16]]; + + if ([[EBConfig sharedConfig] bodyFont] != nil) { + [textView setFont:[[EBConfig sharedConfig] bodyFont]]; + } else { + [textView setFont:[UIFont fontWithName:@"HelveticaNeue-Light" size:16]]; + } + [textView setKeyboardAppearance:UIKeyboardAppearanceAlert]; [textView setTextColor:[UIColor whiteColor]]; //[self setAutoresizingMask:UIViewAutoresizingFlexibleTopMargin| UIViewAutoresizingFlexibleWidth]; @@ -112,7 +119,13 @@ - (void)loadPlaceholderForTextView:(UITextView *)textView { UILabel *label = [[UILabel alloc] initWithFrame:textView.frame]; [label setTextAlignment:NSTextAlignmentLeft]; - [label setFont:textView.font]; + + if ([[EBConfig sharedConfig] bodyFont] != nil) { + [textView setFont:[[EBConfig sharedConfig] bodyFont]]; + } else { + [label setFont:textView.font]; + } + [label setBackgroundColor:[UIColor clearColor]]; [label setTextColor:[UIColor colorWithWhite:0.5 alpha:1]]; [textView.superview insertSubview:label belowSubview:textView]; @@ -141,8 +154,15 @@ - (void)loadPostButton buttonSize.height); UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; [button setFrame:buttonFrame]; - [button setTitle:NSLocalizedString(@"post", @"Appears on a button that posts a comment when tapped.") - forState:UIControlStateNormal]; + + if ([[EBConfig sharedConfig] postButtonTitle] != nil) { + [button setTitle:[[EBConfig sharedConfig] postButtonTitle] + forState:UIControlStateNormal]; + } else { + [button setTitle:NSLocalizedString(@"Post", @"Appears on a button that posts a comment when tapped.") + forState:UIControlStateNormal]; + } + [button addTarget:self action:@selector(didSelectPostButton:) forControlEvents:UIControlEventTouchUpInside]; @@ -250,6 +270,10 @@ - (void)cancelCommenting - (UIColor *)postButtonColor { + if ([[EBConfig sharedConfig] postButtonBackgroundColor] != nil) { + return [[EBConfig sharedConfig] postButtonBackgroundColor]; + } + return [UIColor colorWithRed:0 green:118/255.0 blue:1.0 alpha:1.0]; } diff --git a/EBPhotoPagesController/EBConfig.h b/EBPhotoPagesController/EBConfig.h new file mode 100644 index 0000000..2a4d03e --- /dev/null +++ b/EBPhotoPagesController/EBConfig.h @@ -0,0 +1,92 @@ +// +// EBConfig.h +// EBPhotoPagesControllerDemo +// +// Created by Jesse Onolememen on 11/08/2017. +// Copyright © 2017 Eddy Borja. All rights reserved. +// + +#import + +@interface EBConfig : NSObject + +/// This is the font used for the captions and comments +@property (nonatomic, retain) UIFont* bodyFont; + +/// This is the font used for buttons and titles +@property (nonatomic, retain) UIFont* titleFont; + +/// This is the font used for the comment titles +@property (nonatomic, retain) UIFont* commentTitleFont; + +/// This is the colour for all of the titles +@property (nonatomic, retain) UIColor* textColor; +@property (nonatomic, retain) UIColor* postButtonBackgroundColor; + +/// This is the color used for all of the excluding the post button +@property (nonatomic, retain) UIColor* tintColor; + +/// This is the title for the post button +@property (nonatomic, retain) NSString* postButtonTitle; + +/// This is the formatter used to format the dates for each comment +@property (nonatomic, retain) NSDateFormatter* dateFormatter; +@property BOOL shouldUseRelativeTimeFormatting; + + + +/// This is the font used for the captions and comments +- (UIFont *)bodyFont; + +/// Sets the font used for the captions and comments +- (void)setBodyFont: (UIFont *) font; + +/// This is the font used for the comment titles +- (UIFont *)commentTitleFont; + +/// Sets the font used for the comment avatar title +- (void)setCommentTitleFont: (UIFont *) font; + +/// This is the font used for buttons and titles +- (UIFont *)titleFont; + +/// Sets the font used for buttons and titles +- (void)setTitleFont: (UIFont *) font; + +/// This is the colour for all of the titles +- (UIColor *)textColor; + +/// Sets the colour for all of the titles +- (void)setTextColor: (UIColor *) textColor; + +/// This is the background color for the post button +- (UIColor *)postButtonBackgroundColor; + +/// Sets the background color for the post button +- (void)setPostButtonBackgroundColor: (UIColor *) postButtonBackgroundColor; + +/// This is the color used for all of the excluding the post button +- (UIColor *)tintColor; + +/// Sets the color used for all of the excluding the post button +- (void)setTintColor: (UIColor *) tintColor; + +/// This is the title for the post button +- (NSString *)postButtonTitle; + +/// Sets the title for the post button +- (void)setPostButtonTitle: (NSString *) postButtonTitle; + +/// This is the formatter used to format the dates for each comment +- (NSDateFormatter *)dateFormatter; + +/// Sets the formatter used to format the dates for each comment +- (void)setDateFormatter: (NSDateFormatter *) dateFormatter; + +- (BOOL)shouldUseRelativeTimeFormatting; +- (void)setShouldUseRelativeTimeFormatting: (BOOL) shouldUseRelativeTimeFormatting; + +/// Global configuration ++(EBConfig *)sharedConfig; + +@end diff --git a/EBPhotoPagesController/EBConfig.m b/EBPhotoPagesController/EBConfig.m new file mode 100644 index 0000000..f507a61 --- /dev/null +++ b/EBPhotoPagesController/EBConfig.m @@ -0,0 +1,125 @@ +// +// EBConfig.m +// EBPhotoPagesControllerDemo +// +// Created by Jesse Onolememen on 11/08/2017. +// Copyright © 2017 Eddy Borja. All rights reserved. +// + +#import "EBConfig.h" + +@implementation EBConfig + +@synthesize bodyFont = _bodyFont; +@synthesize titleFont = _titleFont; +@synthesize commentTitleFont = _commentTitleFont; + +@synthesize textColor = _textColor; +@synthesize tintColor = _tintColor; +@synthesize postButtonBackgroundColor = _postButtonBackgroundColor; + +@synthesize postButtonTitle = _postButtonTitle; + +@synthesize dateFormatter = _dateFormatter; +@synthesize shouldUseRelativeTimeFormatting = _shouldUseRelativeTimeFormatting; + ++ (EBConfig *)sharedConfig { + static EBConfig *sharedInstance = nil; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + sharedInstance = [[EBConfig alloc] init]; + }); + return sharedInstance; +} + +#pragma mark Body Font + +- (UIFont *)bodyFont { + return _bodyFont; +} + +- (void)setBodyFont: (UIFont *) font { + _bodyFont = font; +} + +#pragma mark Title Font + +- (UIFont *)titleFont { + return _titleFont; +} + +- (void)setTitleFont: (UIFont *) font { + _titleFont = font; +} + +#pragma mark Comment Title Font + +- (UIFont *)commentTitleFont { + return _commentTitleFont; +} + +- (void)setCommentTitleFont:(UIFont *)font { + _commentTitleFont = font; +} + +#pragma mark Text Color + +- (UIColor *)textColor { + return _textColor; +} + +- (void)setTextColor: (UIColor *) textColor { + _textColor = textColor; +} + +#pragma mark Tint Color + +- (UIColor *)tintColor { + return _tintColor; +} + +- (void)setTintColor:(UIColor *)tintColor { + _tintColor = tintColor; +} + +#pragma mark Date Formatter + +- (NSDateFormatter *)dateFormatter { + return _dateFormatter; +} + +- (void)setDateFormatter:(NSDateFormatter *)dateFormatter { + _dateFormatter = dateFormatter; +} + +#pragma mark Post Button Title + +- (NSString *)postButtonTitle { + return _postButtonTitle; +} + +- (void)setPostButtonTitle:(NSString *)postButtonTitle { + _postButtonTitle = postButtonTitle; +} + +#pragma mark Post Button Background Color +- (UIColor *)postButtonBackgroundColor { + return _postButtonBackgroundColor; +} + +- (void)setPostButtonBackgroundColor:(UIColor *)postButtonBackgroundColor { + _postButtonBackgroundColor = postButtonBackgroundColor; +} + +#pragma mark Relative Timing + +- (BOOL)shouldUseRelativeTimeFormatting { + return _shouldUseRelativeTimeFormatting; +} + +- (void)setShouldUseRelativeTimeFormatting:(BOOL)shouldUseRelativeTimeFormatting { + _shouldUseRelativeTimeFormatting = shouldUseRelativeTimeFormatting; +} + + +@end diff --git a/EBPhotoPagesController/EBPhotoCommentProtocol.h b/EBPhotoPagesController/EBPhotoCommentProtocol.h index f7d58fd..ad80718 100644 --- a/EBPhotoPagesController/EBPhotoCommentProtocol.h +++ b/EBPhotoPagesController/EBPhotoCommentProtocol.h @@ -34,6 +34,9 @@ //This is an image of the person who posted the comment - (UIImage *)authorAvatar; + +/// A URL that represents the image that is shown on the comment +- (NSURL *)authorAvatarURL; //This may contain additional application specific information you want to provide about the comment. - (NSDictionary *)metaInfo; diff --git a/EBPhotoPagesController/EBPhotoPagesController.m b/EBPhotoPagesController/EBPhotoPagesController.m index e627234..15abeee 100644 --- a/EBPhotoPagesController/EBPhotoPagesController.m +++ b/EBPhotoPagesController/EBPhotoPagesController.m @@ -35,17 +35,6 @@ @interface EBPhotoPagesController () @property (strong) NSDictionary *actionSheetTargetInfo; //info about the object the action sheet is currently handling @property (assign) BOOL originalStatusBarVisibility; -@property (nonatomic, strong) UIBarButtonItem *doneBarButtonItem; -@property (nonatomic, strong) UIBarButtonItem *cancelBarButtonItem; -@property (nonatomic, strong) UIBarButtonItem *tagBarButtonItem; -@property (nonatomic, strong) UIBarButtonItem *doneTaggingBarButtonItem; -@property (nonatomic, strong) UIBarButtonItem *activityBarButtonItem; -@property (nonatomic, strong) UIBarButtonItem *commentsBarButtonItem; -@property (nonatomic, strong) UIBarButtonItem *miscBarButtonItem; -@property (nonatomic, strong) UIBarButtonItem *commentsExitBarButtonItem; -@property (nonatomic, strong) UIBarButtonItem *hideCommentsBarButtonItem; -@property (nonatomic, strong) UIBarButtonItem *toggleTagsBarButtonItem; - @property (weak) UIToolbar *upperToolbar; @property (weak) UIToolbar *lowerToolbar; @property (weak) UIView *screenDimmer; @@ -58,6 +47,17 @@ @interface EBPhotoPagesController () @property (assign) NSInteger currentPhotoIndex; +@property (nonatomic) UIBarButtonItem *doneBarButtonItem; +@property (nonatomic) UIBarButtonItem *cancelBarButtonItem; +@property (nonatomic) UIBarButtonItem *tagBarButtonItem; +@property (nonatomic) UIBarButtonItem *doneTaggingBarButtonItem; +@property (nonatomic) UIBarButtonItem *activityBarButtonItem; +@property (nonatomic) UIBarButtonItem *miscBarButtonItem; +@property (nonatomic) UIBarButtonItem *commentsBarButtonItem; +@property (nonatomic) UIBarButtonItem *commentsExitBarButtonItem; +@property (nonatomic) UIBarButtonItem *hideCommentsBarButtonItem; +@property (nonatomic) UIBarButtonItem *toggleTagsBarButtonItem; + @end #pragma mark - diff --git a/EBPhotoPagesController/EBPhotoPagesFactory.m b/EBPhotoPagesController/EBPhotoPagesFactory.m index 1295954..525a140 100644 --- a/EBPhotoPagesController/EBPhotoPagesFactory.m +++ b/EBPhotoPagesController/EBPhotoPagesFactory.m @@ -22,6 +22,7 @@ #import "EBCommentsView.h" #import "EBCommentsTableView.h" #import "EBCommentCell.h" +#import "EBConfig.h" #include //static inline double radians (double degrees) {return degrees * M_PI/180;} @@ -272,6 +273,15 @@ - (UIBarButtonItem *)hideCommentsBarButtonItemForPhotoPagesController:(EBPhotoPa style:UIBarButtonItemStyleDone target:controller selector:@selector(didSelectCancelButton:)]; + + if ([[EBConfig sharedConfig] titleFont] != nil) { + [hideCommentsButton setTitleTextAttributes: + @{ + NSFontAttributeName: [[EBConfig sharedConfig] titleFont], + NSForegroundColorAttributeName: [[EBConfig sharedConfig] textColor] != nil ? [[EBConfig sharedConfig] textColor] : [UIColor whiteColor] + } forState:UIControlStateNormal]; + } + return hideCommentsButton; } @@ -317,6 +327,15 @@ - (UIBarButtonItem *)doneBarButtonItemForPhotoPagesController:(EBPhotoPagesContr style:UIBarButtonItemStyleDone target:controller selector:@selector(didSelectDoneButton:)]; + + if ([[EBConfig sharedConfig] titleFont] != nil) { + [doneButton setTitleTextAttributes: + @{ + NSFontAttributeName: [[EBConfig sharedConfig] titleFont], + NSForegroundColorAttributeName: [[EBConfig sharedConfig] textColor] != nil ? [[EBConfig sharedConfig] textColor] : [UIColor whiteColor] + } forState:UIControlStateNormal]; + } + return doneButton; } @@ -327,6 +346,15 @@ - (UIBarButtonItem *)cancelBarButtonItemForPhotoPagesController:(EBPhotoPagesCon style:UIBarButtonItemStyleDone target:controller selector:@selector(didSelectCancelButton:)]; + + if ([[EBConfig sharedConfig] titleFont] != nil) { + [cancelButton setTitleTextAttributes: + @{ + NSFontAttributeName: [[EBConfig sharedConfig] titleFont], + NSForegroundColorAttributeName: [[EBConfig sharedConfig] textColor] != nil ? [[EBConfig sharedConfig] textColor] : [UIColor whiteColor] + } forState:UIControlStateNormal]; + } + return cancelButton; } @@ -337,6 +365,7 @@ - (UIBarButtonItem *)tagBarButtonItemForPhotoPagesController:(EBPhotoPagesContro style:UIBarButtonItemStylePlain target:controller selector:@selector(didSelectTagButton:)]; + return tagButton; } @@ -347,6 +376,15 @@ - (UIBarButtonItem *)doneTaggingBarButtonItemForPhotoPagesController:(EBPhotoPag style:UIBarButtonItemStyleDone target:controller selector:@selector(didSelectTagDoneButton:)]; + + if ([[EBConfig sharedConfig] titleFont] != nil) { + [doneTaggingButton setTitleTextAttributes: + @{ + NSFontAttributeName: [[EBConfig sharedConfig] titleFont], + NSForegroundColorAttributeName: [[EBConfig sharedConfig] textColor] != nil ? [[EBConfig sharedConfig] textColor] : [UIColor whiteColor] + } forState:UIControlStateNormal]; + } + return doneTaggingButton; } @@ -1056,26 +1094,47 @@ - (UIImage *)iconForCommentsBarButtonItemForPhotoPagesController:(EBPhotoPagesCo - (NSString *)photoPagesDefaultFontName { + if ([[EBConfig sharedConfig] bodyFont] != nil) { + return [[EBConfig sharedConfig] bodyFont].fontName; + } + return @"HelveticaNeue-Light"; } - (NSString *)photoPagesBoldFontName { + if ([[EBConfig sharedConfig] titleFont] != nil) { + return [[EBConfig sharedConfig] titleFont].fontName; + } + return @"HelveticaNeue-Bold"; } - (UIColor *)upperToolbarTintColor { + if ([[EBConfig sharedConfig] tintColor] != nil) { + return [[EBConfig sharedConfig] tintColor]; + } + return [self photoPagesTintColor]; } - (UIColor *)lowerToolbarTintColor { + + if ([[EBConfig sharedConfig] tintColor] != nil) { + return [[EBConfig sharedConfig] tintColor]; + } + return [self photoPagesTintColor]; } - (UIColor *)commentCellTintColor { + if ([[EBConfig sharedConfig] tintColor] != nil) { + return [[[EBConfig sharedConfig] tintColor] colorWithAlphaComponent:0.35]; + } + UIColor *photoPagesColor = [self photoPagesTintColor]; return [photoPagesColor colorWithAlphaComponent:0.35]; } diff --git a/EBPhotoPagesController/EBTagPopover.m b/EBPhotoPagesController/EBTagPopover.m index e9b3562..7762713 100644 --- a/EBPhotoPagesController/EBTagPopover.m +++ b/EBPhotoPagesController/EBTagPopover.m @@ -9,7 +9,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ - +#import "EBConfig.h" #import "EBTagPopover.h" #import "EBPhotoPagesController.h" #import "EBPhotoPagesNotifications.h" @@ -115,6 +115,7 @@ - (UIView *)newContentView { NSString *placeholderText = NSLocalizedString(@"New Tag", @"Appears as placeholder text before a user enters text for a photo tag."); + UIFont *textFieldFont = [UIFont fontWithName:@"HelveticaNeue-Bold" size:12]; CGSize tagSize = [placeholderText sizeWithAttributes:@{NSFontAttributeName: [UIFont fontWithName:@"HelveticaNeue-Bold" size:12]}]; UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, tagSize.width, tagSize.height)]; diff --git a/EBPhotoPagesController/NSDate+TimeAgo.h b/EBPhotoPagesController/NSDate+TimeAgo.h new file mode 100644 index 0000000..e40ed2b --- /dev/null +++ b/EBPhotoPagesController/NSDate+TimeAgo.h @@ -0,0 +1,15 @@ +// +// NSDate+TimeAgo.h +// EBPhotoPagesControllerDemo +// +// Created by Jesse Onolememen on 11/08/2017. +// Copyright © 2017 Eddy Borja. All rights reserved. +// + +#import + +@interface NSDate (TimeAgo) + +- (NSString *)relativeDateString; + +@end diff --git a/EBPhotoPagesController/NSDate+TimeAgo.m b/EBPhotoPagesController/NSDate+TimeAgo.m new file mode 100644 index 0000000..964bca0 --- /dev/null +++ b/EBPhotoPagesController/NSDate+TimeAgo.m @@ -0,0 +1,67 @@ +// +// NSDate+TimeAgo.m +// EBPhotoPagesControllerDemo +// +// Created by Jesse Onolememen on 11/08/2017. +// Copyright © 2017 Eddy Borja. All rights reserved. +// + +#import "NSDate+TimeAgo.h" + +@implementation NSDate (TimeAgo) + + + - (NSString *)relativeDateString + { + const int SECOND = 1; + const int MINUTE = 60 * SECOND; + const int HOUR = 60 * MINUTE; + const int DAY = 24 * HOUR; + const int MONTH = 30 * DAY; + + NSDate *now = [NSDate date]; + NSTimeInterval delta = [self timeIntervalSinceDate:now] * -1.0; + + NSCalendar *calendar = [NSCalendar currentCalendar]; + NSCalendarUnit unitFlags = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond; +// NSDateComponents *components = [calendar components:units fromDate:self toDate:now options:0]; + NSDateComponents *components = [calendar components:unitFlags fromDate:self toDate:now options:0]; + NSString *relativeString; + + if (delta < 0) { + relativeString = @"!n the future!"; + + } else if (delta < 1 * MINUTE) { + relativeString = (components.second == 1) ? @"One second ago" : [NSString stringWithFormat:@"%ld seconds ago",(long)components.second]; + + } else if (delta < 2 * MINUTE) { + relativeString = @"a minute ago"; + + } else if (delta < 45 * MINUTE) { + relativeString = [NSString stringWithFormat:@"%ld minutes ago",(long)components.minute]; + + } else if (delta < 90 * MINUTE) { + relativeString = @"an hour ago"; + + } else if (delta < 24 * HOUR) { + relativeString = [NSString stringWithFormat:@"%ld hours ago",(long)components.hour]; + + } else if (delta < 48 * HOUR) { + relativeString = @"yesterday"; + + } else if (delta < 30 * DAY) { + relativeString = [NSString stringWithFormat:@"%ld days ago",(long)components.day]; + + } else if (delta < 12 * MONTH) { + relativeString = (components.month <= 1) ? @"one month ago" : [NSString stringWithFormat:@"%ld months ago",(long)components.month]; + + } else { + relativeString = (components.year <= 1) ? @"one year ago" : [NSString stringWithFormat:@"%ld years ago",(long)components.year]; + + } + + return relativeString; + } + + + @end diff --git a/EBPhotoPagesControllerDemo.xcodeproj/project.pbxproj b/EBPhotoPagesControllerDemo.xcodeproj/project.pbxproj index 0ef0e62..8adc383 100644 --- a/EBPhotoPagesControllerDemo.xcodeproj/project.pbxproj +++ b/EBPhotoPagesControllerDemo.xcodeproj/project.pbxproj @@ -86,6 +86,8 @@ 8583A59118022E1400D694A5 /* EBTagPopover.m in Sources */ = {isa = PBXBuildFile; fileRef = 8583A58318022E1400D694A5 /* EBTagPopover.m */; }; 8583A59818022FE500D694A5 /* AVFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8583A59718022FE500D694A5 /* AVFoundation.framework */; }; 8583A59A18022FF400D694A5 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8583A59918022FF400D694A5 /* QuartzCore.framework */; }; + 956FF9B71F3E1E5B007F7712 /* NSDate+TimeAgo.m in Sources */ = {isa = PBXBuildFile; fileRef = 956FF9B61F3E1E5B007F7712 /* NSDate+TimeAgo.m */; }; + 956FF9BA1F3E1E64007F7712 /* EBConfig.m in Sources */ = {isa = PBXBuildFile; fileRef = 956FF9B91F3E1E64007F7712 /* EBConfig.m */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -214,6 +216,10 @@ 8583A59718022FE500D694A5 /* AVFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AVFoundation.framework; path = System/Library/Frameworks/AVFoundation.framework; sourceTree = SDKROOT; }; 8583A59918022FF400D694A5 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; 8583A5A11802322900D694A5 /* EBPhotoPagesNotifications.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = EBPhotoPagesNotifications.h; path = EBPhotoPagesController/EBPhotoPagesNotifications.h; sourceTree = ""; }; + 956FF9B51F3E1E5B007F7712 /* NSDate+TimeAgo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "NSDate+TimeAgo.h"; path = "EBPhotoPagesController/NSDate+TimeAgo.h"; sourceTree = ""; }; + 956FF9B61F3E1E5B007F7712 /* NSDate+TimeAgo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "NSDate+TimeAgo.m"; path = "EBPhotoPagesController/NSDate+TimeAgo.m"; sourceTree = ""; }; + 956FF9B81F3E1E64007F7712 /* EBConfig.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = EBConfig.h; path = EBPhotoPagesController/EBConfig.h; sourceTree = ""; }; + 956FF9B91F3E1E64007F7712 /* EBConfig.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = EBConfig.m; path = EBPhotoPagesController/EBConfig.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -419,6 +425,7 @@ 8583A59E180230F500D694A5 /* Photos */, 8583A59D180230D500D694A5 /* Caption */, 8583A59C180230C300D694A5 /* Tags */, + 956FF9AE1F3E0EEC007F7712 /* Config */, 8583A59B180230AF00D694A5 /* Comments */, ); name = EBPhotoPagesController; @@ -493,10 +500,21 @@ 8583A58018022E1400D694A5 /* EBShadedView.h */, 8583A58118022E1400D694A5 /* EBShadedView.m */, 8583A5A11802322900D694A5 /* EBPhotoPagesNotifications.h */, + 956FF9B51F3E1E5B007F7712 /* NSDate+TimeAgo.h */, + 956FF9B61F3E1E5B007F7712 /* NSDate+TimeAgo.m */, ); name = Helpers; sourceTree = ""; }; + 956FF9AE1F3E0EEC007F7712 /* Config */ = { + isa = PBXGroup; + children = ( + 956FF9B81F3E1E64007F7712 /* EBConfig.h */, + 956FF9B91F3E1E64007F7712 /* EBConfig.m */, + ); + name = Config; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -650,8 +668,10 @@ 8583A58B18022E1400D694A5 /* EBPhotoPagesOperation.m in Sources */, 8583A54418022D3800D694A5 /* DEMOTag.m in Sources */, 8583A58918022E1400D694A5 /* EBPhotoPagesController.m in Sources */, + 956FF9B71F3E1E5B007F7712 /* NSDate+TimeAgo.m in Sources */, 8583A54218022D3800D694A5 /* DEMOViewController.m in Sources */, 8583A58A18022E1400D694A5 /* EBPhotoPagesFactory.m in Sources */, + 956FF9BA1F3E1E64007F7712 /* EBConfig.m in Sources */, 8583A54118022D3800D694A5 /* DEMOAppDelegate.m in Sources */, 8583A58818022E1400D694A5 /* EBCommentsView.m in Sources */, ); diff --git a/EBPhotoPagesControllerDemo/DEMOComment.m b/EBPhotoPagesControllerDemo/DEMOComment.m index b4ec834..fbbc385 100644 --- a/EBPhotoPagesControllerDemo/DEMOComment.m +++ b/EBPhotoPagesControllerDemo/DEMOComment.m @@ -63,5 +63,9 @@ - (UIImage *)authorAvatar { return self.image; } + +- (NSURL *)authorAvatarURL { + return nil; +} @end diff --git a/EBPhotoPagesControllerDemo/DEMOViewController.m b/EBPhotoPagesControllerDemo/DEMOViewController.m index aef4d43..fcbe808 100644 --- a/EBPhotoPagesControllerDemo/DEMOViewController.m +++ b/EBPhotoPagesControllerDemo/DEMOViewController.m @@ -21,6 +21,7 @@ #import "EBPhotoPagesController.h" #import "EBPhotoPagesFactory.h" #import "EBTagPopover.h" +#import "EBConfig.h" @interface DEMOViewController () @@ -208,8 +209,6 @@ - (void)loadView @"authorImage": [UIImage imageNamed:@"kerem.jpg"], @"authorName" : @"Kerem"}], ]; - - [self setPhotos:@[ [DEMOPhoto photoWithProperties: @{@"imageFile": @"photo1.jpg", @@ -334,6 +333,8 @@ - (void)loadView [photo setDisabledDeleteForTags:YES]; [photo setDisabledActivities:YES]; + [self customize]; + } - (void)viewDidLoad @@ -358,6 +359,11 @@ - (void)didReceiveMemoryWarning [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } + +- (void) customize { + [[EBConfig sharedConfig] setBodyFont: [UIFont fontWithName:@"Avenir-Book" size:17]]; + [[EBConfig sharedConfig] setShouldUseRelativeTimeFormatting:YES]; +} - (IBAction)didSelectViewPhotos:(id)sender {