MusicRoomViewController.m 13 KB

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