Permalink
Browse files

Show the auth view on startup when the stored credential are invalid.

  • Loading branch information...
1 parent 67ad0a5 commit 0730cb22b67a5511cea8aca3069d2d253b6cb06b @alloy alloy committed Oct 4, 2011
View
16 Classes/Controllers/AuthenticationViewController.h
@@ -1,16 +1,12 @@
#import <UIKit/UIKit.h>
+@class AuthenticationViewController;
+
+@protocol AuthenticationViewControllerDelegate
+- (void)authenticationViewWillDismiss:(AuthenticationViewController *)controller;
+@end
@interface AuthenticationViewController : UIViewController {
- IBOutlet UITableView *tableView;
- IBOutlet UITextField *usernameField;
- IBOutlet UITextField *passwordField;
- IBOutlet UILabel *signedInAsLabel;
- IBOutlet UITableViewCell *usernameCell;
- IBOutlet UITableViewCell *passwordCell;
- IBOutlet UITableViewCell *signingInCell, *signedInCell;
- IBOutlet UIBarButtonItem *doneButton;
- IBOutlet UIButton *helpBannerButton;
BOOL signingIn, signedIn;
}
@@ -24,6 +20,8 @@
@property (nonatomic, retain) IBOutlet UIBarButtonItem *doneButton;
@property (nonatomic, retain) IBOutlet UIButton *helpBannerButton;
+@property (nonatomic, assign) id <AuthenticationViewControllerDelegate> delegate;
+
+ (BOOL)signIn;
+ (NSString *)signedInAs;
+ (void)retrieveUsername:(NSString **)username password:(NSString **)password;
View
8 Classes/Controllers/AuthenticationViewController.m
@@ -42,6 +42,7 @@ + (void)authenticate:(NSString *)username password:(NSString *)password {
}
+@synthesize delegate;
@synthesize tableView;
@synthesize usernameField, passwordField;
@synthesize usernameCell, passwordCell;
@@ -120,6 +121,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
- (IBAction)dismissDialog:(id)sender {
+ [self.delegate authenticationViewWillDismiss:self];
[self.parentViewController dismissModalViewControllerAnimated:YES];
}
@@ -144,11 +146,9 @@ - (IBAction)saveCredentials:(id)sender {
[[Trakt sharedInstance] verifyCredentials:^(BOOL valid) {
if (valid) {
signingIn = NO;
- signedIn = YES;
- [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0]
- withRowAnimation:UITableViewRowAnimationRight];
- //[self dismissDialog:self];
+ [self dismissDialog:self];
} else {
+ NSLog(@"FAIL!");
self.doneButton.enabled = YES;
self.usernameField.enabled = YES;
self.passwordField.enabled = YES;
View
6 Classes/Controllers/iTraktAppDelegate.h
@@ -1,9 +1,9 @@
#import <UIKit/UIKit.h>
#import "HTTPDownload.h"
+#import "AuthenticationViewController.h"
-@interface iTraktAppDelegate : NSObject <UIApplicationDelegate> {
- UIWindow *window;
- IBOutlet UITabBarController* tabBarController;
+@interface iTraktAppDelegate : NSObject <UIApplicationDelegate, AuthenticationViewControllerDelegate> {
+ BOOL refreshDataWhenAuthViewDismisses;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
View
32 Classes/Controllers/iTraktAppDelegate.m
@@ -3,7 +3,6 @@
#import "RootViewController.h"
#import "CalendarViewController.h"
-#import "AuthenticationViewController.h"
// ONLY FOR DEBUGGING PURPOSES!
#import "Authentication.h"
@@ -22,21 +21,32 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
//NSLog(@"[!] Clearing cache");
//[[EGOCache currentCache] clearCache];
+ refreshDataWhenAuthViewDismisses = NO;
+
+ [[Trakt sharedInstance] setApiKey:API_KEY];
+
if ([AuthenticationViewController signIn]) {
NSLog(@"[!] Signed in.");
+ [[Trakt sharedInstance] verifyCredentials:^(BOOL valid) {
+ if (valid) {
+ NSLog(@"Credentials are valid");
+ // Give the controller a chance to initialize
+ [self performSelector:@selector(refreshDataStartingAtCurrentSelectedTopLevelController) withObject:nil afterDelay:0];
+ } else {
+ NSLog(@"Credentials are invalid");
+ refreshDataWhenAuthViewDismisses = YES;
+ [self presentAuthenticationDialog:nil];
+ }
+ }];
} else {
NSLog(@"[!] Not signed in.");
+ [self presentAuthenticationDialog:nil];
}
- [[Trakt sharedInstance] setApiKey:API_KEY];
-
[HTTPDownload setGlobalDelegate:self];
[self.window makeKeyAndVisible];
- // Give the controller a chance to initialize
- [self performSelector:@selector(refreshDataStartingAtCurrentSelectedTopLevelController) withObject:nil afterDelay:0];
-
return YES;
}
@@ -82,11 +92,19 @@ - (void)refreshDataStartingAtCurrentSelectedTopLevelController {
- (IBAction)presentAuthenticationDialog:(id)sender {
- AuthenticationViewController *controller = [[AuthenticationViewController alloc] initWithNibName:@"AuthenticationViewController" bundle:nil];
+ AuthenticationViewController *controller;
+ controller = [[AuthenticationViewController alloc] initWithNibName:@"AuthenticationViewController"
+ bundle:nil];
+ controller.delegate = self;
[self.window.rootViewController presentModalViewController:controller animated:YES];
[controller release];
}
+- (void)authenticationViewWillDismiss:(AuthenticationViewController *)controller {
+ refreshDataWhenAuthViewDismisses = NO;
+ [self refreshDataStartingAtCurrentSelectedTopLevelController];
+}
+
#pragma mark -
#pragma mark Memory management
View
1 Classes/Lib/HTTPDownload.m
@@ -192,6 +192,7 @@ - (void)yieldDownloadedData {
@implementation JSONDownload
- (void)yieldDownloadedData {
+ //NSLog(@"Downloaded:\n%@", [[NSString alloc] initWithData:downloadData encoding:NSUTF8StringEncoding]);
block([downloadData yajl_JSON]);
}
View
11 Classes/Models/Episode.m
@@ -51,7 +51,14 @@ - (NSString *)title {
}
- (NSURL *)thumbURL {
- return [NSURL URLWithString:[dictionary valueForKey:@"thumb"]];
+ if ([NSNull null] != [dictionary objectForKey:@"thumb"]) {
+ return [dictionary valueForKey:@"thumb"];
+ }
+ return nil;
+}
+
+- (UIImage *)thumb {
+ return thumb == nil ? [UIImage imageNamed:@"placeholder-landscape"] : thumb;
}
- (NSInteger)season {
@@ -89,7 +96,7 @@ - (void)toggleSeen:(void (^)())requestCompletedBlock {
- (void)ensureThumbIsLoaded:(void (^)())downloadedBlock {
// important to first check if we already have the thumb loaded for performance!
- if (self.thumb == nil) {
+ if (self.thumb == nil && self.thumbURL != nil) {
[[Trakt sharedInstance] showThumbForURL:self.thumbURL block:^(UIImage *theThumb, BOOL cached) {
self.thumb = theThumb;
if (!cached) {
View
2 TODO.md
@@ -7,6 +7,8 @@ General
iOS app
+* Use CocoaPods for the dependencies.
+* Possibly switch to AFNetworking to replace the http request and json/image code.
* Handle connection errors in some way which is needed to provide a good UX. I.e. should we retry, take a failure block, etc.
* Echofon style network failure notification
* Make HTTPDownload post start/stop notifications so that the refresh/stop buttons in the top-level controllers can show them accurately.
View
80 Views/MainWindow.xib
@@ -2,13 +2,13 @@
<archive type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="7.10">
<data>
<int key="IBDocument.SystemTarget">1056</int>
- <string key="IBDocument.SystemVersion">10J567</string>
- <string key="IBDocument.InterfaceBuilderVersion">1306</string>
- <string key="IBDocument.AppKitVersion">1038.35</string>
- <string key="IBDocument.HIToolboxVersion">462.00</string>
+ <string key="IBDocument.SystemVersion">11A511</string>
+ <string key="IBDocument.InterfaceBuilderVersion">1617</string>
+ <string key="IBDocument.AppKitVersion">1138</string>
+ <string key="IBDocument.HIToolboxVersion">566.00</string>
<object class="NSMutableDictionary" key="IBDocument.PluginVersions">
<string key="NS.key.0">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
- <string key="NS.object.0">301</string>
+ <string key="NS.object.0">534</string>
</object>
<object class="NSArray" key="IBDocument.IntegratedClassDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -74,13 +74,13 @@
</object>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
<bool key="IBUIHorizontal">NO</bool>
- <object class="IBUINavigationController" key="IBUISelectedViewController" id="293488427">
- <string key="IBUITitle">Trending</string>
- <object class="IBUITabBarItem" key="IBUITabBarItem" id="163677930">
- <string key="IBUITitle">Recommended</string>
+ <object class="IBUINavigationController" key="IBUISelectedViewController" id="1002578325">
+ <string key="IBUITitle">Library</string>
+ <object class="IBUITabBarItem" key="IBUITabBarItem" id="453873882">
+ <string key="IBUITitle">Library</string>
<object class="NSCustomResource" key="IBUIImage">
<string key="NSClassName">NSImage</string>
- <string key="NSResourceName">recommended.png</string>
+ <string key="NSResourceName">library.png</string>
</object>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
</object>
@@ -92,7 +92,7 @@
</object>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
<bool key="IBUIHorizontal">NO</bool>
- <object class="IBUINavigationBar" key="IBUINavigationBar" id="662164014">
+ <object class="IBUINavigationBar" key="IBUINavigationBar" id="658286434">
<nil key="NSNextResponder"/>
<int key="NSvFlags">256</int>
<string key="NSFrameSize">{0, 0}</string>
@@ -103,20 +103,20 @@
</object>
<object class="NSMutableArray" key="IBUIViewControllers">
<bool key="EncodedWithXMLCoder">YES</bool>
- <object class="IBUIViewController" id="598962747">
- <string key="IBUITitle">Recommendations</string>
- <object class="IBUINavigationItem" key="IBUINavigationItem" id="494342882">
+ <object class="IBUIViewController" id="847059996">
+ <string key="IBUITitle">Library</string>
+ <object class="IBUINavigationItem" key="IBUINavigationItem" id="99302249">
<string key="IBUITitle">Root View Controller</string>
- <object class="IBUIBarButtonItem" key="IBUIRightBarButtonItem" id="18110761">
+ <object class="IBUIBarButtonItem" key="IBUIRightBarButtonItem" id="234698289">
<string key="IBUITitle">Sign in</string>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
<int key="IBUIStyle">1</int>
- <reference key="IBUINavigationItem" ref="494342882"/>
+ <reference key="IBUINavigationItem" ref="99302249"/>
</object>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
</object>
- <reference key="IBUIParentViewController" ref="293488427"/>
- <string key="IBUINibName">RecommendationsViewController</string>
+ <reference key="IBUIParentViewController" ref="1002578325"/>
+ <string key="IBUINibName">LibraryViewController</string>
<object class="IBUISimulatedOrientationMetrics" key="IBUISimulatedOrientationMetrics">
<int key="IBUIInterfaceOrientation">1</int>
<int key="interfaceOrientation">1</int>
@@ -179,13 +179,14 @@
</object>
</object>
</object>
- <object class="IBUINavigationController" id="1002578325">
- <string key="IBUITitle">Library</string>
- <object class="IBUITabBarItem" key="IBUITabBarItem" id="453873882">
- <string key="IBUITitle">Library</string>
+ <reference ref="1002578325"/>
+ <object class="IBUINavigationController" id="293488427">
+ <string key="IBUITitle">Trending</string>
+ <object class="IBUITabBarItem" key="IBUITabBarItem" id="163677930">
+ <string key="IBUITitle">Recommended</string>
<object class="NSCustomResource" key="IBUIImage">
<string key="NSClassName">NSImage</string>
- <string key="NSResourceName">library.png</string>
+ <string key="NSResourceName">recommended.png</string>
</object>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
</object>
@@ -197,7 +198,7 @@
</object>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
<bool key="IBUIHorizontal">NO</bool>
- <object class="IBUINavigationBar" key="IBUINavigationBar" id="658286434">
+ <object class="IBUINavigationBar" key="IBUINavigationBar" id="662164014">
<nil key="NSNextResponder"/>
<int key="NSvFlags">256</int>
<string key="NSFrameSize">{0, 0}</string>
@@ -208,20 +209,20 @@
</object>
<object class="NSMutableArray" key="IBUIViewControllers">
<bool key="EncodedWithXMLCoder">YES</bool>
- <object class="IBUIViewController" id="847059996">
- <string key="IBUITitle">Library</string>
- <object class="IBUINavigationItem" key="IBUINavigationItem" id="99302249">
+ <object class="IBUIViewController" id="598962747">
+ <string key="IBUITitle">Recommendations</string>
+ <object class="IBUINavigationItem" key="IBUINavigationItem" id="494342882">
<string key="IBUITitle">Root View Controller</string>
- <object class="IBUIBarButtonItem" key="IBUIRightBarButtonItem" id="234698289">
+ <object class="IBUIBarButtonItem" key="IBUIRightBarButtonItem" id="18110761">
<string key="IBUITitle">Sign in</string>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
<int key="IBUIStyle">1</int>
- <reference key="IBUINavigationItem" ref="99302249"/>
+ <reference key="IBUINavigationItem" ref="494342882"/>
</object>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
</object>
- <reference key="IBUIParentViewController" ref="1002578325"/>
- <string key="IBUINibName">LibraryViewController</string>
+ <reference key="IBUIParentViewController" ref="293488427"/>
+ <string key="IBUINibName">RecommendationsViewController</string>
<object class="IBUISimulatedOrientationMetrics" key="IBUISimulatedOrientationMetrics">
<int key="IBUIInterfaceOrientation">1</int>
<int key="interfaceOrientation">1</int>
@@ -231,7 +232,6 @@
</object>
</object>
</object>
- <reference ref="293488427"/>
</object>
<object class="IBUITabBar" key="IBUITabBar" id="572033500">
<reference key="NSNextResponder"/>
@@ -496,12 +496,12 @@
<object class="NSArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>-1.CustomClassName</string>
+ <string>-1.IBPluginDependency</string>
<string>-2.CustomClassName</string>
- <string>17.IBEditorWindowLastContentRect</string>
+ <string>-2.IBPluginDependency</string>
<string>17.IBPluginDependency</string>
<string>18.IBPluginDependency</string>
<string>2.IBAttributePlaceholdersKey</string>
- <string>2.IBEditorWindowLastContentRect</string>
<string>2.IBPluginDependency</string>
<string>3.CustomClassName</string>
<string>3.IBPluginDependency</string>
@@ -510,33 +510,36 @@
<string>47.IBPluginDependency</string>
<string>48.IBPluginDependency</string>
<string>49.IBPluginDependency</string>
+ <string>50.IBPluginDependency</string>
<string>51.IBPluginDependency</string>
<string>52.CustomClassName</string>
<string>52.IBPluginDependency</string>
<string>53.IBPluginDependency</string>
<string>54.IBPluginDependency</string>
+ <string>55.IBPluginDependency</string>
<string>56.IBPluginDependency</string>
<string>57.CustomClassName</string>
<string>57.IBPluginDependency</string>
<string>58.IBPluginDependency</string>
<string>59.IBPluginDependency</string>
+ <string>60.IBPluginDependency</string>
<string>64.IBPluginDependency</string>
<string>65.IBPluginDependency</string>
<string>66.IBPluginDependency</string>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>UIApplication</string>
+ <string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string>UIResponder</string>
- <string>{{67, 276}, {320, 480}}</string>
+ <string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<object class="NSMutableDictionary">
<bool key="EncodedWithXMLCoder">YES</bool>
<reference key="dict.sortedKeys" ref="0"/>
<reference key="dict.values" ref="0"/>
</object>
- <string>{{138, 276}, {320, 480}}</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string>iTraktAppDelegate</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
@@ -546,18 +549,21 @@
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string>LibraryViewController</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string>RecommendationsViewController</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
</object>
</object>
<object class="NSMutableDictionary" key="unlocalizedProperties">
@@ -602,6 +608,6 @@
<string>{30, 30}</string>
</object>
</object>
- <string key="IBCocoaTouchPluginVersion">301</string>
+ <string key="IBCocoaTouchPluginVersion">534</string>
</data>
</archive>

0 comments on commit 0730cb2

Please sign in to comment.