澎湃iPad上线版本

TPLiveHomeController.m 26KB

    // // TPLiveHomeController.m // ThePaperHD // // Created by scar1900 on 15/3/10. // Copyright (c) 2015年 scar1900. All rights reserved. // #import "TPLiveHomeController.h" #import "liveListController.h" #import "toolBarBtnView.h" #import "commentAndAskController.h" #import "TPShareContentControlelr.h" #import "TPSelectButton.h" #import "fontSizeSliderController.h" #import "liveViewModel.h" @interface TPLiveHomeController ()<liveListDelegate,shareContentControllerDelegate,fontSizeSleideControllerDelegate,liveViewModelDelegate> { CGPoint shareStartPoint; BOOL isNeedScrollWithShare; BOOL hiddenStatusBar; } @property(nonatomic, assign)CGFloat statusHeight; @property(nonatomic, strong)UIView *toolBarView; @property(nonatomic, strong)UIButton *backButton; @property(nonatomic, strong)liveListController *liveListVC; @property(nonatomic, strong)liveDetailPageVO *livePageBO; @property(nonatomic, strong)liveInfoBO *liveInfoBO; @property(nonatomic, strong)toolBarBtnView *commentButton; @property(nonatomic, strong)TPSelectButton *fontSizeButton; @property(nonatomic, strong)commentAndAskController *commentController; @property(nonatomic, strong)UIView *maskView; @property(nonatomic, strong)NSMutableArray *commentList; @property(nonatomic, strong)NSMutableDictionary *qaDataDic; @property(nonatomic, strong)UISwipeGestureRecognizer *leftSwipeGesture; @property(nonatomic, strong)TPShareContentControlelr *shareVC; @property(nonatomic, strong)UIPopoverController *popOver; @property(nonatomic, assign)NSInteger actionFlag; @property(nonatomic, strong)NSIndexPath *myIndexPath; @property(nonatomic, strong)liveViewModel *model; @end @implementation TPLiveHomeController @synthesize statusHeight; @synthesize myIndexPath; @synthesize nodeId = _nodeId; @synthesize livePageBO = _livePageBO; @synthesize liveInfoBO = _liveInfoBO; @synthesize actionFlag = _actionFlag; - (void)viewDidLoad { [super viewDidLoad]; isNeedScrollWithShare = NO; if (isIOS7) { self.statusHeight = 18; }else { self.statusHeight = 0; } [MobClick event:@"3"]; [self.view addSubview:self.toolBarView]; [self.view addSubview:self.backButton]; [self.toolBarView addSubview:self.commentButton]; [self.toolBarView addSubview:self.fontSizeButton]; [self addChildViewController:self.liveListVC]; [self addChildViewController:self.commentController]; [self.view addSubview:self.liveListVC.view]; [self.view addSubview:self.commentController.view]; [self.liveListVC didMoveToParentViewController:self]; [self.commentController didMoveToParentViewController:self]; [self setContentFramWithOrirentation]; UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(dismissCommentView:)]; tapGesture.delaysTouchesBegan = YES; [self.maskView addGestureRecognizer:tapGesture]; self.leftSwipeGesture = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(leftSwipeGestureHandler:)]; [self.leftSwipeGesture delaysTouchesBegan]; self.leftSwipeGesture.numberOfTouchesRequired = 1; self.leftSwipeGesture.direction = UISwipeGestureRecognizerDirectionLeft; [self.view addGestureRecognizer:self.leftSwipeGesture]; [self enablePopBackGesture]; [self startHud]; self.actionFlag = 3; self.model = [liveViewModel new]; self.model.delegate = self; self.model.nodeId = self.nodeId; [self.model remoteAction]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(linkWithPush:) name:PUSHCLICK object:nil]; // [self remoteAction]; } - (void)setActionFlag:(NSInteger)flag { _actionFlag = flag; if (flag == 0) { [self stopHud]; } } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; self.navigationController.navigationBarHidden = YES; } - (void)statusBarOrientationChange:(NSNotification *)notification{ [self setContentFramWithOrirentation]; } - (void)setContentFramWithOrirentation { UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; if (orientation == UIInterfaceOrientationLandscapeRight || orientation ==UIInterfaceOrientationLandscapeLeft) { self.view.frame = CGRectMake(0, 0, 1024, 768); self.liveListVC.view.frame = CGRectMake(CGRectGetMaxX(self.toolBarView.frame), self.statusHeight, CGRectGetWidth(self.view.bounds)-CGRectGetWidth(self.toolBarView.frame), CGRectGetHeight(self.view.bounds)-self.statusHeight); }else { self.view.frame = CGRectMake(0, 0, 768, 1024); self.liveListVC.view.frame = CGRectMake(CGRectGetMaxX(self.toolBarView.frame), self.statusHeight, CGRectGetWidth(self.view.bounds)-CGRectGetMaxX(self.toolBarView.frame), CGRectGetHeight(self.view.bounds)-self.statusHeight); } self.maskView.frame = self.view.frame;//直播:竖屏进入互动后,页面显示异样(bug:4114) if (self.maskView && self.maskView.alpha >0) { self.commentController.view.frame = CGRectMake(CGRectGetWidth(self.view.bounds)-1214/2, self.statusHeight, 1214/2, CGRectGetHeight(self.view.bounds)-self.statusHeight); }else { self.commentController.view.frame = CGRectMake(CGRectGetWidth(self.view.bounds)-25, self.statusHeight, 1214/2, CGRectGetHeight(self.view.bounds)-self.statusHeight); } [self.liveListVC.tableView reloadData]; // [self.shareVC.view removeFromSuperview]; // [self.shareVC removeFromParentViewController]; // self.shareVC = nil; [self.shareVC.view removeFromSuperview]; // self.sharBtn.enabled = YES; [self.shareVC dismissViewControllerAnimated:YES completion:^{ [self.shareVC removeFromParentViewController]; self.shareVC = nil; }]; //【倒退】【适配性】ios7,分享:系统分享,闪退(bug:5674) if (isNotIOS8) { if ([shareUtil instance].popController &&[shareUtil instance].popController.isPopoverVisible) { [[shareUtil instance].popController dismissPopoverAnimated:YES]; } } isNeedScrollWithShare = NO; // if (self.shareVC) { // CGFloat padding = 0; // UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; // if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) { // padding = 125; // }else padding = -125; // shareStartPoint = CGPointMake(shareStartPoint.x+padding, shareStartPoint.y); // self.shareVC.startPoint = shareStartPoint; // } // if (self.shareVC) { // CGFloat padding = 0; // UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; // if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) { // padding = 125; // }else padding = -125; // if (shareStartPoint.y > 768) {//直播页,分享出来的菜单,横屏有异常(bug:3915) // isNeedScrollWithShare = YES; // if (isNotIOS7) { // shareStartPoint = CGPointMake(shareStartPoint.x+padding, 356);//【适配性】直播分享:竖屏分享后横屏,分享按钮显示异常(bug:4261) // }else{ // shareStartPoint = CGPointMake(shareStartPoint.x+padding, 365); // } // [self.liveListVC.tableView scrollToRowAtIndexPath:myIndexPath atScrollPosition:UITableViewScrollPositionMiddle animated:YES]; // }else{ // if (isNeedScrollWithShare) { // isNeedScrollWithShare = NO; // if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) { // if (isNotIOS7) { // shareStartPoint = CGPointMake(shareStartPoint.x+padding, 356);//【适配性】直播分享:竖屏分享后横屏,分享按钮显示异常(bug:4261) // }else{ // shareStartPoint = CGPointMake(shareStartPoint.x+padding, 365); // } // }else{ // if (isNotIOS7) { // shareStartPoint = CGPointMake(shareStartPoint.x+padding, 484);//【适配性】直播分享:竖屏分享后横屏,分享按钮显示异常(bug:4261) // }else{ // shareStartPoint = CGPointMake(shareStartPoint.x+padding, 493); // } // } // [self.liveListVC.tableView scrollToRowAtIndexPath:myIndexPath atScrollPosition:UITableViewScrollPositionMiddle animated:YES]; // }else { // isNeedScrollWithShare = NO; // shareStartPoint = CGPointMake(shareStartPoint.x+padding, shareStartPoint.y); // } // } // self.shareVC.startPoint = shareStartPoint; // } } #pragma mark - property get and set - (UIView*)toolBarView { if (!_toolBarView) { _toolBarView = [[UIView alloc]initWithFrame:CGRectMake(0, 18, 77, 600)]; _toolBarView.backgroundColor = [UIColor clearColor]; } return _toolBarView; } - (UIButton*)backButton { if (!_backButton) { _backButton = [UIButton buttonWithType:UIButtonTypeCustom]; _backButton.frame = CGRectMake(0,self.statusHeight, 70, 70); [_backButton setImage:Image(@"detailPage/contentBackImg.png") forState:UIControlStateNormal]; [_backButton setImage:Image(@"detailPage/contentBackImg_s.png") forState:UIControlStateHighlighted]; [_backButton setImageEdgeInsets:UIEdgeInsetsMake(10, 10, 10, 10)]; [_backButton addTarget:self action:@selector(popBack:) forControlEvents:UIControlEventTouchUpInside]; } return _backButton; } - (liveListController *)liveListVC { if (!_liveListVC) { _liveListVC = [[liveListController alloc]init]; _liveListVC.view.backgroundColor = self.view.backgroundColor; _liveListVC.delegate = self; } return _liveListVC; } - (toolBarBtnView*)commentButton { if (!_commentButton) { _commentButton = [[toolBarBtnView alloc]initWithFrame:CGRectMake(0,70+100, CGRectGetWidth(self.toolBarView.bounds), 50) withTarget:self selector:@selector(goToComment:) buttonImage:@"detailPage/Interaction.png" hilightImage:@"detailPage/Interaction_s.png" selectImage:nil]; _commentButton.edgeInsets =UIEdgeInsetsMake(0, CGRectGetWidth(self.toolBarView.bounds)/2-65/4, 45-56/2, CGRectGetWidth(self.toolBarView.bounds)/2-65/4); } return _commentButton; } - (TPSelectButton*)fontSizeButton { if (!_fontSizeButton) { _fontSizeButton = [[TPSelectButton alloc]initWithFrame:CGRectMake(0,CGRectGetMaxY(self.commentButton.frame)+40, CGRectGetWidth(self.toolBarView.bounds), 50) target:self selector:@selector(changeFontSize:)]; if ([[TPUserDefault instance].isNightMode intValue] == 0) { [_fontSizeButton setBUttonNormalImage:Image(@"Button/contentFontSize.png") highLightImage:nil selectedImage:nil]; }else { [_fontSizeButton setBUttonNormalImage:Image(@"Button/contentFontSize_night.png") highLightImage:nil selectedImage:nil]; } _fontSizeButton.textLabel.font = appFont(11, NO); _fontSizeButton.titleText = @"字号"; } return _fontSizeButton; } - (commentAndAskController*)commentController { if (!_commentController) { _commentController = [[commentAndAskController alloc]init]; _commentController.commentOT = @"2"; } return _commentController; } - (UIView*)maskView { if (!_maskView) { _maskView = [[UIView alloc]initWithFrame:self.view.bounds]; _maskView.backgroundColor = [UIColor blackColor]; if ([[TPUserDefault instance].isNightMode intValue] > 0) { _maskView.backgroundColor = [UIColor colorWithHexString:@"0x4c4c4c"]; } _maskView.alpha = 0.0f; } return _maskView; } - (void)setNodeId:(NSString *)nodeIdStr { _nodeId = nodeIdStr; self.liveListVC.viewModel.nodeId = nodeIdStr; self.liveListVC.nodeId = nodeIdStr; self.commentController.nodeId = nodeIdStr; } - (void)setLivePageBO:(liveDetailPageVO *)pageBO { _livePageBO = pageBO; self.liveListVC.livePageBO = pageBO; } - (void)setLiveInfoBO:(liveInfoBO *)infoBO { _liveInfoBO = infoBO; if (!isBlankString(infoBO.interactionNum)) { self.commentButton.titleText = infoBO.interactionNum; } } #pragma mark - button handler - (void)popBack:(UIButton*)btn { if (!self.isPresent) { [self.navigationController popViewControllerAnimated:YES]; }else { [self dismissViewControllerAnimated:YES completion:nil]; } } - (void)leftSwipeGestureHandler:(UISwipeGestureRecognizer*)gesture { [self goToComment:nil]; } //进入互动 - (void)goToComment:(UIButton*)btn { [UIView animateWithDuration:0.25 animations:^{ [self.view addSubview:self.maskView]; [self.view insertSubview:self.maskView belowSubview:self.commentController.view]; //新闻、直播、图集、话题等的详情页打开时,有菊花状加载标志时,点击返回键无效(bug:4447) [self.view insertSubview:self.backButton belowSubview:self.maskView]; self.maskView.alpha = 0.6f; } completion:^(BOOL finished) { [UIView animateWithDuration:0.25 animations:^{ CGRect rightViewFrame = self.commentController.view.frame; rightViewFrame.origin.x = CGRectGetWidth(self.view.bounds)-CGRectGetWidth(self.commentController.view.frame); self.commentController.view.frame = rightViewFrame; [self.commentController hiddenHandler]; } completion:^(BOOL finished) { self.leftSwipeGesture.enabled = NO; }]; }]; } - (void)dismissCommentView:(id)sender { [UIView animateWithDuration:0.35 animations:^{ self.maskView.alpha = 0; self.commentController.view.frame = CGRectMake(CGRectGetWidth(self.view.bounds)-25, self.statusHeight, 1214/2, CGRectGetHeight(self.view.bounds)-self.statusHeight); [self.commentController appearHander]; } completion:^(BOOL finished) { [self.maskView removeFromSuperview]; self.leftSwipeGesture.enabled = YES; }]; } - (void)rightSwipeGestureHandler:(UISwipeGestureRecognizer*)gesture { if (self.maskView.alpha > 0) { [self dismissCommentView:nil]; }else { if (!self.isPresent) { [self.navigationController popViewControllerAnimated:YES]; }else { [self dismissViewControllerAnimated:YES completion:nil]; } } } - (void)changeFontSize:(UIButton*)btn { fontSizeSliderController *fonSizeSelect = [[fontSizeSliderController alloc]init]; self.popOver = nil; self.popOver = [[UIPopoverController alloc]initWithContentViewController:fonSizeSelect]; self.popOver.popoverContentSize = CGSizeMake(650/2, 60); fonSizeSelect.delegate = self; [self.popOver presentPopoverFromRect:self.fontSizeButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES]; } #pragma mark - fong size select delgate - (void)contentFontSizeHasChange { [self.liveListVC reloadTableWithFontChange]; } #pragma mark - remote delegate and datasource - (void)startHud { if (!self.hud) { //新闻、直播、图集、话题等的详情页打开时,有菊花状加载标志时,点击返回键无效(bug:4447) self.leftSwipeGesture.enabled = NO; self.hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES]; // self.hud = [MBProgressHUD showHUDAddedTo:KEY_WINDOW animated:YES]; self.hud.mode = MBProgressHUDModeIndeterminate; self.hud.userInteractionEnabled = YES; self.hud.dimBackground = NO; UIColor *hudColor = [UIColor colorWithRed:76.5f/255.f green:76.5f/255.f blue:76.5f/255.f alpha:0.9f]; self.hud.color = hudColor; self.hud.cornerRadius = 4; self.hud.removeFromSuperViewOnHide = YES; //新闻、直播、图集、话题等的详情页打开时,有菊花状加载标志时,点击返回键无效(bug:4447) [self.view bringSubviewToFront:self.backButton]; } } - (void)stopHud { if (self.hud) { //新闻、直播、图集、话题等的详情页打开时,有菊花状加载标志时,点击返回键无效(bug:4447) self.leftSwipeGesture.enabled = YES; [self.hud hide:YES]; self.hud = nil; } } - (void)startWaitCursor:(int)actionTag { } - (void)stopWaitCursor:(int)actionTag { } #pragma mark -- viewmodel delegate - (void)getLiveDetailPageData:(liveDetailPageVO *)pageBO { self.liveListVC.livePageBO = pageBO; self.actionFlag = self.actionFlag -1; } // - (void)getLiveInfo:(liveInfoBO *)infoBO { self.liveInfoBO = infoBO; } -(void)returnCommentList:(NSMutableArray *)commentArray nodeId:(NSString *)nodeId nextUrl:(NSString *)nextUrl commentTotalRecord:(NSInteger)recordTotal{ self.commentController.nodeId = self.nodeId; self.commentController.commentList = commentArray; self.commentController.commentNextUrl = nextUrl; self.commentController.commentTotalRecord = recordTotal; self.actionFlag = self.actionFlag -1; } -(void)returnHotAskDic:(NSMutableDictionary *)qaDic nodeId:(NSString *)nodeId nextUrl:(NSString *)nextUrl askTotalRecord:(NSInteger)recordTotal{ self.commentController.nodeId = self.nodeId; self.commentController.qaDic = qaDic; self.commentController.askNextUrl = nextUrl; self.commentController.askTotalRecord = recordTotal; self.actionFlag = self.actionFlag -1; } -(void)returnMoreInfoData:(id)responseData{ } - (void)remoteResponsSuccess:(int)actionTag withResponsData:(id)responsData { if (actionTag == 1) { self.actionFlag = self.actionFlag -1; self.livePageBO = setJsonDicToDataModel(responsData, [liveDetailPageVO class]); self.liveInfoBO = setJsonDicToDataModel(self.livePageBO.liveInfo, [liveInfoBO class]); }else if (actionTag == 2) { self.actionFlag = self.actionFlag -1; self.commentList = [NSMutableArray array]; NSMutableArray *hotList = [NSMutableArray array]; NSArray *list = responsData[@"commentList"]; NSArray *hotDicList = responsData[@"hotList"]; [list enumerateObjectsUsingBlock:^(NSDictionary* obj, NSUInteger idx, BOOL *stop) { commentObjectVO *commentBO = setJsonDicToDataModel(obj, [commentObjectVO class]); [self.commentList addObject:commentBO]; }]; [hotDicList enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { commentObjectVO *commentBO = setJsonDicToDataModel(obj, [commentObjectVO class]); [hotList addObject:commentBO]; }]; NSMutableArray *commentDataList = [NSMutableArray array]; if (hotList.count > 0) { [commentDataList addObject:hotList]; } [commentDataList addObject:self.commentList]; self.commentController.commentList = commentDataList; self.commentController.commentNextUrl = responsData[@"nextUrl"]; self.commentController.commentTotalRecord = [responsData[@"recordTotal"] integerValue]; if (!self.commentController.nodeId) { self.commentController.nodeId = self.nodeId; } }else if (actionTag == 3) { self.actionFlag = self.actionFlag -1; self.commentController.askTotalRecord = [responsData[@"recordTotal"] integerValue]; self.qaDataDic = [NSMutableDictionary dictionary]; NSArray *hotQaList = responsData[@"hotQaList"]; NSMutableArray *hotQaArray = [NSMutableArray array]; [hotQaList enumerateObjectsUsingBlock:^(NSDictionary* obj, NSUInteger idx, BOOL *stop) { commentObjectVO *commentBO = setJsonDicToDataModel(obj, [commentObjectVO class]); [hotQaArray addObject:commentBO]; }]; [self.qaDataDic setValue:hotQaArray forKey:@"hotQaList"]; NSArray *qaTempList = responsData[@"qaList"]; NSMutableArray *qaArray = [NSMutableArray array]; [qaTempList enumerateObjectsUsingBlock:^(NSDictionary* obj, NSUInteger idx, BOOL *stop) { commentObjectVO *commentBO = setJsonDicToDataModel(obj, [commentObjectVO class]); [qaArray addObject:commentBO]; }]; [self.qaDataDic setValue:qaArray forKey:@"qaList"]; self.commentController.qaDic = self.qaDataDic; NSString *url = responsData[@"nextUrl"]; self.commentController.askNextUrl = url; if (!self.commentController.nodeId) { self.commentController.nodeId = self.nodeId; } } } - (void)remoteResponsFailed:(int)actionTag withMessage:(NSString *)message resultCode:(NSString *)code{ // [self stopHud]; if ([code intValue] == 5) { [self contentHaveOfflined]; }else { ShowTextMessage(message); } } - (void)remoteFail { [self stopHud]; //【需求】无网络处理优化(重新加载打底图)(bug:5953) // if (![Remote IsEableNetwork]) { [self.liveListVC networkTimeOut]; // } } -(void)needRefrshPage{ [self startHud]; self.model.nodeId = self.nodeId; [self.model remoteAction]; } - (void)contentHaveOffline { [self contentHaveOfflined]; } #pragma mark - child controller delegate - (void)listRefreshed:(liveInfoBO *)liveInfo { self.liveInfoBO = liveInfo; } - (void)beginToShare:(NSString *)shareText startPoint:(CGPoint)startPoint { if (self.shareVC) { [self.shareVC removeFromParentViewController]; [self.shareVC.view removeFromSuperview]; self.shareVC = nil; } if (startPoint.y < 265) { CGFloat offset = 265 - startPoint.y; [self.liveListVC.tableView setContentOffset:CGPointMake(0, self.liveListVC.tableView.contentOffset.y-offset) animated:YES]; startPoint = CGPointMake(startPoint.x, startPoint.y+offset); } shareStartPoint = startPoint; self.shareVC = [[TPShareContentControlelr alloc]init]; self.shareVC.shareImage = Image(@"Button/liveShareBtn.png"); self.shareVC.direction = expandLeft; self.shareVC.sharestyle = shareLiveStyle; self.shareVC.delegate = self; if (isNotIOS7) { startPoint = CGPointMake(startPoint.x, startPoint.y-10); } self.shareVC.startPoint = startPoint; contentObjectBO *contentBO = contentObjectBO.new; contentBO.sharePic = self.liveInfoBO.sharePic; contentBO.shareUrl = self.liveInfoBO.shareUrl; contentBO.name = self.liveInfoBO.name; contentBO.summary = shareText; self.shareVC.contentBO = contentBO; self.shareVC.view.bounds = self.view.bounds; [self addChildViewController:self.shareVC]; [self.view addSubview:self.shareVC.view]; [self.view bringSubviewToFront:self.commentController.view]; } -(void)shareIndexPath:(NSIndexPath *)indexPath{ myIndexPath = indexPath; } //视频:直播页和详情页播放视频,全屏播放视频,点击右上角的叉,会点到状态栏,导致底部页面弹回头部(bug:5748) -(void)statusBarHidden:(BOOL)isHidden{ hiddenStatusBar = isHidden; if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) { [self prefersStatusBarHidden]; [self setNeedsStatusBarAppearanceUpdate]; }else { [[UIApplication sharedApplication] setStatusBarHidden:hiddenStatusBar withAnimation:UIStatusBarAnimationFade]; } } - (BOOL)prefersStatusBarHidden { return hiddenStatusBar; } #pragma mark - sharecontent delegate - (void)dismissContent { [self.shareVC.view removeFromSuperview]; [self.shareVC removeFromParentViewController]; self.shareVC = nil; isNeedScrollWithShare = NO; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (void)dealloc { self.liveListVC = nil; self.model.delegate = nil; self.model = nil; [[NSNotificationCenter defaultCenter]removeObserver:self]; } - (void)linkWithPush:(NSNotification*)noti { [self.liveListVC stopAndRemoveVideo]; } /* #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