[vlc-commits] [Git][videolan/vlc][master] 5 commits: macosx: Extract anyRecents bool to separate method
Jean-Baptiste Kempf (@jbk)
gitlab at videolan.org
Fri Aug 4 19:01:38 UTC 2023
Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC
Commits:
b0475cf5 by Claudio Cambra at 2023-08-04T18:43:24+00:00
macosx: Extract anyRecents bool to separate method
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
b6488941 by Claudio Cambra at 2023-08-04T18:43:24+00:00
macosx: Extract container view addition to stackview to separate method
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
40cec153 by Claudio Cambra at 2023-08-04T18:43:24+00:00
macosx: Separate container view constraint setup from stack view addition
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
ada95fe3 by Claudio Cambra at 2023-08-04T18:43:24+00:00
macosx: Insert or remove recents section container from video library collections stack view depending on library model notifications
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
041a1f37 by Claudio Cambra at 2023-08-04T18:43:24+00:00
macosx: Fix setter for videoGroup in VLCLibraryVideoCollectionViewContainerView
Signed-off-by: Claudio Cambra <developer at claudiocambra.com>
- - - - -
2 changed files:
- modules/gui/macosx/library/video-library/VLCLibraryVideoCollectionViewContainerView.m
- modules/gui/macosx/library/video-library/VLCLibraryVideoCollectionViewsStackViewController.m
Changes:
=====================================
modules/gui/macosx/library/video-library/VLCLibraryVideoCollectionViewContainerView.m
=====================================
@@ -153,6 +153,7 @@
- (void)setGroupDescriptor:(VLCLibraryVideoCollectionViewGroupDescriptor *)groupDescriptor
{
_groupDescriptor = groupDescriptor;
+ _videoGroup = groupDescriptor.group;
_dataSource.groupDescriptor = groupDescriptor;
_collectionViewLayout.scrollDirection = _groupDescriptor.isHorizontalBarCollectionView ?
@@ -168,7 +169,7 @@
return;
}
- VLCLibraryVideoCollectionViewGroupDescriptor *descriptor = [[VLCLibraryVideoCollectionViewGroupDescriptor alloc] initWithVLCVideoLibraryGroup:group];
+ VLCLibraryVideoCollectionViewGroupDescriptor * const descriptor = [[VLCLibraryVideoCollectionViewGroupDescriptor alloc] initWithVLCVideoLibraryGroup:group];
[self setGroupDescriptor:descriptor];
}
=====================================
modules/gui/macosx/library/video-library/VLCLibraryVideoCollectionViewsStackViewController.m
=====================================
@@ -56,14 +56,60 @@
- (void)setup
{
+ NSNotificationCenter * const notificationCenter = NSNotificationCenter.defaultCenter;
+ [notificationCenter addObserver:self
+ selector:@selector(recentsChanged:)
+ name:VLCLibraryModelRecentsMediaListReset
+ object:nil];
+ [notificationCenter addObserver:self
+ selector:@selector(recentsChanged:)
+ name:VLCLibraryModelRecentsMediaItemDeleted
+ object:nil];
+
[self generateCollectionViewContainers];
}
+- (BOOL)recentMediaPresent
+{
+ VLCLibraryModel * const model = VLCMain.sharedInstance.libraryController.libraryModel;
+ return model.numberOfRecentMedia > 0;
+}
+
+- (void)recentsChanged:(NSNotification *)notification
+{
+ const BOOL shouldShowRecentsContainer = [self recentMediaPresent];
+ const NSUInteger recentsContainerIndex = [_collectionViewContainers indexOfObjectPassingTest:^BOOL(VLCLibraryVideoCollectionViewContainerView * const container, const NSUInteger idx, BOOL * const stop) {
+ return container.videoGroup == VLCLibraryVideoRecentsGroup;
+ }];
+ const BOOL recentsContainerPresent = recentsContainerIndex != NSNotFound;
+
+ if (recentsContainerPresent == shouldShowRecentsContainer) {
+ return;
+ }
+
+ NSMutableArray * const mutableContainers = _collectionViewContainers.mutableCopy;
+
+ if (shouldShowRecentsContainer) {
+ VLCLibraryVideoCollectionViewContainerView * const containerView = [[VLCLibraryVideoCollectionViewContainerView alloc] init];
+ containerView.videoGroup = VLCLibraryVideoRecentsGroup;
+ [mutableContainers insertObject:containerView atIndex:0];
+
+ [_collectionsStackView insertArrangedSubview:containerView atIndex:0];
+ [self setupContainerView:containerView forStackView:_collectionsStackView];
+ } else {
+ [mutableContainers removeObjectAtIndex:recentsContainerIndex];
+ VLCLibraryVideoCollectionViewContainerView * const existingContainer = [_collectionViewContainers objectAtIndex:recentsContainerIndex];
+ [_collectionsStackView removeConstraints:existingContainer.constraintsWithSuperview];
+ [_collectionsStackView removeArrangedSubview:existingContainer];
+ }
+
+ _collectionViewContainers = mutableContainers.copy;
+}
+
- (void)generateCollectionViewContainers
{
NSMutableArray * const collectionViewContainers = [[NSMutableArray alloc] init];
- VLCLibraryModel * const model = VLCMain.sharedInstance.libraryController.libraryModel;
- const BOOL anyRecents = model.numberOfRecentMedia > 0;
+ const BOOL anyRecents = [self recentMediaPresent];
NSUInteger i = anyRecents ? VLCLibraryVideoRecentsGroup : VLCLibraryVideoRecentsGroup + 1;
for (; i < VLCLibraryVideoSentinel; ++i) {
@@ -84,12 +130,53 @@
});
}
+- (void)setupContainerView:(VLCLibraryVideoCollectionViewContainerView *)containerView
+ forStackView:(NSStackView *)stackView
+{
+ if (containerView == nil || stackView == nil) {
+ return;
+ }
+
+ containerView.translatesAutoresizingMaskIntoConstraints = NO;
+ NSArray<NSLayoutConstraint*> * const constraintsWithSuperview = @[
+ [NSLayoutConstraint constraintWithItem:containerView
+ attribute:NSLayoutAttributeLeft
+ relatedBy:NSLayoutRelationEqual
+ toItem:stackView
+ attribute:NSLayoutAttributeLeft
+ multiplier:1
+ constant:0
+ ],
+ [NSLayoutConstraint constraintWithItem:containerView
+ attribute:NSLayoutAttributeRight
+ relatedBy:NSLayoutRelationEqual
+ toItem:stackView
+ attribute:NSLayoutAttributeRight
+ multiplier:1
+ constant:0
+ ],
+ ];
+ containerView.constraintsWithSuperview = constraintsWithSuperview;
+ [stackView addConstraints:constraintsWithSuperview];
+}
+
+- (void)addContainerView:(VLCLibraryVideoCollectionViewContainerView *)containerView
+ toStackView:(NSStackView *)stackView
+{
+ if (containerView == nil || stackView == nil) {
+ return;
+ }
+
+ [stackView addArrangedSubview:containerView];
+ [self setupContainerView:containerView forStackView:stackView];
+}
+
- (void)setCollectionsStackView:(NSStackView *)collectionsStackView
{
NSParameterAssert(collectionsStackView);
if (_collectionsStackView) {
- for (VLCLibraryVideoCollectionViewContainerView *containerView in _collectionViewContainers) {
+ for (VLCLibraryVideoCollectionViewContainerView * const containerView in _collectionViewContainers) {
if (containerView.constraintsWithSuperview.count > 0) {
[_collectionsStackView removeConstraints:containerView.constraintsWithSuperview];
}
@@ -105,29 +192,8 @@
forOrientation:NSLayoutConstraintOrientationVertical];
- for (VLCLibraryVideoCollectionViewContainerView *containerView in _collectionViewContainers) {
- containerView.translatesAutoresizingMaskIntoConstraints = NO;
- NSArray<NSLayoutConstraint*> *constraintsWithSuperview = @[
- [NSLayoutConstraint constraintWithItem:containerView
- attribute:NSLayoutAttributeLeft
- relatedBy:NSLayoutRelationEqual
- toItem:_collectionsStackView
- attribute:NSLayoutAttributeLeft
- multiplier:1
- constant:0
- ],
- [NSLayoutConstraint constraintWithItem:containerView
- attribute:NSLayoutAttributeRight
- relatedBy:NSLayoutRelationEqual
- toItem:_collectionsStackView
- attribute:NSLayoutAttributeRight
- multiplier:1
- constant:0
- ],
- ];
- containerView.constraintsWithSuperview = constraintsWithSuperview;
- [_collectionsStackView addConstraints:constraintsWithSuperview];
- [_collectionsStackView addArrangedSubview:containerView];
+ for (VLCLibraryVideoCollectionViewContainerView * const containerView in _collectionViewContainers) {
+ [self addContainerView:containerView toStackView:_collectionsStackView];
}
}
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/7f92d2f36ea41c7d515a2a6d95ce8c21463ec039...041a1f37f89cd89c2d2ff373febb9866943d42f6
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/7f92d2f36ea41c7d515a2a6d95ce8c21463ec039...041a1f37f89cd89c2d2ff373febb9866943d42f6
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list