TeacherShowCell.m 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. //
  2. // TeacherShowCell.m
  3. // KulexiuForStudent
  4. //
  5. // Created by 王智 on 2022/4/22.
  6. //
  7. #import "TeacherShowCell.h"
  8. #import "KSVideoHelper.h"
  9. #import "UIButton+EnlargeEdge.h"
  10. @interface TeacherShowCell ()
  11. @property (weak, nonatomic) IBOutlet UIImageView *videoCover;
  12. @property (weak, nonatomic) IBOutlet UILabel *descLabel;
  13. @property (weak, nonatomic) IBOutlet UIImageView *teacherAvatar;
  14. @property (weak, nonatomic) IBOutlet UILabel *teacherNameLabel;
  15. @property (weak, nonatomic) IBOutlet UILabel *watchCount;
  16. @property (weak, nonatomic) IBOutlet UILabel *durationLabel;
  17. @property (weak, nonatomic) IBOutlet UIButton *playButton;
  18. @property (nonatomic, copy) TeacherStylePlay callback;
  19. @property (nonatomic, strong) TeacherStyleModel *model;
  20. @end
  21. @implementation TeacherShowCell
  22. - (void)awakeFromNib {
  23. [super awakeFromNib];
  24. // Initialization code
  25. [self.playButton setEnlargeEdgeWithTop:10 right:5 bottom:10 left:10];
  26. }
  27. - (void)configWithStyleModel:(TeacherStyleModel *)sourceModel callback:(TeacherStylePlay)callback {
  28. if (callback) {
  29. self.callback = callback;
  30. }
  31. self.model = sourceModel;
  32. [KSVideoHelper getVideoPreviewImageUrl:sourceModel.videoUrl forImageView:self.videoCover placeholder:[UIImage imageNamed:@"video_placeholder"]];
  33. self.descLabel.text = [NSString returnNoNullStringWithString:sourceModel.describe];
  34. [self.teacherAvatar sd_setImageWithURL:[NSURL URLWithString:sourceModel.avatar] placeholderImage:[UIImage imageNamed:USERDEFAULT_LOGO]];
  35. self.teacherNameLabel.text = [NSString returnNoNullStringWithString:sourceModel.username];
  36. self.watchCount.text = [NSString stringWithFormat:@"%@已观看",sourceModel.browse];
  37. // if (![NSString isEmptyString:sourceModel.browse] && ![sourceModel.browse isEqualToString:@"0"]) {
  38. // self.watchCount.text = [NSString stringWithFormat:@"%@已观看",sourceModel.browse];
  39. // }
  40. // else {
  41. // self.watchCount.text = @"";
  42. // }
  43. NSInteger duration = [KSVideoHelper getVideoDuration:sourceModel.videoUrl];
  44. NSString *durationString = @"00:00";
  45. if (duration / 60 > 0) {
  46. durationString = [NSString stringWithFormat:@"%2ld:%2ld", duration / 60, duration % 60];
  47. }
  48. else {
  49. durationString = [NSString stringWithFormat:@"00:%2ld", duration];
  50. }
  51. self.durationLabel.text = durationString;
  52. }
  53. - (IBAction)playButtonAction:(id)sender {
  54. if (self.callback) {
  55. self.callback(self.model.videoUrl);
  56. }
  57. }
  58. @end