From 37b2619277e9f4b57a2de39bab9ca61905e3951b Mon Sep 17 00:00:00 2001 From: Kilian Hofmann Date: Thu, 31 Mar 2016 19:30:10 +0200 Subject: [PATCH] dropbox integrated with table view --- .../xcdebugger/Breakpoints_v2.xcbkptlist | 5 + FMC Planner 2.xcodeproj/project.pbxproj | 28 +-- .../xcdebugger/Breakpoints_v2.xcbkptlist | 18 -- FMC Planner 2/Base.lproj/Main.storyboard | 2 +- FMC Planner 2/TableViewController.h | 4 +- FMC Planner 2/TableViewController.m | 165 +++++++++++++----- FMC Planner 2/ViewControllerServiceMenu.m | 2 +- 7 files changed, 150 insertions(+), 74 deletions(-) create mode 100644 FMC PLanner 2.xcworkspace/xcuserdata/Kili2.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist diff --git a/FMC PLanner 2.xcworkspace/xcuserdata/Kili2.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/FMC PLanner 2.xcworkspace/xcuserdata/Kili2.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist new file mode 100644 index 0000000..ed9a9b4 --- /dev/null +++ b/FMC PLanner 2.xcworkspace/xcuserdata/Kili2.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -0,0 +1,5 @@ + + + diff --git a/FMC Planner 2.xcodeproj/project.pbxproj b/FMC Planner 2.xcodeproj/project.pbxproj index 848e7bc..6c1a74c 100644 --- a/FMC Planner 2.xcodeproj/project.pbxproj +++ b/FMC Planner 2.xcodeproj/project.pbxproj @@ -7,10 +7,12 @@ objects = { /* Begin PBXBuildFile section */ - 538D4E6DD1FC94B931B43D52 /* libPods-FMC Planner 2UITests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 168D3CE5E84BDA0F157A7CF7 /* libPods-FMC Planner 2UITests.a */; }; - 7724A561D957642263D75813 /* libPods-FMC Planner 2.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 02FB9097A522461BE8F904D4 /* libPods-FMC Planner 2.a */; }; E227C7831C9F42AB00DE0CA4 /* ViewControllerKeyboard.m in Sources */ = {isa = PBXBuildFile; fileRef = E227C7821C9F42AB00DE0CA4 /* ViewControllerKeyboard.m */; }; E227C7861C9F474100DE0CA4 /* ViewControllerScreen.m in Sources */ = {isa = PBXBuildFile; fileRef = E227C7851C9F474100DE0CA4 /* ViewControllerScreen.m */; }; + E22E0B561CAD655D00B71EE5 /* libPods-FMC Planner 2.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E22E0B551CAD655D00B71EE5 /* libPods-FMC Planner 2.a */; }; + E22E0B581CAD656700B71EE5 /* libPods-FMC Planner 2UITests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E22E0B571CAD656700B71EE5 /* libPods-FMC Planner 2UITests.a */; }; + E22E0B591CAD656B00B71EE5 /* libPods-FMC Planner 2Tests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E22E0B531CAD655200B71EE5 /* libPods-FMC Planner 2Tests.a */; }; + E22E0B5B1CAD657000B71EE5 /* libSWTableViewCell.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E22E0B5A1CAD657000B71EE5 /* libSWTableViewCell.a */; }; E22EE9D11C9DB7B3001F5BC0 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = E22EE9D01C9DB7B3001F5BC0 /* main.m */; }; E22EE9D41C9DB7B3001F5BC0 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = E22EE9D31C9DB7B3001F5BC0 /* AppDelegate.m */; }; E22EE9D71C9DB7B3001F5BC0 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E22EE9D61C9DB7B3001F5BC0 /* ViewController.m */; }; @@ -29,7 +31,6 @@ E2A927161CA30CEE00606E07 /* SharedDeclerations.m in Sources */ = {isa = PBXBuildFile; fileRef = E2A927151CA30CEE00606E07 /* SharedDeclerations.m */; }; E2B694BC1CAC0C56007B28EF /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E2B694BB1CAC0C56007B28EF /* Security.framework */; }; E2CC73E31CA2B7C7005B786E /* PERF INIT.plist in Resources */ = {isa = PBXBuildFile; fileRef = E2CC73E21CA2B7C7005B786E /* PERF INIT.plist */; }; - FBF6796DA6BFEFE056737798 /* libPods-FMC Planner 2Tests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = EAA5BF6A3B18A12DDBE49807 /* libPods-FMC Planner 2Tests.a */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -50,8 +51,6 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ - 02FB9097A522461BE8F904D4 /* libPods-FMC Planner 2.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-FMC Planner 2.a"; sourceTree = BUILT_PRODUCTS_DIR; }; - 168D3CE5E84BDA0F157A7CF7 /* libPods-FMC Planner 2UITests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-FMC Planner 2UITests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 3A4DEEC164570A675464527C /* Pods-FMC Planner 2UITests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FMC Planner 2UITests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-FMC Planner 2UITests/Pods-FMC Planner 2UITests.debug.xcconfig"; sourceTree = ""; }; 49ECBB2A9C708150C7EF0B6D /* Pods-FMC Planner 2.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FMC Planner 2.release.xcconfig"; path = "Pods/Target Support Files/Pods-FMC Planner 2/Pods-FMC Planner 2.release.xcconfig"; sourceTree = ""; }; 64A5F6E611B5803249E6DC1F /* Pods-FMC Planner 2Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FMC Planner 2Tests.release.xcconfig"; path = "Pods/Target Support Files/Pods-FMC Planner 2Tests/Pods-FMC Planner 2Tests.release.xcconfig"; sourceTree = ""; }; @@ -62,6 +61,10 @@ E227C7821C9F42AB00DE0CA4 /* ViewControllerKeyboard.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ViewControllerKeyboard.m; sourceTree = ""; }; E227C7841C9F474100DE0CA4 /* ViewControllerScreen.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ViewControllerScreen.h; sourceTree = ""; }; E227C7851C9F474100DE0CA4 /* ViewControllerScreen.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ViewControllerScreen.m; sourceTree = ""; }; + E22E0B531CAD655200B71EE5 /* libPods-FMC Planner 2Tests.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = "libPods-FMC Planner 2Tests.a"; path = "../../../Library/Developer/Xcode/DerivedData/FMC_PLanner_2-fsspigtxwcyaejgcrewjeasvcrcv/Build/Products/Debug-iphonesimulator/libPods-FMC Planner 2Tests.a"; sourceTree = ""; }; + E22E0B551CAD655D00B71EE5 /* libPods-FMC Planner 2.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = "libPods-FMC Planner 2.a"; path = "../../../Library/Developer/Xcode/DerivedData/FMC_PLanner_2-fsspigtxwcyaejgcrewjeasvcrcv/Build/Products/Debug-iphonesimulator/libPods-FMC Planner 2.a"; sourceTree = ""; }; + E22E0B571CAD656700B71EE5 /* libPods-FMC Planner 2UITests.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = "libPods-FMC Planner 2UITests.a"; path = "../../../Library/Developer/Xcode/DerivedData/FMC_PLanner_2-fsspigtxwcyaejgcrewjeasvcrcv/Build/Products/Debug-iphonesimulator/libPods-FMC Planner 2UITests.a"; sourceTree = ""; }; + E22E0B5A1CAD657000B71EE5 /* libSWTableViewCell.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libSWTableViewCell.a; path = "../../../Library/Developer/Xcode/DerivedData/FMC_PLanner_2-fsspigtxwcyaejgcrewjeasvcrcv/Build/Products/Debug-iphonesimulator/SWTableViewCell/libSWTableViewCell.a"; sourceTree = ""; }; E22EE9CC1C9DB7B3001F5BC0 /* FMC Planner 2.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "FMC Planner 2.app"; sourceTree = BUILT_PRODUCTS_DIR; }; E22EE9D01C9DB7B3001F5BC0 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; E22EE9D21C9DB7B3001F5BC0 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; @@ -92,7 +95,6 @@ E2A927151CA30CEE00606E07 /* SharedDeclerations.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SharedDeclerations.m; sourceTree = ""; }; E2B694BB1CAC0C56007B28EF /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = System/Library/Frameworks/Security.framework; sourceTree = SDKROOT; }; E2CC73E21CA2B7C7005B786E /* PERF INIT.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "PERF INIT.plist"; sourceTree = ""; }; - EAA5BF6A3B18A12DDBE49807 /* libPods-FMC Planner 2Tests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-FMC Planner 2Tests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -100,9 +102,12 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + E22E0B5B1CAD657000B71EE5 /* libSWTableViewCell.a in Frameworks */, + E22E0B591CAD656B00B71EE5 /* libPods-FMC Planner 2Tests.a in Frameworks */, + E22E0B581CAD656700B71EE5 /* libPods-FMC Planner 2UITests.a in Frameworks */, + E22E0B561CAD655D00B71EE5 /* libPods-FMC Planner 2.a in Frameworks */, E2B694BC1CAC0C56007B28EF /* Security.framework in Frameworks */, E28E106D1C9FF93D006E2C6B /* QuartzCore.framework in Frameworks */, - 7724A561D957642263D75813 /* libPods-FMC Planner 2.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -110,7 +115,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - FBF6796DA6BFEFE056737798 /* libPods-FMC Planner 2Tests.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -118,7 +122,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 538D4E6DD1FC94B931B43D52 /* libPods-FMC Planner 2UITests.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -141,9 +144,10 @@ C605C480B46761595F28A6B2 /* Frameworks */ = { isa = PBXGroup; children = ( - 02FB9097A522461BE8F904D4 /* libPods-FMC Planner 2.a */, - EAA5BF6A3B18A12DDBE49807 /* libPods-FMC Planner 2Tests.a */, - 168D3CE5E84BDA0F157A7CF7 /* libPods-FMC Planner 2UITests.a */, + E22E0B5A1CAD657000B71EE5 /* libSWTableViewCell.a */, + E22E0B571CAD656700B71EE5 /* libPods-FMC Planner 2UITests.a */, + E22E0B551CAD655D00B71EE5 /* libPods-FMC Planner 2.a */, + E22E0B531CAD655200B71EE5 /* libPods-FMC Planner 2Tests.a */, ); name = Frameworks; sourceTree = ""; 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 76a0517..fe2b454 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,22 +2,4 @@ - - - - - - diff --git a/FMC Planner 2/Base.lproj/Main.storyboard b/FMC Planner 2/Base.lproj/Main.storyboard index a7bfb72..a385920 100644 --- a/FMC Planner 2/Base.lproj/Main.storyboard +++ b/FMC Planner 2/Base.lproj/Main.storyboard @@ -171,7 +171,7 @@ - + diff --git a/FMC Planner 2/TableViewController.h b/FMC Planner 2/TableViewController.h index 019efce..59470f7 100644 --- a/FMC Planner 2/TableViewController.h +++ b/FMC Planner 2/TableViewController.h @@ -9,10 +9,11 @@ #import "AppDelegate.h" #import "SharedDeclerations.h" #import "ViewController.h" +#import #import @class ViewController; -@interface TableViewController : UITableViewController +@interface TableViewController : UITableViewController #pragma mark - Refrence to other views in app @@ -21,5 +22,6 @@ #pragma mark - Table view data source @property (strong, nonatomic) NSMutableArray *dataSource; +@property (strong, nonatomic) NSMutableArray *markList; @end diff --git a/FMC Planner 2/TableViewController.m b/FMC Planner 2/TableViewController.m index c0bffb3..9c3cb85 100644 --- a/FMC Planner 2/TableViewController.m +++ b/FMC Planner 2/TableViewController.m @@ -10,6 +10,8 @@ @implementation TableViewController +DropboxV2ObjC *dbClient = nil; + #pragma mark - View management and navigation - (void)viewDidLoad @@ -22,7 +24,13 @@ // Uncomment the following line to display an Edit button in the navigation // bar for this view controller. // self.navigationItem.rightBarButtonItem = self.editButtonItem; - if ([self.title isEqualToString:@"Manage"]) { + self.tableView.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0); + _markList = [[NSMutableArray alloc] init]; + dbClient = + ((AppDelegate *)[UIApplication sharedApplication].delegate).dbClient; + + if ([self.title isEqualToString:@"Manage"] || + [self.title isEqualToString:@"Upload"]) { NSArray *temp = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:[SharedDeclerations savePathForFile:@""] error:nil]; @@ -33,9 +41,6 @@ @"."]] mutableCopy]; } if ([self.title isEqualToString:@"Download"]) { - DropboxV2ObjC *dbClient = - ((AppDelegate *)[UIApplication sharedApplication].delegate) - .dbClient; [dbClient contentsOfPath:nil completion:^(NSArray *data) { @@ -71,11 +76,11 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { - UITableViewCell *cell = - [tableView dequeueReusableCellWithIdentifier:@"Cell" - forIndexPath:indexPath]; + SWTableViewCell *cell = (SWTableViewCell *)[tableView + dequeueReusableCellWithIdentifier:@"Cell"]; - if ([self.title isEqualToString:@"Manage"]) { + if ([self.title isEqualToString:@"Manage"] || + [self.title isEqualToString:@"Upload"]) { NSDictionary *data = [[NSDictionary alloc] initWithContentsOfFile:[SharedDeclerations savePathForFile:_dataSource[indexPath @@ -85,42 +90,14 @@ if ([self.title isEqualToString:@"Download"]) { cell.textLabel.text = _dataSource[indexPath.row]; } - return cell; -} - -#pragma mark - Table view editing action - -- (UITableViewCellEditingStyle)tableView:(UITableView *)aTableView - editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath -{ - // Detemine if it's in editing mode if ([self.title isEqualToString:@"Manage"]) { - return UITableViewCellEditingStyleDelete; + cell.rightUtilityButtons = [self rightButtons]; } - - return UITableViewCellEditingStyleNone; -} - -// Override to support editing the table view. -- (void)tableView:(UITableView *)tableView - commitEditingStyle:(UITableViewCellEditingStyle)editingStyle - forRowAtIndexPath:(NSIndexPath *)indexPath -{ - if (editingStyle == UITableViewCellEditingStyleDelete) { - // Delete the row from the data source - [[NSFileManager defaultManager] - removeItemAtPath:[SharedDeclerations - savePathForFile:_dataSource[indexPath.row]] - error:nil]; - [_dataSource removeObjectAtIndex:indexPath.row]; - [tableView deleteRowsAtIndexPaths:@[ indexPath ] - withRowAnimation:UITableViewRowAnimationFade]; - } - 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 + else { + cell.leftUtilityButtons = [self leftButtonsNormal]; } + cell.delegate = self; + return cell; } #pragma mark - Table view cell selection action @@ -137,6 +114,112 @@ .textLabel.text]; }]; } + else { + [tableView deselectRowAtIndexPath:indexPath animated:YES]; + } +} + +#pragma mark - Helper methods + +/** + * AKA Delete button + */ +- (NSArray *)rightButtons +{ + NSMutableArray *array = [[NSMutableArray alloc] init]; + + [array sw_addUtilityButtonWithColor:[UIColor colorWithRed:1.0f + green:0.231f + blue:0.188 + alpha:1.0f] + title:@"Delete"]; + return array; +} + +/** + * AKA Mark button white + */ +- (NSArray *)leftButtonsNormal +{ + NSMutableArray *array = [[NSMutableArray alloc] init]; + + [array sw_addUtilityButtonWithColor:[UIColor colorWithRed:0.78f + green:0.78f + blue:0.8f + alpha:1.0] + title:@"Mark"]; + return array; +} + +/** + * AKA Mark button green + */ +- (NSArray *)leftButtonsSelected +{ + NSMutableArray *array = [[NSMutableArray alloc] init]; + + [array sw_addUtilityButtonWithColor:[UIColor colorWithRed:0.07 + green:0.75f + blue:0.16f + alpha:1.0] + title:@"Unmark"]; + return array; +} + +- (void)finishSelection +{ + if ([self.title isEqualToString:@"Download"]) { + [dbClient downloadFromDropbox:_markList]; + [self.navigationController popViewControllerAnimated:YES]; + } + if ([self.title isEqualToString:@"Upload"]) { + [dbClient uploadToDropbox:_markList]; + [self.navigationController popViewControllerAnimated:YES]; + } +} + +#pragma mark - SWTableViewDelegate + +- (void)swipeableTableViewCell:(SWTableViewCell *)cell + didTriggerLeftUtilityButtonWithIndex:(NSInteger)index +{ + if ([((UIButton *)cell.leftUtilityButtons[index]) + .titleLabel.text isEqualToString:@"Mark"]) { + [_markList addObject:cell.textLabel.text]; + cell.leftUtilityButtons = [self leftButtonsSelected]; + cell.accessoryType = UITableViewCellAccessoryCheckmark; + [cell hideUtilityButtonsAnimated:YES]; + } + else if ([((UIButton *)cell.leftUtilityButtons[index]) + .titleLabel.text isEqualToString:@"Unmark"]) { + [_markList removeObject:cell.textLabel.text]; + cell.leftUtilityButtons = [self leftButtonsNormal]; + cell.accessoryType = UITableViewCellAccessoryNone; + [cell hideUtilityButtonsAnimated:YES]; + } + if (_markList.count > 0 && self.navigationItem.rightBarButtonItem == nil) { + self.navigationItem.rightBarButtonItem = + [[UIBarButtonItem alloc] initWithTitle:@"Ok" + style:UIBarButtonItemStyleDone + target:self + action:@selector(finishSelection)]; + } + else if (_markList.count == 0) { + self.navigationItem.rightBarButtonItem = nil; + } +} + +- (void)swipeableTableViewCell:(SWTableViewCell *)cell + didTriggerRightUtilityButtonWithIndex:(NSInteger)index +{ + NSIndexPath *indexPath = [self.tableView indexPathForCell:cell]; + [[NSFileManager defaultManager] + removeItemAtPath:[SharedDeclerations + savePathForFile:_dataSource[indexPath.row]] + error:nil]; + [_dataSource removeObjectAtIndex:indexPath.row]; + [self.tableView deleteRowsAtIndexPaths:@[ indexPath ] + withRowAnimation:UITableViewRowAnimationFade]; } @end diff --git a/FMC Planner 2/ViewControllerServiceMenu.m b/FMC Planner 2/ViewControllerServiceMenu.m index 71fc219..807c7b1 100644 --- a/FMC Planner 2/ViewControllerServiceMenu.m +++ b/FMC Planner 2/ViewControllerServiceMenu.m @@ -53,7 +53,7 @@ #pragma mark - Dropbox Button -// Standard action (hence set), dnamically set and unset +// Standard action (hence set), dynamically set and unset - (IBAction)dbConnect:(UIButton *)sender { UIViewController *webController = [[UIViewController alloc] init];