aboutsummaryrefslogtreecommitdiffhomepage
path: root/example/ios/iOS UI Test/iOS UI Test/MasterViewController.m
diff options
context:
space:
mode:
Diffstat (limited to 'example/ios/iOS UI Test/iOS UI Test/MasterViewController.m')
-rw-r--r--example/ios/iOS UI Test/iOS UI Test/MasterViewController.m70
1 files changed, 35 insertions, 35 deletions
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 <MailCore/MailCore.h>
#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];
}
}