diff --git a/5by5Browser.xcodeproj/project.pbxproj b/5by5Browser.xcodeproj/project.pbxproj index d5fe9de..7f41974 100644 --- a/5by5Browser.xcodeproj/project.pbxproj +++ b/5by5Browser.xcodeproj/project.pbxproj @@ -47,6 +47,7 @@ 7B730305149D6714003547E5 /* MWFeedParser_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 7B7302FE149D6714003547E5 /* MWFeedParser_Private.h */; }; 7B730306149D6714003547E5 /* MWFeedParser.h in Headers */ = {isa = PBXBuildFile; fileRef = 7B7302FF149D6714003547E5 /* MWFeedParser.h */; }; 7B730307149D6714003547E5 /* MWFeedParser.m in Sources */ = {isa = PBXBuildFile; fileRef = 7B730300149D6714003547E5 /* MWFeedParser.m */; }; + 7B81722014B137D6003EC770 /* MediaPlayer.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7B81721F14B137D6003EC770 /* MediaPlayer.framework */; }; 7B868946149D593C00F3A2C6 /* Episode.m in Sources */ = {isa = PBXBuildFile; fileRef = 7B868945149D593C00F3A2C6 /* Episode.m */; }; 7B86894B149D5C1000F3A2C6 /* ShowViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7B868949149D5C0F00F3A2C6 /* ShowViewController.m */; }; 7B868951149D5C6F00F3A2C6 /* ShowViewController_iPad.xib in Resources */ = {isa = PBXBuildFile; fileRef = 7B86894D149D5C6F00F3A2C6 /* ShowViewController_iPad.xib */; }; @@ -108,6 +109,7 @@ 7B7302FE149D6714003547E5 /* MWFeedParser_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MWFeedParser_Private.h; sourceTree = ""; }; 7B7302FF149D6714003547E5 /* MWFeedParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MWFeedParser.h; sourceTree = ""; }; 7B730300149D6714003547E5 /* MWFeedParser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MWFeedParser.m; sourceTree = ""; }; + 7B81721F14B137D6003EC770 /* MediaPlayer.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MediaPlayer.framework; path = System/Library/Frameworks/MediaPlayer.framework; sourceTree = SDKROOT; }; 7B868944149D593C00F3A2C6 /* Episode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Episode.h; sourceTree = ""; }; 7B868945149D593C00F3A2C6 /* Episode.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Episode.m; sourceTree = ""; }; 7B868948149D5C0F00F3A2C6 /* ShowViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ShowViewController.h; sourceTree = ""; }; @@ -128,6 +130,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 7B81722014B137D6003EC770 /* MediaPlayer.framework in Frameworks */, 7B4CADE9149FE797007E7941 /* Security.framework in Frameworks */, 7B1A6ECF149D140600FC5105 /* UIKit.framework in Frameworks */, 7B1A6ED1149D140600FC5105 /* Foundation.framework in Frameworks */, @@ -160,6 +163,7 @@ 7B1A6ECD149D140600FC5105 /* Frameworks */ = { isa = PBXGroup; children = ( + 7B81721F14B137D6003EC770 /* MediaPlayer.framework */, 7B4CADE8149FE797007E7941 /* Security.framework */, 7B1A6ECE149D140600FC5105 /* UIKit.framework */, 7B1A6ED0149D140600FC5105 /* Foundation.framework */, diff --git a/5by5Browser.xcodeproj/project.xcworkspace/xcuserdata/sjs.xcuserdatad/UserInterfaceState.xcuserstate b/5by5Browser.xcodeproj/project.xcworkspace/xcuserdata/sjs.xcuserdatad/UserInterfaceState.xcuserstate index 620947a..5398521 100644 Binary files a/5by5Browser.xcodeproj/project.xcworkspace/xcuserdata/sjs.xcuserdatad/UserInterfaceState.xcuserstate and b/5by5Browser.xcodeproj/project.xcworkspace/xcuserdata/sjs.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/5by5Browser/FiveByFive.h b/5by5Browser/FiveByFive.h index 5ea8615..6dcf4d3 100644 --- a/5by5Browser/FiveByFive.h +++ b/5by5Browser/FiveByFive.h @@ -17,5 +17,6 @@ - (id) initWithBaseURL: (NSString *)baseURL; - (void) addShow: (Show *)show; +- (Show *) showWithName: (NSString *)name; @end diff --git a/5by5Browser/FiveByFive.m b/5by5Browser/FiveByFive.m index 54fdb98..82b9fd2 100644 --- a/5by5Browser/FiveByFive.m +++ b/5by5Browser/FiveByFive.m @@ -30,4 +30,12 @@ [self.shows addObject: show]; } +- (Show *) showWithName: (NSString *)name +{ + for (Show *show in self.shows) { + if ([show.name isEqualToString: name]) return show; + } + return nil; +} + @end diff --git a/5by5Browser/SSAppDelegate.m b/5by5Browser/SSAppDelegate.m index 60bbed7..14369ea 100644 --- a/5by5Browser/SSAppDelegate.m +++ b/5by5Browser/SSAppDelegate.m @@ -24,12 +24,12 @@ self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; FiveByFive *fiveByFive = [[FiveByFive alloc] initWithBaseURL: @"http:/feeds.feedburner.com/"]; - [fiveByFive addShow: [Show showWithName: @"Back to Work" path: @"back2work"]]; - [fiveByFive addShow: [Show showWithName: @"Build and Analyze" path: @"buildanalyze"]]; - [fiveByFive addShow: [Show showWithName: @"The Critical Path" path: @"criticalpath"]]; - [fiveByFive addShow: [Show showWithName: @"Geek Friday" path: @"GeekFriday"]]; - [fiveByFive addShow: [Show showWithName: @"Hypercritical" path: @"hypercritical"]]; - [fiveByFive addShow: [Show showWithName: @"The Talk Show" path: @"thetalkshow"]]; + [fiveByFive addShow: [Show showWithName: @"Back to Work" feedPath: @"back2work" webPath: @"b2w"]]; + [fiveByFive addShow: [Show showWithName: @"Build and Analyze" feedPath: @"buildanalyze" webPath: @"buildanalyze"]]; + [fiveByFive addShow: [Show showWithName: @"The Critical Path" feedPath: @"criticalpath" webPath: @"criticalpath"]]; + [fiveByFive addShow: [Show showWithName: @"Geek Friday" feedPath: @"GeekFriday" webPath: @"geekfriday"]]; + [fiveByFive addShow: [Show showWithName: @"Hypercritical" feedPath: @"hypercritical" webPath: @"hypercritical"]]; + [fiveByFive addShow: [Show showWithName: @"The Talk Show" feedPath: @"thetalkshow" webPath: @"talkshow"]]; // Override point for customization after application launch. if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { @@ -90,6 +90,14 @@ - (void)applicationDidBecomeActive:(UIApplication *)application { // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. + SSMasterViewController *masterViewController; + if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { + masterViewController = [[self.navigationController viewControllers] objectAtIndex: 0]; + } + else { + masterViewController = [[[[self.splitViewController viewControllers] objectAtIndex: 0] viewControllers] objectAtIndex: 0]; + } + [masterViewController checkNowPlaying]; } - (void)applicationWillTerminate:(UIApplication *)application diff --git a/5by5Browser/SSMasterViewController.h b/5by5Browser/SSMasterViewController.h index e4d98be..fc81057 100644 --- a/5by5Browser/SSMasterViewController.h +++ b/5by5Browser/SSMasterViewController.h @@ -15,5 +15,10 @@ @property (nonatomic, retain) FiveByFive *fiveByFive; @property (nonatomic, retain) ShowViewController *showViewController; +@property (nonatomic, retain) Show *currentShow; +@property (nonatomic, retain) NSString *currentEpisodeNumber; +@property (nonatomic, retain) NSString *currentEpisodeName; + +- (void) checkNowPlaying; @end diff --git a/5by5Browser/SSMasterViewController.m b/5by5Browser/SSMasterViewController.m index 4ee6da3..6b52489 100644 --- a/5by5Browser/SSMasterViewController.m +++ b/5by5Browser/SSMasterViewController.m @@ -6,13 +6,18 @@ // Copyright (c) 2011 Guru Logic. All rights reserved. // +#import #import "SSMasterViewController.h" #import "Show.h" +#import "NSString+marshmallows.h" @implementation SSMasterViewController @synthesize showViewController = _showViewController; @synthesize fiveByFive = _fiveByFive; +@synthesize currentShow = _currentShow; +@synthesize currentEpisodeNumber = _currentEpisodeNumber; +@synthesize currentEpisodeName = _currentEpisodeName; - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { @@ -25,7 +30,7 @@ } return self; } - + - (void) viewWillAppear: (BOOL)animated { [super viewWillAppear: animated]; @@ -35,6 +40,8 @@ cell.accessoryView = nil; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; } + + [self checkNowPlaying]; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation @@ -46,6 +53,30 @@ } } +- (void) checkNowPlaying +{ + // Determine of the current playing track is a known show + MPMediaItem *song = [[MPMusicPlayerController iPodMusicPlayer] nowPlayingItem]; + if (song) { + NSString *title = [song valueForProperty: MPMediaItemPropertyTitle]; + self.currentEpisodeNumber = [title firstMatch: @"\\d+"]; + self.currentEpisodeName = [title substringFromIndex: [title rangeOfString: @": "].location + 2]; + NSString *showName = [song valueForProperty: MPMediaItemPropertyAlbumTitle]; + self.currentShow = [self.fiveByFive showWithName: showName]; + if (self.currentShow) { + NSLog(@"show: %@, episode: %@, name: %@", showName, self.currentEpisodeNumber, self.currentEpisodeName); + NSLog(@"show url: %@", [self.currentShow webURLForEpisodeNumber: self.currentEpisodeNumber]); + } + else { + NSLog(@"no show named %@", showName); + } + } + else { + NSLog(@"no song is currently playing"); + } + [self.tableView reloadData]; +} + - (void) setFiveByFive: (FiveByFive *)fiveByFive { _fiveByFive = fiveByFive; @@ -56,12 +87,25 @@ - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { - return 1; + return self.currentShow ? 2 : 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - return self.fiveByFive.shows.count; + if (self.currentShow && section == 0) { + return 1; + } + else { + return self.fiveByFive.shows.count; + } +} + +- (NSString *) tableView: (UITableView *)tableView titleForHeaderInSection: (NSInteger)section +{ + if (self.currentShow && section == 0) { + return @"Now Playing"; + } + return @"Shows"; } // Customize the appearance of table view cells. @@ -71,23 +115,44 @@ UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { - cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; + cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; } cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; - Show *show = [self.fiveByFive.shows objectAtIndex: indexPath.row]; - show.delegate = self; - cell.textLabel.text = show.name; + if (self.currentShow && indexPath.section == 0) { + self.currentShow.delegate = self; + cell.textLabel.text = self.currentEpisodeName; + cell.detailTextLabel.text = [NSString stringWithFormat: @"%@ %@", self.currentShow.name, self.currentEpisodeNumber]; + } + else { + Show *show = [self.fiveByFive.shows objectAtIndex: indexPath.row]; + show.delegate = self; + cell.textLabel.text = show.name; + if (show.episodes.count > 0) { + cell.detailTextLabel.text = [NSString stringWithFormat: @"%d episodes", show.episodes.count]; + } + else { + cell.detailTextLabel.text = nil; + } + } return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { - [[self.fiveByFive.shows objectAtIndex: indexPath.row] getEpisodes]; - UIActivityIndicatorView *indicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle: UIActivityIndicatorViewStyleWhite]; - [indicatorView startAnimating]; - [tableView cellForRowAtIndexPath: indexPath].accessoryView = indicatorView; + 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]; + self.showViewController.detailViewController.episode = episode; + [self.navigationController pushViewController: self.showViewController.detailViewController animated: YES]; + } + else { + [[self.fiveByFive.shows objectAtIndex: indexPath.row] getEpisodes]; + UIActivityIndicatorView *indicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle: UIActivityIndicatorViewStyleWhite]; + [indicatorView startAnimating]; + [tableView cellForRowAtIndexPath: indexPath].accessoryView = indicatorView; + } } - (void) gotEpisodesForShow: (Show *)show diff --git a/5by5Browser/Show.h b/5by5Browser/Show.h index bcb3381..6bd328f 100644 --- a/5by5Browser/Show.h +++ b/5by5Browser/Show.h @@ -22,12 +22,14 @@ @property (nonatomic, assign) id delegate; @property (nonatomic, retain) FiveByFive *fiveByFive; @property (nonatomic, retain) NSString *name; -@property (nonatomic, retain) NSString *path; +@property (nonatomic, retain) NSString *feedPath; +@property (nonatomic, retain) NSString *webPath; @property (nonatomic, retain) NSMutableArray *episodes; -+ (id) showWithName: (NSString *)name path: (NSString *)path; -- (id) initWithName: (NSString *)name path: (NSString *)path; ++ (id) showWithName: (NSString *)name feedPath: (NSString *)feedPath webPath: (NSString *)webPath; +- (id) initWithName: (NSString *)name feedPath: (NSString *)feedPath webPath: (NSString *)webPath; - (void) addEpisode: (Episode *)episode; - (void) getEpisodes; +- (NSString *) webURLForEpisodeNumber: (NSString *)episodeNumber; @end diff --git a/5by5Browser/Show.m b/5by5Browser/Show.m index 3dfb145..77e704d 100644 --- a/5by5Browser/Show.m +++ b/5by5Browser/Show.m @@ -20,20 +20,22 @@ @synthesize delegate = _delegate; @synthesize fiveByFive = _fiveByFive; @synthesize name = _name; -@synthesize path = _path; +@synthesize feedPath = _feedPath; +@synthesize webPath = _webPath; @synthesize episodes = _episodes; -+ (id) showWithName: (NSString *)name path: (NSString *)path ++ (id) showWithName: (NSString *)name feedPath: (NSString *)feedPath webPath: (NSString *)webPath { - return [[self alloc] initWithName: name path: path]; + return [[self alloc] initWithName: name feedPath: feedPath webPath: webPath]; } -- (id) initWithName: (NSString *)name path: (NSString *)path +- (id) initWithName: (NSString *)name feedPath: (NSString *)feedPath webPath: (NSString *)webPath { self = [super init]; if (self) { self.name = name; - self.path = path; + self.feedPath = feedPath; + self.webPath = webPath; self.episodes = [NSMutableArray array]; } return self; @@ -60,7 +62,12 @@ - (NSURL *) feedURL { - return [NSURL URLWithString: [[self.fiveByFive baseURL] stringByAppendingPathComponent: self.path]]; + return [NSURL URLWithString: [[self.fiveByFive baseURL] stringByAppendingPathComponent: self.feedPath]]; +} + +- (NSString *) webURLForEpisodeNumber: (NSString *)episodeNumber +{ + return [NSString stringWithFormat: @"http://5by5.tv/%@/%@", self.webPath, episodeNumber]; }