AccompanyDetailViewController.m 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  1. //
  2. // AccompanyDetailViewController.m
  3. // KulexiuForTeacher
  4. //
  5. // Created by 王智 on 2022/4/6.
  6. //
  7. #import "AccompanyDetailViewController.h"
  8. #import "AccompanyNavView.h"
  9. #import "AccompanyAlertView.h"
  10. #import "AccompanyCourseInfoCell.h"
  11. #import "AccompanyEvaluateCell.h"
  12. #import "AccompanyStudentEvaCell.h"
  13. #import "AccompanyArrangeCell.h"
  14. #import "AccompanyHomeworkCell.h"
  15. #import "AccompanyRemarkCell.h"
  16. #import "HomeworkDetailModel.h"
  17. #import "EvaluateDetailModel.h"
  18. #import "AccompanyDetailBottomView.h"
  19. #import "KSChatConversationViewController.h"
  20. #import <WMPlayer.h>
  21. #import <RecordCheckManager.h>
  22. #import "KSPremissionAlert.h"
  23. #import "OnlineClassManager.h"
  24. @interface AccompanyDetailViewController ()<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) AccompanyNavView *navView;
  32. @property (nonatomic, strong) UITableView *tableView;
  33. @property (nonatomic, strong) HomeworkDetailModel *homeworkModel;
  34. @property (nonatomic, strong) EvaluateDetailModel *evaluateModel;
  35. @property (nonatomic, strong) AccompanyDetailBottomView *bottomView;
  36. @property (nonatomic, strong) AccompanyAlertView *alertView;
  37. @property (nonatomic, strong) NSMutableArray *fileArray;
  38. @property (nonatomic, strong) OnlineClassManager *classManager;
  39. @end
  40. @implementation AccompanyDetailViewController
  41. - (void)viewDidLoad {
  42. [super viewDidLoad];
  43. // Do any additional setup after loading the view.
  44. self.ks_prefersNavigationBarHidden = YES;
  45. [self configUI];
  46. }
  47. - (void)requestCourseInfoMessage {
  48. [self requestHomeworkMessage];
  49. [self requestEvaluateMessage];
  50. [self requestRoomConfig];
  51. }
  52. - (void)viewWillAppear:(BOOL)animated {
  53. [super viewWillAppear:animated];
  54. [self requestCourseInfoMessage];
  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:@"practiceStartTime"];
  61. self.quitRomeEndTime = [result ks_integerValueForKey:@"practiceEndTime"];
  62. }
  63. else {
  64. [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
  65. }
  66. } faliure:^(NSError * _Nonnull error) {
  67. }];
  68. }
  69. - (void)requestHomeworkMessage {
  70. [KSNetworkingManager homeworkDetailRequest:KS_GET courseId:self.courseId studentId:self.studentId success:^(NSDictionary * _Nonnull dic) {
  71. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  72. self.homeworkModel = [[HomeworkDetailModel alloc] initWithDictionary:[dic ks_dictionaryValueForKey:@"data"]];
  73. if (self.homeworkModel.submitHomework == 1) {
  74. if (![NSString isEmptyString:self.homeworkModel.studentAttachments]) {
  75. self.fileArray = [NSMutableArray arrayWithArray:[self.homeworkModel.studentAttachments componentsSeparatedByString:@","]];
  76. }
  77. else {
  78. self.fileArray = [NSMutableArray array];
  79. }
  80. }
  81. else {
  82. self.fileArray = [NSMutableArray array];
  83. }
  84. }
  85. else {
  86. [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
  87. }
  88. [self evaluateViewDisplay];
  89. [self.tableView reloadData];
  90. } faliure:^(NSError * _Nonnull error) {
  91. }];
  92. }
  93. - (void)requestEvaluateMessage {
  94. [KSNetworkingManager selectRepliedRequest:KS_POST courseGroupId:self.courseGroupId courseScheduleId:self.courseId studentId:self.studentId success:^(NSDictionary * _Nonnull dic) {
  95. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  96. self.evaluateModel = [[EvaluateDetailModel alloc] initWithDictionary:[dic ks_dictionaryValueForKey:@"data"]];
  97. }
  98. else {
  99. [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
  100. }
  101. [self.tableView reloadData];
  102. } faliure:^(NSError * _Nonnull error) {
  103. }];
  104. }
  105. - (void)configUI {
  106. [self.scrollView removeFromSuperview];
  107. [self.view addSubview:self.navView];
  108. CGFloat height = [self.navView getViewHeight];
  109. [self.navView mas_makeConstraints:^(MASConstraintMaker *make) {
  110. make.left.right.top.mas_equalTo(self.view);
  111. make.height.mas_equalTo(height);
  112. }];
  113. [self.view addSubview:self.tableView];
  114. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  115. make.left.right.mas_equalTo(self.view);
  116. make.top.mas_equalTo(self.view.mas_top).offset(kNaviBarHeight);
  117. make.bottom.mas_equalTo(self.view.mas_bottom).offset(-iPhoneXSafeBottomMargin);
  118. }];
  119. }
  120. - (void)evaluateViewDisplay {
  121. if ([self.homeworkModel.courseStatus isEqualToString:@"COMPLETE"]) {
  122. self.tableView.tableFooterView = [UIView new];
  123. }
  124. else {
  125. self.tableView.tableFooterView = self.bottomView;
  126. self.bottomView.sureButton.userInteractionEnabled = YES;
  127. [self.bottomView.sureButton setTitle:@"进入教室" forState:UIControlStateNormal];
  128. [self.bottomView.sureButton setBackgroundColor:THEMECOLOR];
  129. [self.bottomView.sureButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  130. }
  131. }
  132. - (void)evaluateWithStatusLabel:(UILabel *)statusLabel {
  133. if ([self.homeworkModel.courseStatus isEqualToString:@"COMPLETE"]) {
  134. statusLabel.text = @"已结束";
  135. statusLabel.textColor = HexRGB(0x999999);
  136. }
  137. else if ([self.homeworkModel.courseStatus isEqualToString:@"ING"]) {
  138. statusLabel.text = @"进行中";
  139. statusLabel.textColor = THEMECOLOR;
  140. }
  141. else {
  142. statusLabel.text = @"未开始";
  143. statusLabel.textColor = HexRGB(0xff802c);
  144. }
  145. }
  146. #pragma mark --- table data source
  147. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  148. return 6;
  149. }
  150. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  151. if (indexPath.row == 0) {
  152. AccompanyCourseInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AccompanyCourseInfoCell"];
  153. [self evaluateWithStatusLabel:cell.statusLabel];
  154. [cell configWithStartTime:self.homeworkModel.startTime endTime:self.homeworkModel.endTime studentAvatar:self.homeworkModel.studentAvatar studentName:self.homeworkModel.studentName studentId:self.homeworkModel.studentId studentSubject:self.homeworkModel.subjectName];
  155. cell.hideChatButton = NO;
  156. MJWeakSelf;
  157. [cell chatCalkback:^{
  158. [weakSelf chatAction];
  159. }];
  160. return cell;
  161. }
  162. else if (indexPath.row == 1) {
  163. AccompanyEvaluateCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AccompanyEvaluateCell"];
  164. NSString *message = self.evaluateModel.teacherReplied;
  165. BOOL hasEvaluate = [NSString isEmptyString:self.evaluateModel.teacherReplied] ? NO : YES;
  166. MJWeakSelf;
  167. [cell configWithEvaluateMessage:message hasEvaluate:hasEvaluate callback:^{
  168. [weakSelf evaluateCourse];
  169. }];
  170. return cell;
  171. }
  172. else if (indexPath.row == 2) {
  173. AccompanyStudentEvaCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AccompanyStudentEvaCell"];
  174. NSString *message = self.evaluateModel.studentReplied;
  175. BOOL hasEvaluate = [NSString isEmptyString:self.evaluateModel.studentReplied] ? NO : YES;
  176. [cell configWithEvaluateMessage:message starNum:self.evaluateModel.score hasEvaluate:hasEvaluate];
  177. return cell;
  178. }
  179. else if (indexPath.row == 3) {
  180. AccompanyArrangeCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AccompanyArrangeCell"];
  181. BOOL hasArrange = self.homeworkModel.decorateHomework == 1 ? YES : NO;
  182. MJWeakSelf;
  183. [cell configWithHomeworkContent:self.homeworkModel.content hasArrangeHomework:hasArrange callback:^{
  184. [weakSelf arrangeHomework];
  185. }];
  186. return cell;
  187. }
  188. else if (indexPath.row == 4) {
  189. BOOL hasSubmitHomework = self.homeworkModel.submitHomework == 1 ? YES : NO;
  190. BOOL isExpired = self.homeworkModel.homeworkExpire == 1 ? YES : NO;
  191. AccompanyHomeworkCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AccompanyHomeworkCell"];
  192. MJWeakSelf;
  193. [cell configWithAttachmentArray:self.fileArray hasSubmit:hasSubmitHomework isExpired:isExpired callback:^(NSInteger viewIndex) {
  194. [weakSelf playVideoIndex:viewIndex];
  195. }];
  196. return cell;
  197. }
  198. else {
  199. AccompanyRemarkCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AccompanyRemarkCell"];
  200. BOOL hasEvaluate = self.homeworkModel.reviewHomework == 1? YES : NO;
  201. MJWeakSelf;
  202. [cell configWithRemarkMessage:self.homeworkModel.teacherReplied hasEvaluate:hasEvaluate callback:^{
  203. [weakSelf evaluateHomework];
  204. }];
  205. return cell;
  206. }
  207. }
  208. - (void)chatAction {
  209. if (self.homeworkModel && ![NSString isEmptyString:self.homeworkModel.imUserId]) {
  210. TUIChatConversationModel *model = [[TUIChatConversationModel alloc] init];
  211. model.userID = self.homeworkModel.imUserId;
  212. KSChatConversationViewController *ctrl = [[KSChatConversationViewController alloc] init];
  213. ctrl.conversation = model;
  214. [self.navigationController pushViewController:ctrl animated:YES];
  215. }
  216. }
  217. - (void)evaluateCourse {
  218. if (![self.homeworkModel.courseStatus isEqualToString:@"COMPLETE"]) {
  219. [LOADING_MANAGER MBShowAUTOHidingInWindow:@"课程结束之后才可以评价哦~"];
  220. return;
  221. }
  222. self.alertView = [AccompanyAlertView shareInstance];
  223. self.alertView.alertTitle.text = @"评价学员";
  224. self.alertView.tipsLabel.text = @"请输入您对本次课程学员表现的评价";
  225. self.alertView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight);
  226. [self.alertView showInView:[UIApplication sharedApplication].keyWindow showStarView:NO];
  227. MJWeakSelf;
  228. [self.alertView sureCallback:^(NSString * _Nonnull content, NSInteger starNum) {
  229. [weakSelf evaluateAction:content];
  230. }];
  231. }
  232. - (void)evaluateAction:(NSString *)content {
  233. if ([NSString isEmptyString:content]) {
  234. [LOADING_MANAGER MBShowAUTOHidingInWindow:@"请输入评价内容"];
  235. return;
  236. }
  237. [LOADING_MANAGER showHUD];
  238. [KSNetworkingManager teacherCourseRepliedRequest:KS_POST courseScheduleId:self.courseId courseGroupId:self.courseGroupId studentId:self.studentId teacherReplied:content success:^(NSDictionary * _Nonnull dic) {
  239. [LOADING_MANAGER removeHUD];
  240. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  241. [LOADING_MANAGER MBShowAUTOHidingInWindow:@"评价成功"];
  242. [self requestCourseInfoMessage];
  243. }
  244. else {
  245. [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
  246. }
  247. } faliure:^(NSError * _Nonnull error) {
  248. [LOADING_MANAGER removeHUD];
  249. }];
  250. }
  251. - (void)arrangeHomework {
  252. if (![self.homeworkModel.courseStatus isEqualToString:@"COMPLETE"]) {
  253. [LOADING_MANAGER MBShowAUTOHidingInWindow:@"课程结束之后才可以布置作业哦~"];
  254. return;
  255. }
  256. self.alertView = [AccompanyAlertView shareInstance];
  257. self.alertView.alertTitle.text = @"布置作业";
  258. self.alertView.tipsLabel.text = @"请输入本次课程作业内容";
  259. self.alertView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight);
  260. [self.alertView showInView:[UIApplication sharedApplication].keyWindow showStarView:NO];
  261. MJWeakSelf;
  262. [self.alertView sureCallback:^(NSString * _Nonnull content, NSInteger starNum) {
  263. [weakSelf arrangeAction:content];
  264. }];
  265. }
  266. - (void)arrangeAction:(NSString *)homeworkContent {
  267. [LOADING_MANAGER showHUD];
  268. [KSNetworkingManager homeworkDecorateRequest:KS_POST content:homeworkContent courseScheduleId:self.courseId success:^(NSDictionary * _Nonnull dic) {
  269. [LOADING_MANAGER removeHUD];
  270. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  271. [LOADING_MANAGER MBShowAUTOHidingInWindow:@"布置成功"];
  272. [self requestCourseInfoMessage];
  273. }
  274. else {
  275. [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
  276. }
  277. } faliure:^(NSError * _Nonnull error) {
  278. [LOADING_MANAGER removeHUD];
  279. }];
  280. }
  281. // 评价作业
  282. - (void)evaluateHomework {
  283. if (self.homeworkModel.decorateHomework == 0) {
  284. [LOADING_MANAGER MBShowAUTOHidingInWindow:@"您还未布置作业"];
  285. return;
  286. }
  287. else if (self.homeworkModel.submitHomework == 0) {
  288. [LOADING_MANAGER MBShowAUTOHidingInWindow:@"学生还未提交作业"];
  289. return;
  290. }
  291. self.alertView = [AccompanyAlertView shareInstance];
  292. self.alertView.alertTitle.text = @"作业点评";
  293. self.alertView.tipsLabel.text = @"请输入您对本次作业的点评";
  294. self.alertView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight);
  295. [self.alertView showInView:[UIApplication sharedApplication].keyWindow showStarView:NO];
  296. MJWeakSelf;
  297. [self.alertView sureCallback:^(NSString * _Nonnull content, NSInteger starNum) {
  298. [weakSelf commentAction:content];
  299. }];
  300. }
  301. - (void)commentAction:(NSString *)commentMessage {
  302. [LOADING_MANAGER showHUD];
  303. [KSNetworkingManager homeworkReviewRequest:KS_POST courseScheduleId:self.courseId studentId:self.studentId review:commentMessage success:^(NSDictionary * _Nonnull dic) {
  304. [LOADING_MANAGER removeHUD];
  305. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  306. [LOADING_MANAGER MBShowAUTOHidingInWindow:@"点评成功"];
  307. [self requestCourseInfoMessage];
  308. }
  309. else {
  310. [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
  311. }
  312. } faliure:^(NSError * _Nonnull error) {
  313. [LOADING_MANAGER removeHUD];
  314. }];
  315. }
  316. - (void)playVideoIndex:(NSInteger)index {
  317. if (self.fileArray.count > index) {
  318. NSString *fileUrl = self.fileArray[index];
  319. [self playVideoWithUrl:fileUrl];
  320. }
  321. }
  322. #pragma mark ------ WMPlayer
  323. - (void)playVideoWithUrl:(NSString *)fileUrl {
  324. fileUrl = [fileUrl getUrlEndcodeString];
  325. _playerFrame = CGRectMake(0, iPhoneXSafeTopMargin, kScreenWidth, kScreenHeight - iPhoneXSafeTopMargin - iPhoneXSafeBottomMargin);
  326. _wmPlayer = [[WMPlayer alloc] initWithFrame:_playerFrame];
  327. WMPlayerModel *playModel = [[WMPlayerModel alloc] init];
  328. playModel.videoURL = [NSURL URLWithString:fileUrl];
  329. _wmPlayer.playerModel = playModel;
  330. _wmPlayer.delegate = self;
  331. _wmPlayer.tintColor = THEMECOLOR;
  332. _bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
  333. _bgView.backgroundColor = [UIColor blackColor];
  334. [[UIApplication sharedApplication].keyWindow addSubview:_bgView];
  335. [[UIApplication sharedApplication].keyWindow addSubview:_wmPlayer];
  336. [[UIApplication sharedApplication].keyWindow bringSubviewToFront:_wmPlayer];
  337. [_wmPlayer play];
  338. }
  339. - (void)wmplayer:(WMPlayer *)wmplayer clickedCloseButton:(UIButton *)backBtn {
  340. [wmplayer removePlayer];
  341. [_bgView removeFromSuperview];
  342. [self setNeedsStatusBarAppearanceUpdate];
  343. }
  344. - (void)wmplayer:(WMPlayer *)wmplayer clickedFullScreenButton:(UIButton *)fullScreenBtn {
  345. self.isRatation = !self.isRatation;
  346. if (self.isRatation) {
  347. [wmplayer removeFromSuperview];
  348. [UIView animateWithDuration:1.0f animations:^{
  349. wmplayer.transform = CGAffineTransformMakeRotation(M_PI_2);
  350. } completion:^(BOOL finished) {
  351. wmplayer.frame = CGRectMake(0, iPhoneXSafeTopMargin, kScreenWidth, kScreenHeight - iPhoneXSafeTopMargin - iPhoneXSafeBottomMargin);
  352. [[UIApplication sharedApplication].keyWindow addSubview:wmplayer];
  353. [[UIApplication sharedApplication].keyWindow bringSubviewToFront:wmplayer];
  354. }];
  355. }
  356. else {
  357. [wmplayer removeFromSuperview];
  358. [UIView animateWithDuration:1.0f animations:^{
  359. // 复原
  360. wmplayer.transform = CGAffineTransformIdentity;
  361. } completion:^(BOOL finished) {
  362. wmplayer.frame = CGRectMake(0, iPhoneXSafeTopMargin, kScreenWidth, kScreenHeight - iPhoneXSafeTopMargin - iPhoneXSafeBottomMargin);
  363. [[UIApplication sharedApplication].keyWindow addSubview:wmplayer];
  364. [[UIApplication sharedApplication].keyWindow bringSubviewToFront:wmplayer];
  365. }];
  366. }
  367. }
  368. #pragma mark --- lazying
  369. - (OnlineClassManager *)classManager {
  370. if (!_classManager) {
  371. _classManager = [[OnlineClassManager alloc] init];
  372. }
  373. return _classManager;
  374. }
  375. - (UITableView *)tableView {
  376. if (!_tableView) {
  377. _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
  378. _tableView.delegate = self;
  379. _tableView.dataSource = self;
  380. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  381. _tableView.showsVerticalScrollIndicator = NO;
  382. _tableView.showsHorizontalScrollIndicator = NO;
  383. _tableView.backgroundColor = [UIColor clearColor];
  384. _tableView.rowHeight = UITableViewAutomaticDimension;
  385. [_tableView registerNib:[UINib nibWithNibName:@"AccompanyCourseInfoCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"AccompanyCourseInfoCell"];
  386. [_tableView registerNib:[UINib nibWithNibName:@"AccompanyEvaluateCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"AccompanyEvaluateCell"];
  387. [_tableView registerNib:[UINib nibWithNibName:@"AccompanyStudentEvaCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"AccompanyStudentEvaCell"];
  388. [_tableView registerNib:[UINib nibWithNibName:@"AccompanyArrangeCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"AccompanyArrangeCell"];
  389. [_tableView registerNib:[UINib nibWithNibName:@"AccompanyHomeworkCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"AccompanyHomeworkCell"];
  390. [_tableView registerNib:[UINib nibWithNibName:@"AccompanyRemarkCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"AccompanyRemarkCell"];
  391. _tableView.estimatedRowHeight = 136.0f;
  392. self.bottomView.frame = CGRectMake(0, 0, kScreenWidth, 70);
  393. _tableView.tableFooterView = self.bottomView;
  394. }
  395. return _tableView;
  396. }
  397. - (AccompanyNavView *)navView {
  398. if (!_navView) {
  399. _navView = [AccompanyNavView shareInstance];
  400. MJWeakSelf;
  401. [_navView navCallback:^{
  402. [weakSelf backAction];
  403. }];
  404. }
  405. return _navView;
  406. }
  407. - (AccompanyDetailBottomView *)bottomView {
  408. if (!_bottomView) {
  409. _bottomView = [AccompanyDetailBottomView shareInstance];
  410. MJWeakSelf;
  411. [_bottomView joinroomCallback:^{
  412. [weakSelf tryJoinRoom];
  413. }];
  414. }
  415. return _bottomView;
  416. }
  417. - (void)tryJoinRoom {
  418. NSDateFormatter *dateFormatter = [NSObject getDateformatter];
  419. [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
  420. NSDate *beginDate = [dateFormatter dateFromString:self.homeworkModel.startTime];
  421. NSDate *endDate = [dateFormatter dateFromString:self.homeworkModel.endTime];
  422. NSDate *currentDate = [NSDate date];
  423. NSTimeInterval beginTimeInterval = [beginDate timeIntervalSinceDate:currentDate];
  424. NSTimeInterval endTimeInterval = [currentDate timeIntervalSinceDate:endDate];
  425. if (beginTimeInterval <= self.joinRoomBeforeTime * 60 && endTimeInterval < 0) {
  426. [self joinClassRoom];
  427. }
  428. else if (endTimeInterval > 0) {
  429. [LOADING_MANAGER MBShowAUTOHidingInWindow:@"该课程已结束"];
  430. }
  431. else {
  432. NSString *tipsString = [NSString stringWithFormat:@"课程还未开始,请在上课前%zd分钟进入", self.joinRoomBeforeTime];
  433. [LOADING_MANAGER MBShowAUTOHidingInWindow:tipsString];
  434. }
  435. }
  436. // 加入房间
  437. - (void)joinClassRoom {
  438. // 加入房间前判断摄像头和麦克风逻辑
  439. [RecordCheckManager checkCameraPremissionAvaiableCallback:^(PREMISSIONTYPE type) {
  440. [self afterCheckCameraCheckMic:type];
  441. }];
  442. }
  443. - (void)afterCheckCameraCheckMic:(PREMISSIONTYPE)cameraType {
  444. [RecordCheckManager checkMicPermissionAvaiableCallback:^(PREMISSIONTYPE type) {
  445. if (type == PREMISSIONTYPE_YES && cameraType == PREMISSIONTYPE_YES) {
  446. // 判断是否进行课前检测
  447. [self.classManager joinRoomWithId:self.courseId subjectName:self.homeworkModel.subjectName classEndTime:self.homeworkModel.endTime inViewController:self];
  448. }
  449. else {
  450. NSString *content = @"";
  451. CHECKDEVICETYPE checkType = CHECKDEVICETYPE_BOTH;
  452. if (cameraType == PREMISSIONTYPE_NO && type == PREMISSIONTYPE_NO) {
  453. content = @"请开启相机和麦克风访问权限";
  454. checkType = CHECKDEVICETYPE_BOTH;
  455. }
  456. else if (cameraType == PREMISSIONTYPE_NO && type == PREMISSIONTYPE_YES) {
  457. content = @"请开启相机访问权限";
  458. checkType = CHECKDEVICETYPE_CAMREA;
  459. }
  460. else if (cameraType == PREMISSIONTYPE_YES && type == PREMISSIONTYPE_NO) {
  461. content = @"请开启麦克风访问权限";
  462. checkType = CHECKDEVICETYPE_MIC;
  463. }
  464. [self showAlertWithMessage:content type:checkType];
  465. }
  466. }];
  467. }
  468. - (void)showAlertWithMessage:(NSString *)message type:(CHECKDEVICETYPE)deviceType {
  469. [KSPremissionAlert shareInstanceDisplayImage:deviceType message:message showInView:self.view cancel:^{
  470. } confirm:^{
  471. [self openSettingView];
  472. }];
  473. }
  474. - (void)openSettingView {
  475. if (@available(iOS 10, *)) {
  476. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:@{} completionHandler:nil];
  477. } else {
  478. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
  479. }
  480. }
  481. /*
  482. #pragma mark - Navigation
  483. // In a storyboard-based application, you will often want to do a little preparation before navigation
  484. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  485. // Get the new view controller using [segue destinationViewController].
  486. // Pass the selected object to the new view controller.
  487. }
  488. */
  489. @end