summaryrefslogtreecommitdiffstats
path: root/Classes
diff options
context:
space:
mode:
authormatt handler <matt.handler@gmail.com>2011-04-26 18:05:17 -0400
committermatt handler <matt.handler@gmail.com>2011-04-26 18:05:17 -0400
commit39478a90674f2b4238ba1cfaa49908deb0200e24 (patch)
treeb906aa9132fc883a5f62cf177ddcea97843b2003 /Classes
parent1ee16b02d54bd8c71ae365bdb56d7389702839ea (diff)
downloadpiccast-app-39478a90674f2b4238ba1cfaa49908deb0200e24.tar.gz
piccast-app-39478a90674f2b4238ba1cfaa49908deb0200e24.zip
aww yeah it works
Diffstat (limited to 'Classes')
-rw-r--r--Classes/PhotoViewController.h8
-rw-r--r--Classes/PhotoViewController.m78
-rw-r--r--Classes/Topic.m3
-rw-r--r--Classes/TopicsViewController.m1
4 files changed, 51 insertions, 39 deletions
diff --git a/Classes/PhotoViewController.h b/Classes/PhotoViewController.h
index e1c71ae..471022d 100644
--- a/Classes/PhotoViewController.h
+++ b/Classes/PhotoViewController.h
@@ -11,14 +11,14 @@
#import "Topic.h"
@interface PhotoViewController : TTThumbsViewController <NSURLProtocolClient> {
- NSArray *photoList;
- NSMutableData *_acidcowPage;
+ NSMutableData *_receivedData;
Topic *topic;
}
-@property (nonatomic, retain) NSArray *photoList;
-@property (retain) NSMutableData *_acidcowPage;
+@property (retain) NSMutableData *_receivedData;
@property (retain) Topic *topic;
-(void)convertArray;
+-(void)loadImages;
+
@end
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];
}
diff --git a/Classes/Topic.m b/Classes/Topic.m
index 8b7ec20..12364f8 100644
--- a/Classes/Topic.m
+++ b/Classes/Topic.m
@@ -29,6 +29,7 @@
topic.releaseDate = [result dateForColumn:@"releaseDate"];
topic.category = [result stringForColumn:@"category"];
topic.picCount = [NSNumber numberWithInt:[result intForColumn:@"picCount"]];
+ topic.foreignId = [NSNumber numberWithInt:[result intForColumn:@"foreignId"]];
return topic;
}
@@ -44,7 +45,7 @@
topic.description = [obj objectForKey:@"description"];
topic.releaseDate = [NSDate dateWithTimeIntervalSince1970:[[obj objectForKey:@"created_unixtime"] doubleValue]];
topic.category = [obj objectForKey:@"category"];
- topic.picCount = [NSNumber numberWithInt:10]; //[obj objectForKey:@"picCount"];
+ topic.picCount = [obj objectForKey:@"pic_count"];
return topic;
}
diff --git a/Classes/TopicsViewController.m b/Classes/TopicsViewController.m
index 78258d7..3431e62 100644
--- a/Classes/TopicsViewController.m
+++ b/Classes/TopicsViewController.m
@@ -300,6 +300,7 @@
photoViewController = [[[PhotoViewController alloc] init] autorelease];
photoViewController.topic = [[tableDictionary objectForIndex:indexPath.section] objectAtIndex:indexPath.row];
[self.navigationController pushViewController:photoViewController animated:YES];
+ //[application setStatusBarStyle:UIStatusBarStyleBlackOpaque];
}