From 869398ebfb18702b9de42f723ff8072b116eb04f Mon Sep 17 00:00:00 2001 From: matt handler Date: Fri, 29 Apr 2011 16:35:15 -0400 Subject: changing subscribedSources -> sources, adding instant level today/tomorrow/yesterday for section headers, setting status bar to black and showing once app loads, handling url just an nslog right now, updated image, added piccast:// protocol, setting up faves in the db, adding search and browse views --- Classes/BrowseViewController.h | 31 +++ Classes/BrowseViewController.m | 201 ++++++++++++++ Classes/BrowseViewController.xib | 538 ++++++++++++++++++++++++++++++++++++ Classes/PicCastAppDelegate.m | 11 +- Classes/SearchViewController.h | 39 +++ Classes/SearchViewController.m | 186 +++++++++++++ Classes/Source.m | 2 +- Classes/SourcesEditViewController.m | 6 +- Classes/TabViewController.m | 12 +- Classes/TopicsViewController.h | 4 + Classes/TopicsViewController.m | 26 +- 11 files changed, 1033 insertions(+), 23 deletions(-) create mode 100644 Classes/BrowseViewController.h create mode 100644 Classes/BrowseViewController.m create mode 100644 Classes/BrowseViewController.xib create mode 100644 Classes/SearchViewController.h create mode 100644 Classes/SearchViewController.m (limited to 'Classes') diff --git a/Classes/BrowseViewController.h b/Classes/BrowseViewController.h new file mode 100644 index 0000000..e89ddcd --- /dev/null +++ b/Classes/BrowseViewController.h @@ -0,0 +1,31 @@ +// +// BrowseViewController.h +// PicCast +// +// Created by Matthew Handler on 4/29/11. +// Copyright 2011 Earl Industries. All rights reserved. +// + +#import +#import "HJObjManager.h" +#import "PhotoViewController.h" +#import "FMDatabase.h" +#import "SectionDictionary.h" +#import "Fetcher.h" +#import "Source.h" + +@interface BrowseViewController : UIViewController { + //UINavigationController *topicsNavigationController; + NSMutableDictionary *sectionDictionary; + NSMutableDictionary *sourcesDictionary; + + SectionDictionary *tableDictionary; // structure to sync with table + //FeedViewController *feedViewController; // the view that a source points to, which shows recent sets + //PhotoViewController *photoViewController; + + HJObjManager* objMan; +} + +@property (nonatomic, retain) IBOutlet UITableView *tableView; + +@end diff --git a/Classes/BrowseViewController.m b/Classes/BrowseViewController.m new file mode 100644 index 0000000..22742c7 --- /dev/null +++ b/Classes/BrowseViewController.m @@ -0,0 +1,201 @@ +// +// BrowseViewController.m +// PicCast +// +// Created by Matthew Handler on 4/29/11. +// Copyright 2011 Earl Industries. All rights reserved. +// + +#import "BrowseViewController.h" + + +@implementation BrowseViewController + + +@synthesize tableView; + +#pragma mark - +#pragma mark View lifecycle + + +- (void)viewDidLoad { + [super viewDidLoad]; + + // Uncomment the following line to display an Edit button in the navigation bar for this view controller. + // self.navigationItem.rightBarButtonItem = self.editButtonItem; + + //[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine]; + //[self.tableView setSeparatorColor:[UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1.0]]; + + objMan = [[HJObjManager alloc] initWithLoadingBufferSize:6 memCacheSize:20]; + + NSString* cacheDirectory = [NSHomeDirectory() stringByAppendingString:@"/Library/Caches/imgcache/icons/"] ; + HJMOFileCache* fileCache = [[[HJMOFileCache alloc] initWithRootPath:cacheDirectory] autorelease]; + objMan.fileCache = fileCache; + + // Have the file cache trim itself down to a size & age limit, so it doesn't grow forever + fileCache.fileCountLimit = 100; + fileCache.fileAgeLimit = 60*60*24*7; //1 week + [fileCache trimCacheUsingBackgroundThread]; + + sectionDictionary = [[[SectionDictionary alloc] init] retain]; + sourcesDictionary = [[[NSMutableDictionary alloc] init] retain]; +} + +- (id)initWithFrame:(CGRect)frame { + + self = [super initWithFrame:frame]; + if (self) { + // Initialization code. + } + return self; +} + +- (void)viewWillAppear:(BOOL)animated { + NSIndexPath *selectedRowIndexPath = [self.tableView indexPathForSelectedRow]; + if (selectedRowIndexPath != nil) { + [self.tableView deselectRowAtIndexPath:selectedRowIndexPath animated:NO]; + } +} + +/* +- (void)viewWillAppear:(BOOL)animated { + [super viewWillAppear:animated]; +} +*/ +/* +- (void)viewDidAppear:(BOOL)animated { + [super viewDidAppear:animated]; +} +*/ +/* +- (void)viewWillDisappear:(BOOL)animated { + [super viewWillDisappear:animated]; +} +*/ +/* +- (void)viewDidDisappear:(BOOL)animated { + [super viewDidDisappear:animated]; +} +*/ +/* +// Override to allow orientations other than the default portrait orientation. +- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { + // Return YES for supported orientations. + return (interfaceOrientation == UIInterfaceOrientationPortrait); +} +*/ + + +#pragma mark - +#pragma mark Table view data source + +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { + // Return the number of sections. + return 1; //[sectionDictionary count]; +} + + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { + // Return the number of rows in the section. + return 3; //[[sectionDictionary objectForIndex:section] count]; +} + +- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { + return @"category"; +} + +// Customize the appearance of table view cells. +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { + + static NSString *CellIdentifier = @"Cell"; + + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; + if (cell == nil) { + cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; + } + + // Configure the cell... + + return cell; +} + + +/* +// Override to support conditional editing of the table view. +- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { + // Return NO if you do not want the specified item to be editable. + return YES; +} +*/ + + +/* +// Override to support editing the table view. +- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { + + if (editingStyle == UITableViewCellEditingStyleDelete) { + // Delete the row from the data source. + [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; + } + else if (editingStyle == UITableViewCellEditingStyleInsert) { + // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view. + } +} +*/ + + +/* +// Override to support rearranging the table view. +- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath { +} +*/ + + +/* +// Override to support conditional rearranging of the table view. +- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath { + // Return NO if you do not want the item to be re-orderable. + return YES; +} +*/ + + +#pragma mark - +#pragma mark Table view delegate + +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { + // Navigation logic may go here. Create and push another view controller. + /* + <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil]; + // ... + // Pass the selected object to the new view controller. + [self.navigationController pushViewController:detailViewController animated:YES]; + [detailViewController release]; + */ +} + + +#pragma mark - +#pragma mark Memory management + +- (void)didReceiveMemoryWarning { + // Releases the view if it doesn't have a superview. + [super didReceiveMemoryWarning]; + + // Relinquish ownership any cached data, images, etc. that aren't in use. +} + +- (void)viewDidUnload { + // Relinquish ownership of anything that can be recreated in viewDidLoad or on demand. + // For example: self.myOutlet = nil; +} + + +- (void)dealloc { + [super dealloc]; +} + + +@end + diff --git a/Classes/BrowseViewController.xib b/Classes/BrowseViewController.xib new file mode 100644 index 0000000..7baf5fb --- /dev/null +++ b/Classes/BrowseViewController.xib @@ -0,0 +1,538 @@ + + + + 1056 + 10J567 + 823 + 1038.35 + 462.00 + + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + 132 + + + YES + + + + YES + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + + + YES + + YES + + + YES + + + + YES + + IBFilesOwner + IBCocoaTouchFramework + + + IBFirstResponder + IBCocoaTouchFramework + + + + 292 + + YES + + + 274 + {{0, 44}, {320, 387}} + + + 10 + + 549453824 + {84, 1} + + YES + + YES + + + + TU0AKgAAAVjFzNT/xczU/8XM1P/FzNT/xczS/8vS2P/L0tj/xczU/8XM1P/FzNT/xczU/8XM0v/L0tj/ +y9LY/8XM1P/FzNT/xczU/8XM1P/FzNL/y9LY/8vS2P/FzNT/xczU/8XM1P/FzNT/xczS/8vS2P/L0tj/ +xczU/8XM1P/FzNT/xczU/8XM0v/L0tj/y9LY/8XM1P/FzNT/xczU/8XM1P/FzNL/y9LY/8vS2P/FzNT/ +xczU/8XM1P/FzNT/xczS/8vS2P/L0tj/xczU/8XM1P/FzNT/xczU/8XM0v/L0tj/y9LY/8XM1P/FzNT/ +xczU/8XM1P/FzNL/y9LY/8vS2P/FzNT/xczU/8XM1P/FzNT/xczS/8vS2P/L0tj/xczU/8XM1P/FzNT/ +xczU/8XM0v/L0tj/y9LY/8XM1P/FzNT/xczU/8XM1P/FzNL/y9LY/8vS2P8ADQEAAAMAAAABAFQAAAEB +AAMAAAABAAEAAAECAAMAAAAEAAAB+gEDAAMAAAABAAEAAAEGAAMAAAABAAIAAAERAAQAAAABAAAACAES +AAMAAAABAAEAAAEVAAMAAAABAAQAAAEWAAMAAAABAAEAAAEXAAQAAAABAAABUAEcAAMAAAABAAEAAAFS +AAMAAAABAAEAAAFTAAMAAAAEAAACAgAAAAAACAAIAAgACAABAAEAAQABA + + + + + + 3 + MCAwAA + + + groupTableViewBackgroundColor + + NO + YES + NO + + IBCocoaTouchFramework + NO + 1 + 2 + 0 + YES + 44 + 10 + 10 + + + + 290 + {320, 44} + + IBCocoaTouchFramework + + 1 + MC4wOTMzOTc2Mzk2OSAwLjE3NTQ0MzM4MTEgMC4yNTAzODczMTEAA + + + YES + + + PicCast + IBCocoaTouchFramework + + + + + {320, 431} + + + 3 + MQA + + 2 + + + + IBCocoaTouchFramework + + + + + YES + + + dataSource + + + + 6 + + + + delegate + + + + 7 + + + + tableView + + + + 11 + + + + view + + + + 19 + + + + + YES + + 0 + + + + + + -1 + + + File's Owner + + + -2 + + + + + 8 + + + YES + + + + + + + 9 + + + YES + + + + + + 10 + + + + + 4 + + + + + + + YES + + YES + -1.CustomClassName + -2.CustomClassName + 10.IBPluginDependency + 4.IBEditorWindowLastContentRect + 4.IBPluginDependency + 4.IBViewBoundsToFrameTransform + 8.IBEditorWindowLastContentRect + 8.IBPluginDependency + 8.IBViewBoundsToFrameTransform + 9.IBPluginDependency + + + YES + BrowseViewController + UIResponder + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + {{329, 376}, {320, 480}} + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + + P4AAAL+AAAAAAAAAw9aAAA + + {{114, 369}, {320, 480}} + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + + P4AAAL+AAAAAAAAAw9aAAA + + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + + + + YES + + + YES + + + + + YES + + + YES + + + + 19 + + + + YES + + BrowseViewController + UIViewController + + tableView + UITableView + + + tableView + + tableView + UITableView + + + + IBProjectSource + Classes/BrowseViewController.h + + + + + YES + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSError.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSFileManager.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSKeyValueCoding.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSKeyValueObserving.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSKeyedArchiver.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSObject.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSRunLoop.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSThread.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSURL.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSURLConnection.h + + + + NSObject + + IBFrameworkSource + QuartzCore.framework/Headers/CAAnimation.h + + + + NSObject + + IBFrameworkSource + QuartzCore.framework/Headers/CALayer.h + + + + NSObject + + IBFrameworkSource + UIKit.framework/Headers/UIAccessibility.h + + + + NSObject + + IBFrameworkSource + UIKit.framework/Headers/UINibLoading.h + + + + NSObject + + IBFrameworkSource + UIKit.framework/Headers/UIResponder.h + + + + UIBarButtonItem + UIBarItem + + IBFrameworkSource + UIKit.framework/Headers/UIBarButtonItem.h + + + + UIBarItem + NSObject + + IBFrameworkSource + UIKit.framework/Headers/UIBarItem.h + + + + UINavigationBar + UIView + + IBFrameworkSource + UIKit.framework/Headers/UINavigationBar.h + + + + UINavigationItem + NSObject + + + + UIResponder + NSObject + + + + UIScrollView + UIView + + IBFrameworkSource + UIKit.framework/Headers/UIScrollView.h + + + + UISearchBar + UIView + + IBFrameworkSource + UIKit.framework/Headers/UISearchBar.h + + + + UISearchDisplayController + NSObject + + IBFrameworkSource + UIKit.framework/Headers/UISearchDisplayController.h + + + + UITableView + UIScrollView + + IBFrameworkSource + UIKit.framework/Headers/UITableView.h + + + + UIView + + IBFrameworkSource + UIKit.framework/Headers/UIPrintFormatter.h + + + + UIView + + IBFrameworkSource + UIKit.framework/Headers/UITextField.h + + + + UIView + UIResponder + + IBFrameworkSource + UIKit.framework/Headers/UIView.h + + + + UIViewController + + IBFrameworkSource + UIKit.framework/Headers/UINavigationController.h + + + + UIViewController + + IBFrameworkSource + UIKit.framework/Headers/UIPopoverController.h + + + + UIViewController + + IBFrameworkSource + UIKit.framework/Headers/UISplitViewController.h + + + + UIViewController + + IBFrameworkSource + UIKit.framework/Headers/UITabBarController.h + + + + UIViewController + UIResponder + + IBFrameworkSource + UIKit.framework/Headers/UIViewController.h + + + + + 0 + IBCocoaTouchFramework + + com.apple.InterfaceBuilder.CocoaTouchPlugin.iPhoneOS + + + + com.apple.InterfaceBuilder.CocoaTouchPlugin.InterfaceBuilder3 + + + YES + ../PicCast.xcodeproj + 3 + 132 + + diff --git a/Classes/PicCastAppDelegate.m b/Classes/PicCastAppDelegate.m index a3bc294..3da5a07 100644 --- a/Classes/PicCastAppDelegate.m +++ b/Classes/PicCastAppDelegate.m @@ -50,6 +50,9 @@ // Override point for customization after application launch. // Add the tab bar controller's view to the window and display. + NSLog(@"launched"); + [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone]; + [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque]; [self.window addSubview:tabBarController.view]; [self.window makeKeyAndVisible]; @@ -134,9 +137,11 @@ [self prompt:title withMessage:message andButtonTitle:buttonTitle withDelegate:self]; } -//- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url { -// return [facebook handleOpenURL:url]; -//} +- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url { + NSLog(@"url: %@", [url absoluteString]); + return YES; + //return [facebook handleOpenURL:url]; +} + (NSString *) getDatabasePath { NSString *databaseName = @"PicCastSqlTable.db"; diff --git a/Classes/SearchViewController.h b/Classes/SearchViewController.h new file mode 100644 index 0000000..6888c9e --- /dev/null +++ b/Classes/SearchViewController.h @@ -0,0 +1,39 @@ +// +// SearchViewController.h +// PicCast +// +// Created by Matthew Handler on 4/28/11. +// Copyright 2011 Earl Industries. All rights reserved. +// + +// returned feeds -> turn on/off +// returned sets -> view +// later: returned pics -> view +// later: returned categories -> browse + +#import +#import "HJObjManager.h" + +#import "PhotoViewController.h" +#import "FMDatabase.h" +#import "SectionDictionary.h" +#import "Fetcher.h" +#import "Source.h" + +@interface SearchViewController : UIViewController { + //UINavigationController *topicsNavigationController; + NSMutableDictionary *sourcesDictionary; + + SectionDictionary *tableDictionary; // structure to sync with table + PhotoViewController *photoViewController; + + HJObjManager* objMan; + + FMDatabase* db; + NSString *searchString; +} + +@property (nonatomic, retain) IBOutlet UISearchBar *mainSearchBar; +@property (nonatomic, retain) IBOutlet UITableView *tableView; + +@end diff --git a/Classes/SearchViewController.m b/Classes/SearchViewController.m new file mode 100644 index 0000000..8272dd9 --- /dev/null +++ b/Classes/SearchViewController.m @@ -0,0 +1,186 @@ +// +// SearchViewController.m +// PicCast +// +// Created by Matthew Handler on 4/28/11. +// Copyright 2011 Earl Industries. All rights reserved. +// + +#import "SearchViewController.h" +#import "PicCastAppDelegate.h" + + +@implementation SearchViewController + +@synthesize tableView, mainSearchBar; + +- (void)viewDidLoad { + [super viewDidLoad]; + + [self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine]; + [self.tableView setSeparatorColor:[UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1.0]]; + + objMan = [[HJObjManager alloc] initWithLoadingBufferSize:6 memCacheSize:20]; + + NSString* cacheDirectory = [NSHomeDirectory() stringByAppendingString:@"/Library/Caches/imgcache/icons/"] ; + HJMOFileCache* fileCache = [[[HJMOFileCache alloc] initWithRootPath:cacheDirectory] autorelease]; + objMan.fileCache = fileCache; + + // Have the file cache trim itself down to a size & age limit, so it doesn't grow forever + fileCache.fileCountLimit = 100; + fileCache.fileAgeLimit = 60*60*24*7; //1 week + [fileCache trimCacheUsingBackgroundThread]; + + tableDictionary = [[[SectionDictionary alloc] init] retain]; + sourcesDictionary = [[[NSMutableDictionary alloc] init] retain]; + + db = [[FMDatabase databaseWithPath:[PicCastAppDelegate getDatabasePath]] retain]; + [db setShouldCacheStatements:NO]; + // [db setTraceExecution:true]; + // [db setLogsErrors:true]; + +// [self getTopicsFromDb]; +// +// [self loadSubscribedTopics]; +} + +- (id)initWithFrame:(CGRect)frame { + + self = [super initWithFrame:frame]; + if (self) { + // Initialization code. + } + return self; +} + +/* +// Only override drawRect: if you perform custom drawing. +// An empty implementation adversely affects performance during animation. +- (void)drawRect:(CGRect)rect { + // Drawing code. +} +*/ + +- (void)viewWillAppear:(BOOL)animated { + NSIndexPath *selectedRowIndexPath = [self.tableView indexPathForSelectedRow]; + if (selectedRowIndexPath != nil) { + [self.tableView deselectRowAtIndexPath:selectedRowIndexPath animated:NO]; + } +} + +#pragma mark - +#pragma mark UISearchBar protocol + +- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText { + +// if ([searchText length] > 0) { +// NSError *error = NULL; +// NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"[^a-zA-Z]" +// options:NSRegularExpressionCaseInsensitive +// error:&error]; +// +// NSString *newString = [regex stringByReplacingMatchesInString:searchText +// options:NSRegularExpressionCaseInsensitive +// range:[searchBar.text rangeOfString:searchText] +// withTemplate:@""]; +// +// if (![newString isEqualToString:searchBar.text]) +// searchBar.text = newString; +// } +} + +- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar { + [searchBar setShowsCancelButton:YES animated:YES]; + self.tableView.allowsSelection = NO; + self.tableView.scrollEnabled = NO; +} + +- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar { + searchBar.text = @""; + + [searchBar setShowsCancelButton:NO animated:YES]; + [searchBar resignFirstResponder]; + self.tableView.allowsSelection = YES; + self.tableView.scrollEnabled = YES; +} + +- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar { + [searchBar setShowsCancelButton:NO animated:YES]; + [searchBar resignFirstResponder]; + +// [MBProgressHUD showHUDAddedTo:self.view animated:YES]; +// +// _searchString = [searchBar.text copy]; +// [searchBar setShowsCancelButton:NO animated:YES]; +// [searchBar resignFirstResponder]; +// +// NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://www.werdmerge.com/search.php?word=%@", searchBar.text]] +// cachePolicy:NSURLRequestUseProtocolCachePolicy +// timeoutInterval:60.0]; +// +// if ([NSURLConnection connectionWithRequest:theRequest delegate:self]) { +// [_receivedData setLength:0]; +// } else { +// [MBProgressHUD hideHUDForView:self.view animated:YES]; +// [WerdMergeAppDelegate prompt:@"Error" withMessage:@"No internet connection" andButtonTitle:@"shucks" withDelegate:self]; +// } +// +// [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithBool:YES] forKey:@"haveSearched"]; + +} + +#pragma mark - +#pragma mark uitableviewcontroller protocol + +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { + return 10; +} + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { + return 5; +} + +- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { + return @"tamper proof cap"; +} + +//- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath +//{ +// if (indexPath.section + 1 == [tableDictionary count] && +// indexPath.row == [[tableDictionary objectForIndex:indexPath.section] count]) +// return 44; +// else +// return 100; +//} + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { + + static NSString *identifier = @"resultCell"; + + UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:identifier]; + + if (cell == nil) { + cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier] autorelease]; + } + + return cell; +} + +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { + +} + + +- (void)dealloc { + [mainSearchBar release]; + [tableView release]; + [tableDictionary release]; + [photoViewController release]; + [sourcesDictionary release]; + [objMan release]; + [searchString release]; + [super dealloc]; +} + + +@end diff --git a/Classes/Source.m b/Classes/Source.m index bde21b0..2369d1f 100644 --- a/Classes/Source.m +++ b/Classes/Source.m @@ -63,7 +63,7 @@ - (void) serializeToDb:(FMDatabase *)db { [db retain]; - [db executeUpdate:@"INSERT INTO subscribedSources \ + [db executeUpdate:@"INSERT INTO sources \ (foreignId, title, subscribed, category, favicon) \ VALUES \ (?, ?, ?, ?, ?);", diff --git a/Classes/SourcesEditViewController.m b/Classes/SourcesEditViewController.m index 7c7bf7b..857dbb0 100644 --- a/Classes/SourcesEditViewController.m +++ b/Classes/SourcesEditViewController.m @@ -75,7 +75,7 @@ - (void) loadSourcesFromDb { [db open]; - FMResultSet *result = [db executeQuery:@"SELECT * FROM subscribedSources"]; + FMResultSet *result = [db executeQuery:@"SELECT * FROM sources"]; while ([result next]) { Source *source = [Source initFromDatabaseRow:result]; [sectionDictionary appendObject:source forKey:source.category]; @@ -131,7 +131,7 @@ [db open]; for (NSDictionary *obj in array) { //NSLog(@"foreign key: %d", [obj objectForKey:@"id"]); - FMResultSet *result = [db executeQuery:@"SELECT * FROM subscribedSources WHERE foreignId = ?", [obj objectForKey:@"id"]]; + FMResultSet *result = [db executeQuery:@"SELECT * FROM sources WHERE foreignId = ?", [obj objectForKey:@"id"]]; if (![result next]) { //NSLog(@"found source"); Source *source = [Source initWithJsonObject:obj]; @@ -264,7 +264,7 @@ [db open]; [db beginTransaction]; - [db executeUpdate:@"UPDATE subscribedSources SET subscribed = ? WHERE foreignId = ?", [NSNumber numberWithInt:(switcher.on ? 1 : 0)], foreignId]; + [db executeUpdate:@"UPDATE sources SET subscribed = ? WHERE foreignId = ?", [NSNumber numberWithInt:(switcher.on ? 1 : 0)], foreignId]; [db commit]; [db close]; } diff --git a/Classes/TabViewController.m b/Classes/TabViewController.m index c4ada83..6aaa9f6 100644 --- a/Classes/TabViewController.m +++ b/Classes/TabViewController.m @@ -36,13 +36,13 @@ } */ -/* + // Override to allow orientations other than the default portrait orientation. -- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { - // Return YES for supported orientations - return (interfaceOrientation == UIInterfaceOrientationPortrait); -} -*/ +//- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { +// // Return YES for supported orientations +// return YES; //(interfaceOrientation == UIInterfaceOrientationPortrait); +//} + - (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. diff --git a/Classes/TopicsViewController.h b/Classes/TopicsViewController.h index 98a678c..bdd9eda 100644 --- a/Classes/TopicsViewController.h +++ b/Classes/TopicsViewController.h @@ -26,6 +26,10 @@ HJObjManager* objMan; FMDatabase* db; + + NSString *_today; + NSString *_yesterday; + NSString *_tomorrow; } - (IBAction)showSources:(id)sender; diff --git a/Classes/TopicsViewController.m b/Classes/TopicsViewController.m index 3ad8d95..d7ca089 100644 --- a/Classes/TopicsViewController.m +++ b/Classes/TopicsViewController.m @@ -35,6 +35,10 @@ [self.tableView setSeparatorColor:[UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1.0]]; objMan = [[HJObjManager alloc] initWithLoadingBufferSize:6 memCacheSize:20]; + + _today = [[Topic dateToString:[NSDate new]] retain]; + _yesterday = [[Topic dateToString:[NSDate dateWithTimeIntervalSinceNow:(NSTimeInterval)-86400]] retain]; + _tomorrow = [[Topic dateToString:[NSDate dateWithTimeIntervalSinceNow:(NSTimeInterval)+86400]] retain]; NSString* cacheDirectory = [NSHomeDirectory() stringByAppendingString:@"/Library/Caches/imgcache/icons/"] ; HJMOFileCache* fileCache = [[[HJMOFileCache alloc] initWithRootPath:cacheDirectory] autorelease]; @@ -81,6 +85,8 @@ [dateFormatter setTimeStyle:NSDateFormatterNoStyle]; [dateFormatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"US"] autorelease]]; + // convert releasedate to today if its tomorrow, acidcowwwww! + [tableDictionary appendObject:topic forKey:[dateFormatter dateFromString:[dateFormatter stringFromDate:topic.releaseDate]]]; } @@ -177,7 +183,7 @@ - (void) loadSubscribedTopics { //NSLog(@"load subscribed"); [db open]; - FMResultSet *result = [db executeQuery:@"SELECT * FROM subscribedSources WHERE subscribed = ?", [NSNumber numberWithInt:1]]; + FMResultSet *result = [db executeQuery:@"SELECT * FROM sources WHERE subscribed = ?", [NSNumber numberWithInt:1]]; while ([result next]) { Source *source = [[[Source alloc] init] autorelease]; if ([sourcesDictionary objectForKey:[NSNumber numberWithInt:[result intForColumn:@"foreignId"]]] != nil) { @@ -253,18 +259,15 @@ - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { //NSLog(@"row title: %@", [tableDictionary keyForIndex:section]); //return [tableDictionary keyForIndex:section]; //how do you convert a key to index from mutabledictionary - NSDate *date = [NSDate new]; + NSString *key = [Topic dateToString:[tableDictionary keyForIndex:section]]; - NSString *today = [Topic dateToString:date]; - NSString *yesterday = [Topic dateToString:[NSDate dateWithTimeIntervalSinceNow:(NSTimeInterval)-86400]]; - //NSLog(@"%@ %@ %@ %@", date, key, today, yesterday); - //NSLog(@"%@", [tableDictionary allIndices], [tableDictionary ); - //NSLog(@"%@", [tableDictionary allKeys]); - //[tableDictionary allIndices]; - if ([key compare:today] == 0) + + if ([key compare:_today] == 0) return @"Today"; - else if ([key compare:yesterday] == 0) + else if ([key compare:_yesterday] == 0) return @"Yesterday"; + else if ([key compare:_tomorrow] == 0) + return @"Tomorrow"; else return key; @@ -506,6 +509,9 @@ } - (void)dealloc { + [_today release]; + [_yesterday release]; + [_tomorrow release]; [db release]; [sourcesDictionary release]; [tableDictionary release]; -- cgit v1.2.3