View difference between Paste ID: VknUZmJZ and vmV2c0HT
SHOW: | | - or go back to the newest paste.
1
//  RootViewController.h
2
3
#import "GDataYouTube.h"
4
#import "GDataServiceGoogleYouTube.h"
5
6
7
@interface RootViewController : UITableViewController {
8
	GDataFeedYouTubeVideo *feed;
9
}
10
11
@property (nonatomic, retain) GDataFeedYouTubeVideo *feed;
12
13
@end
14
15
16
---------------------------------------------------------------------------------
17
18
19
//  RootViewController.m
20
21
#import "RootViewController.h"
22
23
@interface RootViewController (PrivateMethods)
24
	- (GDataServiceGoogleYouTube *)youTubeService;
25
@end
26
27
28
@implementation RootViewController
29
30
@synthesize feed;
31
32
- (void)viewDidLoad {
33
	NSLog(@"loading");
34
35
	GDataServiceGoogleYouTube *service = [self youTubeService];
36
37
	NSString *uploadsID = kGDataYouTubeUserFeedIDUploads;
38
	NSURL *feedURL = [GDataServiceGoogleYouTube youTubeURLForUserID:@"annoyingorange"
39
														 userFeedID:uploadsID];
40
	
41
	[service fetchFeedWithURL:feedURL
42
							  delegate:self
43
					 didFinishSelector:@selector(request:finishedWithFeed:error:)];
44
45
    [super viewDidLoad];	
46
}
47
48
- (void)request:(GDataServiceTicket *)ticket
49
            finishedWithFeed:(GDataFeedBase *)aFeed
50
                       error:(NSError *)error {
51
52
	self.feed = (GDataFeedYouTubeVideo *)aFeed;
53
54
	[self.tableView reloadData];
55
}
56
57
58
#pragma mark Table view methods
59
60
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
61
    return 1;
62
}
63
64
65
// Customize the number of rows in the table view.
66
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
67
    return [[feed entries] count];
68
}
69
70
71
// Customize the appearance of table view cells.
72
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
73
    
74
    static NSString *CellIdentifier = @"Cell";
75
    
76
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
77
    if (cell == nil) {
78
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
79
    }
80
    
81
	// Configure the cell.
82
	GDataEntryBase *entry = [[feed entries] objectAtIndex:indexPath.row];
83
	NSString *title = [[entry title] stringValue];
84
	NSArray *thumbnails = [[(GDataEntryYouTubeVideo *)entry mediaGroup] mediaThumbnails];
85
86
	cell.textLabel.text = title;
87
	
88
	NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:[[thumbnails objectAtIndex:0] URLString]]];
89
	cell.imageView.image = [UIImage imageWithData:data];
90
	
91
    return cell;
92
}
93
94
95
- (void)dealloc {
96
    [super dealloc];
97
}
98
99
100
- (GDataServiceGoogleYouTube *)youTubeService {
101
	static GDataServiceGoogleYouTube* _service = nil;
102
	
103
	if (!_service) {
104
		_service = [[GDataServiceGoogleYouTube alloc] init];
105
		
106
		[_service setUserAgent:@"AppWhirl-UserApp-1.0"];
107
		[_service setShouldCacheDatedData:YES];
108
		[_service setServiceShouldFollowNextLinks:YES];
109
	}
110
	
111
	// fetch unauthenticated
112
	[_service setUserCredentialsWithUsername:nil
113
								   password:nil];
114
	
115
	return _service;
116
}
117
118
@end