17
17
#import " StackScrollViewController.h"
18
18
#import < Accounts/Accounts.h>
19
19
#import < Social/Social.h>
20
+ #import " IDTwitterAccountChooserViewController.h"
20
21
21
22
@implementation SettingsTabViewController
22
23
@@ -205,13 +206,12 @@ - (void)reloadTwitterUIElements
205
206
{
206
207
// Get account and communicate with Twitter API
207
208
self.twitterEnabledSwitch .enabled = YES ;
208
- // if ([[appDelegateS.settingsDictionary objectForKey:@"twitterEnabledSetting"] isEqualToString:@"YES"])
209
209
if (settingsS.isTwitterEnabled )
210
210
self.twitterEnabledSwitch .on = YES ;
211
211
else
212
212
self.twitterEnabledSwitch .on = NO ;
213
213
214
- self.twitterSigninButton . imageView . image = [UIImage imageNamed: @" twitter-signout.png" ];
214
+ [ self .twitterSigninButton setImage: [UIImage imageNamed: @" twitter-signout.png" ] forState: UIControlStateNormal ];
215
215
216
216
self.twitterStatusLabel .text = [NSString stringWithFormat: @" %@ signed in" , [acct username ]];
217
217
};
@@ -221,8 +221,8 @@ - (void)reloadTwitterUIElements
221
221
self.twitterEnabledSwitch .on = NO ;
222
222
self.twitterEnabledSwitch .enabled = NO ;
223
223
224
- self.twitterSigninButton . imageView . image = [UIImage imageNamed: @" twitter-signin.png" ];
225
-
224
+ [ self .twitterSigninButton setImage: [UIImage imageNamed: @" twitter-signin.png" ] forState: UIControlStateNormal ];
225
+
226
226
self.twitterStatusLabel .text = @" Signed out" ;
227
227
};
228
228
@@ -235,29 +235,6 @@ - (void)reloadTwitterUIElements
235
235
{
236
236
disableTwitterUI ();
237
237
}
238
-
239
- // if (socialS.twitterEngine)
240
- // {
241
- // self.twitterEnabledSwitch.enabled = YES;
242
- // //if ([[appDelegateS.settingsDictionary objectForKey:@"twitterEnabledSetting"] isEqualToString:@"YES"])
243
- // if (settingsS.isTwitterEnabled)
244
- // self.twitterEnabledSwitch.on = YES;
245
- // else
246
- // self.twitterEnabledSwitch.on = NO;
247
- //
248
- // self.twitterSigninButton.imageView.image = [UIImage imageNamed:@"twitter-signout.png"];
249
- //
250
- // self.twitterStatusLabel.text = [NSString stringWithFormat:@"%@ signed in", [socialS.twitterEngine username]];
251
- // }
252
- // else
253
- // {
254
- // self.twitterEnabledSwitch.on = NO;
255
- // self.twitterEnabledSwitch.enabled = NO;
256
- //
257
- // self.twitterSigninButton.imageView.image = [UIImage imageNamed:@"twitter-signin.png"];
258
- //
259
- // self.twitterStatusLabel.text = @"Signed out";
260
- // }
261
238
}
262
239
263
240
- (void )cachingTypeToggle
@@ -719,8 +696,7 @@ - (IBAction)revertMinFreeSpaceSlider
719
696
- (IBAction )twitterButtonAction
720
697
{
721
698
ACAccountStore *account = [[ACAccountStore alloc ] init ];
722
- ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier:
723
- ACAccountTypeIdentifierTwitter];
699
+ ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier: ACAccountTypeIdentifierTwitter];
724
700
725
701
if (settingsS.currentTwitterAccount )
726
702
{
@@ -729,16 +705,37 @@ - (IBAction)twitterButtonAction
729
705
}
730
706
else
731
707
{
732
- [account requestAccessToAccountsWithType: accountType options: nil
733
- completion: ^(BOOL granted, NSError *error)
708
+ [account requestAccessToAccountsWithType: accountType withCompletionHandler: ^(BOOL granted, NSError *error)
734
709
{
735
710
if (granted == YES )
736
711
{
737
- // Get account and communicate with Twitter API
738
- ALog (@" We're in! Haha!" );
739
- ACAccount *lastAccount = (ACAccount *)[[account accounts ] lastObject ];
740
- settingsS.currentTwitterAccount = [lastAccount identifier ];
741
- [self reloadTwitterUIElements ];
712
+ [EX2Dispatch runInMainThread: ^
713
+ {
714
+ if ([[account accounts ] count ] == 1 )
715
+ {
716
+ settingsS.currentTwitterAccount = [[[account accounts ] firstObjectSafe ] identifier ];
717
+ [self reloadTwitterUIElements ];
718
+ }
719
+ else if ([[account accounts ] count ] > 1 )
720
+ {
721
+ // more than one account, use Chooser
722
+ IDTwitterAccountChooserViewController *chooser = [[IDTwitterAccountChooserViewController alloc ] initWithRootViewController: nil ];
723
+ [chooser setTwitterAccounts: [account accounts ]];
724
+ [chooser setCompletionHandler: ^(ACAccount *account)
725
+ {
726
+ if (account)
727
+ {
728
+ settingsS.currentTwitterAccount = [account identifier ];
729
+ [self reloadTwitterUIElements ];
730
+ }
731
+ }];
732
+ [self .parentController.navigationController presentModalViewController: chooser animated: YES ];
733
+ }
734
+ else
735
+ {
736
+ [[[UIAlertView alloc ] initWithTitle: nil message: NSLocalizedString(@" To use this feature, please add a Twitter account in the iOS Settings app." , @" No twitter accounts alert" ) delegate: nil cancelButtonTitle: @" OK" otherButtonTitles: nil ] show ];
737
+ }
738
+ }];
742
739
}
743
740
}];
744
741
}
0 commit comments