OnlineLearningDetailViewController.m 16 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
//
//  OnlineLearningDetailViewController.m
//  Lighting
//
//  Created by 曹云霄 on 2016/11/25.
//  Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//

#import "OnlineLearningDetailViewController.h"
#import "VideoHelperViewController.h"
#import "VideoDetailViewController.h"
12 13 14
#import "CustomWKWebViewController.h"
#import "LearningCompleteViewController.h"
#import "AssessmentViewController.h"
15

16
@interface OnlineLearningDetailViewController ()<SelectStudyItemDelegate,VideoPlayerDelegate,BeginAssessmentDelegate,InspectionStateDelegate>
17

18
@property (nonatomic,strong) WYPopoverController *settingsPopoverController;
19
@property (nonatomic, assign) BOOL isNotFirstIn;
20

21 22 23 24
@end

@implementation OnlineLearningDetailViewController

25 26 27 28 29

#pragma mark -渲染完成
- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
30
//    self.navigationController.fd_fullscreenPopGestureRecognizer.enabled = NO;
31 32 33
    if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        self.navigationController.interactivePopGestureRecognizer.enabled = NO;
    }
34 35 36 37 38
    if (!self.isNotFirstIn) {
        //播放进入选中的视频
        self.isNotFirstIn = YES;
        [self seleStudyItemCellIndex:self.interIndex];
    }
39 40 41 42 43 44 45 46 47 48
}

#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;
    }
49 50 51 52 53 54 55
    //记录播放时间
    VideoHelperViewController *videoVc = [self.childViewControllers firstObject];
    if (videoVc.learningItem) {
        double currentTime = [videoVc getCurrentPlayingTime];
        double totalTime = videoVc.playerItem.duration.value/videoVc.playerItem.duration.timescale;
        [self switchVideoRecordPlayTime:videoVc.learningItem.attachment withPlayTime:currentTime withPlayPercent:currentTime/totalTime];
    }
56
    [videoVc stopPlay];
57 58
}

59 60 61 62
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self addChildViewController];
63
    [self listeningHomeButton];
64 65
    
    [self transferData:self.studyResult];
66 67
}

68
#pragma mark - 添加子控制器
69 70 71 72
- (void)addChildViewController
{
    //播放窗口
    VideoHelperViewController *videoWindow = [[[self class] getLearningCenterStoryboardClass] instantiateViewControllerWithIdentifier:@"VideoHelperViewController"];
73
    videoWindow.delegate = self;
74 75
    [self addChildViewController:videoWindow];
    [self.view addSubview:videoWindow.view];
76 77 78 79
    //播放简介
    VideoDetailViewController *playDetail = [[[self class] getLearningCenterStoryboardClass] instantiateViewControllerWithIdentifier:@"VideoDetailViewController"];
    [self addChildViewController:playDetail];
    [self.view addSubview:playDetail.view];
80 81
    //播放列表
    VideoListViewController *playList = [[[self class] getLearningCenterStoryboardClass] instantiateViewControllerWithIdentifier:@"VideoListViewController"];
82
    playList.studyItemTitle = self.studyTypeEntity.name;
83
    playList.type = VideoViewTypeDetail;
84
    playList.delegate = self;
85
    videoWindow.progressDelegate = playList;
86 87
    [self addChildViewController:playList];
    [self.view addSubview:playList.view];
88
    
89
    __weak typeof(videoWindow) weakVideWindow = videoWindow;
90 91 92 93
    //全屏
    WS(weakSelf);
    [videoWindow setZoomButtonClickBlock:^(BOOL boolValue) {
        if (boolValue) {
94
            [SHARED_APPDELEGATE.window addSubview:weakVideWindow.view];
95 96 97 98 99 100 101 102 103 104 105 106
            [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];
        }
    }];
107
    videoWindow.view.frame = CGRectMake(0,NavigationHeight, ScreenWidth*2/3, ScreenHeight/2);
108
    playList.view.frame = CGRectMake(ScreenWidth*2/3 + 5, NavigationHeight,ScreenWidth/3-5, ScreenHeight-64);
109
    playDetail.view.frame = CGRectMake(0, ScreenHeight/2+NavigationHeight, ScreenWidth*2/3, ScreenHeight/2-NavigationHeight);
110 111
}

112 113 114 115
#pragma mark - 监听Home键
- (void)listeningHomeButton
{
    //监听是否触发home键挂起程序.
116
    [Notification addObserver:self selector:@selector(applicationWillResignActive:)name:UIApplicationWillResignActiveNotification object:nil];
117
    //监听是否重新进入程序程序.
118
    [Notification addObserver:self selector:@selector(applicationDidBecomeActive:)name:UIApplicationDidBecomeActiveNotification object:nil];
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
}

