Skip to content

Commit

Permalink
Add a cell for the season episodes table view which delegates updatin…
Browse files Browse the repository at this point in the history
…g of episode.seen to the controller when a checkbox is clicked.
  • Loading branch information
alloy committed Mar 19, 2011
1 parent 962d4ce commit b2cdfe3
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 63 deletions.
69 changes: 13 additions & 56 deletions Classes/Controllers/SeasonsViewController.m
Expand Up @@ -4,6 +4,7 @@
#import "EpisodeDetailsViewController.h"
#import "Checkbox.h"
#import "HTTPDownload.h"
#import "SeasonsEpisodeCell.h"

@implementation SeasonsViewController

Expand Down Expand Up @@ -100,74 +101,30 @@ - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInte
}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *cellIdentifier = @"episodeCell";
UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
static NSString *cellIdentifier = @"seasonsEpisodeCell";
SeasonsEpisodeCell *cell = (SeasonsEpisodeCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];

if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier] autorelease];
cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
cell.textLabel.numberOfLines = 0;
cell.textLabel.minimumFontSize = [UIFont systemFontSize];
cell.textLabel.font = [UIFont systemFontOfSize:[UIFont systemFontSize]];

Checkbox *cb = [[Checkbox alloc] initWithFrame:CGRectMake(7, 7, 28, 28)];
[cell addSubview:cb];
[cb release];
cell = [[[SeasonsEpisodeCell alloc] initWithReuseIdentifier:cellIdentifier delegate:self] autorelease];
}

Season *season = [seasons objectAtIndex:indexPath.section];
Episode *episode = [season.episodes objectAtIndex:indexPath.row];
if (episode.seen) {
cell.textLabel.text = [NSString stringWithFormat:@"%@", episode.title];
} else {
cell.textLabel.text = episode.title;
}
[cell updateCellWithEpisode:episode];
return cell;
}


/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
// Return NO if you do not want the specified item to be editable.
return YES;
}
*/


/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source.
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
}
}
*/


/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/


/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
// Return NO if you do not want the item to be re-orderable.
return YES;
- (void)checkboxClicked:(Checkbox *)checkbox {
SeasonsEpisodeCell *cell = (SeasonsEpisodeCell *)checkbox.superview.superview;
NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
Season *season = [seasons objectAtIndex:indexPath.section];
Episode *episode = [season.episodes objectAtIndex:indexPath.row];
[episode toggleSeen:^{
checkbox.selected = episode.seen;
}];
}
*/


#pragma mark -
#pragma mark Table view delegate
Expand Down
7 changes: 0 additions & 7 deletions Classes/Views/Checkbox.m
Expand Up @@ -107,16 +107,13 @@ @implementation Checkbox

- (id)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
//NSLog(@"Complete frame %@", NSStringFromCGRect(frame));
CALayer *layer = self.layer;

drawing = [CheckboxDrawing new];
drawing.frame = CGRectMake(0, 0, 21, 21);
[layer addSublayer:drawing];

self.selected = NO;

[self addTarget:self action:@selector(checkboxClicked:) forControlEvents:UIControlEventTouchUpInside];
}
return self;
}
Expand All @@ -126,10 +123,6 @@ - (void)setSelected:(BOOL)flag {
drawing.selected = flag;
}

- (void)checkboxClicked:(id)sender {
self.selected = !self.selected;
}

- (void)dealloc {
[drawing release];
[super dealloc];
Expand Down
14 changes: 14 additions & 0 deletions Classes/Views/SeasonsEpisodeCell.h
@@ -0,0 +1,14 @@
#import <UIKit/UIKit.h>

@class Checkbox;
@class Episode;

@interface SeasonsEpisodeCell : UITableViewCell {
Checkbox *checkbox;
UILabel *titleLabel;
}

- (id)initWithReuseIdentifier:(NSString *)reuseIdentifier delegate:(id)delegate;
- (void)updateCellWithEpisode:(Episode *)episode;

@end
45 changes: 45 additions & 0 deletions Classes/Views/SeasonsEpisodeCell.m
@@ -0,0 +1,45 @@
#import "SeasonsEpisodeCell.h"
#import "Checkbox.h"
#import "Episode.h"

@implementation SeasonsEpisodeCell

- (id)initWithReuseIdentifier:(NSString *)reuseIdentifier delegate:(id)delegate {
if (self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier]) {
checkbox = [[Checkbox alloc] initWithFrame:CGRectMake(7, 7, 28, 28)];
[checkbox addTarget:delegate action:@selector(checkboxClicked:) forControlEvents:UIControlEventTouchUpInside];
[self.contentView addSubview:checkbox];

titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(42, 7, self.bounds.size.width - 42, 28)];
titleLabel.lineBreakMode = UILineBreakModeWordWrap;
titleLabel.numberOfLines = 0;
titleLabel.minimumFontSize = [UIFont systemFontSize];
titleLabel.font = [UIFont systemFontOfSize:[UIFont systemFontSize]];
[self.contentView addSubview:titleLabel];
}
return self;
}


