VLCPlaylistTableViewCell.m 21.5 KB
Newer Older
1 2 3 4
/*****************************************************************************
 * VLCPlaylistTableViewCell.m
 * VLC for iOS
 *****************************************************************************
5
 * Copyright (c) 2013-2015 VideoLAN. All rights reserved.
6 7 8 9
 * $Id$
 *
 * Authors: Felix Paul Kühne <fkuehne # videolan.org>
 *          Gleb Pinigin <gpinigin # gmail.com>
10
 *          Carola Nitz <nitz.carola #googlemail.com>
11 12 13
 *
 * Refer to the COPYING file of the official project for license.
 *****************************************************************************/
14 15

#import "VLCPlaylistTableViewCell.h"
16
#import "VLCLinearProgressIndicator.h"
17
#import "VLCThumbnailsCache.h"
18
#import "NSString+SupportedMedia.h"
19
#import <MediaLibraryKit/MLAlbum.h>
20

21 22 23 24 25 26 27
@interface VLCPlaylistTableViewCell ()
{
    UILongPressGestureRecognizer *_longPress;
}

@end

28 29
@implementation VLCPlaylistTableViewCell

30 31 32 33 34
- (void)dealloc
{
    [self _removeObserver];
}

35 36
+ (VLCPlaylistTableViewCell *)cellWithReuseIdentifier:(NSString *)ident
{
37
    NSArray *nibContentArray;
Felix Paul Kühne's avatar
Felix Paul Kühne committed
38
    if (SYSTEM_RUNS_IOS7_OR_LATER)
39 40 41
        nibContentArray = [[NSBundle mainBundle] loadNibNamed:@"VLCFuturePlaylistTableViewCell" owner:nil options:nil];
    else
        nibContentArray = [[NSBundle mainBundle] loadNibNamed:@"VLCPlaylistTableViewCell" owner:nil options:nil];
42 43
    NSAssert([nibContentArray count] == 1, @"meh");
    NSAssert([[nibContentArray lastObject] isKindOfClass:[VLCPlaylistTableViewCell class]], @"meh meh");
44
    VLCPlaylistTableViewCell *cell = (VLCPlaylistTableViewCell *)[nibContentArray lastObject];
45
    cell.multipleSelectionBackgroundView = [[UIView alloc] initWithFrame:cell.frame];
46
    cell.metaDataLabel.hidden = YES;
47 48 49 50

    return cell;
}

51 52 53 54 55 56
- (void)setNeedsDisplay
{
    [self collapsWithAnimation:NO];
    [super setNeedsDisplay];
}

57 58
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
59
    [self _updatedDisplayedInformationForKeyPath:keyPath];
60 61
}

62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
- (void)_removeObserver
{
    if ([_mediaObject isKindOfClass:[MLLabel class]]) {
        [_mediaObject removeObserver:self forKeyPath:@"files"];
        [_mediaObject removeObserver:self forKeyPath:@"name"];
    } else if ([_mediaObject isKindOfClass:[MLShow class]])
        [_mediaObject removeObserver:self forKeyPath:@"episodes"];
    else if ([_mediaObject isKindOfClass:[MLShowEpisode class]]) {
        [_mediaObject removeObserver:self forKeyPath:@"name"];
        [_mediaObject removeObserver:self forKeyPath:@"files"];
        [_mediaObject removeObserver:self forKeyPath:@"artworkURL"];
        [_mediaObject removeObserver:self forKeyPath:@"unread"];
    } else if ([_mediaObject isKindOfClass:[MLAlbum class]]) {
        [_mediaObject removeObserver:self forKeyPath:@"name"];
        [_mediaObject removeObserver:self forKeyPath:@"tracks"];
    } else if ([_mediaObject isKindOfClass:[MLFile class]]) {
        [_mediaObject removeObserver:self forKeyPath:@"computedThumbnail"];
        [_mediaObject removeObserver:self forKeyPath:@"lastPosition"];
        [_mediaObject removeObserver:self forKeyPath:@"duration"];
        [_mediaObject removeObserver:self forKeyPath:@"fileSizeInBytes"];
        [_mediaObject removeObserver:self forKeyPath:@"title"];
        [_mediaObject removeObserver:self forKeyPath:@"thumbnailTimeouted"];
        [_mediaObject removeObserver:self forKeyPath:@"unread"];
        [_mediaObject removeObserver:self forKeyPath:@"albumTrackNumber"];
        [_mediaObject removeObserver:self forKeyPath:@"album"];
        [_mediaObject removeObserver:self forKeyPath:@"artist"];
        [_mediaObject removeObserver:self forKeyPath:@"genre"];
        [(MLFile*)_mediaObject didHide];
    }
}

