From d2066220039fb54ea8a6c7bedf1a759ef3a8d4d1 Mon Sep 17 00:00:00 2001 From: Jonathan Willing Date: Tue, 9 Apr 2013 00:44:15 -0500 Subject: complete basic interface for iOS example --- .../iOS UI Test/iOS UI Test/MasterViewController.m | 70 +++++++++++----------- .../iOS UI Test/SettingsViewController.m | 4 +- .../iOS UI Test/en.lproj/MainStoryboard.storyboard | 4 +- example/ios/iOS UI Test/iOS UI Test/main.mm | 1 + 4 files changed, 40 insertions(+), 39 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 bc8fbbbe..c244f611 100644 --- a/example/ios/iOS UI Test/iOS UI Test/MasterViewController.m +++ b/example/ios/iOS UI Test/iOS UI Test/MasterViewController.m @@ -11,9 +11,9 @@ #import #import "FXKeychain.h" -@interface MasterViewController () { - NSMutableArray *_objects; -} +@interface MasterViewController () +@property (nonatomic, strong) NSArray *messages; + @property (nonatomic, strong) MCOIMAPOperation *imapCheckOp; @property (nonatomic, strong) MCOIMAPSession *imapSession; @property (nonatomic, strong) MCOIMAPFetchMessagesOperation *imapMessagesFetchOp; @@ -23,10 +23,17 @@ - (void)viewDidLoad { [super viewDidLoad]; - self.navigationItem.leftBarButtonItem = self.editButtonItem; NSString *username = [[NSUserDefaults standardUserDefaults] objectForKey:UsernameKey]; - NSString *password = [FXKeychain defaultKeychain][PasswordKey]; + NSString *password = [[FXKeychain defaultKeychain] objectForKey:PasswordKey]; + [self loadAccountWithUsername:username password:password]; +} + +- (void)loadAccountWithUsername:(NSString *)username password:(NSString *)password { + 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"; @@ -60,10 +67,15 @@ requestKind:requestKind uids:[MCOIndexSet indexSetWithRange:MCORangeMake(1, UINT64_MAX)]]; [self.imapMessagesFetchOp setProgress:^(unsigned int progress) { - NSLog(@"progress: %u", progress); + //NSLog(@"progress: %u", progress); }]; + + __weak MasterViewController *weakSelf = self; [self.imapMessagesFetchOp start:^(NSError *error, NSArray *messages, MCOIndexSet *vanishedMessages) { - NSLog(@"DONE"); + MasterViewController *strongSelf = weakSelf; + NSLog(@"fetched all messages."); + strongSelf.messages = [NSArray arrayWithArray:messages]; + [strongSelf.tableView reloadData]; }]; } @@ -72,15 +84,6 @@ NSLog(@"%s",__PRETTY_FUNCTION__); } -- (void)insertNewObject:(id)sender { - if (!_objects) { - _objects = [[NSMutableArray alloc] init]; - } - [_objects insertObject:[NSDate date] atIndex:0]; - NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0]; - [self.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic]; -} - #pragma mark - Table View - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { @@ -88,32 +91,21 @@ } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - return _objects.count; + return self.messages.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath]; - - NSDate *object = _objects[indexPath.row]; - cell.textLabel.text = [object description]; + + MCOIMAPMessage *message = self.messages[indexPath.row]; + cell.textLabel.text = message.header.subject; + return cell; } -- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { - // Return NO if you do not want the specified item to be editable. - return YES; -} - -- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { - if (editingStyle == UITableViewCellEditingStyleDelete) { - [_objects removeObjectAtIndex:indexPath.row]; - [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; - } else if (editingStyle == UITableViewCellEditingStyleInsert) { - // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view. - } -} - - (void)showSettingsViewController:(id)sender { + [self.imapMessagesFetchOp cancel]; + SettingsViewController *settingsViewController = [[SettingsViewController alloc] initWithNibName:nil bundle:nil]; settingsViewController.delegate = self; [self presentViewController:settingsViewController animated:YES completion:nil]; @@ -121,12 +113,20 @@ - (void)settingsViewControllerFinished:(SettingsViewController *)viewController { [self dismissViewControllerAnimated:YES completion:nil]; + + NSString *username = [[NSUserDefaults standardUserDefaults] stringForKey:UsernameKey]; + NSString *password = [[FXKeychain defaultKeychain] objectForKey:PasswordKey]; + + if (![username isEqualToString:self.imapSession.username] || ![password isEqualToString:self.imapSession.password]) { + self.imapSession = nil; + [self loadAccountWithUsername:username password:password]; + } } - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([[segue identifier] isEqualToString:@"showDetail"]) { NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow]; - NSDate *object = _objects[indexPath.row]; + NSDate *object = self.messages[indexPath.row]; [[segue destinationViewController] setDetailItem:object]; } } 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 d7621dd0..f08eba77 100644 --- a/example/ios/iOS UI Test/iOS UI Test/SettingsViewController.m +++ b/example/ios/iOS UI Test/iOS UI Test/SettingsViewController.m @@ -29,7 +29,7 @@ NSString * const PasswordKey = @"password"; - (void)done:(id)sender { [[NSUserDefaults standardUserDefaults] setObject:self.emailTextField.text forKey:UsernameKey]; - [FXKeychain defaultKeychain][PasswordKey] = self.passwordTextField.text; + [[FXKeychain defaultKeychain] setObject:self.passwordTextField.text ?: @"" forKey:PasswordKey]; [self.delegate settingsViewControllerFinished:self]; } @@ -39,7 +39,7 @@ NSString * const PasswordKey = @"password"; self.view.backgroundColor = [UIColor underPageBackgroundColor]; self.emailTextField.text = [[NSUserDefaults standardUserDefaults] stringForKey:UsernameKey]; - self.passwordTextField.text = [FXKeychain defaultKeychain][PasswordKey]; + self.passwordTextField.text = [[FXKeychain defaultKeychain] objectForKey:PasswordKey]; } - (void)didReceiveMemoryWarning diff --git a/example/ios/iOS UI Test/iOS UI Test/en.lproj/MainStoryboard.storyboard b/example/ios/iOS UI Test/iOS UI Test/en.lproj/MainStoryboard.storyboard index f28d0b06..70f1848a 100644 --- a/example/ios/iOS UI Test/iOS UI Test/en.lproj/MainStoryboard.storyboard +++ b/example/ios/iOS UI Test/iOS UI Test/en.lproj/MainStoryboard.storyboard @@ -57,7 +57,7 @@ - + @@ -91,7 +91,7 @@ - + diff --git a/example/ios/iOS UI Test/iOS UI Test/main.mm b/example/ios/iOS UI Test/iOS UI Test/main.mm index 0ecfc348..34793ec3 100644 --- a/example/ios/iOS UI Test/iOS UI Test/main.mm +++ b/example/ios/iOS UI Test/iOS UI Test/main.mm @@ -13,6 +13,7 @@ #import int main(int argc, char *argv[]) { + mailcore::logEnabled = false; mailcore::AutoreleasePool *pool = new mailcore::AutoreleasePool(); return UIApplicationMain(argc, argv, NSStringFromClass([Application class]), NSStringFromClass([AppDelegate class])); pool->release(); -- cgit v1.2.3