From bddfd723b7978043f2cc1acf60cf33d77a413f3e Mon Sep 17 00:00:00 2001 From: Kilian Hofmann Date: Sat, 26 Mar 2016 14:10:30 +0100 Subject: [PATCH] Loading from LSK, Alerts (pre ios7 and post ios7) --- FMC Planner 2.xcodeproj/project.pbxproj | 4 + .../xcdebugger/Breakpoints_v2.xcbkptlist | 82 +++++++++++++++++ FMC Planner 2/Base.lproj/Main.storyboard | 1 + FMC Planner 2/Info.plist | 2 + FMC Planner 2/LaunchScreen.storyboard | 7 ++ FMC Planner 2/ViewController.h | 4 +- FMC Planner 2/ViewController.m | 91 +++++++++++++++++-- FMC Planner 2/ViewControllerScreen.h | 3 + FMC Planner 2/ViewControllerScreen.m | 25 +++-- 9 files changed, 203 insertions(+), 16 deletions(-) create mode 100644 FMC Planner 2/LaunchScreen.storyboard diff --git a/FMC Planner 2.xcodeproj/project.pbxproj b/FMC Planner 2.xcodeproj/project.pbxproj index b63051e..6268a04 100644 --- a/FMC Planner 2.xcodeproj/project.pbxproj +++ b/FMC Planner 2.xcodeproj/project.pbxproj @@ -19,6 +19,7 @@ E28E106D1C9FF93D006E2C6B /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E28E106C1C9FF93D006E2C6B /* QuartzCore.framework */; }; E28E10711CA01EC9006E2C6B /* MENU.plist in Resources */ = {isa = PBXBuildFile; fileRef = E28E10701CA01EC9006E2C6B /* MENU.plist */; }; E28E10731CA0375F006E2C6B /* ROUTE.plist in Resources */ = {isa = PBXBuildFile; fileRef = E28E10721CA0375F006E2C6B /* ROUTE.plist */; }; + E29391CE1CA444F4008EB590 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = E29391CD1CA444F4008EB590 /* LaunchScreen.storyboard */; }; E2A927161CA30CEE00606E07 /* SharedDeclerations.m in Sources */ = {isa = PBXBuildFile; fileRef = E2A927151CA30CEE00606E07 /* SharedDeclerations.m */; }; E2CC73E31CA2B7C7005B786E /* PERF INIT.plist in Resources */ = {isa = PBXBuildFile; fileRef = E2CC73E21CA2B7C7005B786E /* PERF INIT.plist */; }; /* End PBXBuildFile section */ @@ -63,6 +64,7 @@ E28E106C1C9FF93D006E2C6B /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; E28E10701CA01EC9006E2C6B /* MENU.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = MENU.plist; sourceTree = ""; }; E28E10721CA0375F006E2C6B /* ROUTE.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = ROUTE.plist; sourceTree = ""; }; + E29391CD1CA444F4008EB590 /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = LaunchScreen.storyboard; sourceTree = ""; }; E2A927141CA30CEE00606E07 /* SharedDeclerations.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SharedDeclerations.h; sourceTree = ""; }; E2A927151CA30CEE00606E07 /* SharedDeclerations.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SharedDeclerations.m; sourceTree = ""; }; E2CC73E21CA2B7C7005B786E /* PERF INIT.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "PERF INIT.plist"; sourceTree = ""; }; @@ -198,6 +200,7 @@ isa = PBXGroup; children = ( E22EE9D81C9DB7B3001F5BC0 /* Main.storyboard */, + E29391CD1CA444F4008EB590 /* LaunchScreen.storyboard */, ); name = Storyboards; sourceTree = ""; @@ -330,6 +333,7 @@ E2CC73E31CA2B7C7005B786E /* PERF INIT.plist in Resources */, E28E10711CA01EC9006E2C6B /* MENU.plist in Resources */, E22EE9DC1C9DB7B3001F5BC0 /* Assets.xcassets in Resources */, + E29391CE1CA444F4008EB590 /* LaunchScreen.storyboard in Resources */, E28E10731CA0375F006E2C6B /* ROUTE.plist in Resources */, E22EE9DA1C9DB7B3001F5BC0 /* Main.storyboard in Resources */, ); diff --git a/FMC Planner 2.xcodeproj/xcuserdata/Kili2.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/FMC Planner 2.xcodeproj/xcuserdata/Kili2.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index fe2b454..44994f5 100644 --- a/FMC Planner 2.xcodeproj/xcuserdata/Kili2.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/FMC Planner 2.xcodeproj/xcuserdata/Kili2.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -2,4 +2,86 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/FMC Planner 2/Base.lproj/Main.storyboard b/FMC Planner 2/Base.lproj/Main.storyboard index 2963cc7..e2ccb6a 100644 --- a/FMC Planner 2/Base.lproj/Main.storyboard +++ b/FMC Planner 2/Base.lproj/Main.storyboard @@ -888,6 +888,7 @@ + diff --git a/FMC Planner 2/Info.plist b/FMC Planner 2/Info.plist index 3a7ff7c..901842a 100644 --- a/FMC Planner 2/Info.plist +++ b/FMC Planner 2/Info.plist @@ -22,6 +22,8 @@ 1 LSRequiresIPhoneOS + UILaunchStoryboardName + LaunchScreen UIMainStoryboardFile Main UIRequiredDeviceCapabilities diff --git a/FMC Planner 2/LaunchScreen.storyboard b/FMC Planner 2/LaunchScreen.storyboard new file mode 100644 index 0000000..673e0f7 --- /dev/null +++ b/FMC Planner 2/LaunchScreen.storyboard @@ -0,0 +1,7 @@ + + + + + + + diff --git a/FMC Planner 2/ViewController.h b/FMC Planner 2/ViewController.h index eea221a..9138e9e 100644 --- a/FMC Planner 2/ViewController.h +++ b/FMC Planner 2/ViewController.h @@ -11,11 +11,13 @@ #import "ViewControllerScreen.h" #import -@interface ViewController : UIViewController +@interface ViewController : UIViewController @property(strong, nonatomic) ViewControllerScreen *screen; @property(strong, nonatomic) ViewControllerKeyboard *keys; @property(strong, nonatomic) NSMutableDictionary *save; +@property(nonatomic) BOOL firstLoad; +@property(strong, nonatomic) NSString *backupCoRte; @property(strong, nonatomic) IBOutlet UIView *backdropKeys; diff --git a/FMC Planner 2/ViewController.m b/FMC Planner 2/ViewController.m index 961453e..8e55822 100644 --- a/FMC Planner 2/ViewController.m +++ b/FMC Planner 2/ViewController.m @@ -20,6 +20,7 @@ _backdropScreen.layer.masksToBounds = YES; // Setup save system _save = [[NSMutableDictionary alloc] init]; + _firstLoad = true; } - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { @@ -34,18 +35,74 @@ } } -#warning TODO: check if file already exists -- load or replace -#warning TODO: else -> jump to file browsing for load/delete - (void)saveToFile:(NSDictionary *)save { - if (!([_save valueForKey:@"MENU@LSKR1"] == nil || - [[_save valueForKey:@"MENU@LSKR1"] isEqualToString:@""])) { + if (_firstLoad) { + if ([[NSFileManager defaultManager] + fileExistsAtPath: + [SharedDeclerations + savePathForFile:[_save valueForKey:@"MENU@LSKR1"]]]) { +#warning TODO: check if file already exists -- load or replace + 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: + [SharedDeclerations + savePathForFile: + [_save + valueForKey:@"MENU@LSKR1"]] + 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]; + } + } else { + [_save + writeToFile:[SharedDeclerations + savePathForFile:[_save + valueForKey:@"MENU@LSKR1"]] + atomically:YES]; + } + } else if (!([_save valueForKey:@"MENU@LSKR1"] == nil || + [[_save valueForKey:@"MENU@LSKR1"] isEqualToString:@""])) { [_save writeToFile:[SharedDeclerations savePathForFile: - [SharedDeclerations - savePathForFile: - [_save valueForKey:@"MENU@LSKR1"]]] - atomically:YES]; + + [_save valueForKey:@"MENU@LSKR1"]] + atomically:NO]; } + _firstLoad = false; } - (void)loadSave:(NSString *)file { @@ -53,6 +110,24 @@ fileExistsAtPath:[SharedDeclerations savePathForFile:file]]) { _save = [[NSMutableDictionary alloc] initWithContentsOfFile:[SharedDeclerations savePathForFile:file]]; + [_screen clearScreen]; + [_screen loadDataToScreen]; + } +} + +#pragma mark - Delegate vo UIAlertView + +- (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; } } diff --git a/FMC Planner 2/ViewControllerScreen.h b/FMC Planner 2/ViewControllerScreen.h index 75c2681..dbc8e90 100644 --- a/FMC Planner 2/ViewControllerScreen.h +++ b/FMC Planner 2/ViewControllerScreen.h @@ -26,7 +26,10 @@ @property(strong, nonatomic) IBOutlet NSLayoutConstraint *FrameHeight; +@property(strong, nonatomic) IBOutlet UILabel *LSK_R1; + - (void)loadScreen:(NSString *)screenName withOptions:(NSArray *)options; - (void)loadDataToScreen; +- (void)clearScreen; @end diff --git a/FMC Planner 2/ViewControllerScreen.m b/FMC Planner 2/ViewControllerScreen.m index 562b3d1..6a011a1 100644 --- a/FMC Planner 2/ViewControllerScreen.m +++ b/FMC Planner 2/ViewControllerScreen.m @@ -71,6 +71,16 @@ - (void)enterLSK:(UITapGestureRecognizer *)tapReg { if ([_Scratchpad.text isEqualToString:@"DELETE"]) { ((UILabel *)tapReg.view).text = @""; + } else if ([((UILabel *)tapReg.view) + .restorationIdentifier isEqualToString:@"LSKR1"]) { + if ([((UILabel *)tapReg.view).text isEqualToString:@""]) { + _main.firstLoad = true; + } else if (!([((UILabel *)tapReg.view) + .text isEqualToString:_Scratchpad.text])) { + _main.firstLoad = true; + } + _main.backupCoRte = ((UILabel *)tapReg.view).text; + ((UILabel *)tapReg.view).text = _Scratchpad.text; } else { ((UILabel *)tapReg.view).text = _Scratchpad.text; } @@ -86,15 +96,16 @@ indexSlash.location) withString:[NSString stringWithFormat: - @"/%u", - _maxNumRoutePages]]; + @"/%lu", + (unsigned long) + _maxNumRoutePages]]; } - _Scratchpad.text = @""; [_main.save setObject:((UILabel *)tapReg.view).text forKey:[NSString stringWithFormat:@"%@@%@", _Header.text, ((UILabel *)tapReg.view) .restorationIdentifier]]; + _Scratchpad.text = @""; [_main saveToFile:_main.save]; } @@ -120,10 +131,10 @@ _numRoutePage = 1; } _Header.text = [_Header.text - stringByAppendingString:[NSString - stringWithFormat:@" %u/%u", - _numRoutePage, - _maxNumRoutePages]]; + stringByAppendingString: + [NSString stringWithFormat:@" %lu/%lu", + (unsigned long)_numRoutePage, + (unsigned long)_maxNumRoutePages]]; } [self loadDataToScreen]; }