dropbox integrated with table view
This commit is contained in:
@@ -171,7 +171,7 @@
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
|
||||
<prototypes>
|
||||
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="Cell" id="GLu-S8-RZg">
|
||||
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="Cell" id="GLu-S8-RZg" customClass="SWTableViewCell">
|
||||
<rect key="frame" x="0.0" y="92" width="320" height="44"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="GLu-S8-RZg" id="r83-TH-eMI">
|
||||
|
||||
@@ -9,10 +9,11 @@
|
||||
#import "AppDelegate.h"
|
||||
#import "SharedDeclerations.h"
|
||||
#import "ViewController.h"
|
||||
#import <SWTableViewCell/SWTableViewCell.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@class ViewController;
|
||||
@interface TableViewController : UITableViewController
|
||||
@interface TableViewController : UITableViewController <SWTableViewCellDelegate>
|
||||
|
||||
#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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user