- (void)_addObserver
{
    if ([_mediaObject isKindOfClass:[MLLabel class]]) {
        [_mediaObject addObserver:self forKeyPath:@"files" options:0 context:nil];
        [_mediaObject addObserver:self forKeyPath:@"name" options:0 context:nil];
    } else if ([_mediaObject isKindOfClass:[MLShow class]])
        [_mediaObject addObserver:self forKeyPath:@"episodes" options:0 context:nil];
    else if ([_mediaObject isKindOfClass:[MLShowEpisode class]]) {
        [_mediaObject addObserver:self forKeyPath:@"name" options:0 context:nil];
        [_mediaObject addObserver:self forKeyPath:@"files" options:0 context:nil];
        [_mediaObject addObserver:self forKeyPath:@"artworkURL" options:0 context:nil];
        [_mediaObject addObserver:self forKeyPath:@"unread" options:0 context:nil];
    } else if ([_mediaObject isKindOfClass:[MLAlbum class]]) {
        [_mediaObject addObserver:self forKeyPath:@"name" options:0 context:nil];
        [_mediaObject addObserver:self forKeyPath:@"tracks" options:0 context:nil];
    } else if ([_mediaObject isKindOfClass:[MLFile class]]) {
        [_mediaObject addObserver:self forKeyPath:@"computedThumbnail" options:0 context:nil];
        [_mediaObject addObserver:self forKeyPath:@"lastPosition" options:0 context:nil];
        [_mediaObject addObserver:self forKeyPath:@"duration" options:0 context:nil];
        [_mediaObject addObserver:self forKeyPath:@"fileSizeInBytes" options:0 context:nil];
        [_mediaObject addObserver:self forKeyPath:@"title" options:0 context:nil];
        [_mediaObject addObserver:self forKeyPath:@"thumbnailTimeouted" options:0 context:nil];
        [_mediaObject addObserver:self forKeyPath:@"unread" options:0 context:nil];
        [_mediaObject addObserver:self forKeyPath:@"albumTrackNumber" options:0 context:nil];
        [_mediaObject addObserver:self forKeyPath:@"album" options:0 context:nil];
        [_mediaObject addObserver:self forKeyPath:@"artist" options:0 context:nil];
        [_mediaObject addObserver:self forKeyPath:@"genre" options:0 context:nil];
        [(MLFile*)_mediaObject willDisplay];
    }
}

124 125 126
- (void)setMediaObject:(MLFile *)mediaObject
{
    if (_mediaObject != mediaObject) {
127
        [self _removeObserver];
128 129

        _mediaObject = mediaObject;
130 131
        // prevent the cell from recycling the current snap for random contents
        self.thumbnailView.image = nil;
132

133
        [self _addObserver];
134 135
    }

136
    [self collapsWithAnimation:NO];
137
    [self _updatedDisplayedInformationForKeyPath:nil];
138 139
}

140 141 142
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
    [super setEditing:editing animated:animated];
143
    [self _updatedDisplayedInformationForKeyPath:@"editing"];
144

145 146 147 148 149 150 151 152 153
    if (SYSTEM_RUNS_IOS7_OR_LATER) {
        if (editing) {
            if (_longPress)
                [self removeGestureRecognizer:_longPress];
        } else {
            if (!_longPress)
                _longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longTouchGestureAction:)];
            [self addGestureRecognizer:_longPress];
        }
154
    }
155 156
}

