MusicRoomDetailViewController.m 23 KB

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