Skip to content
Snippets Groups Projects
Commit c2b2948d authored by Claudio Cambra's avatar Claudio Cambra Committed by Jean-Baptiste Kempf
Browse files

macosx: Cache video media lists and update according to model notifications


Signed-off-by: default avatarClaudio Cambra <developer@claudiocambra.com>
parent 6752d970
No related branches found
No related tags found
Loading
Pipeline #277209 passed with stages
in 32 minutes and 14 seconds
......@@ -36,6 +36,8 @@ NS_ASSUME_NONNULL_BEGIN
@property (readwrite, assign) VLCLibraryModel *libraryModel;
@property (readwrite, assign) NSCollectionView *libraryMediaCollectionView;
- (void)reloadData;
@end
NS_ASSUME_NONNULL_END
......@@ -30,8 +30,51 @@
#import "main/CompatibilityFixes.h"
#import "extensions/NSString+Helpers.h"
@interface VLCLibraryVideoDataSource () <NSCollectionViewDelegate, NSCollectionViewDataSource>
{
NSArray *_recentsArray;
NSArray *_libraryArray;
}
@end
@implementation VLCLibraryVideoDataSource
- (instancetype)init
{
self = [super init];
if(self) {
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
[notificationCenter addObserver:self
selector:@selector(libraryModelUpdated:)
name:VLCLibraryModelVideoMediaListUpdated
object:nil];
[notificationCenter addObserver:self
selector:@selector(libraryModelUpdated:)
name:VLCLibraryModelRecentMediaListUpdated
object:nil];
}
return self;
}
- (void)libraryModelUpdated:(NSNotification *)aNotification
{
[self reloadData];
}
- (void)reloadData
{
if(!_libraryModel) {
return;
}
dispatch_async(dispatch_get_main_queue(), ^{
_recentsArray = [_libraryModel listOfRecentMedia];
_libraryArray = [_libraryModel listOfVideoMedia];
[_libraryMediaCollectionView reloadData];
});
}
- (NSInteger)collectionView:(NSCollectionView *)collectionView
numberOfItemsInSection:(NSInteger)section
{
......@@ -58,19 +101,16 @@
{
VLCLibraryCollectionViewItem *viewItem = [collectionView makeItemWithIdentifier:VLCLibraryCellIdentifier forIndexPath:indexPath];
NSArray *mediaArray;
switch(indexPath.section) {
case VLCVideoLibraryRecentsSection:
mediaArray = [_libraryModel listOfRecentMedia];
viewItem.representedItem = _recentsArray[indexPath.item];
break;
case VLCVideoLibraryLibrarySection:
default:
mediaArray = [_libraryModel listOfVideoMedia];
viewItem.representedItem = _libraryArray[indexPath.item];
break;
}
viewItem.representedItem = mediaArray[indexPath.item];
return viewItem;
}
......@@ -108,13 +148,11 @@ canDragItemsAtIndexPaths:(NSSet<NSIndexPath *> *)indexPaths
writeItemsAtIndexPaths:(NSSet<NSIndexPath *> *)indexPaths
toPasteboard:(NSPasteboard *)pasteboard
{
NSArray *mediaArray = [_libraryModel listOfVideoMedia];
NSUInteger numberOfIndexPaths = indexPaths.count;
NSMutableArray *encodedLibraryItemsArray = [NSMutableArray arrayWithCapacity:numberOfIndexPaths];
NSMutableArray *filePathsArray = [NSMutableArray arrayWithCapacity:numberOfIndexPaths];
for (NSIndexPath *indexPath in indexPaths) {
VLCMediaLibraryMediaItem *mediaItem = mediaArray[indexPath.item];
VLCMediaLibraryMediaItem *mediaItem = _libraryArray[indexPath.item];
[encodedLibraryItemsArray addObject:mediaItem];
VLCMediaLibraryFile *file = mediaItem.files.firstObject;
......
......@@ -299,6 +299,7 @@ static void addShadow(NSImageView *__unsafe_unretained imageView)
forSupplementaryViewOfKind:NSCollectionElementKindSectionHeader
withIdentifier:VLCLibrarySupplementaryElementViewIdentifier];
[(NSCollectionViewFlowLayout *)_videoLibraryCollectionView.collectionViewLayout setHeaderReferenceSize:[VLCLibraryCollectionViewSupplementaryElementView defaultHeaderSize]];
[_libraryVideoDataSource reloadData];
_libraryAudioDataSource = [[VLCLibraryAudioDataSource alloc] init];
_libraryAudioDataSource.libraryModel = mainInstance.libraryController.libraryModel;
......@@ -605,7 +606,7 @@ static void addShadow(NSImageView *__unsafe_unretained imageView)
[_libraryTargetView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[_videoLibraryView(>=572.)]|" options:0 metrics:0 views:dict]];
[_libraryTargetView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[_videoLibraryView(>=444.)]|" options:0 metrics:0 views:dict]];
[_videoLibraryCollectionView reloadData];
[_libraryVideoDataSource reloadData];
}
_librarySortButton.hidden = NO;
......@@ -965,7 +966,7 @@ static void addShadow(NSImageView *__unsafe_unretained imageView)
- (void)updateLibraryRepresentation:(NSNotification *)aNotification
{
if (_videoLibraryView.superview != nil) {
[_videoLibraryCollectionView reloadData];
[_libraryVideoDataSource reloadData];
} else if (_audioLibraryView.superview != nil) {
[_libraryAudioDataSource reloadAppearance];
}
......
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