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"
|
2014-02-11 11:52:32 -08:00
|
|
|
#import "FeedDetailViewController.h"
|
2010-07-15 00:44:38 -04:00
|
|
|
#import "FeedDetailTableCell.h"
|
2014-02-20 18:23:58 -08:00
|
|
|
#import "DashboardViewController.h"
|
2012-07-22 17:08:29 -07:00
|
|
|
#import "ABTableViewCell.h"
|
|
|
|
#import "UIView+TKCategory.h"
|
2014-02-10 19:21:53 -08:00
|
|
|
#import "UIImageView+AFNetworking.h"
|
2012-07-22 17:08:29 -07:00
|
|
|
#import "Utilities.h"
|
2013-09-27 17:23:03 -07:00
|
|
|
#import "MCSwipeTableViewCell.h"
|
2017-04-03 18:52:23 -07:00
|
|
|
#import "PINCache.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
|
|
|
|
2013-09-27 17:23:03 -07:00
|
|
|
@class FeedDetailViewController;
|
2012-07-23 10:57:11 -07:00
|
|
|
|
2010-07-15 00:44:38 -04:00
|
|
|
@implementation FeedDetailTableCell
|
|
|
|
|
|
|
|
@synthesize storyTitle;
|
|
|
|
@synthesize storyAuthor;
|
|
|
|
@synthesize storyDate;
|
2014-02-10 19:21:53 -08:00
|
|
|
@synthesize storyContent;
|
|
|
|
@synthesize storyImageUrl;
|
2013-10-10 12:58:40 -07:00
|
|
|
@synthesize storyTimestamp;
|
2012-08-10 18:10:07 -07:00
|
|
|
@synthesize storyScore;
|
2014-02-10 19:21:53 -08:00
|
|
|
@synthesize storyImage;
|
2012-07-22 14:23:50 -07:00
|
|
|
@synthesize siteTitle;
|
|
|
|
@synthesize siteFavicon;
|
2012-07-22 17:08:29 -07:00
|
|
|
@synthesize isRead;
|
2013-08-05 18:32:43 -07:00
|
|
|
@synthesize isShared;
|
2014-05-20 12:58:04 -07:00
|
|
|
@synthesize isSaved;
|
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;
|
2014-02-11 11:52:32 -08:00
|
|
|
@synthesize inDashboard;
|
2010-07-15 00:44:38 -04:00
|
|
|
|
2012-08-09 11:06:38 -07:00
|
|
|
|
2013-02-21 12:19:15 -08:00
|
|
|
#define leftMargin 30
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-30 12:13:10 -07:00
|
|
|
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
|
|
|
|
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
|
|
|
|
cellContent = [[FeedDetailTableCellView alloc] initWithFrame:self.frame];
|
|
|
|
cellContent.opaque = YES;
|
2015-11-03 17:52:21 -08:00
|
|
|
self.isReadAvailable = YES;
|
|
|
|
|
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 {
|
|
|
|
((FeedDetailTableCellView *)cellContent).cell = self;
|
2014-02-10 19:21:53 -08:00
|
|
|
((FeedDetailTableCellView *)cellContent).storyImage = nil;
|
2014-02-11 11:52:32 -08:00
|
|
|
((FeedDetailTableCellView *)cellContent).appDelegate = (NewsBlurAppDelegate *)[[UIApplication sharedApplication] delegate];
|
2013-09-30 12:13:10 -07:00
|
|
|
cellContent.frame = rect;
|
|
|
|
[cellContent setNeedsDisplay];
|
|
|
|
}
|
|
|
|
|
2015-11-03 22:21:18 -08:00
|
|
|
- (NSString *)accessibilityLabel {
|
|
|
|
NSMutableString *output = [NSMutableString stringWithString:self.siteTitle];
|
|
|
|
|
|
|
|
[output appendFormat:@", \"%@\"", self.storyTitle];
|
|
|
|
|
|
|
|
if (self.storyAuthor.length) {
|
|
|
|
[output appendFormat:@", by %@", self.storyAuthor];
|
|
|
|
}
|
|
|
|
|
|
|
|
[output appendFormat:@", at %@", self.storyDate];
|
|
|
|
[output appendFormat:@". %@", self.storyContent];
|
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
2013-09-27 17:23:03 -07:00
|
|
|
- (void)setupGestures {
|
|
|
|
NSString *unreadIcon;
|
|
|
|
if (storyScore == -1) {
|
|
|
|
unreadIcon = @"g_icn_hidden.png";
|
|
|
|
} else if (storyScore == 1) {
|
|
|
|
unreadIcon = @"g_icn_focus.png";
|
|
|
|
} else {
|
|
|
|
unreadIcon = @"g_icn_unread.png";
|
|
|
|
}
|
2013-10-01 15:38:29 -07:00
|
|
|
|
2014-05-20 12:58:04 -07:00
|
|
|
UIColor *shareColor = self.isSaved ?
|
2013-10-01 15:38:29 -07:00
|
|
|
UIColorFromRGB(0xF69E89) :
|
|
|
|
UIColorFromRGB(0xA4D97B);
|
|
|
|
UIColor *readColor = self.isRead ?
|
|
|
|
UIColorFromRGB(0xBED49F) :
|
|
|
|
UIColorFromRGB(0xFFFFD2);
|
|
|
|
|
2015-11-03 17:52:21 -08:00
|
|
|
if (!self.isReadAvailable) {
|
|
|
|
unreadIcon = nil;
|
|
|
|
readColor = nil;
|
|
|
|
}
|
|
|
|
|
2013-09-27 17:23:03 -07:00
|
|
|
appDelegate = [NewsBlurAppDelegate sharedAppDelegate];
|
2014-02-20 18:23:58 -08:00
|
|
|
if (inDashboard) {
|
|
|
|
[self setDelegate:(FeedDetailViewController <MCSwipeTableViewCellDelegate> *)appDelegate.dashboardViewController.storiesModule];
|
|
|
|
} else {
|
|
|
|
[self setDelegate:(FeedDetailViewController <MCSwipeTableViewCellDelegate> *)appDelegate.feedDetailViewController];
|
|
|
|
}
|
2013-09-27 17:23:03 -07:00
|
|
|
[self setFirstStateIconName:@"clock.png"
|
2013-10-01 15:38:29 -07:00
|
|
|
firstColor:shareColor
|
2013-09-27 17:23:03 -07:00
|
|
|
secondStateIconName:nil
|
|
|
|
secondColor:nil
|
|
|
|
thirdIconName:unreadIcon
|
2013-10-01 15:38:29 -07:00
|
|
|
thirdColor:readColor
|
2013-09-27 17:23:03 -07:00
|
|
|
fourthIconName:nil
|
|
|
|
fourthColor:nil];
|
2013-10-01 15:38:29 -07:00
|
|
|
|
2013-09-27 17:23:03 -07:00
|
|
|
self.mode = MCSwipeTableViewCellModeSwitch;
|
|
|
|
self.shouldAnimatesIcons = NO;
|
|
|
|
}
|
|
|
|
|
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:23:03 -07:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation FeedDetailTableCellView
|
|
|
|
|
|
|
|
@synthesize cell;
|
2014-02-10 19:21:53 -08:00
|
|
|
@synthesize storyImage;
|
2014-02-11 11:52:32 -08:00
|
|
|
@synthesize appDelegate;
|
2012-07-22 17:08:29 -07:00
|
|
|
|
2013-09-27 17:23:03 -07:00
|
|
|
- (void)drawRect:(CGRect)r {
|
2015-11-28 22:07:38 -08:00
|
|
|
if (!cell) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-10-17 18:56:14 -07:00
|
|
|
int riverPadding = 0;
|
2013-09-27 17:23:03 -07:00
|
|
|
if (cell.isRiverOrSocial) {
|
2013-10-17 18:56:14 -07:00
|
|
|
riverPadding = 20;
|
2013-09-27 17:23:03 -07:00
|
|
|
}
|
2014-02-25 15:29:05 -08:00
|
|
|
|
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
|
2018-11-12 20:27:46 -08:00
|
|
|
CGRect dateRect = rect;
|
2013-02-14 15:36:21 -08:00
|
|
|
|
2013-09-24 17:18:20 -07:00
|
|
|
UIColor *backgroundColor;
|
2013-09-27 17:23:03 -07:00
|
|
|
backgroundColor = cell.highlighted || cell.selected ?
|
2016-01-27 21:50:44 -08:00
|
|
|
UIColorFromLightSepiaMediumDarkRGB(0xFFFDEF, 0xFFFDEF, 0x808A90, 0x0F0F22) : UIColorFromRGB(0xf4f4f4);
|
2013-09-24 17:18:20 -07:00
|
|
|
[backgroundColor set];
|
2012-07-22 17:08:29 -07:00
|
|
|
|
|
|
|
CGContextFillRect(context, r);
|
2013-02-14 15:36:21 -08:00
|
|
|
|
2014-02-10 19:21:53 -08:00
|
|
|
if (cell.storyImageUrl) {
|
2018-11-12 20:27:46 -08:00
|
|
|
NSString *preview = [[NSUserDefaults standardUserDefaults] stringForKey:@"story_list_preview_images_size"];
|
|
|
|
BOOL isSmall = [preview isEqualToString:@"small"];
|
|
|
|
CGFloat previewOffset = isSmall ? 60 : 0;
|
|
|
|
CGFloat previewMargin = isSmall ? 10 : 0;
|
|
|
|
|
|
|
|
CGRect imageFrame = CGRectMake(r.size.width - r.size.height + previewOffset - previewMargin, (previewOffset / 2.0) + 1.0,
|
|
|
|
r.size.height - previewOffset, r.size.height - previewOffset);
|
2014-02-10 19:21:53 -08:00
|
|
|
UIImageView *storyImageView = [[UIImageView alloc] initWithFrame:imageFrame];
|
|
|
|
|
2014-02-24 18:56:51 -08:00
|
|
|
UIImage *cachedImage = (UIImage *)[appDelegate.cachedStoryImages objectForKey:cell.storyImageUrl];
|
2014-02-10 19:21:53 -08:00
|
|
|
if (cachedImage && ![cachedImage isKindOfClass:[NSNull class]]) {
|
2014-02-12 15:48:16 -08:00
|
|
|
// NSLog(@"Found cached image: %@", cell.storyTitle);
|
2014-02-10 19:21:53 -08:00
|
|
|
storyImageView.image = cachedImage;
|
|
|
|
[storyImageView setContentMode:UIViewContentModeScaleAspectFill];
|
|
|
|
[storyImageView setClipsToBounds:YES];
|
2014-02-11 13:23:45 -08:00
|
|
|
CGFloat alpha = 1.0f;
|
|
|
|
if (cell.highlighted || cell.selected) {
|
2014-02-11 16:00:31 -08:00
|
|
|
alpha = cell.isRead ? 0.5f : 0.85f;
|
2014-02-11 13:23:45 -08:00
|
|
|
} else if (cell.isRead) {
|
2014-02-11 15:20:41 -08:00
|
|
|
alpha = 0.34f;
|
2014-02-11 13:23:45 -08:00
|
|
|
}
|
2016-10-05 21:03:32 -07:00
|
|
|
[storyImageView.image drawInRect:imageFrame blendMode:0 alpha:alpha];
|
2014-05-20 15:29:16 -07:00
|
|
|
rect.size.width -= imageFrame.size.width;
|
2018-11-12 20:27:46 -08:00
|
|
|
|
|
|
|
if (!isSmall) {
|
|
|
|
dateRect = rect;
|
|
|
|
}
|
2014-02-10 19:21:53 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-22 17:08:29 -07:00
|
|
|
UIColor *textColor;
|
|
|
|
UIFont *font;
|
2014-09-26 18:35:40 -07:00
|
|
|
UIFontDescriptor *fontDescriptor = [cell fontDescriptorUsingPreferredSize:UIFontTextStyleCaption1];
|
2013-09-27 17:23:03 -07:00
|
|
|
|
2013-09-25 17:43:00 -07:00
|
|
|
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle defaultParagraphStyle] mutableCopy];
|
2013-10-01 14:44:13 -07:00
|
|
|
paragraphStyle.lineBreakMode = NSLineBreakByWordWrapping;
|
2013-09-25 17:43:00 -07:00
|
|
|
paragraphStyle.alignment = NSTextAlignmentLeft;
|
2014-10-01 14:54:06 -07:00
|
|
|
paragraphStyle.lineHeightMultiple = 0.95f;
|
2013-10-17 18:56:14 -07:00
|
|
|
|
2013-09-27 17:23:03 -07:00
|
|
|
if (cell.isRiverOrSocial) {
|
2016-01-27 21:50:44 -08:00
|
|
|
if (cell.isRead) {
|
|
|
|
font = [UIFont fontWithDescriptor:fontDescriptor size:0.0];
|
|
|
|
textColor = UIColorFromLightSepiaMediumDarkRGB(0x808080, 0x808080, 0xB0B0B0, 0x707070);
|
|
|
|
} else {
|
|
|
|
UIFontDescriptor *boldFontDescriptor = [fontDescriptor fontDescriptorWithSymbolicTraits: UIFontDescriptorTraitBold];
|
2016-09-13 16:28:19 -07:00
|
|
|
font = [UIFont fontWithDescriptor: boldFontDescriptor size:fontDescriptor.pointSize];
|
2016-01-27 21:50:44 -08:00
|
|
|
textColor = UIColorFromLightSepiaMediumDarkRGB(0x606060, 0x606060, 0xD0D0D0, 0x909090);
|
|
|
|
|
|
|
|
}
|
|
|
|
if (cell.highlighted || cell.selected) {
|
|
|
|
textColor = UIColorFromLightSepiaMediumDarkRGB(0x686868, 0x686868, 0xA0A0A0, 0x808080);
|
|
|
|
}
|
|
|
|
|
2013-10-17 18:56:14 -07:00
|
|
|
NSInteger siteTitleY = (20 - font.pointSize/2)/2;
|
|
|
|
[cell.siteTitle drawInRect:CGRectMake(leftMargin + 20, siteTitleY, rect.size.width - 20, 20)
|
2013-09-25 17:43:00 -07:00
|
|
|
withAttributes:@{NSFontAttributeName: font,
|
|
|
|
NSForegroundColorAttributeName: textColor,
|
|
|
|
NSParagraphStyleAttributeName: paragraphStyle}];
|
2014-01-17 16:23:12 -08:00
|
|
|
|
|
|
|
// site favicon
|
|
|
|
if (cell.isRead && !cell.hasAlpha) {
|
|
|
|
if (cell.isRiverOrSocial) {
|
|
|
|
cell.siteFavicon = [cell imageByApplyingAlpha:cell.siteFavicon withAlpha:0.25];
|
|
|
|
}
|
|
|
|
cell.hasAlpha = YES;
|
|
|
|
}
|
|
|
|
|
2013-10-17 18:56:14 -07:00
|
|
|
[cell.siteFavicon drawInRect:CGRectMake(leftMargin, siteTitleY, 16.0, 16.0)];
|
2012-07-22 17:08:29 -07:00
|
|
|
}
|
|
|
|
|
2013-09-25 17:43:00 -07:00
|
|
|
// story title
|
2016-01-27 21:50:44 -08:00
|
|
|
if (cell.isRead) {
|
|
|
|
font = [UIFont fontWithDescriptor:fontDescriptor size:0.0];
|
|
|
|
textColor = UIColorFromLightSepiaMediumDarkRGB(0x585858, 0x585858, 0x989898, 0x888888);
|
|
|
|
} else {
|
|
|
|
UIFontDescriptor *boldFontDescriptor = [fontDescriptor fontDescriptorWithSymbolicTraits: UIFontDescriptorTraitBold];
|
2016-09-13 16:28:19 -07:00
|
|
|
font = [UIFont fontWithDescriptor: boldFontDescriptor size:fontDescriptor.pointSize];
|
2016-01-28 11:31:18 -08:00
|
|
|
textColor = UIColorFromLightSepiaMediumDarkRGB(0x333333, 0x333333, 0xD0D0D0, 0xCCCCCC);
|
2016-01-27 21:50:44 -08:00
|
|
|
}
|
|
|
|
if (cell.highlighted || cell.selected) {
|
|
|
|
textColor = UIColorFromLightDarkRGB(0x686868, 0xA0A0A0);
|
|
|
|
}
|
2013-09-27 17:23:03 -07:00
|
|
|
CGSize theSize = [cell.storyTitle
|
2013-10-17 18:56:14 -07:00
|
|
|
boundingRectWithSize:CGSizeMake(rect.size.width, cell.isShort ? font.pointSize*1.5 : font.pointSize*3)
|
2013-10-01 14:44:13 -07:00
|
|
|
options:NSStringDrawingTruncatesLastVisibleLine|NSStringDrawingUsesLineFragmentOrigin
|
2013-09-25 17:43:00 -07:00
|
|
|
attributes:@{NSFontAttributeName: font,
|
|
|
|
NSParagraphStyleAttributeName: paragraphStyle}
|
|
|
|
context:nil].size;
|
2012-08-07 09:57:21 -07:00
|
|
|
|
2014-10-01 14:54:06 -07:00
|
|
|
int storyTitleY = 14 + riverPadding + ((font.pointSize*2 - theSize.height)/2);
|
2013-09-27 17:23:03 -07:00
|
|
|
if (cell.isShort) {
|
2014-10-01 14:54:06 -07:00
|
|
|
storyTitleY = 14 + riverPadding - (theSize.height/font.pointSize*2);
|
2012-08-08 18:23:48 -07:00
|
|
|
}
|
2013-08-05 17:29:42 -07:00
|
|
|
int storyTitleX = leftMargin;
|
2014-05-20 12:58:04 -07:00
|
|
|
if (cell.isSaved) {
|
2013-08-05 17:29:42 -07:00
|
|
|
UIImage *savedIcon = [UIImage imageNamed:@"clock"];
|
2016-10-05 21:03:32 -07:00
|
|
|
[savedIcon drawInRect:CGRectMake(storyTitleX, storyTitleY - 1, 16, 16) blendMode:0 alpha:1];
|
2013-08-05 17:29:42 -07:00
|
|
|
storyTitleX += 20;
|
|
|
|
}
|
2013-09-27 17:23:03 -07:00
|
|
|
if (cell.isShared) {
|
2013-08-05 17:29:42 -07:00
|
|
|
UIImage *savedIcon = [UIImage imageNamed:@"menu_icn_share"];
|
2016-10-05 21:03:32 -07:00
|
|
|
[savedIcon drawInRect:CGRectMake(storyTitleX, storyTitleY - 1, 16, 16) blendMode:0 alpha:1];
|
2013-08-05 17:29:42 -07:00
|
|
|
storyTitleX += 20;
|
|
|
|
}
|
2013-10-17 18:56:14 -07:00
|
|
|
CGRect storyTitleFrame = CGRectMake(storyTitleX, storyTitleY,
|
|
|
|
rect.size.width - storyTitleX + leftMargin, theSize.height);
|
|
|
|
[cell.storyTitle drawWithRect:storyTitleFrame
|
2013-10-01 14:44:13 -07:00
|
|
|
options:NSStringDrawingTruncatesLastVisibleLine|NSStringDrawingUsesLineFragmentOrigin
|
|
|
|
attributes:@{NSFontAttributeName: font,
|
|
|
|
NSForegroundColorAttributeName: textColor,
|
|
|
|
NSParagraphStyleAttributeName: paragraphStyle}
|
|
|
|
context:nil];
|
2013-09-27 17:23:03 -07:00
|
|
|
|
2014-02-10 19:21:53 -08:00
|
|
|
if (cell.storyContent) {
|
2014-02-13 17:18:29 -08:00
|
|
|
int storyContentWidth = rect.size.width;
|
|
|
|
if (cell.inDashboard) {
|
|
|
|
storyContentWidth -= leftMargin*2;
|
|
|
|
}
|
2014-02-10 19:21:53 -08:00
|
|
|
CGSize contentSize = [cell.storyContent
|
2014-02-21 16:06:49 -08:00
|
|
|
boundingRectWithSize:CGSizeMake(storyContentWidth,
|
|
|
|
cell.isShort ? font.pointSize*1.5 : font.pointSize*3)
|
2014-02-10 19:21:53 -08:00
|
|
|
options:NSStringDrawingTruncatesLastVisibleLine|NSStringDrawingUsesLineFragmentOrigin
|
|
|
|
attributes:@{NSFontAttributeName: font,
|
|
|
|
NSParagraphStyleAttributeName: paragraphStyle}
|
|
|
|
context:nil].size;
|
2014-02-21 16:06:49 -08:00
|
|
|
|
2014-10-01 14:54:06 -07:00
|
|
|
int storyContentY = r.size.height - 16 - 4 - ((font.pointSize*2 + font.lineHeight) + contentSize.height)/2;
|
2014-02-21 16:06:49 -08:00
|
|
|
if (cell.isShort) {
|
2014-10-01 14:54:06 -07:00
|
|
|
storyContentY = r.size.height - 10 - 4 - ((font.pointSize + font.lineHeight) + contentSize.height)/2;
|
2014-02-21 16:06:49 -08:00
|
|
|
}
|
2014-02-10 19:21:53 -08:00
|
|
|
|
|
|
|
if (cell.isRead) {
|
2016-01-27 21:50:44 -08:00
|
|
|
textColor = UIColorFromLightSepiaMediumDarkRGB(0xB8B8B8, 0xB8B8B8, 0xA0A0A0, 0x707070);
|
2014-02-10 19:21:53 -08:00
|
|
|
font = [UIFont fontWithDescriptor:fontDescriptor size:0.0];
|
|
|
|
} else {
|
2016-01-27 21:50:44 -08:00
|
|
|
textColor = UIColorFromLightSepiaMediumDarkRGB(0x404040, 0x404040, 0xC0C0C0, 0xB0B0B0);
|
2014-02-10 19:21:53 -08:00
|
|
|
font = [UIFont fontWithDescriptor:fontDescriptor size:0.0];
|
|
|
|
}
|
|
|
|
if (cell.highlighted || cell.selected) {
|
2014-02-21 17:24:33 -08:00
|
|
|
if (cell.isRead) {
|
2016-01-27 21:50:44 -08:00
|
|
|
textColor = UIColorFromLightSepiaMediumDarkRGB(0xB8B8B8, 0xB8B8B8, 0xA0A0A0, 0x707070);
|
2014-02-21 17:24:33 -08:00
|
|
|
} else {
|
2016-01-27 21:50:44 -08:00
|
|
|
textColor = UIColorFromLightSepiaMediumDarkRGB(0x686868, 0x686868, 0xA9A9A9, 0x989898);
|
2014-02-21 17:24:33 -08:00
|
|
|
}
|
2014-02-10 19:21:53 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
[cell.storyContent
|
2014-05-20 15:29:16 -07:00
|
|
|
drawWithRect:CGRectMake(storyTitleX, storyContentY,
|
|
|
|
rect.size.width - storyTitleX + leftMargin, contentSize.height)
|
2014-02-13 17:18:29 -08:00
|
|
|
options:NSStringDrawingTruncatesLastVisibleLine|NSStringDrawingUsesLineFragmentOrigin
|
|
|
|
attributes:@{NSFontAttributeName: font,
|
|
|
|
NSForegroundColorAttributeName: textColor,
|
|
|
|
NSParagraphStyleAttributeName: paragraphStyle}
|
|
|
|
context:nil];
|
2014-02-10 19:21:53 -08:00
|
|
|
}
|
|
|
|
|
2014-03-11 18:20:36 -07:00
|
|
|
// story date
|
2013-10-17 18:56:14 -07:00
|
|
|
int storyAuthorDateY = r.size.height - 18;
|
2013-09-27 17:23:03 -07:00
|
|
|
|
|
|
|
if (cell.isRead) {
|
2016-02-27 13:20:32 -08:00
|
|
|
textColor = UIColorFromLightSepiaMediumDarkRGB(0xBABDD1, 0xBABDD1, 0x52535d, 0x21366e);
|
2013-07-02 16:11:14 -07:00
|
|
|
font = [UIFont fontWithName:@"Helvetica" size:10];
|
2012-07-22 17:08:29 -07:00
|
|
|
} else {
|
2016-01-27 21:50:44 -08:00
|
|
|
textColor = UIColorFromLightSepiaMediumDarkRGB(0x262C6C, 0x262C6C, 0x363C5C, 0x21468e);
|
2013-07-02 16:11:14 -07:00
|
|
|
font = [UIFont fontWithName:@"Helvetica-Bold" size:10];
|
2012-07-22 17:08:29 -07:00
|
|
|
}
|
|
|
|
|
2013-09-27 17:23:03 -07:00
|
|
|
if (cell.highlighted || cell.selected) {
|
2013-10-17 17:23:52 -07:00
|
|
|
if (cell.isRead) {
|
2016-01-27 21:50:44 -08:00
|
|
|
textColor = UIColorFromLightSepiaMediumDarkRGB(0xAAADC1, 0xAAADC1, 0x72738d, 0x35363A);
|
2013-10-17 17:23:52 -07:00
|
|
|
} else {
|
2016-01-27 21:50:44 -08:00
|
|
|
textColor = UIColorFromLightSepiaMediumDarkRGB(0x5A5D91, 0x5A5D91, 0x666C8C, 0x11367e);
|
2013-10-17 17:23:52 -07:00
|
|
|
}
|
2012-07-22 17:08:29 -07:00
|
|
|
}
|
|
|
|
|
2013-09-25 17:43:00 -07:00
|
|
|
paragraphStyle.alignment = NSTextAlignmentRight;
|
2013-10-10 12:58:40 -07:00
|
|
|
NSString *date = [Utilities formatShortDateFromTimestamp:cell.storyTimestamp];
|
2014-03-11 18:20:36 -07:00
|
|
|
CGSize dateSize = [date sizeWithAttributes:@{NSFontAttributeName: font,
|
|
|
|
NSForegroundColorAttributeName: textColor,
|
|
|
|
NSParagraphStyleAttributeName: paragraphStyle}];
|
2013-10-10 12:58:40 -07:00
|
|
|
[date
|
2018-11-12 20:27:46 -08:00
|
|
|
drawInRect:CGRectMake(0, storyAuthorDateY, dateRect.size.width + leftMargin, 15.0)
|
2013-09-25 17:43:00 -07:00
|
|
|
withAttributes:@{NSFontAttributeName: font,
|
|
|
|
NSForegroundColorAttributeName: textColor,
|
|
|
|
NSParagraphStyleAttributeName: paragraphStyle}];
|
2012-08-10 18:10:07 -07:00
|
|
|
|
2014-03-11 18:20:36 -07:00
|
|
|
// Story author
|
|
|
|
if (cell.isRead) {
|
2016-01-27 21:50:44 -08:00
|
|
|
textColor = UIColorFromLightSepiaMediumDarkRGB(0xB8B8B8, 0xB8B8B8, 0x909090, 0x404040);
|
2014-10-01 14:54:06 -07:00
|
|
|
font = [UIFont fontWithName:@"Helvetica-Bold" size:10];
|
2014-03-11 18:20:36 -07:00
|
|
|
} else {
|
2016-01-27 21:50:44 -08:00
|
|
|
textColor = UIColorFromLightSepiaMediumDarkRGB(0xA6A8A2, 0xA6A8A2, 0x909090, 0x505050);
|
2014-03-11 18:20:36 -07:00
|
|
|
font = [UIFont fontWithName:@"Helvetica-Bold" size:10];
|
|
|
|
}
|
|
|
|
if (cell.highlighted || cell.selected) {
|
2014-10-01 14:54:06 -07:00
|
|
|
if (cell.isRead) {
|
2016-01-27 21:50:44 -08:00
|
|
|
textColor = UIColorFromLightSepiaMediumDarkRGB(0xA8A8A8, 0xA8A8A8, 0x999999, 0x303030);
|
2014-10-01 14:54:06 -07:00
|
|
|
} else {
|
2016-01-27 21:50:44 -08:00
|
|
|
textColor = UIColorFromLightSepiaMediumDarkRGB(0x959595, 0x959595, 0xA0A0A0, 0x404040);
|
2014-10-01 14:54:06 -07:00
|
|
|
}
|
2014-03-11 18:20:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
paragraphStyle.alignment = NSTextAlignmentLeft;
|
|
|
|
[cell.storyAuthor
|
|
|
|
drawInRect:CGRectMake(leftMargin, storyAuthorDateY, rect.size.width - dateSize.width - 12, 15.0)
|
|
|
|
withAttributes:@{NSFontAttributeName: font,
|
|
|
|
NSForegroundColorAttributeName: textColor,
|
|
|
|
NSParagraphStyleAttributeName: paragraphStyle}];
|
|
|
|
|
|
|
|
// feed bar
|
2013-09-27 17:23:03 -07:00
|
|
|
CGContextSetStrokeColor(context, CGColorGetComponents([cell.feedColorBarTopBorder CGColor]));
|
|
|
|
if (cell.isRead) {
|
2013-02-21 12:19:15 -08:00
|
|
|
CGContextSetAlpha(context, 0.15);
|
2012-08-07 09:57:21 -07:00
|
|
|
}
|
2013-02-21 12:19:15 -08:00
|
|
|
CGContextSetLineWidth(context, 4.0f);
|
2012-08-11 18:03:28 -07:00
|
|
|
CGContextBeginPath(context);
|
2013-09-30 10:26:19 -07:00
|
|
|
CGContextMoveToPoint(context, 2.0f, 0);
|
|
|
|
CGContextAddLineToPoint(context, 2.0f, cell.frame.size.height);
|
2012-08-11 18:03:28 -07:00
|
|
|
CGContextStrokePath(context);
|
2013-09-27 17:23:03 -07:00
|
|
|
|
|
|
|
CGContextSetStrokeColor(context, CGColorGetComponents([cell.feedColorBar CGColor]));
|
2012-08-13 17:35:04 -07:00
|
|
|
CGContextBeginPath(context);
|
2013-09-30 10:26:19 -07:00
|
|
|
CGContextMoveToPoint(context, 6.0f, 0);
|
|
|
|
CGContextAddLineToPoint(context, 6.0, cell.frame.size.height);
|
2012-08-13 17:35:04 -07:00
|
|
|
CGContextStrokePath(context);
|
2012-08-07 09:57:21 -07:00
|
|
|
|
2012-08-08 12:02:54 -07:00
|
|
|
// reset for borders
|
2013-09-30 10:26:19 -07:00
|
|
|
UIColor *white = UIColorFromRGB(0xffffff);
|
2012-08-08 12:02:54 -07:00
|
|
|
CGContextSetAlpha(context, 1.0);
|
2013-09-27 17:23:03 -07:00
|
|
|
if (cell.highlighted || cell.selected) {
|
2012-07-23 10:57:11 -07:00
|
|
|
// top border
|
2013-09-30 10:26:19 -07:00
|
|
|
CGContextSetStrokeColor(context, CGColorGetComponents([white CGColor]));
|
2012-07-23 10:57:11 -07:00
|
|
|
|
2013-09-30 10:26:19 -07:00
|
|
|
CGContextSetLineWidth(context, 1.0f);
|
2012-07-23 10:57:11 -07:00
|
|
|
CGContextBeginPath(context);
|
2012-07-28 23:31:12 -07:00
|
|
|
CGContextMoveToPoint(context, 0, 0.5f);
|
2013-09-27 17:23:03 -07:00
|
|
|
CGContextAddLineToPoint(context, cell.bounds.size.width, 0.5f);
|
2012-07-23 10:57:11 -07:00
|
|
|
CGContextStrokePath(context);
|
|
|
|
|
2013-09-30 10:26:19 -07:00
|
|
|
CGFloat lineWidth = 0.5f;
|
|
|
|
CGContextSetLineWidth(context, lineWidth);
|
|
|
|
UIColor *blue = UIColorFromRGB(0xDFDDCF);
|
|
|
|
|
|
|
|
CGContextSetStrokeColor(context, CGColorGetComponents([blue CGColor]));
|
|
|
|
|
|
|
|
CGContextBeginPath(context);
|
|
|
|
CGContextMoveToPoint(context, 0, 1.0f + 0.5f*lineWidth);
|
|
|
|
CGContextAddLineToPoint(context, cell.bounds.size.width, 1.0f + 0.5f*lineWidth);
|
|
|
|
CGContextStrokePath(context);
|
|
|
|
|
2013-09-27 17:23:03 -07:00
|
|
|
// bottom border
|
2012-07-23 10:57:11 -07:00
|
|
|
CGContextBeginPath(context);
|
2013-09-30 10:26:19 -07:00
|
|
|
CGContextMoveToPoint(context, 0, cell.bounds.size.height - .5f*lineWidth);
|
|
|
|
CGContextAddLineToPoint(context, cell.bounds.size.width, cell.bounds.size.height - .5f*lineWidth);
|
2012-07-23 10:57:11 -07:00
|
|
|
CGContextStrokePath(context);
|
|
|
|
} else {
|
|
|
|
// top border
|
2013-09-30 10:26:19 -07:00
|
|
|
CGContextSetLineWidth(context, 1.0f);
|
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);
|
2013-09-27 17:23:03 -07:00
|
|
|
CGContextAddLineToPoint(context, cell.bounds.size.width, 0.5f);
|
2012-07-23 10:57:11 -07:00
|
|
|
CGContextStrokePath(context);
|
2012-07-22 17:08:29 -07:00
|
|
|
}
|
|
|
|
|
2013-09-27 17:23:03 -07:00
|
|
|
// story indicator
|
2013-10-17 18:56:14 -07:00
|
|
|
int storyIndicatorY = storyTitleFrame.origin.y + storyTitleFrame.size.height / 2;
|
2013-09-27 17:23:03 -07:00
|
|
|
|
2013-02-21 12:19:15 -08:00
|
|
|
UIImage *unreadIcon;
|
2013-09-27 17:23:03 -07:00
|
|
|
if (cell.storyScore == -1) {
|
2013-02-21 12:19:15 -08:00
|
|
|
unreadIcon = [UIImage imageNamed:@"g_icn_hidden"];
|
2013-09-27 17:23:03 -07:00
|
|
|
} else if (cell.storyScore == 1) {
|
2013-02-21 12:19:15 -08:00
|
|
|
unreadIcon = [UIImage imageNamed:@"g_icn_focus"];
|
2012-07-23 10:57:11 -07:00
|
|
|
} else {
|
2013-02-21 12:19:15 -08:00
|
|
|
unreadIcon = [UIImage imageNamed:@"g_icn_unread"];
|
2012-08-10 18:10:07 -07:00
|
|
|
}
|
|
|
|
|
2016-10-05 21:03:32 -07:00
|
|
|
[unreadIcon drawInRect:CGRectMake(15, storyIndicatorY - 3, 8, 8) blendMode:0 alpha:(cell.isRead ? .15 : 1)];
|
2012-07-22 17:08:29 -07:00
|
|
|
}
|
2010-07-15 00:44:38 -04:00
|
|
|
|
2015-11-03 22:21:18 -08:00
|
|
|
@end
|