123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335 |
- //
- // MusicRoomViewController.m
- // KulexiuForTeacher
- //
- // Created by 王智 on 2022/6/14.
- //
- #import "MusicRoomViewController.h"
- #import "MusicRoomDetailModel.h"
- #import "MusicRoomCourseInfoCell.h"
- #import "AccompanyDetailBottomView.h"
- #import "RecordCheckManager.h"
- #import "KSPremissionAlert.h"
- #import "OnlineClassManager.h"
- #import "AccompanyArrangeCell.h"
- #import "MusicRoomStudentCell.h"
- #import "AccompanyAlertView.h"
- #import "KSGroupConversationController.h"
- #import "HomeworkDetailViewController.h"
- @interface MusicRoomViewController ()<UITableViewDelegate,UITableViewDataSource>
- @property (nonatomic, assign) NSInteger joinRoomBeforeTime; // 上课开始时间
- @property (nonatomic, assign) NSInteger quitRomeEndTime; // 下课截止时间
- @property (nonatomic, strong) UIView *bgView;
- @property (nonatomic, strong) MusicRoomDetailModel *detailModel;
- @property (nonatomic, strong) UITableView *tableView;
- @property (nonatomic, strong) OnlineClassManager *classManager;
- @property (nonatomic, strong) AccompanyDetailBottomView *bottomView;
- @property (nonatomic, strong) AccompanyAlertView *alertView;
- @property (nonatomic, strong) NSMutableArray *studentArray;
- @end
- @implementation MusicRoomViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- [self allocTitle:@"课程详情"];
- [self configUI];
- }
- - (void)configUI {
- [self.view addSubview:self.tableView];
- [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.mas_equalTo(self.view);
- make.top.mas_equalTo(self.view.mas_top);
- make.bottom.mas_equalTo(self.view.mas_bottom).offset(-iPhoneXSafeBottomMargin);
- }];
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- [self requestCourseInfoMessage];
- }
- - (void)requestCourseInfoMessage {
- [self requestStudentList];
- [self requestRoomConfig];
- }
- - (void)requestRoomConfig {
- [KSNetworkingManager selectRoomConfigRequest:KS_GET success:^(NSDictionary * _Nonnull dic) {
- if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
- NSDictionary *result = [dic ks_dictionaryValueForKey:@"data"];
- self.joinRoomBeforeTime = [result ks_integerValueForKey:@"pianoStartTime"];
- self.quitRomeEndTime = [result ks_integerValueForKey:@"pianoEndTime"];
- }
- else {
- [self MBPShow:MESSAGEKEY];
- }
- } faliure:^(NSError * _Nonnull error) {
-
- }];
- }
- - (void)requestStudentList {
- [self showhud];
- [KSNetworkingManager musicRoomDetailRequest:KS_POST courseId:self.courseId success:^(NSDictionary * _Nonnull dic) {
- [self removehub];
- if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
- self.detailModel = [[MusicRoomDetailModel alloc] initWithDictionary:[dic ks_dictionaryValueForKey:@"data"]];
- self.studentArray = [NSMutableArray arrayWithArray:self.detailModel.studentHomeworkList.records];
- [self evaluateBottomButtonStatus];
- }
- else {
- [self MBPShow:MESSAGEKEY];
- }
- [self.tableView reloadData];
- } faliure:^(NSError * _Nonnull error) {
- [self removehub];
- }];
- }
- - (void)evaluateBottomButtonStatus {
- if ([self.detailModel.courseStatus isEqualToString:@"COMPLETE"]) {
- [self.bottomView.sureButton setTitle:@"已结束" forState:UIControlStateNormal];
- [self.bottomView.sureButton setBackgroundColor:HexRGB(0xd5d5d5)];
- }
- else if ([self.detailModel.courseStatus isEqualToString:@"ING"]) {
- [self.bottomView.sureButton setTitle:@"进入教室" forState:UIControlStateNormal];
- [self.bottomView.sureButton setBackgroundColor:THEMECOLOR];
- }
- else {
- [self.bottomView.sureButton setTitle:@"进入教室" forState:UIControlStateNormal];
- [self.bottomView.sureButton setBackgroundColor:THEMECOLOR];
- }
- }
- #pragma mark ----- tablb data source
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- return 3;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- if (section == 0 || section == 1) {
- return 1;
- }
- else {
- return self.studentArray.count;
- }
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- if (indexPath.section == 0) {
- MusicRoomCourseInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MusicRoomCourseInfoCell"];
- MJWeakSelf;
- [cell configWithSource:self.detailModel chatAction:^(NSString * _Nonnull targetId) {
- [weakSelf chatAction:targetId];
- }];
- return cell;
- }
- else if (indexPath.section == 1) {
- AccompanyArrangeCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AccompanyArrangeCell"];
- BOOL hasArrange = [self.detailModel.decorateHomework isEqualToString:@"1"] ? YES : NO;
- MJWeakSelf;
- [cell configWithHomeworkContent:self.detailModel.content hasArrangeHomework:hasArrange callback:^{
- [weakSelf arrangeHomework];
- }];
- return cell;
- }
- else {
- BOOL hasArrange = [self.detailModel.decorateHomework isEqualToString:@"1"] ? YES : NO;
- Records *studentModel = self.studentArray[indexPath.row];
- MusicRoomStudentCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MusicRoomStudentCell"];
- [cell configWithStudentInfo:studentModel hasArrangeHomework:hasArrange];
- return cell;
- }
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- if (indexPath.section == 2) { // 学生作业
- if ([self.detailModel.decorateHomework isEqualToString:@"0"]) {
- [self MBPShow:@"您还未布置作业"];
- return;
- }
- Records *studentModel = self.studentArray[indexPath.row];
- HomeworkDetailViewController *detailCtrl = [[HomeworkDetailViewController alloc] init];
- detailCtrl.courseId = self.detailModel.courseId;
- detailCtrl.studentId = studentModel.studentId;
- [self.navigationController pushViewController:detailCtrl animated:YES];
- }
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
- return CGFLOAT_MIN;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
- return CGFLOAT_MIN;
- }
- - (void)chatAction:(NSString *)targetId {
- if ([NSString isEmptyString:targetId]) {
- [self MBPShow:@"报名未结束,暂无群组"];
- return;
- }
- TUIChatConversationModel *model = [[TUIChatConversationModel alloc] init];
- model.groupID = targetId;
- KSGroupConversationController *ctrl = [[KSGroupConversationController alloc] init];
- ctrl.conversation = model;
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- - (void)arrangeHomework {
- if (![self.detailModel.courseStatus isEqualToString:@"COMPLETE"]) {
- [self MBPShow:@"课程结束之后才可以布置作业哦~"];
- return;
- }
- self.alertView = [AccompanyAlertView shareInstance];
- self.alertView.alertTitle.text = @"布置作业";
- self.alertView.tipsLabel.text = @"请输入本次课程作业内容";
- self.alertView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight);
- [self.alertView showInView:[UIApplication sharedApplication].keyWindow showStarView:NO];
- MJWeakSelf;
- [self.alertView sureCallback:^(NSString * _Nonnull content, NSInteger starNum) {
- [weakSelf arrangeAction:content];
- }];
- }
- - (void)arrangeAction:(NSString *)homeworkContent {
- [self showhud];
- [KSNetworkingManager homeworkDecorateRequest:KS_POST content:homeworkContent courseScheduleId:self.courseId success:^(NSDictionary * _Nonnull dic) {
- [self removehub];
- if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
- [self MBPShow:@"布置成功"];
- [self requestCourseInfoMessage];
- }
- else {
- [self MBPShow:MESSAGEKEY];
- }
- } faliure:^(NSError * _Nonnull error) {
- [self removehub];
- }];
- }
- #pragma mark ---- lazying
- - (OnlineClassManager *)classManager {
- if (!_classManager) {
- _classManager = [[OnlineClassManager alloc] init];
- }
- return _classManager;
- }
- - (UITableView *)tableView {
- if (!_tableView) {
- _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
- _tableView.delegate = self;
- _tableView.dataSource = self;
- _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- _tableView.showsVerticalScrollIndicator = NO;
- _tableView.showsHorizontalScrollIndicator = NO;
- _tableView.backgroundColor = [UIColor clearColor];
- _tableView.rowHeight = UITableViewAutomaticDimension;
- _tableView.estimatedRowHeight = 136.0f;
- [_tableView registerNib:[UINib nibWithNibName:@"MusicRoomCourseInfoCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"MusicRoomCourseInfoCell"];
- [_tableView registerNib:[UINib nibWithNibName:@"AccompanyArrangeCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"AccompanyArrangeCell"];
- [_tableView registerNib:[UINib nibWithNibName:@"MusicRoomStudentCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"MusicRoomStudentCell"];
- self.bottomView.frame = CGRectMake(0, 0, kScreenWidth, 70);
- _tableView.tableFooterView = self.bottomView;
- }
- return _tableView;
- }
- - (AccompanyDetailBottomView *)bottomView {
- if (!_bottomView) {
- _bottomView = [AccompanyDetailBottomView shareInstance];
- MJWeakSelf;
- [_bottomView joinroomCallback:^{
- [weakSelf tryJoinRoom];
- }];
- }
- return _bottomView;
- }
- - (void)tryJoinRoom {
-
- NSDateFormatter *dateFormatter = [NSObject getDateformatter];
- [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
- NSDate *beginDate = [dateFormatter dateFromString:self.detailModel.startTime];
- NSDate *endDate = [dateFormatter dateFromString:self.detailModel.endTime];
- NSDate *currentDate = [NSDate date];
- NSTimeInterval beginTimeInterval = [beginDate timeIntervalSinceDate:currentDate];
- NSTimeInterval endTimeInterval = [currentDate timeIntervalSinceDate:endDate];
- if (beginTimeInterval <= self.joinRoomBeforeTime * 60 && endTimeInterval < 0) {
- [self joinClassRoom];
- }
- else if (endTimeInterval > 0) {
- [self MBPShow:@"该课程已结束"];
- }
- else {
- NSString *tipsString = [NSString stringWithFormat:@"课程还未开始,请在上课前%zd分钟进入", self.joinRoomBeforeTime];
- [self MBPShow:tipsString];
- }
- }
- // 加入房间
- - (void)joinClassRoom {
- // 加入房间前判断摄像头和麦克风逻辑
- PREMISSIONTYPE micEnable = [RecordCheckManager checkPermissionShowAlert:NO showInView:nil];
- PREMISSIONTYPE cameraEnable = [RecordCheckManager checkCameraPremissionAvaiable:NO showInView:nil];
- if (micEnable == PREMISSIONTYPE_YES && cameraEnable == PREMISSIONTYPE_YES) {
- // 进入教室
- // 判断是否进行课前检测
- [self.classManager joinRoomWithId:self.courseId subjectName:self.detailModel.subjectName classEndTime:self.detailModel.endTime inViewController:self];
- }
- else {
- if (micEnable == PREMISSIONTYPE_NO && cameraEnable == PREMISSIONTYPE_NO) { // 如果麦克风权限和摄像头权限都没有
- [self showAlertWithMessage:@"请开启相机和麦克风访问权限" type:CHECKDEVICETYPE_BOTH];
- }
- else if (micEnable == PREMISSIONTYPE_NO) { // 如果没有麦克风权限
- [self showAlertWithMessage:@"请开启麦克风访问权限" type:CHECKDEVICETYPE_MIC];
- }
- else if (cameraEnable == PREMISSIONTYPE_NO) { // 如果没有摄像头权限
- [self showAlertWithMessage:@"请开启相机访问权限" type:CHECKDEVICETYPE_CAMREA];
- }
- }
- }
- - (void)showAlertWithMessage:(NSString *)message type:(CHECKDEVICETYPE)deviceType {
- [KSPremissionAlert shareInstanceDisplayImage:deviceType message:message showInView:self.view cancel:^{
-
- } confirm:^{
- [self openSettingView];
- }];
-
- }
- - (void)openSettingView {
- if (@available(iOS 10, *)) {
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:@{} completionHandler:nil];
- } else {
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
- }
- }
- /*
- #pragma mark - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- @end
|