Commit 6ad83679 authored by Victor Gama's avatar Victor Gama Committed by Carola
Browse files

Filter out duplicated VLCLocalNetworkServices (Fix #108)



This prevents an assertion failure thrown by UIViewCollection in
VLCServerListTVViewController caused by several VLCLocalNetworkServices
using the same serviceName and title combination. Now, duplicated items
are removed from the list.

Signed-off-by: Carola's avatarCarola Nitz <nitz.carola@googlemail.com>
parent c6e07e23
...@@ -335,8 +335,12 @@ ...@@ -335,8 +335,12 @@
#pragma mark - VLCLocalServerDiscoveryController #pragma mark - VLCLocalServerDiscoveryController
- (void)discoveryFoundSomethingNew - (void)discoveryFoundSomethingNew
{ {
NSString * (^mapServiceName)(id<VLCLocalNetworkService>) = ^NSString *(id<VLCLocalNetworkService> service) {
return [NSString stringWithFormat:@"%@: %@", service.serviceName, service.title];
};
NSMutableArray<id<VLCLocalNetworkService>> *newNetworkServices = [NSMutableArray array]; NSMutableArray<id<VLCLocalNetworkService>> *newNetworkServices = [NSMutableArray array];
NSMutableSet<NSString *> *addedNetworkServices = [[NSMutableSet alloc] init];
VLCLocalServerDiscoveryController *discoveryController = self.discoveryController; VLCLocalServerDiscoveryController *discoveryController = self.discoveryController;
NSUInteger sectionCount = [discoveryController numberOfSections]; NSUInteger sectionCount = [discoveryController numberOfSections];
for (NSUInteger section = 0; section < sectionCount; ++section) { for (NSUInteger section = 0; section < sectionCount; ++section) {
...@@ -345,17 +349,19 @@ ...@@ -345,17 +349,19 @@
NSIndexPath *indexPath = [NSIndexPath indexPathForItem:index inSection:section]; NSIndexPath *indexPath = [NSIndexPath indexPathForItem:index inSection:section];
id<VLCLocalNetworkService> service = [discoveryController networkServiceForIndexPath:indexPath]; id<VLCLocalNetworkService> service = [discoveryController networkServiceForIndexPath:indexPath];
if (service != nil) { if (service != nil) {
NSString *mappedName = mapServiceName(service);
if(![addedNetworkServices containsObject:mappedName]) {
[addedNetworkServices addObject:mappedName];
[newNetworkServices addObject:service]; [newNetworkServices addObject:service];
} }
} }
} }
}
NSArray *oldNetworkServices = self.networkServices; NSArray *oldNetworkServices = self.networkServices;
GRKArrayDiff *diff = [[GRKArrayDiff alloc] initWithPreviousArray:oldNetworkServices GRKArrayDiff *diff = [[GRKArrayDiff alloc] initWithPreviousArray:oldNetworkServices
currentArray:newNetworkServices currentArray:newNetworkServices
identityBlock:^NSString * _Nullable(id <VLCLocalNetworkService> service) { identityBlock:mapServiceName
return [NSString stringWithFormat:@"%@: %@", service.serviceName, service.title];
}
modifiedBlock:nil]; modifiedBlock:nil];
[diff performBatchUpdatesWithCollectionView:self.collectionView [diff performBatchUpdatesWithCollectionView:self.collectionView
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment