|
//
// detailContentHomeController.m
// ThePaperHD
//
// Created by scar1900 on 15/1/14.
// Copyright (c) 2015年 scar1900. All rights reserved.
//
#import "detailContentHomeController.h"
#import "detailContentController.h"
#import "commentAndAskController.h"
#import "TPSelectButton.h"
#import "loginPopUpController.h"
#import "shareButton.h"
#import "TPShareContentControlelr.h"
#import "toolBarBtnView.h"
#import "fontSizeSliderController.h"
#import "detailPageViewModel.h"
#import "commentOkButton.h"
#define TRACKACTIONTAG 1000
#define CANCELTRACKTAG 1001
#define COLLECTTAG 1002
#define CANCELCOLLECTTAG 1003
@interface detailContentHomeController ()<shareContentControllerDelegate,fontSizeSleideControllerDelegate,detailContentDelegate,detailPageViewModelDelegate>{
BOOL hiddenStatusBar;
}
@property(nonatomic, strong)UIButton *backButton;
@property(nonatomic, assign)CGFloat statusHeight;
@property(nonatomic, strong)UIView *toolBarView;
@property(nonatomic, strong)toolBarBtnView *commentButton;
@property(nonatomic, strong)TPSelectButton *trackButton;
@property(nonatomic, strong)TPSelectButton *collectButton;
@property(nonatomic, strong)TPSelectButton *praiseButton;
@property(nonatomic, strong)TPSelectButton *fontSizeButton;
@property(nonatomic, strong)shareButton *sharBtn;
@property(nonatomic, strong)detailContentController *detailContentVC;
@property(nonatomic, strong)contDetailPageVO *detailContentBO;
@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)ContDetailPageDB *currentDetaialDB;
@property(nonatomic, strong)UIPopoverController *popOverVC;
@property(nonatomic, assign)NSInteger actionFlag;
@property(nonatomic, strong)detailPageViewModel *detailModel;
@end
@implementation detailContentHomeController
@synthesize statusHeight;
@synthesize nodeID = _nodeID;
@synthesize detailContentBO = _detailContentBO;
@synthesize commentList,qaDataDic;
@synthesize leftSwipeGesture;
@synthesize shareVC,currentDetaialDB;
@synthesize actionFlag = _actionFlag;
@synthesize detailModel;
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[MobClick event:@"3"];
if (isIOS7) {
self.statusHeight = 18;
}else {
self.statusHeight = 0;
}
[self.view addSubview:self.toolBarView];
[self.view addSubview:self.backButton];
[self.toolBarView addSubview:self.commentButton];
[self.toolBarView addSubview:self.trackButton];
[self.toolBarView addSubview:self.collectButton];
[self.toolBarView addSubview:self.praiseButton];
[self.toolBarView addSubview:self.fontSizeButton];
[self.view addSubview:self.sharBtn];
[self setContentFramWithOrirentation];
[self addChildViewController:self.detailContentVC];
[self addChildViewController:self.commentController];
[self.view addSubview:self.detailContentVC.view];
[self.view addSubview:self.commentController.view];
[self.detailContentVC didMoveToParentViewController:self];
[self.commentController didMoveToParentViewController:self];
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 startHud];
[self.detailModel checkContentDataInCoreData:self.nodeID tableView:self.detailContentVC.tableView];
// [self checkContentDataInCoreData:self.nodeID];
[self enablePopBackGesture];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willPopBack:) name:CONTENTDETAILPOPBACK object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(linkWithPush:) name:PUSHCLICK object:nil];
int visitNum = [[TPUserDefault instance].visitTime intValue];
// TPLOG(@"=====进去的时候的次数========%d",visitNum);
if ([TPUserDefault instance].visitTime) {
if ([[TPUserDefault instance].visitTime intValue]>=0 && [[TPUserDefault instance].visitTime intValue] < 10) {
visitNum++;
[TPUserDefault instance].visitTime = [NSString stringWithFormat:@"%d",visitNum];
}else{
return;
}
}else{
// [TPUserDefault instance].visitTime = 1;
}
}
- (void)setActionFlag:(NSInteger)flag {
_actionFlag = flag;
if (flag == 0) {
[self stopHud];
}
}
- (void)willPopBack:(NSNotification*)notification {
[TPUserDefault instance].lastContentOffset = self.detailContentVC.tableView.contentOffset;
[TPUserDefault instance].lastContentID = self.nodeID;
if ([[TPUserDefault instance].visitTime intValue]>=10) {//【需求】评分(bug:4308,bug:5259)
// dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.05 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[TPUserDefault instance].visitTime= @"-1";
AppDelegate *delegate=(AppDelegate*)[[UIApplication sharedApplication]delegate];
YRSideViewController *sideController=[delegate sideViewController];
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"" message:@"澎友,您已经用最新版的澎湃看了几篇文章,如果觉得好,请鼓励评分一下。" delegate:sideController cancelButtonTitle:@"鼓励一下" otherButtonTitles:@"还需努力",nil];
[alert show];
// });
}
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.navigationController.navigationBarHidden = YES;
}
- (void)setContentFramWithOrirentation {
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIInterfaceOrientationLandscapeRight
|| orientation ==UIInterfaceOrientationLandscapeLeft) {
self.view.frame = CGRectMake(0, 0, 1024, 768);
self.detailContentVC.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.detailContentVC.view.frame = CGRectMake(CGRectGetMaxX(self.toolBarView.frame),
self.statusHeight,
CGRectGetWidth(self.view.bounds)-CGRectGetMaxX(self.toolBarView.frame),
CGRectGetHeight(self.view.bounds)-self.statusHeight);
}
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.maskView.frame = self.view.bounds;
self.sharBtn.frame = CGRectMake(5, CGRectGetHeight(self.view.bounds)-77, 72, 72);
if (isNotIOS7) {
self.sharBtn.frame = CGRectMake(5, CGRectGetHeight(self.view.bounds)-97, 72, 72);
}
[self.detailContentVC.tableView reloadData];
[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];
}
}
// [self.shareVC dismissViewControllerAnimated:YES completion:nil];
}
#pragma mark - set and get method
- (void)statusBarOrientationChange:(NSNotification *)notification{
[self setContentFramWithOrirentation];
}
- (void)setDetailContentBO:(contDetailPageVO *)detailBO {
if (detailBO) {
_detailContentBO = detailBO;
NSString *interactionStr = detailBO.content[@"interactionNum"]?detailBO.content[@"interactionNum"]:@"";
NSString *isTracked = detailBO.content[@"isTracked"]?detailBO.content[@"isTracked"]:@"";
NSString *isFavorited = detailBO.content[@"isFavorited"]?detailBO.content[@"isFavorited"]:@"";
if (!isBlankString(interactionStr)) {
self.commentButton.titleText = interactionStr;
}
if (!isBlankString(isTracked) && [isTracked intValue] == 1 && [TPUserDefault instance].userBO) {
[self.trackButton setSelect:YES animation:NO];
}else {
[self.trackButton setSelect:NO animation:NO];
}
if (!isBlankString(isFavorited) && [isFavorited intValue] == 1 && [TPUserDefault instance].userBO) {
[self.collectButton setSelect:YES animation:NO];
}else {
[self.collectButton setSelect:NO animation:NO];
}
NSString *praiseNum = detailBO.content[@"praiseTimes"]?detailBO.content[@"praiseTimes"]:@"";
if (!isBlankString(praiseNum)) {
self.praiseButton.titleText = praiseNum;
}
self.detailContentVC.detailContentBO = detailBO;
}
}
- (void)setNodeID:(NSString *)nodeIDStr {
_nodeID = nodeIDStr;
self.detailModel = detailPageViewModel.new;
self.detailModel.delegate = self;
self.detailModel.nodeID = self.nodeID;
self.commentController.nodeId = self.nodeID;
}
- (UIView*)toolBarView {
if (!_toolBarView) {
_toolBarView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 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;
}
- (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*)trackButton {
if (!_trackButton) {
_trackButton = [[TPSelectButton alloc]initWithFrame:CGRectMake(0,CGRectGetMaxY(self.commentButton.frame)+40, CGRectGetWidth(self.toolBarView.bounds), 50)
target:self
selector:@selector(trackHandler:)];
[_trackButton setBUttonNormalImage:Image(@"detailPage/trackImg.png")
highLightImage:Image(@"detailPage/trackImg_h.png")
selectedImage:Image(@"detailPage/trackImg_s.png")];
_trackButton.textLabel.text = @"跟踪";
_trackButton.textLabel.font = appFont(11, NO);
}
return _trackButton;
}
- (TPSelectButton*)collectButton {
if (!_collectButton) {
_collectButton = [[TPSelectButton alloc]initWithFrame:CGRectMake(0,CGRectGetMaxY(self.trackButton.frame)+40, CGRectGetWidth(self.toolBarView.bounds), 50)
target:self
selector:@selector(collectHandler:)];
[_collectButton setBUttonNormalImage:Image(@"detailPage/collectImg.png")
highLightImage:Image(@"detailPage/collectImg_h.png")
selectedImage:Image(@"detailPage/collectImg_s.png")];
_collectButton.textLabel.text = @"收藏";
_collectButton.textLabel.font = appFont(11, NO);
}
return _collectButton;
}
- (TPSelectButton*)praiseButton {
if (!_praiseButton) {
_praiseButton = [[TPSelectButton alloc]initWithFrame:CGRectMake(0,CGRectGetMaxY(self.collectButton.frame)+40, CGRectGetWidth(self.toolBarView.bounds), 50)
target:self
selector:@selector(praiseHandler:)];
[_praiseButton setBUttonNormalImage:Image(@"detailPage/praiseImg.png")
highLightImage:Image(@"detailPage/praiseImg_h.png")
selectedImage:Image(@"detailPage/praiseImg_s.png")];
_praiseButton.textLabel.font = appFont(11, NO);
}
return _praiseButton;
}
- (TPSelectButton*)fontSizeButton {
if (!_fontSizeButton) {
_fontSizeButton = [[TPSelectButton alloc]initWithFrame:CGRectMake(0,CGRectGetMaxY(self.praiseButton.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;
}
- (shareButton*)sharBtn {
if (!_sharBtn) {
_sharBtn = [[shareButton alloc]initWithFrame:CGRectMake(5, CGRectGetHeight(self.view.bounds)-77, 72, 72)];
[_sharBtn setImage:Image(@"detailPage/shareBtn.png") forState:UIControlStateNormal];
[_sharBtn setImage:Image(@"detailPage/shareBtn.png") forState:UIControlStateHighlighted];
[_sharBtn setImage:Image(@"detailPage/shareBtn.png") forState:UIControlStateDisabled];
[_sharBtn addTarget:self action:@selector(shareHandler:) forControlEvents:UIControlEventTouchUpInside];
}
return _sharBtn;
}
- (detailContentController *)detailContentVC {
if (!_detailContentVC) {
_detailContentVC = [[detailContentController alloc]init];
_detailContentVC.view.backgroundColor = self.view.backgroundColor;
_detailContentVC.detailDelegate = self;
}
return _detailContentVC;
}
- (commentAndAskController*)commentController {
if (!_commentController) {
_commentController = [[commentAndAskController alloc]init];
}
return _commentController;
}
- (UIView*)maskView {
if (!_maskView) {
_maskView = [[UIView alloc]initWithFrame:self.view.bounds];
_maskView.backgroundColor = [UIColor colorWithHexString:MaskColor];
_maskView.alpha = 0.0f;
}
return _maskView;
}
#pragma mark - button handler
- (void)popBack:(UIButton*)btn {
// if (!self.isPresent) {
[self.navigationController popViewControllerAnimated:YES];
// }else {
// [self dismissViewControllerAnimated:YES completion:nil];
// }
// if ([[TPUserDefault instance].visitTime intValue]>=10) {//【需求】评分(bug:4308,bug:5259)
// [TPUserDefault instance].visitTime= @"-1";
// UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"" message:@"澎友,您已经用最新版的澎湃看了几篇文章,如果觉得好,请鼓励评分一下。" delegate:self cancelButtonTitle:@"鼓励一下" otherButtonTitles:@"还需努力",nil];
// [alert show];
// }
}
////【需求】评分(bug:4308)
//- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
// if (buttonIndex == 0) {
// [MobClick event:@"45"];//【需求】统计-iPad(BUG:4358)
// NSString *str = [NSString stringWithFormat:@"http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id=%@&pageNumber=0&sortOrdering=2&type=Purple+Software&mt=8", @"986646876" ];
// [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
// }else{
// [MobClick event:@"46"];//【需求】统计-iPad(BUG:4358)
// }
//}
//进入互动
- (void)goToComment:(UIButton*)btn {
[self.detailContentVC stopAndRemoveVideo];
[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)trackHandler:(UIButton*)btn {
if (!btn.selected) {
if (![TPUserDefault instance].userBO) {
__weak typeof(self) Self = self;
[self presentLoginModal:^{
} dismiss:^{
if ([TPUserDefault instance].userBO) {
[self.detailModel trackContent:^{
[MobClick event:@"6"];
[Self stopHud];
[Self.trackButton setSelect:YES animation:YES];
NSString *trackKeyWord = self.detailContentVC.contentBO.trackKeyword;
contDetailPageVO *data = self.detailContentBO;
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithDictionary:self.detailContentBO.content];
[dict setObject:@"1" forKey:@"isTracked"];
data.content = dict;
[Self changeDB:data];
}];
}
}];
return;
}
[self.detailModel trackContent:^{
[MobClick event:@"6"];
[self stopHud];
[self.trackButton setSelect:YES animation:YES];
NSString *trackKeyWord = self.detailContentVC.contentBO.trackKeyword;
contDetailPageVO *data = self.detailContentBO;
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithDictionary:self.detailContentBO.content];
[dict setObject:@"1" forKey:@"isTracked"];
data.content = dict;
[self changeDB:data];
}];
}else {
if (![TPUserDefault instance].userBO) {
__weak typeof(self) Self = self;
[self presentLoginModal:^{
} dismiss:^{
if ([TPUserDefault instance].userBO) {
[Self.detailModel cancelTrackContent:^{
[self stopHud];
[self.trackButton setSelect:NO animation:YES];
NSString *trackKeyWord = self.detailContentVC.contentBO.trackKeyword;
contDetailPageVO *data = self.detailContentBO;
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithDictionary:self.detailContentBO.content];
[dict setObject:@"0" forKey:@"isTracked"];
data.content = dict;
[self changeDB:data];
ShowTextMessage([NSString stringWithFormat:@"取消跟踪:%@",trackKeyWord]);
}];
}
}];
return;
}
[self.detailModel cancelTrackContent:^{
[self stopHud];
[self.trackButton setSelect:NO animation:YES];
NSString *trackKeyWord = self.detailContentVC.contentBO.trackKeyword;
contDetailPageVO *data = self.detailContentBO;
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithDictionary:self.detailContentBO.content];
[dict setObject:@"0" forKey:@"isTracked"];
data.content = dict;
[self changeDB:data];
ShowTextMessage([NSString stringWithFormat:@"取消跟踪:%@",trackKeyWord]);
}];
}
}
- (void)collectHandler:(UIButton*)btn {
if (!btn.selected) {
if (![TPUserDefault instance].userBO) {
__weak typeof(self) Self = self;
[self presentLoginModal:^{
} dismiss:^{
if ([TPUserDefault instance].userBO) {
[Self.detailModel collectContent:^{
[MobClick event:@"7"];
[self stopHud];
[self.collectButton setSelect:YES animation:YES];
contDetailPageVO *data = self.detailContentBO;
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithDictionary:self.detailContentBO.content];
[dict setObject:@"1" forKey:@"isFavorited"];
data.content = dict;
[self changeDB:data];
ShowMessage(@"收藏成功", YES);
}];
}
}];
return;
}
[self.detailModel collectContent:^{
[MobClick event:@"7"];
[self stopHud];
[self.collectButton setSelect:YES animation:YES];
contDetailPageVO *data = self.detailContentBO;
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithDictionary:self.detailContentBO.content];
[dict setObject:@"1" forKey:@"isFavorited"];
data.content = dict;
[self changeDB:data];
ShowMessage(@"收藏成功", YES);
}];
}else {
if (![TPUserDefault instance].userBO) {
__weak typeof(self) Self = self;
[self presentLoginModal:^{
} dismiss:^{
if ([TPUserDefault instance].userBO) {
[Self.detailModel cancelCollect:^{
[self stopHud];
[self.collectButton setSelect:NO animation:YES];
contDetailPageVO *data = self.detailContentBO;
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithDictionary:self.detailContentBO.content];
[dict setObject:@"0" forKey:@"isFavorited"];
data.content = dict;
[self changeDB:data];
ShowMessage(@"取消收藏", YES);
}];
}
}];
return;
}
[self.detailModel cancelCollect:^{
[self stopHud];
[self.collectButton setSelect:NO animation:YES];
contDetailPageVO *data = self.detailContentBO;
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithDictionary:self.detailContentBO.content];
[dict setObject:@"0" forKey:@"isFavorited"];
data.content = dict;
[self changeDB:data];
ShowMessage(@"取消收藏", YES);
}];
}
}
- (void)praiseHandler:(UIButton*)btn {
if (!self.detailContentVC.contentBO) {
return;
}
if (btn.selected) {
return;
}
[self.praiseButton setSelected:YES animated:YES];//【需求】点赞动画(bug:4969)
// NSDictionary *dic = @{@"c":self.detailContentVC.contentBO.contId};
__weak typeof(self) Self = self;
[self.detailModel praiseHandler:self.praiseButton.button completion:^(BOOL success, NSString *message, id responseData) {
if (success) {
[MobClick event:@"8"];
NSString *praseNum = [responseData[@"voteTimes"] stringValue];
if([praseNum intValue] <1000){//点赞:点赞超过1K的,几个页面会出现显示不全的现象(bug:5371)
Self.praiseButton.textLabel.text = praseNum;
}
//点赞按钮:点赞按钮点赞后,再次点击异常(bug:5370)
Self.praiseButton.userInteractionEnabled = NO;
TPLOG(@"点赞成功");
}else {
ShowMessage(@"点赞失败", NO);
}
}];
}
- (void)changeFontSize:(UIButton*)btn {
if (!self.detailContentVC.contentBO) {
return;
}
fontSizeSliderController *fonSizeSelect = [[fontSizeSliderController alloc]init];
self.popOverVC = nil;
self.popOverVC = [[UIPopoverController alloc]initWithContentViewController:fonSizeSelect];
self.popOverVC.popoverContentSize = CGSizeMake(650/2, 60);
fonSizeSelect.delegate = self;
[self.popOverVC presentPopoverFromRect:self.fontSizeButton.frame
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionUp
animated:YES];
}
- (void)shareHandler:(shareButton*)btn {
if (!self.detailContentVC.contentBO) {
return;
}
if (self.shareVC) {
[self.shareVC removeFromParentViewController];
[self.shareVC.view removeFromSuperview];
self.shareVC = nil;
}
self.shareVC = [[TPShareContentControlelr alloc]init];
self.shareVC.direction = expandRight;
self.shareVC.sharestyle = shareNewsStyle;
self.shareVC.startPoint = CGPointMake(5, CGRectGetHeight(self.view.bounds)-77);
if (isNotIOS7) {
self.shareVC.startPoint = CGPointMake(5, CGRectGetHeight(self.view.bounds)-87);
}
self.shareVC.view.bounds = self.view.bounds;
self.shareVC.delegate = self;
self.shareVC.contentBO = self.detailContentVC.contentBO;
[self addChildViewController:self.shareVC];
[self.view addSubview:self.shareVC.view];
self.sharBtn.enabled = NO;
[self.view bringSubviewToFront:self.commentController.view];
}
- (void)presentLoginModal:(void (^)(void))completion dismiss:(void (^)(void))dismiss {
loginPopUpController *loginVC = loginPopUpController.new;
[self presentController:loginVC animated:YES presentSize:loginPopUpSize completion:^{
if (completion) {
completion();
}
} dismiss:^{
if (dismiss) {
dismiss();
}
}];
}
- (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)needRefreshPage {
[self startHud];
self.actionFlag = 3;
[self.detailModel remoteAction];
}
#pragma mark - sharecontent delegate
- (void)dismissContent {
[self.shareVC.view removeFromSuperview];
[self.shareVC removeFromParentViewController];
self.shareVC = nil;
self.sharBtn.enabled = YES;
}
-(void)orderDelegate:(contDetailPageVO *)dataModel{
[self changeDB:dataModel];
}
#pragma mark - swipe handler
- (void)leftSwipeGestureHandler:(UISwipeGestureRecognizer*)gesture {
[self goToComment:nil];
}
#pragma mark - swipe handler
- (void)rightSwipeGestureHandler:(UISwipeGestureRecognizer*)gesture {
if (self.detailContentVC.isVideoPlaying) {
return;
}
if (self.maskView.alpha > 0) {
[self dismissCommentView:nil];
}else {//【需求】评分(bug:4308,bug:5259)
if (!self.isPresent) {
[self.navigationController popViewControllerAnimated:YES];
}else {
[self dismissViewControllerAnimated:YES completion:nil];
}
}
}
#pragma mark - fong size select delgate
- (void)contentFontSizeHasChange {
[self.detailContentVC reloadTableWhenFontChange];
}
#pragma mark - remote handler
- (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)returnDetailPageInfo:(contDetailPageVO *)detailInfoBO {
self.detailContentBO = detailInfoBO;
[self changeDB:detailInfoBO];
}
- (void)returnCommentList:(NSMutableArray*)commentArray
nodeId:(NSString*)nodeId
nextUrl:(NSString*)nextUrl
commentTotalRecord:(NSInteger)recordTotal {
self.commentController.nodeId = nodeId;
self.commentController.commentList = commentArray;
self.commentController.commentNextUrl = nextUrl;
self.commentController.commentTotalRecord = recordTotal;
}
- (void)returnHotAskDic:(NSMutableDictionary *)qaDic
nodeId:(NSString *)nodeId
nextUrl:(NSString *)nextUrl
askTotalRecord:(NSInteger)recordTotal {
self.commentController.qaDic = qaDic;
self.commentController.askNextUrl = nextUrl;
self.commentController.askTotalRecord = recordTotal;
}
//操作数据库
-(void) changeDB:(contDetailPageVO *) dataModal{// 新闻详情页: 跟踪和收藏改变状态后,再次进入该页面时,状态没有改变(bug:3925)
if (self.currentDetaialDB) {
[[CoreDataManager shareInstance].managedObjectContext deleteObject:self.currentDetaialDB];
}
contentObjectBO *contentBO = setJsonDicToDataModel(dataModal.content, [contentObjectBO class]);
ContDetailPageDB *coreDataDB = nil;
coreDataDB = [NSEntityDescription insertNewObjectForEntityForName:@"ContDetailPageDB"
inManagedObjectContext:[CoreDataManager shareInstance].managedObjectContext];
coreDataDB = makeRemoteModelToCoreDataModel(dataModal, [contDetailPageVO class],coreDataDB);
coreDataDB.date = getLocalDate();
coreDataDB.contId = contentBO.contId;
[[CoreDataManager shareInstance] saveContext];
self.currentDetaialDB = coreDataDB;
}
- (void)remoteResponsFailed:(int)actionTag withMessage:(NSString *)message resultCode:(NSString *)code{
[self stopHud];
if ([code intValue] == 5) {
[self contentHaveOfflined];
[TPUserDefault instance].lastContentID = @"";
[TPUserDefault instance].lastContentOffset = CGPointZero;
}else {
if (actionTag == 1 && [message isEqualToString:@"请求超时,请稍后重试!"]) {
[self.detailContentVC networkTimeOut];
}else {
ShowTextMessage(message);
}
}
}
- (void)contentHaveOffline {
[self contentHaveOfflined];
}
- (void)remoteFail:(BOOL)isTimeOut {
[self stopHud];
//【需求】无网络处理优化(重新加载打底图)(bug:5953)
if (isTimeOut || ![Remote IsEableNetwork]) {
[self.detailContentVC networkTimeOut];
}
}
//视频:直播页和详情页播放视频,全屏播放视频,点击右上角的叉,会点到状态栏,导致底部页面弹回头部(bug:5748)
-(void)detailStatusBarHidden:(BOOL)isHidden{
hiddenStatusBar = isHidden;
if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) {
[self prefersStatusBarHidden];
[self setNeedsStatusBarAppearanceUpdate];
}else {
[[UIApplication sharedApplication] setStatusBarHidden:hiddenStatusBar withAnimation:UIStatusBarAnimationFade];
}
}
- (BOOL)prefersStatusBarHidden
{
return hiddenStatusBar;
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter]removeObserver:self];
self.commentController = nil;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)linkWithPush:(NSNotification*)noti {
[self.detailContentVC 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
|