MusicRoomDetailViewController.m 23 KB

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