热更新demo

TPLiveHomeController.m 11KB

    // // TPLiveHomeController.m // ThePaperDemo // // Created by zhousan on 15/7/1. // Copyright (c) 2015年 scar1900. All rights reserved. // #import "TPLiveHomeController.h" #import "liveListController.h" #import "liveViewModel.h" #import "commentAndAskController.h" #import "shareContent.h" #import "MLNavigationController.h" #define SHARECONTENTTAG 2500 @interface TPLiveHomeController () <liveViewModelDelegate,liveListDelegate,shareContentDelegate,fontSizeSleideControllerDelegate> { BOOL isHiddenStatusBar; BOOL isCouldChangeToPortait; } @property(nonatomic, strong)liveListController *liveListVC; @property(nonatomic, strong)liveViewModel *viewModel; @property(nonatomic, strong)liveInfoBO *liveInfoBO; @property(nonatomic, strong)UIButton *commentButton; @property(nonatomic, strong)UIButton *fontSizeButton; @property(nonatomic, strong)UISwipeGestureRecognizer *leftSwipeGesture; @property(nonatomic, strong)commentAndAskController *commentController; @property(nonatomic, strong)UIView *maskView; @end @implementation TPLiveHomeController @synthesize isPlay; - (void)viewDidLoad { [super viewDidLoad]; [MobClick event:@"7"]; isCouldChangeToPortait = NO; self.liveListVC.nodeId = self.nodeId; self.viewModel = [liveViewModel new]; self.viewModel.nodeId = self.nodeId; self.viewModel.delegate = self; // [self.viewModel remoteAction]; self.fontVC.delegate = self; self.commentController.nodeId = self.nodeId; [self.viewModel remoteAction]; self.contentVC = self.liveListVC; self.askVC = self.commentController; self.titleStr = @"直播"; [self.naviBar addSubview:self.commentButton]; [self.naviBar addSubview:self.fontSizeButton]; self.commentButton.titleLabel.font = appFont(12, NO); self.commentButton.titleLabel.textAlignment = NSTextAlignmentLeft; [self.commentButton setTitleColor:[UIColor colorWithHexString:BLUECOLOR] forState:UIControlStateNormal]; isPlay = NO; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(linkWithPush:) name:PUSHCLICK object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(statusBarOrientationWillChange:) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil]; } - (void)linkWithPush:(NSNotification*)noti { [self.liveListVC stopAndRemoveVideo]; /** * bug:5682( 推送:视频播放中收到推送,有如下问题) */ } #pragma mark - Getter and setter - (void)setNodeId:(NSString *)nodeId { _nodeId = nodeId; } - (liveListController *)liveListVC { if (!_liveListVC) { _liveListVC = [[liveListController alloc] init]; _liveListVC.delegate = self; } return _liveListVC; } - (commentAndAskController*)commentController { if (!_commentController) { _commentController = [[commentAndAskController alloc]init]; _commentController.commentOT = @"2"; } return _commentController; } - (void)beginToShare:(NSString *)shareText button:(UIButton *)btn { contentObjectBO *contentBO = contentObjectBO.new; contentBO.sharePic = self.liveInfoBO.sharePic; contentBO.shareUrl = self.liveInfoBO.shareUrl; contentBO.name = self.liveInfoBO.name; contentBO.summary = shareText; if (!btn.selected) { shareContent *shareContentView = [[shareContent alloc]initWithFrame:self.view.bounds]; shareContentView.delegate = self; shareContentView.tag = SHARECONTENTTAG; shareContentView.contentBO = contentBO; shareContentView.sharestyle = shareLiveStyle; shareContentView.baseController = self; [shareContentView presentShareContentInView:self.view sender:btn]; }else { shareContent *shareContentView = (shareContent*)[self.view viewWithTag:SHARECONTENTTAG]; if (shareContentView) { [shareContentView dismissShareContent]; } } } - (void)didDismissShareContent:(UIView *)contentView { contentView = nil; } - (UIButton *)commentButton { if (!_commentButton) { _commentButton = [UIButton buttonWithType:UIButtonTypeCustom]; _commentButton.frame = CGRectMake(CGRectGetMaxX(self.naviBar.frame)-60, 22, 60, 40); [_commentButton setImage:Image(@"live/commentIcon.png") forState:UIControlStateNormal]; [_commentButton addTarget:self action:@selector(gotoComment:) forControlEvents:UIControlEventTouchUpInside]; _commentButton.imageEdgeInsets = UIEdgeInsetsMake(9, 10, 13, 5); _commentButton.titleEdgeInsets = UIEdgeInsetsMake(7, 10, 11, 0); // _commentButton.backgroundColor = [UIColor greenColor]; } return _commentButton; } - (UIButton *)fontSizeButton { if (!_fontSizeButton) { _fontSizeButton = [UIButton buttonWithType:UIButtonTypeCustom]; _fontSizeButton.frame = CGRectMake(_commentButton.frame.origin.x - 35, 22, 35, 40); [_fontSizeButton setImage:Image(@"live/fontChangeBtn.png") forState:UIControlStateNormal]; [_fontSizeButton addTarget:self action:@selector(fontSizeClick:) forControlEvents:UIControlEventTouchUpInside]; [_fontSizeButton setImageEdgeInsets:UIEdgeInsetsMake(7.5, 6, 12.5, 11)]; // _fontSizeButton.backgroundColor = [UIColor redColor]; UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(_commentButton.frame.origin.x, 34, 0.5, 15)]; lineView.backgroundColor = [UIColor colorWithHexString:LINECOLOR]; [self.naviBar addSubview:lineView]; } return _fontSizeButton; } #pragma mark - fontDelegate - (void)contentFontSizeHasChange { [self.liveListVC reloadTableWithFontChange]; } - (void)getLiveDetailPageData:(liveDetailPageVO *)pageBO { // self.actionFlag = self.actionFlag -1; self.liveListVC.livePageBO = pageBO; } // - (void)getLiveInfo:(liveInfoBO *)infoBO { self.liveInfoBO = infoBO; if (!isBlankString(infoBO.interactionNum)) { [self.commentButton setTitle:infoBO.interactionNum forState:UIControlStateNormal]; } } #pragma mark - backBtnClick - (void)backHandler { ((MLNavigationController *)self.navigationController).canDragBack = YES; if ([self.navigationController.topViewController isKindOfClass:[TPLiveHomeController class]]) { [self.liveListVC stopAndRemoveVideo]; } [self.navigationController popViewControllerAnimated:YES]; } #pragma mark - button handler - (void)gotoComment:(id)sender { [self moveToAskAndComment]; } - (void)fontSizeClick:(UIButton *)sender { [self.fontVC reflashSize:[TPUserDefault instance].contFontSize]; if (!sender.selected) { self.fontVC.view.hidden = NO; [self.fontVC showfontSizeSliderCellFinishedWithCompletion:^(BOOL finished) { sender.selected = YES; ((MLNavigationController *)self.navigationController).canDragBack = NO; [self removePanGesture]; }]; }else { [self.fontVC dismissfontSizeSliderCellFinishCompletion:^(BOOL finished) { self.fontVC.view.hidden = YES; sender.selected = NO; ((MLNavigationController *)self.navigationController).canDragBack = YES; [self reAddpanGesture]; }]; } } - (void)clickToDismiss { [self fontSizeClick:self.fontSizeButton]; } - (void)returnCommentList:(NSMutableArray *)commentArray nodeId:(NSString *)nodeId nextUrl:(NSString *)nextUrl commentTotalRecord:(NSInteger)recordTotal { self.commentController.nodeId = self.nodeId; self.commentController.commentList = commentArray; self.commentController.firstCommentUrl = nextUrl; self.commentController.commentSum = recordTotal; } - (void)returnHotAskDic:(NSMutableDictionary *)qaDic nodeId:(NSString *)nodeId nextUrl:(NSString *)nextUrl askTotalRecord:(NSInteger)recordTotal { self.commentController.nodeId = self.nodeId; self.commentController.dataDic = qaDic; self.commentController.firstAskUrl = nextUrl; self.commentController.qaNum = recordTotal; } - (void)remoteFail:(BOOL)isTimeOut { self.commentController.nodeId = self.nodeId; if (isTimeOut) { [self.liveListVC networkTimeOut]; [self stopHud]; } } //网络出错 - (void)contentHaveOffline { [self stopHud]; [self contentHaveOfflined]; } - (void)startHud { [self.view addSubview:self.waitBackView]; [self.view bringSubviewToFront:self.waitBackView]; [self removePanGesture]; self.waitCursor.animating = YES; } - (void)stopHud { [self.waitBackView removeFromSuperview]; self.waitBackView = nil; [self reAddpanGesture]; self.waitCursor.animating = NO; } - (void)refreshData { [self.viewModel remoteAction]; } - (void)videoEnterFullScreen:(BOOL)isEnterFullScreen { if (isEnterFullScreen) { [self hideStatusBar]; }else { [self showStatusBar]; } } - (void)startHudAnimation { [self startHud]; } - (BOOL)prefersStatusBarHidden { return isHiddenStatusBar; } - (void)stopHudAnimation { [self stopHud]; } - (void)showStatusBar { isHiddenStatusBar = NO; if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) { [self prefersStatusBarHidden]; [self setNeedsStatusBarAppearanceUpdate]; } } - (void)hideStatusBar { isHiddenStatusBar = YES; if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) { [self prefersStatusBarHidden]; [self setNeedsStatusBarAppearanceUpdate]; } } - (void)listRefreshed:(liveInfoBO *)liveInfo { } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (void)dealloc { [[NSNotificationCenter defaultCenter]removeObserver:self]; } - (BOOL)shouldAutorotate { if (self.liveListVC.viewModel.moviePlayerController) { return YES; }else { return isCouldChangeToPortait; } } - (UIInterfaceOrientationMask)supportedInterfaceOrientations { if (self.liveListVC.viewModel.moviePlayerController) { isCouldChangeToPortait = NO; if (self.isClose) { return UIInterfaceOrientationMaskPortrait; }else { return UIInterfaceOrientationMaskLandscape; } }else { isCouldChangeToPortait = YES; return UIInterfaceOrientationMaskPortrait; } } - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { if (self.liveListVC.viewModel.moviePlayerController) { return UIInterfaceOrientationLandscapeLeft | UIInterfaceOrientationLandscapeRight; }else { return UIInterfaceOrientationPortrait; } } - (void)statusBarOrientationWillChange:(NSNotification *)note { if (self.liveListVC.viewModel.moviePlayerController) { [self.liveListVC.viewModel.moviePlayerController relayoutSubViewForScreen:KEY_WINDOW.bounds fullScreen:YES]; [self hideStatusBar]; } } /* #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