// // SavedCachesController.m // Geopher iPad // // Created by Jeremy on 11/29/10. // Copyright 2010 Stone Software. All rights reserved. // #import "SavedCachesController.h" #import "Geopher_OpenCachingAppDelegate.h" #import "ParseUtils.h" #import "LocatorModel.h" #import "Calculations.h" @implementation SavedCachesController @synthesize cacheTable, cacheData, waypointList; #pragma mark - #pragma mark View lifecycle // The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad. /* - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization. } return self; } */ /* // Implement loadView to create a view hierarchy programmatically, without using a nib. - (void)loadView { } */ /* // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. - (void)viewDidLoad { [super viewDidLoad]; } */ - (void) viewWillAppear:(BOOL)animated { // this iwll be the final code, for now just hack us in a special loc file. // we may want to store all of this in with our preferences as well, since these are both plists underneath anyhow. // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); // NSString *documentsDirectory = [paths objectAtIndex:0]; // NSString *finalPath = [documentsDirectory stringByAppendingPathComponent:kSavedCachesFilename]; // self.cacheData = [NSMutableDictionary dictionaryWithContentsOfFile:finalPath]; // test our XML stuff! NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *finalPath = [documentsDirectory stringByAppendingPathComponent:@"test.loc"]; self.cacheData = parseLocFileToDict(finalPath); // NSArray* waypoints = [self.cacheData objectForKey:kCacheEntry]; // grab our list of individual caches here self.waypointList = [self.cacheData objectForKey:kCacheEntry];//[waypoints sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)]; [self.cacheTable reloadData]; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Overriden to allow any orientation. return YES; } - (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning]; // Release any cached data, images, etc. that aren't in use. } - (void)viewDidUnload { [super viewDidUnload]; // Release any retained subviews of the main view. // e.g. self.myOutlet = nil; } - (void)dealloc { [cacheTable release], cacheTable = nil; [super dealloc]; } #pragma mark - #pragma mark Table view data source - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { // Return the number of sections. return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { // Return the number of rows in the section. return [waypointList count]; } // 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:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; } // get the appropriate object // fill in it's details. NSDictionary* dict = [self.waypointList objectAtIndex:indexPath.row]; cell.textLabel.text = [dict objectForKey:kCacheName]; // sub-text NSString* gccode = [dict objectForKey:kCacheGeocode]; CLLocationDegrees lat = [[dict objectForKey:kLatitudeNodeName] doubleValue]; CLLocationDegrees lon = [[dict objectForKey:kLongitudeNodeName] doubleValue]; CLLocationDistance distToCache = [Calculations calcDistanceFromLat:lat lon:lon toLat:[LocatorModel sharedInstance].currentLocation.coordinate.latitude lon:[LocatorModel sharedInstance].currentLocation.coordinate.longitude]; NSString* latLonString = [NSString stringWithFormat:@"%@, (%@)", gccode, [Calculations distToDisplayInDecimal:distToCache]]; cell.detailTextLabel.text = latLonString; 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. Geopher_OpenCachingAppDelegate* del = GetAppDelegate(); NSDictionary* info = [self.waypointList objectAtIndex:indexPath.row]; NSString* lat = [info objectForKey:kLatitudeNodeName]; NSString* lon = [info objectForKey:kLongitudeNodeName]; [del setNewTargetWithLatitude:lat longitude:lon]; } @end