MusicRoomDetailViewController.m 22 KB

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