Skip to content
Snippets Groups Projects
Commit 79ff6c37 authored by Alexandre Janniaux's avatar Alexandre Janniaux Committed by Steve Lhomme
Browse files

VLCLibraryHomeViewController: refactor notifications

NSNotificationCenter was used repeatedly with repeated allocation to the
autorelease pool in order to setup the suffix addition for the
notification name.

This commit uses a for-loop releasing the local autorelease allocations
and create the notification names on-the-fly to avoid repetition.
parent 9183d89c
No related branches found
No related tags found
1 merge request!5442VLCLibraryHomeViewController: refactor notifications
Pipeline #476112 passed with warnings with stage
in 19 minutes and 24 seconds
......@@ -69,64 +69,33 @@
[self setupHomeLibraryViews];
NSNotificationCenter *notificationCenter = NSNotificationCenter.defaultCenter;
[notificationCenter addObserver:self
selector:@selector(libraryModelUpdated:)
name:VLCLibraryModelVideoMediaListReset
object:nil];
[notificationCenter addObserver:self
selector:@selector(libraryModelUpdated:)
name:VLCLibraryModelVideoMediaItemDeleted
object:nil];
[notificationCenter addObserver:self
selector:@selector(libraryModelUpdated:)
name:VLCLibraryModelAudioMediaListReset
object:nil];
[notificationCenter addObserver:self
selector:@selector(libraryModelUpdated:)
name:VLCLibraryModelAudioMediaItemDeleted
object:nil];
NSString * const videoMediaResetLongLoadStartNotification = [VLCLibraryModelVideoMediaListReset stringByAppendingString:VLCLongNotificationNameStartSuffix];
NSString * const videoMediaResetLongLoadFinishNotification = [VLCLibraryModelVideoMediaListReset stringByAppendingString:VLCLongNotificationNameFinishSuffix];
NSString * const audioMediaResetLongLoadStartNotification = [VLCLibraryModelAudioMediaListReset stringByAppendingString:VLCLongNotificationNameStartSuffix];
NSString * const audioMediaResetLongLoadFinishNotification = [VLCLibraryModelAudioMediaListReset stringByAppendingString:VLCLongNotificationNameFinishSuffix];
NSString * const videoMediaDeletedLongLoadStartNotification = [VLCLibraryModelVideoMediaItemDeleted stringByAppendingString:VLCLongNotificationNameStartSuffix];
NSString * const videoMediaDeletedLongLoadFinishNotification = [VLCLibraryModelVideoMediaItemDeleted stringByAppendingString:VLCLongNotificationNameFinishSuffix];
NSString * const audioMediaDeletedLongLoadStartNotification = [VLCLibraryModelAudioMediaItemDeleted stringByAppendingString:VLCLongNotificationNameStartSuffix];
NSString * const audioMediaDeletedLongLoadFinishNotification = [VLCLibraryModelAudioMediaItemDeleted stringByAppendingString:VLCLongNotificationNameFinishSuffix];
[notificationCenter addObserver:self
selector:@selector(libraryModelLongLoadStarted:)
name:videoMediaResetLongLoadStartNotification
object:nil];
[notificationCenter addObserver:self
selector:@selector(libraryModelLongLoadFinished:)
name:videoMediaResetLongLoadFinishNotification
object:nil];
[notificationCenter addObserver:self
selector:@selector(libraryModelLongLoadStarted:)
name:audioMediaResetLongLoadStartNotification
object:nil];
[notificationCenter addObserver:self
selector:@selector(libraryModelLongLoadFinished:)
name:audioMediaResetLongLoadFinishNotification
object:nil];
[notificationCenter addObserver:self
selector:@selector(libraryModelLongLoadStarted:)
name:videoMediaDeletedLongLoadStartNotification
object:nil];
[notificationCenter addObserver:self
selector:@selector(libraryModelLongLoadFinished:)
name:videoMediaDeletedLongLoadFinishNotification
object:nil];
[notificationCenter addObserver:self
selector:@selector(libraryModelLongLoadStarted:)
name:audioMediaDeletedLongLoadStartNotification
object:nil];
[notificationCenter addObserver:self
selector:@selector(libraryModelLongLoadFinished:)
name:audioMediaDeletedLongLoadFinishNotification
object:nil];
NSString *notificationNames[] =
{
VLCLibraryModelVideoMediaListReset,
VLCLibraryModelAudioMediaListReset,
VLCLibraryModelVideoMediaItemDeleted,
VLCLibraryModelAudioMediaItemDeleted,
};
for (size_t i = 0; i < ARRAY_SIZE(notificationNames); ++i) @autoreleasepool
{
[notificationCenter addObserver:self
selector:@selector(libraryModelUpdated:)
name:notificationNames[i]
object:nil];
NSString *startedNotification = [notificationNames[i] stringByAppendingString:VLCLongNotificationNameStartSuffix];
[notificationCenter addObserver:self
selector:@selector(libraryModelLongLoadStarted:)
name:startedNotification
object:nil];
NSString *finishedNotification = [notificationNames[i] stringByAppendingString:VLCLongNotificationNameFinishSuffix];
[notificationCenter addObserver:self
selector:@selector(libraryModelLongLoadFinished:)
name:finishedNotification
object:nil];
}
}
return self;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment