Skip to content

Commit

Permalink
Merge pull request #21 from vermiculus/feature/auto-capture-mode
Browse files Browse the repository at this point in the history
Auto-Capture Mode
  • Loading branch information
webframp committed Feb 25, 2013
2 parents 533f0bf + a8b8a21 commit 5bda921
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 1 deletion.
12 changes: 12 additions & 0 deletions Classes/MobileOrgAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#import "DataUtils.h"
#import "Reachability.h"
#import "SessionManager.h"
#import "Settings.h"

@interface MobileOrgAppDelegate(private)
- (void)updateInterfaceWithReachability:(Reachability*)curReach;
Expand Down Expand Up @@ -79,6 +80,17 @@ - (void)applicationDidFinishLaunching:(UIApplication *)application {
[window makeKeyAndVisible];
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
if ([[Settings instance] launchTab] == LaunchTabCapture) {
// TODO Add some sort of minimum time-lapse to activate
// that is, don't create a new capture if the button was hit accidentally
// (Allow maybe a minute or two before this setting 'sctivates' again)
// (this can be done by storing the time and doing a difference.)
[[self tabBarController] setSelectedIndex:1]; // Capture!!
[[self noteListController] addNote];
}
}

/**
applicationWillTerminate: saves changes in the application's managed object context before the application terminates.
*/
Expand Down
8 changes: 8 additions & 0 deletions Classes/Settings/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ typedef enum {
ServerModeDropbox
} ServerMode;

typedef enum {
LaunchTabOutline = 0,
LaunchTabCapture,
} LaunchTab;

@interface Settings : NSObject {
NSURL *indexUrl;

Expand All @@ -51,6 +56,8 @@ typedef enum {
AppBadgeMode appBadgeMode;

ServerMode serverMode;

LaunchTab launchTab;

NSString *dropboxIndex;

Expand All @@ -68,6 +75,7 @@ typedef enum {
@property (nonatomic, copy) NSMutableArray *priorities;
@property (nonatomic) AppBadgeMode appBadgeMode;
@property (nonatomic) ServerMode serverMode;
@property (nonatomic) LaunchTab launchTab;
@property (nonatomic, copy) NSString *dropboxIndex;
@property (nonatomic, copy) NSString *encryptionPassword;

Expand Down
13 changes: 13 additions & 0 deletions Classes/Settings/Settings.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
static NSString *kPrioritiesKey = @"Priorities";
static NSString *kAppBadgeModeKey = @"AppBadgeMode";
static NSString *kServerModeKey = @"ServerMode";
static NSString *kLaunchTabKey = @"LaunchTab";
static NSString *kDropboxIndexKey = @"DropboxIndex";
static NSString *kEncryptionPassKey = @"EncryptionPassword";

Expand All @@ -62,6 +63,7 @@ @implementation Settings
@synthesize priorities;
@synthesize appBadgeMode;
@synthesize serverMode;
@synthesize launchTab;
@synthesize dropboxIndex;
@synthesize encryptionPassword;

Expand Down Expand Up @@ -131,6 +133,11 @@ - (id)init {
if (!serverMode) {
self.serverMode = ServerModeWebDav;
}

launchTab = [[NSUserDefaults standardUserDefaults] integerForKey:kLaunchTabKey];
if (!serverMode) {
self.launchTab = LaunchTabOutline;
}

dropboxIndex = [[NSUserDefaults standardUserDefaults] objectForKey:kDropboxIndexKey];
[dropboxIndex retain];
Expand Down Expand Up @@ -309,6 +316,12 @@ - (void)setServerMode:(ServerMode)newServerMode {
[[NSUserDefaults standardUserDefaults] synchronize];
}

- (void)setLaunchTab:(LaunchTab)newLaunchTab {
launchTab = newLaunchTab;
[[NSUserDefaults standardUserDefaults] setInteger:launchTab forKey:kLaunchTabKey];
[[NSUserDefaults standardUserDefaults] synchronize];
}

- (void)setDropboxIndex:(NSString*)anIndex {
[dropboxIndex release];
dropboxIndex = [anIndex copy];
Expand Down
36 changes: 35 additions & 1 deletion Classes/Settings/SettingsController.m
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger
return 2;
break;
case SettingsGroup:
return 1;
return 2;
break;
case EncryptionGroup:
return 1;
Expand Down Expand Up @@ -399,6 +399,31 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N

return cell;
}
case 1:
{
static NSString *CellIdentifier = @"SettingsLaunchTabCell";

UISwitch *launchTabSwitch = nil;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
if (IsIpad())
launchTabSwitch = [[[UISwitch alloc] initWithFrame:CGRectMake(620,10,200,25)] autorelease];
else
launchTabSwitch = [[[UISwitch alloc] initWithFrame:CGRectMake(200,10,200,25)] autorelease];
[cell addSubview:launchTabSwitch];
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
[[cell textLabel] setFont:[UIFont boldSystemFontOfSize:15.0]];
} else {
launchTabSwitch = (UISwitch*)[cell.contentView viewWithTag:1];
}

[launchTabSwitch addTarget:self action:@selector(launchTabSwitchChanged:) forControlEvents:UIControlEventValueChanged];
[[cell textLabel] setText:@"AutoCapture Mode"];
[launchTabSwitch setOn:([[Settings instance] launchTab] == LaunchTabCapture)];

return cell;
}
default:
break;
}
Expand Down Expand Up @@ -610,6 +635,15 @@ - (void)modeSwitchChanged:(id)sender {
[[self tableView] setNeedsDisplay];
}

- (void)launchTabSwitchChanged:(id)sender {
UISwitch *launchTabSwitch = (UISwitch*)sender;
if ([launchTabSwitch isOn]) {
[[Settings instance] setLaunchTab:LaunchTabCapture];
} else {
[[Settings instance] setLaunchTab:LaunchTabOutline];
}
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 46;
}
Expand Down

0 comments on commit 5bda921

Please sign in to comment.