From 417f1e02bc0c1a7a3d3afa57d8d2ee3c82d0e1d6 Mon Sep 17 00:00:00 2001 From: Diego Waxemberg Date: Thu, 1 Jan 2015 23:25:09 -0500 Subject: [PATCH] Added long press to remove/unpair host --- Limelight/Network/DiscoveryManager.h | 1 + Limelight/Network/DiscoveryManager.m | 4 ++++ Limelight/UIComputerView.h | 1 + Limelight/UIComputerView.m | 7 +++++++ .../ViewControllers/MainFrameViewController.m | 19 +++++++++++++++++++ 5 files changed, 32 insertions(+) diff --git a/Limelight/Network/DiscoveryManager.h b/Limelight/Network/DiscoveryManager.h index 5f88502..4252420 100644 --- a/Limelight/Network/DiscoveryManager.h +++ b/Limelight/Network/DiscoveryManager.h @@ -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 diff --git a/Limelight/Network/DiscoveryManager.m b/Limelight/Network/DiscoveryManager.m index 9e93bea..9bff988 100644 --- a/Limelight/Network/DiscoveryManager.m +++ b/Limelight/Network/DiscoveryManager.m @@ -130,6 +130,10 @@ [_hostQueue addObject:host]; } +- (void) removeHostFromDiscovery:(Host *)host { + [_hostQueue removeObject:host]; +} + - (void)updateHosts:(NSArray *)hosts { [_hostQueue addObjectsFromArray:hosts]; } diff --git a/Limelight/UIComputerView.h b/Limelight/UIComputerView.h index cd96624..0765d0f 100644 --- a/Limelight/UIComputerView.h +++ b/Limelight/UIComputerView.h @@ -12,6 +12,7 @@ @protocol HostCallback - (void) hostClicked:(Host*)host; +- (void) hostLongClicked:(Host*)host; - (void) addHostClicked; @end diff --git a/Limelight/UIComputerView.m b/Limelight/UIComputerView.m index 02938cd..53adcdc 100644 --- a/Limelight/UIComputerView.m +++ b/Limelight/UIComputerView.m @@ -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]; } diff --git a/Limelight/ViewControllers/MainFrameViewController.m b/Limelight/ViewControllers/MainFrameViewController.m index a6ebae3..23c0a6e 100644 --- a/Limelight/ViewControllers/MainFrameViewController.m +++ b/Limelight/ViewControllers/MainFrameViewController.m @@ -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];