AccompanyDetailViewController.m 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  1. //
  2. // AccompanyDetailViewController.m
  3. // KulexiuForStudent
  4. //
  5. // Created by 王智 on 2022/4/19.
  6. //
  7. #import "AccompanyDetailViewController.h"
  8. #import "AccompanyCourseInfoCell.h"
  9. #import "AccompanyArrangeCell.h"
  10. #import "AccompanyHomeworkCell.h"
  11. #import "AccompanyRemarkCell.h"
  12. #import "AccompanyEvaluateCell.h"
  13. #import "AccompanyStudentEvaCell.h"
  14. #import "AccompanyDetailBottomView.h"
  15. #import "HomeworkDetailModel.h"
  16. #import "EvaluateDetailModel.h"
  17. #import "AccompanyAlertView.h"
  18. #import "WMPlayer.h"
  19. #import "RecordCheckManager.h"
  20. #import "KSPremissionAlert.h"
  21. #import "KSMediaManager.h"
  22. #import "OnlineClassManager.h"
  23. #import "HomeworkDetailViewController.h"
  24. #import "KSChatConversationViewController.h"
  25. @interface AccompanyDetailViewController ()<UITableViewDelegate,UITableViewDataSource,WMPlayerDelegate>
  26. {
  27. WMPlayer *_wmPlayer;
  28. CGRect _playerFrame;
  29. }
  30. @property (nonatomic, strong) UIView *bgView;
  31. @property (nonatomic, assign) BOOL isRatation;
  32. @property (nonatomic, strong) UITableView *tableView;
  33. @property (nonatomic, strong) AccompanyAlertView *alertView;
  34. @property (nonatomic, strong) NSMutableArray *fileArray;
  35. @property (nonatomic, strong) KSMediaManager *mediaManager;
  36. @property (nonatomic, strong) HomeworkDetailModel *homeworkModel;
  37. @property (nonatomic, strong) EvaluateDetailModel *evaluateModel;
  38. @property (strong, nonatomic) MBProgressHUD *HUD;
  39. @property (nonatomic, strong) AccompanyDetailBottomView *bottomView;
  40. @property (nonatomic, strong) OnlineClassManager *classManager;
  41. @property (nonatomic, assign) BOOL canModify;
  42. @property (nonatomic, assign) BOOL isModify; // 是否修改作业
  43. @end
  44. @implementation AccompanyDetailViewController
  45. - (void)viewDidLoad {
  46. [super viewDidLoad];
  47. // Do any additional setup after loading the view.
  48. [self allocTitle:@"课程详情"];
  49. [self configUI];
  50. [self requestCourseInfoMessage];
  51. self.isModify = NO;
  52. }
  53. - (void)requestCourseInfoMessage {
  54. [self requestHomeworkMessage];
  55. [self requestEvaluateMessage];
  56. [self requestRoomConfig];
  57. }
  58. - (void)requestRoomConfig {
  59. [KSNetworkingManager selectRoomConfigRequest:KS_GET success:^(NSDictionary * _Nonnull dic) {
  60. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  61. NSDictionary *result = [dic ks_dictionaryValueForKey:@"data"];
  62. self.joinRoomBeforeTime = [result ks_integerValueForKey:@"practiceStartTime"];
  63. self.quitRomeEndTime = [result ks_integerValueForKey:@"practiceEndTime"];
  64. }
  65. else {
  66. [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
  67. }
  68. } faliure:^(NSError * _Nonnull error) {
  69. }];
  70. }
  71. - (void)requestHomeworkMessage {
  72. [KSNetworkingManager homeworkDetailRequest:KS_GET courseId:self.courseId success:^(NSDictionary * _Nonnull dic) {
  73. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  74. self.homeworkModel = [[HomeworkDetailModel alloc] initWithDictionary:[dic ks_dictionaryValueForKey:@"data"]];
  75. if (self.homeworkModel.submitHomework == 1) {
  76. if (![NSString isEmptyString:self.homeworkModel.studentAttachments]) {
  77. self.fileArray = [NSMutableArray arrayWithArray:[self.homeworkModel.studentAttachments componentsSeparatedByString:@","]];
  78. }
  79. else {
  80. self.fileArray = [NSMutableArray array];
  81. }
  82. }
  83. else {
  84. self.fileArray = [NSMutableArray array];
  85. }
  86. }
  87. else {
  88. [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
  89. }
  90. [self evaluateViewDisplay];
  91. [self.tableView reloadData];
  92. } faliure:^(NSError * _Nonnull error) {
  93. }];
  94. }
  95. - (void)evaluateViewDisplay {
  96. // 老师布置过作业且没有点评 可以点击
  97. if (self.homeworkModel.reviewHomework == 1 || self.homeworkModel.decorateHomework == 0) {
  98. self.canModify = NO;
  99. self.bottomView.actionButton.userInteractionEnabled = NO;
  100. self.bottomView.actionButton.backgroundColor = HexRGB(0xe5e5e5);
  101. [self.bottomView.actionButton setTitleColor:HexRGB(0x666666) forState:UIControlStateNormal];
  102. }
  103. else {
  104. self.canModify = YES;
  105. self.bottomView.actionButton.userInteractionEnabled = YES;
  106. self.bottomView.actionButton.backgroundColor = THEMECOLOR;
  107. [self.bottomView.actionButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  108. }
  109. }
  110. - (void)requestEvaluateMessage {
  111. [KSNetworkingManager selectRepliedRequest:KS_POST courseGroupId:self.courseGroupId courseScheduleId:self.courseId success:^(NSDictionary * _Nonnull dic) {
  112. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  113. self.evaluateModel = [[EvaluateDetailModel alloc] initWithDictionary:[dic ks_dictionaryValueForKey:@"data"]];
  114. }
  115. else {
  116. [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
  117. }
  118. [self.tableView reloadData];
  119. } faliure:^(NSError * _Nonnull error) {
  120. }];
  121. }
  122. - (void)configUI {
  123. [self.scrollView removeFromSuperview];
  124. [self.view addSubview:self.tableView];
  125. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  126. make.left.right.mas_equalTo(self.view);
  127. make.top.mas_equalTo(self.view.mas_top);
  128. make.bottom.mas_equalTo(self.view.mas_bottom).offset(-iPhoneXSafeBottomMargin);
  129. }];
  130. }
  131. - (void)evaluateWithStatusLabel:(UILabel *)statusLabel {
  132. if ([self.homeworkModel.courseStatus isEqualToString:@"COMPLETE"]) {
  133. statusLabel.text = @"已结束";
  134. statusLabel.textColor = HexRGB(0x999999);
  135. self.bottomView.actionButton.userInteractionEnabled = NO;
  136. [self.bottomView.actionButton setTitle:@"已结束" forState:UIControlStateNormal];
  137. [self.bottomView.actionButton setBackgroundColor:HexRGB(0xe5e5e5)];
  138. [self.bottomView.actionButton setTitleColor:HexRGB(0x666666) forState:UIControlStateNormal];
  139. // // 老师已点评作业 或者老师未布置作业
  140. // if (self.homeworkModel.reviewHomework == 1 || self.homeworkModel.decorateHomework == 0) {
  141. // self.bottomView.actionButton.userInteractionEnabled = NO;
  142. // [self.bottomView.actionButton setTitle:@"确认提交" forState:UIControlStateNormal];
  143. // [self.bottomView.actionButton setBackgroundColor:HexRGB(0xe5e5e5)];
  144. // [self.bottomView.actionButton setTitleColor:HexRGB(0x666666) forState:UIControlStateNormal];
  145. // }
  146. // else {
  147. // self.bottomView.actionButton.userInteractionEnabled = YES;
  148. // [self.bottomView.actionButton setTitle:@"确认提交" forState:UIControlStateNormal];
  149. // [self.bottomView.actionButton setBackgroundColor:THEMECOLOR];
  150. // [self.bottomView.actionButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  151. // }
  152. }
  153. else if ([self.homeworkModel.courseStatus isEqualToString:@"ING"]) {
  154. statusLabel.text = @"进行中";
  155. statusLabel.textColor = THEMECOLOR;
  156. self.bottomView.actionButton.userInteractionEnabled = YES;
  157. [self.bottomView.actionButton setTitle:@"进入教室" forState:UIControlStateNormal];
  158. [self.bottomView.actionButton setBackgroundColor:THEMECOLOR];
  159. [self.bottomView.actionButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  160. }
  161. else {
  162. statusLabel.text = @"未开始";
  163. statusLabel.textColor = HexRGB(0xff802c);
  164. self.bottomView.actionButton.userInteractionEnabled = YES;
  165. [self.bottomView.actionButton setTitle:@"进入教室" forState:UIControlStateNormal];
  166. [self.bottomView.actionButton setBackgroundColor:THEMECOLOR];
  167. [self.bottomView.actionButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  168. }
  169. }
  170. #pragma mark --- table data source
  171. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  172. return 6;
  173. }
  174. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  175. if (indexPath.row == 0) {
  176. AccompanyCourseInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AccompanyCourseInfoCell"];
  177. cell.statusLabel.textColor = HexRGB(0x999999);
  178. [self evaluateWithStatusLabel:cell.statusLabel];
  179. [cell configWithStartTime:self.homeworkModel.startTime endTime:self.homeworkModel.endTime teacherAvatar:self.homeworkModel.teacherAvatar teacherName:self.homeworkModel.teacherName teacherId:self.homeworkModel.teacherId courseSubject:self.homeworkModel.subjectName isMusicRoom:NO];
  180. MJWeakSelf;
  181. [cell chatCalkback:^{
  182. [weakSelf chatAction];
  183. }];
  184. // cell.hideChatButton = YES;
  185. return cell;
  186. }
  187. else if (indexPath.row == 1) {
  188. AccompanyEvaluateCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AccompanyEvaluateCell"];
  189. NSString *message = self.evaluateModel.teacherReplied;
  190. BOOL hasEvaluate = [NSString isEmptyString:self.evaluateModel.teacherReplied] ? NO : YES;
  191. [cell configWithEvaluateMessage:message hasEvaluate:hasEvaluate];
  192. return cell;
  193. }
  194. else if (indexPath.row == 2) {
  195. AccompanyStudentEvaCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AccompanyStudentEvaCell"];
  196. NSString *message = self.evaluateModel.studentReplied;
  197. BOOL hasEvaluate = [NSString isEmptyString:self.evaluateModel.studentReplied] ? NO : YES;
  198. MJWeakSelf;
  199. [cell configWithEvaluateMessage:message starNum:self.evaluateModel.score hasEvaluate:hasEvaluate callback:^{
  200. [weakSelf evaluateCourse];
  201. }];
  202. return cell;
  203. }
  204. else if (indexPath.row == 3) {
  205. AccompanyArrangeCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AccompanyArrangeCell"];
  206. BOOL hasArrange = self.homeworkModel.decorateHomework == 1 ? YES : NO;
  207. [cell configWithHomeworkContent:self.homeworkModel.content hasArrangeHomework:hasArrange];
  208. return cell;
  209. }
  210. else if (indexPath.row == 4) {
  211. // studentAttachments
  212. BOOL canDisplay = self.homeworkModel.decorateHomework == 1 ? YES : NO;
  213. BOOL isExpired = self.homeworkModel.homeworkExpire == 1 ? YES : NO;
  214. AccompanyHomeworkCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AccompanyHomeworkCell"];
  215. cell.canSubmit = NO;
  216. cell.showSubmitButton = self.canModify;
  217. MJWeakSelf;
  218. [cell configWithAttachmentArray:self.fileArray canDisplaySubmitView:canDisplay isExpired:isExpired callback:^(HOMEWORKACTION action, NSInteger viewIndex) {
  219. [weakSelf operationActionWithType:action index:viewIndex];
  220. }];
  221. return cell;
  222. }
  223. else {
  224. AccompanyRemarkCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AccompanyRemarkCell"];
  225. BOOL hasEvaluate = self.homeworkModel.reviewHomework == 1? YES : NO;
  226. [cell configWithRemarkMessage:self.homeworkModel.teacherReplied hasEvaluate:hasEvaluate];
  227. return cell;
  228. }
  229. }
  230. - (void)chatAction {
  231. if (self.homeworkModel && ![NSString isEmptyString:self.homeworkModel.imUserId]) {
  232. TUIChatConversationModel *model = [[TUIChatConversationModel alloc] init];
  233. model.userID = self.homeworkModel.imUserId;
  234. KSChatConversationViewController *ctrl = [[KSChatConversationViewController alloc] init];
  235. ctrl.conversation = model;
  236. [self.navigationController pushViewController:ctrl animated:YES];
  237. }
  238. }
  239. // 课程评价
  240. - (void)evaluateCourse {
  241. if (![self.homeworkModel.courseStatus isEqualToString:@"COMPLETE"]) {
  242. [LOADING_MANAGER MBShowAUTOHidingInWindow:@"课程结束之后才可以评价哦~"];
  243. return;
  244. }
  245. self.alertView = [AccompanyAlertView shareInstance];
  246. self.alertView.alertTitle.text = @"课程评价";
  247. self.alertView.tipsLabel.text = @"请输入您对本次课程的评价~";
  248. self.alertView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight);
  249. [self.alertView showInView:[UIApplication sharedApplication].keyWindow showStarView:YES];
  250. MJWeakSelf;
  251. [self.alertView sureCallback:^(NSString * _Nonnull content, NSInteger starNum) {
  252. [weakSelf evaluateAction:content starNum:starNum];
  253. }];
  254. }
  255. - (void)evaluateAction:(NSString *)content starNum:(NSInteger)starNum {
  256. if ([NSString isEmptyString:content]) {
  257. [LOADING_MANAGER MBShowAUTOHidingInWindow:@"请输入评价内容"];
  258. return;
  259. }
  260. [LOADING_MANAGER showHUD];
  261. [KSNetworkingManager accompanyCourseRepliedRequest:KS_POST courseScheduleId:self.courseId courseGroupId:self.courseGroupId studentReplied:content score:starNum success:^(NSDictionary * _Nonnull dic) {
  262. [LOADING_MANAGER removeHUD];
  263. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  264. [LOADING_MANAGER MBShowAUTOHidingInWindow:@"评价成功"];
  265. [self requestCourseInfoMessage];
  266. }
  267. else {
  268. [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
  269. }
  270. } faliure:^(NSError * _Nonnull error) {
  271. [LOADING_MANAGER removeHUD];
  272. }];
  273. }
  274. - (void)operationActionWithType:(HOMEWORKACTION)action index:(NSInteger)viewIndex {
  275. switch (action) {
  276. case HOMEWORKACTION_PLAY:
  277. {
  278. [self playVideoIndex:viewIndex];
  279. }
  280. break;
  281. case HOMEWORKACTION_DELETE:
  282. {
  283. [self deleteVideoIndex:viewIndex];
  284. }
  285. break;
  286. case HOMEWORKACTION_ADD: // 选择视频作业
  287. {
  288. // 调用相册
  289. self.mediaManager = [[KSMediaManager alloc] init];
  290. self.mediaManager.mediaType = MEDIATYPE_VIDEO;
  291. self.mediaManager.maxPhotoNumber = 1;
  292. self.mediaManager.baseCtrl = self;
  293. self.mediaManager.needCropImage = NO;
  294. MJWeakSelf;
  295. [self.mediaManager noAlertCallback:^(NSString * _Nullable videoUrl, NSMutableArray * _Nullable imageArray, NSMutableArray * _Nullable imageAsset) {
  296. NSLog(@"%@", videoUrl);
  297. // 上传视频
  298. [weakSelf uploadVideoWithUrl:videoUrl];
  299. }];
  300. [self.mediaManager pushImagePickerController];
  301. }
  302. case HOMEWORKACTION_HOMEWOEKPAGE:
  303. {
  304. HomeworkDetailViewController *detalVC = [[HomeworkDetailViewController alloc] init];
  305. detalVC.courseId = self.courseId;
  306. MJWeakSelf;
  307. [detalVC backRefreshAction:^{
  308. [weakSelf requestCourseInfoMessage];
  309. }];
  310. [self.navigationController pushViewController:detalVC animated:YES];
  311. }
  312. default:
  313. break;
  314. }
  315. }
  316. #pragma mark --- 上传视频文件
  317. - (void)uploadVideoWithUrl:(NSString *)videoUrl {
  318. [self hudTipWillShow:YES];
  319. NSURL *uploadFileUrl = [NSURL fileURLWithPath:videoUrl];
  320. NSData *fileData = [NSData dataWithContentsOfURL:uploadFileUrl];
  321. NSString *suffix = [NSString stringWithFormat:@".%@",[uploadFileUrl pathExtension]];
  322. [[KSUploadManager shareInstance] configBucketName:@"homework"];
  323. [[KSUploadManager shareInstance] videoUpload:fileData fileName:@"video" fileSuffix:suffix progress:^(int64_t bytesWritten, int64_t totalBytes) {
  324. dispatch_main_async_safe(^{
  325. // 显示进度
  326. if (self.HUD) {
  327. self.HUD.progress = bytesWritten / totalBytes;// progress是回调进度
  328. }
  329. });
  330. } successCallback:^(NSMutableArray * _Nonnull fileUrlArray) {
  331. [self hudTipWillShow:NO];
  332. NSString *fileUrl = [fileUrlArray lastObject];
  333. self.isModify = YES;
  334. // 删除文件
  335. [self removeVideoWithPath:videoUrl];
  336. [self.fileArray addObject:fileUrl];
  337. [self.tableView reloadData];
  338. } faliure:^(NSError * _Nullable error, NSString * _Nullable descMessaeg) {
  339. [self hudTipWillShow:NO];
  340. if (![NSString isEmptyString:descMessaeg]) {
  341. [LOADING_MANAGER MBShowAUTOHidingInWindow:descMessaeg];
  342. }
  343. }];
  344. }
  345. - (void)removeVideoWithPath:(NSString *)videoUrl {
  346. NSFileManager *fileMamager = [NSFileManager defaultManager];
  347. if ([fileMamager fileExistsAtPath:videoUrl]) {
  348. [fileMamager removeItemAtPath:videoUrl error:nil];
  349. }
  350. }
  351. // 播放
  352. - (void)playVideoIndex:(NSInteger)index {
  353. if (self.fileArray.count > index) {
  354. NSString *fileUrl = self.fileArray[index];
  355. [self playVideoWithUrl:fileUrl];
  356. }
  357. }
  358. // 删除
  359. - (void)deleteVideoIndex:(NSInteger)index {
  360. if (self.fileArray.count > index) {
  361. [self.fileArray removeObjectAtIndex:index];
  362. [self.tableView reloadData];
  363. }
  364. self.isModify = YES;
  365. }
  366. #pragma mark ------ WMPlayer
  367. - (void)playVideoWithUrl:(NSString *)fileUrl {
  368. fileUrl = [fileUrl getUrlEndcodeString];
  369. _playerFrame = CGRectMake(0, iPhoneXSafeTopMargin, kScreenWidth, kScreenHeight - iPhoneXSafeTopMargin - iPhoneXSafeBottomMargin);
  370. _wmPlayer = [[WMPlayer alloc] initWithFrame:_playerFrame];
  371. WMPlayerModel *playModel = [[WMPlayerModel alloc] init];
  372. playModel.videoURL = [NSURL URLWithString:fileUrl];
  373. _wmPlayer.playerModel = playModel;
  374. _wmPlayer.delegate = self;
  375. _bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
  376. _bgView.backgroundColor = [UIColor blackColor];
  377. [[UIApplication sharedApplication].keyWindow addSubview:_bgView];
  378. [[UIApplication sharedApplication].keyWindow addSubview:_wmPlayer];
  379. [[UIApplication sharedApplication].keyWindow bringSubviewToFront:_wmPlayer];
  380. [_wmPlayer play];
  381. }
  382. - (void)wmplayer:(WMPlayer *)wmplayer clickedCloseButton:(UIButton *)backBtn {
  383. [wmplayer removePlayer];
  384. [_bgView removeFromSuperview];
  385. [self setNeedsStatusBarAppearanceUpdate];
  386. }
  387. - (void)wmplayer:(WMPlayer *)wmplayer clickedFullScreenButton:(UIButton *)fullScreenBtn {
  388. self.isRatation = !self.isRatation;
  389. if (self.isRatation) {
  390. [wmplayer removeFromSuperview];
  391. [UIView animateWithDuration:1.0f animations:^{
  392. wmplayer.transform = CGAffineTransformMakeRotation(M_PI_2);
  393. } completion:^(BOOL finished) {
  394. wmplayer.frame = CGRectMake(0, iPhoneXSafeTopMargin, kScreenWidth, kScreenHeight - iPhoneXSafeTopMargin - iPhoneXSafeBottomMargin);
  395. [[UIApplication sharedApplication].keyWindow addSubview:wmplayer];
  396. [[UIApplication sharedApplication].keyWindow bringSubviewToFront:wmplayer];
  397. }];
  398. }
  399. else {
  400. [wmplayer removeFromSuperview];
  401. [UIView animateWithDuration:1.0f animations:^{
  402. // 复原
  403. wmplayer.transform = CGAffineTransformIdentity;
  404. } completion:^(BOOL finished) {
  405. wmplayer.frame = CGRectMake(0, iPhoneXSafeTopMargin, kScreenWidth, kScreenHeight - iPhoneXSafeTopMargin - iPhoneXSafeBottomMargin);
  406. [[UIApplication sharedApplication].keyWindow addSubview:wmplayer];
  407. [[UIApplication sharedApplication].keyWindow bringSubviewToFront:wmplayer];
  408. }];
  409. }
  410. }
  411. - (void)bottomButtonAction {
  412. // 判断
  413. if ([self.homeworkModel.courseStatus isEqualToString:@"COMPLETE"]) { // 判断是否能提交作业
  414. if (self.fileArray.count == 0 || self.homeworkModel.reviewHomework == 1 || self.homeworkModel.decorateHomework == 0) {
  415. return;
  416. }
  417. else { // 提交作业
  418. [self submitHomeworkAction];
  419. }
  420. }
  421. else {
  422. [self tryJoinRoom];
  423. }
  424. }
  425. - (void)submitHomeworkAction {
  426. if (self.homeworkModel.homeworkExpire == 1) {
  427. [LOADING_MANAGER MBShowAUTOHidingInWindow:@"作业已过期无法提交和查看!"];
  428. return;
  429. }
  430. if (self.isModify == NO) {
  431. [LOADING_MANAGER MBShowAUTOHidingInWindow:@"请先选择视频文件"];
  432. return;
  433. }
  434. if (self.fileArray.count == 0) {
  435. [LOADING_MANAGER MBShowAUTOHidingInWindow:@"请选择作业视频"];
  436. return;
  437. }
  438. NSString *attachment = [self.fileArray componentsJoinedByString:@","];
  439. [LOADING_MANAGER showHUD];
  440. [KSNetworkingManager homeSubmitAction:KS_POST courseScheduleId:self.courseId attachment:attachment success:^(NSDictionary * _Nonnull dic) {
  441. [LOADING_MANAGER removeHUD];
  442. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  443. [LOADING_MANAGER MBShowAUTOHidingInWindow:@"作业提交成功"];
  444. [self requestCourseInfoMessage];
  445. self.isModify = NO;
  446. }
  447. else {
  448. [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
  449. }
  450. } faliure:^(NSError * _Nonnull error) {
  451. [LOADING_MANAGER removeHUD];
  452. }];
  453. }
  454. #pragma mark --- lazying
  455. - (OnlineClassManager *)classManager {
  456. if (!_classManager) {
  457. _classManager = [[OnlineClassManager alloc] init];
  458. }
  459. return _classManager;
  460. }
  461. - (AccompanyDetailBottomView *)bottomView {
  462. if (!_bottomView) {
  463. _bottomView = [AccompanyDetailBottomView shareInstance];
  464. _bottomView.frame = CGRectMake(0, 0, kScreenWidth, 70);
  465. MJWeakSelf;
  466. [_bottomView sureAction:^{
  467. [weakSelf bottomButtonAction];
  468. }];
  469. }
  470. return _bottomView;
  471. }
  472. - (UITableView *)tableView {
  473. if (!_tableView) {
  474. _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
  475. _tableView.backgroundColor = [UIColor clearColor];
  476. _tableView.delegate = self;
  477. _tableView.dataSource = self;
  478. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  479. _tableView.showsHorizontalScrollIndicator = NO;
  480. _tableView.showsVerticalScrollIndicator = NO;
  481. _tableView.rowHeight = UITableViewAutomaticDimension;
  482. _tableView.estimatedRowHeight = 136.0f;
  483. [_tableView registerNib:[UINib nibWithNibName:@"AccompanyCourseInfoCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"AccompanyCourseInfoCell"];
  484. [_tableView registerNib:[UINib nibWithNibName:@"AccompanyEvaluateCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"AccompanyEvaluateCell"];
  485. [_tableView registerNib:[UINib nibWithNibName:@"AccompanyStudentEvaCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"AccompanyStudentEvaCell"];
  486. [_tableView registerNib:[UINib nibWithNibName:@"AccompanyArrangeCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"AccompanyArrangeCell"];
  487. [_tableView registerNib:[UINib nibWithNibName:@"AccompanyHomeworkCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"AccompanyHomeworkCell"];
  488. [_tableView registerNib:[UINib nibWithNibName:@"AccompanyRemarkCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"AccompanyRemarkCell"];
  489. _tableView.tableFooterView = self.bottomView;
  490. }
  491. return _tableView;
  492. }
  493. - (void)hudTipWillShow:(BOOL)willShow{
  494. if (willShow) {
  495. [self resignFirstResponder];
  496. UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
  497. if (!_HUD) {
  498. _HUD = [MBProgressHUD showHUDAddedTo:keyWindow animated:YES];
  499. _HUD.removeFromSuperViewOnHide = YES;
  500. _HUD.mode = MBProgressHUDModeDeterminateHorizontalBar;
  501. _HUD.label.text = @"正在上传视频文件...";
  502. _HUD.contentColor = [UIColor whiteColor];
  503. _HUD.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
  504. _HUD.bezelView.backgroundColor = [UIColor colorWithHexString:@"#000000" alpha:0.8];
  505. }else{
  506. _HUD.progress = 0;
  507. [keyWindow addSubview:_HUD];
  508. [_HUD showAnimated:YES];
  509. }
  510. }else{
  511. [_HUD hideAnimated:YES];
  512. }
  513. }
  514. - (void)tryJoinRoom {
  515. NSDateFormatter *dateFormatter = [NSObject getDateformatter];
  516. [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
  517. NSDate *beginDate = [dateFormatter dateFromString:self.homeworkModel.startTime];
  518. NSDate *endDate = [dateFormatter dateFromString:self.homeworkModel.endTime];
  519. NSDate *currentDate = [NSDate date];
  520. NSTimeInterval beginTimeInterval = [beginDate timeIntervalSinceDate:currentDate];
  521. NSTimeInterval endTimeInterval = [currentDate timeIntervalSinceDate:endDate];
  522. if (beginTimeInterval <= self.joinRoomBeforeTime * 60 && endTimeInterval < 0) {
  523. [self joinClassRoom];
  524. }
  525. else if (endTimeInterval > 0) {
  526. [LOADING_MANAGER MBShowAUTOHidingInWindow:@"该课程已结束"];
  527. }
  528. else {
  529. NSString *tipsString = [NSString stringWithFormat:@"课程还未开始,请在上课前%zd分钟进入", self.joinRoomBeforeTime];
  530. [LOADING_MANAGER MBShowAUTOHidingInWindow:tipsString];
  531. }
  532. }
  533. // 加入房间
  534. - (void)joinClassRoom {
  535. // 加入房间前判断摄像头和麦克风逻辑
  536. PREMISSIONTYPE micEnable = [RecordCheckManager checkPermissionShowAlert:NO showInView:nil];
  537. PREMISSIONTYPE cameraEnable = [RecordCheckManager checkCameraPremissionAvaiable:NO showInView:nil];
  538. if (micEnable == PREMISSIONTYPE_YES && cameraEnable == PREMISSIONTYPE_YES) {
  539. // 进入教室
  540. // 判断是否进行课前检测
  541. [self.classManager joinRoomWithId:self.courseId subjectName:self.homeworkModel.subjectName classEndTime:self.homeworkModel.endTime inViewController:self];
  542. }
  543. else {
  544. if (micEnable == PREMISSIONTYPE_NO && cameraEnable == PREMISSIONTYPE_NO) { // 如果麦克风权限和摄像头权限都没有
  545. [self showAlertWithMessage:@"请开启相机和麦克风访问权限" type:CHECKDEVICETYPE_BOTH];
  546. }
  547. else if (micEnable == PREMISSIONTYPE_NO) { // 如果没有麦克风权限
  548. [self showAlertWithMessage:@"请开启麦克风访问权限" type:CHECKDEVICETYPE_MIC];
  549. }
  550. else if (cameraEnable == PREMISSIONTYPE_NO) { // 如果没有摄像头权限
  551. [self showAlertWithMessage:@"请开启相机访问权限" type:CHECKDEVICETYPE_CAMREA];
  552. }
  553. }
  554. }
  555. - (void)showAlertWithMessage:(NSString *)message type:(CHECKDEVICETYPE)deviceType {
  556. [KSPremissionAlert shareInstanceDisplayImage:deviceType message:message showInView:self.view cancel:^{
  557. } confirm:^{
  558. [self openSettingView];
  559. }];
  560. }
  561. - (void)openSettingView {
  562. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:@{} completionHandler:nil];
  563. }
  564. /*
  565. #pragma mark - Navigation
  566. // In a storyboard-based application, you will often want to do a little preparation before navigation
  567. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  568. // Get the new view controller using [segue destinationViewController].
  569. // Pass the selected object to the new view controller.
  570. }
  571. */
  572. @end