VLCPlaylistTableViewCell.m 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. /*****************************************************************************
  2. * VLCPlaylistTableViewCell.m
  3. * VLC for iOS
  4. *****************************************************************************
  5. * Copyright (c) 2013-2015 VideoLAN. All rights reserved.
  6. * $Id$
  7. *
  8. * Authors: Felix Paul Kühne <fkuehne # videolan.org>
  9. * Gleb Pinigin <gpinigin # gmail.com>
  10. * Carola Nitz <nitz.carola #googlemail.com>
  11. *
  12. * Refer to the COPYING file of the official project for license.
  13. *****************************************************************************/
  14. #import "VLCPlaylistTableViewCell.h"
  15. #import "VLCLinearProgressIndicator.h"
  16. #import "VLCThumbnailsCache.h"
  17. #import "NSString+SupportedMedia.h"
  18. #import <MediaLibraryKit/MLAlbum.h>
  19. @interface VLCPlaylistTableViewCell ()
  20. {
  21. UILongPressGestureRecognizer *_longPress;
  22. }
  23. @end
  24. @implementation VLCPlaylistTableViewCell
  25. - (void)dealloc
  26. {
  27. [self _removeObserver];
  28. }
  29. + (VLCPlaylistTableViewCell *)cellWithReuseIdentifier:(NSString *)ident
  30. {
  31. NSArray *nibContentArray;
  32. nibContentArray = [[NSBundle mainBundle] loadNibNamed:@"VLCPlaylistTableViewCell" owner:nil options:nil];
  33. NSAssert([nibContentArray count] == 1, @"meh");
  34. NSAssert([[nibContentArray lastObject] isKindOfClass:[VLCPlaylistTableViewCell class]], @"meh meh");
  35. VLCPlaylistTableViewCell *cell = (VLCPlaylistTableViewCell *)[nibContentArray lastObject];
  36. cell.multipleSelectionBackgroundView = [[UIView alloc] initWithFrame:cell.frame];
  37. cell.metaDataLabel.hidden = YES;
  38. return cell;
  39. }
  40. - (void)setNeedsDisplay
  41. {
  42. [self collapsWithAnimation:NO];
  43. [super setNeedsDisplay];
  44. }
  45. - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
  46. {
  47. [self _updatedDisplayedInformationForKeyPath:keyPath];
  48. }
  49. - (void)_removeObserver
  50. {
  51. if ([_mediaObject isKindOfClass:[MLLabel class]]) {
  52. [_mediaObject removeObserver:self forKeyPath:@"files"];
  53. [_mediaObject removeObserver:self forKeyPath:@"name"];
  54. } else if ([_mediaObject isKindOfClass:[MLShow class]])
  55. [_mediaObject removeObserver:self forKeyPath:@"episodes"];
  56. else if ([_mediaObject isKindOfClass:[MLShowEpisode class]]) {
  57. [_mediaObject removeObserver:self forKeyPath:@"name"];
  58. [_mediaObject removeObserver:self forKeyPath:@"files"];
  59. [_mediaObject removeObserver:self forKeyPath:@"artworkURL"];
  60. [_mediaObject removeObserver:self forKeyPath:@"unread"];
  61. } else if ([_mediaObject isKindOfClass:[MLAlbum class]]) {
  62. [_mediaObject removeObserver:self forKeyPath:@"name"];
  63. [_mediaObject removeObserver:self forKeyPath:@"tracks"];
  64. } else if ([_mediaObject isKindOfClass:[MLAlbumTrack class]]) {
  65. [_mediaObject addObserver:self forKeyPath:@"unread" options:0 context:nil];
  66. [_mediaObject removeObserver:self forKeyPath:@"artist"];
  67. [_mediaObject removeObserver:self forKeyPath:@"title"];
  68. [_mediaObject removeObserver:self forKeyPath:@"files"];
  69. MLFile *anyFileFromTrack = [(MLAlbumTrack *)_mediaObject files].anyObject;
  70. [anyFileFromTrack removeObserver:self forKeyPath:@"artworkURL"];
  71. } else if ([_mediaObject isKindOfClass:[MLFile class]]) {
  72. [_mediaObject removeObserver:self forKeyPath:@"computedThumbnail"];
  73. [_mediaObject removeObserver:self forKeyPath:@"lastPosition"];
  74. [_mediaObject removeObserver:self forKeyPath:@"duration"];
  75. [_mediaObject removeObserver:self forKeyPath:@"fileSizeInBytes"];
  76. [_mediaObject removeObserver:self forKeyPath:@"title"];
  77. [_mediaObject removeObserver:self forKeyPath:@"thumbnailTimeouted"];
  78. [_mediaObject removeObserver:self forKeyPath:@"unread"];
  79. [_mediaObject removeObserver:self forKeyPath:@"albumTrackNumber"];
  80. [_mediaObject removeObserver:self forKeyPath:@"album"];
  81. [_mediaObject removeObserver:self forKeyPath:@"artist"];
  82. [_mediaObject removeObserver:self forKeyPath:@"genre"];
  83. [[NSNotificationCenter defaultCenter] removeObserver:self];
  84. [(MLFile*)_mediaObject didHide];
  85. }
  86. }
  87. - (void)_addObserver
  88. {
  89. if ([_mediaObject isKindOfClass:[MLLabel class]]) {
  90. [_mediaObject addObserver:self forKeyPath:@"files" options:0 context:nil];
  91. [_mediaObject addObserver:self forKeyPath:@"name" options:0 context:nil];
  92. } else if ([_mediaObject isKindOfClass:[MLShow class]])
  93. [_mediaObject addObserver:self forKeyPath:@"episodes" options:0 context:nil];
  94. else if ([_mediaObject isKindOfClass:[MLShowEpisode class]]) {
  95. [_mediaObject addObserver:self forKeyPath:@"name" options:0 context:nil];
  96. [_mediaObject addObserver:self forKeyPath:@"files" options:0 context:nil];
  97. [_mediaObject addObserver:self forKeyPath:@"artworkURL" options:0 context:nil];
  98. [_mediaObject addObserver:self forKeyPath:@"unread" options:0 context:nil];
  99. } else if ([_mediaObject isKindOfClass:[MLAlbum class]]) {
  100. [_mediaObject addObserver:self forKeyPath:@"name" options:0 context:nil];
  101. [_mediaObject addObserver:self forKeyPath:@"tracks" options:0 context:nil];
  102. } else if ([_mediaObject isKindOfClass:[MLAlbumTrack class]]) {
  103. [_mediaObject addObserver:self forKeyPath:@"unread" options:0 context:nil];
  104. [_mediaObject addObserver:self forKeyPath:@"artist" options:0 context:nil];
  105. [_mediaObject addObserver:self forKeyPath:@"title" options:0 context:nil];
  106. [_mediaObject addObserver:self forKeyPath:@"files" options:0 context:nil];
  107. MLFile *anyFileFromTrack = [(MLAlbumTrack *)_mediaObject files].anyObject;
  108. [anyFileFromTrack addObserver:self forKeyPath:@"artworkURL" options:0 context:nil];
  109. } else if ([_mediaObject isKindOfClass:[MLFile class]]) {
  110. [_mediaObject addObserver:self forKeyPath:@"computedThumbnail" options:0 context:nil];
  111. [_mediaObject addObserver:self forKeyPath:@"lastPosition" options:0 context:nil];
  112. [_mediaObject addObserver:self forKeyPath:@"duration" options:0 context:nil];
  113. [_mediaObject addObserver:self forKeyPath:@"fileSizeInBytes" options:0 context:nil];
  114. [_mediaObject addObserver:self forKeyPath:@"title" options:0 context:nil];
  115. [_mediaObject addObserver:self forKeyPath:@"thumbnailTimeouted" options:0 context:nil];
  116. [_mediaObject addObserver:self forKeyPath:@"unread" options:0 context:nil];
  117. [_mediaObject addObserver:self forKeyPath:@"albumTrackNumber" options:0 context:nil];
  118. [_mediaObject addObserver:self forKeyPath:@"album" options:0 context:nil];
  119. [_mediaObject addObserver:self forKeyPath:@"artist" options:0 context:nil];
  120. [_mediaObject addObserver:self forKeyPath:@"genre" options:0 context:nil];
  121. [[NSNotificationCenter defaultCenter] addObserver:self
  122. selector:@selector(thumbnailWasUpdated:)
  123. name:MLFileThumbnailWasUpdated
  124. object:nil];
  125. [(MLFile*)_mediaObject willDisplay];
  126. }
  127. }
  128. - (void)setMediaObject:(MLFile *)mediaObject
  129. {
  130. if (_mediaObject != mediaObject) {
  131. [self _removeObserver];
  132. _mediaObject = mediaObject;
  133. // prevent the cell from recycling the current snap for random contents
  134. self.thumbnailView.image = nil;
  135. [self _addObserver];
  136. }
  137. [self collapsWithAnimation:NO];
  138. [self _updatedDisplayedInformationForKeyPath:nil];
  139. }
  140. - (void)setEditing:(BOOL)editing animated:(BOOL)animated
  141. {
  142. [super setEditing:editing animated:animated];
  143. [self _updatedDisplayedInformationForKeyPath:@"editing"];
  144. if (editing) {
  145. if (_longPress)
  146. [self removeGestureRecognizer:_longPress];
  147. } else {
  148. if (!_longPress)
  149. _longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longTouchGestureAction:)];
  150. [self addGestureRecognizer:_longPress];
  151. }
  152. }
  153. - (void)_updatedDisplayedInformationForKeyPath:(NSString *)keyPath
  154. {
  155. self.thumbnailView.contentMode = UIViewContentModeScaleAspectFill;
  156. if ([self.mediaObject isKindOfClass:[MLFile class]]) {
  157. [self _configureForMLFile:(MLFile *)self.mediaObject];
  158. } else if ([self.mediaObject isKindOfClass:[MLLabel class]]) {
  159. [self _configureForFolder:(MLLabel *)self.mediaObject];
  160. } else if ([self.mediaObject isKindOfClass:[MLAlbum class]]) {
  161. [self _configureForAlbum:(MLAlbum *)self.mediaObject];
  162. } else if ([self.mediaObject isKindOfClass:[MLAlbumTrack class]]) {
  163. [self _configureForAlbumTrack:(MLAlbumTrack *)self.mediaObject];
  164. if ([keyPath isEqualToString:@"computedThumbnail"] || !keyPath || (!self.thumbnailView.image && [keyPath isEqualToString:@"editing"])) {
  165. self.thumbnailView.image = [VLCThumbnailsCache thumbnailForManagedObject:self.mediaObject];
  166. }
  167. } else if ([self.mediaObject isKindOfClass:[MLShow class]]) {
  168. MLShow *mediaObject = (MLShow *)self.mediaObject;
  169. [self _configureForShow:mediaObject];
  170. if ([keyPath isEqualToString:@"computedThumbnail"] || [keyPath isEqualToString:@"episodes"] || !keyPath || (!self.thumbnailView.image && [keyPath isEqualToString:@"editing"])) {
  171. self.thumbnailView.image = [VLCThumbnailsCache thumbnailForManagedObject:mediaObject];
  172. }
  173. } else if ([self.mediaObject isKindOfClass:[MLShowEpisode class]]) {
  174. [self _configureForShowEpisode:(MLShowEpisode *)self.mediaObject];
  175. }
  176. if (![self.mediaObject isKindOfClass:[MLShow class]] && ([keyPath isEqualToString:@"computedThumbnail"] || !keyPath || (!self.thumbnailView.image && [keyPath isEqualToString:@"editing"]))) {
  177. self.thumbnailView.image = [VLCThumbnailsCache thumbnailForManagedObject:self.mediaObject];
  178. }
  179. [self setNeedsDisplay];
  180. }
  181. + (CGFloat)heightOfCell
  182. {
  183. return 90.;
  184. }
  185. #pragma mark - presentation
  186. - (void)_configureForShow:(MLShow *)show
  187. {
  188. self.titleLabel.text = show.name;
  189. NSUInteger count = show.episodes.count;
  190. NSString *string = @"";
  191. if (show.releaseYear)
  192. string = [NSString stringWithFormat:@"%@ — ", show.releaseYear];
  193. self.subtitleLabel.text = [string stringByAppendingString:[NSString stringWithFormat:(count > 1) ? NSLocalizedString(@"LIBRARY_EPISODES", nil) : NSLocalizedString(@"LIBRARY_SINGLE_EPISODE", nil), count, show.unreadEpisodes.count]];
  194. self.mediaIsUnreadView.hidden = YES;
  195. self.progressIndicator.hidden = YES;
  196. self.folderIconView.image = [UIImage imageNamed:@"tvShow"];
  197. self.folderIconView.hidden = NO;
  198. }
  199. - (void)_configureForAlbumTrack:(MLAlbumTrack *)albumTrack
  200. {
  201. MLFile *anyFileFromTrack = albumTrack.files.anyObject;
  202. self.subtitleLabel.text = [NSString stringWithFormat:@"%@ — %@ — %@", albumTrack.artist, [NSString stringWithFormat:NSLocalizedString(@"LIBRARY_TRACK_N", nil), albumTrack.trackNumber.intValue], [VLCTime timeWithNumber:[anyFileFromTrack duration]]];
  203. self.titleLabel.text = albumTrack.title;
  204. [self _showPositionOfItem:anyFileFromTrack];
  205. self.folderIconView.hidden = YES;
  206. }
  207. - (void)_configureForShowEpisode:(MLShowEpisode *)showEpisode
  208. {
  209. self.titleLabel.text = showEpisode.name;
  210. MLFile *anyFileFromEpisode = showEpisode.files.anyObject;
  211. if (self.titleLabel.text.length < 1) {
  212. self.titleLabel.text = [NSString stringWithFormat:@"S%02dE%02d", showEpisode.seasonNumber.intValue, showEpisode.episodeNumber.intValue];
  213. self.subtitleLabel.text = [NSString stringWithFormat:@"%@", [VLCTime timeWithNumber:[anyFileFromEpisode duration]]];
  214. } else
  215. self.subtitleLabel.text = [NSString stringWithFormat:@"S%02dE%02d — %@", showEpisode.seasonNumber.intValue, showEpisode.episodeNumber.intValue, [VLCTime timeWithNumber:[anyFileFromEpisode duration]]];
  216. [self _showPositionOfItem:anyFileFromEpisode];
  217. self.folderIconView.hidden = YES;
  218. }
  219. - (void)_configureForAlbum:(MLAlbum *)album
  220. {
  221. self.titleLabel.text = album.name;
  222. MLAlbumTrack *anyTrack = [album.tracks anyObject];
  223. NSUInteger count = album.tracks.count;
  224. NSMutableString *string = [[NSMutableString alloc] init];
  225. if (anyTrack) {
  226. if (anyTrack.artist.length > 0) {
  227. [string appendString:anyTrack.artist];
  228. [string appendString:@" — "];
  229. }
  230. }
  231. [string appendString:[NSString stringWithFormat:(count > 1) ? NSLocalizedString(@"LIBRARY_TRACKS", nil) : NSLocalizedString(@"LIBRARY_SINGLE_TRACK", nil), count]];
  232. if (album.releaseYear.length > 0)
  233. [string appendFormat:@" — %@", album.releaseYear];
  234. self.subtitleLabel.text = string;
  235. self.mediaIsUnreadView.hidden = YES;
  236. self.progressIndicator.hidden = YES;
  237. self.folderIconView.hidden = YES;
  238. }
  239. - (void)_configureForFolder:(MLLabel *)label
  240. {
  241. self.titleLabel.text = label.name;
  242. NSUInteger count = label.files.count;
  243. self.subtitleLabel.text = (count == 1) ? NSLocalizedString(@"ONE_FILE", nil) : [NSString stringWithFormat:NSLocalizedString(@"NUM_OF_FILES", nil), count];
  244. self.mediaIsUnreadView.hidden = YES;
  245. self.progressIndicator.hidden = YES;
  246. self.folderIconView.image = [UIImage imageNamed:@"folderIcon"];
  247. self.folderIconView.hidden = NO;
  248. }
  249. - (void)_configureForMLFile:(MLFile *)mediaFile
  250. {
  251. if (mediaFile.isAlbumTrack) {
  252. NSString *string = @"";
  253. if (mediaFile.albumTrack.artist)
  254. string = [NSString stringWithFormat:@"%@ — ", mediaFile.albumTrack.artist];
  255. else if (mediaFile.albumTrack.album.name)
  256. string = [NSString stringWithFormat:@"%@ — ", mediaFile.albumTrack.artist];
  257. self.titleLabel.text = [string stringByAppendingString:(mediaFile.albumTrack.title.length > 1) ? mediaFile.albumTrack.title : mediaFile.title];
  258. } else
  259. self.titleLabel.text = mediaFile.title;
  260. if (self.isEditing)
  261. self.subtitleLabel.text = [NSString stringWithFormat:@"%@ — %@", [VLCTime timeWithNumber:[mediaFile duration]], [NSByteCountFormatter stringFromByteCount:[mediaFile fileSizeInBytes] countStyle:NSByteCountFormatterCountStyleFile]];
  262. else {
  263. self.subtitleLabel.text = [NSString stringWithFormat:@"%@", [VLCTime timeWithNumber:[mediaFile duration]]];
  264. if (mediaFile.videoTrack) {
  265. NSString *width = [[mediaFile videoTrack] valueForKey:@"width"];
  266. NSString *height = [[mediaFile videoTrack] valueForKey:@"height"];
  267. if (width.intValue > 0 && height.intValue > 0)
  268. self.subtitleLabel.text = [self.subtitleLabel.text stringByAppendingFormat:@" — %@x%@", width, height];
  269. }
  270. }
  271. [self _showPositionOfItem:mediaFile];
  272. self.folderIconView.hidden = YES;
  273. }
  274. - (void)_showPositionOfItem:(MLFile *)mediaLibraryFile
  275. {
  276. CGFloat position = mediaLibraryFile.lastPosition.floatValue;
  277. CGFloat duration = mediaLibraryFile.duration.floatValue;
  278. if (position > .05f && position < .95f && (duration * position - duration) < -60000) {
  279. [(UITextView*)self.mediaIsUnreadView setText:[NSString stringWithFormat:NSLocalizedString(@"LIBRARY_MINUTES_LEFT", nil), [[VLCTime timeWithInt:(duration * position - duration)] minuteStringValue]]];
  280. self.mediaIsUnreadView.hidden = NO;
  281. } else if (mediaLibraryFile.unread.intValue) {
  282. [(UILabel *)self.mediaIsUnreadView setText:[NSLocalizedString(@"NEW", nil) capitalizedStringWithLocale:[NSLocale currentLocale]]];
  283. self.mediaIsUnreadView.hidden = NO;
  284. } else
  285. self.mediaIsUnreadView.hidden = YES;
  286. }
  287. - (void)longTouchGestureAction:(UIGestureRecognizer *)recognizer
  288. {
  289. _isExpanded = YES;
  290. CGRect frame = self.frame;
  291. frame.size.height = 180.;
  292. BOOL metaHidden = NO;
  293. MLFile *theFile;
  294. if ([self.mediaObject isKindOfClass:[MLFile class]])
  295. theFile = (MLFile *)self.mediaObject;
  296. else if ([self.mediaObject isKindOfClass:[MLShowEpisode class]])
  297. theFile = [[(MLShowEpisode *)self.mediaObject files]anyObject];
  298. else if ([self.mediaObject isKindOfClass:[MLAlbumTrack class]])
  299. theFile = [[(MLAlbumTrack *)self.mediaObject files]anyObject];
  300. NSMutableString *mediaInfo = [[NSMutableString alloc] init];
  301. if (theFile) {
  302. NSMutableArray *videoTracks = [[NSMutableArray alloc] init];
  303. NSMutableArray *audioTracks = [[NSMutableArray alloc] init];
  304. NSMutableArray *spuTracks = [[NSMutableArray alloc] init];
  305. NSArray *tracks = [[theFile tracks] allObjects];
  306. NSUInteger trackCount = tracks.count;
  307. for (NSUInteger x = 0; x < trackCount; x++) {
  308. NSManagedObject *track = tracks[x];
  309. NSString *trackEntityName = [[track entity] name];
  310. if ([trackEntityName isEqualToString:@"VideoTrackInformation"])
  311. [videoTracks addObject:track];
  312. else if ([trackEntityName isEqualToString:@"AudioTrackInformation"])
  313. [audioTracks addObject:track];
  314. else if ([trackEntityName isEqualToString:@"SubtitlesTrackInformation"])
  315. [spuTracks addObject:track];
  316. }
  317. /* print video info */
  318. trackCount = videoTracks.count;
  319. if (trackCount > 0) {
  320. if (trackCount != 1)
  321. [mediaInfo appendFormat:@"%lu video tracks", (unsigned long)trackCount];
  322. else
  323. [mediaInfo appendString:@"1 video track"];
  324. [mediaInfo appendString:@" ("];
  325. for (NSUInteger x = 0; x < trackCount; x++) {
  326. int fourcc = [[videoTracks[x] valueForKey:@"codec"] intValue];
  327. if (x != 0)
  328. [mediaInfo appendFormat:@", %4.4s", (char *)&fourcc];
  329. else
  330. [mediaInfo appendFormat:@"%4.4s", (char *)&fourcc];
  331. }
  332. [mediaInfo appendString:@")"];
  333. }
  334. /* print audio info */
  335. trackCount = audioTracks.count;
  336. if (trackCount > 0) {
  337. if (mediaInfo.length > 0)
  338. [mediaInfo appendString:@"\n\n"];
  339. if (trackCount != 1)
  340. [mediaInfo appendFormat:@"%lu audio tracks", (unsigned long)trackCount];
  341. else
  342. [mediaInfo appendString:@"1 audio track"];
  343. [mediaInfo appendString:@":\n"];
  344. for (NSUInteger x = 0; x < trackCount; x++) {
  345. NSManagedObject *track = audioTracks[x];
  346. int fourcc = [[track valueForKey:@"codec"] intValue];
  347. if (x != 0)
  348. [mediaInfo appendFormat:@", %4.4s", (char *)&fourcc];
  349. else
  350. [mediaInfo appendFormat:@"%4.4s", (char *)&fourcc];
  351. int channelNumber = [[track valueForKey:@"channelsNumber"] intValue];
  352. NSString *language = [track valueForKey:@"language"];
  353. int bitrate = [[track valueForKey:@"bitrate"] intValue];
  354. if (channelNumber != 0 || language != nil || bitrate > 0) {
  355. [mediaInfo appendString:@" ["];
  356. if (bitrate > 0)
  357. [mediaInfo appendFormat:@"%i kbit/s", bitrate / 1024];
  358. if (channelNumber > 0) {
  359. if (bitrate > 0)
  360. [mediaInfo appendString:@", "];
  361. if (channelNumber == 1)
  362. [mediaInfo appendString:@"MONO"];
  363. else if (channelNumber == 2)
  364. [mediaInfo appendString:@"STEREO"];
  365. else
  366. [mediaInfo appendString:@"MULTI-CHANNEL"];
  367. }
  368. if (language != nil) {
  369. if (channelNumber > 0 || bitrate > 0)
  370. [mediaInfo appendString:@", "];
  371. [mediaInfo appendString:[language uppercaseString]];
  372. }
  373. [mediaInfo appendString:@"]"];
  374. }
  375. }
  376. }
  377. /* SPU */
  378. trackCount = spuTracks.count;
  379. if (trackCount == 0) {
  380. NSFileManager *fileManager = [NSFileManager defaultManager];
  381. NSString *folderLocation = [theFile.url.path stringByDeletingLastPathComponent];
  382. NSArray *allfiles = [fileManager contentsOfDirectoryAtPath:folderLocation error:nil];
  383. NSString *fileName = [theFile.path.lastPathComponent stringByDeletingPathExtension];
  384. NSUInteger count = allfiles.count;
  385. NSString *additionalFilePath;
  386. for (unsigned int x = 0; x < count; x++) {
  387. additionalFilePath = [NSString stringWithFormat:@"%@", allfiles[x]];
  388. if ([additionalFilePath isSupportedSubtitleFormat])
  389. if ([additionalFilePath rangeOfString:fileName].location != NSNotFound)
  390. trackCount ++;
  391. }
  392. }
  393. if ((trackCount > 0) && (spuTracks.count > 0)) {
  394. if (mediaInfo.length > 0)
  395. [mediaInfo appendString:@"\n\n"];
  396. if (trackCount != 1)
  397. [mediaInfo appendFormat:@"%lu subtitles tracks", (unsigned long)trackCount];
  398. else
  399. [mediaInfo appendString:@"1 subtitles track"];
  400. [mediaInfo appendString:@" ("];
  401. for (NSUInteger x = 0; x < trackCount; x++) {
  402. NSString *language = [spuTracks[x] valueForKey:@"language"];
  403. if (language) {
  404. if (x != 0)
  405. [mediaInfo appendFormat:@", %@", [language uppercaseString]];
  406. else
  407. [mediaInfo appendString:[language uppercaseString]];
  408. }
  409. }
  410. [mediaInfo appendString:@")"];
  411. }
  412. self.metaDataLabel.text = mediaInfo;
  413. videoTracks = audioTracks = spuTracks = nil;
  414. } else
  415. self.metaDataLabel.text = @"";
  416. void (^animationBlock)() = ^() {
  417. self.frame = frame;
  418. self.metaDataLabel.hidden = metaHidden;
  419. };
  420. void (^completionBlock)(BOOL finished) = ^(BOOL finished) {
  421. self.frame = frame;
  422. self.metaDataLabel.hidden = metaHidden;
  423. };
  424. NSTimeInterval animationDuration = .2;
  425. [UIView animateWithDuration:animationDuration animations:animationBlock completion:completionBlock];
  426. }
  427. - (void)collapsWithAnimation:(BOOL)animate
  428. {
  429. _isExpanded = NO;
  430. if (!animate) {
  431. self.metaDataLabel.hidden = YES;
  432. CGRect frame = self.frame;
  433. frame.size.height = 90.;
  434. self.frame = frame;
  435. return;
  436. }
  437. CGRect frame = self.frame;
  438. frame.size.height = 90.;
  439. BOOL metaHidden = YES;
  440. void (^animationBlock)() = ^() {
  441. self.frame = frame;
  442. self.metaDataLabel.hidden = metaHidden;
  443. };
  444. void (^completionBlock)(BOOL finished) = ^(BOOL finished) {
  445. self.frame = frame;
  446. self.metaDataLabel.hidden = metaHidden;
  447. };
  448. NSTimeInterval animationDuration = .2;
  449. [UIView animateWithDuration:animationDuration animations:animationBlock completion:completionBlock];
  450. }
  451. - (void)thumbnailWasUpdated:(NSNotification *)aNotification
  452. {
  453. self.thumbnailView.contentMode = UIViewContentModeScaleAspectFill;
  454. self.thumbnailView.image = [VLCThumbnailsCache thumbnailForManagedObject:self.mediaObject refreshCache:YES];
  455. }
  456. @end