// // ViewController.m // FMC Planner 2 // // Created by Kilian Hofmann on 19.03.16. // Copyright © 2016 Kilian Hofmann. All rights reserved. // #import "ViewController.h" @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. // Round corners _backdropKeys.layer.cornerRadius = 5; _backdropKeys.layer.masksToBounds = YES; _backdropScreen.layer.cornerRadius = 5; _backdropScreen.layer.masksToBounds = YES; // Setup save system _save = [[NSMutableDictionary alloc] init]; _firstLoad = true; self.title = @"FMC"; } - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { NSString *segueName = segue.identifier; if ([segueName isEqualToString:@"keyboard"]) { _keys = (ViewControllerKeyboard *)segue.destinationViewController; _keys.main = self; } if ([segueName isEqualToString:@"screen"]) { _screen = (ViewControllerScreen *)segue.destinationViewController; _screen.main = self; } } - (void)saveToFile:(NSDictionary *)save { NSString *file = [SharedDeclerations savePathForFile:[_save valueForKey:@"MENU@LSKR1"]]; if (_firstLoad) { if ([[NSFileManager defaultManager] fileExistsAtPath:file]) { [self alertViewiOS7:file]; } else if (!([[_save valueForKey:@"MENU@LSKR1"] isEqualToString:@""]) && [_save valueForKey:@"MENU@LSKR1"] != nil) { [_save writeToFile:file atomically:YES]; } } else if (!([_save valueForKey:@"MENU@LSKR1"] == nil || [[_save valueForKey:@"MENU@LSKR1"] isEqualToString:@""])) { [_save writeToFile:file atomically:YES]; } _firstLoad = false; } - (void)loadSave:(NSString *)file { if ([[NSFileManager defaultManager] fileExistsAtPath:[SharedDeclerations savePathForFile:file]]) { _save = [[NSMutableDictionary alloc] initWithContentsOfFile:[SharedDeclerations savePathForFile:file]]; [_screen clearScreen]; [_screen loadDataToScreen]; } } #pragma mark - Delegate for UIAlertView and UIAlertController outsource - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { if (buttonIndex == 1) { [self loadSave:[_save valueForKey:@"MENU@LSKR1"]]; } else if (buttonIndex == 2) { [_save writeToFile:[SharedDeclerations savePathForFile:[_save valueForKey:@"MENU@LSKR1"]] atomically:YES]; } else { _screen.LSK_R1.text = _backupCoRte; } } - (void)alertViewiOS7:(NSString *)file { if ([UIAlertController class]) { UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Load or replace?" message:@"The entered CO ROUTE alreay exists. " @"Do you want to load or replace it?" preferredStyle:UIAlertControllerStyleActionSheet]; UIAlertAction *defaultAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]; UIAlertAction *loadAction = [UIAlertAction actionWithTitle:@"Load" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { [self loadSave:[_save valueForKey:@"MENU@LSKR1"]]; }]; UIAlertAction *replaceAction = [UIAlertAction actionWithTitle:@"Replace" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { [_save writeToFile:file atomically:YES]; }]; [alert addAction:defaultAction]; [alert addAction:loadAction]; [alert addAction:replaceAction]; [self presentViewController:alert animated:YES completion:nil]; } else { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Load or replace?" message:@"The entered CO ROUTE alreay exists. Do " @"you want to load " @"or replace it?" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Load", @"Replace", nil]; [alert show]; } } @end