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-07-01 12:08:30 -07:00
|
|
|
}
|
2012-06-29 10:20:06 -07:00
|
|
|
}
|
|
|
|
|
2013-09-30 12:13:10 -07:00
|
|
|
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
|
|
|
|
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
|
|
|
|
cellContent = [[FeedTableCellView alloc] initWithFrame:self.frame];
|
|
|
|
cellContent.opaque = YES;
|
|
|
|
[self.contentView addSubview:cellContent];
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)drawRect:(CGRect)rect {
|
|
|
|
((FeedTableCellView *)cellContent).cell = self;
|
|
|
|
cellContent.frame = rect;
|
|
|
|
[cellContent setNeedsDisplay];
|
2013-10-02 16:05:22 -07:00
|
|
|
[self setupGestures];
|
2013-09-30 12:13:10 -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;
|
2013-10-01 15:38:29 -07:00
|
|
|
// [cellContent 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;
|
2013-10-01 15:38:29 -07:00
|
|
|
// [cellContent 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];
|
2013-10-01 15:38:29 -07:00
|
|
|
// [cellContent setNeedsDisplay];
|
2012-06-29 10:20:06 -07:00
|
|
|
}
|
|
|
|
|
2013-09-27 17:54:06 -07:00
|
|
|
- (void)setupGestures {
|
2013-09-30 16:18:11 -07:00
|
|
|
appDelegate = [NewsBlurAppDelegate sharedAppDelegate];
|
2013-09-30 12:13:10 -07:00
|
|
|
[self setDelegate:(NewsBlurViewController <MCSwipeTableViewCellDelegate> *)appDelegate.feedsViewController];
|
2013-10-02 16:05:22 -07:00
|
|
|
[self setFirstStateIconName:self.isSocial ? @"menu_icn_fetch_subscribers.png" : @"train.png"
|
2013-10-01 15:38:29 -07:00
|
|
|
firstColor:UIColorFromRGB(0xA4D97B)
|
2013-09-27 17:54:06 -07:00
|
|
|
secondStateIconName:nil
|
|
|
|
secondColor:nil
|
2013-09-30 12:13:10 -07:00
|
|
|
thirdIconName:@"g_icn_unread.png"
|
2013-10-01 15:38:29 -07:00
|
|
|
thirdColor:UIColorFromRGB(0xFFFFD2)
|
2013-09-27 17:54:06 -07:00
|
|
|
fourthIconName:nil
|
|
|
|
fourthColor:nil];
|
|
|
|
|
|
|
|
self.mode = MCSwipeTableViewCellModeSwitch;
|
|
|
|
self.shouldAnimatesIcons = NO;
|
|
|
|
}
|
2012-06-29 10:20:06 -07:00
|
|
|
|
2013-09-27 17:54:06 -07:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation FeedTableCellView
|
|
|
|
|
|
|
|
@synthesize cell;
|
|
|
|
|
|
|
|
- (void)drawRect:(CGRect)r {
|
2012-07-01 12:08:30 -07:00
|
|
|
CGContextRef context = UIGraphicsGetCurrentContext();
|
|
|
|
|
|
|
|
UIColor *backgroundColor;
|
2012-06-29 10:20:06 -07:00
|
|
|
|
2013-09-27 17:54:06 -07:00
|
|
|
backgroundColor = cell.highlighted || cell.selected ?
|
2013-09-24 17:18:20 -07:00
|
|
|
UIColorFromRGB(0xFFFFD2) :
|
2013-09-27 17:54:06 -07:00
|
|
|
cell.isSocial ? UIColorFromRGB(0xE6ECE8) :
|
2013-02-14 15:36:21 -08:00
|
|
|
UIColorFromRGB(0xF7F8F5);
|
2012-07-20 19:55:38 -07:00
|
|
|
|
2012-07-01 12:08:30 -07:00
|
|
|
[backgroundColor set];
|
|
|
|
CGContextFillRect(context, r);
|
|
|
|
|
2013-09-27 17:54:06 -07:00
|
|
|
if (cell.highlighted || cell.selected) {
|
2013-09-24 17:18:20 -07:00
|
|
|
// [NewsBlurAppDelegate fillGradient:CGRectMake(r.origin.x, r.origin.y + 1, r.size.width, r.size.height - 1) startColor:UIColorFromRGB(0xFFFFD2) endColor:UIColorFromRGB(0xFDED8D)];
|
2013-02-14 15:36:21 -08:00
|
|
|
|
2012-07-30 16:19:06 -07:00
|
|
|
// top border
|
2013-02-14 15:36:21 -08:00
|
|
|
UIColor *highlightBorderColor = UIColorFromRGB(0xE3D0AE);
|
2013-09-30 10:26:19 -07:00
|
|
|
CGFloat lineWidth = 0.5f;
|
2013-02-14 15:36:21 -08:00
|
|
|
CGContextSetStrokeColor(context, CGColorGetComponents([highlightBorderColor CGColor]));
|
2013-09-30 10:26:19 -07:00
|
|
|
CGContextSetLineWidth(context, lineWidth);
|
2012-07-30 16:19:06 -07:00
|
|
|
CGContextBeginPath(context);
|
2013-09-30 10:26:19 -07:00
|
|
|
CGContextMoveToPoint(context, 0, lineWidth*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);
|
2013-09-30 10:26:19 -07:00
|
|
|
CGContextSetLineWidth(context, lineWidth);
|
|
|
|
CGContextMoveToPoint(context, 0, r.size.height - .5f*lineWidth);
|
|
|
|
CGContextAddLineToPoint(context, r.size.width, r.size.height - .5f*lineWidth);
|
2012-07-30 16:19:06 -07:00
|
|
|
CGContextStrokePath(context);
|
|
|
|
}
|
|
|
|
|
2012-10-03 18:27:21 -07:00
|
|
|
UnreadCountView *unreadCount = [UnreadCountView alloc];
|
2013-09-27 17:54:06 -07:00
|
|
|
unreadCount.appDelegate = cell.appDelegate;
|
|
|
|
[unreadCount drawInRect:r ps:cell.positiveCount nt:cell.neutralCount
|
|
|
|
listType:(cell.isSocial ? NBFeedListSocial : NBFeedListFeed)];
|
2012-06-29 10:20:06 -07:00
|
|
|
|
2013-09-27 17:54:06 -07:00
|
|
|
UIColor *textColor = cell.highlighted || cell.selected ?
|
2012-07-30 16:19:06 -07:00
|
|
|
[UIColor blackColor]:
|
2013-02-19 14:18:41 -08:00
|
|
|
UIColorFromRGB(0x3a3a3a);
|
2012-06-29 10:20:06 -07:00
|
|
|
UIFont *font;
|
2013-09-27 17:54:06 -07:00
|
|
|
if (cell.negativeCount || cell.neutralCount || cell.positiveCount) {
|
2012-06-29 10:20:06 -07:00
|
|
|
font = [UIFont fontWithName:@"HelveticaNeue-Bold" size:13.0];
|
|
|
|
} else {
|
|
|
|
font = [UIFont fontWithName:@"Helvetica" size:12.6];
|
|
|
|
}
|
2013-09-24 17:18:20 -07:00
|
|
|
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle defaultParagraphStyle] mutableCopy];
|
|
|
|
paragraphStyle.lineBreakMode = NSLineBreakByTruncatingTail;
|
|
|
|
paragraphStyle.alignment = NSTextAlignmentLeft;
|
|
|
|
|
2013-09-27 17:54:06 -07:00
|
|
|
if (cell.isSocial) {
|
2012-08-02 12:01:42 -07:00
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
2013-09-27 17:54:06 -07:00
|
|
|
[cell.feedFavicon drawInRect:CGRectMake(9.0, 2.0, 28.0, 28.0)];
|
|
|
|
[cell.feedTitle drawInRect:CGRectMake(46, 7, r.size.width - ([unreadCount offsetWidth] + 36) - 10 - 16, 20.0)
|
2013-09-24 17:18:20 -07:00
|
|
|
withAttributes:@{NSFontAttributeName: font,
|
2013-09-25 17:43:00 -07:00
|
|
|
NSForegroundColorAttributeName: textColor,
|
2013-09-24 17:18:20 -07:00
|
|
|
NSParagraphStyleAttributeName: paragraphStyle}];
|
2012-08-02 12:01:42 -07:00
|
|
|
} else {
|
2013-09-27 17:54:06 -07:00
|
|
|
[cell.feedFavicon drawInRect:CGRectMake(9.0, 3.0, 26.0, 26.0)];
|
|
|
|
[cell.feedTitle drawInRect:CGRectMake(42, 7, r.size.width - ([unreadCount offsetWidth] + 36) - 10 - 12, 20.0)
|
2013-09-24 17:18:20 -07:00
|
|
|
withAttributes:@{NSFontAttributeName: font,
|
2013-09-25 17:43:00 -07:00
|
|
|
NSForegroundColorAttributeName: textColor,
|
2013-09-24 17:18:20 -07:00
|
|
|
NSParagraphStyleAttributeName: paragraphStyle}];
|
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) {
|
2013-09-27 17:54:06 -07:00
|
|
|
[cell.feedFavicon drawInRect:CGRectMake(12.0, 7.0, 16.0, 16.0)];
|
|
|
|
[cell.feedTitle drawInRect:CGRectMake(36.0, 7.0, r.size.width - ([unreadCount offsetWidth] + 36) - 10, 20.0)
|
2013-09-24 17:18:20 -07:00
|
|
|
withAttributes:@{NSFontAttributeName: font,
|
2013-09-25 17:43:00 -07:00
|
|
|
NSForegroundColorAttributeName: textColor,
|
2013-09-24 17:18:20 -07:00
|
|
|
NSParagraphStyleAttributeName: paragraphStyle}];
|
2012-08-02 18:33:55 -07:00
|
|
|
} else {
|
2013-09-27 17:54:06 -07:00
|
|
|
[cell.feedFavicon drawInRect:CGRectMake(9.0, 7.0, 16.0, 16.0)];
|
|
|
|
[cell.feedTitle drawInRect:CGRectMake(34.0, 7.0, r.size.width - ([unreadCount offsetWidth] + 36) - 10, 20.0)
|
2013-09-24 17:18:20 -07:00
|
|
|
withAttributes:@{NSFontAttributeName: font,
|
2013-09-25 17:43:00 -07:00
|
|
|
NSForegroundColorAttributeName: textColor,
|
2013-09-24 17:18:20 -07:00
|
|
|
NSParagraphStyleAttributeName: paragraphStyle}];
|
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
|