// // topicContentController.m // ThePaperHD // // Created by scar1900 on 15/5/10. // Copyright (c) 2015年 scar1900. All rights reserved. // #import "topicContentController.h" #import "AsyncImageView.h" #import "topicContentTableController.h" //#import "otherPersonHomepageController.h" //#import "customFlowLayout.h" #import "topicListController.h" #import "TPSelectButton.h" //#import "shareButton.h" #import "shareContent.h" #import "loginHomeController.h" #import "writeCommentAndAskController.h" #import "topicContentTableController.h" #import "InterViewPageViewController.h" #import "imageShareContent.h" @interface topicContentController () { CGFloat topPadding; shareContent *shareContentView; } @property(nonatomic, strong)TopicInfoBO *topicInfo; @property(nonatomic, strong)topicContentTableController *tableVC; @property(nonatomic, strong)UIView *topicView; @property(nonatomic, strong)shareContent *shareView; @property(nonatomic, strong)writeCommentAndAskController *writeCommentContentVC; @property(nonatomic, strong)UIButton *askButton; @end @implementation topicContentController @synthesize preTopicInfo = _preTopicInfo; @synthesize creatUser; @synthesize isCreatPage; @synthesize shareView; @synthesize topicInfo = _topicInfo; @synthesize currentIndex; - (void)viewDidLoad { [super viewDidLoad]; self.titleStr = @"话题"; // Do any additional setup after loading the view. if (isIOS7) { topPadding = 64; }else topPadding = 44; NSString *forWardType = @""; if (self.creatUser.sname) { if ([TPUserDefault instance].userBO && [[TPUserDefault instance].userBO.userId intValue] == [self.creatUser.userId intValue]) { forWardType = @"6"; isCreatPage = YES; }else { forWardType = @"5"; isCreatPage = NO; } }else { if (isCreatPage) { forWardType = @"6"; }else { forWardType = @"5"; } } self.tableVC = [[topicContentTableController alloc]init]; self.tableVC.topicInfo = self.preTopicInfo; self.tableVC.userBo = self.creatUser; self.tableVC.isCreat = isCreatPage; self.tableVC.topicTableDelegate = self; self.tableVC.currentIndex = self.currentIndex; self.tableVC.view.frame = CGRectMake(0, self.barHeight, rect_screen.size.width, rect_screen.size.height-self.barHeight); [self addChildViewController:self.tableVC]; [self.view addSubview:self.tableVC.view]; [self.naviBar addSubview:self.askButton]; [self.askButton makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(self.naviBar); make.bottom.equalTo(self.naviBar); make.size.mas_equalTo(CGSizeMake(75, 40)); }]; [self.view bringSubviewToFront:self.naviBar]; if (self.preTopicInfo != nil) { NSDictionary *dic = @{@"topicId":self.preTopicInfo.topicId,@"forwordType":forWardType}; [Remote doJsonAction:0 requestUrl:topicInfoURL parameter:dic delegate:self]; } } - (UIButton *)askButton { if (!_askButton) { _askButton = [UIButton buttonWithType:UIButtonTypeCustom]; [_askButton setImage:Image(@"topic/topicAskIcon.png") forState:UIControlStateNormal]; [_askButton setTitle:@"问吧" forState:UIControlStateNormal]; [_askButton setTitleColor:[UIColor colorWithHexString:TextGray] forState:UIControlStateNormal]; _askButton.titleLabel.font = appFont(TEXT_SIX_LEVELSIZE, NO); _askButton.titleLabel.textAlignment = NSTextAlignmentCenter; [_askButton setTitleEdgeInsets:UIEdgeInsetsMake(14, 0, 15, 33)]; [_askButton setImageEdgeInsets:UIEdgeInsetsMake(10, 46, 10, 10)]; [_askButton addTarget:self action:@selector(askButtonClick:) forControlEvents:UIControlEventTouchUpInside]; } return _askButton; } - (void)askButtonClick:(UIButton *)btn { NSLog(@"askButtonClick:"); categoryBO *bo = [categoryBO new]; bo.category = self.topicInfo.category; InterViewPageViewController *interViewVC = [[InterViewPageViewController alloc] init]; interViewVC.cateBo = bo; [self.navigationController pushViewController:interViewVC animated:YES]; } - (void)setPreTopicInfo:(TopicInfoBO *)data { _preTopicInfo = data; } - (void)setTopicInfo:(TopicInfoBO *)data { _topicInfo = data; userBO *user = setJsonDicToDataModel(data.userInfo, [userBO class]); if (!self.creatUser) { self.creatUser = user; if ([[TPUserDefault instance].userBO.userId intValue] == [self.creatUser.userId intValue]) { isCreatPage = YES; }else { isCreatPage = NO; } }else { self.creatUser = user; if ([[TPUserDefault instance].userBO.userId intValue] == [self.creatUser.userId intValue]) { isCreatPage = YES; }else { isCreatPage = NO; } } } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; self.title = @"话题"; self.navigationController.navigationBarHidden = NO; if (isIOS7) { self.automaticallyAdjustsScrollViewInsets = NO; } self.navigationController.navigationBar.translucent = YES; NSString *barColor; for (int i = 0 ; i < [TPUserDefault instance].channldataList.count; i++) { if ([[TPUserDefault instance].channldataList[i][@"nodeId"] isEqualToString:@"-3"]) { barColor =[TPUserDefault instance].channldataList[i][@"color"]; } } if (isIOS7) { self.navigationController.navigationBar.barTintColor = [UIColor colorWithHexString:barColor]; }else { self.navigationController.navigationBar.tintColor = [UIColor colorWithHexString:barColor]; } // if (isIOS7) { // self.navigationController.navigationBar.barTintColor = [UIColor colorWithHexString:@"0xa89271"]; // }else { // self.navigationController.navigationBar.tintColor = [UIColor colorWithHexString:@"0xa89271"]; // } if (_topicView) { [self.topicView removeFromSuperview]; } [self.navigationController.navigationBar addSubview:self.topicView]; } - (void)viewWillLayoutSubviews { [super viewWillLayoutSubviews]; self.topicView.frame = CGRectMake(CGRectGetWidth(self.view.bounds)-70, 0, 70, CGRectGetHeight(self.navigationController.navigationBar.bounds)); } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; [self.topicView removeFromSuperview]; } #pragma mark - writeDelegatr - (void)dismissWriteContent:(commentAndAskType)type{ __weak typeof(self) Self = self; [self dismissViewController:self.writeCommentContentVC animated:YES completion:^{ ((MLNavigationController *)self.navigationController).canDragBack = YES; Self.writeCommentContentVC = nil; }]; } #pragma mark - handler - (void)backButtonHandler:(id)sender { [self.navigationController popViewControllerAnimated:YES]; } - (void)gotoAsk { [self writeComment:interactionAskType commentBO:nil]; } -(void)topicTableToAsk{ [self gotoAsk]; } - (void)answerByCreatInTopic:(commentObjectVO *)commentBO { [self writeComment:interactionCommentType commentBO:commentBO]; } - (void)writeComment:(commentAndAskType)type commentBO:(commentObjectVO*)commentBO{ __weak typeof(self) Self = self; if (![TPUserDefault instance].userBO) { loginHomeController *loginVC = [loginHomeController new]; [self.navigationController pushViewController:loginVC animated:YES]; }else { Self.writeCommentContentVC = [[writeCommentAndAskController alloc]init]; Self.writeCommentContentVC.type = type; Self.writeCommentContentVC.nodeId = Self.topicInfo.topicId; Self.writeCommentContentVC.delegate = self; Self.writeCommentContentVC.commentOT = @"3"; if (commentBO) { Self.writeCommentContentVC.commentBO = commentBO; } ((MLNavigationController *)self.navigationController).canDragBack = NO; [Self presentController:self.writeCommentContentVC animated:YES completion:^{ }]; } } - (void)gotoAnswerForAsk:(commentObjectVO *)comment { if (![TPUserDefault instance].userBO) { loginHomeController *loginVC = [loginHomeController new]; [self.navigationController pushViewController:loginVC animated:YES]; }else { self.writeCommentContentVC = [[writeCommentAndAskController alloc]init]; self.writeCommentContentVC.type = askForUserType; self.writeCommentContentVC.nodeId = self.topicInfo.topicId; self.writeCommentContentVC.delegate = self; self.writeCommentContentVC.commentBO = comment; self.writeCommentContentVC.isPush = YES; self.writeCommentContentVC.commentOT = @"3"; } ((MLNavigationController *)self.navigationController).canDragBack = NO; [self presentController:self.writeCommentContentVC animated:YES completion:^{ }]; } - (void)commentSuccess:(commentAndAskType)type { [self dismissWriteContent:type]; ((MLNavigationController *)self.navigationController).canDragBack = YES; if (type == interactionAskType) { // ShowTextMessageWithDelay(@"提问成功,如果题主回答了你的问题,就会在话题页中显示出来", 3); [self.tableVC refreshNumAfterAsk]; [self setAttentionAlert]; }else { // ShowTextMessage(@"回复成功"); [self.tableVC reloadAskCellAfterAsking]; } } #pragma mark - remote delegate - (void)remoteResponsSuccess:(int)actionTag withResponsData:(id)responsData { if (actionTag == 0) { self.topicInfo = setJsonDicToDataModel(responsData[@"topicInfo"], [TopicInfoBO class]); self.topicInfo.desc = responsData[@"topicInfo"][@"description"]; NSString *newNums = responsData[@"topicInfo"][@"newNums"]; if (newNums) { self.topicInfo.unNums = newNums; } userBO *user = setJsonDicToDataModel(self.topicInfo.userInfo, [userBO class]); if ([[TPUserDefault instance].userBO.userId intValue] == [user.userId intValue]) { self.tableVC.isCreat = YES; }else{ self.tableVC.isCreat = NO; } self.creatUser = user; self.tableVC.userBo = user; // self.praiseButton.titleText = self.topicInfo.praiseTimes; self.tableVC.topicInfo = self.topicInfo; self.tableVC.topicPageVO = setJsonDicToDataModel(responsData, [topicInfoPageVO class]); } } - (void)shareBtnHandler:(contentObjectBO *)contentBO WithButton:(UIButton *)btn { if (!btn.selected) { contentObjectBO *contentBO1 = contentObjectBO.new; // contentBO.sharePic = self.liveInfoBO.sharePic; // contentBO.shareUrl = self.liveInfoBO.shareUrl; // contentBO.name = self.liveInfoBO.name; // contentBO.summary = shareText; contentBO1.sharePic = @"other/topicLogo.png"; contentBO1.shareUrl = self.topicInfo.shareUrl; contentBO1.name = self.topicInfo.title; contentBO1.summary = self.topicInfo.desc; shareContentView = [[shareContent alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds)-50)]; shareContentView.delegate = self; shareContentView.contentBO = contentBO1; shareContentView.baseController = self; shareContentView.sharestyle = shareTopicStyle; [shareContentView presentShareContentInView:self.view sender:btn]; }else { if (shareContentView) { [shareContentView dismissShareContent]; } } } #pragma mark - sharecontent delegate - (void)didDismissShareContent:(UIView *)contentView { contentView = nil; } - (void)remoteResponsFailed:(int)actionTag withMessage:(NSString *)message resultCode:(NSString *)code { if ([code intValue] == 5) { [self topicHaveOfflined]; [TPUserDefault instance].lastContentID = @""; [TPUserDefault instance].lastContentOffset = CGPointZero; }else { if ([message isEqualToString:@"请求超时,请稍后重试!"]) { [self networkTimeOut]; /** * bug:5565(【倒退】在图集和话题详情页中显示网络不给力,点击重新加载页面没有返回箭头) */ }else { if ([message isEqualToString:@"网络连接中断,请检查网络设置!"]) { [self networkTimeOut]; } ShowTextMessage(message); } } } - (void)refreshPage { NSString *forWardType = @""; if (self.creatUser) { if ([[TPUserDefault instance].userBO.userId intValue] == [self.creatUser.userId intValue]) { forWardType = @"6"; isCreatPage = YES; }else { forWardType = @"5"; isCreatPage = NO; } // [self setUserInfo]; }else { if (isCreatPage) { forWardType = @"6"; }else { forWardType = @"5"; } } NSDictionary *dic = @{@"topicId":self.preTopicInfo.topicId,@"forwordType":forWardType}; [Remote doJsonAction:0 requestUrl:topicInfoURL parameter:dic delegate:self]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (void)tapNaviBar:(id)sender { [self.tableVC.tableView setContentOffset:CGPointMake(0, -240*rect_screen.size.width/320) animated:YES]; } -(void) setAttentionAlert{ if ([[TPUserDefault instance].isAttention intValue] == 0 && ![self.tableVC getAttentionStatus]) { // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"" message:@"对这个话题感兴趣? 关注话题,掌握话题最新动态" delegate:self cancelButtonTitle:@"关注" otherButtonTitles:@"暂不关注",nil]; [alert show]; [TPUserDefault instance].isAttention = @"1"; // }); /** * bug:5052(话题用户页,首次提问后,是否关注的提示和“提问成功……”提示有重叠) */ } } - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { if (buttonIndex == 0) { NSDictionary *dic = @{@"ot":@"1",@"commentId":self.topicInfo.topicId}; [Remote doJsonActionWithBlock:1 requestUrl:addAttentionURL parameter:dic withWaitCursor:YES completion:^(BOOL success, NSString *message, id responseData) { if (success) { ShowMessage(@"关注成功", YES); TopicInfoBO* topicData = self.topicInfo; topicData.isAttented = @"1"; [self.tableVC changeAttention]; }else { ShowTextMessage(message); } }]; } } -(void)gotoShare:(UIImage *)img contentBO:(contentObjectBO *)contentBO{ imageShareContent *topicShareView = [[imageShareContent alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds))]; topicShareView.contentBO = contentBO; topicShareView.shareImg = img; topicShareView.baseController = self; topicShareView.sharestyle = shareTopicStyle; [topicShareView 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