summaryrefslogtreecommitdiffstats
path: root/Classes/PhotoViewController.m
diff options
context:
space:
mode:
Diffstat (limited to 'Classes/PhotoViewController.m')
-rw-r--r--Classes/PhotoViewController.m78
1 files changed, 44 insertions, 34 deletions
diff --git a/Classes/PhotoViewController.m b/Classes/PhotoViewController.m
index 151aabd..850d425 100644
--- a/Classes/PhotoViewController.m
+++ b/Classes/PhotoViewController.m
@@ -9,6 +9,7 @@
#import "PhotoViewController.h"
#import "PhotoSource.h"
#import <Three20/Three20.h>
+#import "CJSONDeserializer.h"
@interface MyPhotoViewController : TTPhotoViewController
{
@@ -64,15 +65,15 @@
@implementation PhotoViewController
-@synthesize photoList, topic;
+@synthesize topic;
- (void)viewDidLoad {
-// [self convertArray];
[super viewDidLoad];
- _acidcowPage = [[NSMutableData data] retain];
+ [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque];
+
+ _receivedData = [[NSMutableData data] retain];
- [self loadImages];
}
- (void)viewWillDisappear:(BOOL)animated {
@@ -80,24 +81,25 @@
self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:24/255.0 green:45/255.0 blue:64/255.0 alpha:1.0];
}
-- (void)setPhotoList:(NSArray *)list {
- photoList = list;
- [self convertArray];
-}
-
-(void)setTopic:(Topic *)t {
topic = t;
self.navigationItem.title = topic.title;
[self loadImages];
- //NSLog(@"%@", topic.guid);
}
- (void)convertArray {
- NSMutableArray *converted = [[NSMutableArray alloc] initWithCapacity:[photoList count]];
- for (NSString *url in photoList) {
- [converted addObject:[[[Photo alloc] initWithURL:url
- smallURL:url
- size:CGSizeMake(0, 0)] autorelease]];
+ NSMutableArray *converted = [[[NSMutableArray alloc] init] retain];
+
+ NSError *theError = nil;
+ id dictionary = [[CJSONDeserializer deserializer] deserialize:(NSData *)_receivedData error:&theError];
+ NSLog(@"%@", dictionary);
+ NSArray *array = [dictionary objectForKey:@"list"];
+
+ for (NSDictionary *obj in array) {
+ [converted addObject:[[[Photo alloc] initWithURL:[obj objectForKey:@"original_url"]
+ smallURL:[obj objectForKey:@"original_url"]
+ size:CGSizeMake(0,0)
+ caption:[obj objectForKey:@"caption"]] autorelease]];
}
@@ -106,18 +108,26 @@
title:topic.title
photos:converted
photos2:nil];
+
+ [converted release];
}
#pragma mark -
#pragma mark URL Connection Stuff
- (void)loadImages {
-
- NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:topic.guid]
+//
+// NSLog(@"%@", [NSString stringWithFormat:@"http://piccast.memeschemes.com/json/pics_by_set/%@/",
+// topic.foreignId]);
+
+ NSURLRequest *theRequest=[NSURLRequest requestWithURL:
+ [NSURL URLWithString:
+ [NSString stringWithFormat:@"http://piccast.memeschemes.com/json/pics_by_set/%@/",
+ topic.foreignId]]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:3600.0];
if ([NSURLConnection connectionWithRequest:theRequest delegate:self]) {
- [_acidcowPage setLength:0];
+ [_receivedData setLength:0];
} else {
//[MBProgressHUD hideHUDForView:self.view animated:YES];
//[WerdMergeAppDelegate prompt:@"Error" withMessage:@"No internet connection" andButtonTitle:@"shucks" withDelegate:self];
@@ -125,11 +135,11 @@
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
- [_acidcowPage setLength:0];
+ [_receivedData setLength:0];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
- [_acidcowPage appendData:data];
+ [_receivedData appendData:data];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
@@ -143,21 +153,21 @@
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
- NSString *html = [[[NSString alloc] initWithData:_acidcowPage encoding:NSUTF8StringEncoding] autorelease];
-
- NSRegularExpression* regex = [NSRegularExpression regularExpressionWithPattern:@"http://acidcow\\.com/pics[^ \"]+\\.(jpg|png|jpeg|gif)"
- options:NSRegularExpressionCaseInsensitive
- error:nil];
- NSArray *results = [regex matchesInString:html options:0 range:NSMakeRange(0, [html length])];
- NSMutableArray *strings = [[NSMutableArray alloc] initWithCapacity:[results count]];
- for (NSTextCheckingResult *obj in results) {
- [strings addObject:[html substringWithRange:[obj range]]];
-
- //NSLog(@"found: %@", [html substringWithRange:[obj range]]);
- }
+// NSString *html = [[[NSString alloc] initWithData:_receivedData encoding:NSUTF8StringEncoding] autorelease];
+//
+// NSRegularExpression* regex = [NSRegularExpression regularExpressionWithPattern:@"http://acidcow\\.com/pics[^ \"]+\\.(jpg|png|jpeg|gif)"
+// options:NSRegularExpressionCaseInsensitive
+// error:nil];
+// NSArray *results = [regex matchesInString:html options:0 range:NSMakeRange(0, [html length])];
+// NSMutableArray *strings = [[NSMutableArray alloc] initWithCapacity:[results count]];
+// for (NSTextCheckingResult *obj in results) {
+// [strings addObject:[html substringWithRange:[obj range]]];
+//
+// //NSLog(@"found: %@", [html substringWithRange:[obj range]]);
+// }
//PhotoViewController *photoView = [[[PhotoViewController alloc] init] autorelease];
- self.photoList = strings;
+ //self.photoList = strings;
[self convertArray];
//[self.navigationController pushViewController:photoView animated:YES];
// [self.view addSubview:(UIView *)photoView];
@@ -196,7 +206,7 @@
*/
- (void)dealloc {
- [photoList release];
+ //[photoList release];
[super dealloc];
}