#pragma mark - 进入后台
- (void)applicationWillResignActive:(NSNotification *)notification
{
    printf("触发home按下\n");
    //记录播放时间
    VideoHelperViewController *videoVc = [self.childViewControllers firstObject];
    if (videoVc.learningItem) {
        double currentTime = [videoVc getCurrentPlayingTime];
        double totalTime = videoVc.playerItem.duration.value/videoVc.playerItem.duration.timescale;
        [self switchVideoRecordPlayTime:videoVc.learningItem.attachment withPlayTime:currentTime withPlayPercent:currentTime/totalTime];
    }
}

#pragma mark - 进入前台
- (void)applicationDidBecomeActive:(NSNotification *)notification
{
    printf("重新进来后响应\n");
}
139

140 141 142 143
#pragma mark - 获取学习项详情
- (void)getStudyItemDetailAction
{
    WS(weakSelf);
144
    StudyTaskCondition *studyListModel = [[StudyTaskCondition alloc]init];
145
    studyListModel.employeeIdEquals = [Shoppersmanager manager].shoppers.employee.fid;
146
    studyListModel.typeEquals = self.studyTypeEntity.fid;
147 148 149 150
    DataPage *page = [[DataPage alloc] init];
    page.page = ONE;
    page.rows = 9999;
    studyListModel.page = page;
151
    [XBLoadingView showHUDViewWithDefault];
曹云霄's avatar
曹云霄 committed
152
    [HTTP networkRequestWithURL:SERVERREQUESTURL(STUDYLIST) withRequestType:ZERO withParameter:studyListModel withReturnValueBlock:^(id returnValue) {
153
        
154
        [XBLoadingView hideHUDViewWithDefault];
曹云霄's avatar
曹云霄 committed
155
        if (RESULT(returnValue)) {
曹云霄's avatar
曹云霄 committed
156
            weakSelf.studyResult = [[StudyTaskResponse alloc]initWithDictionary:RESPONSE(returnValue) error:nil];
157
            [weakSelf transferData:weakSelf.studyResult];
158
        }else {
159
            [XBLoadingView showHUDViewWithText:MESSAGE(returnValue)];
160
        }
161
        
162
    }withFailureBlock:^(NSError *error) {
163
        [XBLoadingView showHUDViewWithText:error.localizedDescription];
164 165 166
    }];
}

167 168 169
#pragma mark - 选中学习项
- (void)seleStudyItemCellIndex:(NSIndexPath *)indexPath
{
170 171 172 173 174 175
    //判断学习列表是否处于全屏状态,第一次选中是需要取消全屏状态
    VideoListViewController *studyListVC = self.childViewControllers[2];
    if (studyListVC.view.width == ScreenWidth) {
        [studyListVC narrowAnimation];
    }
    VideoDetailViewController *studyDetailVc = self.childViewControllers[1];
176
    studyDetailVc.indexPath = indexPath;
177
    WS(weakSelf);
178 179 180
    VideoHelperViewController *videoVc = [self.childViewControllers firstObject];
    RsStudyTask *studyEntity = self.studyResult.studyEntity[indexPath.section];
    CustomStudyEntity *studyList = studyEntity.studyTasks[indexPath.row];
181
    videoVc.indexPath = indexPath;
182
    [studyListVC selectedIndexPath:indexPath withIsQualified:[studyList.examResult boolValue]];
183
//    [self.superListVC selectedIndexPath:indexPath withIsQualified:[studyList.examResult boolValue]];
184
    if ([studyList.attachment.fileUrl rangeOfString:@".mp4"].location != NSNotFound) {
185 186 187 188 189 190
        //判断是否是第一次播放
        if (videoVc.learningItem) {
            double currentTime = [videoVc getCurrentPlayingTime];
            double totalTime = videoVc.playerItem.duration.value/videoVc.playerItem.duration.timescale;
            [self switchVideoRecordPlayTime:videoVc.learningItem.attachment withPlayTime:currentTime withPlayPercent:currentTime/totalTime];
        }
191 192 193 194
        videoVc.learningItem = studyList;
    }else if ([studyList.attachment.fileUrl rangeOfString:@".ppt"].location != NSNotFound) {
        
        [videoVc resetPlayer];
195 196 197 198 199
        CustomWKWebViewController *pptVc = [[CustomWKWebViewController alloc]init];
        pptVc.urlString = studyList.attachment.fileUrl;
        pptVc.type = Study;
        pptVc.indexPath = indexPath;
        videoVc.learningItem = nil;
200
        pptVc.studyId = studyList.fid;
201
        [pptVc setScrollViewEndBottomBlock:^(NSIndexPath *indexPath){
202
            [weakSelf dismissViewControllerAnimated:YES completion:^{
203
                [weakSelf videoPlayFinish:studyList withIndexPath:indexPath];
204 205
            }];
        }];
Sandy's avatar
Sandy committed
206
        
207
        [self presentViewController:pptVc animated:YES completion:nil];
208 209 210
    }
}

