[vlc-commits] [Git][videolan/vlc][master] macosx: Unify the video library view into one collection view with sections

Rémi Denis-Courmont (@Courmisch) gitlab at videolan.org
Tue Aug 2 16:47:46 UTC 2022



Rémi Denis-Courmont pushed to branch master at VideoLAN / VLC


Commits:
db807b51 by Claudio Cambra at 2022-08-02T16:30:16+00:00
macosx: Unify the video library view into one collection view with sections

Signed-off-by: Claudio Cambra <claudio.cambra at gmail.com>

- - - - -


5 changed files:

- modules/gui/macosx/UI/VLCLibraryWindow.xib
- modules/gui/macosx/library/VLCLibraryVideoDataSource.h
- modules/gui/macosx/library/VLCLibraryVideoDataSource.m
- modules/gui/macosx/library/VLCLibraryWindow.h
- modules/gui/macosx/library/VLCLibraryWindow.m


Changes:

=====================================
modules/gui/macosx/UI/VLCLibraryWindow.xib
=====================================
@@ -699,7 +699,6 @@
                 <outlet property="playlistDragDropView" destination="VFI-oW-dMZ" id="gVc-mu-f8T"/>
                 <outlet property="playlistTableView" destination="Fr1-af-8gb" id="yaB-Ab-jrx"/>
                 <outlet property="playlistView" destination="dus-WQ-AmE" id="fTF-HP-Chb"/>
-                <outlet property="recentVideoLibraryCollectionView" destination="hnE-Hj-MZo" id="Fko-5v-1bC"/>
                 <outlet property="repeatPlaylistButton" destination="8zF-Wo-H79" id="6bH-HF-arx"/>
                 <outlet property="segmentedTitleControl" destination="W1M-0o-qYG" id="Gw1-T6-78k"/>
                 <outlet property="segmentedTitleControlToolbarItem" destination="KnW-Lr-R1d" id="Wg1-Y2-34a"/>
@@ -707,7 +706,8 @@
                 <outlet property="upNextLabel" destination="TET-5r-zHx" id="3oI-LK-NDP"/>
                 <outlet property="upNextSeparator" destination="qmL-Ar-cj1" id="GRX-ZE-2UG"/>
                 <outlet property="videoLibraryCollectionView" destination="B8x-e8-7zp" id="u1I-gn-IU1"/>
-                <outlet property="videoLibraryStackView" destination="vak-Gp-ljo" id="ulu-pc-ctF"/>
+                <outlet property="videoLibraryView" destination="vak-Gp-ljo" id="ulu-pc-ctF"/>
+                <outlet property="videoLibraryScrollView" destination="nXS-11-7iK" id="v1d-30-scr"/>
             </connections>
             <point key="canvasLocation" x="-609" y="325"/>
         </window>
@@ -733,48 +733,18 @@
                 <outlet property="volumeUpButton" destination="75c-FF-mgb" id="xRz-F4-n0Z"/>
             </connections>
         </customObject>
-        <stackView distribution="fill" orientation="vertical" alignment="leading" spacing="0.0" horizontalStackHuggingPriority="249.99998474121094" verticalStackHuggingPriority="249.99998474121094" detachesHiddenViews="YES" id="vak-Gp-ljo">
-            <rect key="frame" x="0.0" y="0.0" width="242" height="808"/>
+        <customView id="vak-Gp-ljo">
+            <rect key="frame" x="0.0" y="0.0" width="869" height="808"/>
             <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
             <subviews>
