Permalink
Browse files

Initial setup for responding to `brief://` and `briefcast://` urls pa…

…ssed from elsewhere in the device.
  • Loading branch information...
1 parent f24f418 commit 5621d724c52fc2348ddd1110a8c13a1ff8c8739d @capttaco committed Mar 15, 2010
Showing with 154 additions and 146 deletions.
  1. +12 −0 Briefs-Info.plist
  2. +29 −0 Classes/BFMainViewController.h
  3. +76 −27 Classes/BFMainViewController.m
  4. +36 −1 Classes/BriefsAppDelegate.m
  5. +1 −118 Classes/MainWindow.xib
View
@@ -28,5 +28,17 @@
<string>MainWindow</string>
<key>UIPrerenderedIcon</key>
<true/>
+ <key>CFBundleURLTypes</key>
+ <array>
+ <dict>
+ <key>CFBundleURLName</key>
+ <string>com.digitalarch.briefs</string>
+ <key>CFBundleURLSchemes</key>
+ <array>
+ <string>brief</string>
+ <string>briefcast</string>
+ </array>
+ </dict>
+ </array>
</dict>
</plist>
@@ -8,13 +8,42 @@
#import <UIKit/UIKit.h>
+// Display states for various start-up conditions
+typedef enum {
+ /** Start-up triggered by a brief:// or briefcast:// url */
+ BFMainViewOpenedByURL = -2100,
+
+ /** restarting the app, after it was interuppted while showing a brief */
+ BFMainViewClosedWhilePlayingBrief = -2101,
+
+ /** user has not entered any new briefs or briefcasts, encourage them */
+ BFMainViewNoDataToDisplay = -2102,
+
+ /** the default state, which presents recently opened briefs/briefcasts */
+ BFMainViewDefaultState = -2103,
+
+ /** first time the user opens the app, show welcome launch */
+ BFMainViewFirstTimeOpened = -2104,
+
+} BFMainViewState;
+
+
@interface BFMainViewController : UIViewController
{
IBOutlet UIView *openingView;
IBOutlet UIView *menuView;
+
+ BFMainViewState stateUponLaunch;
+
+ // optional context ivars
+ NSURL *urlLaunchWith;
}
+// Initialization
+- (id)initWithState:(BFMainViewState)state;
+- (id)initWithExternalURL:(NSURL *)url;
+
// Menu Actions
- (IBAction)browseYourBriefs;
- (IBAction)browseYourBriefcasts;
@@ -15,6 +15,7 @@
@interface BFMainViewController (private)
- (void)hideMenuWithAnimation;
+- (void)showMenuWithAnimation;
@end
@@ -25,45 +26,82 @@ @implementation BFMainViewController
#pragma mark -
#pragma mark NSObject Methods
-- (void)viewDidLoad
+- (id)initWithState:(BFMainViewState)state
{
- [super viewDidLoad];
- self.navigationController.navigationBar.tintColor = [BFColor tintColorForNavigationBar];
- self.title = @"Welcome";
+ self = [super initWithNibName:@"BFMainViewController" bundle:nil];
+ if (self != nil) {
+ stateUponLaunch = state;
+ }
+ return self;
}
-- (void)viewWillAppear:(BOOL)animated
+- (id)initWithExternalURL:(NSURL *)url
{
- // push down the menu view
- [UIView beginAnimations:@"MenuSlideUpTransition" context:nil];
- [UIView setAnimationDelegate:self];
- [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
- [UIView setAnimationDuration:0.3f];
-
- CGSize size = menuView.frame.size;
- menuView.frame = CGRectMake(0.0f, 280.0f, size.width, size.height);
+ self = [self initWithState:BFMainViewOpenedByURL];
+ if (self != nil) {
+ urlLaunchWith = url;
+ }
- [UIView commitAnimations];
+ return self;
}
-- (void)didReceiveMemoryWarning
+- (void)dealloc
{
- // Releases the view if it doesn't have a superview.
- [super didReceiveMemoryWarning];
-
- // Release any cached data, images, etc that aren't in use.
+ [super dealloc];
}
-- (void)viewDidUnload
+///////////////////////////////////////////////////////////////////////////////
+#pragma mark -
+#pragma mark NSViewController Methods
+
+- (void)viewDidLoad
{
- // Release any retained subviews of the main view.
- // e.g. self.myOutlet = nil;
+ [super viewDidLoad];
+ self.navigationController.navigationBar.tintColor = [BFColor tintColorForNavigationBar];
+ self.title = @"Welcome";
}
+- (void)viewWillAppear:(BOOL)animated
+{
+ switch (stateUponLaunch) {
+ case BFMainViewOpenedByURL:
+
+ // TODO: Open brief or briefcast at URL
+
+ stateUponLaunch = BFMainViewDefaultState;
+ break;
+
+ case BFMainViewClosedWhilePlayingBrief:
+
+ // TODO: Offer to re-open brief that was disrupted
+
+ stateUponLaunch = BFMainViewDefaultState;
+ break;
+
+ case BFMainViewNoDataToDisplay:
+
+ // TODO: Explain how to find a briefcast
+ break;
+
+ case BFMainViewFirstTimeOpened:
+
+ // TODO: Display the welcome screens
+ break;
+
+ case BFMainViewDefaultState:
+ if (menuView.frame.origin.y <= 480.0f)
+ [self showMenuWithAnimation];
+
+ // TODO: Display recent briefs/briefcasts
+
+ break;
+ }
+}
-- (void)dealloc
+- (void)viewDidUnload
{
- [super dealloc];
+ // Release any retained subviews of the main view.
+ // e.g. self.myOutlet = nil;
}
@@ -83,15 +121,26 @@ - (void)hideMenuWithAnimation
[UIView commitAnimations];
}
+- (void)showMenuWithAnimation
+{
+ // push up the menu view
+ [UIView beginAnimations:@"MenuSlideUpTransition" context:nil];
+ [UIView setAnimationDelegate:self];
+ [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
+ [UIView setAnimationDuration:0.3f];
+
+ CGSize size = menuView.frame.size;
+ menuView.frame = CGRectMake(0.0f, 280.0f, size.width, size.height);
+
+ [UIView commitAnimations];
+}
+
- (IBAction)browseYourBriefs
{
[self hideMenuWithAnimation];
-
- // show browser view
[self.navigationController pushViewController:[[BFBrowseViewController alloc] init] animated:YES];
}
-
- (IBAction)browseYourBriefcasts
{
[self hideMenuWithAnimation];
@@ -8,25 +8,60 @@
#import "BriefsAppDelegate.h"
#import "BFSceneViewController.h"
+#import "BFMainViewController.h"
#import "BFDataManager.h"
@implementation BriefsAppDelegate
@synthesize navigationController, window;
-- (void)applicationDidFinishLaunching:(UIApplication *)application
+- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[BFDataManager sharedBFDataManager] load];
+
+ BFMainViewController *controller = [BFMainViewController alloc];
+ if (launchOptions) {
+ NSURL *url = [launchOptions objectForKey:UIApplicationLaunchOptionsURLKey];
+ controller = [controller initWithState:BFMainViewOpenedByURL];
+ }
+
+ else {
+ // no url sent, going to default for now
+ // TODO: Need to flesh out rest of the launch states.
+ controller = [controller initWithState:BFMainViewDefaultState];
+ }
+
+ self.navigationController = [[UINavigationController alloc] initWithRootViewController:controller];
+ self.navigationController.delegate = self;
[window addSubview:[self.navigationController view]];
[window makeKeyAndVisible];
+ [controller release];
+
+ return YES;
}
- (void)applicationWillTerminate:(UIApplication *)application
{
[[BFDataManager sharedBFDataManager] save];
}
+//- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
+//{
+// if ([[url scheme] isEqualToString:@"brief"]) {
+// NSLog(@"Received the following URL for a brief: %@", url);
+//
+//
+//
+// return YES;
+// }
+// else if ([[url scheme] isEqualToString:@"brieflist"]) {
+// NSLog(@"Received the following URL for a briefcast: %@", url);
+// return YES;
+// }
+// return NO;
+//}
+
- (void)dealloc
{
[navigationController release];
Oops, something went wrong.

0 comments on commit 5621d72

Please sign in to comment.