display the date on episodes

This commit is contained in:
Sami Samhuri 2012-03-24 10:59:20 -07:00
parent 0cf01b669f
commit 22f6126f66
5 changed files with 27 additions and 12 deletions

View file

@ -8,17 +8,20 @@
#import <Foundation/Foundation.h>
#import "Show.h"
#import "MWFeedItem.h"
@class Show;
@interface Episode : NSObject
@property (nonatomic, retain) NSDate *date;
@property (nonatomic, retain) NSString *name;
@property (nonatomic, retain) NSString *number;
@property (nonatomic, retain) Show *show;
@property (nonatomic, retain) NSURL *url;
+ (id) episodeWithShow: (Show *)show name: (NSString *)name number: (NSString *)number url: (NSURL *)url;
- (id) initWithShow: (Show *)show name: (NSString *)name number: (NSString *)number url: (NSURL *)url;
+ (id) episodeWithShow: (Show *)show feedItem: (MWFeedItem *)item;
+ (id) episodeWithShow: (Show *)show name: (NSString *)name number: (NSString *)number date: (NSDate *)date url: (NSURL *)url;
- (id) initWithShow: (Show *)show name: (NSString *)name number: (NSString *)number date: (NSDate *)date url: (NSURL *)url;
@end

View file

@ -10,23 +10,30 @@
@implementation Episode
@synthesize date = _date;
@synthesize name = _name;
@synthesize number = _number;
@synthesize show = _show;
@synthesize url = _url;
+ (id) episodeWithShow: (Show *)show name: (NSString *)name number: (NSString *)number url: (NSURL *)url
+ (id) episodeWithShow: (Show *)show feedItem: (MWFeedItem *)item
{
return [[self alloc] initWithShow: show name: name number: number url: url];
return [[self alloc] initWithShow: show name: item.title number: @"<n>" date: item.date url: [NSURL URLWithString: item.link]];
}
- (id) initWithShow: (Show *)show name: (NSString *)name number: (NSString *)number url: (NSURL *)url
+ (id) episodeWithShow: (Show *)show name: (NSString *)name number: (NSString *)number date: (NSDate *)date url: (NSURL *)url
{
return [[self alloc] initWithShow: show name: name number: number date: date url: url];
}
- (id) initWithShow: (Show *)show name: (NSString *)name number: (NSString *)number date: (NSDate *)date url: (NSURL *)url
{
self = [super init];
if (self) {
self.show = show;
self.name = name;
self.number = number;
self.date = date;
self.url = url;
}
return self;

View file

@ -10,6 +10,7 @@
#import "SSMasterViewController.h"
#import "Show.h"
#import "NSString+marshmallows.h"
#import "NSDate+relative.h"
@implementation SSMasterViewController
@ -155,7 +156,7 @@
cell.textLabel.text = show.name;
cell.imageView.image = show.image;
if (show.episodes.count > 0) {
cell.detailTextLabel.text = [NSString stringWithFormat: @"%d episodes", show.episodes.count];
cell.detailTextLabel.text = [[[[show episodes] objectAtIndex: 0] date] relativeToNow];
}
else {
cell.detailTextLabel.text = nil;
@ -168,7 +169,7 @@
{
if (self.currentShow && indexPath.section == 0) {
NSURL *url = [NSURL URLWithString: [self.currentShow webURLForEpisodeNumber: self.currentEpisodeNumber]];
Episode *episode = [Episode episodeWithShow: self.currentShow name: self.currentEpisodeName number: self.currentEpisodeNumber url: url];
Episode *episode = [Episode episodeWithShow: self.currentShow name: self.currentEpisodeName number: self.currentEpisodeNumber date: nil url: url];
self.showViewController.detailViewController.episode = episode;
[self.navigationController pushViewController: self.showViewController.detailViewController animated: YES];
}
@ -182,6 +183,7 @@
- (void) gotEpisodesForShow: (Show *)show
{
self.selectedCell.detailTextLabel.text = [[[[show episodes] objectAtIndex: 0] date] relativeToNow];
self.showViewController.show = show;
[self.navigationController pushViewController: self.showViewController animated: YES];
}

View file

@ -94,7 +94,7 @@
- (void) feedParser: (MWFeedParser *)parser didParseFeedItem: (MWFeedItem *)item
{
// NSLog(@"feed item: %@", item);
[self addEpisode: [Episode episodeWithShow: self name: item.title number: @"<n>" url: [NSURL URLWithString: item.link]]];
[self addEpisode: [Episode episodeWithShow: self feedItem: item]];
}
- (void) feedParserDidFinish: (MWFeedParser *)parser

View file

@ -9,6 +9,7 @@
#import "ShowViewController.h"
#import "SSDetailViewController.h"
#import "Episode.h"
#import "NSDate+relative.h"
@interface ShowViewController ()
@ -76,17 +77,19 @@
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell = [[UITableViewCell alloc] initWithStyle: UITableViewCellStyleSubtitle reuseIdentifier: CellIdentifier];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
cell.textLabel.adjustsFontSizeToFitWidth = YES;
cell.textLabel.textColor = [UIColor darkGrayColor];
}
Episode *episode = [self.show.episodes objectAtIndex: indexPath.row];
cell.textLabel.text = episode.name;
cell.detailTextLabel.text = [episode.date relativeToNow];
return cell;
}
@ -95,7 +98,7 @@
Episode *episode = [self.show.episodes objectAtIndex: indexPath.row];
self.detailViewController.episode = episode;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
[self.navigationController pushViewController: self.detailViewController animated:YES];
[self.navigationController pushViewController: self.detailViewController animated: YES];
}
}