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"
|
2015-03-03 15:57:08 -05:00
|
|
|
#import "MCSwipeTableViewCell.h"
|
2012-06-29 10:20:06 -07:00
|
|
|
|
|
|
|
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;
|
2014-05-20 12:58:04 -07:00
|
|
|
@synthesize isSaved;
|
2013-10-09 14:54:49 -07:00
|
|
|
@synthesize unreadCount;
|
2012-06-29 10:20:06 -07:00
|
|
|
|
|
|
|
+ (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]) {
|
2013-10-09 14:54:49 -07:00
|
|
|
appDelegate = [NewsBlurAppDelegate sharedAppDelegate];
|
|
|
|
|
|
|
|
unreadCount = [UnreadCountView alloc];
|
|
|
|
unreadCount.appDelegate = self.appDelegate;
|
|
|
|
self.unreadCount = unreadCount;
|
2014-09-26 18:35:40 -07:00
|
|
|
|
2013-09-30 12:13:10 -07:00
|
|
|
cellContent = [[FeedTableCellView alloc] initWithFrame:self.frame];
|
|
|
|
cellContent.opaque = YES;
|
2013-10-09 14:54:49 -07:00
|
|
|
|
2016-01-27 21:50:44 -08:00
|
|
|
// Clear out half pixel border on top and bottom that the draw code can't touch
|
|
|
|
UIView *selectedBackground = [[UIView alloc] init];
|
|
|
|
[selectedBackground setBackgroundColor:[UIColor clearColor]];
|
|
|
|
self.selectedBackgroundView = selectedBackground;
|
|
|
|
|
2013-09-30 12:13:10 -07:00
|
|
|
[self.contentView addSubview:cellContent];
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)drawRect:(CGRect)rect {
|
|
|
|
((FeedTableCellView *)cellContent).cell = self;
|
|
|
|
cellContent.frame = rect;
|
|
|
|
[cellContent setNeedsDisplay];
|
|
|
|
}
|
|
|
|
|
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 {
|
2014-05-20 12:58:04 -07:00
|
|
|
if (self.isSaved) {
|
|
|
|
self.shouldDrag = NO;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-11-24 16:41:41 -05:00
|
|
|
NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults];
|
|
|
|
BOOL isNotifications = [[preferences stringForKey:@"feed_swipe_left"]
|
|
|
|
isEqualToString:@"notifications"];
|
2013-09-30 12:13:10 -07:00
|
|
|
[self setDelegate:(NewsBlurViewController <MCSwipeTableViewCellDelegate> *)appDelegate.feedsViewController];
|
2016-11-24 16:41:41 -05:00
|
|
|
[self setFirstStateIconName:(self.isSocial ? @"menu_icn_fetch_subscribers.png" :
|
|
|
|
isNotifications ? @"menu_icn_notifications.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-10-17 17:23:52 -07:00
|
|
|
- (void)redrawUnreadCounts {
|
|
|
|
[((FeedTableCellView *)cellContent) redrawUnreadCounts];
|
|
|
|
}
|
|
|
|
|
2014-09-26 18:35:40 -07:00
|
|
|
|
|
|
|
- (UIFontDescriptor *)fontDescriptorUsingPreferredSize:(NSString *)textStyle {
|
2014-10-01 14:23:57 -07:00
|
|
|
UIFontDescriptor *fontDescriptor = appDelegate.fontDescriptorTitleSize;
|
|
|
|
if (fontDescriptor) return fontDescriptor;
|
2014-09-26 18:35:40 -07:00
|
|
|
NSUserDefaults *userPreferences = [NSUserDefaults standardUserDefaults];
|
|
|
|
|
2014-10-01 14:23:57 -07:00
|
|
|
fontDescriptor = [UIFontDescriptor preferredFontDescriptorWithTextStyle:textStyle];
|
2014-09-26 18:35:40 -07:00
|
|
|
if (![userPreferences boolForKey:@"use_system_font_size"]) {
|
|
|
|
if ([[userPreferences stringForKey:@"feed_list_font_size"] isEqualToString:@"xs"]) {
|
2014-10-01 14:23:57 -07:00
|
|
|
fontDescriptor = [fontDescriptor fontDescriptorWithSize:11.0f];
|
2014-09-26 18:35:40 -07:00
|
|
|
} else if ([[userPreferences stringForKey:@"feed_list_font_size"] isEqualToString:@"small"]) {
|
2014-10-01 14:23:57 -07:00
|
|
|
fontDescriptor = [fontDescriptor fontDescriptorWithSize:12.0f];
|
2014-09-26 18:35:40 -07:00
|
|
|
} else if ([[userPreferences stringForKey:@"feed_list_font_size"] isEqualToString:@"medium"]) {
|
2014-10-01 14:23:57 -07:00
|
|
|
fontDescriptor = [fontDescriptor fontDescriptorWithSize:13.0f];
|
2014-09-26 18:35:40 -07:00
|
|
|
} else if ([[userPreferences stringForKey:@"feed_list_font_size"] isEqualToString:@"large"]) {
|
2015-09-22 13:10:35 -07:00
|
|
|
fontDescriptor = [fontDescriptor fontDescriptorWithSize:15.0f];
|
2014-09-26 18:35:40 -07:00
|
|
|
} else if ([[userPreferences stringForKey:@"feed_list_font_size"] isEqualToString:@"xl"]) {
|
2015-09-22 13:10:35 -07:00
|
|
|
fontDescriptor = [fontDescriptor fontDescriptorWithSize:17.0f];
|
2014-09-26 18:35:40 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-01 14:23:57 -07:00
|
|
|
return fontDescriptor;
|
2014-09-26 18:35:40 -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 ?
|
2019-10-22 21:14:15 -07:00
|
|
|
UIColorFromLightSepiaMediumDarkRGB(0xFFFFD2, 0xFFFFD2, 0x304050, 0x000022) :
|
2013-09-27 17:54:06 -07:00
|
|
|
cell.isSocial ? UIColorFromRGB(0xE6ECE8) :
|
2014-05-21 12:24:22 -07:00
|
|
|
cell.isSaved ? UIColorFromRGB(0xE9EBEE) :
|
2013-02-14 15:36:21 -08:00
|
|
|
UIColorFromRGB(0xF7F8F5);
|
2012-07-20 19:55:38 -07:00
|
|
|
|
2017-09-27 12:19:58 -07:00
|
|
|
// [backgroundColor set];
|
|
|
|
self.backgroundColor = backgroundColor;
|
|
|
|
cell.backgroundColor = backgroundColor;
|
2018-08-29 14:55:37 -07:00
|
|
|
|
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
|
2016-01-27 21:50:44 -08:00
|
|
|
UIColor *highlightBorderColor = UIColorFromLightDarkRGB(0xE3D0AE, 0x1F1F72);
|
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);
|
|
|
|
}
|
2016-03-26 21:27:25 -07:00
|
|
|
|
|
|
|
if (cell.savedStoriesCount > 0) {
|
|
|
|
[cell.unreadCount drawInRect:r ps:cell.savedStoriesCount nt:0 listType:NBFeedListSaved];
|
|
|
|
} else {
|
|
|
|
[cell.unreadCount drawInRect:r ps:cell.positiveCount nt:cell.neutralCount
|
2014-05-20 12:58:04 -07:00
|
|
|
listType:(cell.isSocial ? NBFeedListSocial : cell.isSaved ? NBFeedListSaved : NBFeedListFeed)];
|
2016-03-26 21:27:25 -07:00
|
|
|
}
|
2012-06-29 10:20:06 -07:00
|
|
|
|
2013-09-27 17:54:06 -07:00
|
|
|
UIColor *textColor = cell.highlighted || cell.selected ?
|
2015-12-07 16:09:49 -08:00
|
|
|
UIColorFromRGB(NEWSBLUR_BLACK_COLOR):
|
2016-01-27 21:50:44 -08:00
|
|
|
UIColorFromRGB(0x3A3A3A);
|
2012-06-29 10:20:06 -07:00
|
|
|
UIFont *font;
|
2014-09-26 18:35:40 -07:00
|
|
|
UIFontDescriptor *fontDescriptor = [cell fontDescriptorUsingPreferredSize:UIFontTextStyleFootnote];
|
2013-09-27 17:54:06 -07:00
|
|
|
if (cell.negativeCount || cell.neutralCount || cell.positiveCount) {
|
2013-11-23 13:03:14 -08:00
|
|
|
UIFontDescriptor *boldFontDescriptor = [fontDescriptor fontDescriptorWithSymbolicTraits:UIFontDescriptorTraitBold];
|
2016-09-13 16:28:19 -07:00
|
|
|
font = [UIFont fontWithDescriptor:boldFontDescriptor size:fontDescriptor.pointSize];
|
2012-06-29 10:20:06 -07:00
|
|
|
} else {
|
2013-10-17 18:56:14 -07:00
|
|
|
font = [UIFont fontWithDescriptor:fontDescriptor size:0.0];
|
2012-06-29 10:20:06 -07:00
|
|
|
}
|
2017-10-04 16:34:30 -07:00
|
|
|
NSInteger titleOffsetY = ((r.size.height - font.pointSize) / 2) - 1;
|
2013-09-24 17:18:20 -07:00
|
|
|
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle defaultParagraphStyle] mutableCopy];
|
|
|
|
paragraphStyle.lineBreakMode = NSLineBreakByTruncatingTail;
|
|
|
|
paragraphStyle.alignment = NSTextAlignmentLeft;
|
2017-10-04 16:34:30 -07:00
|
|
|
NSInteger faviconSize;
|
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) {
|
2017-10-04 16:34:30 -07:00
|
|
|
faviconSize = 28;
|
|
|
|
[cell.feedFavicon drawInRect:CGRectMake(9.0, CGRectGetMidY(r)-faviconSize/2, faviconSize, faviconSize)];
|
2013-10-17 18:56:14 -07:00
|
|
|
[cell.feedTitle drawInRect:CGRectMake(46, titleOffsetY, r.size.width - ([cell.unreadCount offsetWidth] + 36) - 10 - 16, font.pointSize*1.4)
|
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 {
|
2017-10-04 16:34:30 -07:00
|
|
|
faviconSize = 26;
|
|
|
|
[cell.feedFavicon drawInRect:CGRectMake(9.0, CGRectGetMidY(r)-faviconSize/2, faviconSize, faviconSize)];
|
2013-10-17 18:56:14 -07:00
|
|
|
[cell.feedTitle drawInRect:CGRectMake(42, titleOffsetY, r.size.width - ([cell.unreadCount offsetWidth] + 36) - 10 - 12, font.pointSize*1.4)
|
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 {
|
2017-10-04 16:34:30 -07:00
|
|
|
faviconSize = 16;
|
2012-08-02 18:33:55 -07:00
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
2017-10-04 16:34:30 -07:00
|
|
|
[cell.feedFavicon drawInRect:CGRectMake(12.0, CGRectGetMidY(r)-faviconSize/2, faviconSize, faviconSize)];
|
2013-10-17 18:56:14 -07:00
|
|
|
[cell.feedTitle drawInRect:CGRectMake(36.0, titleOffsetY, r.size.width - ([cell.unreadCount offsetWidth] + 36) - 10, font.pointSize*1.4)
|
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 {
|
2017-10-04 16:34:30 -07:00
|
|
|
[cell.feedFavicon drawInRect:CGRectMake(9.0, CGRectGetMidY(r)-faviconSize/2, faviconSize, faviconSize)];
|
2013-10-17 18:56:14 -07:00
|
|
|
[cell.feedTitle drawInRect:CGRectMake(34.0, titleOffsetY, r.size.width - ([cell.unreadCount offsetWidth] + 36) - 10, font.pointSize*1.4)
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-17 17:23:52 -07:00
|
|
|
- (void)redrawUnreadCounts {
|
2016-03-26 21:27:25 -07:00
|
|
|
if (cell.savedStoriesCount) {
|
|
|
|
cell.unreadCount.blueCount = cell.savedStoriesCount;
|
|
|
|
} else if (cell.isSaved) {
|
2014-05-20 13:12:03 -07:00
|
|
|
cell.unreadCount.blueCount = cell.positiveCount;
|
|
|
|
} else {
|
|
|
|
cell.unreadCount.psCount = cell.positiveCount;
|
|
|
|
cell.unreadCount.ntCount = cell.neutralCount;
|
|
|
|
}
|
2013-10-17 17:23:52 -07:00
|
|
|
[cell.unreadCount setNeedsLayout];
|
|
|
|
}
|
2012-06-29 10:20:06 -07:00
|
|
|
|
2016-09-13 16:28:19 -07:00
|
|
|
@end
|