MusicRoomViewController.m 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. //
  2. // MusicRoomViewController.m
  3. // KulexiuForTeacher
  4. //
  5. // Created by 王智 on 2022/6/14.
  6. //
  7. #import "MusicRoomViewController.h"
  8. #import "MusicRoomDetailModel.h"
  9. #import "MusicRoomCourseInfoCell.h"
  10. #import "AccompanyDetailBottomView.h"
  11. #import <RecordCheckManager.h>
  12. #import "KSPremissionAlert.h"
  13. #import "OnlineClassManager.h"
  14. #import "AccompanyArrangeCell.h"
  15. #import "MusicRoomStudentCell.h"
  16. #import "CourseGroupPlanAlertView.h"
  17. #import "KSGroupConversationController.h"
  18. #import "HomeworkDetailViewController.h"
  19. #import "CourseGroupNavView.h"
  20. @interface MusicRoomViewController ()<UITableViewDelegate,UITableViewDataSource>
  21. @property (nonatomic, strong) CourseGroupNavView *navView;
  22. @property (nonatomic, assign) NSInteger joinRoomBeforeTime; // 上课开始时间
  23. @property (nonatomic, assign) NSInteger quitRomeEndTime; // 下课截止时间
  24. @property (nonatomic, strong) UIView *bgView;
  25. @property (nonatomic, strong) MusicRoomDetailModel *detailModel;
  26. @property (nonatomic, strong) UITableView *tableView;
  27. @property (nonatomic, strong) OnlineClassManager *classManager;
  28. @property (nonatomic, strong) AccompanyDetailBottomView *bottomView;
  29. @property (nonatomic, strong) CourseGroupPlanAlertView *alertView;
  30. @property (nonatomic, strong) NSMutableArray *studentArray;
  31. @end
  32. @implementation MusicRoomViewController
  33. - (void)viewDidLoad {
  34. [super viewDidLoad];
  35. // Do any additional setup after loading the view.
  36. self.ks_prefersNavigationBarHidden = YES;
  37. [self allocTitle:@"课程详情"];
  38. [self configUI];
  39. }
  40. - (void)configUI {
  41. [self.scrollView removeFromSuperview];
  42. UIImage *bgImage = [UIImage imageNamed:@"homework_detail_bg"];
  43. CGFloat height = bgImage.size.height / bgImage.size.width * KPortraitWidth;
  44. UIImageView *imageView = [[UIImageView alloc] initWithImage:bgImage];
  45. imageView.frame = CGRectMake(0, 0, KPortraitWidth, height);
  46. [self.view addSubview:imageView];
  47. [self.view addSubview:self.navView];
  48. CGFloat navHeight = [CourseGroupNavView getViewHeight];
  49. [self.navView mas_makeConstraints:^(MASConstraintMaker *make) {
  50. make.left.right.top.mas_equalTo(self.view);
  51. make.height.mas_equalTo(navHeight);
  52. }];
  53. [self.view addSubview:self.tableView];
  54. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  55. make.left.right.mas_equalTo(self.view);
  56. make.top.mas_equalTo(self.navView.mas_bottom);
  57. make.bottom.mas_equalTo(self.view.mas_bottom);
  58. }];
  59. CGFloat bottomHeight = [AccompanyDetailBottomView getViewHeight];
  60. [self.view addSubview:self.bottomView];
  61. [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
  62. make.left.right.bottom.mas_equalTo(self.view);
  63. make.height.mas_equalTo(bottomHeight);
  64. }];
  65. self.bottomView.hidden = YES;
  66. }
  67. - (void)viewWillAppear:(BOOL)animated {
  68. [super viewWillAppear:animated];
  69. [self requestCourseInfoMessage];
  70. [self configStatusViewColorWhite:YES];
  71. }
  72. - (void)viewWillDisappear:(BOOL)animated {
  73. [super viewWillDisappear:animated];
  74. [self configStatusViewColorWhite:NO];
  75. }
  76. - (void)requestCourseInfoMessage {
  77. [self requestStudentList];
  78. [self requestRoomConfig];
  79. }
  80. - (void)requestRoomConfig {
  81. [KSNetworkingManager selectRoomConfigRequest:KS_GET success:^(NSDictionary * _Nonnull dic) {
  82. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  83. NSDictionary *result = [dic ks_dictionaryValueForKey:@"data"];
  84. if (self.courseType == MUTIL_COURSE_TYPE_GROUP) {
  85. self.joinRoomBeforeTime = [result ks_integerValueForKey:@"groupStartTime"];
  86. self.quitRomeEndTime = [result ks_integerValueForKey:@"groupEndTime"];
  87. }
  88. else {
  89. self.joinRoomBeforeTime = [result ks_integerValueForKey:@"pianoStartTime"];
  90. self.quitRomeEndTime = [result ks_integerValueForKey:@"pianoEndTime"];
  91. }
  92. }
  93. else {
  94. [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
  95. }
  96. } faliure:^(NSError * _Nonnull error) {
  97. }];
  98. }
  99. - (void)requestStudentList {
  100. [LOADING_MANAGER showCustomLoading:@"加载中..."];
  101. [KSNetworkingManager musicRoomDetailRequest:KS_POST courseId:self.courseId success:^(NSDictionary * _Nonnull dic) {
  102. [LOADING_MANAGER removeCustomLoading];
  103. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  104. self.detailModel = [[MusicRoomDetailModel alloc] initWithDictionary:[dic ks_dictionaryValueForKey:@"data"]];
  105. self.studentArray = [NSMutableArray arrayWithArray:self.detailModel.studentHomeworkList.records];
  106. [self evaluateBottomButtonStatus];
  107. }
  108. else {
  109. [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
  110. }
  111. [self.tableView reloadData];
  112. } faliure:^(NSError * _Nonnull error) {
  113. [LOADING_MANAGER removeCustomLoading];
  114. }];
  115. }
  116. - (void)evaluateBottomButtonStatus {
  117. if ([self.detailModel.courseStatus isEqualToString:@"COMPLETE"]) {
  118. self.bottomView.hidden = YES;
  119. UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KPortraitWidth, 15)];
  120. self.tableView.tableFooterView = bottomView;
  121. }
  122. else {
  123. CGFloat bottomHeight = [AccompanyDetailBottomView getViewHeight];
  124. UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KPortraitWidth, bottomHeight)];
  125. self.tableView.tableFooterView = bottomView;
  126. self.bottomView.hidden = NO;
  127. self.bottomView.sureButton.userInteractionEnabled = YES;
  128. [self.bottomView.sureButton setTitle:@"进入教室" forState:UIControlStateNormal];
  129. [self.bottomView.sureButton setBackgroundColor:THEMECOLOR];
  130. [self.bottomView.sureButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  131. }
  132. }
  133. #pragma mark ----- tablb data source
  134. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  135. return 3;
  136. }
  137. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  138. if (section == 0 || section == 1) {
  139. return 1;
  140. }
  141. else {
  142. return self.studentArray.count;
  143. }
  144. }
  145. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  146. if (indexPath.section == 0) {
  147. MusicRoomCourseInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MusicRoomCourseInfoCell"];
  148. MJWeakSelf;
  149. BOOL isGroup = self.courseType == MUTIL_COURSE_TYPE_GROUP ? YES : NO;
  150. [cell configWithSource:self.detailModel isGroup:isGroup chatAction:^(NSString * _Nonnull targetId) {
  151. [weakSelf chatAction:targetId];
  152. }];
  153. return cell;
  154. }
  155. else if (indexPath.section == 1) {
  156. AccompanyArrangeCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AccompanyArrangeCell"];
  157. BOOL hasArrange = [self.detailModel.decorateHomework isEqualToString:@"1"] ? YES : NO;
  158. MJWeakSelf;
  159. [cell configWithHomeworkContent:self.detailModel.content hasArrangeHomework:hasArrange courseStatus:self.detailModel.courseStatus callback:^{
  160. [weakSelf arrangeHomework];
  161. }];
  162. return cell;
  163. }
  164. else {
  165. BOOL hasArrange = [self.detailModel.decorateHomework isEqualToString:@"1"] ? YES : NO;
  166. Records *studentModel = self.studentArray[indexPath.row];
  167. MusicRoomStudentCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MusicRoomStudentCell"];
  168. [cell configWithStudentInfo:studentModel hasArrangeHomework:hasArrange];
  169. return cell;
  170. }
  171. }
  172. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  173. if (indexPath.section == 2) { // 学生作业
  174. if ([self.detailModel.decorateHomework isEqualToString:@"0"]) {
  175. [LOADING_MANAGER MBShowAUTOHidingInWindow:@"您还未布置作业"];
  176. return;
  177. }
  178. Records *studentModel = self.studentArray[indexPath.row];
  179. HomeworkDetailViewController *detailCtrl = [[HomeworkDetailViewController alloc] init];
  180. detailCtrl.courseId = self.detailModel.courseId;
  181. detailCtrl.studentId = studentModel.studentId;
  182. [self.navigationController pushViewController:detailCtrl animated:YES];
  183. }
  184. }
  185. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  186. return CGFLOAT_MIN;
  187. }
  188. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  189. return CGFLOAT_MIN;
  190. }
  191. - (void)chatAction:(NSString *)targetId {
  192. if ([NSString isEmptyString:targetId]) {
  193. [LOADING_MANAGER MBShowAUTOHidingInWindow:@"报名未结束,暂无群组"];
  194. return;
  195. }
  196. TUIChatConversationModel *model = [[TUIChatConversationModel alloc] init];
  197. model.groupID = targetId;
  198. KSGroupConversationController *ctrl = [[KSGroupConversationController alloc] init];
  199. ctrl.conversation = model;
  200. [self.navigationController pushViewController:ctrl animated:YES];
  201. }
  202. - (void)arrangeHomework {
  203. if (![self.detailModel.courseStatus isEqualToString:@"COMPLETE"]) {
  204. [LOADING_MANAGER MBShowAUTOHidingInWindow:@"课程结束之后才可以布置作业哦~"];
  205. return;
  206. }
  207. self.alertView = [CourseGroupPlanAlertView sharedInstance];
  208. [self.alertView configWithHeadTitle:@"布置作业" tipsDesc:@"请输入本次课程作业内容" sureButtonTitle:@"提交" maxCount:200];
  209. MJWeakSelf;
  210. [self.alertView configWithDesc:@"" callback:^(NSString * _Nullable planString) {
  211. [weakSelf arrangeAction:planString];
  212. }];
  213. [self.alertView showInView:self.view];
  214. }
  215. - (void)arrangeAction:(NSString *)homeworkContent {
  216. [LOADING_MANAGER showCustomLoading:@"加载中..."];
  217. [KSNetworkingManager homeworkDecorateRequest:KS_POST content:homeworkContent courseScheduleId:self.courseId success:^(NSDictionary * _Nonnull dic) {
  218. [LOADING_MANAGER removeCustomLoading];
  219. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  220. [LOADING_MANAGER MBShowAUTOHidingInWindow:@"布置成功"];
  221. [self requestCourseInfoMessage];
  222. }
  223. else {
  224. [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
  225. }
  226. } faliure:^(NSError * _Nonnull error) {
  227. [LOADING_MANAGER removeCustomLoading];
  228. }];
  229. }
  230. #pragma mark ---- lazying
  231. - (OnlineClassManager *)classManager {
  232. if (!_classManager) {
  233. _classManager = [[OnlineClassManager alloc] init];
  234. }
  235. return _classManager;
  236. }
  237. - (UITableView *)tableView {
  238. if (!_tableView) {
  239. _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
  240. _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  241. _tableView.delegate = self;
  242. _tableView.dataSource = self;
  243. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  244. _tableView.showsVerticalScrollIndicator = NO;
  245. _tableView.showsHorizontalScrollIndicator = NO;
  246. _tableView.backgroundColor = [UIColor clearColor];
  247. _tableView.rowHeight = UITableViewAutomaticDimension;
  248. _tableView.estimatedRowHeight = 136.0f;
  249. [_tableView registerNib:[UINib nibWithNibName:@"MusicRoomCourseInfoCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"MusicRoomCourseInfoCell"];
  250. [_tableView registerNib:[UINib nibWithNibName:@"AccompanyArrangeCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"AccompanyArrangeCell"];
  251. [_tableView registerNib:[UINib nibWithNibName:@"MusicRoomStudentCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"MusicRoomStudentCell"];
  252. UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KPortraitWidth, iPhoneXSafeBottomMargin)];
  253. _tableView.tableFooterView = bottomView;
  254. }
  255. return _tableView;
  256. }
  257. - (AccompanyDetailBottomView *)bottomView {
  258. if (!_bottomView) {
  259. _bottomView = [AccompanyDetailBottomView shareInstance];
  260. MJWeakSelf;
  261. [_bottomView joinroomCallback:^{
  262. [weakSelf tryJoinRoom];
  263. }];
  264. }
  265. return _bottomView;
  266. }
  267. - (void)tryJoinRoom {
  268. NSDateFormatter *dateFormatter = [NSObject getDateformatter];
  269. [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
  270. NSDate *beginDate = [dateFormatter dateFromString:self.detailModel.startTime];
  271. NSDate *endDate = [dateFormatter dateFromString:self.detailModel.endTime];
  272. NSDate *currentDate = [NSDate date];
  273. NSTimeInterval beginTimeInterval = [beginDate timeIntervalSinceDate:currentDate];
  274. NSTimeInterval endTimeInterval = [currentDate timeIntervalSinceDate:endDate];
  275. if (beginTimeInterval <= self.joinRoomBeforeTime * 60 && endTimeInterval < 0) {
  276. [self joinClassRoom];
  277. }
  278. else if (endTimeInterval > 0) {
  279. [LOADING_MANAGER MBShowAUTOHidingInWindow:@"该课程已结束"];
  280. }
  281. else {
  282. NSString *tipsString = [NSString stringWithFormat:@"课程还未开始,请在上课前%zd分钟进入", self.joinRoomBeforeTime];
  283. [LOADING_MANAGER MBShowAUTOHidingInWindow:tipsString];
  284. }
  285. }
  286. // 加入房间
  287. - (void)joinClassRoom {
  288. // 加入房间前判断摄像头和麦克风逻辑
  289. [RecordCheckManager checkCameraPremissionAvaiableCallback:^(PREMISSIONTYPE type) {
  290. [self afterCheckCameraCheckMic:type];
  291. }];
  292. }
  293. - (void)afterCheckCameraCheckMic:(PREMISSIONTYPE)cameraType {
  294. [RecordCheckManager checkMicPermissionAvaiableCallback:^(PREMISSIONTYPE type) {
  295. if (type == PREMISSIONTYPE_YES && cameraType == PREMISSIONTYPE_YES) {
  296. // 判断是否进行课前检测
  297. [self.classManager joinRoomWithId:self.courseId subjectName:self.detailModel.subjectName classEndTime:self.detailModel.endTime inViewController:self];
  298. }
  299. else {
  300. NSString *content = @"";
  301. CHECKDEVICETYPE checkType = CHECKDEVICETYPE_BOTH;
  302. if (cameraType == PREMISSIONTYPE_NO && type == PREMISSIONTYPE_NO) {
  303. content = @"请开启相机和麦克风访问权限";
  304. checkType = CHECKDEVICETYPE_BOTH;
  305. }
  306. else if (cameraType == PREMISSIONTYPE_NO && type == PREMISSIONTYPE_YES) {
  307. content = @"请开启相机访问权限";
  308. checkType = CHECKDEVICETYPE_CAMREA;
  309. }
  310. else if (cameraType == PREMISSIONTYPE_YES && type == PREMISSIONTYPE_NO) {
  311. content = @"请开启麦克风访问权限";
  312. checkType = CHECKDEVICETYPE_MIC;
  313. }
  314. [self showAlertWithMessage:content type:checkType];
  315. }
  316. }];
  317. }
  318. - (void)showAlertWithMessage:(NSString *)message type:(CHECKDEVICETYPE)deviceType {
  319. [KSPremissionAlert shareInstanceDisplayImage:deviceType message:message showInView:self.view cancel:^{
  320. } confirm:^{
  321. [self openSettingView];
  322. }];
  323. }
  324. - (void)openSettingView {
  325. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:@{} completionHandler:nil];
  326. }
  327. - (CourseGroupNavView *)navView {
  328. if (!_navView) {
  329. _navView = [CourseGroupNavView sharedInstance];
  330. MJWeakSelf;
  331. [_navView configWithNavTitle:@"课程详情" callback:^{
  332. [weakSelf backAction];
  333. }];
  334. }
  335. return _navView;
  336. }
  337. /*
  338. #pragma mark - Navigation
  339. // In a storyboard-based application, you will often want to do a little preparation before navigation
  340. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  341. // Get the new view controller using [segue destinationViewController].
  342. // Pass the selected object to the new view controller.
  343. }
  344. */
  345. @end