211 212 213 214 215 216
#pragma mark - 切换视频播放记录播放时间
- (void)switchVideoRecordPlayTime:(TOAttachmentEntity *)attachment withPlayTime:(double)playTime withPlayPercent:(double)percent
{
    TOAttachmentPlayEntity *playTimeEntity = [[TOAttachmentPlayEntity alloc] init];
    playTimeEntity.fid = attachment.entityId;
    playTimeEntity.attachmentId = attachment.fid;
217
    playTimeEntity.employeeId = [Shoppersmanager manager].shoppers.employee.fid;
218 219
    playTimeEntity.playTime = [NSString stringWithFormat:@"%.0lf",playTime];
    playTimeEntity.playPercent = [NSString stringWithFormat:@"%.2lf",percent];
曹云霄's avatar
曹云霄 committed
220
    [HTTP networkRequestWithURL:SERVERREQUESTURL(ATTACHMENTPLAYTIME) withRequestType:ZERO withParameter:playTimeEntity withReturnValueBlock:^(id returnValue) {
曹云霄's avatar
曹云霄 committed
221
        if (RESULT(returnValue)) {
222 223 224
            attachment.playTime = playTimeEntity.playTime;
            attachment.playPercent = playTimeEntity.playPercent;
        }else {
225
            [XBLoadingView showHUDViewWithText:MESSAGE(returnValue)];
226 227
        }
        
228
    } withFailureBlock:^(NSError *error) {
229 230 231 232
        [XBLoadingView showHUDViewWithText:error.localizedDescription];
    }];
}

233

234

235
#pragma mark - 视频播放完成
236
- (void)videoPlayFinish:(CustomStudyEntity *)studyEntity withIndexPath:(NSIndexPath *)indexPath
237
{
238 239 240 241 242 243
    WS(weakSelf);
    [self studyFinishGetIntegral:^(NSString *integral) {
        LearningCompleteViewController *assessmentVc = [[[weakSelf class] getLearningCenterStoryboardClass] instantiateViewControllerWithIdentifier:@"LearningCompleteViewController"];
        assessmentVc.delegate = weakSelf;
        assessmentVc.studyEntity = studyEntity;
        assessmentVc.integralString = integral;
244
        assessmentVc.indexPath = indexPath;
245 246 247 248 249 250 251 252
        assessmentVc.preferredContentSize = CGSizeMake(520, 450);
        weakSelf.settingsPopoverController = [[WYPopoverController alloc] initWithContentViewController:assessmentVc];
        weakSelf.settingsPopoverController.wantsDefaultContentAppearance = NO;
        weakSelf.settingsPopoverController.theme.fillBottomColor = [UIColor clearColor];
        weakSelf.settingsPopoverController.theme.fillTopColor = [UIColor clearColor];
        weakSelf.settingsPopoverController.theme.glossShadowColor = [UIColor clearColor];
        [weakSelf.settingsPopoverController presentPopoverAsDialogAnimated:YES
                                                               options:WYPopoverAnimationOptionFadeWithScale];
253
    }withStudyEntity:studyEntity];
254 255 256
}

