diff --git a/FMC Planner 2/AppDelegate.m b/FMC Planner 2/AppDelegate.m
index cbc552b..2ec222c 100644
--- a/FMC Planner 2/AppDelegate.m
+++ b/FMC Planner 2/AppDelegate.m
@@ -26,6 +26,7 @@
[_dbClient setupDropboxWithHandler:^{
}
presenter:nil];
+ [self setup];
return YES;
}
@@ -86,4 +87,49 @@
return YES;
}
+#pragma mark - Setup of save system
+
+- (void)setup
+{
+ NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
+ NSUserDomainMask, YES);
+ NSString *documentsPath = paths[0];
+ BOOL saves = false;
+ BOOL oldSaves = false;
+ BOOL navData = false;
+ [[NSFileManager defaultManager]
+ fileExistsAtPath:[documentsPath stringByAppendingString:@"/SAVES"]
+ isDirectory:&saves];
+ [[NSFileManager defaultManager]
+ fileExistsAtPath:[documentsPath stringByAppendingString:@"/OLDSAVES"]
+ isDirectory:&oldSaves];
+ [[NSFileManager defaultManager]
+ fileExistsAtPath:[documentsPath stringByAppendingString:@"/NAVDATA"]
+ isDirectory:&navData];
+ if (!saves) {
+ [[NSFileManager defaultManager]
+ createDirectoryAtPath:[documentsPath
+ stringByAppendingString:@"/SAVES"]
+ withIntermediateDirectories:NO
+ attributes:nil
+ error:nil];
+ }
+ if (!oldSaves) {
+ [[NSFileManager defaultManager]
+ createDirectoryAtPath:
+ [documentsPath stringByAppendingString:@"/OLDSAVES"]
+ withIntermediateDirectories:NO
+ attributes:nil
+ error:nil];
+ }
+ if (!navData) {
+ [[NSFileManager defaultManager]
+ createDirectoryAtPath:[documentsPath
+ stringByAppendingString:@"/NAVDATA"]
+ withIntermediateDirectories:NO
+ attributes:nil
+ error:nil];
+ }
+}
+
@end
diff --git a/FMC Planner 2/Base.lproj/Main.storyboard b/FMC Planner 2/Base.lproj/Main.storyboard
index 05de0ef..ae306aa 100644
--- a/FMC Planner 2/Base.lproj/Main.storyboard
+++ b/FMC Planner 2/Base.lproj/Main.storyboard
@@ -126,16 +126,30 @@
+
+
+
+
@@ -147,6 +161,7 @@
+
diff --git a/FMC Planner 2/DropboxV2ObjC.m b/FMC Planner 2/DropboxV2ObjC.m
index 7d05440..b334a4a 100644
--- a/FMC Planner 2/DropboxV2ObjC.m
+++ b/FMC Planner 2/DropboxV2ObjC.m
@@ -93,8 +93,10 @@
else if (error != nil) {
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
- [SharedDeclerations presentErrorAlert:error
- presenter:presenter];
+ [SharedDeclerations
+ presentErrorAlert:error
+ presenter:presenter.navigationController
+ .topViewController];
}];
}
@@ -103,20 +105,45 @@
error:nil]
isEqualToDictionary:@{}]) {
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
- [SharedDeclerations
- presentErrorAlert:
- [NSError
- errorWithDomain:DropboxErrorDomain
- code:100
- userInfo:
- [[NSJSONSerialization
- JSONObjectWithData:data
- options:0
- error:nil]
- valueForKey:
- DropboxErrorUserInfo]]
-
- presenter:presenter];
+ if ([[NSJSONSerialization JSONObjectWithData:data
+ options:0
+ error:nil]
+ isKindOfClass:[NSDictionary class]]) {
+ [SharedDeclerations
+ presentErrorAlert:
+ [NSError
+ errorWithDomain:DropboxErrorDomain
+ code:100
+ userInfo:@{
+ [[NSJSONSerialization
+ JSONObjectWithData:data
+ options:0
+ error:nil]
+ valueForKey:
+ DropboxErrorUserInfo] :
+ NSLocalizedDescriptionKey
+ }]
+ presenter:presenter
+ .navigationController
+ .topViewController];
+ }
+ else {
+ [SharedDeclerations
+ presentErrorAlert:
+ [NSError
+ errorWithDomain:DropboxErrorDomain
+ code:100
+ userInfo:@{
+ [[NSString alloc]
+ initWithData:data
+ encoding:
+ NSASCIIStringEncoding] :
+ NSLocalizedDescriptionKey
+ }]
+ presenter:presenter
+ .navigationController
+ .topViewController];
+ }
}];
}
@@ -176,22 +203,54 @@
if (data2 == nil) {
[[NSOperationQueue
mainQueue] addOperationWithBlock:^{
- [SharedDeclerations
- presentErrorAlert:
- [NSError
- errorWithDomain:DropboxErrorDomain
- code:100
- userInfo:
- [[NSJSONSerialization
- JSONObjectWithData:
- data
- options:
- 0
- error:
- nil]
- valueForKey:
- DropboxErrorUserInfo]]
- presenter:presenter];
+ if ([[NSJSONSerialization
+ JSONObjectWithData:data
+ options:0
+ error:nil]
+ isKindOfClass:[NSDictionary class]]) {
+ [SharedDeclerations
+ presentErrorAlert:
+ [NSError
+ errorWithDomain:
+ DropboxErrorDomain
+ code:100
+ userInfo:@{
+ [[NSJSONSerialization
+ JSONObjectWithData:
+ data
+ options:
+ 0
+ error:
+ nil]
+ valueForKey:
+ DropboxErrorUserInfo] :
+ NSLocalizedDescriptionKey
+ }]
+ presenter:
+ presenter
+ .navigationController
+ .topViewController];
+ }
+ else {
+ [SharedDeclerations
+ presentErrorAlert:
+ [NSError
+ errorWithDomain:
+ DropboxErrorDomain
+ code:100
+ userInfo:@{
+ [[NSString alloc]
+ initWithData:
+ data
+ encoding:
+ NSASCIIStringEncoding] :
+ NSLocalizedDescriptionKey
+ }]
+ presenter:
+ presenter
+ .navigationController
+ .topViewController];
+ }
}];
}
else {
@@ -202,16 +261,20 @@
else if (error != nil) {
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
- [SharedDeclerations presentErrorAlert:error
- presenter:presenter];
+ [SharedDeclerations
+ presentErrorAlert:error
+ presenter:presenter.navigationController
+ .topViewController];
}];
}
+ handler(nil);
}];
}
/**
* Specify if EXPORT or SAVE in file name
+ * IS synchronus URLRequest, best executed in background thread.
*/
- (void)downloadFromDropbox:(NSArray *)files
presenter:(UIViewController *)presenter
@@ -231,79 +294,95 @@
// File Path
for (NSString *string in files) {
- NSData *data = [NSJSONSerialization dataWithJSONObject:@{
+ NSData *data2 = [NSJSONSerialization dataWithJSONObject:@{
@"path" : [NSString stringWithFormat:@"/%@", string]
.precomposedStringWithCanonicalMapping
}
- options:0
- error:nil];
- NSString *temp =
- [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
+ options:0
+ error:nil];
+ NSString *temp = [[NSString alloc] initWithData:data2
+ encoding:NSASCIIStringEncoding];
temp =
[temp stringByReplacingOccurrencesOfString:@"\\/" withString:@"/"];
- [request addValue:temp.precomposedStringWithCanonicalMapping
+ [request setValue:temp.precomposedStringWithCanonicalMapping
forHTTPHeaderField:(@"Dropbox-API-Arg")
.precomposedStringWithCanonicalMapping];
- [NSURLConnection
- sendAsynchronousRequest:request
- queue:[[NSOperationQueue alloc] init]
- completionHandler:^(NSURLResponse *response, NSData *data,
- NSError *error) {
- if (error == nil) {
- if ([[NSJSONSerialization JSONObjectWithData:data
- options:0
- error:nil]
- valueForKey:@"error_summary"] == nil) {
- [data writeToFile:
- [SharedDeclerations
- savePathForFile:
- [string
- substringFromIndex:
- [string
- rangeOfString:@"/"]
- .location]]
- atomically:YES];
- }
- else {
- [[NSOperationQueue
- mainQueue] addOperationWithBlock:^{
- [SharedDeclerations
- presentErrorAlert:
- [NSError
- errorWithDomain:DropboxErrorDomain
- code:100
- userInfo:
- [[NSJSONSerialization
- JSONObjectWithData:
- data
- options:
- 0
- error:
- nil]
- valueForKey:
- DropboxErrorUserInfo]]
- presenter:presenter];
- }];
- }
- }
- else if (error != nil) {
- [[NSOperationQueue mainQueue] addOperationWithBlock:^{
+ NSURLResponse *response = nil;
+ NSError *error = nil;
- [SharedDeclerations presentErrorAlert:error
- presenter:presenter];
+ NSData *data = [NSURLConnection sendSynchronousRequest:request
+ returningResponse:&response
+ error:&error];
- }];
- }
+ if (error == nil) {
+ if ([[NSJSONSerialization JSONObjectWithData:data
+ options:0
+ error:nil]
+ valueForKey:@"error_summary"] == nil) {
+ [data writeToFile:[SharedDeclerations savePathForFile:string]
+ atomically:YES];
+ }
+ else {
+ [[NSOperationQueue mainQueue] addOperationWithBlock:^{
+ if ([[NSJSONSerialization JSONObjectWithData:data
+ options:0
+ error:nil]
+ isKindOfClass:[NSDictionary class]]) {
+ [SharedDeclerations
+ presentErrorAlert:
+ [NSError
+ errorWithDomain:DropboxErrorDomain
+ code:100
+ userInfo:@{
+ [[NSJSONSerialization
+ JSONObjectWithData:data
+ options:0
+ error:nil]
+ valueForKey:
+ DropboxErrorUserInfo] :
+ NSLocalizedDescriptionKey
+ }]
+ presenter:presenter.navigationController
+ .topViewController];
+ }
+ else {
+ [SharedDeclerations
+ presentErrorAlert:
+ [NSError
+ errorWithDomain:DropboxErrorDomain
+ code:100
+ userInfo:@{
+ [[NSString alloc]
+ initWithData:data
+ encoding:
+ NSASCIIStringEncoding] :
+ NSLocalizedDescriptionKey
+ }]
+ presenter:presenter.navigationController
+ .topViewController];
+ }
+ }];
+ }
+ }
+ else if (error != nil) {
+ [[NSOperationQueue mainQueue] addOperationWithBlock:^{
- }];
+ [SharedDeclerations
+ presentErrorAlert:error
+ presenter:presenter.navigationController
+ .topViewController];
+
+ }];
+ }
}
handler();
}
/**
* Specify if SAVE or OLDSAVE in file name
+ * IS synchronus URLRequest, best executed in background thread.
*/
- (void)uploadToDropbox:(NSArray *)files
presenter:(UIViewController *)presenter
@@ -323,59 +402,83 @@
// File Path
for (NSString *string in files) {
- NSData *data = [NSJSONSerialization dataWithJSONObject:@{
+ NSData *data2 = [NSJSONSerialization dataWithJSONObject:@{
@"path" : [NSString stringWithFormat:@"/%@", string]
.precomposedStringWithCanonicalMapping,
@"mode" : @"overwrite".precomposedStringWithCanonicalMapping,
}
- options:0
- error:nil];
- NSString *temp =
- [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
+ options:0
+ error:nil];
+ NSString *temp = [[NSString alloc] initWithData:data2
+ encoding:NSASCIIStringEncoding];
temp =
[temp stringByReplacingOccurrencesOfString:@"\\/" withString:@"/"];
- [request addValue:temp.precomposedStringWithCanonicalMapping
+ [request setValue:temp.precomposedStringWithCanonicalMapping
forHTTPHeaderField:(@"Dropbox-API-Arg")
.precomposedStringWithCanonicalMapping];
request.HTTPBody = [NSData
dataWithContentsOfFile:[SharedDeclerations savePathForFile:string]];
- [NSURLConnection
- sendAsynchronousRequest:request
- queue:[[NSOperationQueue alloc] init]
- completionHandler:^(NSURLResponse *response, NSData *data,
- NSError *error) {
- if (error != nil) {
- [[NSOperationQueue mainQueue] addOperationWithBlock:^{
+ NSURLResponse *response = nil;
+ NSError *error = nil;
- [SharedDeclerations presentErrorAlert:error
- presenter:presenter];
+ NSData *data = [NSURLConnection sendSynchronousRequest:request
+ returningResponse:&response
+ error:&error];
- }];
- }
- if ([[NSJSONSerialization JSONObjectWithData:data
- options:0
- error:nil]
- valueForKey:@"error_summary"] != nil) {
- [[NSOperationQueue mainQueue] addOperationWithBlock:^{
- [SharedDeclerations
- presentErrorAlert:
- [NSError
- errorWithDomain:DropboxErrorDomain
- code:100
- userInfo:
- [[NSJSONSerialization
- JSONObjectWithData:data
- options:0
- error:nil]
- valueForKey:
- DropboxErrorUserInfo]]
- presenter:presenter];
- }];
- }
- }];
+ if (error != nil) {
+ [[NSOperationQueue mainQueue] addOperationWithBlock:^{
+
+ [SharedDeclerations
+ presentErrorAlert:error
+ presenter:presenter.navigationController
+ .topViewController];
+
+ }];
+ }
+ if ([[NSJSONSerialization JSONObjectWithData:data options:0 error:nil]
+ valueForKey:@"error_summary"] != nil) {
+ [[NSOperationQueue mainQueue] addOperationWithBlock:^{
+ if ([[NSJSONSerialization JSONObjectWithData:data
+ options:0
+ error:nil]
+ isKindOfClass:[NSDictionary class]]) {
+ [SharedDeclerations
+ presentErrorAlert:
+ [NSError errorWithDomain:DropboxErrorDomain
+ code:100
+ userInfo:@{
+ [[NSJSONSerialization
+ JSONObjectWithData:data
+ options:0
+ error:nil]
+ valueForKey:
+ DropboxErrorUserInfo] :
+ NSLocalizedDescriptionKey
+ }]
+ presenter:presenter.navigationController
+ .topViewController];
+ }
+ else {
+ [SharedDeclerations
+ presentErrorAlert:
+ [NSError
+ errorWithDomain:DropboxErrorDomain
+ code:100
+ userInfo:@{
+ [[NSString alloc]
+ initWithData:data
+ encoding:
+ NSASCIIStringEncoding] :
+ NSLocalizedDescriptionKey
+ }]
+ presenter:presenter.navigationController
+ .topViewController];
+ }
+ }];
+ }
}
handler();
}
@@ -399,12 +502,14 @@
}
}
if (!exports) {
- [self createFolderAtPath:@"EXPORTS"
- presenter:presenter];
+ [self
+ createFolderAtPath:@"EXPORTS"
+ presenter:presenter.navigationController
+ .topViewController];
}
}
presenter:presenter];
- // NavData (Two files from PMDG Navigraph data
+ // NavData (3 files from QW Navigraph data
[self contentsOfPath:nil
completion:^(NSArray *data) {
BOOL exports = false;
@@ -416,29 +521,33 @@
}
}
if (!exports) {
- [self createFolderAtPath:@"NAVDATA"
- presenter:presenter];
+ [self
+ createFolderAtPath:@"NAVDATA"
+ presenter:presenter.navigationController
+ .topViewController];
}
}
- presenter:presenter];
+ presenter:presenter.navigationController.topViewController];
// Backups of Saves
- [self
- contentsOfPath:nil
- completion:^(NSArray *data) {
- BOOL exports = false;
- for (NSDictionary *dict in data) {
- if ([[dict valueForKey:@"name"]
- isEqualToString:@"SAVES"]) {
- exports = true;
- break;
- }
- }
- if (!exports) {
- [self createFolderAtPath:@"SAVES" presenter:presenter];
- }
- }
- presenter:presenter];
- // Old saves (FMC Planner + (or X))
+ [self contentsOfPath:nil
+ completion:^(NSArray *data) {
+ BOOL exports = false;
+ for (NSDictionary *dict in data) {
+ if ([[dict valueForKey:@"name"]
+ isEqualToString:@"SAVES"]) {
+ exports = true;
+ break;
+ }
+ }
+ if (!exports) {
+ [self
+ createFolderAtPath:@"SAVES"
+ presenter:presenter.navigationController
+ .topViewController];
+ }
+ }
+ presenter:presenter.navigationController.topViewController];
+ // Old saves (FMC Planner + (or X?))
[self contentsOfPath:nil
completion:^(NSArray *data) {
BOOL exports = false;
@@ -450,11 +559,13 @@
}
}
if (!exports) {
- [self createFolderAtPath:@"OLDSAVES"
- presenter:presenter];
+ [self
+ createFolderAtPath:@"OLDSAVES"
+ presenter:presenter.navigationController
+ .topViewController];
}
}
- presenter:presenter];
+ presenter:presenter.navigationController.topViewController];
}];
handler();
}
@@ -524,22 +635,28 @@
[NSError
errorWithDomain:DropboxErrorDomain
code:100
- userInfo:
+ userInfo:@{
[[NSJSONSerialization
JSONObjectWithData:data
options:0
error:nil]
valueForKey:
- DropboxErrorUserInfo]]
- presenter:presenter];
+ DropboxErrorUserInfo] :
+ NSLocalizedDescriptionKey
+ }]
+ presenter:presenter
+ .navigationController
+ .topViewController];
}];
}
}
else if (error != nil) {
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
- [SharedDeclerations presentErrorAlert:error
- presenter:presenter];
+ [SharedDeclerations
+ presentErrorAlert:error
+ presenter:presenter.navigationController
+ .topViewController];
}];
}
diff --git a/FMC Planner 2/SharedDeclerations.m b/FMC Planner 2/SharedDeclerations.m
index 74e8163..c48158b 100644
--- a/FMC Planner 2/SharedDeclerations.m
+++ b/FMC Planner 2/SharedDeclerations.m
@@ -70,7 +70,7 @@ NSString *const DropboxErrorUserInfo = @"error_summary";
stringByAppendingString:[NSString stringWithFormat:@"/%@", file]];
}
-#pragma mark - Alert for handling displaying Eroor Messages.
+#pragma mark - Alert for handling displaying Error Messages.
+ (void)presentErrorAlert:(NSError *)error
presenter:(UIViewController *)presenter
diff --git a/FMC Planner 2/TableViewController.m b/FMC Planner 2/TableViewController.m
index a57a0b5..f72d440 100644
--- a/FMC Planner 2/TableViewController.m
+++ b/FMC Planner 2/TableViewController.m
@@ -32,7 +32,8 @@ DropboxV2ObjC *dbClient = nil;
if ([self.title isEqualToString:@"Manage"] ||
[self.title isEqualToString:@"Upload"]) {
NSArray *temp = [[NSFileManager defaultManager]
- contentsOfDirectoryAtPath:[SharedDeclerations savePathForFile:@""]
+ contentsOfDirectoryAtPath:[SharedDeclerations
+ savePathForFile:@"SAVES"]
error:nil];
_dataSource = [[temp
@@ -85,9 +86,11 @@ DropboxV2ObjC *dbClient = nil;
if ([self.title isEqualToString:@"Manage"] ||
[self.title isEqualToString:@"Upload"]) {
NSDictionary *data = [[NSDictionary alloc]
- initWithContentsOfFile:[SharedDeclerations
- savePathForFile:_dataSource[indexPath
- .row]]];
+ initWithContentsOfFile:
+ [SharedDeclerations
+ savePathForFile:[@"SAVES/"
+ stringByAppendingString:
+ _dataSource[indexPath.row]]]];
cell.textLabel.text = [data valueForKey:@"MENU@LSKR1"];
}
if ([self.title isEqualToString:@"Download"]) {
@@ -171,26 +174,43 @@ DropboxV2ObjC *dbClient = nil;
- (void)finishSelection
{
+ NSOperationQueue *queue = [[NSOperationQueue alloc] init];
if ([self.title isEqualToString:@"Download"]) {
_sm.dbDownload.enabled = NO;
_sm.dbDownload.alpha = 0.5;
- [dbClient downloadFromDropbox:_markList
- presenter:self
- completion:^{
- _sm.dbDownload.enabled = YES;
- _sm.dbDownload.alpha = 1.0;
- }];
+ _main.downloadActive = true;
+ [queue addOperationWithBlock:^{
+ [dbClient downloadFromDropbox:_markList
+ presenter:self
+ completion:^{
+ [[NSOperationQueue mainQueue]
+ addOperationWithBlock:^{
+ _sm.dbDownload.enabled = YES;
+ _sm.dbDownload.alpha = 1.0;
+ _main.downloadActive = false;
+ [self.view setNeedsDisplay];
+ }];
+ }];
+ }];
[self.navigationController popViewControllerAnimated:YES];
}
if ([self.title isEqualToString:@"Upload"]) {
_sm.dbUpload.enabled = NO;
_sm.dbUpload.alpha = 0.5;
- [dbClient uploadToDropbox:_markList
- presenter:self
- completion:^{
- _sm.dbUpload.enabled = YES;
- _sm.dbUpload.alpha = 1.0;
- }];
+ _main.uploadActive = true;
+ [queue addOperationWithBlock:^{
+ [dbClient
+ uploadToDropbox:_markList
+ presenter:self
+ completion:^{
+ [[NSOperationQueue mainQueue] addOperationWithBlock:^{
+ _sm.dbUpload.enabled = YES;
+ _sm.dbUpload.alpha = 1.0;
+ _main.uploadActive = false;
+ [self.view setNeedsDisplay];
+ }];
+ }];
+ }];
[self.navigationController popViewControllerAnimated:YES];
}
}
diff --git a/FMC Planner 2/ViewController.h b/FMC Planner 2/ViewController.h
index 89bfcf2..be0f8e1 100644
--- a/FMC Planner 2/ViewController.h
+++ b/FMC Planner 2/ViewController.h
@@ -30,6 +30,13 @@
@property (strong, nonatomic) IBOutlet UIView *backdropKeys;
@property (strong, nonatomic) IBOutlet UIView *backdropScreen;
+#pragma mark - Network indictaors
+@property (nonatomic) BOOL downloadActive;
+@property (nonatomic) BOOL uploadActive;
+@property (nonatomic) BOOL oldSavesActive;
+@property (nonatomic) BOOL exportActive;
+@property (nonatomic) BOOL navDataActive;
+
#pragma mark - Save and loading methods
- (void)loadSave:(NSString *)file;
diff --git a/FMC Planner 2/ViewControllerServiceMenu.h b/FMC Planner 2/ViewControllerServiceMenu.h
index 403c431..3d3b861 100644
--- a/FMC Planner 2/ViewControllerServiceMenu.h
+++ b/FMC Planner 2/ViewControllerServiceMenu.h
@@ -13,7 +13,7 @@
#import "ViewController.h"
#import
-@interface ViewControllerServiceMenu : UIViewController
+@interface ViewControllerServiceMenu : UIViewController
#pragma mark - Refrence to other views in app
@@ -24,10 +24,12 @@
@property (strong, nonatomic) IBOutlet UIButton *dbConnectButton;
@property (strong, nonatomic) IBOutlet UIButton *dbDownload;
@property (strong, nonatomic) IBOutlet UIButton *dbUpload;
+@property (strong, nonatomic) IBOutlet UIButton *dbNavData;
#pragma mark - Dropbox authentictaion methods
- (IBAction)dbConnect:(UIButton *)sender;
- (IBAction)dbDisconnect:(UIButton *)sender;
+- (IBAction)dbGetNavData:(UIButton *)sender;
@end
diff --git a/FMC Planner 2/ViewControllerServiceMenu.m b/FMC Planner 2/ViewControllerServiceMenu.m
index 3e13fbf..790e8a1 100644
--- a/FMC Planner 2/ViewControllerServiceMenu.m
+++ b/FMC Planner 2/ViewControllerServiceMenu.m
@@ -37,6 +37,26 @@
action:@selector(dbDisconnect:)
forControlEvents:UIControlEventTouchUpInside];
}
+
+ _dbDownload.enabled = YES;
+ _dbDownload.alpha = 1.0;
+ _dbUpload.enabled = YES;
+ _dbUpload.alpha = 1.0;
+ _dbNavData.enabled = YES;
+ _dbNavData.alpha = 1.0;
+
+ if (_main.downloadActive) {
+ _dbDownload.enabled = NO;
+ _dbDownload.alpha = 0.5;
+ }
+ if (_main.uploadActive) {
+ _dbUpload.enabled = NO;
+ _dbUpload.alpha = 0.5;
+ }
+ if (_main.navDataActive) {
+ _dbNavData.enabled = NO;
+ _dbNavData.alpha = 0.5;
+ }
}
- (void)back
@@ -90,4 +110,106 @@
forControlEvents:UIControlEventTouchUpInside];
}
+- (IBAction)dbGetNavData:(UIButton *)sender
+{
+ [self alertViewiOS7];
+}
+
+- (void)dbGetNavDataHelper
+{
+ NSOperationQueue *queue = [[NSOperationQueue alloc] init];
+ _dbNavData.enabled = NO;
+ _dbNavData.alpha = 0.5;
+ _main.navDataActive = true;
+ [queue addOperationWithBlock:^{
+ DropboxV2ObjC *dbClient =
+ ((AppDelegate *)[UIApplication sharedApplication].delegate)
+ .dbClient;
+ [dbClient
+ contentsOfPath:@"NAVDATA"
+ completion:^(NSArray *files) {
+ if (files != nil) {
+ NSMutableArray *dlList = [[NSMutableArray alloc] init];
+ for (NSDictionary *file in files) {
+ [dlList
+ addObject:[[file valueForKey:@"path_display"]
+ substringFromIndex:1]];
+ }
+ [dbClient
+ downloadFromDropbox:dlList
+ presenter:self
+ completion:^{
+ [[NSOperationQueue mainQueue]
+ addOperationWithBlock:^{
+ _main.navDataActive = false;
+ _dbNavData.enabled = YES;
+ _dbNavData.alpha = 1.0;
+ [self.view setNeedsDisplay];
+ }];
+ }];
+ }
+ else {
+ [[NSOperationQueue mainQueue] addOperationWithBlock:^{
+ _main.navDataActive = false;
+ _dbNavData.enabled = YES;
+ _dbNavData.alpha = 1.0;
+ [self.view setNeedsDisplay];
+ }];
+ }
+
+ }
+ presenter:self];
+ }];
+}
+
+#pragma mark - Delegate for UIAlertView and UIAlertController outsource
+
+- (void)alertView:(UIAlertView *)alertView
+ clickedButtonAtIndex:(NSInteger)buttonIndex
+{
+ if (buttonIndex == 1) {
+ [self dbGetNavDataHelper];
+ }
+}
+
+- (void)alertViewiOS7
+{
+ if ([UIAlertController class]) {
+ UIAlertController *alert = [UIAlertController
+ alertControllerWithTitle:@"NavData"
+ message:@"This app requires the QualityWings "
+ @"NavData "
+ @"files. Please ensure that you have the "
+ @"awys.txt, ints.txt and navs.txt inside "
+ @"the "
+ @"NAVDATA folder in your Dropbox."
+ preferredStyle:UIAlertControllerStyleActionSheet];
+ UIAlertAction *defaultAction =
+ [UIAlertAction actionWithTitle:@"Cancel"
+ style:UIAlertActionStyleCancel
+ handler:nil];
+ UIAlertAction *loadAction =
+ [UIAlertAction actionWithTitle:@"Ok"
+ style:UIAlertActionStyleDefault
+ handler:^(UIAlertAction *action) {
+ [self dbGetNavDataHelper];
+ }];
+ [alert addAction:defaultAction];
+ [alert addAction:loadAction];
+ [self presentViewController:alert animated:YES completion:nil];
+ }
+ else {
+ UIAlertView *alert = [[UIAlertView alloc]
+ initWithTitle:@"NavData"
+ message:@"This app requires the QualityWings NavData "
+ @"files. Please ensure that you have the "
+ @"awys.txt, ints.txt and navs.txt inside the "
+ @"NAVDATA folder in your Dropbox."
+ delegate:self
+ cancelButtonTitle:@"Cancel"
+ otherButtonTitles:@"Ok", nil];
+ [alert show];
+ }
+}
+
@end