[vlc-commits] macosx/library collection view item: refactor for increased readibility
Felix Paul Kühne
git at videolan.org
Thu May 30 21:12:34 CEST 2019
vlc | branch: master | Felix Paul Kühne <felix at feepk.net> | Thu May 30 20:25:50 2019 +0200| [5337f1bc805d97ab299578cfc6e56edb9678f611] | committer: Felix Paul Kühne
macosx/library collection view item: refactor for increased readibility
No functional changes
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=5337f1bc805d97ab299578cfc6e56edb9678f611
---
.../macosx/library/VLCLibraryCollectionViewItem.m | 39 +++++++++++++---------
modules/gui/macosx/library/VLCLibraryDataTypes.h | 1 +
modules/gui/macosx/library/VLCLibraryDataTypes.m | 1 +
3 files changed, 26 insertions(+), 15 deletions(-)
diff --git a/modules/gui/macosx/library/VLCLibraryCollectionViewItem.m b/modules/gui/macosx/library/VLCLibraryCollectionViewItem.m
index d06c0728b2..a4b1aa2523 100644
--- a/modules/gui/macosx/library/VLCLibraryCollectionViewItem.m
+++ b/modules/gui/macosx/library/VLCLibraryCollectionViewItem.m
@@ -142,12 +142,31 @@ const CGFloat VLCLibraryCollectionViewItemMaximumDisplayedProgress = 0.95;
- (void)updateRepresentation
{
if (_representedMediaItem == nil) {
+ NSAssert(1, @"no media item assigned for collection view item", nil);
return;
}
_mediaTitleTextField.stringValue = _representedMediaItem.title;
- _durationTextField.stringValue = [NSString stringWithTime:_representedMediaItem.duration / 1000];
+ _durationTextField.stringValue = [NSString stringWithTime:_representedMediaItem.duration / VLCMediaLibraryMediaItemDurationDenominator];
+ _mediaImageView.image = [self imageForMedia];
+
+ VLCMediaLibraryTrack *videoTrack = _representedMediaItem.firstVideoTrack;
+ [self showVideoSizeIfNeededForWidth:videoTrack.videoWidth andHeight:videoTrack.videoHeight];
+
+ CGFloat position = _representedMediaItem.lastPlaybackPosition;
+ if (position > VLCLibraryCollectionViewItemMinimalDisplayedProgress && position < VLCLibraryCollectionViewItemMaximumDisplayedProgress) {
+ _progressIndicator.progress = position;
+ _progressIndicator.hidden = NO;
+ }
+
+ if (_representedMediaItem.playCount == 0) {
+ _unplayedIndicatorTextField.hidden = NO;
+ }
+}
+
+- (NSImage *)imageForMedia
+{
NSImage *image;
if (_representedMediaItem.artworkGenerated) {
image = [[NSImage alloc] initWithContentsOfURL:[NSURL URLWithString:_representedMediaItem.artworkMRL]];
@@ -159,11 +178,11 @@ const CGFloat VLCLibraryCollectionViewItemMaximumDisplayedProgress = 0.95;
if (!image) {
image = [NSImage imageNamed: @"noart.png"];
}
- _mediaImageView.image = image;
+ return image;
+}
- VLCMediaLibraryTrack *videoTrack = _representedMediaItem.firstVideoTrack;
- CGFloat width = videoTrack.videoWidth;
- CGFloat height = videoTrack.videoHeight;
+- (void)showVideoSizeIfNeededForWidth:(CGFloat)width andHeight:(CGFloat)height
+{
if (width >= VLCMediaLibrary4KWidth || height >= VLCMediaLibrary4KHeight) {
_annotationTextField.stringValue = @" 4K ";
_annotationTextField.hidden = NO;
@@ -171,16 +190,6 @@ const CGFloat VLCLibraryCollectionViewItemMaximumDisplayedProgress = 0.95;
_annotationTextField.stringValue = @" HD ";
_annotationTextField.hidden = NO;
}
-
- CGFloat position = _representedMediaItem.lastPlaybackPosition;
- if (position > VLCLibraryCollectionViewItemMinimalDisplayedProgress && position < VLCLibraryCollectionViewItemMaximumDisplayedProgress) {
- _progressIndicator.progress = position;
- _progressIndicator.hidden = NO;
- }
-
- if (_representedMediaItem.playCount == 0) {
- _unplayedIndicatorTextField.hidden = NO;
- }
}
#pragma mark - actions
diff --git a/modules/gui/macosx/library/VLCLibraryDataTypes.h b/modules/gui/macosx/library/VLCLibraryDataTypes.h
index 8fb75bc8a8..5d50c69e5b 100644
--- a/modules/gui/macosx/library/VLCLibraryDataTypes.h
+++ b/modules/gui/macosx/library/VLCLibraryDataTypes.h
@@ -31,6 +31,7 @@ extern const CGFloat VLCMediaLibrary4KWidth;
extern const CGFloat VLCMediaLibrary4KHeight;
extern const CGFloat VLCMediaLibrary720pWidth;
extern const CGFloat VLCMediaLibrary720pHeight;
+extern const long long int VLCMediaLibraryMediaItemDurationDenominator;
@interface VLCMediaLibraryFile : NSObject
diff --git a/modules/gui/macosx/library/VLCLibraryDataTypes.m b/modules/gui/macosx/library/VLCLibraryDataTypes.m
index af99634fd2..76ec78fd4e 100644
--- a/modules/gui/macosx/library/VLCLibraryDataTypes.m
+++ b/modules/gui/macosx/library/VLCLibraryDataTypes.m
@@ -31,6 +31,7 @@ const CGFloat VLCMediaLibrary4KWidth = 3840.;
const CGFloat VLCMediaLibrary4KHeight = 2160.;
const CGFloat VLCMediaLibrary720pWidth = 1280.;
const CGFloat VLCMediaLibrary720pHeight = 720.;
+const long long int VLCMediaLibraryMediaItemDurationDenominator = 1000;
@implementation VLCMediaLibraryFile
More information about the vlc-commits
mailing list