Skip to content

Commit

Permalink
Refactor table cells.
Browse files Browse the repository at this point in the history
  • Loading branch information
kishikawakatsumi committed Aug 29, 2009
1 parent 5d5420c commit 34d9c17
Show file tree
Hide file tree
Showing 12 changed files with 219 additions and 88 deletions.
14 changes: 8 additions & 6 deletions Classes/MyBookmarkCell.h
@@ -1,13 +1,15 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>


@interface MyBookmarkCell : UITableViewCell { @interface MyBookmarkCell : UITableViewCell {
IBOutlet UILabel *titleLabel; NSString *titleText;
IBOutlet UILabel *linkLabel; NSString *linkText;
IBOutlet UILabel *numberLabel; NSString *numberText;
} }


@property (nonatomic, retain) UILabel *titleLabel; @property (nonatomic, retain) NSString *titleText;
@property (nonatomic, retain) UILabel *linkLabel; @property (nonatomic, retain) NSString *linkText;
@property (nonatomic, retain) UILabel *numberLabel; @property (nonatomic, retain) NSString *numberText;

- (void)drawSelectedBackgroundRect:(CGRect)rect;


@end @end
96 changes: 67 additions & 29 deletions Classes/MyBookmarkCell.m
@@ -1,50 +1,88 @@
#import "MyBookmarkCell.h" #import "MyBookmarkCell.h"
#import "MyBookmarkCellSelectedBackgroundView.h"
#import "TableCellDrawing.h"


@implementation MyBookmarkCell @implementation MyBookmarkCell


@synthesize titleLabel; @synthesize titleText;
@synthesize linkLabel; @synthesize linkText;
@synthesize numberLabel; @synthesize numberText;

static UIColor *blueColor = NULL;
static UIColor *darkGrayColor = NULL;

+ (void)initialize {
blueColor = [[UIColor colorWithRed:0.0f green:0.2f blue:1.0f alpha:1.0f] retain];
darkGrayColor = [[UIColor colorWithRed:0.2f green:0.2f blue:0.2f alpha:1.0f] retain];
}

- (void)setTitleText:(NSString *)text {
if (titleText != text) {
[titleText release];
titleText = [text retain];
[self setNeedsDisplay];
}
}

- (void)setLinkText:(NSString *)text {
if (linkText != text) {
[linkText release];
linkText = [text retain];
[self setNeedsDisplay];
}
}

- (void)setNumberText:(NSString *)text {
if (numberText != text) {
[numberText release];
numberText = [text retain];
[self setNeedsDisplay];
}
}


- (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier { - (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithFrame:frame reuseIdentifier:reuseIdentifier]) { if (self = [super initWithFrame:frame reuseIdentifier:reuseIdentifier]) {
[self setAccessoryType:UITableViewCellAccessoryDisclosureIndicator]; [self setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
[self setOpaque:YES]; [self setOpaque:YES];


titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(20.0f, 5.0f, 277.0f, 37.0f)]; MyBookmarkCellSelectedBackgroundView *selectedBackgroundView = [[MyBookmarkCellSelectedBackgroundView alloc] initWithFrame:[self frame]];
[titleLabel setOpaque:YES]; [selectedBackgroundView setCell:self];
[titleLabel setNumberOfLines:2]; [self setSelectedBackgroundView:selectedBackgroundView];
[titleLabel setFont:[UIFont boldSystemFontOfSize:14.0f]]; [selectedBackgroundView release];
[titleLabel setTextColor:[UIColor colorWithRed:0.0f green:0.2f blue:1.0f alpha:1.0f]];
[titleLabel setHighlightedTextColor:[UIColor whiteColor]];
[self addSubview:titleLabel];

linkLabel = [[UILabel alloc] initWithFrame:CGRectMake(20.0f, 42.0f, 277.0f, 26.0f)];
[linkLabel setOpaque:YES];
[linkLabel setFont:[UIFont systemFontOfSize:12.0f]];
[linkLabel setTextColor:[UIColor colorWithRed:0.2f green:0.2f blue:0.2f alpha:1.0f]];
[linkLabel setHighlightedTextColor:[UIColor whiteColor]];
[self addSubview:linkLabel];

numberLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 25.0f, 16.0f, 21.0f)];
[numberLabel setOpaque:YES];
[numberLabel setFont:[UIFont systemFontOfSize:9.0f]];
[numberLabel setTextAlignment:UITextAlignmentRight];
[numberLabel setTextColor:[UIColor blackColor]];
[numberLabel setHighlightedTextColor:[UIColor whiteColor]];
[self addSubview:numberLabel];
} }
return self; return self;
} }


