|
//
// topicHomeController.m
// ThePaperHD
//
// Created by scar1900 on 15/2/13.
// Copyright (c) 2015年 scar1900. All rights reserved.
//
#import "topicHomeController.h"
#import "specialTopicTableController.h"
#import "shareButton.h"
#import "TPShareContentControlelr.h"
#import "hotAskListHomeController.h"
#import "otherPersonHomepageController.h"
#import "specialTopicViewModel.h"
@interface topicHomeController ()<shareContentControllerDelegate,topicTableDelegate,specialTopicDelegate>
@property(nonatomic, assign)CGFloat statusHeight;
@property(nonatomic, strong)UIButton *backButton;
@property(nonatomic, strong)NSMutableArray *nodeList;
@property(nonatomic, strong)specialObjectBO *specialBO;
@property(nonatomic, strong)NSMutableArray *contentList;
@property(nonatomic, strong)specialTopicTableController *topicTableController;
@property(nonatomic, strong)shareButton *sharBtn;
@property(nonatomic, strong)TPShareContentControlelr *shareVC;
@property(nonatomic, strong)SpecialObjectDB *currentSpecialDB;
@property(nonatomic, strong)specialTopicViewModel *specialModel;
@end
@implementation topicHomeController
@synthesize nodeID = _nodeID;
@synthesize statusHeight;
@synthesize nodeList = _nodeList,specialBO;
@synthesize contentList;
@synthesize currentSpecialDB;
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
if (isIOS7) {
self.statusHeight = 18;
}else {
self.statusHeight = 0;
}
[MobClick event:@"3"];
[self.view addSubview:self.backButton];
[self.view addSubview:self.sharBtn];
[self setContentFramWithOrirentation];
[self addChildViewController:self.topicTableController];
[self.view addSubview:self.topicTableController.view];
[self.topicTableController didMoveToParentViewController:self];
[self enablePopBackGesture];
//弱网络环境:进入一个专题,未加载内容前点击返回无效(bug:5955)
[self startHud];
self.specialModel = specialTopicViewModel.new;
self.specialModel.delegate = self;
self.specialModel.nodeId = self.nodeID;
[self.specialModel checkContentDataInCoreData:self.nodeID table:self.topicTableController.tableView];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willPopBack:) name:CONTENTDETAILPOPBACK object:nil];
}
-(void)gotoPersonInfo:(commentObjectVO *)comment{
[self dismissControllerAnimated:YES completion:^{
otherPersonHomepageController *otherVC = [otherPersonHomepageController new];
otherVC.commentBo = comment;
[self.navigationController pushViewController:otherVC animated:YES];
}];
}
- (void)willPopBack:(NSNotification*)notification {
[TPUserDefault instance].lastContentOffset = self.topicTableController.tableView.contentOffset;
[TPUserDefault instance].lastContentID = self.nodeID;
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.navigationController.navigationBarHidden = YES;
}
#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;
}
}
- (specialTopicTableController*)topicTableController {
if (!_topicTableController) {
_topicTableController = [[specialTopicTableController alloc]init];
_topicTableController.delegate = self;
}
return _topicTableController;
}
- (void)setNodeList:(NSMutableArray *)list {
_nodeList = list;
if (list.count > 0) {
self.topicTableController.dataList = list;
}
}
- (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;
}
- (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;
}
- (void)setNodeID:(NSString *)nodeIDStr {
_nodeID = nodeIDStr;
}
#pragma mark - orirentation method
- (void)statusBarOrientationChange:(NSNotification *)notification{
[self setContentFramWithOrirentation];
}
- (void)setContentFramWithOrirentation {
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIInterfaceOrientationLandscapeRight
|| orientation ==UIInterfaceOrientationLandscapeLeft) {
if (isJustIos7) {
CGRect rect = [UIScreen mainScreen].bounds;
self.view.frame = CGRectMake(0, 0, rect.size.height, rect.size.width);
}
if (isNotIOS7) {
CGRect rect = [UIScreen mainScreen].bounds;
self.view.frame = CGRectMake(0, 0, rect.size.height, rect.size.width);
}
}else {
CGRect rect = [UIScreen mainScreen].bounds;
self.view.frame = rect;
}
self.topicTableController.view.frame = CGRectMake(158/2,
self.statusHeight,
CGRectGetWidth(self.view.bounds)-158/2,
CGRectGetHeight(self.view.bounds)-self.statusHeight);
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.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];
}
}
if (self.contentList.count > 0) {
NSMutableArray *array = [NSMutableArray array];
[array addObject:self.specialBO];
[self.contentList enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
[array addObject:obj];
}];
self.nodeList = [NSMutableArray arrayWithArray:array];
}
}
#pragma mark - button handler
- (void)popBack:(UIButton*)btn {
if (!self.isPresent) {
[self.navigationController popViewControllerAnimated:YES];
}else {
[self dismissViewControllerAnimated:YES completion:nil];
}
}
- (void)shareHandler:(shareButton*)btn {
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 = shareSpecicalTopicStyle;
self.shareVC.startPoint = self.sharBtn.frame.origin;
if (isNotIOS7) {
self.shareVC.startPoint = CGPointMake(5, CGRectGetHeight(self.view.bounds)-87);
}
self.shareVC.hasImage = NO;
self.shareVC.view.bounds = self.view.bounds;
self.shareVC.delegate = self;
contentObjectBO *contentBO = contentObjectBO.new;
contentBO.sharePic = self.specialBO.sharePic;//【需求变更】澎湃专题分享的图片使用“澎湃专题”LOGO(bug:5455)
contentBO.shareUrl = self.specialBO.shareUrl;
contentBO.name = self.specialBO.name;
contentBO.summary= self.specialBO.desc;
self.shareVC.contentBO = contentBO;
[self addChildViewController:self.shareVC];
[self.view addSubview:self.shareVC.view];
self.sharBtn.enabled = NO;
[self.view bringSubviewToFront:self.sharBtn];
}
#pragma mark - sharecontent delegate
- (void)dismissContent {
[self.shareVC.view removeFromSuperview];
[self.shareVC removeFromParentViewController];
self.shareVC = nil;
self.sharBtn.enabled = YES;
}
#pragma mark - viewmodel delegate
-(void)returnNodeList:(NSMutableArray *)nodeArray contentList:(NSMutableArray *)contentArray specialBO:(specialObjectBO *)specialData{
self.nodeList = nodeArray;
self.specialBO = specialData;
self.contentList = contentArray;
[self stopHud];
}
- (void)needRefreshPage {
[self startHud];
[self.specialModel remoteAction];
}
- (void)contentHaveOffline {
[self contentHaveOfflined];
}
- (void)remoteFail:(BOOL)isTimeOut {
if (isTimeOut || ![Remote IsEableNetwork]) {
[self stopHud];
[self.topicTableController networkTimeOut];
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter]removeObserver:self name:CONTENTDETAILPOPBACK object:nil];
}
@end
|