VipCouseDetailViewController.m 26 KB

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