AccompanyDetailViewController.m 27 KB

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