Added long press to remove/unpair host

This commit is contained in:
Diego Waxemberg
2015-01-01 23:25:09 -05:00
parent 3eee684961
commit 417f1e02bc
5 changed files with 32 additions and 0 deletions

View File

@@ -22,6 +22,7 @@
- (void) startDiscovery;
- (void) stopDiscovery;
- (void) addHostToDiscovery:(Host*)host;
- (void) removeHostFromDiscovery:(Host*)host;
- (void) discoverHost:(NSString*)hostAddress withCallback:(void (^)(Host*))callback;
@end

View File

@@ -130,6 +130,10 @@
[_hostQueue addObject:host];
}
- (void) removeHostFromDiscovery:(Host *)host {
[_hostQueue removeObject:host];
}
- (void)updateHosts:(NSArray *)hosts {
[_hostQueue addObjectsFromArray:hosts];
}

View File

@@ -12,6 +12,7 @@
@protocol HostCallback <NSObject>
- (void) hostClicked:(Host*)host;
- (void) hostLongClicked:(Host*)host;
- (void) addHostClicked;
@end

View File

@@ -74,6 +74,9 @@ static int LABEL_DY = 20;
_hostPairState.center = CGPointMake(_hostLabel.center.x, _hostLabel.center.y + LABEL_DY);
_hostStatus.center = CGPointMake(_hostPairState.center.x, _hostPairState.center.y + LABEL_DY);
UILongPressGestureRecognizer* longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(hostLongClicked)];
[_hostButton addGestureRecognizer:longPressRecognizer];
[self updateBounds];
[self addSubview:_hostButton];
[self addSubview:_hostLabel];
@@ -118,6 +121,10 @@ static int LABEL_DY = 20;
return self;
}
- (void) hostLongClicked {
[_callback hostLongClicked:_host];
}
- (void) hostClicked {
[_callback hostClicked:_host];
}

View File

@@ -112,6 +112,25 @@ static StreamConfiguration* streamConfig;
});
}
- (void)hostLongClicked:(Host *)host {
NSLog(@"Long clicked host: %@", host.name);
UIAlertController* longClickAlert = [UIAlertController alertControllerWithTitle:host.name message:@"" preferredStyle:UIAlertControllerStyleActionSheet];
[longClickAlert addAction:[UIAlertAction actionWithTitle:@"Unpair" style:UIAlertActionStyleDefault handler:^(UIAlertAction* action){
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
HttpManager* hMan = [[HttpManager alloc] initWithHost:host.address uniqueId:_uniqueId deviceName:deviceName cert:_cert];
[hMan executeRequestSynchronously:[hMan newUnpairRequest]];
});
}]];
[longClickAlert addAction:[UIAlertAction actionWithTitle:@"Remove Host" style:UIAlertActionStyleDestructive handler:^(UIAlertAction* action) {
[hostList removeObject:host];
[_discMan removeHostFromDiscovery:host];
}]];
[longClickAlert addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]];
[self presentViewController:longClickAlert animated:YES completion:^{
[self updateHosts];
}];
}
- (void) addHostClicked {
NSLog(@"Clicked add host");
UIAlertController* alertController = [UIAlertController alertControllerWithTitle:@"Host Address" message:@"Please enter a hostname or IP address" preferredStyle:UIAlertControllerStyleAlert];