- (void)setSelected:(BOOL)selected animated:(BOOL)animated { - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated]; [super setSelected:selected animated:animated];
[self setNeedsDisplay];
[self.selectedBackgroundView setNeedsDisplay];
}

- (void)drawRect:(CGRect)rect {
[super drawRect:rect];
[blueColor set];
[titleText drawInRect:CGRectMake(20.0f, 5.0f, 277.0f, 37.0f) withFont:[UIFont boldSystemFontOfSize:14.0f] lineBreakMode:UILineBreakModeTailTruncation];
[darkGrayColor set];
[linkText drawInRect:CGRectMake(20.0f, 46.0f, 277.0f, 26.0f) withFont:[UIFont systemFontOfSize:12.0f] lineBreakMode:UILineBreakModeTailTruncation];
[[UIColor blackColor] set];
[numberText drawInRect:CGRectMake(0.0f, 28.0f, 16.0f, 21.0f) withFont:[UIFont systemFontOfSize:9.0f] lineBreakMode:UILineBreakModeClip alignment:UITextAlignmentRight];
}

- (void)drawSelectedBackgroundRect:(CGRect)rect {
CGGradientRef gradientForSelected = createTwoColorsGradient(5, 140, 245, 1, 93, 230);
drawRoundedRectBackgroundGradient(rect, gradientForSelected, NO, NO, NO);
CGGradientRelease(gradientForSelected);
[[UIColor whiteColor] set];
[titleText drawInRect:CGRectMake(20.0f, 5.0f, 277.0f, 37.0f) withFont:[UIFont boldSystemFontOfSize:14.0f] lineBreakMode:UILineBreakModeTailTruncation];
[linkText drawInRect:CGRectMake(20.0f, 46.0f, 277.0f, 26.0f) withFont:[UIFont systemFontOfSize:12.0f] lineBreakMode:UILineBreakModeTailTruncation];
[numberText drawInRect:CGRectMake(0.0f, 28.0f, 16.0f, 21.0f) withFont:[UIFont systemFontOfSize:9.0f] lineBreakMode:UILineBreakModeClip alignment:UITextAlignmentRight];
} }


- (void)dealloc { - (void)dealloc {
[titleLabel release]; [titleText release];
[linkLabel release]; [linkText release];
[numberLabel release]; [numberText release];
[super dealloc]; [super dealloc];
} }


Expand Down
19 changes: 19 additions & 0 deletions Classes/MyBookmarkCellSelectedBackgroundView.h
@@ -0,0 +1,19 @@
//
// MyBookmarkCellSelectedBackgroundView.h
// HatenaTouch
//
// Created by KISHIKAWA Katsumi on 09/08/30.
// Copyright 2009 KISHIKAWA Katsumi. All rights reserved.
//

#import <UIKit/UIKit.h>

@class MyBookmarkCell;

@interface MyBookmarkCellSelectedBackgroundView : UITableViewCell {
MyBookmarkCell *cell;
}

@property (nonatomic, assign) MyBookmarkCell *cell;

@end
24 changes: 24 additions & 0 deletions Classes/MyBookmarkCellSelectedBackgroundView.m
@@ -0,0 +1,24 @@
//
// MyBookmarkCellSelectedBackgroundView.m
// HatenaTouch
//
// Created by KISHIKAWA Katsumi on 09/08/30.
// Copyright 2009 KISHIKAWA Katsumi. All rights reserved.
//

#import "MyBookmarkCellSelectedBackgroundView.h"
#import "MyBookmarkCell.h"

@implementation MyBookmarkCellSelectedBackgroundView

@synthesize cell;

- (void)drawRect:(CGRect)rect {
[cell drawSelectedBackgroundRect:rect];
}

- (void)dealloc {
[super dealloc];
}

@end
2 changes: 2 additions & 0 deletions Classes/MyBookmarkNextCell.h
Expand Up @@ -2,4 +2,6 @@


