Skip to content

Commit 051b042

Browse files
committed
- Added support for choosing from multiple twitter accounts
- Fixed twitter support on iOS 5 - Fixed UI issue after adding twitter account [libSub] - Fixed genres tab not being populated during scan - Fixed can't switch servers after doing a scan - Removed old twitter support - Fixed new twitter support to work on iOS 5 and check tweet length
1 parent 87f6df7 commit 051b042

File tree

9 files changed

+1001
-70
lines changed

9 files changed

+1001
-70
lines changed

Classes/SettingsTabViewController.m

+33-36
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#import "StackScrollViewController.h"
1818
#import <Accounts/Accounts.h>
1919
#import <Social/Social.h>
20+
#import "IDTwitterAccountChooserViewController.h"
2021

2122
@implementation SettingsTabViewController
2223

@@ -205,13 +206,12 @@ - (void)reloadTwitterUIElements
205206
{
206207
// Get account and communicate with Twitter API
207208
self.twitterEnabledSwitch.enabled = YES;
208-
//if ([[appDelegateS.settingsDictionary objectForKey:@"twitterEnabledSetting"] isEqualToString:@"YES"])
209209
if (settingsS.isTwitterEnabled)
210210
self.twitterEnabledSwitch.on = YES;
211211
else
212212
self.twitterEnabledSwitch.on = NO;
213213

214-
self.twitterSigninButton.imageView.image = [UIImage imageNamed:@"twitter-signout.png"];
214+
[self.twitterSigninButton setImage:[UIImage imageNamed:@"twitter-signout.png"] forState:UIControlStateNormal];
215215

216216
self.twitterStatusLabel.text = [NSString stringWithFormat:@"%@ signed in", [acct username]];
217217
};
@@ -221,8 +221,8 @@ - (void)reloadTwitterUIElements
221221
self.twitterEnabledSwitch.on = NO;
222222
self.twitterEnabledSwitch.enabled = NO;
223223

224-
self.twitterSigninButton.imageView.image = [UIImage imageNamed:@"twitter-signin.png"];
225-
224+
[self.twitterSigninButton setImage:[UIImage imageNamed:@"twitter-signin.png"] forState:UIControlStateNormal];
225+
226226
self.twitterStatusLabel.text = @"Signed out";
227227
};
228228

@@ -235,29 +235,6 @@ - (void)reloadTwitterUIElements
235235
{
236236
disableTwitterUI();
237237
}
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-
// }
261238
}
262239

263240
- (void)cachingTypeToggle
@@ -719,8 +696,7 @@ - (IBAction)revertMinFreeSpaceSlider
719696
- (IBAction)twitterButtonAction
720697
{
721698
ACAccountStore *account = [[ACAccountStore alloc] init];
722-
ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier:
723-
ACAccountTypeIdentifierTwitter];
699+
ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
724700

725701
if (settingsS.currentTwitterAccount)
726702
{
@@ -729,16 +705,37 @@ - (IBAction)twitterButtonAction
729705
}
730706
else
731707
{
732-
[account requestAccessToAccountsWithType:accountType options:nil
733-
completion:^(BOOL granted, NSError *error)
708+
[account requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error)
734709
{
735710
if (granted == YES)
736711
{
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+
}];
742739
}
743740
}];
744741
}

0 commit comments

Comments
 (0)