157
- (void)_updatedDisplayedInformationForKeyPath:(NSString *)keyPath
158
{
159
    self.thumbnailView.contentMode = UIViewContentModeScaleAspectFill;
160
    if ([self.mediaObject isKindOfClass:[MLFile class]]) {
161
        [self _configureForMLFile:(MLFile *)self.mediaObject];
162
    } else if ([self.mediaObject isKindOfClass:[MLLabel class]]) {
163
        [self _configureForFolder:(MLLabel *)self.mediaObject];
164
    } else if ([self.mediaObject isKindOfClass:[MLAlbum class]]) {
165
        [self _configureForAlbum:(MLAlbum *)self.mediaObject];
166
    } else if ([self.mediaObject isKindOfClass:[MLAlbumTrack class]]) {
167
        [self _configureForAlbumTrack:(MLAlbumTrack *)self.mediaObject];
168
    } else if ([self.mediaObject isKindOfClass:[MLShow class]]) {
169

170
        MLShow *mediaObject = (MLShow *)self.mediaObject;
171
        [self _configureForShow:mediaObject];
172

173 174
        if ([keyPath isEqualToString:@"computedThumbnail"] || [keyPath isEqualToString:@"episodes"] || !keyPath || (!self.thumbnailView.image && [keyPath isEqualToString:@"editing"])) {
            self.thumbnailView.image = [VLCThumbnailsCache thumbnailForManagedObject:mediaObject];
175
        }
176
    } else if ([self.mediaObject isKindOfClass:[MLShowEpisode class]]) {
177 178 179 180
        [self _configureForShowEpisode:(MLShowEpisode *)self.mediaObject];
    }
    if (![self.mediaObject isKindOfClass:[MLShow class]] && ([keyPath isEqualToString:@"computedThumbnail"] || !keyPath || (!self.thumbnailView.image && [keyPath isEqualToString:@"editing"]))) {
        self.thumbnailView.image = [VLCThumbnailsCache thumbnailForManagedObject:self.mediaObject];
181
    }
182 183 184
    [self setNeedsDisplay];
}

185 186
+ (CGFloat)heightOfCell
{
Felix Paul Kühne's avatar
Felix Paul Kühne committed
187
    if (SYSTEM_RUNS_IOS7_OR_LATER)
188
        return 90.;
189

190 191 192
    return 80.;
}

193 194
#pragma mark - presentation

195
- (void)_configureForShow:(MLShow *)show
196 197 198
{
    self.titleLabel.text = show.name;
    NSUInteger count = show.episodes.count;
199 200 201
    NSString *string = @"";
    if (show.releaseYear)
        string = [NSString stringWithFormat:@"%@ — ", show.releaseYear];
202
    self.subtitleLabel.text = [string stringByAppendingString:[NSString stringWithFormat:(count > 1) ? NSLocalizedString(@"LIBRARY_EPISODES", nil) : NSLocalizedString(@"LIBRARY_SINGLE_EPISODE", nil), count, show.unreadEpisodes.count]];
203 204
    self.mediaIsUnreadView.hidden = YES;
    self.progressIndicator.hidden = YES;
205
    self.folderIconView.image = [UIImage imageNamed:@"tvShow"];
206
    self.folderIconView.hidden = NO;
207 208
}

209
- (void)_configureForAlbumTrack:(MLAlbumTrack *)albumTrack
210
{
211
    MLFile *anyFileFromTrack = albumTrack.files.anyObject;
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
}

218
- (void)_configureForShowEpisode:(MLShowEpisode *)showEpisode
219 220 221 222 223
{
    self.titleLabel.text = showEpisode.name;

    MLFile *anyFileFromEpisode = showEpisode.files.anyObject;
    if (self.titleLabel.text.length < 1) {
224
        self.titleLabel.text = [NSString stringWithFormat:@"S%02dE%02d", showEpisode.seasonNumber.intValue, showEpisode.episodeNumber.intValue];
225 226
        self.subtitleLabel.text = [NSString stringWithFormat:@"%@", [VLCTime timeWithNumber:[anyFileFromEpisode duration]]];
    } else
227
        self.subtitleLabel.text = [NSString stringWithFormat:@"S%02dE%02d — %@", showEpisode.seasonNumber.intValue, showEpisode.episodeNumber.intValue, [VLCTime timeWithNumber:[anyFileFromEpisode duration]]];
228

229
    [self _showPositionOfItem:anyFileFromEpisode];
230
    self.folderIconView.hidden = YES;
231 232
}