@interface MyBookmarkNextCell : UITableViewCell @interface MyBookmarkNextCell : UITableViewCell


- (void)drawSelectedBackgroundRect:(CGRect)rect;

@end @end
37 changes: 37 additions & 0 deletions Classes/MyBookmarkNextCell.m
@@ -1,9 +1,46 @@
#import "MyBookmarkNextCell.h" #import "MyBookmarkNextCell.h"
#import "MyBookmarkNextCellSelectedBackgroundView.h"
#import "TableCellDrawing.h"


@implementation MyBookmarkNextCell @implementation MyBookmarkNextCell


static NSString *cellText;

+ (void)initialize {
cellText = NSLocalizedString(@"Read Next 20 Entries...", nil);
}

- (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithFrame:frame reuseIdentifier:reuseIdentifier]) {
[self setAccessoryType:UITableViewCellAccessoryNone];
[self setOpaque:YES];

MyBookmarkNextCellSelectedBackgroundView *selectedBackgroundView = [[MyBookmarkNextCellSelectedBackgroundView alloc] initWithFrame:[self frame]];
[selectedBackgroundView setCell:self];
[self setSelectedBackgroundView:selectedBackgroundView];
[selectedBackgroundView release];
}
return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated { - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated]; [super setSelected:selected animated:animated];
[self setNeedsDisplay];
[self.selectedBackgroundView setNeedsDisplay];
}

- (void)drawRect:(CGRect)rect {
[super drawRect:rect];
[[UIColor blackColor] set];
[cellText drawInRect:CGRectMake(20.0f, 24.0f, 280.0f, 21.0f) withFont:[UIFont boldSystemFontOfSize:17.0f] lineBreakMode:UILineBreakModeClip alignment:UITextAlignmentCenter];
}

- (void)drawSelectedBackgroundRect:(CGRect)rect {
CGGradientRef gradientForSelected = createTwoColorsGradient(5, 140, 245, 1, 93, 230);
drawRoundedRectBackgroundGradient(rect, gradientForSelected, NO, NO, NO);
CGGradientRelease(gradientForSelected);
[[UIColor whiteColor] set];
[cellText drawInRect:CGRectMake(20.0f, 24.0f, 280.0f, 21.0f) withFont:[UIFont boldSystemFontOfSize:17.0f] lineBreakMode:UILineBreakModeClip alignment:UITextAlignmentCenter];
} }


