//
//  TopUpAppDelegate.m
//  TopUp
//
//  Created by Frank McPherson on 5/20/10.
//  Copyright bitdoctors.com 2010. All rights reserved.
//

#import "TopUpAppDelegate.h"
#import "FuelServicesViewController.h";
#import "FileHelpers.h"

@implementation TopUpAppDelegate

@synthesize window;


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

	NSMutableArray *fuelServices = [NSKeyedUnarchiver unarchiveObjectWithFile:[self fuelServicesArrayPath]];
	
	if (!fuelServices)
		fuelServices = [NSMutableArray array];
	
	fuelServicesViewController = [[FuelServicesViewController alloc] init];
	[fuelServicesViewController setFuelServices:fuelServices];
	
	UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:fuelServicesViewController];
	
	[window addSubview:[navController view]];
    [window makeKeyAndVisible];
	return YES;
}

- (NSString *)fuelServicesArrayPath
{
	return pathInDocumentDirectory(@"FuelServices.data");
}

- (void)applicationWillTerminate:(UIApplication *)application
{
	[NSKeyedArchiver archiveRootObject:[fuelServicesViewController fuelServices] toFile:[self fuelServicesArrayPath]];
}

- (void)dealloc {
    [window release];
    [super dealloc];
}


@end
