aboutsummaryrefslogtreecommitdiffhomepage
path: root/example
diff options
context:
space:
mode:
authorGravatar Jonathan Willing <jwilling@me.com>2013-04-09 00:44:15 -0500
committerGravatar Jonathan Willing <jwilling@me.com>2013-04-12 17:48:33 -0500
commitd2066220039fb54ea8a6c7bedf1a759ef3a8d4d1 (patch)
tree474750c57a7f9c9d32d14a6cf94d5402cb6f1616 /example
parent0f9621522c597dedf4f4e21ab074d54282b433f4 (diff)
complete basic interface for iOS example
Diffstat (limited to 'example')
-rw-r--r--example/ios/iOS UI Test/iOS UI Test/MasterViewController.m70
-rw-r--r--example/ios/iOS UI Test/iOS UI Test/SettingsViewController.m4
-rw-r--r--example/ios/iOS UI Test/iOS UI Test/en.lproj/MainStoryboard.storyboard4
-rw-r--r--example/ios/iOS UI Test/iOS UI Test/main.mm1
4 files changed, 40 insertions, 39 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];
}
}
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 @@
<outlet property="delegate" destination="12" id="15"/>
</connections>
</tableView>
- <navigationItem key="navigationItem" title="Master" id="36">
+ <navigationItem key="navigationItem" title="Inbox" id="36">
<barButtonItem key="rightBarButtonItem" title="Settings" id="91f-3m-Uww">
<connections>
<action selector="showSettingsViewController:" destination="12" id="i9b-HB-ul1"/>
@@ -91,7 +91,7 @@
<constraint firstAttribute="trailing" secondItem="27" secondAttribute="trailing" constant="20" symbolic="YES" type="default" id="pRe-qY-58T"/>
</constraints>
</view>
- <navigationItem key="navigationItem" title="Detail" id="26"/>
+ <navigationItem key="navigationItem" title="Message" id="26"/>
<connections>
<outlet property="detailDescriptionLabel" destination="27" id="28"/>
</connections>
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 <MailCore/MailCore.h>
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();