- (void)dealloc { - (void)dealloc {
Expand Down
19 changes: 19 additions & 0 deletions Classes/MyBookmarkNextCellSelectedBackgroundView.h
@@ -0,0 +1,19 @@
//
// MyBookmarkNextCellSelectedBackgroundView.h
// HatenaTouch
//
// Created by KISHIKAWA Katsumi on 09/08/30.
// Copyright 2009 KISHIKAWA Katsumi. All rights reserved.
//

#import <UIKit/UIKit.h>

@class MyBookmarkNextCell;

@interface MyBookmarkNextCellSelectedBackgroundView : UITableViewCell {
MyBookmarkNextCell *cell;
}

@property (nonatomic, assign) MyBookmarkNextCell *cell;

@end
24 changes: 24 additions & 0 deletions Classes/MyBookmarkNextCellSelectedBackgroundView.m
@@ -0,0 +1,24 @@
//
// MyBookmarkNextCellSelectedBackgroundView.m
// HatenaTouch
//
// Created by KISHIKAWA Katsumi on 09/08/30.
// Copyright 2009 KISHIKAWA Katsumi. All rights reserved.
//

#import "MyBookmarkNextCellSelectedBackgroundView.h"
#import "MyBookmarkNextCell.h"

@implementation MyBookmarkNextCellSelectedBackgroundView

@synthesize cell;

- (void)drawRect:(CGRect)rect {
[cell drawSelectedBackgroundRect:rect];
}

- (void)dealloc {
[super dealloc];
}

@end
32 changes: 7 additions & 25 deletions Classes/MyBookmarkViewController.m
Expand Up @@ -4,7 +4,6 @@
#import "HatenaTouchAppDelegate.h" #import "HatenaTouchAppDelegate.h"
#import "WebViewController.h" #import "WebViewController.h"
#import "HatenaAtomPub.h" #import "HatenaAtomPub.h"
#import "MyBookmarkNextCellController.h";
#import "MyBookmarkNextCell.h" #import "MyBookmarkNextCell.h"
#import "Debug.h" #import "Debug.h"


Expand All @@ -16,13 +15,6 @@ @implementation MyBookmarkViewController
@synthesize myBookmarks; @synthesize myBookmarks;
@synthesize selectedRow; @synthesize selectedRow;


- (id)initWithStyle:(UITableViewStyle)style {
if (self = [super initWithStyle:style]) {
;
}
return self;
}

- (void)dealloc { - (void)dealloc {
[selectedRow release]; [selectedRow release];
[myBookmarks release]; [myBookmarks release];
Expand Down Expand Up @@ -72,10 +64,8 @@ - (void)refleshIfNeeded {
} }


- (void)loadNext { - (void)loadNext {
[myBookmarks release];
myBookmarks = nil;
offset += FEED_OFFSET; offset += FEED_OFFSET;
[self refleshIfNeeded]; [self loadMyBookmarks];
} }


- (BOOL)deleteEntry:(NSDictionary *)entry { - (BOOL)deleteEntry:(NSDictionary *)entry {
Expand All @@ -99,20 +89,16 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger
NSInteger count = [myBookmarks count]; NSInteger count = [myBookmarks count];
if (count == 0) { if (count == 0) {
return 0; return 0;
} else if (count == FEED_OFFSET) {
return count + 1;
} else { } else {
return count; return count + 1;
} }
} }


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == [myBookmarks count]) { if (indexPath.row == [myBookmarks count]) {
MyBookmarkNextCell *cell = (MyBookmarkNextCell *)[tableView dequeueReusableCellWithIdentifier:@"MyBookmarkNextCell"]; MyBookmarkNextCell *cell = (MyBookmarkNextCell *)[tableView dequeueReusableCellWithIdentifier:@"MyBookmarkNextCell"];
if (cell == nil) { if (cell == nil) {
MyBookmarkNextCellController *controller = [[MyBookmarkNextCellController alloc] initWithNibName:@"MyBookmarkNextCell" bundle:nil]; cell = [[[MyBookmarkNextCell alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 70.0f) reuseIdentifier:@"MyBookmarkNextCell"] autorelease];
cell = (MyBookmarkNextCell *)controller.view;
[controller release];
} }


return cell; return cell;
Expand All @@ -123,9 +109,9 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
} }


NSDictionary *entry = [myBookmarks objectAtIndex:indexPath.row]; NSDictionary *entry = [myBookmarks objectAtIndex:indexPath.row];
[cell.titleLabel setText:[entry objectForKey:@"title"]]; [cell setTitleText:[entry objectForKey:@"title"]];
[cell.linkLabel setText:[entry objectForKey:@"related"]]; [cell setLinkText:[entry objectForKey:@"related"]];
[cell.numberLabel setText:[NSString stringWithFormat:@"%d", indexPath.row +1]]; [cell setNumberText:[NSString stringWithFormat:@"%d", indexPath.row +1]];


return cell; return cell;
} }
Expand All @@ -139,7 +125,7 @@ - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInte
#pragma mark <UITableViewDelegate> Methods #pragma mark <UITableViewDelegate> Methods


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == FEED_OFFSET) { if (indexPath.row == [myBookmarks count]) {
[self loadNext]; [self loadNext];
[tableView deselectRowAtIndexPath:indexPath animated:YES]; [tableView deselectRowAtIndexPath:indexPath animated:YES];
} else { } else {
Expand Down Expand Up @@ -185,10 +171,6 @@ - (void)viewWillAppear:(BOOL)animated {
[self refleshIfNeeded]; [self refleshIfNeeded];
} }


- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
}

- (void)didReceiveMemoryWarning { - (void)didReceiveMemoryWarning {
LOG_CURRENT_METHOD; LOG_CURRENT_METHOD;
[super didReceiveMemoryWarning]; [super didReceiveMemoryWarning];
Expand Down
Binary file modified English.lproj/Localizable.strings
Binary file not shown.

0 comments on commit 34d9c17

Please sign in to comment.