2
0

WFCFavoriteVideoCell.m 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. //
  2. // WFCFavoriteUnknownCell.m
  3. // WildFireChat
  4. //
  5. // Created by Tom Lee on 2020/11/1.
  6. // Copyright © 2020 WildFireChat. All rights reserved.
  7. //
  8. #import "WFCFavoriteVideoCell.h"
  9. @interface WFCFavoriteVideoCell ()
  10. @property(nonatomic, strong)UIImageView *thumbView;
  11. @property(nonatomic, strong)UIImageView *videoIcon;
  12. @property(nonatomic, strong)UILabel *durationLabel;
  13. @end
  14. @implementation WFCFavoriteVideoCell
  15. - (void)awakeFromNib {
  16. [super awakeFromNib];
  17. // Initialization code
  18. }
  19. - (void)setFavoriteItem:(WFCUFavoriteItem *)favoriteItem {
  20. [super setFavoriteItem:favoriteItem];
  21. NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:[favoriteItem.data dataUsingEncoding:NSUTF8StringEncoding] options:kNilOptions error:nil];
  22. NSString *thumbStr = dict[@"thumb"];
  23. NSData *thumbData = [[NSData alloc] initWithBase64EncodedString:thumbStr options:NSDataBase64DecodingIgnoreUnknownCharacters];
  24. UIImage *image = [UIImage imageWithData:thumbData];
  25. self.thumbView.frame = CGRectMake(0, 0, image.size.width, image.size.height);
  26. self.thumbView.image = image;
  27. self.videoIcon.center = self.thumbView.center;
  28. int duration = [dict[@"duration"] intValue];
  29. self.durationLabel.text = [NSString stringWithFormat:@"%d 秒", duration];
  30. self.durationLabel.frame = CGRectMake(8, image.size.height - 30, image.size.width-16, 20);
  31. }
  32. + (CGFloat)contentHeight:(WFCUFavoriteItem *)favoriteItem {
  33. NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:[favoriteItem.data dataUsingEncoding:NSUTF8StringEncoding] options:kNilOptions error:nil];
  34. NSString *thumbStr = dict[@"thumb"];
  35. NSData *thumbData = [[NSData alloc] initWithBase64EncodedString:thumbStr options:NSDataBase64DecodingIgnoreUnknownCharacters];
  36. UIImage *image = [UIImage imageWithData:thumbData];
  37. return image.size.height;
  38. }
  39. - (UIImageView *)thumbView {
  40. if (!_thumbView) {
  41. _thumbView = [[UIImageView alloc] init];
  42. [self.contentArea addSubview:_thumbView];
  43. }
  44. return _thumbView;
  45. }
  46. - (UIImageView *)videoIcon {
  47. if (!_videoIcon) {
  48. _videoIcon = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
  49. _videoIcon.image = [UIImage imageNamed:@"video_msg_cover"];
  50. [self.thumbView addSubview:_videoIcon];
  51. }
  52. return _videoIcon;
  53. }
  54. - (UILabel *)durationLabel {
  55. if (!_durationLabel) {
  56. _durationLabel = [[UILabel alloc] init];
  57. _durationLabel.textAlignment = NSTextAlignmentRight;
  58. _durationLabel.font = [UIFont systemFontOfSize:14];
  59. [self.thumbView addSubview:_durationLabel];
  60. }
  61. return _durationLabel;
  62. }
  63. @end