-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSettingsViewController.mm
152 lines (126 loc) · 4.41 KB
/
SettingsViewController.mm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// -*- Mode: ObjC -*-
//
// Copyright (C) 2011, Brad Howes. All rights reserved.
//
#import <DropboxSDK/DropboxSDK.h>
#import "AppDelegate.h"
#import "IASKSpecifier.h"
#import "IASKSettingsReader.h"
#import "SettingsViewController.h"
@interface SettingsViewController ()
- (void)showAbout:(id)sender;
- (void)setupDropbox;
@end
@implementation SettingsViewController
@synthesize dropboxCell;
- (void)viewDidLoad
{
LOG(@"SettingsViewController.viewDidLoad");
appDelegate = static_cast<AppDelegate*>([[UIApplication sharedApplication] delegate]);
[super setDelegate: self];
[super viewDidLoad];
}
- (void)viewDidUnload
{
LOG(@"SettingsViewController.viewDidUnload");
appDelegate = nil;
[super setDelegate:nil];
[super viewDidUnload];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
self.dropboxCell = nil;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
IASKSpecifier *specifier = [self.settingsReader specifierForIndexPath:indexPath];
self.dropboxCell = nil;
if ([[specifier type] isEqualToString:kIASKCustomViewSpecifier]) {
self.dropboxCell = [tableView cellForRowAtIndexPath:indexPath];
[self setupDropbox];
}
[super tableView:tableView didSelectRowAtIndexPath:indexPath];
}
- (void)dealloc
{
self.dropboxCell = nil;
[super dealloc];
}
- (void)showAbout:(id)sender
{
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
#pragma mark -
#pragma mark Dropbox Management and Settings Display
- (void)updateDropboxCell
{
if ([[DBSession sharedSession] isLinked]) {
dropboxCell.textLabel.text = NSLocalizedString(@"Account linked",
@"Name of the Dropbox button shown in the Settings Display");
dropboxCell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else {
dropboxCell.textLabel.text = NSLocalizedString(@"Link account", @"Name of the Dropbox button shown in the Settings Display");
dropboxCell.accessoryType = UITableViewCellAccessoryNone;
}
[dropboxCell setNeedsDisplay];
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == [actionSheet destructiveButtonIndex]) {
[[DBSession sharedSession] unlinkAll];
[self updateDropboxCell];
}
}
- (void)setupDropbox
{
if (![[DBSession sharedSession] isLinked]) {
[[DBSession sharedSession] linkFromController:self];
}
else {
//
// Request to unlink Dropbox account. Show an action sheet, but don't show a cancel button per iPad UI
// guidelines.
//
NSString* cancel = [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone ? @"No" : nil;
UIActionSheet* actionSheet = [[UIActionSheet alloc]
initWithTitle:NSLocalizedString(@"Really unlink Dropbox account?",
@"Prompt to show before unlinking account")
delegate:self
cancelButtonTitle:cancel
destructiveButtonTitle:NSLocalizedString(@"Unlink", @"Unlink button title")
otherButtonTitles:nil];
[actionSheet setDelegate:self];
[actionSheet showFromTabBar:[appDelegate.tabBarController tabBar]];
}
}
- (CGFloat)tableView:(UITableView*)tableView heightForSpecifier:(IASKSpecifier*)specifier {
return 44;
}
- (UITableViewCell*)tableView:(UITableView*)tableView cellForSpecifier:(IASKSpecifier*)specifier {
UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:specifier.key];
if (!cell) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:specifier.key] autorelease];
}
self.dropboxCell = cell;
[self updateDropboxCell];
return cell;
}
#pragma mark -
#pragma mark IASKAppSettingsViewControllerDelegate protocol
- (void)settingsViewControllerDidEnd:(IASKAppSettingsViewController*)sender
{
[self synchronizeSettings];
[appDelegate updateFromSettings];
[self synchronizeSettings];
}
@end