mirror of
https://github.com/moonlight-stream/moonlight-ios.git
synced 2026-02-16 10:31:02 +00:00
Added long press to remove/unpair host
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -130,6 +130,10 @@
|
||||
[_hostQueue addObject:host];
|
||||
}
|
||||
|
||||
- (void) removeHostFromDiscovery:(Host *)host {
|
||||
[_hostQueue removeObject:host];
|
||||
}
|
||||
|
||||
- (void)updateHosts:(NSArray *)hosts {
|
||||
[_hostQueue addObjectsFromArray:hosts];
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
@protocol HostCallback <NSObject>
|
||||
|
||||
- (void) hostClicked:(Host*)host;
|
||||
- (void) hostLongClicked:(Host*)host;
|
||||
- (void) addHostClicked;
|
||||
|
||||
@end
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
|
||||
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user