233
- (void)_configureForAlbum:(MLAlbum *)album
234 235 236 237
{
    self.titleLabel.text = album.name;
    MLAlbumTrack *anyTrack = [album.tracks anyObject];
    NSUInteger count = album.tracks.count;
238 239
    NSMutableString *string = [[NSMutableString alloc] init];
    if (anyTrack) {
240 241 242 243
        if (anyTrack.artist.length > 0) {
            [string appendString:anyTrack.artist];
            [string appendString:@" — "];
        }
244
    }
245
    [string appendString:[NSString stringWithFormat:(count > 1) ? NSLocalizedString(@"LIBRARY_TRACKS", nil) : NSLocalizedString(@"LIBRARY_SINGLE_TRACK", nil), count]];
246
    if (album.releaseYear.length > 0)
247
        [string appendFormat:@" — %@", album.releaseYear];
248
    self.subtitleLabel.text = string;
249 250
    self.mediaIsUnreadView.hidden = YES;
    self.progressIndicator.hidden = YES;
251
    self.folderIconView.hidden = YES;
252 253
}

254 255 256 257
- (void)_configureForFolder:(MLLabel *)label
{
    self.titleLabel.text = label.name;
    NSUInteger count = label.files.count;
258
    self.subtitleLabel.text = [NSString stringWithFormat:(count == 1) ? NSLocalizedString(@"LIBRARY_SINGLE_TRACK", nil) : NSLocalizedString(@"LIBRARY_TRACKS", nil), count];
259 260
    self.mediaIsUnreadView.hidden = YES;
    self.progressIndicator.hidden = YES;
261 262
    self.folderIconView.image = [UIImage imageNamed:@"folderIcon"];
    self.folderIconView.hidden = NO;
263 264
}

265
- (void)_configureForMLFile:(MLFile *)mediaFile
266
{
267
    if (mediaFile.isAlbumTrack) {
268 269 270 271 272 273
        NSString *string = @"";
        if (mediaFile.albumTrack.artist)
            string = [NSString stringWithFormat:@"%@ — ", mediaFile.albumTrack.artist];
        else if (mediaFile.albumTrack.album.name)
            string = [NSString stringWithFormat:@"%@ — ", mediaFile.albumTrack.artist];
        self.titleLabel.text = [string stringByAppendingString:(mediaFile.albumTrack.title.length > 1) ? mediaFile.albumTrack.title : mediaFile.title];
274 275 276 277
    } else
        self.titleLabel.text = mediaFile.title;

    if (self.isEditing)
278
        self.subtitleLabel.text = [NSString stringWithFormat:@"%@ — %@", [VLCTime timeWithNumber:[mediaFile duration]], [NSByteCountFormatter stringFromByteCount:[mediaFile fileSizeInBytes] countStyle:NSByteCountFormatterCountStyleFile]];
279 280 281 282 283 284 285 286 287
    else {
        self.subtitleLabel.text = [NSString stringWithFormat:@"%@", [VLCTime timeWithNumber:[mediaFile duration]]];
        if (mediaFile.videoTrack) {
            NSString *width = [[mediaFile videoTrack] valueForKey:@"width"];
            NSString *height = [[mediaFile videoTrack] valueForKey:@"height"];
            if (width.intValue > 0 && height.intValue > 0)
                self.subtitleLabel.text = [self.subtitleLabel.text stringByAppendingFormat:@" — %@x%@", width, height];
        }
    }
288
    [self _showPositionOfItem:mediaFile];
289
    self.folderIconView.hidden = YES;
290 291
}

292
- (void)_showPositionOfItem:(MLFile *)mediaLibraryFile
293
{
294
    CGFloat position = mediaLibraryFile.lastPosition.floatValue;
295

Felix Paul Kühne's avatar
Felix Paul Kühne committed
296
    if (SYSTEM_RUNS_IOS7_OR_LATER) {
297
        CGFloat duration = mediaLibraryFile.duration.floatValue;
298
        if (position > .05f && position < .95f && (duration * position - duration) < -60000) {
299
            [(UITextView*)self.mediaIsUnreadView setText:[NSString stringWithFormat:NSLocalizedString(@"LIBRARY_MINUTES_LEFT", nil), [[VLCTime timeWithInt:(duration * position - duration)] minuteStringValue]]];
300
            self.mediaIsUnreadView.hidden = NO;
301
        } else if (mediaLibraryFile.unread.intValue) {
302
            [(UILabel *)self.mediaIsUnreadView setText:[NSLocalizedString(@"NEW", nil) capitalizedStringWithLocale:[NSLocale currentLocale]]];
303 304 305 306 307 308 309
            self.mediaIsUnreadView.hidden = NO;
        } else
            self.mediaIsUnreadView.hidden = YES;
    } else {
        self.progressIndicator.progress = position;
        self.progressIndicator.hidden = ((position < .1f) || (position > .95f)) ? YES : NO;
        [self.progressIndicator setNeedsDisplay];
310
        self.mediaIsUnreadView.hidden = !mediaLibraryFile.unread.intValue;
311
    }
312 313
}

