From ba0ba5f706014e097b190065c577cdc4f789b7cb Mon Sep 17 00:00:00 2001 From: Kilian Hofmann Date: Wed, 30 Mar 2016 23:50:24 +0200 Subject: [PATCH] Added pragma marks, new clang-format --- .clang-format | 72 +++++++++------------ FMC Planner 2/AppDelegate.h | 12 +++- FMC Planner 2/AppDelegate.m | 25 +++++--- FMC Planner 2/DropboxV2ObjC.h | 25 +++++--- FMC Planner 2/DropboxV2ObjC.m | 76 ++++++++++++++--------- FMC Planner 2/SharedDeclerations.h | 9 ++- FMC Planner 2/SharedDeclerations.m | 16 +++-- FMC Planner 2/TableViewController.h | 8 ++- FMC Planner 2/TableViewController.m | 32 ++++++---- FMC Planner 2/ViewController.h | 22 ++++--- FMC Planner 2/ViewController.m | 42 ++++++++----- FMC Planner 2/ViewControllerKeyboard.h | 19 ++++-- FMC Planner 2/ViewControllerKeyboard.m | 43 +++++++++---- FMC Planner 2/ViewControllerScreen.h | 26 +++++--- FMC Planner 2/ViewControllerScreen.m | 74 ++++++++++++++-------- FMC Planner 2/ViewControllerServiceMenu.h | 11 +++- FMC Planner 2/ViewControllerServiceMenu.m | 24 ++++--- FMC Planner 2/main.m | 3 +- 18 files changed, 347 insertions(+), 192 deletions(-) diff --git a/.clang-format b/.clang-format index 40eb739..9d7b316 100644 --- a/.clang-format +++ b/.clang-format @@ -1,65 +1,51 @@ --- -Language: Cpp -# BasedOnStyle: LLVM +Language: Cpp AccessModifierOffset: -2 -AlignAfterOpenBracket: true AlignEscapedNewlinesLeft: false -AlignOperands: true AlignTrailingComments: true +AlignAfterOpenBracket: true AllowAllParametersOfDeclarationOnNextLine: true -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: false AllowShortIfStatementsOnASingleLine: false AllowShortLoopsOnASingleLine: false -AllowShortFunctionsOnASingleLine: All -AlwaysBreakAfterDefinitionReturnType: false -AlwaysBreakTemplateDeclarations: false AlwaysBreakBeforeMultilineStrings: false -BreakBeforeBinaryOperators: None +AlwaysBreakTemplateDeclarations: false +BinPackParameters: true +BreakBeforeBinaryOperators: false +BreakBeforeBraces: Linux BreakBeforeTernaryOperators: true BreakConstructorInitializersBeforeComma: false -BinPackParameters: true -BinPackArguments: true -ColumnLimit: 80 +ColumnLimit: 80 +CommentPragmas: '^ IWYU pragma:' ConstructorInitializerAllOnOneLineOrOnePerLine: false ConstructorInitializerIndentWidth: 4 -DerivePointerAlignment: false +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DerivePointerBinding: false ExperimentalAutoDetectBinPacking: false -IndentCaseLabels: false -IndentWrappedFunctionNames: false -IndentFunctionDeclarationAfterType: false -MaxEmptyLinesToKeep: 1 -KeepEmptyLinesAtTheStartOfBlocks: true +IndentCaseLabels: true +IndentFunctionDeclarationAfterType: true +IndentWidth: 4 +MaxEmptyLinesToKeep: 2 NamespaceIndentation: None -ObjCBlockIndentWidth: 4 -ObjCSpaceAfterProperty: false +ObjCSpaceAfterProperty: true ObjCSpaceBeforeProtocolList: true +ObjCBlockIndentWidth: 4 PenaltyBreakBeforeFirstCallParameter: 19 PenaltyBreakComment: 300 -PenaltyBreakString: 1000 PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 PenaltyExcessCharacter: 1000000 PenaltyReturnTypeOnItsOwnLine: 60 -PointerAlignment: Right -SpacesBeforeTrailingComments: 1 -Cpp11BracedListStyle: true -Standard: Cpp11 -IndentWidth: 4 -TabWidth: 8 -UseTab: Never -BreakBeforeBraces: Attach -SpacesInParentheses: false -SpacesInSquareBrackets: false -SpacesInAngles: false -SpaceInEmptyParentheses: false -SpacesInCStyleCastParentheses: false -SpaceAfterCStyleCast: false -SpacesInContainerLiterals: true +PointerBindsToType: false SpaceBeforeAssignmentOperators: true -ContinuationIndentWidth: 4 -CommentPragmas: '^ IWYU pragma:' -ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] SpaceBeforeParens: ControlStatements -DisableFormat: false -... - +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +Standard: Cpp11 +TabWidth: 8 +UseTab: Never diff --git a/FMC Planner 2/AppDelegate.h b/FMC Planner 2/AppDelegate.h index ab984c0..1052884 100644 --- a/FMC Planner 2/AppDelegate.h +++ b/FMC Planner 2/AppDelegate.h @@ -12,8 +12,14 @@ @interface AppDelegate : UIResponder -@property(strong, nonatomic) UIWindow *window; -@property(strong, nonatomic) DropboxV2ObjC *dbClient; -@property(strong, nonatomic) UIViewController *smWebView; +@property (strong, nonatomic) UIWindow *window; + +#pragma mark - Shared Dropbox client +/// Shared Dropbox client +@property (strong, nonatomic) DropboxV2ObjC *dbClient; + +#pragma mark - Refrence to authentication web view in order to dismiss it + +@property (strong, nonatomic) UIViewController *smWebView; @end diff --git a/FMC Planner 2/AppDelegate.m b/FMC Planner 2/AppDelegate.m index a45e248..fb87111 100644 --- a/FMC Planner 2/AppDelegate.m +++ b/FMC Planner 2/AppDelegate.m @@ -10,8 +10,11 @@ @implementation AppDelegate +#pragma mark - Application lifecycle delegate methods + - (BOOL)application:(UIApplication *)application - didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + didFinishLaunchingWithOptions:(NSDictionary *)launchOptions +{ // Override point for customization after application launch. _dbClient = [[DropboxV2ObjC alloc] init]; NSDictionary *credentials = @@ -22,7 +25,8 @@ return YES; } -- (void)applicationWillResignActive:(UIApplication *)application { +- (void)applicationWillResignActive:(UIApplication *)application +{ // Sent when the application is about to move from active to inactive state. // This can occur for certain types of temporary interruptions (such as an // incoming phone call or SMS message) or when the user quits the @@ -31,7 +35,8 @@ // OpenGL ES frame rates. Games should use this method to pause the game. } -- (void)applicationDidEnterBackground:(UIApplication *)application { +- (void)applicationDidEnterBackground:(UIApplication *)application +{ // Use this method to release shared resources, save user data, invalidate // timers, and store enough application state information to restore your // application to its current state in case it is terminated later. @@ -39,24 +44,30 @@ // instead of applicationWillTerminate: when the user quits. } -- (void)applicationWillEnterForeground:(UIApplication *)application { +- (void)applicationWillEnterForeground:(UIApplication *)application +{ // Called as part of the transition from the background to the inactive // state; here you can undo many of the changes made on entering the // background. } -- (void)applicationDidBecomeActive:(UIApplication *)application { +- (void)applicationDidBecomeActive:(UIApplication *)application +{ // Restart any tasks that were paused (or not yet started) while the // application was inactive. If the application was previously in the // background, optionally refresh the user interface. } -- (void)applicationWillTerminate:(UIApplication *)application { +- (void)applicationWillTerminate:(UIApplication *)application +{ // Called when the application is about to terminate. Save data if // appropriate. See also applicationDidEnterBackground:. } -- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url { +#pragma mark - URL scheme handling + +- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url +{ // Display text [_dbClient authorizeUserWithToke:url completion:^(void) { diff --git a/FMC Planner 2/DropboxV2ObjC.h b/FMC Planner 2/DropboxV2ObjC.h index 7cc0b0b..44a347e 100644 --- a/FMC Planner 2/DropboxV2ObjC.h +++ b/FMC Planner 2/DropboxV2ObjC.h @@ -12,17 +12,28 @@ @interface DropboxV2ObjC : NSObject -@property(strong, nonatomic) NSString *token; +#pragma mark Client fields + +@property (strong, nonatomic) NSString *token; /// No trailing slash -@property(strong, nonatomic) NSString *rootDirectory; -@property(strong, nonatomic) NSData *kJSONNullObject; -@property(strong, nonatomic) NSURLProtectionSpace *kDropboxProtectionSpace; +@property (strong, nonatomic) NSString *rootDirectory; +@property (strong, nonatomic) NSData *kJSONNullObject; +@property (strong, nonatomic) NSURLProtectionSpace *kDropboxProtectionSpace; + +#pragma mark - Authorization methods - (BOOL)authorizeUserWithToke:(NSURL *)token completion:(void (^)(void))handler; +- (void)deauthorizeUser; + +#pragma mark - File and directory methods + - (void)downloadFromDropbox:(NSArray *)files; - (void)uploadToDropbox:(NSData *)data; - (NSArray *)contentsOfPath:(NSString *)path; -- (NSDictionary *)getUserInfo; -- (void)deauthorizeUser; -@end +#pragma mark - Other methods + +- (NSDictionary *)getUserInfo; + + +@end \ No newline at end of file diff --git a/FMC Planner 2/DropboxV2ObjC.m b/FMC Planner 2/DropboxV2ObjC.m index a52435d..8b86da3 100644 --- a/FMC Planner 2/DropboxV2ObjC.m +++ b/FMC Planner 2/DropboxV2ObjC.m @@ -9,7 +9,9 @@ #import "DropboxV2ObjC.h" @implementation DropboxV2ObjC -- (DropboxV2ObjC *)init { + +- (DropboxV2ObjC *)init +{ self = [super init]; self.rootDirectory = @""; self.kJSONNullObject = [@"null" dataUsingEncoding:NSASCIIStringEncoding]; @@ -23,8 +25,8 @@ } #pragma mark - OAuth stuff -- (BOOL)authorizeUserWithToke:(NSURL *)token - completion:(void (^)(void))handler { +- (BOOL)authorizeUserWithToke:(NSURL *)token completion:(void (^)(void))handler +{ NSScanner *scan = [NSScanner scannerWithString:token.absoluteString]; NSString *error = [[NSString alloc] init]; [scan scanUpToString:@"&error=" intoString:&error]; @@ -50,7 +52,8 @@ return true; } -- (void)deauthorizeUser { +- (void)deauthorizeUser +{ NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; request.URL = [NSURL URLWithString:@"https://api.dropboxapi.com/1/disable_access_token"]; @@ -65,15 +68,15 @@ request.HTTPMethod = @"POST"; request.HTTPBody = _kJSONNullObject; - [NSURLConnection sendAsynchronousRequest:request - queue:[[NSOperationQueue alloc] init] - completionHandler:^(NSURLResponse *response, - NSData *data, NSError *error) { - if ([[NSJSONSerialization - JSONObjectWithData:data - options:0 - error:nil] isEqualToDictionary - : @{}]) { + [NSURLConnection + sendAsynchronousRequest:request + queue:[[NSOperationQueue alloc] init] + completionHandler:^(NSURLResponse *response, NSData *data, + NSError *error) { + if ([[NSJSONSerialization JSONObjectWithData:data + options:0 + error:nil] + isEqualToDictionary:@{}]) { NSDictionary *credentials = [[NSURLCredentialStorage sharedCredentialStorage] credentialsForProtectionSpace: @@ -85,7 +88,7 @@ forProtectionSpace:_kDropboxProtectionSpace]; } - }]; + }]; } #pragma mark - File and directory operations @@ -93,11 +96,14 @@ * Pass nil as path for root dir * @return Content of directory at path or nil if error */ -- (NSArray *)contentsOfPath:(NSString *)path { +#warning make async +- (NSArray *)contentsOfPath:(NSString *)path +{ if (path == nil) { path = _rootDirectory; - } else { + } + else { path = [path stringByAppendingString:[NSString stringWithFormat:@"/%@", path]]; } @@ -131,12 +137,14 @@ error:&error]]; if ([dataOut isKindOfClass:[NSDictionary class]]) { return [dataOut valueForKey:@"entries"]; - } else { + } + else { return nil; } } -- (void)downloadFromDropbox:(NSArray *)files { +- (void)downloadFromDropbox:(NSArray *)files +{ NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; request.URL = [NSURL URLWithString:@"https://content.dropboxapi.com/2/files/download"]; @@ -166,19 +174,26 @@ forHTTPHeaderField:(@"Dropbox-API-Arg") .precomposedStringWithCanonicalMapping]; - NSURLResponse *response = nil; - NSError *error = nil; - NSData *dataOut = [NSURLConnection sendSynchronousRequest:request - returningResponse:&response - error:&error]; - [dataOut writeToFile:[SharedDeclerations savePathForFile:string] - atomically:YES]; + [NSURLConnection + sendAsynchronousRequest:request + queue:[[NSOperationQueue alloc] init] + completionHandler:^(NSURLResponse *response, NSData *data, + NSError *error) { + if (error == nil) { + [data writeToFile:[SharedDeclerations + savePathForFile:string] + atomically:YES]; + } + + }]; } } #pragma mark - Other operations -- (NSDictionary *)getUserInfo { +#warning make async +- (NSDictionary *)getUserInfo +{ NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; request.URL = [NSURL URLWithString: @@ -201,20 +216,23 @@ error:&error]]; if ([data isKindOfClass:[NSDictionary class]]) { return data; - } else { + } + else { return nil; } } #pragma mark - Helper methods -- (id)parseJSON:(NSData *)data { +- (id)parseJSON:(NSData *)data +{ NSError *error = nil; id object = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error]; if (error == nil) { return object; - } else { + } + else { return [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding]; } diff --git a/FMC Planner 2/SharedDeclerations.h b/FMC Planner 2/SharedDeclerations.h index 085d12e..262f758 100644 --- a/FMC Planner 2/SharedDeclerations.h +++ b/FMC Planner 2/SharedDeclerations.h @@ -7,6 +7,11 @@ // #import + +@interface SharedDeclerations : NSObject + +#pragma mark - Route page management macros + #define FOO1 NEXTRTEPAGE #define STRINGIZE(x) #x #define STRINGIZE2(x) STRINGIZE(x) @@ -16,12 +21,14 @@ #define STRINGIZE2(x) STRINGIZE(x) #define FMCFIRSTRTEPAGE @STRINGIZE2(FOO2) -@interface SharedDeclerations : NSObject +#pragma mark - Adaptive font size method + (UIFont *)findAdaptiveFontForUILabelSize:(CGSize)labelSize withMinimumSize:(NSInteger)minSize withMod:(float)mod; +#pragma mark - Savepath method + + (NSString *)savePathForFile:(NSString *)file; @end diff --git a/FMC Planner 2/SharedDeclerations.m b/FMC Planner 2/SharedDeclerations.m index 54c2bef..f9ccea1 100644 --- a/FMC Planner 2/SharedDeclerations.m +++ b/FMC Planner 2/SharedDeclerations.m @@ -10,9 +10,12 @@ @implementation SharedDeclerations +#pragma mark - Adaptive font size method + + (UIFont *)findAdaptiveFontForUILabelSize:(CGSize)labelSize withMinimumSize:(NSInteger)minSize - withMod:(float)mod { + withMod:(float)mod +{ UIFont *tempFont = nil; NSString *testString = @"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; @@ -39,9 +42,11 @@ if (difference < 0) { tempMax = mid - 1; - } else if (difference > 0) { + } + else if (difference > 0) { tempMin = mid + 1; - } else { + } + else { return [UIFont systemFontOfSize:mid]; } } @@ -49,7 +54,10 @@ return [UIFont systemFontOfSize:mid]; } -+ (NSString *)savePathForFile:(NSString *)file { +#pragma mark - Savepath method + ++ (NSString *)savePathForFile:(NSString *)file +{ NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsPath = paths[0]; diff --git a/FMC Planner 2/TableViewController.h b/FMC Planner 2/TableViewController.h index c40f4f0..e16557a 100644 --- a/FMC Planner 2/TableViewController.h +++ b/FMC Planner 2/TableViewController.h @@ -13,8 +13,12 @@ @class ViewController; @interface TableViewController : UITableViewController -@property(strong, nonatomic) ViewController *main; +#pragma mark - Refrence to other views in app -@property(strong, nonatomic) NSMutableArray *dataSource; +@property (strong, nonatomic) ViewController *main; + +#pragma mark - Table view data source + +@property (strong, nonatomic) NSMutableArray *dataSource; @end diff --git a/FMC Planner 2/TableViewController.m b/FMC Planner 2/TableViewController.m index 0108d5b..9e7b0aa 100644 --- a/FMC Planner 2/TableViewController.m +++ b/FMC Planner 2/TableViewController.m @@ -10,7 +10,10 @@ @implementation TableViewController -- (void)viewDidLoad { +#pragma mark - View management and navigation + +- (void)viewDidLoad +{ [super viewDidLoad]; // Uncomment the following line to preserve selection between presentations. @@ -31,24 +34,22 @@ } } -- (void)didReceiveMemoryWarning { - [super didReceiveMemoryWarning]; - // Dispose of any resources that can be recreated. -} - #pragma mark - Table view data source -- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView +{ return 1; } - (NSInteger)tableView:(UITableView *)tableView - numberOfRowsInSection:(NSInteger)section { + numberOfRowsInSection:(NSInteger)section +{ return _dataSource.count; } - (UITableViewCell *)tableView:(UITableView *)tableView - cellForRowAtIndexPath:(NSIndexPath *)indexPath { + cellForRowAtIndexPath:(NSIndexPath *)indexPath +{ UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath]; @@ -63,10 +64,13 @@ return cell; } +#pragma mark - Table view editing action + // Override to support editing the table view. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle - forRowAtIndexPath:(NSIndexPath *)indexPath { + forRowAtIndexPath:(NSIndexPath *)indexPath +{ if (editingStyle == UITableViewCellEditingStyleDelete) { // Delete the row from the data source [[NSFileManager defaultManager] @@ -76,14 +80,18 @@ [_dataSource removeObjectAtIndex:indexPath.row]; [tableView deleteRowsAtIndexPaths:@[ indexPath ] withRowAnimation:UITableViewRowAnimationFade]; - } else if (editingStyle == UITableViewCellEditingStyleInsert) { + } + 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 } } +#pragma mark - Table view cell selection action + - (void)tableView:(UITableView *)tableView - didSelectRowAtIndexPath:(NSIndexPath *)indexPath { + didSelectRowAtIndexPath:(NSIndexPath *)indexPath +{ if ([self.title isEqualToString:@"Manage"]) { [self dismissViewControllerAnimated:YES completion:^(void) { diff --git a/FMC Planner 2/ViewController.h b/FMC Planner 2/ViewController.h index e01ef19..89bfcf2 100644 --- a/FMC Planner 2/ViewController.h +++ b/FMC Planner 2/ViewController.h @@ -14,15 +14,23 @@ @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; +#pragma mark - Refrence to other views in app -@property(strong, nonatomic) IBOutlet UIView *backdropKeys; +@property (strong, nonatomic) ViewControllerScreen *screen; +@property (strong, nonatomic) ViewControllerKeyboard *keys; -@property(strong, nonatomic) IBOutlet UIView *backdropScreen; +#pragma mark - Save and loading + +@property (strong, nonatomic) NSMutableDictionary *save; +@property (nonatomic) BOOL firstLoad; +@property (strong, nonatomic) NSString *backupCoRte; + +#pragma mark - Refrences to views for corner rounding + +@property (strong, nonatomic) IBOutlet UIView *backdropKeys; +@property (strong, nonatomic) IBOutlet UIView *backdropScreen; + +#pragma mark - Save and loading methods - (void)loadSave:(NSString *)file; - (void)saveToFile:(NSDictionary *)save; diff --git a/FMC Planner 2/ViewController.m b/FMC Planner 2/ViewController.m index 8f689a3..aaeb88a 100644 --- a/FMC Planner 2/ViewController.m +++ b/FMC Planner 2/ViewController.m @@ -10,7 +10,10 @@ @implementation ViewController -- (void)viewDidLoad { +#pragma mark - View management and navigation + +- (void)viewDidLoad +{ [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. // Round corners @@ -24,7 +27,8 @@ self.title = @"FMC"; } -- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { +- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender +{ NSString *segueName = segue.identifier; if ([segueName isEqualToString:@"keyboard"]) { _keys = (ViewControllerKeyboard *)segue.destinationViewController; @@ -36,25 +40,30 @@ } } -- (void)saveToFile:(NSDictionary *)save { +#pragma mark - Loading and saving actions + +- (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) { + } + 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:@""])) { + } + else if (!([_save valueForKey:@"MENU@LSKR1"] == nil || + [[_save valueForKey:@"MENU@LSKR1"] isEqualToString:@""])) { [_save writeToFile:file atomically:YES]; } _firstLoad = false; } -- (void)loadSave:(NSString *)file { +- (void)loadSave:(NSString *)file +{ if ([[NSFileManager defaultManager] fileExistsAtPath:[SharedDeclerations savePathForFile:file]]) { _save = [[NSMutableDictionary alloc] @@ -67,20 +76,24 @@ #pragma mark - Delegate for UIAlertView and UIAlertController outsource - (void)alertView:(UIAlertView *)alertView - clickedButtonAtIndex:(NSInteger)buttonIndex { + clickedButtonAtIndex:(NSInteger)buttonIndex +{ if (buttonIndex == 1) { [self loadSave:[_save valueForKey:@"MENU@LSKR1"]]; - } else if (buttonIndex == 2) { + } + else if (buttonIndex == 2) { [_save writeToFile:[SharedDeclerations savePathForFile:[_save valueForKey:@"MENU@LSKR1"]] atomically:YES]; - } else { + } + else { _screen.LSK_R1.text = _backupCoRte; } } -- (void)alertViewiOS7:(NSString *)file { +- (void)alertViewiOS7:(NSString *)file +{ if ([UIAlertController class]) { UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Load or replace?" @@ -107,7 +120,8 @@ [alert addAction:loadAction]; [alert addAction:replaceAction]; [self presentViewController:alert animated:YES completion:nil]; - } else { + } + else { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Load or replace?" message:@"The entered CO ROUTE alreay exists. Do " diff --git a/FMC Planner 2/ViewControllerKeyboard.h b/FMC Planner 2/ViewControllerKeyboard.h index 7a7309d..acfd9c0 100644 --- a/FMC Planner 2/ViewControllerKeyboard.h +++ b/FMC Planner 2/ViewControllerKeyboard.h @@ -12,12 +12,21 @@ @class ViewController; @interface ViewControllerKeyboard : UIViewController -@property(nonatomic) BOOL alphaOn; -@property(strong, nonatomic) NSArray *alphabet; -@property(strong, nonatomic) NSArray *numeric; -@property(strong, nonatomic) ViewController *main; +#pragma mark - Keyboard management -@property(strong, nonatomic) IBOutletCollection(UIButton) NSArray *Keys; +@property (nonatomic) BOOL alphaOn; +@property (strong, nonatomic) NSArray *alphabet; +@property (strong, nonatomic) NSArray *numeric; + +#pragma mark - Refrence to other views in app + +@property (strong, nonatomic) ViewController *main; + +#pragma mark - Keys as Array + +@property (strong, nonatomic) IBOutletCollection(UIButton) NSArray *Keys; + +#pragma mark - Key methods - (IBAction)KeyTaps:(UIButton *)sender; diff --git a/FMC Planner 2/ViewControllerKeyboard.m b/FMC Planner 2/ViewControllerKeyboard.m index b40c47c..9d476aa 100644 --- a/FMC Planner 2/ViewControllerKeyboard.m +++ b/FMC Planner 2/ViewControllerKeyboard.m @@ -11,7 +11,10 @@ @implementation ViewControllerKeyboard -- (void)viewDidLoad { +#pragma mark - View management and navigation + +- (void)viewDidLoad +{ [super viewDidLoad]; // Do any additional setup after loading the view. _alphaOn = true; @@ -94,41 +97,54 @@ } } -- (IBAction)KeyTaps:(UIButton *)sender { +#pragma mark - Keyborad actions + +- (IBAction)KeyTaps:(UIButton *)sender +{ if ([sender.restorationIdentifier isEqualToString:@"Switch"]) { _alphaOn = !_alphaOn; [self switchKeyboard]; - } else if ([sender.restorationIdentifier isEqualToString:@"Space"]) { + } + else if ([sender.restorationIdentifier isEqualToString:@"Space"]) { _main.screen.Scratchpad.text = [_main.screen.Scratchpad.text stringByAppendingString:@" "]; - } else if ([sender.restorationIdentifier isEqualToString:@"Clear"]) { + } + else if ([sender.restorationIdentifier isEqualToString:@"Clear"]) { if ([_main.screen.Scratchpad.text isEqualToString:@"DELETE"]) { _main.screen.Scratchpad.text = @""; - } else if (_main.screen.Scratchpad.text.length > 0) { + } + else if (_main.screen.Scratchpad.text.length > 0) { _main.screen.Scratchpad.text = [_main.screen.Scratchpad.text substringToIndex:(_main.screen.Scratchpad.text).length - 1]; } - } else if ([sender.restorationIdentifier isEqualToString:@"Delete"]) { + } + else if ([sender.restorationIdentifier isEqualToString:@"Delete"]) { _main.screen.Scratchpad.text = @"DELETE"; - } else if ([sender.restorationIdentifier isEqualToString:@"Top"]) { + } + else if ([sender.restorationIdentifier isEqualToString:@"Top"]) { [_main.screen loadScreen:@"MENU" withOptions:nil]; - } else if ([sender.restorationIdentifier isEqualToString:@"Mid"]) { + } + else if ([sender.restorationIdentifier isEqualToString:@"Mid"]) { [_main.screen loadScreen:@"PERF INIT" withOptions:nil]; - } else if ([sender.restorationIdentifier isEqualToString:@"Bot"]) { + } + else if ([sender.restorationIdentifier isEqualToString:@"Bot"]) { if (_main.screen.maxNumRoutePages > _main.screen.numRoutePage && ([[_main.screen.Header.text substringToIndex:3] isEqualToString:@"ROU"])) { [_main.screen loadScreen:@"ROUTE" withOptions:@[ FMCNEXTRTEPAGE ]]; - } else { + } + else { [_main.screen loadScreen:@"ROUTE" withOptions:@[ FMCFIRSTRTEPAGE ]]; } - } else { + } + else { _main.screen.Scratchpad.text = [_main.screen.Scratchpad.text stringByAppendingString:sender.titleLabel.text]; } } -- (void)switchKeyboard { +- (void)switchKeyboard +{ if (_alphaOn) { for (int i = 0; i < _Keys.count; i++) { ((UIButton *)_Keys[i]).titleLabel.numberOfLines = 0; @@ -138,7 +154,8 @@ forState:UIControlStateNormal]; [((UIButton *)_Keys[i]).titleLabel sizeToFit]; } - } else { + } + else { for (int i = 0; i < _Keys.count; i++) { ((UIButton *)_Keys[i]).titleLabel.numberOfLines = 0; ((UIButton *)_Keys[i]).titleLabel.lineBreakMode = diff --git a/FMC Planner 2/ViewControllerScreen.h b/FMC Planner 2/ViewControllerScreen.h index bbf3902..b5557c5 100644 --- a/FMC Planner 2/ViewControllerScreen.h +++ b/FMC Planner 2/ViewControllerScreen.h @@ -14,20 +14,28 @@ @class ViewController; @interface ViewControllerScreen : UIViewController -@property(strong, nonatomic) ViewController *main; -@property(nonatomic) NSUInteger maxNumRoutePages; -@property(nonatomic) NSUInteger numRoutePage; +#pragma mark - Refrence to other views in app -@property(strong, nonatomic) IBOutletCollection(UILabel) NSArray *LSK; -@property(strong, nonatomic) IBOutletCollection(UILabel) NSArray *Desc; +@property (strong, nonatomic) ViewController *main; -@property(strong, nonatomic) IBOutlet UILabel *Scratchpad; +#pragma mark - Route page management -@property(strong, nonatomic) IBOutlet UILabel *Header; +@property (nonatomic) NSUInteger maxNumRoutePages; +@property (nonatomic) NSUInteger numRoutePage; -@property(strong, nonatomic) IBOutlet NSLayoutConstraint *FrameHeight; +#pragma mark - Text fileds on view -@property(strong, nonatomic) IBOutlet UILabel *LSK_R1; +@property (strong, nonatomic) IBOutletCollection(UILabel) NSArray *LSK; +@property (strong, nonatomic) IBOutletCollection(UILabel) NSArray *Desc; +@property (strong, nonatomic) IBOutlet UILabel *Scratchpad; +@property (strong, nonatomic) IBOutlet UILabel *Header; +@property (strong, nonatomic) IBOutlet UILabel *LSK_R1; + +#pragma mark - Constraint to adjust dynamic label height + +@property (strong, nonatomic) IBOutlet NSLayoutConstraint *FrameHeight; + +#pragma mark - Screen methods - (void)loadScreen:(NSString *)screenName withOptions:(NSArray *)options; - (void)loadDataToScreen; diff --git a/FMC Planner 2/ViewControllerScreen.m b/FMC Planner 2/ViewControllerScreen.m index 0b90333..e2876b3 100644 --- a/FMC Planner 2/ViewControllerScreen.m +++ b/FMC Planner 2/ViewControllerScreen.m @@ -11,7 +11,10 @@ @implementation ViewControllerScreen -- (void)viewDidLoad { +#pragma mark - View management and navigation + +- (void)viewDidLoad +{ [super viewDidLoad]; // Do any additional setup after loading the view. @@ -36,12 +39,14 @@ } } -- (void)viewDidAppear:(BOOL)animated { +- (void)viewDidAppear:(BOOL)animated +{ [super viewDidAppear:YES]; [self loadScreen:@"MENU" withOptions:nil]; } -- (void)viewDidLayoutSubviews { +- (void)viewDidLayoutSubviews +{ _FrameHeight.constant = self.view.frame.size.height / 14.5; // Size and LineBreak _Header.font = @@ -62,28 +67,28 @@ } } -- (void)clearScreen { - for (UILabel *label in _LSK) { - label.text = @""; - } -} +#pragma mark - LSK action -- (void)enterLSK:(UITapGestureRecognizer *)tapReg { +- (void)enterLSK:(UITapGestureRecognizer *)tapReg +{ if ([_Scratchpad.text isEqualToString:@"DELETE"]) { ((UILabel *)tapReg.view).text = @""; - } else if ([_Header.text isEqualToString:@"MENU"]) { + } + else if ([_Header.text isEqualToString:@"MENU"]) { 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])) { + } + 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 if ([((UILabel *)tapReg.view) - .restorationIdentifier isEqualToString:@"LSKR4"]) { + } + else if ([((UILabel *)tapReg.view) + .restorationIdentifier isEqualToString:@"LSKR4"]) { [_main saveToFile:_main.save]; _main.save = [[NSMutableDictionary alloc] init]; [self clearScreen]; @@ -102,20 +107,24 @@ } } } - } else if ([((UILabel *)tapReg.view) - .restorationIdentifier isEqualToString:@"LSKR5"]) { + } + else if ([((UILabel *)tapReg.view) + .restorationIdentifier isEqualToString:@"LSKR5"]) { #warning EXPORT TO PMDG GOES HERE - } else if ([((UILabel *)tapReg.view) - .restorationIdentifier isEqualToString:@"LSKR6"]) { + } + else if ([((UILabel *)tapReg.view) + .restorationIdentifier isEqualToString:@"LSKR6"]) { UINavigationController *sm = [self.storyboard instantiateViewControllerWithIdentifier:@"ServiceMenu"]; ((ViewControllerServiceMenu *)(sm.childViewControllers).firstObject) .main = _main; [self presentViewController:sm animated:YES completion:nil]; - } else { + } + else { ((UILabel *)tapReg.view).text = _Scratchpad.text; } - } else { + } + else { ((UILabel *)tapReg.view).text = _Scratchpad.text; } if ([((UILabel *)tapReg.view) @@ -135,14 +144,25 @@ (unsigned long) _maxNumRoutePages]]; } - (_main.save)[[NSString stringWithFormat:@"%@@%@", _Header.text, - ((UILabel *)tapReg.view) - .restorationIdentifier]] = ((UILabel *)tapReg.view).text; + (_main.save)[[NSString + stringWithFormat:@"%@@%@", _Header.text, + ((UILabel *)tapReg.view).restorationIdentifier]] = + ((UILabel *)tapReg.view).text; _Scratchpad.text = @""; [_main saveToFile:_main.save]; } -- (void)loadScreen:(NSString *)screenName withOptions:(NSArray *)options { +#pragma mark - Screen actions + +- (void)clearScreen +{ + for (UILabel *label in _LSK) { + label.text = @""; + } +} + +- (void)loadScreen:(NSString *)screenName withOptions:(NSArray *)options +{ [self clearScreen]; _Header.text = screenName; NSArray *screen = @@ -167,7 +187,8 @@ for (NSString *opt in options) { if ([opt isEqualToString:FMCNEXTRTEPAGE]) { _numRoutePage += 1; - } else if ([opt isEqualToString:FMCFIRSTRTEPAGE]) { + } + else if ([opt isEqualToString:FMCFIRSTRTEPAGE]) { _numRoutePage = 1; } _Header.text = [_Header.text @@ -193,7 +214,8 @@ } } -- (void)loadDataToScreen { +- (void)loadDataToScreen +{ for (NSString *ident in _main.save) { NSRange range = [ident rangeOfString:@"@"]; if ([[ident substringToIndex:range.location] diff --git a/FMC Planner 2/ViewControllerServiceMenu.h b/FMC Planner 2/ViewControllerServiceMenu.h index 042aeaf..296d047 100644 --- a/FMC Planner 2/ViewControllerServiceMenu.h +++ b/FMC Planner 2/ViewControllerServiceMenu.h @@ -15,8 +15,15 @@ @interface ViewControllerServiceMenu : UIViewController -@property(strong, nonatomic) ViewController *main; -@property(strong, nonatomic) IBOutlet UIButton *dbConnectButton; +#pragma mark - Refrence to other views in app + +@property (strong, nonatomic) ViewController *main; + +#pragma mark - Outlet fo Dropbox button + +@property (strong, nonatomic) IBOutlet UIButton *dbConnectButton; + +#pragma mark - Dropbox authentictaion methods - (IBAction)dbConnect:(UIButton *)sender; - (IBAction)dbDisconnect:(UIButton *)sender; diff --git a/FMC Planner 2/ViewControllerServiceMenu.m b/FMC Planner 2/ViewControllerServiceMenu.m index 87185f1..30bc250 100644 --- a/FMC Planner 2/ViewControllerServiceMenu.m +++ b/FMC Planner 2/ViewControllerServiceMenu.m @@ -9,7 +9,10 @@ @implementation ViewControllerServiceMenu -- (void)viewDidLoad { +#pragma mark - View management and navigation + +- (void)viewDidLoad +{ [super viewDidLoad]; self.title = @"Service Menu"; self.navigationItem.leftBarButtonItem = @@ -19,7 +22,9 @@ action:@selector(back)]; } -- (void)viewWillAppear:(BOOL)animated { +- (void)viewWillAppear:(BOOL)animated +{ + [super viewWillAppear:animated]; DropboxV2ObjC *dbClient = ((AppDelegate *)[UIApplication sharedApplication].delegate).dbClient; if (dbClient.token != nil) { @@ -34,11 +39,13 @@ } } -- (void)back { +- (void)back +{ [self dismissViewControllerAnimated:YES completion:nil]; } -- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { +- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender +{ ((TableViewController *)segue.destinationViewController).title = segue.identifier; ((TableViewController *)segue.destinationViewController).main = _main; @@ -47,7 +54,8 @@ #pragma mark - Dropbox Button // Standard action (hence set), dnamically set and unset -- (IBAction)dbConnect:(UIButton *)sender { +- (IBAction)dbConnect:(UIButton *)sender +{ UIViewController *webController = [[UIViewController alloc] init]; webController.title = @"Dropbox"; UIWebView *web = [[UIWebView alloc] initWithFrame:webController.view.frame]; @@ -65,7 +73,8 @@ } // Dynamically set and unset -- (IBAction)dbDisconnect:(UIButton *)sender { +- (IBAction)dbDisconnect:(UIButton *)sender +{ DropboxV2ObjC *dbClient = ((AppDelegate *)[UIApplication sharedApplication].delegate).dbClient; [dbClient deauthorizeUser]; @@ -80,7 +89,8 @@ } #warning TESTING GROUNDS -- (IBAction)testing:(id)sender { +- (IBAction)testing:(id)sender +{ DropboxV2ObjC *dbClient = ((AppDelegate *)[UIApplication sharedApplication].delegate).dbClient; NSLog(@"%@", [dbClient contentsOfPath:nil]); diff --git a/FMC Planner 2/main.m b/FMC Planner 2/main.m index b35c7bd..b8a91af 100644 --- a/FMC Planner 2/main.m +++ b/FMC Planner 2/main.m @@ -9,7 +9,8 @@ #import "AppDelegate.h" #import -int main(int argc, char *argv[]) { +int main(int argc, char *argv[]) +{ @autoreleasepool { return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));