// // topicHomeController.m // ThePaperDemo // // Created by zhousan on 15/7/15. // Copyright (c) 2015年 scar1900. All rights reserved. // #import "topicHomeController.h" #import "specialTopicTableController.h" #import "specialTopicViewModel.h" #import "shareContent.h" #import "imageShareContent.h" #define SHARECONTENTTAG 10086 @interface topicHomeController () @property (nonatomic, strong) specialTopicTableController *specialTopicVC; @property (nonatomic, strong) specialTopicViewModel *viewModel; @property (nonatomic, strong) NSMutableArray *nodeArray; @property (nonatomic, strong) specialObjectBO *specialBo; @property (nonatomic, strong) NSMutableArray *contentArray; @property (nonatomic, strong) UIButton *shareBtn; @end @implementation topicHomeController - (void)viewDidLoad { [super viewDidLoad]; [MobClick event:@"7"]; [self addChildViewController:self.specialTopicVC]; self.titleStr = @"专题"; self.viewModel = [[specialTopicViewModel alloc] init]; self.viewModel.delegate = self; self.nodeArray = [[NSMutableArray alloc] init]; self.contentArray = [[NSMutableArray alloc] init]; [self.view addSubview:self.specialTopicVC.view]; [self.specialTopicVC.view makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.view.left); make.top.equalTo(self.naviBar.bottom); make.right.equalTo(self.view.right); make.bottom.equalTo(self.view.bottom); }]; [self.naviBar addSubview:self.shareBtn]; [self.viewModel checkContentDataInCoreData:self.nodeID table:self.specialTopicVC.tableView]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(needrefreshNightMode:) name:REFRESHAFTERNIGHTMODE object:nil]; } - (void)needrefreshNightMode:(id)sender{ if ([[TPUserDefault instance].isNightMode intValue] == 0) { [_shareBtn setImage:Image(@"topic/shareBtn_spec.png") forState:UIControlStateNormal]; [_shareBtn setImage:Image(@"topic/shareBtn_spec_s.png") forState:UIControlStateHighlighted]; }else { [_shareBtn setImage:Image(@"topic/shareBtn_spec_night.png") forState:UIControlStateNormal]; [_shareBtn setImage:Image(@"topic/shareBtn_spec_night_s.png") forState:UIControlStateHighlighted]; } } - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; } #pragma mark - navTap - (void)tapNaviBar:(id)sender { [self.specialTopicVC.tableView setContentOffset:CGPointMake(0, -(85*rect_screen.size.width/320)) animated:YES]; } #pragma mark - getter - (specialTopicTableController *)specialTopicVC { if (!_specialTopicVC) { _specialTopicVC = [[specialTopicTableController alloc] init]; _specialTopicVC.delegate = self; } return _specialTopicVC; } - (UIButton *)shareBtn { if (!_shareBtn) { _shareBtn = [UIButton buttonWithType:UIButtonTypeCustom]; _shareBtn.frame = CGRectMake(rect_screen.size.width-40, CGRectGetHeight(self.naviBar.frame)-43, 40, 40); if ([[TPUserDefault instance].isNightMode intValue] == 0) { [_shareBtn setImage:Image(@"topic/shareBtn_spec.png") forState:UIControlStateNormal]; [_shareBtn setImage:Image(@"topic/shareBtn_spec_s.png") forState:UIControlStateHighlighted]; }else { [_shareBtn setImage:Image(@"topic/shareBtn_spec_night.png") forState:UIControlStateNormal]; [_shareBtn setImage:Image(@"topic/shareBtn_spec_night_s.png") forState:UIControlStateHighlighted]; } _shareBtn.imageEdgeInsets = UIEdgeInsetsMake(10, 10, 10, 10); [_shareBtn addTarget:self action:@selector(topicShare:) forControlEvents:UIControlEventTouchUpInside]; } return _shareBtn; } #pragma mark - setter - (void)setNodeID:(NSString *)nodeID { if (_nodeID != nodeID) { _nodeID = nodeID; } } - (void)topicShare:(UIButton *)btn { contentObjectBO *contentBO = contentObjectBO.new; // 【需求变更】澎湃专题分享的图片使用“澎湃专题”LOGO(bug:5454) // contentBO.sharePic = nil; contentBO.sharePic = self.specialBo.sharePic; contentBO.shareUrl = self.specialBo.shareUrl; contentBO.name = self.specialBo.name; contentBO.summary = self.specialBo.desc; if (!btn.selected) { shareContent *shareContentView = [[shareContent alloc]initWithFrame:self.view.bounds]; shareContentView.delegate = self; shareContentView.tag = SHARECONTENTTAG; shareContentView.contentBO = contentBO; shareContentView.sharestyle = shareSpecicalTopicStyle; 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; } #pragma mark - table delegate - (void)needRefreshPage { } - (void)refreshPage { [self.viewModel remoteAction]; } #pragma mark - specialTopicDelegate - (void)returnNodeList:(NSMutableArray*)nodeArray contentList:(NSMutableArray*)contentArray specialBO:(specialObjectBO*)specialData { self.nodeArray = nodeArray; self.specialTopicVC.dataList = nodeArray; self.specialBo = specialData; self.contentArray = contentArray; } - (void)contentHaveOffline { } //文章已下线 - (void)remoteFail:(BOOL)isTimeOut { if (isTimeOut) { [self networkTimeOut]; } } //网络出错 - (void)startHud { [self.view addSubview:self.waitBackView]; [self.view bringSubviewToFront:self.waitBackView]; self.waitCursor.animating = YES; } - (void)stopHud { [self.waitBackView removeFromSuperview]; self.waitBackView = nil; self.waitCursor.animating = NO; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } -(void)gotoShare:(UIImage *)img contentBO:(contentObjectBO *)contenBO{ imageShareContent *specialShareContentView = [[imageShareContent alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds))]; specialShareContentView.contentBO = contenBO; specialShareContentView.shareImg = img; specialShareContentView.baseController = self; specialShareContentView.sharestyle = shareNewsStyle; [specialShareContentView 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