2010-06-21 17:17:26 -04:00
|
|
|
//
|
|
|
|
// FeedDetailViewController.m
|
|
|
|
// NewsBlur
|
|
|
|
//
|
|
|
|
// Created by Samuel Clay on 6/20/10.
|
|
|
|
// Copyright 2010 NewsBlur. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "FeedDetailViewController.h"
|
|
|
|
#import "NewsBlurAppDelegate.h"
|
2010-06-24 00:22:26 -04:00
|
|
|
#import "JSON.h"
|
2010-06-21 17:17:26 -04:00
|
|
|
|
|
|
|
|
|
|
|
@implementation FeedDetailViewController
|
|
|
|
|
|
|
|
@synthesize storyTitlesTable, feedViewToolbar, feedScoreSlider;
|
2010-06-24 00:22:26 -04:00
|
|
|
@synthesize stories;
|
2010-06-21 17:17:26 -04:00
|
|
|
@synthesize appDelegate;
|
2010-06-24 12:53:50 -04:00
|
|
|
@synthesize jsonString;
|
2010-06-21 17:17:26 -04:00
|
|
|
|
|
|
|
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
|
|
|
|
|
|
|
|
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
|
2010-06-25 18:36:01 -04:00
|
|
|
|
2010-06-21 17:17:26 -04:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-06-24 12:53:50 -04:00
|
|
|
- (void)viewWillAppear:(BOOL)animated {
|
2010-06-25 18:36:01 -04:00
|
|
|
NSLog(@"Loaded Feed view: %@", appDelegate.activeFeed);
|
2010-06-27 19:35:17 -04:00
|
|
|
|
2010-06-24 00:22:26 -04:00
|
|
|
[self fetchFeedDetail];
|
2010-06-24 12:53:50 -04:00
|
|
|
|
|
|
|
[super viewWillAppear:animated];
|
2010-06-21 17:17:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)viewDidAppear:(BOOL)animated {
|
2010-06-25 18:36:01 -04:00
|
|
|
//[appDelegate showNavigationBar:animated];
|
2010-06-21 17:17:26 -04:00
|
|
|
|
|
|
|
[super viewDidAppear:animated];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)didReceiveMemoryWarning {
|
|
|
|
// Releases the view if it doesn't have a superview.
|
|
|
|
[super didReceiveMemoryWarning];
|
|
|
|
|
|
|
|
// Release any cached data, images, etc that aren't in use.
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)viewDidUnload {
|
|
|
|
// Release any retained subviews of the main view.
|
|
|
|
// e.g. self.myOutlet = nil;
|
2010-06-24 12:53:50 -04:00
|
|
|
//NSLog(@"Unloading detail view: %@", self);
|
2010-06-24 00:22:26 -04:00
|
|
|
self.appDelegate = nil;
|
2010-06-24 12:53:50 -04:00
|
|
|
self.jsonString = nil;
|
2010-06-21 17:17:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)dealloc {
|
|
|
|
[appDelegate release];
|
2010-06-24 00:22:26 -04:00
|
|
|
[stories release];
|
2010-06-24 12:53:50 -04:00
|
|
|
[jsonString release];
|
2010-06-21 17:17:26 -04:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark -
|
2010-06-24 00:22:26 -04:00
|
|
|
#pragma mark Initialization
|
|
|
|
|
|
|
|
- (void)fetchFeedDetail {
|
2010-06-25 18:36:01 -04:00
|
|
|
if ([appDelegate.activeFeed objectForKey:@"id"] != nil) {
|
|
|
|
NSString *theFeedDetailURL = [[NSString alloc] initWithFormat:@"http://www.newsblur.com/reader/load_single_feed/?feed_id=%@",
|
|
|
|
[appDelegate.activeFeed objectForKey:@"id"]];
|
2010-06-24 12:53:50 -04:00
|
|
|
//NSLog(@"Url: %@", theFeedDetailURL);
|
2010-06-24 00:22:26 -04:00
|
|
|
NSURL *urlFeedDetail = [NSURL URLWithString:theFeedDetailURL];
|
|
|
|
[theFeedDetailURL release];
|
2010-06-24 12:53:50 -04:00
|
|
|
jsonString = nil;
|
2010-06-24 00:22:26 -04:00
|
|
|
NSURLRequest *request = [[NSURLRequest alloc] initWithURL: urlFeedDetail];
|
|
|
|
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
|
|
|
|
[connection release];
|
|
|
|
[request release];
|
|
|
|
}
|
|
|
|
}
|
2010-06-21 17:17:26 -04:00
|
|
|
|
2010-06-24 00:22:26 -04:00
|
|
|
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
|
2010-06-24 12:53:50 -04:00
|
|
|
{
|
|
|
|
if(jsonString == nil) {
|
|
|
|
jsonString = [[NSMutableString alloc]
|
|
|
|
initWithData:data
|
|
|
|
encoding:NSUTF8StringEncoding];
|
|
|
|
|
|
|
|
} else {
|
|
|
|
NSMutableString *temp_string = [[NSMutableString alloc]
|
|
|
|
initWithString:jsonString];
|
|
|
|
|
|
|
|
[jsonString release];
|
|
|
|
jsonString = [[NSMutableString alloc]
|
|
|
|
initWithData:data
|
|
|
|
encoding:NSUTF8StringEncoding];
|
|
|
|
[temp_string appendString:jsonString];
|
|
|
|
|
|
|
|
[jsonString release];
|
|
|
|
jsonString = [[NSMutableString alloc] initWithString: temp_string];
|
|
|
|
[temp_string release];
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
|
|
|
|
NSDictionary *results = [[NSDictionary alloc]
|
|
|
|
initWithDictionary:[jsonString JSONValue]];
|
2010-06-24 00:22:26 -04:00
|
|
|
|
2010-06-24 12:53:50 -04:00
|
|
|
NSArray *storiesArray = [[NSArray alloc]
|
|
|
|
initWithArray:[results objectForKey:@"stories"]];
|
2010-06-25 18:36:01 -04:00
|
|
|
[appDelegate setActiveFeedStories:storiesArray];
|
|
|
|
//NSLog(@"Stories: %d -- %@", [appDelegate.activeFeedStories count], [self storyTitlesTable]);
|
2010-06-24 00:22:26 -04:00
|
|
|
[[self storyTitlesTable] reloadData];
|
|
|
|
|
|
|
|
[storiesArray release];
|
|
|
|
[results release];
|
|
|
|
[jsonString release];
|
2010-06-21 17:17:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-24 00:22:26 -04:00
|
|
|
#pragma mark -
|
|
|
|
#pragma mark Table View - Feed List
|
2010-06-21 17:17:26 -04:00
|
|
|
|
|
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
2010-06-25 18:36:01 -04:00
|
|
|
//NSLog(@"Stories: %d", [appDelegate.activeFeedStories count]);
|
|
|
|
return [appDelegate.activeFeedStories count];
|
2010-06-21 17:17:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
|
static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier";
|
|
|
|
|
|
|
|
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SimpleTableIdentifier];
|
|
|
|
if (cell == nil) {
|
|
|
|
|
|
|
|
cell = [[[UITableViewCell alloc]
|
|
|
|
initWithStyle:UITableViewCellStyleDefault
|
|
|
|
reuseIdentifier:SimpleTableIdentifier] autorelease];
|
|
|
|
}
|
2010-06-24 00:22:26 -04:00
|
|
|
|
2010-06-25 18:36:01 -04:00
|
|
|
cell.textLabel.text = [[appDelegate.activeFeedStories objectAtIndex:indexPath.row]
|
2010-06-24 00:22:26 -04:00
|
|
|
objectForKey:@"story_title"];
|
2010-06-21 17:17:26 -04:00
|
|
|
//
|
|
|
|
// int section_index = 0;
|
|
|
|
// for (id f in self.dictFoldersArray) {
|
|
|
|
// // NSLog(@"Cell: %i: %@", section_index, f);
|
|
|
|
// if (section_index == indexPath.section) {
|
|
|
|
// NSArray *feeds = [self.dictFolders objectForKey:f];
|
|
|
|
// // NSLog(@"Cell: %i: %@: %@", section_index, f, [feeds objectAtIndex:indexPath.row]);
|
|
|
|
// cell.textLabel.text = [[feeds objectAtIndex:indexPath.row]
|
|
|
|
// objectForKey:@"feed_title"];
|
|
|
|
// return cell;
|
|
|
|
// }
|
|
|
|
// section_index++;
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
2010-06-25 18:36:01 -04:00
|
|
|
[appDelegate setActiveStory:[[appDelegate activeFeedStories] objectAtIndex:indexPath.row]];
|
|
|
|
NSLog(@"Active Story: %@", [appDelegate activeStory]);
|
|
|
|
[appDelegate loadStoryDetailView];
|
2010-06-21 17:17:26 -04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|