Permalink
Browse files

Generic cell + some updates of template stuff

  • Loading branch information...
1 parent 9b84305 commit f31a4ea9d28f62917fb2131b07cffb0b78b5c287 @myell0w committed Apr 18, 2012
Submodule AFNetworking updated 57 files
+5 −4 AFNetworking.podspec
+88 −20 AFNetworking/AFHTTPClient.h
+262 −39 AFNetworking/AFHTTPClient.m
+12 −6 AFNetworking/AFHTTPRequestOperation.h
+79 −12 AFNetworking/AFHTTPRequestOperation.m
+0 −69 AFNetworking/AFImageCache.h
+0 −63 AFNetworking/AFImageCache.m
+1 −9 AFNetworking/AFImageRequestOperation.h
+17 −12 AFNetworking/AFImageRequestOperation.m
+3 −5 AFNetworking/AFJSONRequestOperation.h
+15 −13 AFNetworking/AFJSONRequestOperation.m
+2 −126 AFNetworking/AFJSONUtilities.h
+217 −0 AFNetworking/AFJSONUtilities.m
+6 −6 AFNetworking/AFNetworkActivityIndicatorManager.h
+29 −14 AFNetworking/AFNetworkActivityIndicatorManager.m
+1 −2 AFNetworking/AFNetworking.h
+1 −7 AFNetworking/AFPropertyListRequestOperation.h
+15 −13 AFNetworking/AFPropertyListRequestOperation.m
+40 −22 AFNetworking/AFURLConnectionOperation.h
+227 −97 AFNetworking/AFURLConnectionOperation.m
+1 −8 AFNetworking/AFXMLRequestOperation.h
+32 −37 AFNetworking/AFXMLRequestOperation.m
+58 −16 AFNetworking/UIImageView+AFNetworking.m
+102 −0 CHANGES
+6 −8 Mac Example/AFNetworking Mac Example.xcodeproj/project.pbxproj
+2 −2 Mac Example/Classes/Controllers/NearbySpotsController.h
+1 −40 Mac Example/Classes/Controllers/NearbySpotsController.m
+2 −4 Mac Example/Classes/Models/Spot.h
+2 −3 Mac Example/Classes/Models/Spot.m
+102 −70 Mac Example/en.lproj/MainMenu.xib
+87 −68 README.md
+114 −135 iOS Example/AFNetworking iOS Example.xcodeproj/project.pbxproj
+4 −4 iOS Example/AppDelegate.h
+8 −12 iOS Example/AppDelegate.m
+5 −6 iOS Example/Classes/AFTwitterAPIClient.h
+10 −22 iOS Example/Classes/AFTwitterAPIClient.m
+0 −191 iOS Example/Classes/Controllers/NearbySpotsViewController.m
+3 −7 iOS Example/Classes/Controllers/PublicTimelineViewController.h
+128 −0 iOS Example/Classes/Controllers/PublicTimelineViewController.m
+0 −84 iOS Example/Classes/Models/Spot.m
+13 −18 iOS Example/Classes/Models/Tweet.h
+77 −0 iOS Example/Classes/Models/Tweet.m
+33 −0 iOS Example/Classes/Models/User.h
+52 −0 iOS Example/Classes/Models/User.m
+0 −98 iOS Example/Classes/Views/SpotTableViewCell.m
+9 −8 iOS Example/Classes/Views/TweetTableViewCell.h
+81 −0 iOS Example/Classes/Views/TweetTableViewCell.m
+ iOS Example/Images/placeholder-stamp.png
+ iOS Example/Images/placeholder-stamp@2x.png
+ iOS Example/Images/profile-image-placeholder.png
+ iOS Example/Images/profile-image-placeholder@2x.png
+1 −0 iOS Example/Prefix.pch
+0 −251 iOS Example/Vendor/JSONKit/JSONKit.h
+0 −3,011 iOS Example/Vendor/JSONKit/JSONKit.m
+0 −83 iOS Example/Vendor/TTT/TTTLocationFormatter.h
+0 −299 iOS Example/Vendor/TTT/TTTLocationFormatter.m
+5 −5 iOS Example/main.m

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,21 @@
+// Part of iOSKit http://foundationk.it
+
+#import "FKTableViewCell.h"
+
+@interface FKGenericTableViewCell : FKTableViewCell
+
++ (CGFloat)neededHeightForHeaderText:(NSString *)headerText
+ detailText:(NSString *)detailText
+ footerText:(NSString *)footerText
+ imageVisible:(BOOL)imageVisible
+ constrainedToWidth:(CGFloat)width;
+
+@property (nonatomic, strong) UIImage *image;
+
+@property (nonatomic, copy) NSString *headerText;
+@property (nonatomic, copy) NSString *detailText;
+@property (nonatomic, copy) NSString *footerText;
+
+- (void)setImageURL:(NSURL *)imageURL;
+
+@end
@@ -0,0 +1,268 @@
+#import "FKGenericTableViewCell.h"
+#import "FKIncludes.h"
+#import "UIImageView+AFNetworking.h"
+
+
+#define kFKPaddingX 5.f
+#define kFKPaddingYOutside 5.f
+#define kFKPaddingYInside 2.f
+#define kFKPaddingYImage kFKPaddingYOutside + kFKPaddingYInside
+#define kFKHeaderLineBreakMode UILineBreakModeWordWrap
+#define kFKDetailTextLineBreakMode UILineBreakModeWordWrap
+#define kFKFooterLineBreakMode UILineBreakModeWordWrap
+#define kFKImageViewRect CGRectMake(kFKPaddingX, kFKPaddingYImage, 55.f, 55.f)
+
+
+static UIFont *headerFont = nil;
+static UIFont *detailFont = nil;
+static UIFont *footerFont = nil;
+static UIImage *placeholderImage = nil;
+
+
+@interface FKGenericTableViewCell ()
+
+@property (nonatomic, strong) UIImageView *cellImageView;
+@property (nonatomic, readonly) BOOL imageVisible;
+
+@end
+
+
+@implementation FKGenericTableViewCell
+
+@synthesize headerText = _headerText;
+@synthesize detailText = _detailText;
+@synthesize footerText = _footerText;
+@synthesize cellImageView = _cellImageView;
+
+////////////////////////////////////////////////////////////////////////
+#pragma mark - Lifecycle
+////////////////////////////////////////////////////////////////////////
+
++ (void)initialize {
+ if (self == [FKGenericTableViewCell class]) {
+ static dispatch_once_t onceToken;
+ dispatch_once(&onceToken, ^{
+ headerFont = [UIFont boldSystemFontOfSize:16.f];
+ detailFont = [UIFont systemFontOfSize:14.f];
+ footerFont = [UIFont italicSystemFontOfSize:13.f];
+ // TODO: Set placeholder image
+ placeholderImage = [UIImage imageNamed:@"IMAGE"];
+ });
+ }
+}
+
+- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
+ if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) {
+ _cellImageView = [[UIImageView alloc] initWithFrame:kFKImageViewRect];
+ _cellImageView.clipsToBounds = YES;
+ _cellImageView.contentMode = UIViewContentModeScaleAspectFill;
+ _cellImageView.hidden = YES;
+
+ [self addSubview:_cellImageView];
+ }
+
+ return self;
+}
+
+////////////////////////////////////////////////////////////////////////
+#pragma mark - Class Methods
+////////////////////////////////////////////////////////////////////////
+
++ (CGFloat)neededHeightForHeaderText:(NSString *)headerText
+ detailText:(NSString *)detailText
+ footerText:(NSString *)footerText
+ imageVisible:(BOOL)imageVisible
+ constrainedToWidth:(CGFloat)width {
+ NSInteger numberOfVisibleLabels = 0;
+ CGFloat innerWidth = width - 2*kFKPaddingX;
+
+ if (imageVisible) {
+ innerWidth -= CGRectGetWidth(kFKImageViewRect) + kFKPaddingX;
+ }
+
+ CGSize constraint = CGSizeMake(innerWidth, CGFLOAT_MAX);
+
+ CGSize sizeHeaderText = [headerText sizeWithFont:headerFont
+ constrainedToSize:constraint
+ lineBreakMode:kFKHeaderLineBreakMode];
+ CGSize sizeDetailText = [detailText sizeWithFont:detailFont
+ constrainedToSize:constraint
+ lineBreakMode:kFKDetailTextLineBreakMode];
+ CGSize sizeFooterText = [footerText sizeWithFont:footerFont
+ constrainedToSize:constraint
+ lineBreakMode:kFKFooterLineBreakMode];
+
+ if (sizeHeaderText.height > 0.f) {
+ numberOfVisibleLabels++;
+ }
+
+ if (sizeDetailText.height > 0.f) {
+ numberOfVisibleLabels++;
+ }
+
+ if (sizeFooterText.height > 0.f) {
+ numberOfVisibleLabels++;
+ }
+
+ CGFloat computedHeight = (sizeHeaderText.height
+ + sizeDetailText.height
+ + sizeFooterText.height
+ + (numberOfVisibleLabels-1)*kFKPaddingYInside
+ + 2*kFKPaddingYOutside);
+
+ return imageVisible ? MAX(computedHeight, CGRectGetHeight(kFKImageViewRect) + 2*kFKPaddingYImage) : computedHeight;
+}
+
+////////////////////////////////////////////////////////////////////////
+#pragma mark - UIView
+////////////////////////////////////////////////////////////////////////
+
+- (void)layoutSubviews {
+ [super layoutSubviews];
+
+ // show/hide ImageView
+ if (self.cellImageView.image != nil) {
+ self.cellImageView.hidden = NO;
+ } else {
+ self.cellImageView.hidden = YES;
+ }
+}
+
+////////////////////////////////////////////////////////////////////////
+#pragma mark - UITableViewCell
+////////////////////////////////////////////////////////////////////////
+
+- (void)prepareForReuse {
+ [super prepareForReuse];
+
+ self.cellImageView.hidden = YES;
+ self.cellImageView.image = nil;
+ _headerText = nil;
+ _detailText = nil;
+ _footerText = nil;
+}
+
+////////////////////////////////////////////////////////////////////////
+#pragma mark - FKTableViewCell
+////////////////////////////////////////////////////////////////////////
+
+- (void)drawContentViewInRect:(CGRect)rect highlighted:(BOOL)highlighted {
+ CGContextRef context = UIGraphicsGetCurrentContext();
+ UIColor *headerTextColor = [UIColor blackColor];
+ UIColor *detailTextColor = [UIColor blackColor];
+ UIColor *footerTextColor = [UIColor darkGrayColor];
+ CGFloat textX = self.imageVisible ? self.cellImageView.frameRight + kFKPaddingX : kFKPaddingX;
+ CGFloat textRightPadding = 25.f;
+ CGFloat innerWidth = self.frameWidth - textX - textRightPadding;
+ CGPoint p = CGPointMake(textX, kFKPaddingYOutside);
+
+ // change colors when selected
+ if (highlighted) {
+ headerTextColor = [UIColor blackColor];
+ detailTextColor = [UIColor darkGrayColor];
+ footerTextColor = [UIColor darkGrayColor];
+
+ // draw gradient
+ CGGradientRef gradientRef = FKCreateGradientWithColors($array([UIColor whiteColor],
+ [UIColor lightGrayColor]));
+ FKDrawGradientInRect(context, gradientRef, rect);
+ CGGradientRelease(gradientRef);
+ } else {
+ // Only draw gradient on fast devices
+ if ([[UIDevice currentDevice] isCrappy]) {
+ [[UIColor whiteColor] set];
+ CGContextFillRect(context, rect);
+ } else {
+ CGGradientRef gradientRef = FKCreateGradientWithColors($array([UIColor whiteColor],
+ [UIColor whiteColor]));
+ FKDrawGradientInRect(context, gradientRef, rect);
+ CGGradientRelease(gradientRef);
+ }
+ }
+
+ // Draw Header Text
+ [headerTextColor set];
+ CGSize neededSize = [_headerText drawInRect:CGRectMake(p.x, p.y, innerWidth, CGFLOAT_MAX)
+ withFont:headerFont
+ lineBreakMode:kFKHeaderLineBreakMode
+ alignment:UITextAlignmentLeft];
+
+ p.y += neededSize.height + kFKPaddingYInside;
+
+ if (!$empty(_detailText)) {
+ // Draw Detail Text
+ [detailTextColor set];
+ neededSize = [_detailText drawInRect:CGRectMake(p.x, p.y, innerWidth, CGFLOAT_MAX)
+ withFont:detailFont
+ lineBreakMode:kFKDetailTextLineBreakMode
+ alignment:UITextAlignmentLeft];
+
+ p.y += neededSize.height + kFKPaddingYInside;
+ }
+
+ // Draw Footer Text?
+ if (!$empty(_footerText)) {
+ [footerTextColor set];
+ [_footerText drawInRect:CGRectMake(p.x, p.y, innerWidth, CGFLOAT_MAX)
+ withFont:footerFont
+ lineBreakMode:kFKFooterLineBreakMode
+ alignment:UITextAlignmentLeft];
+
+ }
+}
+
+////////////////////////////////////////////////////////////////////////
+#pragma mark - NDRTableViewCell
+////////////////////////////////////////////////////////////////////////
+
+- (void)setImage:(UIImage *)image {
+ self.cellImageView.image = image;
+}
+
+- (UIImage *)image {
+ return self.cellImageView.image;
+}
+
+- (void)setImageURL:(NSURL *)imageURL {
+ __unsafe_unretained FKGenericTableViewCell *weakSelf = self;
+
+ [self.cellImageView setImageWithURLRequest:[NSURLRequest requestWithURL:imageURL]
+ placeholderImage:placeholderImage
+ success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
+ [weakSelf.cellImageView setImage:image animated:YES];
+ } failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
+ weakSelf.cellImageView.image = placeholderImage;
+ }];
+}
+
+- (void)setHeaderText:(NSString *)headerText {
+ if (_headerText != headerText) {
+ _headerText = headerText;
+ [self setNeedsDisplay];
+ }
+}
+
+- (void)setDetailText:(NSString *)detailText {
+ if (_detailText != detailText) {
+ _detailText = detailText;
+ [self setNeedsDisplay];
+ }
+}
+
+- (void)setFooterText:(NSString *)footerText {
+ if (_footerText != footerText) {
+ _footerText = footerText;
+ [self setNeedsDisplay];
+ }
+}
+
+////////////////////////////////////////////////////////////////////////
+#pragma mark - Private
+////////////////////////////////////////////////////////////////////////
+
+- (BOOL)imageVisible {
+ return self.cellImageView.image != nil && self.cellImageView.hidden == NO;
+}
+
+
+@end
@@ -2,8 +2,8 @@
@implementation FKBaseCollapsableTableViewController
-$synthesize(expandedSections);
-$synthesize(minNumberOfRowsToCollapse);
+@synthesize expandedSections = _expandedSections;
+@synthesize minNumberOfRowsToCollapse = _minNumberOfRowsToCollapse;
////////////////////////////////////////////////////////////////////////
#pragma mark -
@@ -12,8 +12,8 @@ @implementation FKBaseCollapsableTableViewController
- (id)initWithStyle:(UITableViewStyle)style {
if ((self = [super initWithStyle:style])) {
- expandedSections_ = [[NSMutableIndexSet alloc] init];
- minNumberOfRowsToCollapse_ = 10;
+ _expandedSections = [[NSMutableIndexSet alloc] init];
+ _minNumberOfRowsToCollapse = 10;
}
return self;
Oops, something went wrong.

0 comments on commit f31a4ea

Please sign in to comment.