VLCPlaylistTableViewCell.m 23 KB

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