123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- //
- // AccompanyHomeworkCell.m
- // KulexiuForTeacher
- //
- // Created by 王智 on 2022/4/13.
- //
- #import "AccompanyHomeworkCell.h"
- #import "HomeworkAddView.h"
- @interface AccompanyHomeworkCell ()
- @property (weak, nonatomic) IBOutlet UIView *emptyView;
- @property (weak, nonatomic) IBOutlet UILabel *emptyDescLabel;
- @property (weak, nonatomic) IBOutlet UIView *videoContainer;
- @property (weak, nonatomic) IBOutlet UIView *submitView;
- @property (nonatomic, copy) HomeworkCellAction callback;
- @end
- @implementation AccompanyHomeworkCell
- - (void)awakeFromNib {
- [super awakeFromNib];
- // Initialization code
- self.selectionStyle = UITableViewCellSelectionStyleNone;
-
- }
- - (void)configWithAttachmentArray:(NSMutableArray *)fileArray canDisplaySubmitView:(BOOL)canDisplay isExpired:(BOOL)homeworkExpire callback:(HomeworkCellAction)callback {
- if (callback) {
- self.callback = callback;
- }
- [self.videoContainer removeAllSubViews];
- if (canDisplay && homeworkExpire == NO) { // 如果已经布置作业
-
- [self configVideoViewWithSource:fileArray];
- if (self.showSubmitButton) {
- self.submitView.hidden = NO;
- if (fileArray.count == 0) {
- self.emptyView.hidden = NO;
- NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
- [paragraphStyle setLineSpacing:4];//调整行间距
- NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:@"尚未提交作业哦~" attributes:@{NSParagraphStyleAttributeName:paragraphStyle,NSFontAttributeName:[UIFont systemFontOfSize:13.0f],NSForegroundColorAttributeName:HexRGB(0x999999)}];
- self.emptyDescLabel.attributedText = attr;
- }
- else {
- self.emptyView.hidden = YES;
- }
- }
- else {
- self.emptyView.hidden = YES;
- self.submitView.hidden = YES;
- }
- }
- else { // 未布置 或已过期
- self.submitView.hidden = YES;
- self.emptyView.hidden = NO;
- NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
- [paragraphStyle setLineSpacing:4];//调整行间距
- NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] init];
- if (homeworkExpire) {
- attr = [[NSMutableAttributedString alloc] initWithString:@"作业已过期无法提交和查看!" attributes:@{NSParagraphStyleAttributeName:paragraphStyle,NSFontAttributeName:[UIFont systemFontOfSize:13.0f],NSForegroundColorAttributeName:HexRGB(0x999999)}];
- }
- else {
- attr = [[NSMutableAttributedString alloc] initWithString:@"课程结束之后可上传视频作业" attributes:@{NSParagraphStyleAttributeName:paragraphStyle,NSFontAttributeName:[UIFont systemFontOfSize:13.0f],NSForegroundColorAttributeName:HexRGB(0x999999)}];
-
- }
- self.emptyDescLabel.attributedText = attr;
- }
- }
- - (void)configVideoViewWithSource:(NSMutableArray *)fileArray {
- CGFloat maxWidth = kScreenWidth - 24 - 20;
- CGFloat space = 0;
- CGFloat width = (maxWidth - space * 2) / 3.0f;
- CGFloat height = 92.0f;
- for (NSInteger i = 0; i < fileArray.count; i++) {
- if (i > 2) {
- return;
- }
- CGFloat positionX = i * (width + space);
- NSString *videoUrl = fileArray[i];
- HomeworkVideoView *videoView = [HomeworkVideoView shareInstance];
- videoView.frame = CGRectMake(positionX, 0, width, height);
- if (self.canSubmit == NO) {
- videoView.hideDeleteButton = YES;
- }
- videoView.tag = i+1000;
- MJWeakSelf
- [videoView displayVideoUrl:videoUrl callback:^(VIDEOVIEWACTION action, NSInteger viewIndex) {
- if (action == VIDEOVIEWACTION_PLAY) {
- [weakSelf playVideoIndex:viewIndex];
- }
- else {
- [weakSelf deleteVideoIndex:viewIndex];
- }
- }];
- [self.videoContainer addSubview:videoView];
- }
- if (fileArray.count < 3 && self.canSubmit) { // 添加上传按钮
- CGFloat positionX = fileArray.count * (width + space);
- HomeworkAddView *addView = [[HomeworkAddView alloc] initWithFrame:CGRectMake(positionX, 0, width, height)];
- [self.videoContainer addSubview:addView];
- MJWeakSelf;
- [addView chooseCallback:^{
- [weakSelf chooseVideo];
- }];
- }
- }
- - (void)chooseVideo {
- if (self.callback) {
- self.callback(HOMEWORKACTION_ADD,0);
- }
- }
- // 播放
- - (void)playVideoIndex:(NSInteger)index {
- if (self.callback) {
- self.callback(HOMEWORKACTION_PLAY,index);
- }
- }
- // 删除
- - (void)deleteVideoIndex:(NSInteger)index {
- if (self.callback) {
- self.callback(HOMEWORKACTION_DELETE, index);
- }
- }
- - (void)setCanSubmit:(BOOL)canSubmit {
- _canSubmit = canSubmit;
- }
- - (IBAction)toHomeworkDetail:(id)sender {
- if (self.callback) {
- self.callback(HOMEWORKACTION_HOMEWOEKPAGE, 0);
- }
- }
- - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
- [super setSelected:selected animated:animated];
- // Configure the view for the selected state
- }
- @end
|