Revision 7db1712d Classes/SharingAccountsViewController.m
b/Classes/SharingAccountsViewController.m | ||
---|---|---|
43 | 43 |
#import "AccountManager.h" |
44 | 44 |
#import "SBJSON.h" |
45 | 45 |
#import "AccountHomeViewController.h" |
46 |
#import "APICallback.h" |
|
46 | 47 |
|
47 | 48 |
@implementation SharingAccountsViewController |
48 | 49 |
|
... | ... | |
68 | 69 |
activityIndicatorView = [[ActivityIndicatorView alloc] initWithFrame:[ActivityIndicatorView frameForText:activityMessage] text:activityMessage]; |
69 | 70 |
[activityIndicatorView addToView:self.view]; |
70 | 71 |
|
71 |
[self.account.manager getSharingAccounts]; |
|
72 |
getSharingAccountsSuccessObserver = [[NSNotificationCenter defaultCenter] addObserverForName:@"getSharingAccountsSucceeed" |
|
73 |
object:account |
|
74 |
queue:[NSOperationQueue mainQueue] |
|
75 |
usingBlock:^(NSNotification *notification) |
|
76 |
{ |
|
77 |
OpenStackRequest *request = [[notification userInfo] objectForKey:@"request"]; |
|
78 |
SBJSON *parser = [[SBJSON alloc] init]; |
|
79 |
NSArray *jsonObjects = [parser objectWithString:[request responseString]]; |
|
80 |
|
|
81 |
[sharingAccounts removeAllObjects]; |
|
82 |
for (int i = 0; i < [jsonObjects count]; i++) { |
|
83 |
NSDictionary *dict = [jsonObjects objectAtIndex:i]; |
|
84 |
[sharingAccounts addObject:[dict objectForKey:@"name"]]; |
|
85 |
} |
|
86 |
[parser release]; |
|
87 |
|
|
88 |
[activityIndicatorView removeFromSuperviewAndRelease]; |
|
89 |
refreshButton.enabled = YES; |
|
90 |
contentsLoaded = YES; |
|
91 |
|
|
92 |
[self.tableView reloadData]; |
|
93 |
[[NSNotificationCenter defaultCenter] removeObserver:getSharingAccountsSuccessObserver]; |
|
94 |
}]; |
|
95 |
|
|
96 |
|
|
97 |
getSharingAccountsFailureObserver = [[NSNotificationCenter defaultCenter] addObserverForName:@"getSharingAccountsFailed" |
|
98 |
object:account |
|
99 |
queue:[NSOperationQueue mainQueue] |
|
100 |
usingBlock:^(NSNotification *notification) |
|
101 |
{ |
|
102 |
|
|
103 |
[self alert:@"Request failed" message:@"There was a problem getting the shared accounts"]; |
|
104 |
[activityIndicatorView removeFromSuperviewAndRelease]; |
|
105 |
refreshButton.enabled = YES; |
|
106 |
[self.tableView reloadData]; |
|
107 |
[[NSNotificationCenter defaultCenter] removeObserver:getSharingAccountsFailureObserver]; |
|
108 |
}]; |
|
109 |
|
|
72 |
[[self.account.manager getSharingAccounts] |
|
73 |
success:^(OpenStackRequest *request) { |
|
74 |
SBJSON *parser = [[SBJSON alloc] init]; |
|
75 |
NSArray *jsonObjects = [parser objectWithString:[request responseString]]; |
|
76 |
|
|
77 |
[sharingAccounts removeAllObjects]; |
|
78 |
for (int i = 0; i < [jsonObjects count]; i++) { |
|
79 |
NSDictionary *dict = [jsonObjects objectAtIndex:i]; |
|
80 |
[sharingAccounts addObject:[dict objectForKey:@"name"]]; |
|
81 |
} |
|
82 |
[parser release]; |
|
83 |
|
|
84 |
[activityIndicatorView removeFromSuperviewAndRelease]; |
|
85 |
refreshButton.enabled = YES; |
|
86 |
contentsLoaded = YES; |
|
87 |
|
|
88 |
[self.tableView reloadData]; |
|
89 |
} |
|
90 |
failure:^(OpenStackRequest *request) { |
|
91 |
[self alert:@"Request failed" message:@"There was a problem getting the shared accounts"]; |
|
92 |
[activityIndicatorView removeFromSuperviewAndRelease]; |
|
93 |
refreshButton.enabled = YES; |
|
94 |
[self.tableView reloadData]; |
|
95 |
}]; |
|
110 | 96 |
} |
111 | 97 |
|
112 | 98 |
#pragma mark - Button handlers |
... | ... | |
134 | 120 |
account.sharingAccount = nil; |
135 | 121 |
} |
136 | 122 |
|
137 |
- (void)viewDidDisappear:(BOOL)animated |
|
138 |
{ |
|
139 |
[[NSNotificationCenter defaultCenter] removeObserver:getSharingAccountsSuccessObserver]; |
|
140 |
[[NSNotificationCenter defaultCenter] removeObserver:getSharingAccountsFailureObserver]; |
|
141 |
} |
|
142 |
|
|
143 | 123 |
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { |
144 | 124 |
return (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) || (toInterfaceOrientation == UIInterfaceOrientationPortrait); |
145 | 125 |
} |
Also available in: Unified diff