VipCouseDetailViewController.m 26 KB

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