summaryrefslogtreecommitdiffstats
path: root/Classes
diff options
context:
space:
mode:
Diffstat (limited to 'Classes')
-rw-r--r--Classes/Fetcher.h10
-rw-r--r--Classes/Fetcher.m17
-rw-r--r--Classes/Source.h2
-rw-r--r--Classes/Source.m11
-rw-r--r--Classes/SourcesEditViewController.m12
-rw-r--r--Classes/Topic.h4
-rw-r--r--Classes/Topic.m30
-rw-r--r--Classes/TopicTableViewCell.h2
-rw-r--r--Classes/TopicTableViewCell.m2
-rw-r--r--Classes/TopicTableViewCell.xib89
-rw-r--r--Classes/TopicsViewController.h16
-rw-r--r--Classes/TopicsViewController.m175
12 files changed, 221 insertions, 149 deletions
diff --git a/Classes/Fetcher.h b/Classes/Fetcher.h
index d51a39d..cc32aba 100644
--- a/Classes/Fetcher.h
+++ b/Classes/Fetcher.h
@@ -13,17 +13,25 @@
- (void) connection:(NSURLConnection *)connection failedWithError:(NSError *)error;
- (void) connection:(NSURLConnection *)connection finishedWithData:(NSData *)data;
+@optional
+
+- (void) connection:(NSURLConnection *)connection failedWithError:(NSError *)error andPayload:(id)payload;
+- (void) connection:(NSURLConnection *)connection finishedWithData:(NSData *)data andPayload:(id)payload;
+
@end
@interface Fetcher : NSObject <NSURLProtocolClient> {
NSMutableData *receivedData;
id<FetcherDelegate> delegate;
+ id payload;
}
@property (nonatomic, assign) id<FetcherDelegate> delegate;
+@property (nonatomic, retain) id payload;
-+ (Fetcher *) initWithString:(NSString *)string andDelegate:(id <FetcherDelegate>)delegate;
++ (Fetcher *) initWithString:(NSString *)string payload:(id)p andDelegate:(id <FetcherDelegate>)d;
++ (Fetcher *) initWithString:(NSString *)string andDelegate:(id <FetcherDelegate>)d;
- (void) setUrlAndConnect:(NSString *)string;
@end
diff --git a/Classes/Fetcher.m b/Classes/Fetcher.m
index 3fe162f..6e3e7b3 100644
--- a/Classes/Fetcher.m
+++ b/Classes/Fetcher.m
@@ -11,11 +11,16 @@
@implementation Fetcher
-@synthesize delegate;
+@synthesize delegate, payload;
+ (Fetcher *) initWithString:(NSString *)string andDelegate:(id<FetcherDelegate>)d {
+ return [Fetcher initWithString:string payload:nil andDelegate:d];
+}
+
++ (Fetcher *) initWithString:(NSString *)string payload:(id)p andDelegate:(id <FetcherDelegate>)d {
Fetcher *fetcher = [[[Fetcher alloc] init] autorelease];
fetcher.delegate = d;
+ if (payload != nil) fetcher.payload = p;
[fetcher setUrlAndConnect:string];
return fetcher;
}
@@ -46,11 +51,17 @@
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
- [delegate connection:connection failedWithError:error];
+ if (payload != nil && [(NSObject *)delegate respondsToSelector:@selector(connection:failedWithError:andPayload:)])
+ [delegate connection:connection failedWithError:error andPayload:payload];
+ else
+ [delegate connection:connection failedWithError:error];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
- [delegate connection:connection finishedWithData:receivedData];
+ if (payload != nil && [(NSObject *)delegate respondsToSelector:@selector(connection:finishedWithData:andPayload:)])
+ [delegate connection:connection finishedWithData:receivedData andPayload:payload];
+ else
+ [delegate connection:connection finishedWithData:receivedData];
}
- (void) dealloc {
diff --git a/Classes/Source.h b/Classes/Source.h
index ea8fe0d..1793d4b 100644
--- a/Classes/Source.h
+++ b/Classes/Source.h
@@ -15,8 +15,10 @@
NSString *category;
BOOL subscribed;
NSNumber *foreignId;
+ NSString *favicon;
}
+@property (retain) NSString *favicon;
@property (retain) NSString *category;
@property (retain) NSString *title;
@property BOOL subscribed;
diff --git a/Classes/Source.m b/Classes/Source.m
index f36e41e..bde21b0 100644
--- a/Classes/Source.m
+++ b/Classes/Source.m
@@ -12,7 +12,7 @@
@implementation Source
-@synthesize title, foreignId, subscribed, category;
+@synthesize title, foreignId, subscribed, category, favicon;
//+ (Topic *) initFromDatabaseRow:(FMResultSet *)result {
// NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
@@ -41,6 +41,7 @@
source.foreignId = [NSNumber numberWithInt:[result intForColumn:@"foreignId"]];
source.subscribed = [result intForColumn:@"subscribed"] == 0 ? false : true;
source.category = [result stringForColumn:@"category"];
+ source.favicon = [result stringForColumn:@"favicon"];
return source;
}
@@ -50,7 +51,7 @@
Source *source = [[[Source alloc] init] autorelease];
//NSDictionary *info = [obj objectForKey:@"fields"];
-
+ source.favicon = [NSString stringWithFormat:@"http://www.%@.com/favicon.ico", [obj objectForKey:@"shortname"]]; //[obj objectForKey:@"favicon"];
source.title = [obj objectForKey:@"title"];
source.foreignId = [obj objectForKey:@"id"];
source.subscribed = false;
@@ -63,10 +64,10 @@
[db retain];
[db executeUpdate:@"INSERT INTO subscribedSources \
- (foreignId, title, subscribed, category) \
+ (foreignId, title, subscribed, category, favicon) \
VALUES \
- (?, ?, ?, ?);",
- foreignId, title, [NSNumber numberWithInt:(subscribed ? 1 : 0)], category];
+ (?, ?, ?, ?, ?);",
+ foreignId, title, [NSNumber numberWithInt:(subscribed ? 1 : 0)], category, favicon];
[db release];
}
diff --git a/Classes/SourcesEditViewController.m b/Classes/SourcesEditViewController.m
index 0d5bd85..7c7bf7b 100644
--- a/Classes/SourcesEditViewController.m
+++ b/Classes/SourcesEditViewController.m
@@ -52,9 +52,9 @@
sectionDictionary = [[[SectionDictionary alloc] init] retain];
db = [[FMDatabase databaseWithPath:[PicCastAppDelegate getDatabasePath]] retain];
- [db setShouldCacheStatements:YES];
- [db setTraceExecution:true];
- [db setLogsErrors:true];
+ [db setShouldCacheStatements:NO];
+ //[db setTraceExecution:true];
+ //[db setLogsErrors:true];
[self loadSourcesFromDb];
@@ -130,10 +130,10 @@
//NSLog(@"class: %@", [array class]);
[db open];
for (NSDictionary *obj in array) {
- NSLog(@"foreign key: %d", [obj objectForKey:@"id"]);
+ //NSLog(@"foreign key: %d", [obj objectForKey:@"id"]);
FMResultSet *result = [db executeQuery:@"SELECT * FROM subscribedSources WHERE foreignId = ?", [obj objectForKey:@"id"]];
if (![result next]) {
- NSLog(@"found source");
+ //NSLog(@"found source");
Source *source = [Source initWithJsonObject:obj];
[sectionDictionary appendObject:source forKey:source.category];
@@ -260,7 +260,7 @@
MyButton *switcher = (MyButton *)sender;
NSIndexPath *indexPath = switcher.indexPath;
NSNumber *foreignId = [[[sectionDictionary objectForIndex:indexPath.section] objectAtIndex:indexPath.row] foreignId];
- NSLog(@"number %d", foreignId);
+ NSLog(@"number %@", foreignId);
[db open];
[db beginTransaction];
diff --git a/Classes/Topic.h b/Classes/Topic.h
index 93c1925..fd01bfb 100644
--- a/Classes/Topic.h
+++ b/Classes/Topic.h
@@ -19,9 +19,11 @@
NSNumber *picCount;
NSString *guid;
NSNumber *foreignId;
+ NSNumber *sourceId;
}
+@property (nonatomic, retain) NSNumber *sourceId;
@property (nonatomic, retain) NSNumber *foreignId;
@property (nonatomic, copy) NSNumber *picCount;
@property (nonatomic, copy) NSString *title;
@@ -34,7 +36,7 @@
+ (Topic *) initFromDatabaseRow:(FMResultSet *)result;
+ (Topic *) initWithJsonObject:(NSDictionary *)obj;
+ (NSString *) dateToString:(NSDate *)date;
-+ (NSDate *) stringToDate:(NSString *)string;
- (void) serializeToDatabase:(FMDatabase *)db;
+ (NSString *) getImageUrl:(NSDictionary *)obj;
+
@end
diff --git a/Classes/Topic.m b/Classes/Topic.m
index 12364f8..36be5f6 100644
--- a/Classes/Topic.m
+++ b/Classes/Topic.m
@@ -12,7 +12,7 @@
@implementation Topic
-@synthesize guid, title, iconUrl, description, releaseDate, category, picCount, foreignId;
+@synthesize guid, title, iconUrl, description, releaseDate, category, picCount, foreignId, sourceId;
+ (Topic *) initFromDatabaseRow:(FMResultSet *)result {
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
@@ -22,6 +22,7 @@
Topic *topic = [[[Topic alloc] init] autorelease];
+ topic.sourceId = [NSNumber numberWithInt:[result intForColumn:@"sourceId"]];
topic.guid = [result stringForColumn:@"link"];
topic.title = [result stringForColumn:@"title"];
topic.iconUrl = [result stringForColumn:@"iconUrl"];
@@ -50,6 +51,10 @@
return topic;
}
+- (Topic *) init {
+ return self;
+}
+
+ (NSString *) getImageUrl:(NSDictionary *)obj {
if (obj == nil || [obj class] == [NSNull class]) return nil;
else {
@@ -66,29 +71,15 @@
return [dateFormatter stringFromDate:date];
}
-+ (NSDate *) stringToDate:(NSString *)string {
- NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
- [dateFormatter setDateStyle:NSDateFormatterLongStyle];
- [dateFormatter setTimeStyle:NSDateFormatterNoStyle];
- [dateFormatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"US"] autorelease]];
-
- return [dateFormatter dateFromString:string];
-}
-
- (void)serializeToDatabase:(FMDatabase *)db {
[db retain];
- NSLog(@"title: %d", [releaseDate timeIntervalSince1970]);
+
[db executeUpdate:@"INSERT INTO picCasts \
- (foreignId, link, title, description, releaseDate, category, iconUrl, picCount) \
+ (foreignId, link, title, description, releaseDate, category, iconUrl, picCount, sourceId) \
VALUES \
- (?, ?, ?, ?, ?, ?, ?, ?)",
- foreignId, guid, title, description, releaseDate, category, iconUrl, picCount];
- //NSLog(@"insert id:%d error: %@", [db lastInsertRowId], [db lastErrorMessage]);
+ (?, ?, ?, ?, ?, ?, ?, ?, ?)",
+ foreignId, guid, title, description, releaseDate, category, iconUrl, picCount, sourceId];
- // [NSString stringWithFormat:@"number %d", i],
- // [NSNumber numberWithInt:i],
- // [NSDate date],
- // [NSNumber numberWithFloat:2.2f]];
[db release];
}
@@ -100,6 +91,7 @@
[releaseDate release];
[category release];
[iconUrl release];
+ [sourceId release];
[super dealloc];
}
diff --git a/Classes/TopicTableViewCell.h b/Classes/TopicTableViewCell.h
index 583d56c..a78b3a5 100644
--- a/Classes/TopicTableViewCell.h
+++ b/Classes/TopicTableViewCell.h
@@ -16,6 +16,7 @@
BOOL useDarkBackground;
IBOutlet UILabel *titleLabel;
+ IBOutlet UILabel *categoryLabel;
IBOutlet UILabel *picCountLabel;
IBOutlet UIImageView *icon;
IBOutlet UIImageView *gradient;
@@ -23,6 +24,7 @@
@property BOOL useDarkBackground;
@property (nonatomic, retain) UIImageView *gradient;
@property (nonatomic, retain) UILabel *titleLabel;
+@property (nonatomic, retain) UILabel *categoryLabel;
@property (nonatomic, retain) UIImageView *icon;
@property (nonatomic, retain) UILabel *picCountLabel;
@property (retain) NSString *picCount;
diff --git a/Classes/TopicTableViewCell.m b/Classes/TopicTableViewCell.m
index 2e87d28..c2753b6 100644
--- a/Classes/TopicTableViewCell.m
+++ b/Classes/TopicTableViewCell.m
@@ -11,7 +11,7 @@
@implementation TopicTableViewCell
-@synthesize title, iconUrl, picCount, picCountLabel, gradient; // titleLabel, icon
+@synthesize title, iconUrl, picCount, picCountLabel, gradient, categoryLabel; // titleLabel, icon
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
diff --git a/Classes/TopicTableViewCell.xib b/Classes/TopicTableViewCell.xib
index a66bd79..a62d0cb 100644
--- a/Classes/TopicTableViewCell.xib
+++ b/Classes/TopicTableViewCell.xib
@@ -47,18 +47,6 @@
<int key="NSvFlags">256</int>
<object class="NSMutableArray" key="NSSubviews">
<bool key="EncodedWithXMLCoder">YES</bool>
- <object class="IBUIImageView" id="647701623">
- <reference key="NSNextResponder" ref="885389068"/>
- <int key="NSvFlags">292</int>
- <string key="NSFrameSize">{320, 100}</string>
- <reference key="NSSuperview" ref="885389068"/>
- <bool key="IBUIUserInteractionEnabled">NO</bool>
- <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
- <object class="NSCustomResource" key="IBUIImage">
- <string key="NSClassName">NSImage</string>
- <string key="NSResourceName">gradient.png</string>
- </object>
- </object>
<object class="IBUILabel" id="840200400">
<reference key="NSNextResponder" ref="885389068"/>
<int key="NSvFlags">292</int>
@@ -72,7 +60,7 @@
<string key="IBUIText">Title</string>
<object class="NSFont" key="IBUIFont">
<string key="NSName">Helvetica-Bold</string>
- <double key="NSSize">22</double>
+ <double key="NSSize">20</double>
<int key="NSfFlags">16</int>
</object>
<object class="NSColor" key="IBUITextColor">
@@ -158,6 +146,30 @@
<bool key="IBUIAnimating">YES</bool>
<int key="IBUIStyle">2</int>
</object>
+ <object class="IBUILabel" id="587556857">
+ <reference key="NSNextResponder" ref="885389068"/>
+ <int key="NSvFlags">292</int>
+ <string key="NSFrame">{{127, 67}, {43, 27}}</string>
+ <reference key="NSSuperview" ref="885389068"/>
+ <bool key="IBUIOpaque">NO</bool>
+ <bool key="IBUIClipsSubviews">YES</bool>
+ <int key="IBUIContentMode">7</int>
+ <bool key="IBUIUserInteractionEnabled">NO</bool>
+ <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
+ <string key="IBUIText">category</string>
+ <object class="NSFont" key="IBUIFont">
+ <string key="NSName">Helvetica-LightOblique</string>
+ <double key="NSSize">11</double>
+ <int key="NSfFlags">16</int>
+ </object>
+ <object class="NSColor" key="IBUITextColor">
+ <int key="NSColorSpace">3</int>
+ <bytes key="NSWhite">MC4zMzMzMzMzMzMzAA</bytes>
+ </object>
+ <reference key="IBUIHighlightedColor" ref="350503524"/>
+ <int key="IBUIBaselineAdjustment">1</int>
+ <float key="IBUIMinimumFontSize">10</float>
+ </object>
</object>
<string key="NSFrameSize">{300, 100}</string>
<reference key="NSSuperview" ref="896521461"/>
@@ -205,11 +217,11 @@
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchOutletConnection" key="connection">
- <string key="label">gradient</string>
+ <string key="label">categoryLabel</string>
<reference key="source" ref="896521461"/>
- <reference key="destination" ref="647701623"/>
+ <reference key="destination" ref="587556857"/>
</object>
- <int key="connectionID">19</int>
+ <int key="connectionID">21</int>
</object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
@@ -242,7 +254,7 @@
<reference ref="439279812"/>
<reference ref="559717521"/>
<reference ref="94212658"/>
- <reference ref="647701623"/>
+ <reference ref="587556857"/>
</object>
<reference key="parent" ref="0"/>
</object>
@@ -272,8 +284,8 @@
<reference key="parent" ref="896521461"/>
</object>
<object class="IBObjectRecord">
- <int key="objectID">18</int>
- <reference key="object" ref="647701623"/>
+ <int key="objectID">20</int>
+ <reference key="object" ref="587556857"/>
<reference key="parent" ref="896521461"/>
</object>
</object>
@@ -288,11 +300,11 @@
<string>13.IBPluginDependency</string>
<string>13.IBViewBoundsToFrameTransform</string>
<string>16.IBPluginDependency</string>
- <string>18.IBPluginDependency</string>
- <string>18.IBViewBoundsToFrameTransform</string>
<string>2.CustomClassName</string>
<string>2.IBEditorWindowLastContentRect</string>
<string>2.IBPluginDependency</string>
+ <string>20.IBPluginDependency</string>
+ <string>20.IBViewBoundsToFrameTransform</string>
<string>3.IBPluginDependency</string>
<string>3.IBViewBoundsToFrameTransform</string>
<string>9.IBPluginDependency</string>
@@ -306,16 +318,18 @@
</object>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<object class="NSAffineTransform">
- <bytes key="NSTransformStruct">P4AAAL+AAABDFAAAwrYAAA</bytes>
+ <bytes key="NSTransformStruct">P4AAAL+AAABDiQAAwrgAAA</bytes>
</object>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
- <string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
- <object class="NSAffineTransform"/>
<string>TopicTableViewCell</string>
<string>{{460, 755}, {320, 100}}</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<object class="NSAffineTransform">
+ <bytes key="NSTransformStruct">AUOJAABChgAAA</bytes>
+ </object>
+ <string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <object class="NSAffineTransform">
<bytes key="NSTransformStruct">P4AAAL+AAABDJAAAwrAAAA</bytes>
</object>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
@@ -337,7 +351,7 @@
</object>
</object>
<nil key="sourceID"/>
- <int key="maxID">19</int>
+ <int key="maxID">21</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
@@ -349,6 +363,7 @@
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
+ <string>categoryLabel</string>
<string>gradient</string>
<string>icon</string>
<string>picCountLabel</string>
@@ -356,6 +371,7 @@
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
+ <string>UILabel</string>
<string>UIImageView</string>
<string>UIImageView</string>
<string>UILabel</string>
@@ -366,6 +382,7 @@
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
+ <string>categoryLabel</string>
<string>gradient</string>
<string>icon</string>
<string>picCountLabel</string>
@@ -374,6 +391,10 @@
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="IBToOneOutletInfo">
+ <string key="name">categoryLabel</string>
+ <string key="candidateClassName">UILabel</string>
+ </object>
+ <object class="IBToOneOutletInfo">
<string key="name">gradient</string>
<string key="candidateClassName">UIImageView</string>
</object>
@@ -473,6 +494,20 @@
<string key="className">NSObject</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">QuartzCore.framework/Headers/CAAnimation.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">NSObject</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">QuartzCore.framework/Headers/CALayer.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">NSObject</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBFrameworkSource</string>
<string key="minorKey">UIKit.framework/Headers/UIAccessibility.h</string>
</object>
</object>
@@ -564,10 +599,6 @@
<bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool>
<string key="IBDocument.LastKnownRelativeProjectPath">../PicCast.xcodeproj</string>
<int key="IBDocument.defaultPropertyAccessControl">3</int>
- <object class="NSMutableDictionary" key="IBDocument.LastKnownImageSizes">
- <string key="NS.key.0">gradient.png</string>
- <string key="NS.object.0">{320, 100}</string>
- </object>
<string key="IBCocoaTouchPluginVersion">132</string>
</data>
</archive>
diff --git a/Classes/TopicsViewController.h b/Classes/TopicsViewController.h
index 490046d..98a678c 100644
--- a/Classes/TopicsViewController.h
+++ b/Classes/TopicsViewController.h
@@ -7,7 +7,6 @@
//
#import <UIKit/UIKit.h>
-#import "XMLParser.h"
#import "HJObjManager.h"
//#import "PicDumpViewController.h"
#import "SourcesEditViewController.h"
@@ -15,32 +14,31 @@
#import "FMDatabase.h"
#import "SectionDictionary.h"
#import "Fetcher.h"
+#import "Source.h"
-@interface TopicsViewController : UIViewController <FetcherDelegate, XMLParserDelegate, SourcesEditViewControllerDelegate, UITableViewDataSource>{
+@interface TopicsViewController : UIViewController <FetcherDelegate, SourcesEditViewControllerDelegate, UITableViewDataSource>{
UINavigationController *topicsNavigationController;
- NSMutableArray *topics; // topics loaded from the web
+ NSMutableDictionary *sourcesDictionary;
SectionDictionary *tableDictionary; // structure to sync with table
PhotoViewController *photoViewController;
- XMLParser *parser;
+
HJObjManager* objMan;
+
FMDatabase* db;
}
- (IBAction)showSources:(id)sender;
+@property (nonatomic, retain) NSMutableDictionary *sourcesDictionary;
@property (nonatomic, retain) IBOutlet UITableView *tableView;
@property (nonatomic, retain, readonly) UINavigationController *topicsNavigationController;
@property (nonatomic, retain) PhotoViewController *photoViewController;
-@property (nonatomic, retain) NSMutableArray *topics;
-//@property (nonatomic, retain, readonly) PicDumpViewController *picDumpViewController;
-@property (nonatomic, retain) XMLParser *parser;
-// Called by the ParserChoiceViewController based on the selected parser type.
-- (void)startParsing;
- (void)getTopicsFromDb;
- (void)addTopicToSectionDictionary:(Topic *)topic;
- (void)loadSubscribedTopics;
- (void)addTopicsFromJson:(NSData *)topics;
+- (void)addTopicsFromJson:(NSData *)data forSource:(Source *)source;
@end
diff --git a/Classes/TopicsViewController.m b/Classes/TopicsViewController.m
index 3431e62..31191ee 100644
--- a/Classes/TopicsViewController.m
+++ b/Classes/TopicsViewController.m
@@ -7,7 +7,6 @@
//
#import "TopicsViewController.h"
-#import "XMLParser.h"
#import "Topic.h"
#import "TopicTableViewCell.h"
#import "AcidCowFeedburnerParser.h"
@@ -22,10 +21,11 @@
#import "PicCastAppDelegate.h"
#import "CJSONDeserializer.h"
#import "Fetcher.h"
+#import "Source.h"
@implementation TopicsViewController
-@synthesize topics, parser, tableView;
+@synthesize tableView, sourcesDictionary;
- (void)viewDidLoad {
[super viewDidLoad];
@@ -44,9 +44,11 @@
[fileCache trimCacheUsingBackgroundThread];
tableDictionary = [[[SectionDictionary alloc] init] retain];
-
+ sourcesDictionary = [[[NSMutableDictionary alloc] init] retain];
+
+
db = [[FMDatabase databaseWithPath:[PicCastAppDelegate getDatabasePath]] retain];
- [db setShouldCacheStatements:YES];
+ [db setShouldCacheStatements:NO];
// [db setTraceExecution:true];
// [db setLogsErrors:true];
@@ -109,19 +111,21 @@
#pragma mark -
#pragma mark custom sheeyit
-- (void) addTopicsFromJson:(NSData *)data {
-
+- (void) addTopicsFromJson:(NSData *)data forSource:(Source *)source {
+
NSError *theError = nil;
id dictionary = [[CJSONDeserializer deserializer] deserialize:(NSData *)data error:&theError];
NSArray *array = [dictionary objectForKey:@"list"];
-
+
[db open];
for (NSDictionary *obj in array) {
- NSLog(@"foreign key: %d", [obj objectForKey:@"id"]);
FMResultSet *result = [db executeQuery:@"SELECT id FROM picCasts WHERE foreignId = ?", [obj objectForKey:@"id"]];
if (![result next]) {
NSLog(@"found new topic");
Topic *topic = [Topic initWithJsonObject:obj];
+ topic.sourceId = source.foreignId;
+
+ if ([topic.picCount intValue] == 0) break;
[db beginTransaction];
[topic serializeToDatabase:db];
@@ -133,43 +137,60 @@
}
[db close];
- [self.tableView reloadData];
+ [self.tableView reloadData];
+
}
-// called after parsing is finished
-- (void) updateTopicsFromWeb:(NSArray *)parsedTopics {
- // add topics to sql
- [db open];
- for (Topic *topic in parsedTopics) {
- // if topic is already in database
- //FMResultSet *rs = [db executeQuery:@"SELECT id FROM picCasts WHERE foreignId = ?", [NSNumber numberWithInt:10]];
- if (true) {
- //[rs close];
+- (void) addTopicsFromJson:(NSData *)data {
+
+ NSError *theError = nil;
+ id dictionary = [[CJSONDeserializer deserializer] deserialize:(NSData *)data error:&theError];
+ NSArray *array = [dictionary objectForKey:@"list"];
+
+ [db open];
+ for (NSDictionary *obj in array) {
+ FMResultSet *result = [db executeQuery:@"SELECT id FROM picCasts WHERE foreignId = ?", [obj objectForKey:@"id"]];
+ if (![result next]) {
+ Topic *topic = [Topic initWithJsonObject:obj];
+
+ if (topic.picCount == 0) break;
+
[db beginTransaction];
[topic serializeToDatabase:db];
[db commit];
- // add topics to structure
[self addTopicToSectionDictionary:topic];
}
- }
+ [result close];
+ }
[db close];
- // tell table to animate things being added
- [self.tableView reloadData];
+ [self.tableView reloadData];
}
- (void) loadSubscribedTopics {
+ NSLog(@"load subscribed");
[db open];
- FMResultSet *result = [db executeQuery:@"SELECT foreignId FROM subscribedSources WHERE subscribed = ?", [NSNumber numberWithInt:1]];
+ FMResultSet *result = [db executeQuery:@"SELECT * FROM subscribedSources WHERE subscribed = ?", [NSNumber numberWithInt:1]];
while ([result next]) {
-
+ Source *source = [[[Source alloc] init] autorelease];
+ if ([sourcesDictionary objectForKey:[NSNumber numberWithInt:[result intForColumn:@"foreignId"]]] != nil) {
+ source = [sourcesDictionary objectForKey:[NSNumber numberWithInt:[result intForColumn:@"foreignId"]]];
+ }
+ else {
+ source = [Source initFromDatabaseRow:result];
+ [sourcesDictionary setObject:source forKey:source.foreignId];
+ }
+
Fetcher *fetcher = [Fetcher initWithString:[NSString
- stringWithFormat:@"http://piccast.memeschemes.com/json/sets_by_feed/%d/",
- [result intForColumn:@"foreignId"]]
+ stringWithFormat:@"http://piccast.memeschemes.com/json/sets_by_feed/%@/",
+ source.foreignId]
+ payload:source
andDelegate:self];
}
+ [result close];
+ [db close];
}
#pragma mark -
@@ -184,6 +205,10 @@
[self addTopicsFromJson:data];
}
+- (void) connection:(NSURLConnection *)connection finishedWithData:(NSData *)data andPayload:(id)payload {
+ [self addTopicsFromJson:data forSource:(Source *)payload];
+}
+
#pragma mark -
#pragma mark Table view data source
@@ -276,9 +301,11 @@
Topic *topic = [[tableDictionary objectForIndex:[indexPath section]] objectAtIndex:[indexPath row]];
//cell.useDarkBackground = (indexPath.row % 2 == 0);
cell.title = topic.title;
+ [cell.categoryLabel setText:topic.category];
+
cell.picCount = [NSString stringWithFormat:@"%@", topic.picCount];
- micon.url = [NSURL URLWithString:@"http://www.acidcow.com/favicon.ico"];
+ micon.url = [NSURL URLWithString:[[sourcesDictionary objectForKey:topic.sourceId] favicon]];
mi.url = [NSURL URLWithString:topic.iconUrl];
mi.squareCropped = true;
@@ -343,51 +370,51 @@
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
-
-#pragma mark <iTunesRSSParserDelegate> Implementation
-
-- (void)startParsing {
- NSLog(@"startParsing");
- //self.navigationItem.rightBarButtonItem.enabled = NO;
- // Reset the title
- //self.title = NSLocalizedString(@"Getting Recent Picdumps...", @"Loading");
- // Allocate the array for song storage, or empty the results of previous parses
- if (topics == nil) {
- self.topics = [NSMutableArray array];
- } else {
- [topics removeAllObjects];
- [self.tableView reloadData];
- }
- // Create the parser, set its delegate, and start it.
- self.parser = [[[AcidCowFeedburnerParser alloc] init] autorelease];
- parser.delegate = self;
- [parser start];
-}
-
-- (void)parserDidEndParsingData:(XMLParser *)parser {
- //self.title = [NSString stringWithFormat:NSLocalizedString(@"Recent Picdumps (%d)", @"Recent"), [topics count]];
- [self.tableView reloadData];
- //self.navigationItem.rightBarButtonItem.enabled = YES;
- self.parser = nil;
-}
-
-- (void)parser:(XMLParser *)parser didParseTopics:(NSArray *)parsedTopics {
- [self updateTopicsFromWeb:parsedTopics];
-
- // Three scroll view properties are checked to keep the user interface smooth during parse. When new objects are delivered
- // by the parser, the table view is reloaded to display them. If the table is reloaded while
- // the user is scrolling, this can result in eratic behavior. dragging, tracking, and decelerating can be checked
- // for this purpose. When the parser finishes, reloadData will be called in parserDidEndParsingData:, guaranteeing
- // that all data will ultimately be displayed even if reloadData is not called in this method because of user interaction.
- if (!self.tableView.dragging && !self.tableView.tracking && !self.tableView.decelerating) {
- //self.title = [NSString stringWithFormat:NSLocalizedString(@"Recent Picdumps (%d)", @"Recent"), [topics count]];
- [self.tableView reloadData];
- }
-}
-
-- (void)parser:(XMLParser *)parser didFailWithError:(NSError *)error {
- // handle errors as appropriate to your application...
-}
+//
+//#pragma mark <iTunesRSSParserDelegate> Implementation
+//
+//- (void)startParsing {
+// NSLog(@"startParsing");
+// //self.navigationItem.rightBarButtonItem.enabled = NO;
+// // Reset the title
+// //self.title = NSLocalizedString(@"Getting Recent Picdumps...", @"Loading");
+// // Allocate the array for song storage, or empty the results of previous parses
+// if (topics == nil) {
+// self.topics = [NSMutableArray array];
+// } else {
+// [topics removeAllObjects];
+// [self.tableView reloadData];
+// }
+// // Create the parser, set its delegate, and start it.
+// self.parser = [[[AcidCowFeedburnerParser alloc] init] autorelease];
+// parser.delegate = self;
+// [parser start];
+//}
+//
+//- (void)parserDidEndParsingData:(XMLParser *)parser {
+// //self.title = [NSString stringWithFormat:NSLocalizedString(@"Recent Picdumps (%d)", @"Recent"), [topics count]];
+// [self.tableView reloadData];
+// //self.navigationItem.rightBarButtonItem.enabled = YES;
+// self.parser = nil;
+//}
+//
+//- (void)parser:(XMLParser *)parser didParseTopics:(NSArray *)parsedTopics {
+// [self updateTopicsFromWeb:parsedTopics];
+//
+// // Three scroll view properties are checked to keep the user interface smooth during parse. When new objects are delivered
+// // by the parser, the table view is reloaded to display them. If the table is reloaded while
+// // the user is scrolling, this can result in eratic behavior. dragging, tracking, and decelerating can be checked
+// // for this purpose. When the parser finishes, reloadData will be called in parserDidEndParsingData:, guaranteeing
+// // that all data will ultimately be displayed even if reloadData is not called in this method because of user interaction.
+// if (!self.tableView.dragging && !self.tableView.tracking && !self.tableView.decelerating) {
+// //self.title = [NSString stringWithFormat:NSLocalizedString(@"Recent Picdumps (%d)", @"Recent"), [topics count]];
+// [self.tableView reloadData];
+// }
+//}
+//
+//- (void)parser:(XMLParser *)parser didFailWithError:(NSError *)error {
+// // handle errors as appropriate to your application...
+//}
#pragma mark -
#pragma mark Memory management
@@ -406,11 +433,9 @@
- (void)dealloc {
[db release];
+ [sourcesDictionary release];
[tableDictionary release];
[objMan release];
- [topics release];
- //[detailController release];
- [parser release];
[super dealloc];
}