NewsBlur/clients/ios/Classes/FolderTitleView.m

216 lines
8.7 KiB
Mathematica
Raw Normal View History

//
// FolderTitleView.m
// NewsBlur
//
// Created by Samuel Clay on 10/2/12.
// Copyright (c) 2012 NewsBlur. All rights reserved.
//
#import <QuartzCore/QuartzCore.h>
#import "NewsBlurAppDelegate.h"
#import "FolderTitleView.h"
#import "UnreadCountView.h"
@implementation FolderTitleView
@synthesize appDelegate;
@synthesize section;
@synthesize unreadCount;
- (void)setNeedsDisplay {
[unreadCount setNeedsDisplay];
[super setNeedsDisplay];
}
- (void) drawRect:(CGRect)rect {
self.appDelegate = [NewsBlurAppDelegate sharedAppDelegate];
NSUserDefaults *userPreferences = [NSUserDefaults standardUserDefaults];
CGContextRef context = UIGraphicsGetCurrentContext();
for (UIView *subview in self.subviews) {
[subview removeFromSuperview];
}
NSString *folderName;
if (section == 0) {
folderName = @"river_global";
} else if (section == 1) {
folderName = @"river_blurblogs";
} else {
folderName = [appDelegate.dictFoldersArray objectAtIndex:section];
}
NSString *collapseKey = [NSString stringWithFormat:@"folderCollapsed:%@", folderName];
bool isFolderCollapsed = [userPreferences boolForKey:collapseKey];
int countWidth = 0;
if (isFolderCollapsed) {
UnreadCounts *counts = [appDelegate splitUnreadCountForFolder:folderName];
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];
} else if ([folderName isEqual:@"saved_stories"]) {
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];
}
// create the parent view that will hold header Label
UIView* customView = [[UIView alloc] initWithFrame:rect];
// Background
[NewsBlurAppDelegate fillGradient:rect
startColor:UIColorFromRGB(0xEAECE5)
endColor:UIColorFromRGB(0xDCDFD6)];
// UIColor *backgroundColor = UIColorFromRGB(0xD7DDE6);
// [backgroundColor set];
// CGContextFillRect(context, rect);
// Borders
UIColor *topColor = UIColorFromRGB(0xFDFDFD);
CGContextSetStrokeColor(context, CGColorGetComponents([topColor CGColor]));
CGContextBeginPath(context);
CGContextMoveToPoint(context, 0, 0.5f);
CGContextAddLineToPoint(context, rect.size.width, 0.5f);
CGContextStrokePath(context);
// bottom border
UIColor *bottomColor = UIColorFromRGB(0xB7BBAA);
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);
// Folder title
UIColor *textColor = [UIColor colorWithRed:0.3 green:0.3 blue:0.3 alpha:1.0];
UIFont *font = [UIFont boldSystemFontOfSize:11];
NSString *folderTitle;
if (section == 0) {
folderTitle = [@"Global Shared Stories" uppercaseString];
} else if (section == 1) {
folderTitle = [@"All Shared Stories" uppercaseString];
} else if (section == 2) {
folderTitle = [@"All Stories" uppercaseString];
} else if ([folderName isEqual:@"saved_stories"]) {
folderTitle = [@"Saved Stories" uppercaseString];
} else {
folderTitle = [[appDelegate.dictFoldersArray objectAtIndex:section] uppercaseString];
}
2013-02-15 16:41:20 -08:00
UIColor *shadowColor = UIColorFromRGB(0xF0F2E9);
CGContextSetShadowWithColor(context, CGSizeMake(0, 1), 0, [shadowColor CGColor]);
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle defaultParagraphStyle] mutableCopy];
paragraphStyle.lineBreakMode = NSLineBreakByTruncatingTail;
paragraphStyle.alignment = NSTextAlignmentLeft;
[folderTitle
2013-02-15 16:41:20 -08:00
drawInRect:CGRectMake(36.0, 10, rect.size.width - 36 - 36 - countWidth, 14)
withAttributes:@{NSFontAttributeName: font,
2013-09-26 16:12:09 -07:00
NSForegroundColorAttributeName: textColor,
NSParagraphStyleAttributeName: paragraphStyle}];
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];
[customView addSubview:invisibleHeaderButton];
if (!appDelegate.hasNoSites) {
UIButton *disclosureButton = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *disclosureImage = [UIImage imageNamed:@"disclosure.png"];
[disclosureButton setImage:disclosureImage forState:UIControlStateNormal];
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
if (section != 0 && section != 2 && ![folderName isEqual:@"saved_stories"]) {
if (!isFolderCollapsed) {
UIImage *disclosureImage = [UIImage imageNamed:@"disclosure_down.png"];
[disclosureButton setImage:disclosureImage forState:UIControlStateNormal];
// disclosureButton.transform = CGAffineTransformMakeRotation(M_PI_2);
}
disclosureButton.tag = section;
[disclosureButton addTarget:appDelegate.feedsViewController action:@selector(didCollapseFolder:) forControlEvents:UIControlEventTouchUpInside];
UIImage *disclosureBorder = [UIImage imageNamed:@"disclosure_border.png"];
[disclosureBorder drawInRect:CGRectMake(customView.frame.size.width - 32, 1, 29, 29)];
2012-10-14 19:39:24 -04:00
} else {
// Everything/Saved folder doesn't get a button
2012-10-14 19:39:24 -04:00
[disclosureButton setUserInteractionEnabled:NO];
}
[customView addSubview:disclosureButton];
}
UIImage *folderImage;
int folderImageViewX = 10;
if (section == 0) {
folderImage = [UIImage imageNamed:@"ak-icon-global.png"];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
folderImageViewX = 10;
} else {
folderImageViewX = 8;
}
} else if (section == 1) {
folderImage = [UIImage imageNamed:@"ak-icon-blurblogs.png"];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
folderImageViewX = 10;
} else {
folderImageViewX = 8;
}
} else if (section == 2) {
folderImage = [UIImage imageNamed:@"ak-icon-allstories.png"];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
folderImageViewX = 10;
} else {
folderImageViewX = 7;
}
} else if ([folderName isEqual:@"saved_stories"]) {
2013-03-07 10:55:23 -05:00
folderImage = [UIImage imageNamed:@"clock.png"];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
folderImageViewX = 10;
} else {
folderImageViewX = 7;
}
} else {
if (isFolderCollapsed) {
folderImage = [UIImage imageNamed:@"g_icn_folder_rss"];
} else {
folderImage = [UIImage imageNamed:@"g_icn_folder"];
}
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
} else {
folderImageViewX = 7;
}
}
2013-02-15 16:41:20 -08:00
[folderImage drawInRect:CGRectMake(folderImageViewX, 6, 20, 20)];
[customView setAutoresizingMask:UIViewAutoresizingNone];
if (isFolderCollapsed) {
[self insertSubview:customView belowSubview:unreadCount];
} else {
[self addSubview:customView];
}
}
@end