Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 9 additions & 2 deletions EBPhotoPagesController/EBCaptionView.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@


#import "EBCaptionView.h"
#import "EBConfig.h"
#import <QuartzCore/QuartzCore.h>

const NSInteger MaximumNumberOfCaptionLines = 1000000;
Expand Down Expand Up @@ -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
@end
69 changes: 61 additions & 8 deletions EBPhotoPagesController/EBCommentCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)];
Expand All @@ -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)];
Expand All @@ -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)];
Expand All @@ -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<EBPhotoCommentProtocol>)comment
Expand All @@ -147,7 +181,16 @@ - (void)setComment:(id<EBPhotoCommentProtocol>)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];
Expand All @@ -167,9 +210,19 @@ - (void)setComment:(id<EBPhotoCommentProtocol>)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]];
}
}

}
Expand Down
32 changes: 28 additions & 4 deletions EBPhotoPagesController/EBCommentsView.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#import "EBCommentsView.h"
#import <QuartzCore/QuartzCore.h>
#import "EBCommentsTableView.h"
#import "EBConfig.h"

@interface EBCommentsView ()
@property (weak, readwrite) EBCommentsTableView *tableView;
Expand Down Expand Up @@ -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];
Expand All @@ -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];
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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];
}

Expand Down
92 changes: 92 additions & 0 deletions EBPhotoPagesController/EBConfig.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
//
// EBConfig.h
// EBPhotoPagesControllerDemo
//
// Created by Jesse Onolememen on 11/08/2017.
// Copyright © 2017 Eddy Borja. All rights reserved.
//

#import <Foundation/Foundation.h>

@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
Loading