summaryrefslogtreecommitdiffstats
path: root/Classes/Topic.m
diff options
context:
space:
mode:
authormatt handler <matt.handler@gmail.com>2011-04-26 17:18:49 -0400
committermatt handler <matt.handler@gmail.com>2011-04-26 17:18:49 -0400
commit46642320901ebaaedae5618e423ebfe70f316351 (patch)
treefa4f7d55589c1057ee8e33194a71bbf7b587960a /Classes/Topic.m
parent9ac2c9e13eb63c2a3a5e9b5a14b079d4fc24a220 (diff)
downloadpiccast-app-46642320901ebaaedae5618e423ebfe70f316351.tar.gz
piccast-app-46642320901ebaaedae5618e423ebfe70f316351.zip
updated topics dynamic loading, added fetcher class, storing in database and not overwriting is good, need to add info to photo view controller and also sort results
Diffstat (limited to 'Classes/Topic.m')
-rw-r--r--Classes/Topic.m27
1 files changed, 17 insertions, 10 deletions
diff --git a/Classes/Topic.m b/Classes/Topic.m
index 1ed4420..8b7ec20 100644
--- a/Classes/Topic.m
+++ b/Classes/Topic.m
@@ -33,22 +33,29 @@
return topic;
}
-+ (Topic *) initFromJsonObject:(NSDictionary *)obj {
++ (Topic *) initWithJsonObject:(NSDictionary *)obj {
Topic *topic = [[[Topic alloc] init] autorelease];
- NSDictionary *info = [obj objectForKey:@"fields"];
+ //NSDictionary *info = [obj objectForKey:@"fields"];
- topic.title = [info objectForKey:@"title"];
- topic.foreignId = [obj objectForKey:@"pk"];
- topic.iconUrl = [info objectForKey:@"iconUrl"];
- topic.description = [info objectForKey:@"description"];
- topic.releaseDate = [self stringToDate:[info objectForKey:@"releaseDate"]];
- topic.category = [info objectForKey:@"category"];
- topic.picCount = [info objectForKey:@"picCount"];
+ topic.title = [obj objectForKey:@"title"];
+ topic.foreignId = [obj objectForKey:@"id"];
+ topic.iconUrl = [self getImageUrl:[obj objectForKey:@"image"]];
+ 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"];
return topic;
}
++ (NSString *) getImageUrl:(NSDictionary *)obj {
+ if (obj == nil || [obj class] == [NSNull class]) return nil;
+ else {
+ return [obj objectForKey:@"original_url"];
+ }
+}
+
+ (NSString *) dateToString:(NSDate *)date {
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setDateStyle:NSDateFormatterLongStyle];
@@ -74,7 +81,7 @@
(foreignId, link, title, description, releaseDate, category, iconUrl, picCount) \
VALUES \
(?, ?, ?, ?, ?, ?, ?, ?)",
- [NSNumber numberWithInt:12], guid, title, description, releaseDate, category, iconUrl, picCount];
+ foreignId, guid, title, description, releaseDate, category, iconUrl, picCount];
//NSLog(@"insert id:%d error: %@", [db lastInsertRowId], [db lastErrorMessage]);
// [NSString stringWithFormat:@"number %d", i],