2010-07-15 00:44:38 -04:00
|
|
|
//
|
|
|
|
// FeedDetailTableCell.m
|
|
|
|
// NewsBlur
|
|
|
|
//
|
|
|
|
// Created by Samuel Clay on 7/14/10.
|
|
|
|
// Copyright 2010 NewsBlur. All rights reserved.
|
|
|
|
//
|
|
|
|
|
2012-07-22 17:08:29 -07:00
|
|
|
#import "NewsBlurAppDelegate.h"
|
2010-07-15 00:44:38 -04:00
|
|
|
#import "FeedDetailTableCell.h"
|
2012-07-22 17:08:29 -07:00
|
|
|
#import "ABTableViewCell.h"
|
|
|
|
#import "UIView+TKCategory.h"
|
|
|
|
#import "Utilities.h"
|
2010-07-15 00:44:38 -04:00
|
|
|
|
2012-07-22 17:08:29 -07:00
|
|
|
static UIFont *textFont = nil;
|
|
|
|
static UIFont *indicatorFont = nil;
|
2010-07-15 00:44:38 -04:00
|
|
|
|
2012-07-23 10:57:11 -07:00
|
|
|
|
2010-07-15 00:44:38 -04:00
|
|
|
@implementation FeedDetailTableCell
|
|
|
|
|
|
|
|
@synthesize storyTitle;
|
|
|
|
@synthesize storyAuthor;
|
|
|
|
@synthesize storyDate;
|
2012-08-10 18:10:07 -07:00
|
|
|
@synthesize storyScore;
|
2012-07-22 14:23:50 -07:00
|
|
|
@synthesize siteTitle;
|
|
|
|
@synthesize siteFavicon;
|
2012-07-22 17:08:29 -07:00
|
|
|
@synthesize isRead;
|
2012-08-08 18:23:48 -07:00
|
|
|
@synthesize isShort;
|
2012-07-22 17:08:29 -07:00
|
|
|
@synthesize isRiverOrSocial;
|
|
|
|
@synthesize feedColorBar;
|
|
|
|
@synthesize feedColorBarTopBorder;
|
2012-07-23 10:57:11 -07:00
|
|
|
@synthesize hasAlpha;
|
2010-07-15 00:44:38 -04:00
|
|
|
|
2012-08-09 11:06:38 -07:00
|
|
|
|
2012-08-10 18:10:07 -07:00
|
|
|
#define leftMargin 26
|
2012-07-22 17:08:29 -07:00
|
|
|
#define rightMargin 18
|
|
|
|
|
|
|
|
|
2012-07-22 17:21:32 -07:00
|
|
|
+ (void) initialize {
|
2012-07-22 17:08:29 -07:00
|
|
|
if (self == [FeedDetailTableCell class]) {
|
|
|
|
textFont = [UIFont boldSystemFontOfSize:18];
|
|
|
|
indicatorFont = [UIFont boldSystemFontOfSize:12];
|
2010-07-15 00:44:38 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-08 18:23:48 -07:00
|
|
|
- (void)drawContentView:(CGRect)r highlighted:(BOOL)highlighted {
|
2012-08-10 18:10:07 -07:00
|
|
|
|
|
|
|
|
2012-07-23 10:57:11 -07:00
|
|
|
int adjustForSocial = 3;
|
|
|
|
if (self.isRiverOrSocial) {
|
|
|
|
adjustForSocial = 20;
|
|
|
|
}
|
2012-07-22 17:08:29 -07:00
|
|
|
|
|
|
|
CGContextRef context = UIGraphicsGetCurrentContext();
|
|
|
|
|
2012-07-23 10:57:11 -07:00
|
|
|
CGRect rect = CGRectInset(r, 12, 12);
|
|
|
|
rect.size.width -= 18; // Scrollbar padding
|
|
|
|
|
2012-07-22 17:08:29 -07:00
|
|
|
// set the background color
|
|
|
|
UIColor *backgroundColor;
|
2012-10-04 15:44:25 -07:00
|
|
|
if (highlighted) {
|
2012-08-10 09:45:44 -07:00
|
|
|
backgroundColor = UIColorFromRGB(NEWSBLUR_HIGHLIGHT_COLOR);
|
2012-07-22 17:08:29 -07:00
|
|
|
} else {
|
2012-08-10 18:10:07 -07:00
|
|
|
backgroundColor = UIColorFromRGB(0xf4f4f4);
|
2012-07-22 17:08:29 -07:00
|
|
|
}
|
|
|
|
[backgroundColor set];
|
|
|
|
|
|
|
|
CGContextFillRect(context, r);
|
|
|
|
// set site title
|
|
|
|
UIColor *textColor;
|
|
|
|
UIFont *font;
|
2012-10-16 17:24:01 -07:00
|
|
|
|
2012-07-22 17:08:29 -07:00
|
|
|
if (self.isRead) {
|
|
|
|
font = [UIFont fontWithName:@"Helvetica" size:11];
|
|
|
|
textColor = UIColorFromRGB(0xc0c0c0);
|
|
|
|
} else {
|
|
|
|
font = [UIFont fontWithName:@"Helvetica-Bold" size:11];
|
|
|
|
textColor = UIColorFromRGB(0x606060);
|
|
|
|
|
|
|
|
}
|
2012-10-04 15:44:25 -07:00
|
|
|
if (highlighted) {
|
2012-07-28 23:31:12 -07:00
|
|
|
textColor = UIColorFromRGB(0x686868); //0x686868
|
2012-07-22 17:08:29 -07:00
|
|
|
}
|
|
|
|
[textColor set];
|
|
|
|
|
2012-07-23 10:57:11 -07:00
|
|
|
if (self.isRiverOrSocial) {
|
|
|
|
[self.siteTitle
|
2012-08-10 18:10:07 -07:00
|
|
|
drawInRect:CGRectMake(leftMargin + 20, 7, rect.size.width - 20, 21)
|
2012-07-23 10:57:11 -07:00
|
|
|
withFont:font
|
|
|
|
lineBreakMode:UILineBreakModeTailTruncation
|
|
|
|
alignment:UITextAlignmentLeft];
|
|
|
|
|
|
|
|
if (self.isRead) {
|
|
|
|
font = [UIFont fontWithName:@"Helvetica" size:12];
|
|
|
|
textColor = UIColorFromRGB(0xc0c0c0);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
textColor = UIColorFromRGB(0x333333);
|
|
|
|
font = [UIFont fontWithName:@"Helvetica-Bold" size:12];
|
|
|
|
}
|
2012-10-04 15:44:25 -07:00
|
|
|
if (highlighted) {
|
2012-07-28 23:31:12 -07:00
|
|
|
textColor = UIColorFromRGB(0x686868);
|
2012-07-23 10:57:11 -07:00
|
|
|
}
|
|
|
|
[textColor set];
|
2012-07-22 17:08:29 -07:00
|
|
|
}
|
|
|
|
|
2012-08-10 18:10:07 -07:00
|
|
|
// story title
|
2012-08-07 09:57:21 -07:00
|
|
|
|
2012-08-10 18:10:07 -07:00
|
|
|
CGSize theSize = [self.storyTitle sizeWithFont:font constrainedToSize:CGSizeMake(rect.size.width, 30.0) lineBreakMode:UILineBreakModeTailTruncation];
|
2012-08-07 09:57:21 -07:00
|
|
|
|
2012-08-10 18:10:07 -07:00
|
|
|
int storyTitleY = 7 + adjustForSocial + ((30 - theSize.height)/2);
|
2012-08-08 18:23:48 -07:00
|
|
|
if (self.isShort){
|
2012-08-10 18:10:07 -07:00
|
|
|
storyTitleY = 7 + adjustForSocial + 2;
|
2012-08-08 18:23:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
[self.storyTitle
|
2012-08-10 18:10:07 -07:00
|
|
|
drawInRect:CGRectMake(leftMargin, storyTitleY, rect.size.width, theSize.height)
|
2012-07-22 17:08:29 -07:00
|
|
|
withFont:font
|
|
|
|
lineBreakMode:UILineBreakModeTailTruncation
|
|
|
|
alignment:UITextAlignmentLeft];
|
2012-08-07 09:57:21 -07:00
|
|
|
|
2012-08-13 17:35:04 -07:00
|
|
|
int storyAuthorDateY = 41 + adjustForSocial;
|
2012-08-08 18:23:48 -07:00
|
|
|
if (self.isShort){
|
2012-08-13 17:35:04 -07:00
|
|
|
storyAuthorDateY -= 13;
|
2012-08-08 18:23:48 -07:00
|
|
|
}
|
2012-08-10 18:10:07 -07:00
|
|
|
|
2012-07-22 17:08:29 -07:00
|
|
|
// story author style
|
2012-08-10 18:10:07 -07:00
|
|
|
|
2012-07-22 17:08:29 -07:00
|
|
|
if (self.isRead) {
|
|
|
|
textColor = UIColorFromRGB(0xc0c0c0);
|
|
|
|
font = [UIFont fontWithName:@"Helvetica" size:10];
|
|
|
|
} else {
|
|
|
|
textColor = UIColorFromRGB(0x959595);
|
|
|
|
font = [UIFont fontWithName:@"Helvetica-Bold" size:10];
|
|
|
|
}
|
2012-10-04 15:44:25 -07:00
|
|
|
if (highlighted) {
|
2012-07-28 23:31:12 -07:00
|
|
|
textColor = UIColorFromRGB(0x686868);
|
2012-07-22 17:08:29 -07:00
|
|
|
}
|
|
|
|
[textColor set];
|
2012-08-08 18:23:48 -07:00
|
|
|
|
|
|
|
[self.storyAuthor
|
2012-08-10 18:10:07 -07:00
|
|
|
drawInRect:CGRectMake(leftMargin, storyAuthorDateY, (rect.size.width) / 2 - 10, 15.0)
|
2012-07-22 17:08:29 -07:00
|
|
|
withFont:font
|
2012-08-08 18:23:48 -07:00
|
|
|
lineBreakMode:UILineBreakModeTailTruncation
|
2012-07-22 17:08:29 -07:00
|
|
|
alignment:UITextAlignmentLeft];
|
2012-08-08 18:23:48 -07:00
|
|
|
|
2012-07-22 17:08:29 -07:00
|
|
|
// story date
|
|
|
|
if (self.isRead) {
|
|
|
|
textColor = UIColorFromRGB(0xbabdd1);
|
|
|
|
font = [UIFont fontWithName:@"Helvetica" size:10];
|
|
|
|
} else {
|
|
|
|
textColor = UIColorFromRGB(0x262c6c);
|
|
|
|
font = [UIFont fontWithName:@"Helvetica-Bold" size:10];
|
|
|
|
}
|
|
|
|
|
2012-10-04 15:44:25 -07:00
|
|
|
if (highlighted) {
|
2012-07-28 23:31:12 -07:00
|
|
|
textColor = UIColorFromRGB(0x686868);
|
2012-07-22 17:08:29 -07:00
|
|
|
}
|
|
|
|
[textColor set];
|
|
|
|
|
|
|
|
[self.storyDate
|
2012-08-10 18:10:07 -07:00
|
|
|
drawInRect:CGRectMake(leftMargin + (rect.size.width) / 2 - 10, storyAuthorDateY, (rect.size.width) / 2 + 10, 15.0)
|
2012-07-22 17:08:29 -07:00
|
|
|
withFont:font
|
|
|
|
lineBreakMode:UILineBreakModeTailTruncation
|
|
|
|
alignment:UITextAlignmentRight];
|
|
|
|
|
2012-08-07 09:57:21 -07:00
|
|
|
// feed bar
|
2012-08-10 18:10:07 -07:00
|
|
|
|
2012-08-13 17:35:04 -07:00
|
|
|
CGContextSetStrokeColor(context, CGColorGetComponents([self.feedColorBarTopBorder CGColor])); //feedColorBarTopBorder
|
2012-08-07 09:57:21 -07:00
|
|
|
if (self.isRead) {
|
|
|
|
CGContextSetAlpha(context, 0.25);
|
|
|
|
}
|
2012-08-10 18:10:07 -07:00
|
|
|
CGContextSetLineWidth(context, 6.0f);
|
2012-08-11 18:03:28 -07:00
|
|
|
CGContextBeginPath(context);
|
|
|
|
CGContextMoveToPoint(context, 3.0f, 1.0f);
|
|
|
|
CGContextAddLineToPoint(context, 3.0f, self.frame.size.height - 1);
|
|
|
|
CGContextStrokePath(context);
|
2012-08-10 18:10:07 -07:00
|
|
|
|
2012-08-13 17:35:04 -07:00
|
|
|
CGContextSetStrokeColor(context, CGColorGetComponents([self.feedColorBar CGColor]));
|
|
|
|
CGContextBeginPath(context);
|
|
|
|
CGContextMoveToPoint(context, 9.0f, 1.0f);
|
|
|
|
CGContextAddLineToPoint(context, 9.0, self.frame.size.height - 1);
|
|
|
|
CGContextStrokePath(context);
|
2012-08-07 09:57:21 -07:00
|
|
|
|
2012-08-08 12:02:54 -07:00
|
|
|
// reset for borders
|
2012-08-10 18:10:07 -07:00
|
|
|
|
2012-08-08 12:02:54 -07:00
|
|
|
CGContextSetAlpha(context, 1.0);
|
2012-08-07 09:57:21 -07:00
|
|
|
CGContextSetLineWidth(context, 1.0f);
|
2012-10-04 15:44:25 -07:00
|
|
|
if (highlighted) {
|
2012-07-23 10:57:11 -07:00
|
|
|
// top border
|
|
|
|
UIColor *blue = UIColorFromRGB(0x6eadf5);
|
|
|
|
|
|
|
|
CGContextSetStrokeColor(context, CGColorGetComponents([blue CGColor]));
|
|
|
|
|
|
|
|
CGContextBeginPath(context);
|
2012-07-28 23:31:12 -07:00
|
|
|
CGContextMoveToPoint(context, 0, 0.5f);
|
2012-07-29 22:44:28 -07:00
|
|
|
CGContextAddLineToPoint(context, self.bounds.size.width, 0.5f);
|
2012-07-23 10:57:11 -07:00
|
|
|
CGContextStrokePath(context);
|
|
|
|
|
|
|
|
// bottom border
|
|
|
|
CGContextBeginPath(context);
|
2012-08-10 18:10:07 -07:00
|
|
|
CGContextMoveToPoint(context, 0, self.bounds.size.height - 1.5f);
|
|
|
|
CGContextAddLineToPoint(context, self.bounds.size.width, self.bounds.size.height - 1.5f);
|
2012-07-23 10:57:11 -07:00
|
|
|
CGContextStrokePath(context);
|
|
|
|
} else {
|
|
|
|
// top border
|
2012-08-10 18:10:07 -07:00
|
|
|
UIColor *white = UIColorFromRGB(0xffffff);
|
2012-07-23 10:57:11 -07:00
|
|
|
|
2012-08-10 18:10:07 -07:00
|
|
|
CGContextSetStrokeColor(context, CGColorGetComponents([white CGColor]));
|
2012-07-23 10:57:11 -07:00
|
|
|
|
|
|
|
CGContextBeginPath(context);
|
|
|
|
CGContextMoveToPoint(context, 0.0f, 0.5f);
|
2012-08-10 18:10:07 -07:00
|
|
|
CGContextAddLineToPoint(context, self.bounds.size.width, 0.5f);
|
2012-07-23 10:57:11 -07:00
|
|
|
CGContextStrokePath(context);
|
2012-07-22 17:08:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// site favicon
|
2012-07-23 10:57:11 -07:00
|
|
|
if (self.isRead && !self.hasAlpha) {
|
|
|
|
if (self.isRiverOrSocial) {
|
|
|
|
self.siteFavicon = [self imageByApplyingAlpha:self.siteFavicon withAlpha:0.25];
|
|
|
|
}
|
|
|
|
self.hasAlpha = YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (self.isRiverOrSocial) {
|
2012-08-10 18:10:07 -07:00
|
|
|
[self.siteFavicon drawInRect:CGRectMake(leftMargin, 6.0, 16.0, 16.0)];
|
|
|
|
}
|
|
|
|
|
|
|
|
// story indicator
|
|
|
|
int storyIndicatorY = 4 + adjustForSocial;
|
|
|
|
if (self.isShort){
|
|
|
|
storyIndicatorY = 4 + adjustForSocial - 5 ;
|
|
|
|
}
|
|
|
|
|
|
|
|
UIColor *scoreColor;
|
|
|
|
if (storyScore == -1) {
|
|
|
|
scoreColor = UIColorFromRGB(0xCC2A2E);
|
|
|
|
} else if (storyScore == 0) {
|
|
|
|
scoreColor = UIColorFromRGB(0xF9C72A);
|
2012-07-23 10:57:11 -07:00
|
|
|
} else {
|
2012-08-10 18:10:07 -07:00
|
|
|
scoreColor = UIColorFromRGB(0x3B7613);
|
2012-07-23 10:57:11 -07:00
|
|
|
}
|
2012-08-10 18:10:07 -07:00
|
|
|
CGContextSetFillColorWithColor(context, UIColorFromRGB(0xf4f4f4).CGColor);
|
2012-08-13 17:35:04 -07:00
|
|
|
CGContextFillEllipseInRect(context, CGRectMake(7, storyIndicatorY + 12, 12, 12));
|
2012-07-23 10:57:11 -07:00
|
|
|
|
2012-08-10 18:10:07 -07:00
|
|
|
if (self.isRead) {
|
|
|
|
CGContextSetAlpha(context, 0.25);
|
|
|
|
}
|
|
|
|
|
|
|
|
CGContextSetFillColorWithColor(context, scoreColor.CGColor);
|
2012-08-13 17:35:04 -07:00
|
|
|
CGContextFillEllipseInRect(context, CGRectMake(9, storyIndicatorY + 14, 8, 8));
|
2012-07-23 10:57:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (UIImage *)imageByApplyingAlpha:(UIImage *)image withAlpha:(CGFloat) alpha {
|
|
|
|
UIGraphicsBeginImageContextWithOptions(image.size, NO, 0.0f);
|
|
|
|
|
|
|
|
CGContextRef ctx = UIGraphicsGetCurrentContext();
|
|
|
|
CGRect area = CGRectMake(0, 0, image.size.width, image.size.height);
|
|
|
|
|
|
|
|
CGContextScaleCTM(ctx, 1, -1);
|
|
|
|
CGContextTranslateCTM(ctx, 0, -area.size.height);
|
|
|
|
|
|
|
|
CGContextSetBlendMode(ctx, kCGBlendModeMultiply);
|
|
|
|
|
|
|
|
CGContextSetAlpha(ctx, alpha);
|
|
|
|
|
|
|
|
CGContextDrawImage(ctx, area, image.CGImage);
|
|
|
|
|
|
|
|
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
|
|
|
|
|
|
|
|
UIGraphicsEndImageContext();
|
2012-07-22 17:08:29 -07:00
|
|
|
|
2012-07-23 10:57:11 -07:00
|
|
|
return newImage;
|
2012-07-22 17:08:29 -07:00
|
|
|
}
|
2010-07-15 00:44:38 -04:00
|
|
|
|
|
|
|
|
|
|
|
@end
|