// // askDetailController.m // ThePaperDemo // // Created by scar1900 on 14/11/14. // Copyright (c) 2014年 scar1900. All rights reserved. // #import "askDetailController.h" #import "askDetailListController.h" #import "detailContentHomeController.h" #import "loginHomeController.h" #import "writeCommentAndAskController.h" #import "TPLiveHomeController.h" #import "ImageContentController.h" #import "TPcontentWebController.h" #import "topicHomeController.h" #import "imageShareContent.h" #define IMGTOPINSET 5 #define IMGLEFTRIGHTINSET CGRectGetWidth(self.bounds)/2-51/4 #define IMGBOTTOMINSET CGRectGetHeight(self.bounds)-5-51/2 @implementation inviteButton -(id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { self.backgroundColor = [UIColor clearColor]; [self setImage:Image(@"detailPage/inviteAnswer.png") forState:UIControlStateNormal]; [self addSubview:self.textLabel]; }return self; } - (UILabel*)textLabel { if (!_textLabel) { _textLabel = [[UILabel alloc]initWithFrame:CGRectZero]; _textLabel.textAlignment = NSTextAlignmentCenter; _textLabel.userInteractionEnabled = NO; _textLabel.backgroundColor = [UIColor clearColor]; _textLabel.textColor = [UIColor colorWithHexString:LIGHTGRAY]; _textLabel.text = @"邀请回答"; } _textLabel.font = appFont(11, NO); return _textLabel; } - (void)setHighlighted:(BOOL)highlighted { [super setHighlighted:highlighted]; if (highlighted) { self.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR]; // self.textLabel.textColor = [UIColor whiteColor]; }else { self.backgroundColor = [UIColor clearColor]; // self.textLabel.textColor = [UIColor colorWithHexString:LIGHTGRAY]; } } - (void)layoutSubviews { self.textLabel.frame = CGRectMake(0, CGRectGetHeight(self.bounds)-33/2, CGRectGetWidth(self.bounds), 21/2); [self setImageEdgeInsets:UIEdgeInsetsMake(IMGTOPINSET, IMGLEFTRIGHTINSET, IMGBOTTOMINSET, IMGLEFTRIGHTINSET)]; [super layoutSubviews]; } @end @implementation commentBarView @synthesize delegate = _delegate; - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self addSubview:self.topLine]; [self addSubview:self.commentLine]; [self addSubview:self.separateLine]; [self addSubview:self.commentImgView]; [self addSubview:self.textLabel]; [self addSubview:self.inviteBtn]; [self addSubview:self.commentBackBtn]; } return self; } - (void)setDelegate:(id)del { _delegate = del; if (del) { [self.inviteBtn addTarget:del action:@selector(inviteAnswerHandler:) forControlEvents:UIControlEventTouchUpInside]; [self.commentBackBtn addTarget:del action:@selector(clickToAsk:) forControlEvents:UIControlEventTouchUpInside]; } } - (UIButton*)commentBackBtn { if (!_commentBackBtn) { _commentBackBtn = [UIButton buttonWithType:UIButtonTypeCustom]; _commentBackBtn.backgroundColor = [UIColor clearColor]; } return _commentBackBtn; } - (UIView*)topLine { if (!_topLine) { _topLine = [[UIView alloc]initWithFrame:CGRectZero]; _topLine.backgroundColor = [UIColor colorWithHexString:LINECOLOR]; } return _topLine; } - (UIView*)commentLine { if (!_commentLine) { _commentLine = [[UIView alloc]initWithFrame:CGRectZero]; _commentLine.backgroundColor = [UIColor colorWithHexString:LINECOLOR]; } return _commentLine; } - (UIView*)separateLine { if (!_separateLine) { _separateLine = [[UIView alloc]initWithFrame:CGRectZero]; _separateLine.backgroundColor = [UIColor colorWithHexString:LINECOLOR]; } return _separateLine; } - (UIImageView*)commentImgView { if (!_commentImgView) { _commentImgView = [[UIImageView alloc]initWithFrame:CGRectZero]; _commentImgView.image = Image(@"detailPage/answerIcon.png"); } return _commentImgView; } - (UILabel*)textLabel { if (!_textLabel) { _textLabel = [[UILabel alloc]initWithFrame:CGRectZero]; _textLabel.textColor = [UIColor colorWithHexString:LINECOLOR]; _textLabel.textAlignment = NSTextAlignmentLeft; _textLabel.text = @"回复"; } _textLabel.font = appFont(TEXT_FOUR_LEVELSIZE, NO); return _textLabel; } - (inviteButton*)inviteBtn { if (!_inviteBtn) { _inviteBtn = [[inviteButton alloc]initWithFrame:CGRectZero]; } return _inviteBtn; } - (void)subLayoutSubviews { self.topLine.frame = CGRectMake(0, 0, CGRectGetWidth(self.bounds), 0.5); self.commentImgView.frame = CGRectMake(10, 8, 20, 20); self.separateLine.frame = CGRectMake(CGRectGetWidth(self.bounds)-146/2-0.5, 0, 0.5, CGRectGetHeight(self.bounds)); self.inviteBtn.frame = CGRectMake(CGRectGetMaxX(self.separateLine.frame), 0.5, CGRectGetWidth(self.bounds)-CGRectGetMaxX(self.separateLine.frame), CGRectGetHeight(self.bounds)-0.5); self.textLabel.frame = CGRectMake(CGRectGetMaxX(self.commentImgView.frame)+15/2, CGRectGetMinY(self.commentImgView.frame)+4, 30, 15); self.commentLine.frame = CGRectMake(CGRectGetMinX(self.commentImgView.frame), CGRectGetMaxY(self.commentImgView.frame)+6, 450/2, 1); self.commentBackBtn.frame = CGRectMake(0, 0.5, CGRectGetWidth(self.bounds)-CGRectGetWidth(self.inviteBtn.frame), CGRectGetHeight(self.bounds)-0.5); } - (void)relayouSubView { self.topLine.frame = CGRectMake(0, 0, CGRectGetWidth(self.bounds), 0.5); self.commentImgView.frame = CGRectMake(10, 8, 20, 20); self.textLabel.frame = CGRectMake(CGRectGetMaxX(self.commentImgView.frame)+15/2, CGRectGetMinY(self.commentImgView.frame)+4, 30, 15); self.commentLine.frame = CGRectMake(CGRectGetMinX(self.commentImgView.frame), CGRectGetMaxY(self.commentImgView.frame)+6, CGRectGetWidth(self.bounds)-20, 1); self.commentBackBtn.frame = CGRectMake(0, 0.5, CGRectGetWidth(self.bounds), CGRectGetHeight(self.bounds)-0.5); } @end @interface askDetailController () @property(nonatomic, strong)askDetailListController *detailListController; @property(nonatomic, strong)commentBarView *commentBar; @property(nonatomic, strong)objInfoBO *objInfo; @property(nonatomic, strong)writeCommentAndAskController *writeCommentContentVC; @end @implementation askDetailController @synthesize commentBO = _commentBO; @synthesize objInfo; - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.titleStr = @"进入原新闻"; self.view.backgroundColor = [UIColor whiteColor]; [self addChildViewController:self.detailListController]; [self.view addSubview:self.detailListController.view]; [self.view addSubview:self.commentBar]; self.detailListController.commmentId = self.commentBO.commentId; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(needrefreshNightMode:) name:REFRESHAFTERNIGHTMODE object:nil]; } - (void)needrefreshNightMode:(id)sender{ self.detailListController.tableView.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR]; self.commentBar.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; self.view.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR]; } - (askDetailListController*)detailListController { if (!_detailListController) { _detailListController = [[askDetailListController alloc]init]; _detailListController.delegate = self; _detailListController.view.frame = CGRectMake(0, self.barHeight, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds)-self.barHeight-CGRectGetHeight(self.commentBar.frame)); } return _detailListController; } - (commentBarView*)commentBar { if (!_commentBar) { _commentBar = [[commentBarView alloc]initWithFrame:CGRectMake(0, CGRectGetHeight(self.view.bounds)-50, CGRectGetWidth(self.view.bounds), 50)]; _commentBar.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; _commentBar.inviteBtn.hidden = YES; _commentBar.delegate = self; [_commentBar relayouSubView]; } return _commentBar; } - (void)setCommentBO:(commentObjectVO *)obj { _commentBO = obj; } - (void)refreshObjInfo:(objInfoBO*)infoBO { self.objInfo = infoBO; } - (void)tapNaviBar:(id)sender { pushContentWithObjInfo(self.navigationController, self.objInfo); } #pragma mark - comment bar delegate - (void)inviteAnswerHandler:(inviteButton*)btn { } - (void)clickToAsk:(UIButton*)btn { if ([TPUserDefault instance].userBO) { self.writeCommentContentVC = [[writeCommentAndAskController alloc]init]; self.writeCommentContentVC.type = aswerType; self.writeCommentContentVC.nodeId = self.commentBO.contId; self.writeCommentContentVC.delegate = self; self.writeCommentContentVC.commentBO = self.commentBO; [self presentController:self.writeCommentContentVC animated:YES completion:^{ }]; }else { loginHomeController *vc = loginHomeController.new; [self.navigationController pushViewController:vc animated:YES]; } } - (void)dismissWriteContent:(commentAndAskType)type{ __weak typeof(self) Self = self; [self dismissViewController:self.writeCommentContentVC animated:YES completion:^{ Self.writeCommentContentVC = nil; }]; } - (void)commentSuccess:(commentAndAskType)type { __weak typeof(self) Self = self; [self dismissViewController:self.writeCommentContentVC animated:YES completion:^{ [self.detailListController manualRefresh]; Self.writeCommentContentVC = nil; }]; } - (void)presentAskToUserContent:(commentObjectVO *)commentBO { self.writeCommentContentVC = [[writeCommentAndAskController alloc]init]; self.writeCommentContentVC.type = askForUserType; self.writeCommentContentVC.nodeId = self.commentBO.contId; self.writeCommentContentVC.delegate = self; self.writeCommentContentVC.commentBO = commentBO; [self presentController:self.writeCommentContentVC animated:YES completion:^{ }]; } - (void)gotoCommentFromHotAnwser:(commentObjectVO *)comment { if ([TPUserDefault instance].userBO) { [self presentAskToUserContent:comment]; }else { [self askPushToLoginView]; } } - (void)askPushToLoginView { loginHomeController *vc = [loginHomeController new]; [self.navigationController pushViewController:vc animated:YES]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } -(void)askListToShare:(UIImage *)img contentBO:(contentObjectBO *)contentBO{ imageShareContent *askListshareContentView = [[imageShareContent alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds))]; askListshareContentView.contentBO = contentBO; askListshareContentView.shareImg = img; askListshareContentView.baseController = self; askListshareContentView.sharestyle = shareNewsStyle; [askListshareContentView presentShareContentInView:self.view sender:nil]; } /* #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