314 315
- (void)longTouchGestureAction:(UIGestureRecognizer *)recognizer
{
316
    _isExpanded = YES;
317
    CGRect frame = self.frame;
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352
    frame.size.height = 180.;
    BOOL metaHidden = NO;

    MLFile *theFile;
    if ([self.mediaObject isKindOfClass:[MLFile class]])
        theFile = (MLFile *)self.mediaObject;
    else if ([self.mediaObject isKindOfClass:[MLShowEpisode class]])
        theFile = [[(MLShowEpisode *)self.mediaObject files]anyObject];
    else if ([self.mediaObject isKindOfClass:[MLAlbumTrack class]])
        theFile = [[(MLAlbumTrack *)self.mediaObject files]anyObject];

    NSMutableString *mediaInfo = [[NSMutableString alloc] init];

    if (theFile) {
        NSMutableArray *videoTracks = [[NSMutableArray alloc] init];
        NSMutableArray *audioTracks = [[NSMutableArray alloc] init];
        NSMutableArray *spuTracks = [[NSMutableArray alloc] init];
        NSArray *tracks = [[theFile tracks] allObjects];
        NSUInteger trackCount = tracks.count;

        for (NSUInteger x = 0; x < trackCount; x++) {
            NSManagedObject *track = tracks[x];
            NSString *trackEntityName = [[track entity] name];
            if ([trackEntityName isEqualToString:@"VideoTrackInformation"])
                [videoTracks addObject:track];
            else if ([trackEntityName isEqualToString:@"AudioTrackInformation"])
                [audioTracks addObject:track];
            else if ([trackEntityName isEqualToString:@"SubtitlesTrackInformation"])
                [spuTracks addObject:track];
        }

        /* print video info */
        trackCount = videoTracks.count;

        if (trackCount > 0) {
353 354 355 356 357
            if (trackCount != 1)
                [mediaInfo appendFormat:@"%lu video tracks", (unsigned long)trackCount];
            else
                [mediaInfo appendString:@"1 video track"];

358 359 360 361 362 363 364 365 366 367 368 369 370 371 372
            [mediaInfo appendString:@" ("];
            for (NSUInteger x = 0; x < trackCount; x++) {
                int fourcc = [[videoTracks[x] valueForKey:@"codec"] intValue];
                if (x != 0)
                    [mediaInfo appendFormat:@", %4.4s", (char *)&fourcc];
                else
                    [mediaInfo appendFormat:@"%4.4s", (char *)&fourcc];
            }
            [mediaInfo appendString:@")"];
        }

        /* print audio info */
        trackCount = audioTracks.count;

        if (trackCount > 0) {
373 374 375 376 377 378 379 380
            if (mediaInfo.length > 0)
                [mediaInfo appendString:@"\n\n"];

            if (trackCount != 1)
                [mediaInfo appendFormat:@"%lu audio tracks", (unsigned long)trackCount];
            else
                [mediaInfo appendString:@"1 audio track"];

381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424
            [mediaInfo appendString:@":\n"];
            for (NSUInteger x = 0; x < trackCount; x++) {
                NSManagedObject *track = audioTracks[x];
                int fourcc = [[track valueForKey:@"codec"] intValue];
                if (x != 0)
                    [mediaInfo appendFormat:@", %4.4s", (char *)&fourcc];
                else
                    [mediaInfo appendFormat:@"%4.4s", (char *)&fourcc];

                int channelNumber = [[track valueForKey:@"channelsNumber"] intValue];
                NSString *language = [track valueForKey:@"language"];
                int bitrate = [[track valueForKey:@"bitrate"] intValue];
                if (channelNumber != 0 || language != nil || bitrate > 0) {
                    [mediaInfo appendString:@" ["];

                    if (bitrate > 0)
                        [mediaInfo appendFormat:@"%i kbit/s", bitrate / 1024];

                    if (channelNumber > 0) {
                        if (bitrate > 0)
                            [mediaInfo appendString:@", "];

                        if (channelNumber == 1)
                            [mediaInfo appendString:@"MONO"];
                        else if (channelNumber == 2)
                            [mediaInfo appendString:@"STEREO"];
                        else
                            [mediaInfo appendString:@"MULTI-CHANNEL"];
                    }

                    if (language != nil) {
                        if (channelNumber > 0 || bitrate > 0)
                            [mediaInfo appendString:@", "];

                        [mediaInfo appendString:[language uppercaseString]];
                    }

                    [mediaInfo appendString:@"]"];
                }
            }
        }

        /* SPU */
        trackCount = spuTracks.count;
425 426
        if (trackCount == 0) {
            NSFileManager *fileManager = [NSFileManager defaultManager];
427
            NSString *folderLocation = [theFile.url.path stringByDeletingLastPathComponent];
428
            NSArray *allfiles = [fileManager contentsOfDirectoryAtPath:folderLocation error:nil];
429
            NSString *fileName = [theFile.path.lastPathComponent stringByDeletingPathExtension];
430 431 432 433 434 435 436 437 438
            NSUInteger count = allfiles.count;
            NSString *additionalFilePath;
            for (unsigned int x = 0; x < count; x++) {
                additionalFilePath = [NSString stringWithFormat:@"%@", allfiles[x]];
                if ([additionalFilePath isSupportedSubtitleFormat])
                    if ([additionalFilePath rangeOfString:fileName].location != NSNotFound)
                        trackCount ++;
            }
        }
439

440
        if ((trackCount > 0) && (spuTracks.count > 0)) {
441 442 443 444 445 446 447 448
            if (mediaInfo.length > 0)
                [mediaInfo appendString:@"\n\n"];

            if (trackCount != 1)
                [mediaInfo appendFormat:@"%lu subtitles tracks", (unsigned long)trackCount];
            else
                [mediaInfo appendString:@"1 subtitles track"];

449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487
            [mediaInfo appendString:@" ("];
            for (NSUInteger x = 0; x < trackCount; x++) {
                NSString *language = [spuTracks[x] valueForKey:@"language"];

                if (language) {
                    if (x != 0)
                        [mediaInfo appendFormat:@", %@", [language uppercaseString]];
                    else
                        [mediaInfo appendString:[language uppercaseString]];
                }
            }
            [mediaInfo appendString:@")"];
        }

        self.metaDataLabel.text = mediaInfo;
        videoTracks = audioTracks = spuTracks = nil;
    } else
        self.metaDataLabel.text = @"";

    void (^animationBlock)() = ^() {
        self.frame = frame;
        self.metaDataLabel.hidden = metaHidden;
    };

    void (^completionBlock)(BOOL finished) = ^(BOOL finished) {
        self.frame = frame;
        self.metaDataLabel.hidden = metaHidden;
    };

    NSTimeInterval animationDuration = .2;
    [UIView animateWithDuration:animationDuration animations:animationBlock completion:completionBlock];
}

- (void)collapsWithAnimation:(BOOL)animate
{
    _isExpanded = NO;
    if (!animate) {
        self.metaDataLabel.hidden = YES;
        CGRect frame = self.frame;
488
        frame.size.height = 90.;
489 490 491 492 493 494 495
        self.frame = frame;
        return;
    }

    CGRect frame = self.frame;
    frame.size.height = 90.;
    BOOL metaHidden = YES;
496 497 498

    void (^animationBlock)() = ^() {
        self.frame = frame;
499
        self.metaDataLabel.hidden = metaHidden;
500 501 502 503
    };

    void (^completionBlock)(BOOL finished) = ^(BOOL finished) {
        self.frame = frame;
504
        self.metaDataLabel.hidden = metaHidden;
505 506 507 508 509 510
    };

    NSTimeInterval animationDuration = .2;
    [UIView animateWithDuration:animationDuration animations:animationBlock completion:completionBlock];
}

511
@end