2012-10-02 15:39:18 -07:00
|
|
|
//
|
|
|
|
// FolderTitleView.m
|
|
|
|
// NewsBlur
|
|
|
|
//
|
|
|
|
// Created by Samuel Clay on 10/2/12.
|
|
|
|
// Copyright (c) 2012 NewsBlur. All rights reserved.
|
|
|
|
//
|
|
|
|
|
2012-10-07 15:47:21 -04:00
|
|
|
#import <QuartzCore/QuartzCore.h>
|
2012-10-02 15:39:18 -07:00
|
|
|
#import "NewsBlurAppDelegate.h"
|
|
|
|
#import "FolderTitleView.h"
|
2012-10-04 10:59:44 -07:00
|
|
|
#import "UnreadCountView.h"
|
2012-10-02 15:39:18 -07:00
|
|
|
|
|
|
|
@implementation FolderTitleView
|
|
|
|
|
|
|
|
@synthesize appDelegate;
|
2012-10-04 15:44:25 -07:00
|
|
|
@synthesize section;
|
2012-10-12 15:33:40 -04:00
|
|
|
@synthesize unreadCount;
|
|
|
|
|
|
|
|
- (void)setNeedsDisplay {
|
|
|
|
[unreadCount setNeedsDisplay];
|
|
|
|
|
|
|
|
[super setNeedsDisplay];
|
|
|
|
}
|
2012-10-02 15:39:18 -07:00
|
|
|
|
2012-10-04 15:44:25 -07:00
|
|
|
- (void) drawRect:(CGRect)rect {
|
2012-10-02 15:39:18 -07:00
|
|
|
|
|
|
|
self.appDelegate = (NewsBlurAppDelegate *)[[UIApplication sharedApplication] delegate];
|
2012-10-03 15:46:02 -07:00
|
|
|
NSUserDefaults *userPreferences = [NSUserDefaults standardUserDefaults];
|
2012-10-04 15:44:25 -07:00
|
|
|
|
2012-10-11 20:19:26 -04:00
|
|
|
CGContextRef context = UIGraphicsGetCurrentContext();
|
2012-10-14 17:33:07 -04:00
|
|
|
for (UIView *subview in self.subviews) {
|
|
|
|
[subview removeFromSuperview];
|
|
|
|
}
|
|
|
|
|
2012-10-03 15:46:02 -07:00
|
|
|
NSString *folderName;
|
|
|
|
if (section == 0) {
|
2012-12-07 15:17:22 -08:00
|
|
|
folderName = @"river_global";
|
|
|
|
} else if (section == 1) {
|
2012-10-03 15:46:02 -07:00
|
|
|
folderName = @"river_blurblogs";
|
|
|
|
} else {
|
|
|
|
folderName = [appDelegate.dictFoldersArray objectAtIndex:section];
|
|
|
|
}
|
|
|
|
NSString *collapseKey = [NSString stringWithFormat:@"folderCollapsed:%@", folderName];
|
|
|
|
bool isFolderCollapsed = [userPreferences boolForKey:collapseKey];
|
2012-10-07 15:47:21 -04:00
|
|
|
int countWidth = 0;
|
2012-10-12 15:33:40 -04:00
|
|
|
|
2012-10-07 15:47:21 -04:00
|
|
|
if (isFolderCollapsed) {
|
2012-10-12 15:33:40 -04:00
|
|
|
UnreadCounts *counts = [appDelegate splitUnreadCountForFolder:folderName];
|
2012-10-07 15:47:21 -04:00
|
|
|
unreadCount = [[UnreadCountView alloc] initWithFrame:rect];
|
|
|
|
unreadCount.appDelegate = appDelegate;
|
|
|
|
unreadCount.opaque = NO;
|
|
|
|
unreadCount.psCount = counts.ps;
|
|
|
|
unreadCount.ntCount = counts.nt;
|
|
|
|
|
|
|
|
[unreadCount calculateOffsets:counts.ps nt:counts.nt];
|
|
|
|
countWidth = [unreadCount offsetWidth];
|
|
|
|
[self addSubview:unreadCount];
|
2013-02-06 15:15:43 -08:00
|
|
|
} else if ([folderName isEqual:@"saved_stories"]) {
|
2012-10-17 15:07:53 -07:00
|
|
|
unreadCount = [[UnreadCountView alloc] initWithFrame:rect];
|
|
|
|
unreadCount.appDelegate = appDelegate;
|
|
|
|
unreadCount.opaque = NO;
|
|
|
|
unreadCount.psCount = appDelegate.savedStoriesCount;
|
|
|
|
unreadCount.blueCount = appDelegate.savedStoriesCount;
|
|
|
|
|
|
|
|
[unreadCount calculateOffsets:appDelegate.savedStoriesCount nt:0];
|
|
|
|
countWidth = [unreadCount offsetWidth];
|
|
|
|
[self addSubview:unreadCount];
|
2012-10-07 15:47:21 -04:00
|
|
|
}
|
|
|
|
|
2012-10-02 15:39:18 -07:00
|
|
|
// create the parent view that will hold header Label
|
2012-10-04 15:44:25 -07:00
|
|
|
UIView* customView = [[UIView alloc] initWithFrame:rect];
|
2012-10-11 20:19:26 -04:00
|
|
|
|
|
|
|
// Background
|
|
|
|
UIColor *backgroundColor = UIColorFromRGB(0xD7DDE6);
|
|
|
|
[backgroundColor set];
|
|
|
|
CGContextFillRect(context, rect);
|
|
|
|
|
|
|
|
// Borders
|
|
|
|
UIColor *topColor = UIColorFromRGB(0xE7EDF6);
|
|
|
|
CGContextSetStrokeColor(context, CGColorGetComponents([topColor CGColor]));
|
|
|
|
|
|
|
|
CGContextBeginPath(context);
|
|
|
|
CGContextMoveToPoint(context, 0, 0.5f);
|
|
|
|
CGContextAddLineToPoint(context, rect.size.width, 0.5f);
|
|
|
|
CGContextStrokePath(context);
|
2012-10-02 15:39:18 -07:00
|
|
|
|
2012-10-11 20:19:26 -04:00
|
|
|
// bottom border
|
|
|
|
UIColor *bottomColor = UIColorFromRGB(0xB7BDC6);
|
|
|
|
CGContextSetStrokeColor(context, CGColorGetComponents([bottomColor CGColor]));
|
|
|
|
CGContextBeginPath(context);
|
|
|
|
CGContextMoveToPoint(context, 0, rect.size.height - .5f);
|
|
|
|
CGContextAddLineToPoint(context, rect.size.width, rect.size.height - .5f);
|
|
|
|
CGContextStrokePath(context);
|
2012-10-02 15:39:18 -07:00
|
|
|
|
2012-10-11 20:19:26 -04:00
|
|
|
// Folder title
|
|
|
|
UIColor *textColor = [UIColor colorWithRed:0.3 green:0.3 blue:0.3 alpha:1.0];
|
|
|
|
[textColor set];
|
|
|
|
UIFont *font = [UIFont boldSystemFontOfSize:11];
|
|
|
|
NSString *folderTitle;
|
2012-10-02 15:39:18 -07:00
|
|
|
if (section == 0) {
|
2012-12-07 15:17:22 -08:00
|
|
|
folderTitle = [@"Global Shared Stories" uppercaseString];
|
2012-10-02 15:39:18 -07:00
|
|
|
} else if (section == 1) {
|
2012-12-07 15:17:22 -08:00
|
|
|
folderTitle = [@"All Shared Stories" uppercaseString];
|
|
|
|
} else if (section == 2) {
|
2012-10-17 15:07:53 -07:00
|
|
|
folderTitle = [@"All Stories" uppercaseString];
|
2013-02-06 15:15:43 -08:00
|
|
|
} else if ([folderName isEqual:@"saved_stories"]) {
|
2012-10-17 15:07:53 -07:00
|
|
|
folderTitle = [@"Saved Stories" uppercaseString];
|
2012-10-02 15:39:18 -07:00
|
|
|
} else {
|
2012-10-11 20:19:26 -04:00
|
|
|
folderTitle = [[appDelegate.dictFoldersArray objectAtIndex:section] uppercaseString];
|
2012-10-02 15:39:18 -07:00
|
|
|
}
|
2012-10-11 20:19:26 -04:00
|
|
|
UIColor *shadowColor = UIColorFromRGB(0xE7EDF6);
|
|
|
|
CGContextSetShadowWithColor(context, CGSizeMake(0, 1), 0, [shadowColor CGColor]);
|
2012-10-02 15:39:18 -07:00
|
|
|
|
2012-10-11 20:19:26 -04:00
|
|
|
[folderTitle
|
2012-10-30 17:05:39 -07:00
|
|
|
drawInRect:CGRectMake(36.0, 9, rect.size.width - 36 - 36 - countWidth, 14)
|
2012-10-11 20:19:26 -04:00
|
|
|
withFont:font
|
|
|
|
lineBreakMode:UILineBreakModeTailTruncation
|
|
|
|
alignment:UITextAlignmentLeft];
|
|
|
|
|
2012-10-02 15:39:18 -07:00
|
|
|
UIButton *invisibleHeaderButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
|
|
invisibleHeaderButton.frame = CGRectMake(0, 0, customView.frame.size.width, customView.frame.size.height);
|
|
|
|
invisibleHeaderButton.alpha = .1;
|
|
|
|
invisibleHeaderButton.tag = section;
|
|
|
|
[invisibleHeaderButton addTarget:appDelegate.feedsViewController action:@selector(didSelectSectionHeader:) forControlEvents:UIControlEventTouchUpInside];
|
|
|
|
[invisibleHeaderButton addTarget:appDelegate.feedsViewController action:@selector(sectionTapped:) forControlEvents:UIControlEventTouchDown];
|
|
|
|
[invisibleHeaderButton addTarget:appDelegate.feedsViewController action:@selector(sectionUntapped:) forControlEvents:UIControlEventTouchUpInside];
|
|
|
|
[invisibleHeaderButton addTarget:appDelegate.feedsViewController action:@selector(sectionUntappedOutside:) forControlEvents:UIControlEventTouchUpOutside];
|
2012-10-11 20:19:26 -04:00
|
|
|
[customView addSubview:invisibleHeaderButton];
|
2012-10-02 15:39:18 -07:00
|
|
|
|
|
|
|
if (!appDelegate.hasNoSites) {
|
|
|
|
UIButton *disclosureButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
|
|
UIImage *disclosureImage = [UIImage imageNamed:@"disclosure.png"];
|
|
|
|
[disclosureButton setImage:disclosureImage forState:UIControlStateNormal];
|
2012-10-30 17:05:39 -07:00
|
|
|
disclosureButton.frame = CGRectMake(customView.frame.size.width - 32, 1, 29, 29);
|
2012-10-14 19:39:24 -04:00
|
|
|
|
|
|
|
// Add collapse button to all folders except Everything
|
2013-02-06 15:15:43 -08:00
|
|
|
if (section != 0 && section != 2 && ![folderName isEqual:@"saved_stories"]) {
|
2012-10-03 15:46:02 -07:00
|
|
|
if (!isFolderCollapsed) {
|
|
|
|
disclosureButton.transform = CGAffineTransformMakeRotation(M_PI_2);
|
|
|
|
}
|
|
|
|
|
|
|
|
disclosureButton.tag = section;
|
|
|
|
[disclosureButton addTarget:appDelegate.feedsViewController action:@selector(didCollapseFolder:) forControlEvents:UIControlEventTouchUpInside];
|
2012-10-14 17:33:07 -04:00
|
|
|
|
|
|
|
UIImage *disclosureBorder = [UIImage imageNamed:@"disclosure_border.png"];
|
2012-10-30 17:05:39 -07:00
|
|
|
[disclosureBorder drawInRect:CGRectMake(customView.frame.size.width - 32, 1, 29, 29)];
|
2012-10-14 19:39:24 -04:00
|
|
|
} else {
|
2012-10-17 15:07:53 -07:00
|
|
|
// Everything/Saved folder doesn't get a button
|
2012-10-14 19:39:24 -04:00
|
|
|
[disclosureButton setUserInteractionEnabled:NO];
|
2012-10-02 15:39:18 -07:00
|
|
|
}
|
|
|
|
[customView addSubview:disclosureButton];
|
|
|
|
}
|
|
|
|
|
2012-10-03 15:46:02 -07:00
|
|
|
UIImage *folderImage;
|
|
|
|
int folderImageViewX = 10;
|
|
|
|
|
2012-12-07 15:17:22 -08:00
|
|
|
if (section == 0 || section == 1) {
|
2012-10-03 15:46:02 -07:00
|
|
|
folderImage = [UIImage imageNamed:@"group.png"];
|
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
|
|
|
folderImageViewX = 10;
|
|
|
|
} else {
|
|
|
|
folderImageViewX = 8;
|
|
|
|
}
|
2012-12-07 15:17:22 -08:00
|
|
|
} else if (section == 2) {
|
2012-10-03 15:46:02 -07:00
|
|
|
folderImage = [UIImage imageNamed:@"archive.png"];
|
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
|
|
|
folderImageViewX = 10;
|
|
|
|
} else {
|
|
|
|
folderImageViewX = 7;
|
|
|
|
}
|
2013-02-06 15:15:43 -08:00
|
|
|
} else if ([folderName isEqual:@"saved_stories"]) {
|
2012-10-17 15:07:53 -07:00
|
|
|
folderImage = [UIImage imageNamed:@"clock.png"];
|
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
|
|
|
folderImageViewX = 10;
|
|
|
|
} else {
|
|
|
|
folderImageViewX = 7;
|
|
|
|
}
|
2012-10-03 15:46:02 -07:00
|
|
|
} else {
|
|
|
|
if (isFolderCollapsed) {
|
|
|
|
folderImage = [UIImage imageNamed:@"folder_collapsed.png"];
|
|
|
|
} else {
|
|
|
|
folderImage = [UIImage imageNamed:@"folder_2.png"];
|
|
|
|
}
|
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
|
|
|
} else {
|
|
|
|
folderImageViewX = 7;
|
|
|
|
}
|
|
|
|
}
|
2012-10-30 17:05:39 -07:00
|
|
|
[folderImage drawInRect:CGRectMake(folderImageViewX, 5, 20, 20)];
|
2012-10-03 15:46:02 -07:00
|
|
|
|
2012-10-02 15:39:18 -07:00
|
|
|
[customView setAutoresizingMask:UIViewAutoresizingNone];
|
|
|
|
|
2012-10-04 15:44:25 -07:00
|
|
|
if (isFolderCollapsed) {
|
2012-10-07 15:47:21 -04:00
|
|
|
[self insertSubview:customView belowSubview:unreadCount];
|
|
|
|
} else {
|
|
|
|
[self addSubview:customView];
|
2012-10-04 15:44:25 -07:00
|
|
|
}
|
2012-10-02 15:39:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|