Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // MasterViewController.m
- // youtubedemo
- //
- // Created by Your Name on 4/24/12.
- // Copyright (c) 2012 Your Company. All rights reserved.
- //
- #import "MasterViewController.h"
- #import "DetailViewController.h"
- @interface MasterViewController (PrivateMethods)
- - (GDataServiceGoogleYouTube *)youTubeService;
- @end
- @implementation MasterViewController
- @synthesize feed;
- - (void)awakeFromNib
- {
- [super awakeFromNib];
- }
- - (void)viewDidLoad
- {
- NSLog(@"Loading");
- GDataServiceGoogleYouTube *service = [self youTubeService];
- NSString *uploadsID = kGDataYouTubeUserFeedIDUploads;
- NSURL *feedURL = [GDataServiceGoogleYouTube youTubeURLForUserID:@"JMEveryday"
- userFeedID:uploadsID];
- [service fetchFeedWithURL:feedURL
- delegate:self
- didFinishSelector:@selector(request:finishedWithFeed:error:)];
- [super viewDidLoad];
- // Do any additional setup after loading the view, typically from a nib.
- }
- - (void)request:(GDataServiceTicket *)ticket
- finishedWithFeed:(GDataFeedBase *)aFeed
- error:(NSError *)error {
- self.feed = (GDataFeedYouTubeVideo *)aFeed;
- [self.tableView reloadData];
- }
- - (void)viewDidUnload
- {
- [super viewDidUnload];
- // Release any retained subviews of the main view.
- }
- - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
- {
- return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
- }
- #pragma mark - Table View
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return [[feed entries] count];
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
- return 70.0f;
- }
- /*- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- static NSString *CellIdentifier = @"Cell";
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
- if (cell == nil) {
- cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
- }
- //Configure the cell
- GDataEntryBase *entry = [[feed entries] objectAtIndex:indexPath.row];
- NSString *title = [[entry title] stringValue];
- NSArray *thumbnails = [[(GDataEntryYouTubeVideo *)entry mediaGroup] mediaThumbnails];
- cell.textLabel.text = title;
- NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:[[thumbnails objectAtIndex:0] URLString]]];
- cell.imageView.image = [UIImage imageWithData:data];
- return cell;
- }
- */
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- static NSString *CellIdentifier = @"Cell";
- UITableViewCell *cell = nil;
- cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
- if (cell == nil)
- {
- cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
- }
- // Configure the cell.
- GDataEntryBase *entry = [[feed entries] objectAtIndex:indexPath.row];
- NSString *title = [[entry title] stringValue];
- NSArray *thumbnails = [[(GDataEntryYouTubeVideo *)entry mediaGroup] mediaThumbnails];
- cell.textLabel.text = title;
- // Load the image with an GCD block executed in another thread
- dispatch_queue_t downloadQueue = dispatch_queue_create("image downloader", NULL);
- dispatch_async(downloadQueue, ^{
- NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:[[thumbnails objectAtIndex:0] URLString]]];
- UIImage * image = [UIImage imageWithData:data];
- dispatch_async(dispatch_get_main_queue(), ^{
- cell.imageView.image = image;
- cell.imageView.contentMode = UIViewContentModeScaleAspectFit;
- [cell setNeedsLayout];
- });
- });
- dispatch_release(downloadQueue);
- return cell;
- }
- - (GDataServiceGoogleYouTube *)youTubeService {
- static GDataServiceGoogleYouTube* _service = nil;
- if (!_service) {
- _service = [[GDataServiceGoogleYouTube alloc] init];
- [_service setUserAgent:@"AppWhirl-UserApp-1.0"];
- //[_service setShouldCacheDatedData:YES];
- [_service setServiceShouldFollowNextLinks:NO];
- }
- // fetch unauthenticated
- [_service setUserCredentialsWithUsername:nil
- password:nil];
- return _service;
- }
- /*
- // 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)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- DetailViewController *detailController = [self.storyboard instantiateViewControllerWithIdentifier:@"DetailController"];
- GDataEntryBase *entry2 = [[feed entries] objectAtIndex:indexPath.row];
- NSString *title = [[entry2 title] stringValue];
- NSArray *contents = [[(GDataEntryYouTubeVideo *)entry2 mediaGroup] mediaContents];
- GDataMediaContent *flashContent = [GDataUtilities firstObjectFromArray:contents withValue:@"application/x-shockwave-flash" forKeyPath:@"type"];
- NSString *tempURL = [flashContent URLString];
- //NSLog(@"The URL is:%@",tempURL);
- //NSString *test = @"This is a test";
- detailController.videoString = tempURL;
- detailController.titleString = title;
- // [self embedYouTube:[flashContent URLString] frame:CGRectMake(70, 100, 200, 200)];
- [self.navigationController pushViewController:detailController animated:YES];
- }
- /*- (void)embedYouTube:(NSString *)urlString frame:(CGRect)frame {
- NSString *embedHTML = @"<html><head> <meta name = \"viewport\" content = \"initial-scale = 1.0, user-scalable = no, width = 200\"/></head> <body style=\"background:#F00;margin-top:0px;margin-left:0px\"> <div><object width=\"200\" height=\"200\"> <param name=\"movie\" value=\"%@\"></param> <param name=\"wmode\" value=\"transparent\"></param> <embed src=\"%@\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"200\" height=\"200\"></embed> </object></div></body></html>";
- NSString *html =[NSString stringWithFormat:embedHTML, urlString, urlString, frame.size.width, frame.size.height];
- [webView loadHTMLString:html baseURL:nil];
- } */
- @end
Add Comment
Please, Sign In to add comment