- Pass-through support

This commit is contained in:
Zaid Elkurdi 2015-04-09 19:45:25 -07:00
parent ae6daf45b4
commit a836b59617
6 changed files with 39 additions and 6 deletions

View File

@ -13,6 +13,7 @@
@property (nonatomic, strong) NSString *name;
@property (nonatomic, strong) NSString *trigger;
@property (nonatomic) BOOL enabled;
@property (nonatomic) BOOL willPassthrough;
@property (nonatomic, strong) NSString *uniqueId;
-(id)initWithDictionary:(NSDictionary*)dict;

View File

@ -15,13 +15,21 @@
NSString *name = dict[@"name"];
NSString *trigger = dict[@"trigger"];
NSString *identifier = dict[@"identifier"] ? dict[@"identifier"] : [NSString stringWithFormat:@"%@", [NSDate date]];
BOOL enabled = false;
if (dict[@"enabled"]) {
enabled = [dict[@"enabled"] boolValue];
}
BOOL passthrough = false;
if (dict[@"passthrough"]) {
enabled = [dict[@"passthrough"] boolValue];
}
self.name = name;
self.trigger = trigger;
self.enabled = enabled;
self.willPassthrough = passthrough;
self.uniqueId = identifier;
}
return self;
@ -31,6 +39,7 @@
return @{@"name" : self.name ? self.name : @"Untitled",
@"trigger" : self.trigger ? self.trigger : @"",
@"enabled" : self.enabled ? [NSNumber numberWithBool:self.enabled] : [NSNumber numberWithBool:NO],
@"passthrough": self.willPassthrough ? [NSNumber numberWithBool:self.willPassthrough] : [NSNumber numberWithBool:NO],
@"identifier" : self.uniqueId };
}

View File

@ -11,6 +11,7 @@
@interface ListenerDetailViewController ()
@property (strong, nonatomic) APActivatorListener *currListener;
@property (strong, nonatomic) UISwitch *enabledSwitch;
@property (strong, nonatomic) UISwitch *passthroughSwitch;
@property (strong, nonatomic) UITextField *nameField;
@property (strong, nonatomic) UITextView *triggerField;
@property (nonatomic) BOOL didChange;
@ -33,12 +34,23 @@
UIView *switchBackground = [[UIView alloc] initWithFrame:CGRectMake(0, 90, self.view.frame.size.width, 50)];
switchBackground.backgroundColor = [UIColor whiteColor];
UILabel *switchLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 80, 50)];
switchLabel.text = @"Enabled:";
UILabel *enabledSwitchLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 80, 50)];
enabledSwitchLabel.text = @"Enabled:";
UILabel *passthroughSwitchLabel = [[UILabel alloc] initWithFrame:CGRectMake(170, 0, 80, 50)];
passthroughSwitchLabel.text = @"Pass-Through:";
self.enabledSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(100, 9.5, 51, 31)];
[self.enabledSwitch addTarget:self action:@selector(didToggleSwitch:) forControlEvents:UIControlEventValueChanged];
self.enabledSwitch.on = self.currListener.enabled;
[switchBackground addSubview:switchLabel];
self.passthroughSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(100, 9.5, 51, 31)];
[self.passthroughSwitch addTarget:self action:@selector(didToggleSwitch:) forControlEvents:UIControlEventValueChanged];
self.passthroughSwitch.on = self.currListener.willPassthrough;
[switchBackground addSubview:enabledSwitchLabel];
[switchBackground addSubview:passthroughSwitchLabel];
[switchBackground addSubview:self.enabledSwitch];
[self.view addSubview:switchBackground];
@ -81,7 +93,12 @@
- (void)didToggleSwitch:(UISwitch*)theSwitch {
self.didChange = YES;
self.currListener.enabled = theSwitch.on;
if (theSwitch == self.enabledSwitch) {
self.currListener.enabled = theSwitch.on;
} else if (theSwitch == self.passthroughSwitch) {
self.currListener.willPassthrough = theSwitch.on;
}
}
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {

View File

@ -13,5 +13,6 @@
@property (strong, nonatomic) NSString *triggerString;
@property (strong, nonatomic) NSRegularExpression *trigger;
@property (strong, nonatomic) NSString *identifier;
@property (nonatomic) BOOL willPassthrough;
- (id)initWithDictionary:(NSDictionary*)dict;
@end

View File

@ -16,6 +16,9 @@
self.triggerString = dict[@"trigger"];
self.trigger = [NSRegularExpression regularExpressionWithPattern:self.triggerString options:NSRegularExpressionCaseInsensitive error:nil];
self.identifier = dict[@"identifier"];
NSNumber *pass = dict[@"passthrough"];
self.willPassthrough = pass ? [pass boolValue] : NO;
}
return self;
}

View File

@ -66,8 +66,10 @@ static NSString *EVENT_PREFIX = @"APListener";
if (match.numberOfRanges > 0) {
NSString *eventName = [NSString stringWithFormat:@"%@%@", EVENT_PREFIX, currListener.identifier];
[LASharedActivator sendEventToListener:[LAEvent eventWithName:eventName mode:LASharedActivator.currentEventMode]];
[currSession sendRequestCompleted];
return YES;
if (!currListener.willPassthrough) {
[currSession sendRequestCompleted];
return YES;
}
}
}
}