Dropbox restructured, cleanup
This commit is contained in:
parent
a7796afbc8
commit
262be5a429
@ -2,22 +2,4 @@
|
|||||||
<Bucket
|
<Bucket
|
||||||
type = "0"
|
type = "0"
|
||||||
version = "2.0">
|
version = "2.0">
|
||||||
<Breakpoints>
|
|
||||||
<BreakpointProxy
|
|
||||||
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
|
|
||||||
<BreakpointContent
|
|
||||||
shouldBeEnabled = "No"
|
|
||||||
ignoreCount = "0"
|
|
||||||
continueAfterRunningActions = "No"
|
|
||||||
filePath = "FMC Planner 2/DropboxV2ObjC.m"
|
|
||||||
timestampString = "481396548.273272"
|
|
||||||
startingColumnNumber = "9223372036854775807"
|
|
||||||
endingColumnNumber = "9223372036854775807"
|
|
||||||
startingLineNumber = "78"
|
|
||||||
endingLineNumber = "78"
|
|
||||||
landmarkName = "-deauthorizeUserWithPresenter:"
|
|
||||||
landmarkType = "5">
|
|
||||||
</BreakpointContent>
|
|
||||||
</BreakpointProxy>
|
|
||||||
</Breakpoints>
|
|
||||||
</Bucket>
|
</Bucket>
|
||||||
|
|||||||
@ -144,6 +144,8 @@
|
|||||||
C605C480B46761595F28A6B2 /* Frameworks */ = {
|
C605C480B46761595F28A6B2 /* Frameworks */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
|
E2B694BB1CAC0C56007B28EF /* Security.framework */,
|
||||||
|
E28E106C1C9FF93D006E2C6B /* QuartzCore.framework */,
|
||||||
E22E0B5A1CAD657000B71EE5 /* libSWTableViewCell.a */,
|
E22E0B5A1CAD657000B71EE5 /* libSWTableViewCell.a */,
|
||||||
E22E0B571CAD656700B71EE5 /* libPods-FMC Planner 2UITests.a */,
|
E22E0B571CAD656700B71EE5 /* libPods-FMC Planner 2UITests.a */,
|
||||||
E22E0B551CAD655D00B71EE5 /* libPods-FMC Planner 2.a */,
|
E22E0B551CAD655D00B71EE5 /* libPods-FMC Planner 2.a */,
|
||||||
@ -155,8 +157,6 @@
|
|||||||
E22EE9C31C9DB7B3001F5BC0 = {
|
E22EE9C31C9DB7B3001F5BC0 = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
E2B694BB1CAC0C56007B28EF /* Security.framework */,
|
|
||||||
E28E106C1C9FF93D006E2C6B /* QuartzCore.framework */,
|
|
||||||
E22EE9CE1C9DB7B3001F5BC0 /* FMC Planner 2 */,
|
E22EE9CE1C9DB7B3001F5BC0 /* FMC Planner 2 */,
|
||||||
E22EE9E81C9DB7B4001F5BC0 /* FMC Planner 2Tests */,
|
E22EE9E81C9DB7B4001F5BC0 /* FMC Planner 2Tests */,
|
||||||
E22EE9F31C9DB7B4001F5BC0 /* FMC Planner 2UITests */,
|
E22EE9F31C9DB7B4001F5BC0 /* FMC Planner 2UITests */,
|
||||||
|
|||||||
@ -22,4 +22,8 @@
|
|||||||
|
|
||||||
@property (strong, nonatomic) UIViewController *smWebView;
|
@property (strong, nonatomic) UIViewController *smWebView;
|
||||||
|
|
||||||
|
#pragma mark - Refrence to main view for Alerts and shit.
|
||||||
|
|
||||||
|
@property (strong, nonatomic) UIViewController *smMenu;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@ -22,6 +22,10 @@
|
|||||||
credentialsForProtectionSpace:_dbClient.kDropboxProtectionSpace];
|
credentialsForProtectionSpace:_dbClient.kDropboxProtectionSpace];
|
||||||
NSURLCredential *credential = [credentials.objectEnumerator nextObject];
|
NSURLCredential *credential = [credentials.objectEnumerator nextObject];
|
||||||
_dbClient.token = credential.password;
|
_dbClient.token = credential.password;
|
||||||
|
// Reset if user changed it
|
||||||
|
[_dbClient setupDropboxWithHandler:^{
|
||||||
|
}
|
||||||
|
presenter:nil];
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,8 +77,11 @@
|
|||||||
completion:^(void) {
|
completion:^(void) {
|
||||||
[_smWebView.navigationController
|
[_smWebView.navigationController
|
||||||
popViewControllerAnimated:YES];
|
popViewControllerAnimated:YES];
|
||||||
|
[_dbClient setupDropboxWithHandler:^{
|
||||||
|
}
|
||||||
|
presenter:_smMenu];
|
||||||
}
|
}
|
||||||
presenter:nil];
|
presenter:_smMenu];
|
||||||
|
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -39,9 +39,9 @@
|
|||||||
completion:(void (^)(NSArray *data))handler
|
completion:(void (^)(NSArray *data))handler
|
||||||
presenter:(UIViewController *)presenter;
|
presenter:(UIViewController *)presenter;
|
||||||
|
|
||||||
#pragma mark - Other methods
|
#pragma mark - Setup methods
|
||||||
|
|
||||||
- (NSDictionary *)getUserInfoWithPresenter:(UIViewController *)presenter;
|
|
||||||
|
|
||||||
|
- (void)setupDropboxWithHandler:(void (^)(void))handler
|
||||||
|
presenter:(UIViewController *)presenter;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
@ -137,8 +137,7 @@
|
|||||||
path = _rootDirectory;
|
path = _rootDirectory;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
path = [path
|
path = [NSString stringWithFormat:@"/%@", path];
|
||||||
stringByAppendingString:[NSString stringWithFormat:@"/%@", path]];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
|
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
|
||||||
@ -211,6 +210,9 @@
|
|||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specify if EXPORT or SAVE in file name
|
||||||
|
*/
|
||||||
- (void)downloadFromDropbox:(NSArray *)files
|
- (void)downloadFromDropbox:(NSArray *)files
|
||||||
presenter:(UIViewController *)presenter
|
presenter:(UIViewController *)presenter
|
||||||
completion:(void (^)(void))handler
|
completion:(void (^)(void))handler
|
||||||
@ -254,8 +256,14 @@
|
|||||||
options:0
|
options:0
|
||||||
error:nil]
|
error:nil]
|
||||||
valueForKey:@"error_summary"] == nil) {
|
valueForKey:@"error_summary"] == nil) {
|
||||||
[data writeToFile:[SharedDeclerations
|
[data writeToFile:
|
||||||
savePathForFile:string]
|
[SharedDeclerations
|
||||||
|
savePathForFile:
|
||||||
|
[string
|
||||||
|
substringFromIndex:
|
||||||
|
[string
|
||||||
|
rangeOfString:@"/"]
|
||||||
|
.location]]
|
||||||
atomically:YES];
|
atomically:YES];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -294,6 +302,9 @@
|
|||||||
handler();
|
handler();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specify if SAVE or OLDSAVE in file name
|
||||||
|
*/
|
||||||
- (void)uploadToDropbox:(NSArray *)files
|
- (void)uploadToDropbox:(NSArray *)files
|
||||||
presenter:(UIViewController *)presenter
|
presenter:(UIViewController *)presenter
|
||||||
completion:(void (^)(void))handler
|
completion:(void (^)(void))handler
|
||||||
@ -369,65 +380,83 @@
|
|||||||
handler();
|
handler();
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark - Other operations
|
#pragma mark - Setup methods
|
||||||
|
|
||||||
// !!!: Cannot be asynchronous
|
- (void)setupDropboxWithHandler:(void (^)(void))handler
|
||||||
- (NSDictionary *)getUserInfoWithPresenter:(UIViewController *)presenter
|
presenter:(UIViewController *)presenter
|
||||||
{
|
{
|
||||||
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
|
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
|
||||||
request.URL =
|
[queue addOperationWithBlock:^{
|
||||||
[NSURL URLWithString:
|
// Exports (PMDG format)
|
||||||
@"https://api.dropboxapi.com/2/users/get_current_account"];
|
[self contentsOfPath:nil
|
||||||
[request addValue:[NSString stringWithFormat:@"Bearer %@", _token]
|
completion:^(NSArray *data) {
|
||||||
.precomposedStringWithCanonicalMapping
|
BOOL exports = false;
|
||||||
forHTTPHeaderField:(@"Authorization")
|
for (NSDictionary *dict in data) {
|
||||||
.precomposedStringWithCanonicalMapping];
|
if ([[dict valueForKey:@"name"]
|
||||||
[request addValue:(@"application/json")
|
isEqualToString:@"EXPORTS"]) {
|
||||||
.precomposedStringWithCanonicalMapping
|
exports = true;
|
||||||
forHTTPHeaderField:(@"Content-Type")
|
break;
|
||||||
.precomposedStringWithCanonicalMapping];
|
}
|
||||||
request.HTTPMethod = @"POST";
|
}
|
||||||
request.HTTPBody = _kJSONNullObject;
|
if (!exports) {
|
||||||
|
[self createFolderAtPath:@"EXPORTS"
|
||||||
NSURLResponse *response = nil;
|
presenter:presenter];
|
||||||
NSError *error = nil;
|
}
|
||||||
NSError *error2 = nil;
|
}
|
||||||
id data = [self parseJSON:[NSURLConnection sendSynchronousRequest:request
|
presenter:presenter];
|
||||||
returningResponse:&response
|
// NavData (Two files from PMDG Navigraph data
|
||||||
error:&error2]];
|
[self contentsOfPath:nil
|
||||||
if ([data isKindOfClass:[NSDictionary class]]) {
|
completion:^(NSArray *data) {
|
||||||
if ([[NSJSONSerialization JSONObjectWithData:data options:0 error:nil]
|
BOOL exports = false;
|
||||||
valueForKey:@"error_summary"] == nil) {
|
for (NSDictionary *dict in data) {
|
||||||
return data;
|
if ([[dict valueForKey:@"name"]
|
||||||
}
|
isEqualToString:@"NAVDATA"]) {
|
||||||
else {
|
exports = true;
|
||||||
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
|
break;
|
||||||
[SharedDeclerations
|
}
|
||||||
presentErrorAlert:
|
}
|
||||||
[NSError errorWithDomain:DropboxErrorDomain
|
if (!exports) {
|
||||||
code:100
|
[self createFolderAtPath:@"NAVDATA"
|
||||||
userInfo:[[NSJSONSerialization
|
presenter:presenter];
|
||||||
JSONObjectWithData:data
|
}
|
||||||
options:0
|
}
|
||||||
error:nil]
|
presenter:presenter];
|
||||||
valueForKey:
|
// Backups of Saves
|
||||||
DropboxErrorUserInfo]]
|
[self
|
||||||
presenter:presenter];
|
contentsOfPath:nil
|
||||||
}];
|
completion:^(NSArray *data) {
|
||||||
return nil;
|
BOOL exports = false;
|
||||||
}
|
for (NSDictionary *dict in data) {
|
||||||
}
|
if ([[dict valueForKey:@"name"]
|
||||||
else if (error != nil) {
|
isEqualToString:@"SAVES"]) {
|
||||||
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
|
exports = true;
|
||||||
|
break;
|
||||||
[SharedDeclerations presentErrorAlert:error presenter:presenter];
|
}
|
||||||
|
}
|
||||||
}];
|
if (!exports) {
|
||||||
return nil;
|
[self createFolderAtPath:@"SAVES" presenter:presenter];
|
||||||
}
|
}
|
||||||
else {
|
}
|
||||||
return nil;
|
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:@"OLDSAVES"]) {
|
||||||
|
exports = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!exports) {
|
||||||
|
[self createFolderAtPath:@"OLDSAVES"
|
||||||
|
presenter:presenter];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
presenter:presenter];
|
||||||
|
}];
|
||||||
|
handler();
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark - Helper methods
|
#pragma mark - Helper methods
|
||||||
@ -446,4 +475,76 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)createFolderAtPath:(NSString *)path
|
||||||
|
presenter:(UIViewController *)presenter
|
||||||
|
{
|
||||||
|
if (path == nil) {
|
||||||
|
path = _rootDirectory;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
path = [NSString stringWithFormat:@"/%@", path];
|
||||||
|
}
|
||||||
|
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
|
||||||
|
request.URL = [NSURL
|
||||||
|
URLWithString:@"https://api.dropboxapi.com/2/files/create_folder"];
|
||||||
|
[request addValue:[NSString stringWithFormat:@"Bearer %@", _token]
|
||||||
|
.precomposedStringWithCanonicalMapping
|
||||||
|
forHTTPHeaderField:(@"Authorization")
|
||||||
|
.precomposedStringWithCanonicalMapping];
|
||||||
|
[request addValue:(@"application/json")
|
||||||
|
.precomposedStringWithCanonicalMapping
|
||||||
|
forHTTPHeaderField:(@"Content-Type")
|
||||||
|
.precomposedStringWithCanonicalMapping];
|
||||||
|
request.HTTPMethod = @"POST";
|
||||||
|
NSData *data = [NSJSONSerialization dataWithJSONObject:@{
|
||||||
|
@"path" : path.precomposedStringWithCanonicalMapping
|
||||||
|
}
|
||||||
|
options:0
|
||||||
|
error:nil];
|
||||||
|
NSString *temp =
|
||||||
|
[[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
|
||||||
|
temp = [temp stringByReplacingOccurrencesOfString:@"\\/" withString:@"/"];
|
||||||
|
request.HTTPBody = [temp dataUsingEncoding:NSASCIIStringEncoding];
|
||||||
|
|
||||||
|
[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) {
|
||||||
|
}
|
||||||
|
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:^{
|
||||||
|
|
||||||
|
[SharedDeclerations presentErrorAlert:error
|
||||||
|
presenter:presenter];
|
||||||
|
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@ -42,7 +42,7 @@ DropboxV2ObjC *dbClient = nil;
|
|||||||
}
|
}
|
||||||
if ([self.title isEqualToString:@"Download"]) {
|
if ([self.title isEqualToString:@"Download"]) {
|
||||||
[dbClient
|
[dbClient
|
||||||
contentsOfPath:nil
|
contentsOfPath:@"SAVES"
|
||||||
completion:^(NSArray *data) {
|
completion:^(NSArray *data) {
|
||||||
NSMutableArray *temp = [[NSMutableArray alloc] init];
|
NSMutableArray *temp = [[NSMutableArray alloc] init];
|
||||||
|
|
||||||
@ -200,16 +200,26 @@ DropboxV2ObjC *dbClient = nil;
|
|||||||
- (void)swipeableTableViewCell:(SWTableViewCell *)cell
|
- (void)swipeableTableViewCell:(SWTableViewCell *)cell
|
||||||
didTriggerLeftUtilityButtonWithIndex:(NSInteger)index
|
didTriggerLeftUtilityButtonWithIndex:(NSInteger)index
|
||||||
{
|
{
|
||||||
|
NSString *file = @"";
|
||||||
|
if ([self.title isEqualToString:@"Download"] ||
|
||||||
|
[self.title isEqualToString:@"Upload"]) {
|
||||||
|
file = @"SAVES/";
|
||||||
|
}
|
||||||
|
else if (false) {
|
||||||
|
// TODO: Import of old saves and export of PMDG
|
||||||
|
}
|
||||||
if ([((UIButton *)cell.leftUtilityButtons[index])
|
if ([((UIButton *)cell.leftUtilityButtons[index])
|
||||||
.titleLabel.text isEqualToString:@"Mark"]) {
|
.titleLabel.text isEqualToString:@"Mark"]) {
|
||||||
[_markList addObject:cell.textLabel.text];
|
[_markList
|
||||||
|
addObject:[file stringByAppendingString:cell.textLabel.text]];
|
||||||
cell.leftUtilityButtons = [self leftButtonsSelected];
|
cell.leftUtilityButtons = [self leftButtonsSelected];
|
||||||
cell.accessoryType = UITableViewCellAccessoryCheckmark;
|
cell.accessoryType = UITableViewCellAccessoryCheckmark;
|
||||||
[cell hideUtilityButtonsAnimated:YES];
|
[cell hideUtilityButtonsAnimated:YES];
|
||||||
}
|
}
|
||||||
else if ([((UIButton *)cell.leftUtilityButtons[index])
|
else if ([((UIButton *)cell.leftUtilityButtons[index])
|
||||||
.titleLabel.text isEqualToString:@"Unmark"]) {
|
.titleLabel.text isEqualToString:@"Unmark"]) {
|
||||||
[_markList removeObject:cell.textLabel.text];
|
[_markList
|
||||||
|
removeObject:[file stringByAppendingString:cell.textLabel.text]];
|
||||||
cell.leftUtilityButtons = [self leftButtonsNormal];
|
cell.leftUtilityButtons = [self leftButtonsNormal];
|
||||||
cell.accessoryType = UITableViewCellAccessoryNone;
|
cell.accessoryType = UITableViewCellAccessoryNone;
|
||||||
[cell hideUtilityButtonsAnimated:YES];
|
[cell hideUtilityButtonsAnimated:YES];
|
||||||
|
|||||||
@ -64,6 +64,7 @@
|
|||||||
[self.navigationController pushViewController:webController animated:YES];
|
[self.navigationController pushViewController:webController animated:YES];
|
||||||
((AppDelegate *)[UIApplication sharedApplication].delegate).smWebView =
|
((AppDelegate *)[UIApplication sharedApplication].delegate).smWebView =
|
||||||
webController;
|
webController;
|
||||||
|
((AppDelegate *)[UIApplication sharedApplication].delegate).smMenu = self;
|
||||||
[web loadRequest:
|
[web loadRequest:
|
||||||
[NSURLRequest
|
[NSURLRequest
|
||||||
requestWithURL:
|
requestWithURL:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user