#pragma mark - 学习完成获取积分
257
- (void)studyFinishGetIntegral:(void(^)(NSString *integral))getIntegral withStudyEntity:(CustomStudyEntity *)studuEntity
258 259
{
    [XBLoadingView showHUDViewWithDefault];
260
    // 任务一,学习项完成
261
    [HTTP networkWithDictionaryRequestWithURL:[NSString stringWithFormat:SERVERREQUESTURL(FINISHSTUDY),studuEntity.fid,[Shoppersmanager manager].shoppers.employee.fid] withRequestType:ONE withParameter:nil withReturnValueBlock:^(id returnValue) {
262
        
曹云霄's avatar
曹云霄 committed
263
        if (RESULT(returnValue)) {
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
            BOOL boolValue = [RESPONSE(returnValue) boolValue];
            if (!boolValue) {
                [XBLoadingView hideHUDViewWithDefault];
                return;
            }else{
                // 任务二,获得学习积分
                [HTTP networkWithDictionaryRequestWithURL:[NSString stringWithFormat:SERVERREQUESTURL(GETINTEGRAL),STUDYFINISH] withRequestType:ONE withParameter:nil withReturnValueBlock:^(id returnValue) {
                    
                    [XBLoadingView hideHUDViewWithDefault];
                    if (RESULT(returnValue)) {
                        if (getIntegral) {
                            getIntegral(RESPONSE(returnValue));
                        }
                    }else {
                        [XBLoadingView showHUDViewWithText:MESSAGE(returnValue)];
                    }
                    
                } withFailureBlock:^(NSError *error) {
                    [XBLoadingView showHUDViewWithText:error.localizedDescription];
                }];
284
            }
285
            
286
        }else {
287
            [XBLoadingView showHUDViewWithText:MESSAGE(returnValue)];
288 289
        }
        
290
    } withFailureBlock:^(NSError *error) {
291 292
        [XBLoadingView showHUDViewWithText:error.localizedDescription];
    }];
293 294 295
}

#pragma mark - 开始考核
296
- (void)beginAssessment:(CustomStudyEntity *)studyEntity withIndexPath:(NSIndexPath *)indexPath
297 298
{
    WS(weakSelf);
299 300 301 302 303 304 305
    VideoHelperViewController *videoWindow = self.childViewControllers[0];
    if (videoWindow.view.height == ScreenHeight) {
        [self.view insertSubview:videoWindow.view atIndex:0];
        [UIView animateWithDuration:0.2 animations:^{
            videoWindow.view.frame = CGRectMake(0, NavigationHeight, ScreenWidth*2/3, ScreenHeight/2);
            videoWindow.playerLayer.frame = CGRectMake(0, 0, ScreenWidth*2/3, ScreenHeight/2);
        }completion:^(BOOL finished) {
306
            [weakSelf assessment:studyEntity.fid withIndexPath:indexPath];
307
            
308
        }];
309
    }else {
310
        [weakSelf assessment:studyEntity.fid withIndexPath:indexPath];
311
    }
312 313
}

314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330
#pragma mark - 考核
- (void)assessment:(NSString *)taskId withIndexPath:(NSIndexPath *)indexPath
{
    WS(weakSelf);
    [self.settingsPopoverController dismissPopoverAnimated:YES completion:^{
        AssessmentViewController *assessmentVc = [[[self class] getLearningCenterStoryboardClass] instantiateViewControllerWithIdentifier:@"AssessmentViewController"];
        assessmentVc.taskId = taskId;
        assessmentVc.indexPath = indexPath;
        assessmentVc.delegate = weakSelf;
        [weakSelf.navigationController pushViewController:assessmentVc animated:YES];
    }];
}

#pragma mark --- <InspectionStateDelegate>考核状态
#pragma mark -再学一遍
- (void)learningAgainButtonClick:(NSIndexPath *)indexPath
{
331
    VideoListViewController *studyListVC = self.childViewControllers[2];
332
    [studyListVC selectedIndexPath:indexPath withIsQualified:NO];
333
//     [self.superListVC selectedIndexPath:indexPath withIsQualified:NO];
334 335 336 337 338 339
    [self seleStudyItemCellIndex:indexPath];
}

#pragma mark -考核完成
- (void)inspectionThroughAction:(NSIndexPath *)indexPath
{
340
    VideoListViewController *studyListVC = self.childViewControllers[2];
341
    [studyListVC selectedIndexPath:indexPath withIsQualified:YES];
342
//     [self.superListVC selectedIndexPath:indexPath withIsQualified:YES];
343 344 345 346 347 348 349 350
}

#pragma mark - <VideoPlayerDelegate>
- (void)isFirstPLayOrPPTPlay:(NSIndexPath *)indexPath
{
    [self seleStudyItemCellIndex:indexPath];
}

351 352 353
#pragma mark - 赋值
- (void)transferData:(StudyTaskResponse *)result
{
354
    if (result.studyEntity.count == 0) {
355 356 357
        [XBLoadingView showHUDViewWithText:@"学习内容为空"];
        [self.navigationController popViewControllerAnimated:YES];
        return;
358
    }
359
    VideoListViewController *studyListVC = self.childViewControllers[2];
360
    studyListVC.datasArray = [NSMutableArray arrayWithArray:result.studyEntity];
361
//    self.superListVC.datasArray = studyListVC.datasArray;
362
    VideoDetailViewController *studyDetailsVC = self.childViewControllers[1];
363 364 365 366
    studyDetailsVC.datasArray = result.studyEntity;
    studyDetailsVC.indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
}

367

368
@end