-                <scrollView wantsLayer="YES" borderType="none" autohidesScrollers="YES" horizontalLineScroll="10" horizontalPageScroll="10" verticalLineScroll="10" verticalPageScroll="10" hasVerticalScroller="NO" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="HmU-mL-Tjk">
-                    <rect key="frame" x="0.0" y="498" width="242" height="310"/>
-                    <clipView key="contentView" copiesOnScroll="NO" id="J5s-sy-il6">
-                        <rect key="frame" x="0.0" y="0.0" width="242" height="310"/>
-                        <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
-                        <subviews>
-                            <collectionView selectable="YES" id="hnE-Hj-MZo">
-                                <rect key="frame" x="0.0" y="0.0" width="242" height="310"/>
-                                <autoresizingMask key="autoresizingMask" heightSizable="YES"/>
-                                <collectionViewFlowLayout key="collectionViewLayout" minimumInteritemSpacing="20" minimumLineSpacing="20" scrollDirection="horizontal" id="N2a-bI-WQc">
-                                    <size key="itemSize" width="354" height="270"/>
-                                    <edgeInsets key="sectionInset" left="20" right="20" top="20" bottom="20"/>
-                                </collectionViewFlowLayout>
-                                <color key="primaryBackgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
-                                <color key="secondaryBackgroundColor" name="controlAlternatingRowColor" catalog="System" colorSpace="catalog"/>
-                            </collectionView>
-                        </subviews>
-                    </clipView>
-                    <constraints>
-                        <constraint firstAttribute="height" constant="310" id="Htb-Ql-chZ"/>
-                    </constraints>
-                    <scroller key="horizontalScroller" hidden="YES" wantsLayer="YES" verticalHuggingPriority="750" horizontal="YES" id="f2z-AL-CFF">
-                        <rect key="frame" x="-100" y="-100" width="233" height="15"/>
-                        <autoresizingMask key="autoresizingMask"/>
-                    </scroller>
-                    <scroller key="verticalScroller" hidden="YES" wantsLayer="YES" verticalHuggingPriority="750" horizontal="NO" id="psR-Xx-0YH">
-                        <rect key="frame" x="-100" y="-100" width="16" height="218"/>
-                        <autoresizingMask key="autoresizingMask"/>
-                    </scroller>
-                </scrollView>
                 <scrollView wantsLayer="YES" borderType="none" autohidesScrollers="YES" horizontalLineScroll="10" horizontalPageScroll="10" verticalLineScroll="10" verticalPageScroll="10" hasHorizontalScroller="NO" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="nXS-11-7iK">
-                    <rect key="frame" x="0.0" y="0.0" width="242" height="498"/>
+                    <rect key="frame" x="0.0" y="0.0" width="869" height="808"/>
                     <clipView key="contentView" copiesOnScroll="NO" id="OKa-dt-1yY">
-                        <rect key="frame" x="0.0" y="0.0" width="242" height="498"/>
+                        <rect key="frame" x="0.0" y="0.0" width="869" height="808"/>
                         <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                         <subviews>
                             <collectionView selectable="YES" id="B8x-e8-7zp">
-                                <rect key="frame" x="0.0" y="0.0" width="242" height="498"/>
+                                <rect key="frame" x="0.0" y="0.0" width="869" height="808"/>
                                 <autoresizingMask key="autoresizingMask" widthSizable="YES"/>
                                 <collectionViewFlowLayout key="collectionViewLayout" minimumInteritemSpacing="20" minimumLineSpacing="20" id="Rag-cM-k1g">
                                     <size key="itemSize" width="256" height="214"/>
@@ -796,24 +766,13 @@
                 </scrollView>
             </subviews>
             <constraints>
-                <constraint firstItem="HmU-mL-Tjk" firstAttribute="leading" secondItem="vak-Gp-ljo" secondAttribute="leading" id="5co-en-4Uf"/>
-                <constraint firstAttribute="trailing" secondItem="HmU-mL-Tjk" secondAttribute="trailing" id="9Wn-DC-CFC"/>
+                <constraint firstItem="nXS-11-7iK" firstAttribute="top" secondItem="vak-Gp-ljo" secondAttribute="top" id="KNa-C4-CIY"/>
                 <constraint firstItem="nXS-11-7iK" firstAttribute="leading" secondItem="vak-Gp-ljo" secondAttribute="leading" id="LP8-Hf-WCx"/>
-                <constraint firstItem="HmU-mL-Tjk" firstAttribute="top" secondItem="vak-Gp-ljo" secondAttribute="top" id="XE0-gE-X8v"/>
                 <constraint firstAttribute="trailing" secondItem="nXS-11-7iK" secondAttribute="trailing" id="kmc-KU-iRY"/>
                 <constraint firstAttribute="bottom" secondItem="nXS-11-7iK" secondAttribute="bottom" id="tpH-Q7-TH4"/>
-                <constraint firstItem="nXS-11-7iK" firstAttribute="top" secondItem="HmU-mL-Tjk" secondAttribute="bottom" id="w6G-g6-ZtO"/>
             </constraints>
-            <visibilityPriorities>
-                <integer value="1000"/>
-                <integer value="1000"/>
-            </visibilityPriorities>
-            <customSpacing>
-                <real value="3.4028234663852886e+38"/>
-                <real value="3.4028234663852886e+38"/>
-            </customSpacing>
-            <point key="canvasLocation" x="585" y="10"/>
-        </stackView>
+            <point key="canvasLocation" x="748.5" y="10"/>
+        </customView>
         <customView id="eHd-Q9-F8D">
             <rect key="frame" x="0.0" y="0.0" width="528" height="411"/>
             <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>


