|
//
// TPcontentWebController.m
// ThePaperHD
//
// Created by scar1900 on 15/3/11.
// Copyright (c) 2015年 scar1900. All rights reserved.
//
#import "TPcontentWebController.h"
#import "commentAndAskController.h"
#import "TPSelectButton.h"
#import "loginPopUpController.h"
#import "shareButton.h"
#import "TPShareContentControlelr.h"
#import "toolBarBtnView.h"
#import "TPWebContentViewModel.h"
#define COLLECTTAG 1002
#define CANCELCOLLECTTAG 1003
@interface TPcontentWebController ()<shareContentControllerDelegate,TPWebContentViewModelDelegate>
@property(nonatomic, strong)toolBarBtnView *commentButton;
@property(nonatomic, strong)TPSelectButton *collectButton;
@property(nonatomic, strong)toolBarBtnView *sharBtn;
@property(nonatomic, strong)contDetailPageVO *detailContentBO;
@property(nonatomic, strong)contentObjectBO *contentBO;
@property(nonatomic, strong)commentAndAskController *commentController;
@property(nonatomic, strong)UIView *maskView;
@property(nonatomic, strong)NSMutableArray *commentList;
@property(nonatomic, strong)NSMutableDictionary *qaDataDic;
@property(nonatomic, strong)TPShareContentControlelr *shareVC;
@property(nonatomic, assign)CGFloat naviHeight;
@property(nonatomic, assign)NSInteger actionFlag;
@property(nonatomic, strong)TPWebContentViewModel *webModel;
@end
@implementation TPcontentWebController
@synthesize contentId = _contentId;
@synthesize detailContentBO = _detailContentBO;
@synthesize commentList,qaDataDic,shareVC;
@synthesize naviHeight;
@synthesize actionFlag = _actionFlag;
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.naviHeight = 0;
[self startHud];
self.actionFlag = 3;
self.webModel = TPWebContentViewModel.new;
self.webModel.delegate = self;
self.webModel.nodeID = self.contentId;
[self.webModel remoteAction];
[self addChildViewController:self.commentController];
[self.view addSubview:self.commentController.view];
[self.commentController didMoveToParentViewController:self];
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(dismissCommentView:)];
tapGesture.delaysTouchesBegan = YES;
[self.maskView addGestureRecognizer:tapGesture];
[self.commentController hiddenHandler];
}
-(void)viewWillAppear:(BOOL)animated{//外链文章:进入评论,点击一个头像进入个人动态,上方不应再显示收藏和评论等内容(bug:5956)
[super viewWillAppear:animated];
[self.navigationController.navigationBar addSubview:self.naviBarView];
self.naviBarView.frame = CGRectMake(CGRectGetWidth(self.view.bounds)-690/2, 0, 690/2, 45);
if (isNotIOS8) {
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) {
self.naviBarView.frame = CGRectMake(1024-690/2, 0, 690/2, 45);
}else {
self.naviBarView.frame = CGRectMake(768-690/2, 0, 690/2, 45);
}
}
[self.naviBarView addSubview:self.commentButton];
[self.naviBarView addSubview:self.collectButton];
[self.naviBarView addSubview:self.sharBtn];
[self setContentFramWithOrirentation];
}
-(void)viewWillDisappear:(BOOL)animated{//外链文章:进入评论,点击一个头像进入个人动态,上方不应再显示收藏和评论等内容(bug:5956)
[super viewWillDisappear:animated];
[self.naviBarView removeFromSuperview];
}
- (void)setActionFlag:(NSInteger)flag {
_actionFlag = flag;
if (flag == 0) {
[self stopHud];
}
}
- (void)statusBarOrientationChange:(NSNotification *)notification{
self.naviBarView.frame = CGRectMake(CGRectGetWidth(self.view.bounds)-690/2, 0, 690/2, 45);
if (isNotIOS8) {
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) {
self.naviBarView.frame = CGRectMake(1024-690/2, 0, 690/2, 45);
}else {
self.naviBarView.frame = CGRectMake(768-690/2, 0, 690/2, 45);
}
}
[self setContentFramWithOrirentation];
}
- (void)setContentFramWithOrirentation {
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIInterfaceOrientationLandscapeRight
|| orientation ==UIInterfaceOrientationLandscapeLeft) {
self.view.frame = CGRectMake(0, 0, 1024, 768);
}else {
self.view.frame = CGRectMake(0, 0, 768, 1024);
}
self.activityView.frame = CGRectMake(CGRectGetWidth(self.webView.bounds)/2-10,CGRectGetHeight(self.webView.bounds)/2-10 , 20, 20);
self.activityView.center = self.webView.center;
if (self.maskView && self.maskView.alpha >0) {
self.commentController.view.frame = CGRectMake(CGRectGetWidth(self.view.bounds)-1214/2,
naviHeight,
1214/2,
CGRectGetHeight(self.view.bounds)-naviHeight);
}else {
self.commentController.view.frame = CGRectMake(CGRectGetWidth(self.view.bounds)-25,
naviHeight,
1214/2,
CGRectGetHeight(self.view.bounds)-naviHeight);
}
self.maskView.frame = self.view.bounds;
[self.shareVC.view removeFromSuperview];
self.sharBtn.toolBtn.selected = NO;
[self.shareVC dismissViewControllerAnimated:YES completion:^{
// [self.shareVC.view removeFromSuperview];
[self.shareVC removeFromParentViewController];
self.shareVC = nil;
}];
//【倒退】【适配性】ios7,分享:系统分享,闪退(bug:5674)
if (isNotIOS8) {
if ([shareUtil instance].popController
&&[shareUtil instance].popController.isPopoverVisible) {
[[shareUtil instance].popController dismissPopoverAnimated:YES];
}
}
}
- (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)setDetailContentBO:(contDetailPageVO *)detailBO {
if (detailBO) {
_detailContentBO = detailBO;
self.contentBO = setJsonDicToDataModel(detailBO.content, [contentObjectBO class]);
NSString *interactionStr = detailBO.content[@"interactionNum"]?detailBO.content[@"interactionNum"]:@"";
NSString *isFavorited = detailBO.content[@"isFavorited"]?detailBO.content[@"isFavorited"]:@"";
if (!isBlankString(interactionStr)) {
self.commentButton.titleText = interactionStr;
}
if (!isBlankString(isFavorited) && [isFavorited intValue] == 1 && [TPUserDefault instance].userBO) {
[self.collectButton setSelect:YES animation:NO];
}else {
[self.collectButton setSelect:NO animation:NO];
}
if (isBlankString(self.url)) {
self.url = self.contentBO.shareUrl;
}
[self.view bringSubviewToFront:self.commentController.view];
}
}
- (void)setContentId:(NSString *)contentId {
_contentId = contentId;
}
- (commentAndAskController*)commentController {
if (!_commentController) {
_commentController = [[commentAndAskController alloc]init];
}
return _commentController;
}
//- (void)remoteAction {
// NSDictionary *dic = @{@"c":self.contentId};
// [Remote doJsonAction:1
// requestUrl:contentDetailPageURL
// parameter:dic
// delegate:self];
//
// [Remote doJsonAction:2
// requestUrl:contentCommentURL
// parameter:dic
// delegate:self];
//
// [Remote doJsonAction:3
// requestUrl:contentAskURL
// parameter:dic
// delegate:self];
//}
#pragma mark - get views
- (TPSelectButton*)collectButton {
if (!_collectButton) {
_collectButton = [[TPSelectButton alloc]initWithFrame:CGRectMake(CGRectGetMaxX(self.safariButton.frame)+26,
0,
50,
CGRectGetHeight(self.naviBarView.bounds)-3)
target:self
selector:@selector(collectHandler:)];
[_collectButton setBUttonNormalImage:Image(@"Button/webCollect.png")
highLightImage:Image(@"Button/webCollect_s.png")
selectedImage:Image(@"Button/webCollect_s.png")];
_collectButton.textLabel.text = @"收藏";
_collectButton.textLabel.font = appFont(11, NO);
_collectButton.textLabel.textColor = [UIColor whiteColor];
}
return _collectButton;
}
- (toolBarBtnView*)commentButton {
if (!_commentButton) {
_commentButton = [[toolBarBtnView alloc]initWithFrame:CGRectMake(CGRectGetMaxX(self.collectButton.frame),
0,
50,
CGRectGetHeight(self.naviBarView.bounds)-3)
withTarget:self
selector:@selector(goToComment:)
buttonImage:@"Button/webInteraction.png"
hilightImage:@"Button/webInteraction_s.png"
selectImage:nil];
_commentButton.edgeInsets =UIEdgeInsetsMake(2,
50/2-55/4,
CGRectGetHeight(self.naviBarView.bounds)-56/2,
50/2-55/4);
_commentButton.titleLabel.textColor = [UIColor whiteColor];
}
return _commentButton;
}
- (toolBarBtnView*)sharBtn{
if (!_sharBtn) {
_sharBtn = [[toolBarBtnView alloc]initWithFrame:CGRectMake(CGRectGetMaxX(self.commentButton.frame),
0,
50,
CGRectGetHeight(self.naviBarView.bounds)-3)
withTarget:self
selector:@selector(shareHandler:)
buttonImage:@"Button/webShare.png"
hilightImage:@"Button/webShare_s.png"
selectImage:nil];
_sharBtn.edgeInsets =UIEdgeInsetsMake(0,
50/2-45/4,
CGRectGetHeight(self.naviBarView.bounds)-56/2,
50/2-45/4);
_sharBtn.titleText = @"分享";
_sharBtn.titleLabel.textColor = [UIColor whiteColor];
}
return _sharBtn;
}
#pragma mark - button event
- (void)goToComment:(UIButton*)btn {
[UIView animateWithDuration:0.25 animations:^{
[self.view addSubview:self.maskView];
[self.view insertSubview:self.maskView belowSubview:self.commentController.view];
self.maskView.alpha = 0.6f;
if (![Remote IsEableNetwork]) {//无网络:外链文章,关于互动列表有两个症状(bug:6093)
[self.view insertSubview:self.webView belowSubview:self.maskView];
}
} 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.nodeId = self.contentId;
[self.commentController hiddenHandler];
} completion:^(BOOL finished) {
}];
}];
}
- (void)collectHandler:(UIButton*)btn {
if (!btn.selected) {
if (![TPUserDefault instance].userBO) {
[self presentLoginModal:^{
} dismiss:^{
if ([TPUserDefault instance].userBO) {
[self.webModel collectContent];
}
}];
return;
}
[self.webModel collectContent];
}else {
if (![TPUserDefault instance].userBO) {
[self presentLoginModal:^{
} dismiss:^{
if ([TPUserDefault instance].userBO) {
[self.webModel cancelCollect];
}
}];
return;
}
[self.webModel cancelCollect];
}
}
- (void)shareHandler:(shareButton*)btn {
if (!btn.selected) {
//全景现场:点击评论列表后再点击分享,tab头部消失(bug:5820)
if (self.maskView.alpha != 0) {
[UIView animateWithDuration:0.35 animations:^{
self.maskView.alpha = 0;
self.commentController.view.frame = CGRectMake(CGRectGetWidth(self.view.bounds)-25,
naviHeight,
1214/2,
CGRectGetHeight(self.view.bounds)-naviHeight);
[self.commentController hiddenHandler];
} completion:^(BOOL finished) {
[self.maskView removeFromSuperview];
}];
}
if (self.shareVC) {
[self.shareVC removeFromParentViewController];
[self.shareVC.view removeFromSuperview];
self.shareVC = nil;
}
self.shareVC = [[TPShareContentControlelr alloc]init];
self.shareVC.hasImage = NO;
self.shareVC.direction = expandLeftBottom;
self.shareVC.sharestyle = shareNewsStyle;
self.shareVC.startPoint = CGPointMake(CGRectGetWidth(self.view.bounds)-60, 0); //初次进入shareContent起始纵轴错误 bug:3891
self.shareVC.view.frame = self.view.bounds;
self.shareVC.delegate = self;
self.shareVC.contentBO = self.contentBO;
[self addChildViewController:self.shareVC];
[self.view addSubview:self.shareVC.view];
self.sharBtn.toolBtn.selected = YES;
[self.view bringSubviewToFront:self.commentController.view];
}else {
[self.shareVC dismissShareContent:^{
[self dismissContent];
}];
}
}
- (void)dismissCommentView:(id)sender {
[UIView animateWithDuration:0.35 animations:^{
self.maskView.alpha = 0;
self.commentController.view.frame = CGRectMake(CGRectGetWidth(self.view.bounds)-25,
naviHeight,
1214/2,
CGRectGetHeight(self.view.bounds)-naviHeight);
[self.commentController hiddenHandler];
} completion:^(BOOL finished) {
[self.maskView removeFromSuperview];
}];
}
- (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)collectContent{
// [self startHud];
// NSDictionary *dic = @{@"cids":self.contentBO.contId};
// [Remote doJsonAction:COLLECTTAG
// requestUrl:addFavoriteURL
// parameter:dic
// delegate:self];
//}
//
//
//- (void)cancelCollect {
// [self startHud];
// NSDictionary *dic = @{@"cids":self.contentBO.contId};
// [Remote doJsonAction:CANCELCOLLECTTAG
// requestUrl:deleteFavoriteURL
// parameter:dic
// delegate:self];
//}
#pragma mark - sharecontent delegate
- (void)dismissContent {
[self.shareVC.view removeFromSuperview];
[self.shareVC removeFromParentViewController];
self.shareVC = nil;
self.sharBtn.toolBtn.selected = NO;
}
#pragma mark - remote handler
- (void)startHud {
if (!self.hud) {
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;
}
}
- (void)stopHud {
if (self.hud) {
[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;
}
- (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.askTotalRecord = recordTotal;
self.commentController.qaDic = qaDic;
self.commentController.askNextUrl = nextUrl;
}
- (void)collectResult:(BOOL)success {
if (success) {
[self.collectButton setSelect:YES animation:YES];
// [self.collectButton setSelected:YES];
}else {
[self.collectButton setSelect:NO animation:NO];
// [self.collectButton setSelected:NO];
}
}
- (void)contentHaveOffline {
[self contentHaveOfflined];
}
- (void)remoteFail:(BOOL)isTimeOut{
if (isTimeOut) {
[self networkTimeOut];
}
[self stopHud];
}
- (void)refreshPage {
NSDictionary *dic = @{@"c":self.contentId};
[Remote doJsonAction:1
requestUrl:contentDetailPageURL
parameter:dic
delegate:self];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#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
|