- (void)updateCellWithEpisode:(Episode *)episode {
checkbox.selected = episode.seen;
titleLabel.text = episode.title;
}


//- (void)setSelected:(BOOL)selected animated:(BOOL)animated {

//[super setSelected:selected animated:animated];

//// Configure the view for the selected state.
//}


- (void)dealloc {
[checkbox release];
[titleLabel release];
[super dealloc];
}


@end
1 change: 1 addition & 0 deletions TODO.md
Expand Up @@ -4,6 +4,7 @@ General
* Research which OSS license the app should have and that we adhere to the licenses of APIs.
TVDB: http://forums.thetvdb.com/viewtopic.php?f=8&t=2507

* Add -[NSArray objectAtIndexPath:] and refactor controllers.
* Probably not really necessary to do things like: [[shows copy] autorelease] in Trakt.m
* Rename -[Episode initWithDictionary:] to initWithEpisodeInfo and same for -[Show initWithDictionary:].
* Episode watched field in the calendar feed is outside of the episode hash.
Expand Down
6 changes: 6 additions & 0 deletions iTrakt.xcodeproj/project.pbxproj
Expand Up @@ -100,6 +100,7 @@
5181A1C31306EB4800B3761A /* AsyncImageTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5181A1C21306EB4800B3761A /* AsyncImageTableViewController.m */; };
518D6768131EF7260086143B /* Checkbox.m in Sources */ = {isa = PBXBuildFile; fileRef = 518D6767131EF7260086143B /* Checkbox.m */; };
518D6799131F030D0086143B /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 518D6798131F030D0086143B /* QuartzCore.framework */; };
51BFFAEB13350CF1006EBF54 /* SeasonsEpisodeCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 51BFFAEA13350CF1006EBF54 /* SeasonsEpisodeCell.m */; };
51FBCC9712EA375500073C68 /* EpisodeTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 51FBCC9612EA375500073C68 /* EpisodeTableViewCell.m */; };
51FBCC9A12EA391B00073C68 /* Episode.m in Sources */ = {isa = PBXBuildFile; fileRef = 51FBCC9912EA391B00073C68 /* Episode.m */; };
/* End PBXBuildFile section */
Expand Down Expand Up @@ -225,6 +226,8 @@
518D6766131EF7260086143B /* Checkbox.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Checkbox.h; path = Views/Checkbox.h; sourceTree = "<group>"; };
518D6767131EF7260086143B /* Checkbox.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Checkbox.m; path = Views/Checkbox.m; sourceTree = "<group>"; };
518D6798131F030D0086143B /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
51BFFAE913350CF1006EBF54 /* SeasonsEpisodeCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SeasonsEpisodeCell.h; path = Views/SeasonsEpisodeCell.h; sourceTree = "<group>"; };
51BFFAEA13350CF1006EBF54 /* SeasonsEpisodeCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SeasonsEpisodeCell.m; path = Views/SeasonsEpisodeCell.m; sourceTree = "<group>"; };
51FBCC9512EA375500073C68 /* EpisodeTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = EpisodeTableViewCell.h; path = Views/EpisodeTableViewCell.h; sourceTree = "<group>"; };
51FBCC9612EA375500073C68 /* EpisodeTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = EpisodeTableViewCell.m; path = Views/EpisodeTableViewCell.m; sourceTree = "<group>"; };
51FBCC9812EA391B00073C68 /* Episode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Episode.h; path = Models/Episode.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -472,6 +475,8 @@
51FBCC9612EA375500073C68 /* EpisodeTableViewCell.m */,
518D6766131EF7260086143B /* Checkbox.h */,
518D6767131EF7260086143B /* Checkbox.m */,
51BFFAE913350CF1006EBF54 /* SeasonsEpisodeCell.h */,
51BFFAEA13350CF1006EBF54 /* SeasonsEpisodeCell.m */,
);
name = Views;
sourceTree = "<group>";
Expand Down Expand Up @@ -662,6 +667,7 @@
511EE73A13192A6B0000B12D /* Base64.m in Sources */,
511EE7C6131969F00000B12D /* Season.m in Sources */,
518D6768131EF7260086143B /* Checkbox.m in Sources */,
51BFFAEB13350CF1006EBF54 /* SeasonsEpisodeCell.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down

0 comments on commit b2cdfe3

Please sign in to comment.