=====================================
modules/gui/macosx/library/VLCLibraryVideoDataSource.h
=====================================
@@ -22,6 +22,11 @@
 
 #import <Cocoa/Cocoa.h>
 
+typedef NS_ENUM(NSUInteger, VLCVideoLibrarySection) {
+    VLCVideoLibraryRecentsSection = 0,
+    VLCVideoLibraryLibrarySection,
+};
+
 NS_ASSUME_NONNULL_BEGIN
 
 @class VLCLibraryModel;
@@ -29,7 +34,6 @@ NS_ASSUME_NONNULL_BEGIN
 @interface VLCLibraryVideoDataSource : NSObject <NSCollectionViewDataSource, NSCollectionViewDelegate>
 
 @property (readwrite, assign) VLCLibraryModel *libraryModel;
- at property (readwrite, assign) NSCollectionView *recentMediaCollectionView;
 @property (readwrite, assign) NSCollectionView *libraryMediaCollectionView;
 
 @end


=====================================
modules/gui/macosx/library/VLCLibraryVideoDataSource.m
=====================================
@@ -38,16 +38,19 @@
     if (!_libraryModel) {
         return 0;
     }
-    if (collectionView == self.recentMediaCollectionView) {
-        return [_libraryModel numberOfRecentMedia];
-    }
 
-    return [_libraryModel numberOfVideoMedia];
+    switch(section) {
+        case VLCVideoLibraryRecentsSection:
+            return [_libraryModel numberOfRecentMedia];
+        case VLCVideoLibraryLibrarySection:
+        default:
+            return [_libraryModel numberOfVideoMedia];
+    }
 }
 
 - (NSInteger)numberOfSectionsInCollectionView:(NSCollectionView *)collectionView
 {
-    return 1;
+    return 2;
 }
 
 - (NSCollectionViewItem *)collectionView:(NSCollectionView *)collectionView
@@ -56,10 +59,14 @@
     VLCLibraryCollectionViewItem *viewItem = [collectionView makeItemWithIdentifier:VLCLibraryCellIdentifier forIndexPath:indexPath];
 
     NSArray *mediaArray;
