AccompanyHomeworkCell.m 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. //
  2. // AccompanyHomeworkCell.m
  3. // KulexiuForTeacher
  4. //
  5. // Created by 王智 on 2022/4/13.
  6. //
  7. #import "AccompanyHomeworkCell.h"
  8. #import "HomeworkAddView.h"
  9. @interface AccompanyHomeworkCell ()
  10. @property (weak, nonatomic) IBOutlet UIView *emptyView;
  11. @property (weak, nonatomic) IBOutlet UILabel *emptyDescLabel;
  12. @property (weak, nonatomic) IBOutlet UIView *videoContainer;
  13. @property (weak, nonatomic) IBOutlet UIView *submitView;
  14. @property (nonatomic, copy) HomeworkCellAction callback;
  15. @end
  16. @implementation AccompanyHomeworkCell
  17. - (void)awakeFromNib {
  18. [super awakeFromNib];
  19. // Initialization code
  20. self.selectionStyle = UITableViewCellSelectionStyleNone;
  21. }
  22. - (void)configWithAttachmentArray:(NSMutableArray *)fileArray canDisplaySubmitView:(BOOL)canDisplay isExpired:(BOOL)homeworkExpire callback:(HomeworkCellAction)callback {
  23. if (callback) {
  24. self.callback = callback;
  25. }
  26. [self.videoContainer removeAllSubViews];
  27. if (canDisplay && homeworkExpire == NO) { // 如果已经布置作业
  28. [self configVideoViewWithSource:fileArray];
  29. if (self.showSubmitButton) {
  30. self.submitView.hidden = NO;
  31. if (fileArray.count == 0) {
  32. self.emptyView.hidden = NO;
  33. NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
  34. [paragraphStyle setLineSpacing:4];//调整行间距
  35. NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:@"尚未提交作业哦~" attributes:@{NSParagraphStyleAttributeName:paragraphStyle,NSFontAttributeName:[UIFont systemFontOfSize:13.0f],NSForegroundColorAttributeName:HexRGB(0x999999)}];
  36. self.emptyDescLabel.attributedText = attr;
  37. }
  38. else {
  39. self.emptyView.hidden = YES;
  40. }
  41. }
  42. else {
  43. self.emptyView.hidden = YES;
  44. self.submitView.hidden = YES;
  45. }
  46. }
  47. else { // 未布置 或已过期
  48. self.submitView.hidden = YES;
  49. self.emptyView.hidden = NO;
  50. NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
  51. [paragraphStyle setLineSpacing:4];//调整行间距
  52. NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] init];
  53. if (homeworkExpire) {
  54. attr = [[NSMutableAttributedString alloc] initWithString:@"作业已过期无法提交和查看!" attributes:@{NSParagraphStyleAttributeName:paragraphStyle,NSFontAttributeName:[UIFont systemFontOfSize:13.0f],NSForegroundColorAttributeName:HexRGB(0x999999)}];
  55. }
  56. else {
  57. attr = [[NSMutableAttributedString alloc] initWithString:@"课程结束之后可上传视频作业" attributes:@{NSParagraphStyleAttributeName:paragraphStyle,NSFontAttributeName:[UIFont systemFontOfSize:13.0f],NSForegroundColorAttributeName:HexRGB(0x999999)}];
  58. }
  59. self.emptyDescLabel.attributedText = attr;
  60. }
  61. }
  62. - (void)configVideoViewWithSource:(NSMutableArray *)fileArray {
  63. CGFloat maxWidth = kScreenWidth - 24 - 20;
  64. CGFloat space = 0;
  65. CGFloat width = (maxWidth - space * 2) / 3.0f;
  66. CGFloat height = 92.0f;
  67. for (NSInteger i = 0; i < fileArray.count; i++) {
  68. if (i > 2) {
  69. return;
  70. }
  71. CGFloat positionX = i * (width + space);
  72. NSString *videoUrl = fileArray[i];
  73. HomeworkVideoView *videoView = [HomeworkVideoView shareInstance];
  74. videoView.frame = CGRectMake(positionX, 0, width, height);
  75. if (self.canSubmit == NO) {
  76. videoView.hideDeleteButton = YES;
  77. }
  78. videoView.tag = i+1000;
  79. MJWeakSelf
  80. [videoView displayVideoUrl:videoUrl callback:^(VIDEOVIEWACTION action, NSInteger viewIndex) {
  81. if (action == VIDEOVIEWACTION_PLAY) {
  82. [weakSelf playVideoIndex:viewIndex];
  83. }
  84. else {
  85. [weakSelf deleteVideoIndex:viewIndex];
  86. }
  87. }];
  88. [self.videoContainer addSubview:videoView];
  89. }
  90. if (fileArray.count < 3 && self.canSubmit) { // 添加上传按钮
  91. CGFloat positionX = fileArray.count * (width + space);
  92. HomeworkAddView *addView = [[HomeworkAddView alloc] initWithFrame:CGRectMake(positionX, 0, width, height)];
  93. [self.videoContainer addSubview:addView];
  94. MJWeakSelf;
  95. [addView chooseCallback:^{
  96. [weakSelf chooseVideo];
  97. }];
  98. }
  99. }
  100. - (void)chooseVideo {
  101. if (self.callback) {
  102. self.callback(HOMEWORKACTION_ADD,0);
  103. }
  104. }
  105. // 播放
  106. - (void)playVideoIndex:(NSInteger)index {
  107. if (self.callback) {
  108. self.callback(HOMEWORKACTION_PLAY,index);
  109. }
  110. }
  111. // 删除
  112. - (void)deleteVideoIndex:(NSInteger)index {
  113. if (self.callback) {
  114. self.callback(HOMEWORKACTION_DELETE, index);
  115. }
  116. }
  117. - (void)setCanSubmit:(BOOL)canSubmit {
  118. _canSubmit = canSubmit;
  119. }
  120. - (IBAction)toHomeworkDetail:(id)sender {
  121. if (self.callback) {
  122. self.callback(HOMEWORKACTION_HOMEWOEKPAGE, 0);
  123. }
  124. }
  125. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  126. [super setSelected:selected animated:animated];
  127. // Configure the view for the selected state
  128. }
  129. @end