// // OnlineLearningDetailViewController.m // Lighting // // Created by 曹云霄 on 2016/11/25. // Copyright © 2016年 上海勾芒科技有限公司. All rights reserved. // #import "OnlineLearningDetailViewController.h" #import "VideoHelperViewController.h" #import "VideoListViewController.h" #import "VideoDetailViewController.h" #import "CustomWKWebViewController.h" #import "LearningCompleteViewController.h" #import "AssessmentViewController.h" @interface OnlineLearningDetailViewController ()<SelectStudyItemDelegate,VideoPlayerDelegate,BeginAssessmentDelegate> /** 学习数据 */ @property (nonatomic,strong) StudyTaskResponse *studyResult; @property (nonatomic,strong) WYPopoverController *settingsPopoverController; @end @implementation OnlineLearningDetailViewController #pragma mark -渲染完成 - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; self.navigationController.fd_fullscreenPopGestureRecognizer.enabled = NO; if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) { self.navigationController.interactivePopGestureRecognizer.enabled = NO; } } #pragma mark -视图即将消失 - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; // 开启 self.navigationController.fd_fullscreenPopGestureRecognizer.enabled = YES; if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) { self.navigationController.interactivePopGestureRecognizer.enabled = YES; } } - (void)viewDidLoad { [super viewDidLoad]; [self addChildViewController]; [self getStudyItemDetailAction]; } #pragma mark - - (void)addChildViewController { //播放窗口 VideoHelperViewController *videoWindow = [[[self class] getLearningCenterStoryboardClass] instantiateViewControllerWithIdentifier:@"VideoHelperViewController"]; videoWindow.view.frame = CGRectMake(0, NavigationHeight, ScreenWidth*2/3, ScreenHeight/2); videoWindow.delegate = self; [self addChildViewController:videoWindow]; [self.view addSubview:videoWindow.view]; //播放列表 VideoListViewController *playList = [[[self class] getLearningCenterStoryboardClass] instantiateViewControllerWithIdentifier:@"VideoListViewController"]; playList.view.frame = CGRectMake(ScreenWidth*2/3 + 5, NavigationHeight, ScreenWidth/3-5, ScreenHeight-64); playList.studyItemTitleLabel.text = self.studyTypeEntity.name; playList.delegate = self; [self addChildViewController:playList]; [self.view addSubview:playList.view]; //播放简介 VideoDetailViewController *playDetail = [[[self class] getLearningCenterStoryboardClass] instantiateViewControllerWithIdentifier:@"VideoDetailViewController"]; playDetail.view.frame = CGRectMake(0, ScreenHeight/2+NavigationHeight, ScreenWidth*2/3, ScreenHeight/2-NavigationHeight); [self addChildViewController:playDetail]; [self.view addSubview:playDetail.view]; __block VideoHelperViewController *weakVideWindow = videoWindow; //全屏 WS(weakSelf); [videoWindow setZoomButtonClickBlock:^(BOOL boolValue) { if (boolValue) { [weakSelf.view.window addSubview:weakVideWindow.view]; [UIView animateWithDuration:0.2 animations:^{ weakVideWindow.view.frame = [UIScreen mainScreen].bounds; weakVideWindow.playerLayer.frame = [UIScreen mainScreen].bounds; }]; }else{ [weakSelf.view insertSubview:weakVideWindow.view atIndex:0]; [UIView animateWithDuration:0.2 animations:^{ weakVideWindow.view.frame = CGRectMake(0, NavigationHeight, ScreenWidth*2/3, ScreenHeight/2); weakVideWindow.playerLayer.frame = CGRectMake(0, 0, ScreenWidth*2/3, ScreenHeight/2); }completion:nil]; } }]; } #pragma mark - 获取学习项详情 - (void)getStudyItemDetailAction { WS(weakSelf); StudyTaskCondition *studyListModel = [[StudyTaskCondition alloc]init]; studyListModel.employeeIdEquals = [Shoppersmanager manager].Shoppers.employee.fid; studyListModel.typeEquals = self.studyTypeEntity.fid; DataPage *page = [[DataPage alloc] init]; page.page = ONE; page.rows = 9999; studyListModel.page = page; [self CreateMBProgressHUDLoding]; [[NetworkRequestClassManager Manager] NetworkRequestWithURL:SERVERREQUESTURL(STUDYLIST) WithCallClass:weakSelf WithRequestType:ZERO WithParameter:studyListModel WithReturnValueBlock:^(id returnValue) { [weakSelf RemoveMBProgressHUDLoding]; if ([returnValue[@"code"] isEqualToNumber:@0]) { weakSelf.studyResult = [[StudyTaskResponse alloc]initWithDictionary:returnValue[@"data"] error:nil]; [weakSelf transferData:weakSelf.studyResult]; }else { [weakSelf ErrorMBProgressView:returnValue[@"message"]]; } } WithErrorCodeBlock:^(id errorCodeValue) { [weakSelf ErrorMBProgressView:NETWORK]; } WithFailureBlock:^(NSError *error) { [weakSelf ErrorMBProgressView:error.localizedDescription]; }]; } #pragma mark - 选中学习项 - (void)seleStudyItemCellIndex:(NSIndexPath *)indexPath { VideoDetailViewController *studyDetailVc = [self.childViewControllers lastObject]; studyDetailVc.indexPath = indexPath; VideoHelperViewController *videoVc = [self.childViewControllers firstObject]; RsStudyTask *studyEntity = self.studyResult.studyEntity[indexPath.section]; CustomStudyEntity *studyList = studyEntity.studyTasks[indexPath.row]; if ([studyList.attachment.fileUrl rangeOfString:@".mp4"].location != NSNotFound) { videoVc.learningItem = studyList; videoVc.videoTitleLabel.text = studyList.title; }else if ([studyList.attachment.fileUrl rangeOfString:@".ppt"].location != NSNotFound) { [videoVc resetPlayer]; CustomWKWebViewController *pdfvc = [[CustomWKWebViewController alloc]init]; pdfvc.urlString = studyList.attachment.fileUrl; [self presentViewController:pdfvc animated:YES completion:nil]; } } #pragma mark - 视频播放完成 - (void)videoPlayFinish:(CustomStudyEntity *)studyEntity { LearningCompleteViewController *assessmentVc = [[[self class] getLearningCenterStoryboardClass] instantiateViewControllerWithIdentifier:@"LearningCompleteViewController"]; assessmentVc.delegate = self; assessmentVc.studyEntity = studyEntity; assessmentVc.preferredContentSize = CGSizeMake(520, 450); self.settingsPopoverController = [[WYPopoverController alloc] initWithContentViewController:assessmentVc]; self.settingsPopoverController.wantsDefaultContentAppearance = NO; self.settingsPopoverController.theme.fillBottomColor = [UIColor clearColor]; self.settingsPopoverController.theme.fillTopColor = [UIColor clearColor]; self.settingsPopoverController.theme.glossShadowColor = [UIColor clearColor]; [self.settingsPopoverController presentPopoverAsDialogAnimated:YES options:WYPopoverAnimationOptionFadeWithScale]; } #pragma mark - 开始考核 - (void)beginAssessment:(CustomStudyEntity *)studyEntity { WS(weakSelf); [self.settingsPopoverController dismissPopoverAnimated:YES completion:^{ AssessmentViewController *assessmentVc = [[[self class] getLearningCenterStoryboardClass] instantiateViewControllerWithIdentifier:@"AssessmentViewController"]; assessmentVc.taskId = studyEntity.fid; [weakSelf.navigationController pushViewController:assessmentVc animated:YES]; }]; } #pragma mark - 赋值 - (void)transferData:(StudyTaskResponse *)result { VideoListViewController *studyListVC = self.childViewControllers[1]; studyListVC.datasArray = result.studyEntity; VideoDetailViewController *studyDetailsVC = self.childViewControllers[2]; studyDetailsVC.datasArray = result.studyEntity; studyDetailsVC.indexPath = [NSIndexPath indexPathForRow:0 inSection:0]; } @end