From ce800f23933baa4fa0e86e3277aeb4a45e558532 Mon Sep 17 00:00:00 2001 From: Jonathan Willing Date: Sat, 11 May 2013 16:53:41 -0500 Subject: add the ability in the iOS demo to change the hostname --- .../iOS UI Test/iOS UI Test/MasterViewController.m | 21 ++- .../iOS UI Test/SettingsViewController.h | 2 + .../iOS UI Test/SettingsViewController.m | 24 +-- .../iOS UI Test/SettingsViewController.xib | 175 ++++++++++++++++++++- 4 files changed, 192 insertions(+), 30 deletions(-) (limited to 'example') diff --git a/example/ios/iOS UI Test/iOS UI Test/MasterViewController.m b/example/ios/iOS UI Test/iOS UI Test/MasterViewController.m index 0e4c848b..493c8e5b 100644 --- a/example/ios/iOS UI Test/iOS UI Test/MasterViewController.m +++ b/example/ios/iOS UI Test/iOS UI Test/MasterViewController.m @@ -24,19 +24,23 @@ - (void)viewDidLoad { [super viewDidLoad]; + [[NSUserDefaults standardUserDefaults] registerDefaults:@{ HostnameKey: @"imap.gmail.com" }]; + NSString *username = [[NSUserDefaults standardUserDefaults] objectForKey:UsernameKey]; NSString *password = [[FXKeychain defaultKeychain] objectForKey:PasswordKey]; - [self loadAccountWithUsername:username password:password]; + NSString *hostname = [[NSUserDefaults standardUserDefaults] objectForKey:HostnameKey]; + + [self loadAccountWithUsername:username password:password hostname:hostname]; } -- (void)loadAccountWithUsername:(NSString *)username password:(NSString *)password { +- (void)loadAccountWithUsername:(NSString *)username password:(NSString *)password hostname:(NSString *)hostname { if (!username.length || !password.length) { [self performSelector:@selector(showSettingsViewController:) withObject:nil afterDelay:0.5]; return; } self.imapSession = [[MCOIMAPSession alloc] init]; - self.imapSession.hostname = @"imap.gmail.com"; + self.imapSession.hostname = hostname; self.imapSession.port = 993; self.imapSession.username = username; self.imapSession.password = password; @@ -74,7 +78,9 @@ [self.imapMessagesFetchOp start:^(NSError *error, NSArray *messages, MCOIndexSet *vanishedMessages) { MasterViewController *strongSelf = weakSelf; NSLog(@"fetched all messages."); - strongSelf.messages = [NSArray arrayWithArray:messages]; + + NSSortDescriptor *sort = [NSSortDescriptor sortDescriptorWithKey:@"header.date" ascending:NO]; + strongSelf.messages = [messages sortedArrayUsingDescriptors:@[sort]];//[NSArray arrayWithArray:messages]; [strongSelf.tableView reloadData]; }]; } @@ -116,10 +122,13 @@ NSString *username = [[NSUserDefaults standardUserDefaults] stringForKey:UsernameKey]; NSString *password = [[FXKeychain defaultKeychain] objectForKey:PasswordKey]; + NSString *hostname = [[NSUserDefaults standardUserDefaults] objectForKey:HostnameKey]; - if (![username isEqualToString:self.imapSession.username] || ![password isEqualToString:self.imapSession.password]) { + if (![username isEqualToString:self.imapSession.username] || + ![password isEqualToString:self.imapSession.password] || + ![hostname isEqualToString:self.imapSession.hostname]) { self.imapSession = nil; - [self loadAccountWithUsername:username password:password]; + [self loadAccountWithUsername:username password:password hostname:hostname]; } } diff --git a/example/ios/iOS UI Test/iOS UI Test/SettingsViewController.h b/example/ios/iOS UI Test/iOS UI Test/SettingsViewController.h index 2c6cd2ef..2172b4d4 100644 --- a/example/ios/iOS UI Test/iOS UI Test/SettingsViewController.h +++ b/example/ios/iOS UI Test/iOS UI Test/SettingsViewController.h @@ -10,6 +10,7 @@ extern NSString * const UsernameKey; extern NSString * const PasswordKey; +extern NSString * const HostnameKey; @protocol SettingsViewControllerDelegate; @@ -17,6 +18,7 @@ extern NSString * const PasswordKey; @property (weak, nonatomic) IBOutlet UITextField *emailTextField; @property (weak, nonatomic) IBOutlet UITextField *passwordTextField; +@property (weak, nonatomic) IBOutlet UITextField *hostnameTextField; @property (nonatomic, weak) id delegate; - (IBAction)done:(id)sender; diff --git a/example/ios/iOS UI Test/iOS UI Test/SettingsViewController.m b/example/ios/iOS UI Test/iOS UI Test/SettingsViewController.m index f08eba77..6fbd6db2 100644 --- a/example/ios/iOS UI Test/iOS UI Test/SettingsViewController.m +++ b/example/ios/iOS UI Test/iOS UI Test/SettingsViewController.m @@ -11,25 +11,14 @@ NSString * const UsernameKey = @"username"; NSString * const PasswordKey = @"password"; - -@interface SettingsViewController () - -@end +NSString * const HostnameKey = @"hostname"; @implementation SettingsViewController -- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil -{ - self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; - if (self) { - // Custom initialization - } - return self; -} - - (void)done:(id)sender { - [[NSUserDefaults standardUserDefaults] setObject:self.emailTextField.text forKey:UsernameKey]; + [[NSUserDefaults standardUserDefaults] setObject:self.emailTextField.text ?: @"" forKey:UsernameKey]; [[FXKeychain defaultKeychain] setObject:self.passwordTextField.text ?: @"" forKey:PasswordKey]; + [[NSUserDefaults standardUserDefaults] setObject:self.hostnameTextField.text ?: @"" forKey:HostnameKey]; [self.delegate settingsViewControllerFinished:self]; } @@ -40,12 +29,7 @@ NSString * const PasswordKey = @"password"; self.view.backgroundColor = [UIColor underPageBackgroundColor]; self.emailTextField.text = [[NSUserDefaults standardUserDefaults] stringForKey:UsernameKey]; self.passwordTextField.text = [[FXKeychain defaultKeychain] objectForKey:PasswordKey]; -} - -- (void)didReceiveMemoryWarning -{ - [super didReceiveMemoryWarning]; - // Dispose of any resources that can be recreated. + self.hostnameTextField.text = [[NSUserDefaults standardUserDefaults] stringForKey:HostnameKey]; } @end diff --git a/example/ios/iOS UI Test/iOS UI Test/SettingsViewController.xib b/example/ios/iOS UI Test/iOS UI Test/SettingsViewController.xib index 6e788970..00041150 100644 --- a/example/ios/iOS UI Test/iOS UI Test/SettingsViewController.xib +++ b/example/ios/iOS UI Test/iOS UI Test/SettingsViewController.xib @@ -44,10 +44,11 @@ 290 {320, 44} + _NS:9 IBCocoaTouchFramework - + Settings @@ -66,6 +67,7 @@ 292 {{20, 66}, {280, 30}} + _NS:9 NO @@ -103,7 +105,8 @@ 292 {{20, 104}, {280, 30}} - + + _NS:9 NO YES @@ -127,9 +130,39 @@ + + + 292 + {{20, 142}, {280, 30}} + + + + _NS:9 + NO + YES + IBCocoaTouchFramework + 0 + + 3 + imap hostname (e.g. imap.gmail.com) + + 3 + MAA + + + YES + 17 + + IBCocoaTouchFramework + + 1 + + + {{0, 20}, {320, 548}} + 1 @@ -182,6 +215,14 @@ 50 + + + hostnameTextField + + + + 55 + done: @@ -203,6 +244,54 @@ 1 + + + 6 + 0 + + 6 + 1 + + 20 + + 1000 + + 8 + 29 + 3 + + + + 5 + 0 + + 5 + 1 + + 20 + + 1000 + + 8 + 29 + 3 + + + + 3 + 0 + + 4 + 1 + + 8 + + 1000 + + 6 + 24 + 3 + 3 @@ -350,6 +439,7 @@ + @@ -441,6 +531,26 @@ + + 51 + + + + + 52 + + + + + 53 + + + + + 54 + + + @@ -459,6 +569,9 @@ + + + com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin @@ -476,15 +589,69 @@ com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin - 50 + 55 + + + + + NSLayoutConstraint + NSObject + + IBProjectSource + ./Classes/NSLayoutConstraint.h + + + + SettingsViewController + UIViewController + + done: + id + + + done: + + done: + id + + + + UITextField + UITextField + UITextField + + + + emailTextField + UITextField + + + hostnameTextField + UITextField + + + passwordTextField + UITextField + + + + IBProjectSource + ./Classes/SettingsViewController.h + + + - 0 IBCocoaTouchFramework YES -- cgit v1.2.3