2012-06-29 10:20:06 -07:00
|
|
|
//
|
|
|
|
// FeedTableCell.m
|
|
|
|
// NewsBlur
|
|
|
|
//
|
|
|
|
// Created by Samuel Clay on 7/18/11.
|
|
|
|
// Copyright 2011 NewsBlur. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "NewsBlurAppDelegate.h"
|
|
|
|
#import "FeedTableCell.h"
|
2012-10-03 18:27:21 -07:00
|
|
|
#import "UnreadCountView.h"
|
2012-06-29 10:20:06 -07:00
|
|
|
#import "ABTableViewCell.h"
|
|
|
|
|
|
|
|
static UIFont *textFont = nil;
|
|
|
|
|
|
|
|
@implementation FeedTableCell
|
|
|
|
|
|
|
|
@synthesize appDelegate;
|
|
|
|
@synthesize feedTitle;
|
|
|
|
@synthesize feedFavicon;
|
|
|
|
@synthesize positiveCount = _positiveCount;
|
|
|
|
@synthesize neutralCount = _neutralCount;
|
|
|
|
@synthesize negativeCount = _negativeCount;
|
|
|
|
@synthesize negativeCountStr;
|
|
|
|
@synthesize isSocial;
|
|
|
|
|
|
|
|
+ (void) initialize{
|
2012-07-01 12:08:30 -07:00
|
|
|
if (self == [FeedTableCell class]) {
|
2012-07-15 15:06:06 -07:00
|
|
|
textFont = [UIFont boldSystemFontOfSize:18];
|
2012-06-29 10:20:06 -07:00
|
|
|
// UIColor *psGrad = UIColorFromRGB(0x559F4D);
|
|
|
|
// UIColor *ntGrad = UIColorFromRGB(0xE4AB00);
|
|
|
|
// UIColor *ngGrad = UIColorFromRGB(0x9B181B);
|
|
|
|
// const CGFloat* psTop = CGColorGetComponents(ps.CGColor);
|
|
|
|
// const CGFloat* psBot = CGColorGetComponents(psGrad.CGColor);
|
|
|
|
// CGFloat psGradient[] = {
|
|
|
|
// psTop[0], psTop[1], psTop[2], psTop[3],
|
|
|
|
// psBot[0], psBot[1], psBot[2], psBot[3]
|
|
|
|
// };
|
|
|
|
// psColors = psGradient;
|
2012-07-01 12:08:30 -07:00
|
|
|
}
|
2012-06-29 10:20:06 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-01 12:08:30 -07:00
|
|
|
- (void) setPositiveCount:(int)ps {
|
|
|
|
if (ps == _positiveCount) return;
|
2012-06-29 10:20:06 -07:00
|
|
|
|
2012-07-01 12:08:30 -07:00
|
|
|
_positiveCount = ps;
|
|
|
|
[self setNeedsDisplay];
|
2012-06-29 10:20:06 -07:00
|
|
|
}
|
|
|
|
|
2012-07-01 12:08:30 -07:00
|
|
|
- (void) setNeutralCount:(int)nt {
|
|
|
|
if (nt == _neutralCount) return;
|
2012-06-29 10:20:06 -07:00
|
|
|
|
2012-07-01 12:08:30 -07:00
|
|
|
_neutralCount = nt;
|
|
|
|
[self setNeedsDisplay];
|
2012-06-29 10:20:06 -07:00
|
|
|
}
|
|
|
|
|
2012-07-01 12:08:30 -07:00
|
|
|
- (void) setNegativeCount:(int)ng {
|
|
|
|
if (ng == _negativeCount) return;
|
2012-06-29 10:20:06 -07:00
|
|
|
|
2012-07-01 12:08:30 -07:00
|
|
|
_negativeCount = ng;
|
2012-07-15 15:06:06 -07:00
|
|
|
_negativeCountStr = [NSString stringWithFormat:@"%d", ng];
|
2012-07-01 12:08:30 -07:00
|
|
|
[self setNeedsDisplay];
|
2012-06-29 10:20:06 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void) drawContentView:(CGRect)r highlighted:(BOOL)highlighted {
|
|
|
|
|
2012-07-01 12:08:30 -07:00
|
|
|
CGContextRef context = UIGraphicsGetCurrentContext();
|
|
|
|
|
|
|
|
UIColor *backgroundColor;
|
2012-06-29 10:20:06 -07:00
|
|
|
|
2012-10-04 15:44:25 -07:00
|
|
|
backgroundColor = highlighted ?
|
2012-08-10 09:45:44 -07:00
|
|
|
UIColorFromRGB(NEWSBLUR_HIGHLIGHT_COLOR) :
|
2013-02-14 15:36:21 -08:00
|
|
|
self.isSocial ? UIColorFromRGB(0xE6ECE8) :
|
|
|
|
UIColorFromRGB(0xF7F8F5);
|
2012-07-20 19:55:38 -07:00
|
|
|
|
2012-07-01 12:08:30 -07:00
|
|
|
[backgroundColor set];
|
|
|
|
CGContextFillRect(context, r);
|
|
|
|
|
2012-10-04 15:44:25 -07:00
|
|
|
if (highlighted) {
|
2013-02-14 15:36:21 -08:00
|
|
|
[NewsBlurAppDelegate fillGradient:r startColor:UIColorFromRGB(0xFFFFD2) endColor:UIColorFromRGB(0xFDED8D)];
|
|
|
|
|
2012-07-30 16:19:06 -07:00
|
|
|
// top border
|
2013-02-14 15:36:21 -08:00
|
|
|
UIColor *highlightBorderColor = UIColorFromRGB(0xE3D0AE);
|
|
|
|
CGContextSetStrokeColor(context, CGColorGetComponents([highlightBorderColor CGColor]));
|
2012-07-30 16:19:06 -07:00
|
|
|
|
|
|
|
CGContextBeginPath(context);
|
|
|
|
CGContextMoveToPoint(context, 0, 0.5f);
|
2012-10-15 14:57:20 -07:00
|
|
|
CGContextAddLineToPoint(context, r.size.width, 0.5f);
|
2012-07-30 16:19:06 -07:00
|
|
|
CGContextStrokePath(context);
|
|
|
|
|
|
|
|
// bottom border
|
|
|
|
CGContextBeginPath(context);
|
2012-10-15 14:57:20 -07:00
|
|
|
CGContextMoveToPoint(context, 0, r.size.height - .5f);
|
|
|
|
CGContextAddLineToPoint(context, r.size.width, r.size.height - .5f);
|
2012-07-30 16:19:06 -07:00
|
|
|
CGContextStrokePath(context);
|
|
|
|
}
|
|
|
|
|
2012-10-03 18:27:21 -07:00
|
|
|
UnreadCountView *unreadCount = [UnreadCountView alloc];
|
2012-10-07 15:47:21 -04:00
|
|
|
unreadCount.appDelegate = appDelegate;
|
2012-10-03 18:27:21 -07:00
|
|
|
[unreadCount drawInRect:r ps:_positiveCount nt:_neutralCount
|
|
|
|
listType:(isSocial ? NBFeedListSocial : NBFeedListFeed)];
|
2012-06-29 10:20:06 -07:00
|
|
|
|
2012-10-04 15:44:25 -07:00
|
|
|
UIColor *textColor = highlighted ?
|
2012-07-30 16:19:06 -07:00
|
|
|
[UIColor blackColor]:
|
2013-02-19 14:18:41 -08:00
|
|
|
UIColorFromRGB(0x3a3a3a);
|
2012-08-02 12:01:42 -07:00
|
|
|
|
2012-06-29 10:20:06 -07:00
|
|
|
[textColor set];
|
|
|
|
UIFont *font;
|
|
|
|
if (self.negativeCount || self.neutralCount || self.positiveCount) {
|
|
|
|
font = [UIFont fontWithName:@"HelveticaNeue-Bold" size:13.0];
|
|
|
|
} else {
|
|
|
|
font = [UIFont fontWithName:@"Helvetica" size:12.6];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isSocial) {
|
2012-08-02 12:01:42 -07:00
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
2012-11-28 12:36:48 -08:00
|
|
|
[self.feedFavicon drawInRect:CGRectMake(9.0, 2.0, 28.0, 28.0)];
|
2012-08-02 12:01:42 -07:00
|
|
|
[feedTitle
|
2012-11-28 12:36:48 -08:00
|
|
|
drawInRect:CGRectMake(46, 7, r.size.width - ([unreadCount offsetWidth] + 36) - 10 - 16, 20.0)
|
2012-08-02 12:01:42 -07:00
|
|
|
withFont:font
|
2013-06-17 11:50:13 -07:00
|
|
|
lineBreakMode:NSLineBreakByTruncatingTail
|
|
|
|
alignment:NSTextAlignmentLeft];
|
2012-08-02 12:01:42 -07:00
|
|
|
} else {
|
2012-11-28 12:36:48 -08:00
|
|
|
[self.feedFavicon drawInRect:CGRectMake(9.0, 3.0, 26.0, 26.0)];
|
2012-08-02 12:01:42 -07:00
|
|
|
[feedTitle
|
2012-11-28 12:36:48 -08:00
|
|
|
drawInRect:CGRectMake(42, 7, r.size.width - ([unreadCount offsetWidth] + 36) - 10 - 12, 20.0)
|
2012-08-02 12:01:42 -07:00
|
|
|
withFont:font
|
2013-06-17 11:50:13 -07:00
|
|
|
lineBreakMode:NSLineBreakByTruncatingTail
|
|
|
|
alignment:NSTextAlignmentLeft];
|
2012-08-02 12:01:42 -07:00
|
|
|
}
|
|
|
|
|
2012-06-29 10:20:06 -07:00
|
|
|
} else {
|
2012-08-02 18:33:55 -07:00
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
2012-10-03 15:46:02 -07:00
|
|
|
[self.feedFavicon drawInRect:CGRectMake(12.0, 7.0, 16.0, 16.0)];
|
2012-08-02 18:33:55 -07:00
|
|
|
[feedTitle
|
2012-10-07 15:47:21 -04:00
|
|
|
drawInRect:CGRectMake(36.0, 7.0, r.size.width - ([unreadCount offsetWidth] + 36) - 10, 20.0)
|
2012-08-02 18:33:55 -07:00
|
|
|
withFont:font
|
2013-06-17 11:50:13 -07:00
|
|
|
lineBreakMode:NSLineBreakByTruncatingTail
|
|
|
|
alignment:NSTextAlignmentLeft];
|
2012-08-02 18:33:55 -07:00
|
|
|
} else {
|
2012-10-03 15:46:02 -07:00
|
|
|
[self.feedFavicon drawInRect:CGRectMake(9.0, 7.0, 16.0, 16.0)];
|
2012-08-02 18:33:55 -07:00
|
|
|
[feedTitle
|
2012-10-07 15:47:21 -04:00
|
|
|
drawInRect:CGRectMake(34.0, 7.0, r.size.width - ([unreadCount offsetWidth] + 36) - 10, 20.0)
|
2012-08-02 18:33:55 -07:00
|
|
|
withFont:font
|
2013-06-17 11:50:13 -07:00
|
|
|
lineBreakMode:NSLineBreakByTruncatingTail
|
|
|
|
alignment:NSTextAlignmentLeft];
|
2012-08-02 18:33:55 -07:00
|
|
|
}
|
2012-06-29 10:20:06 -07:00
|
|
|
}
|
2012-08-02 18:33:55 -07:00
|
|
|
|
2012-06-29 10:20:06 -07:00
|
|
|
}
|
|
|
|
|
2012-07-02 10:45:25 -07:00
|
|
|
|
2012-06-29 10:20:06 -07:00
|
|
|
|
2012-07-01 12:08:30 -07:00
|
|
|
@end
|