Selaa lähdekoodia

VLCPlaylistCollectionViewCell: Add VLCMLMedia

Soomin Lee 7 vuotta sitten
vanhempi
commit
76db6a7497

+ 2 - 0
Sources/VLCPlaylistCollectionViewCell.h

@@ -15,6 +15,7 @@
 
 #import <UIKit/UIKit.h>
 #import "VLCLinearProgressIndicator.h"
+#import <VLCMediaLibraryKit/VLCMLMedia.h>
 
 @interface VLCPlaylistCollectionViewCell : UICollectionViewCell
 
@@ -28,6 +29,7 @@
 @property (nonatomic, strong) IBOutlet UILabel *metaDataLabel;
 
 @property (nonatomic, retain) NSManagedObject *mediaObject;
+@property (nonatomic, retain) VLCMLMedia *media;
 
 @property (nonatomic, weak) UICollectionView *collectionView;
 @property (readonly) BOOL showsMetaData;

+ 19 - 0
Sources/VLCPlaylistCollectionViewCell.m

@@ -17,6 +17,8 @@
 #import "VLCThumbnailsCache.h"
 #import "NSString+SupportedMedia.h"
 
+#import <VLCMediaLibraryKit/VLCMLFile.h>
+
 @interface VLCPlaylistCollectionViewCell ()
 {
     UIImage *_checkboxEmptyImage;
@@ -198,6 +200,22 @@
     [self _updatedDisplayedInformationForKeyPath:nil];
 }
 
+- (void)setMedia:(VLCMLMedia *)media
+{
+    if (_media != media) {
+        _media = media;
+    }
+    [self _updateDisplayedInformations];
+}
+
+- (void)_updateDisplayedInformations
+{
+    _titleLabel.text = _media.title;
+    _subtitleLabel.text = [NSString stringWithFormat:@"%@ — %@", [VLCTime timeWithNumber:[NSNumber numberWithLongLong:_media.duration]],
+                                                                  [NSByteCountFormatter stringFromByteCount:[_media.mainFile size] countStyle:NSByteCountFormatterCountStyleFile]];
+
+}
+
 - (void)_updatedDisplayedInformationForKeyPath:(NSString *)keyPath
 {
     self.thumbnailView.contentMode = UIViewContentModeScaleAspectFill;
@@ -526,6 +544,7 @@
 - (void)prepareForReuse
 {
     [super prepareForReuse];
+    self.media = nil;
     self.mediaObject = nil;
     self.thumbnailView.image = nil;
     self.titleLabel.text = @"";