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

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: 's avatarCarola Nitz <nitz.carola@googlemail.com>
parent c6e07e23
......@@ -335,8 +335,12 @@
#pragma mark - VLCLocalServerDiscoveryController
- (void)discoveryFoundSomethingNew
{
NSString * (^mapServiceName)(id<VLCLocalNetworkService>) = ^NSString *(id<VLCLocalNetworkService> service) {
return [NSString stringWithFormat:@"%@: %@", service.serviceName, service.title];
};
NSMutableArray<id<VLCLocalNetworkService>> *newNetworkServices = [NSMutableArray array];
NSMutableSet<NSString *> *addedNetworkServices = [[NSMutableSet alloc] init];
VLCLocalServerDiscoveryController *discoveryController = self.discoveryController;
NSUInteger sectionCount = [discoveryController numberOfSections];
for (NSUInteger section = 0; section < sectionCount; ++section) {
......@@ -345,7 +349,11 @@
NSIndexPath *indexPath = [NSIndexPath indexPathForItem:index inSection:section];
id<VLCLocalNetworkService> service = [discoveryController networkServiceForIndexPath:indexPath];
if (service != nil) {
[newNetworkServices addObject:service];
NSString *mappedName = mapServiceName(service);
if(![addedNetworkServices containsObject:mappedName]) {
[addedNetworkServices addObject:mappedName];
[newNetworkServices addObject:service];
}
}
}
}
......@@ -353,9 +361,7 @@
NSArray *oldNetworkServices = self.networkServices;
GRKArrayDiff *diff = [[GRKArrayDiff alloc] initWithPreviousArray:oldNetworkServices
currentArray:newNetworkServices
identityBlock:^NSString * _Nullable(id <VLCLocalNetworkService> service) {
return [NSString stringWithFormat:@"%@: %@", service.serviceName, service.title];
}
identityBlock:mapServiceName
modifiedBlock:nil];
[diff performBatchUpdatesWithCollectionView:self.collectionView
......
Markdown is supported
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