-    if (collectionView == self.recentMediaCollectionView) {
-        mediaArray = [_libraryModel listOfRecentMedia];
-    } else {
-        mediaArray = [_libraryModel listOfVideoMedia];
+    switch(indexPath.section) {
+        case VLCVideoLibraryRecentsSection:
+            mediaArray = [_libraryModel listOfRecentMedia];
+            break;
+        case VLCVideoLibraryLibrarySection:
+        default:
+            mediaArray = [_libraryModel listOfVideoMedia];
+            break;
     }
 
     viewItem.representedItem = mediaArray[indexPath.item];
@@ -74,11 +81,17 @@ viewForSupplementaryElementOfKind:(NSCollectionViewSupplementaryElementKind)kind
     VLCLibraryCollectionViewSupplementaryElementView *view = [collectionView makeSupplementaryViewOfKind:kind
                                                                                           withIdentifier:VLCLibrarySupplementaryElementViewIdentifier
                                                                                             forIndexPath:indexPath];
-    if (collectionView == self.recentMediaCollectionView) {
-        view.stringValue = _NS("Recent");
-    } else {
-        view.stringValue = _NS("Library");
+
+    switch(indexPath.section) {
+        case VLCVideoLibraryRecentsSection:
+            view.stringValue = _NS("Recent");
+            break;
+        case VLCVideoLibraryLibrarySection:
+        default:
+            view.stringValue = _NS("Library");
+            break;
     }
+
     return view;
 }
 
@@ -95,12 +108,7 @@ canDragItemsAtIndexPaths:(NSSet<NSIndexPath *> *)indexPaths
 writeItemsAtIndexPaths:(NSSet<NSIndexPath *> *)indexPaths
           toPasteboard:(NSPasteboard *)pasteboard
 {
-    NSArray *mediaArray;
-    if (collectionView == self.recentMediaCollectionView) {
-        mediaArray = [_libraryModel listOfRecentMedia];
-    } else {
-        mediaArray = [_libraryModel listOfVideoMedia];
-    }
+    NSArray *mediaArray = [_libraryModel listOfVideoMedia];
 
     NSUInteger numberOfIndexPaths = indexPaths.count;
     NSMutableArray *encodedLibraryItemsArray = [NSMutableArray arrayWithCapacity:numberOfIndexPaths];


=====================================
modules/gui/macosx/library/VLCLibraryWindow.h
=====================================
@@ -49,10 +49,10 @@ NS_ASSUME_NONNULL_BEGIN
 @property (readwrite, weak) IBOutlet NSToolbarItem *segmentedTitleControlToolbarItem;
 @property (readwrite, weak) IBOutlet NSSegmentedControl *gridVsListSegmentedControl;
 @property (readwrite, weak) IBOutlet NSSplitView *mainSplitView;
- at property (readwrite, weak) IBOutlet NSStackView *videoLibraryStackView;
+ at property (readwrite, weak) IBOutlet NSView *videoLibraryView;
+ at property (readwrite, weak) IBOutlet NSScrollView *videoLibraryScrollView;
 @property (readwrite, strong) IBOutlet NSView *playlistView;
 @property (readwrite, weak) IBOutlet NSCollectionView *videoLibraryCollectionView;
- at property (readwrite, weak) IBOutlet NSCollectionView *recentVideoLibraryCollectionView;
 @property (readwrite, weak) IBOutlet NSCollectionView *mediaSourceCollectionView;
 @property (readwrite, weak) IBOutlet NSView *audioLibraryView;
 @property (readwrite, weak) IBOutlet NSSplitView *audioLibrarySplitView;


=====================================
modules/gui/macosx/library/VLCLibraryWindow.m
=====================================
@@ -280,7 +280,6 @@ static void addShadow(NSImageView *__unsafe_unretained imageView)
 
     _libraryVideoDataSource = [[VLCLibraryVideoDataSource alloc] init];
     _libraryVideoDataSource.libraryModel = mainInstance.libraryController.libraryModel;
-    _libraryVideoDataSource.recentMediaCollectionView = _recentVideoLibraryCollectionView;
     _libraryVideoDataSource.libraryMediaCollectionView = _videoLibraryCollectionView;
     _videoLibraryCollectionView.dataSource = _libraryVideoDataSource;
     _videoLibraryCollectionView.delegate = _libraryVideoDataSource;
@@ -289,14 +288,6 @@ static void addShadow(NSImageView *__unsafe_unretained imageView)
                forSupplementaryViewOfKind:NSCollectionElementKindSectionHeader
                            withIdentifier:VLCLibrarySupplementaryElementViewIdentifier];
     [(NSCollectionViewFlowLayout *)_videoLibraryCollectionView.collectionViewLayout setHeaderReferenceSize:[VLCLibraryCollectionViewSupplementaryElementView defaultHeaderSize]];
-    _recentVideoLibraryCollectionView.dataSource = _libraryVideoDataSource;
-    _recentVideoLibraryCollectionView.delegate = _libraryVideoDataSource;
-    [_recentVideoLibraryCollectionView registerClass:[VLCLibraryCollectionViewItem class] forItemWithIdentifier:VLCLibraryCellIdentifier];
-    [_recentVideoLibraryCollectionView registerClass:[VLCLibraryCollectionViewSupplementaryElementView class]
-               forSupplementaryViewOfKind:NSCollectionElementKindSectionHeader
-                           withIdentifier:VLCLibrarySupplementaryElementViewIdentifier];
-    [(NSCollectionViewFlowLayout *)_recentVideoLibraryCollectionView.collectionViewLayout setHeaderReferenceSize:[VLCLibraryCollectionViewSupplementaryElementView defaultHeaderSize]];
-    [_recentVideoLibraryCollectionView setDraggingSourceOperationMask:NSDragOperationCopy forLocal:NO];
 
     _libraryAudioDataSource = [[VLCLibraryAudioDataSource alloc] init];
     _libraryAudioDataSource.libraryModel = mainInstance.libraryController.libraryModel;
@@ -348,6 +339,10 @@ static void addShadow(NSImageView *__unsafe_unretained imageView)
     const CGFloat scrollViewRightInset = 0.;
     const CGFloat scrollViewBottomInset = 16.;
     const CGFloat scrollViewLeftInset = 16.;
+    const NSEdgeInsets defaultInsets = NSEdgeInsetsMake(scrollViewTopInset,
+                                                        scrollViewLeftInset,
+                                                        scrollViewBottomInset,
+                                                        scrollViewRightInset);
     
     _audioCollectionViewScrollView.automaticallyAdjustsContentInsets = NO;
     _audioCollectionViewScrollView.contentInsets = NSEdgeInsetsMake(audioCollectionScrollViewTopInset,
@@ -355,11 +350,11 @@ static void addShadow(NSImageView *__unsafe_unretained imageView)
                                                                     scrollViewBottomInset,
                                                                     scrollViewRightInset);
     
+    _videoLibraryScrollView.automaticallyAdjustsContentInsets = NO;
+    _videoLibraryScrollView.contentInsets = defaultInsets;
+
     _mediaSourceCollectionViewScrollView.automaticallyAdjustsContentInsets = NO;
-    _mediaSourceCollectionViewScrollView.contentInsets = NSEdgeInsetsMake(scrollViewTopInset,
-                                                                          scrollViewLeftInset,
-                                                                          scrollViewBottomInset,
-                                                                          scrollViewRightInset);
+    _mediaSourceCollectionViewScrollView.contentInsets = defaultInsets;
 
     const CGFloat collectionItemSpacing = 20.;
     const NSEdgeInsets collectionViewSectionInset = NSEdgeInsetsMake(20., 20., 20., 20.);
@@ -370,6 +365,12 @@ static void addShadow(NSImageView *__unsafe_unretained imageView)
     audioLibraryCollectionViewLayout.minimumInteritemSpacing = collectionItemSpacing;
     audioLibraryCollectionViewLayout.sectionInset = collectionViewSectionInset;
 
+    NSCollectionViewFlowLayout *videoLibraryCollectionViewLayout = _videoLibraryCollectionView.collectionViewLayout;
+    videoLibraryCollectionViewLayout.itemSize = CGSizeMake(214., 260.);
+    videoLibraryCollectionViewLayout.minimumLineSpacing = collectionItemSpacing;
+    videoLibraryCollectionViewLayout.minimumInteritemSpacing = collectionItemSpacing;
+    videoLibraryCollectionViewLayout.sectionInset = collectionViewSectionInset;
+
     NSCollectionViewFlowLayout *mediaSourceCollectionViewLayout = _mediaSourceCollectionView.collectionViewLayout;
     mediaSourceCollectionViewLayout.itemSize = CGSizeMake(214., 246.);
     mediaSourceCollectionViewLayout.minimumLineSpacing = collectionItemSpacing;
@@ -544,15 +545,13 @@ static void addShadow(NSImageView *__unsafe_unretained imageView)
         _placeholderLabel.stringValue = _NS("Your favorite videos will appear here.\nGo to the Browse section to add videos you love.");
     }
     else {
-        _videoLibraryStackView.translatesAutoresizingMaskIntoConstraints = NO;
-        [_libraryTargetView addSubview:_videoLibraryStackView];
-        NSDictionary *dict = NSDictionaryOfVariableBindings(_videoLibraryStackView);
-        [_libraryTargetView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[_videoLibraryStackView(>=572.)]|" options:0 metrics:0 views:dict]];
-        [_libraryTargetView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[_videoLibraryStackView(>=444.)]|" options:0 metrics:0 views:dict]];
-        
+        _videoLibraryView.translatesAutoresizingMaskIntoConstraints = NO;
+        [_libraryTargetView addSubview:_videoLibraryView];
+        NSDictionary *dict = NSDictionaryOfVariableBindings(_videoLibraryView);
+        [_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];
-        [_recentVideoLibraryCollectionView reloadData];
     }
     
     _librarySortButton.hidden = NO;
@@ -618,8 +617,8 @@ static void addShadow(NSImageView *__unsafe_unretained imageView)
 
 - (void)showMediaSourceAppearance
 {
-    if (_videoLibraryStackView.superview != nil) {
-        [_videoLibraryStackView removeFromSuperview];
+    if (_videoLibraryView.superview != nil) {
+        [_videoLibraryView removeFromSuperview];
     }
     if (_audioLibraryView.superview != nil) {
         [_audioLibraryView removeFromSuperview];
@@ -810,7 +809,7 @@ static void addShadow(NSImageView *__unsafe_unretained imageView)
 - (void)enableVideoPlaybackAppearance
 {
     [_mediaSourceView removeFromSuperviewWithoutNeedingDisplay];
-    [_videoLibraryStackView removeFromSuperviewWithoutNeedingDisplay];
+    [_videoLibraryView removeFromSuperviewWithoutNeedingDisplay];
     [_audioLibraryView removeFromSuperviewWithoutNeedingDisplay];
 
     [self.videoView setHidden:NO];
@@ -868,9 +867,8 @@ static void addShadow(NSImageView *__unsafe_unretained imageView)
 #pragma mark - library representation and interaction
 - (void)updateLibraryRepresentation:(NSNotification *)aNotification
 {
-    if (_videoLibraryStackView.superview != nil) {
+    if (_videoLibraryView.superview != nil) {
         [_videoLibraryCollectionView reloadData];
-        [_recentVideoLibraryCollectionView reloadData];
     } else if (_audioLibraryView.superview != nil) {
         [_libraryAudioDataSource reloadAppearance];
     }



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/db807b51249b950813bb25b8f30d7ed153b194ff

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/db807b51249b950813bb25b8f30d7ed153b194ff
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