|
//
// UITestSuperController.m
// ThePaperDemo
//
// Created by Scar on 14-9-15.
// Copyright (c) 2014年 scar1900. All rights reserved.
//
#import "channelContentListController.h"
#import "visualDataMethod.h"
#import "channelListCell.h"
#import "SCGIFImageView.h"
#import "MLNavigationController.h"
#import "channalMyPaperController.h"
#import "channelPromoteTitleCell.h"
#import "channelPromoteCell.h"
#import "channnelListHeadCell.h"
#import "channelSmallListCell.h"
#import "hotAskCardCell.h"
#import "hotTopicListCardCell.h"
#import "topicDeatilController.h"
#import "channelListBannerCell.h"
#import "topicContentController.h"
#import "askDetailController.h"
#import "Reachability.h"
#define TextGrayColor @"0xa6a6a6"
#define TextBlackColor @"0x4c4c4c"
#define channelListAdScale (float)338/600
@interface channelContentListController ()<bannerCellDelgate,channelListDelegate> {
void (^selectItemBlock)(id listOBJ);
BOOL _loadingMore;
NSTimer *gifTimer;
BOOL needManualRefresh; //需要接受通知刷新标志位
CGFloat titleTopPadding;
CGFloat titleLeftAndRightPadding;
CGFloat titleBottomPadding;
CGFloat cardPadding;
}
@end
@implementation channelContentListController
@synthesize isUseSystemFont;
@synthesize dataList = _dataList;
@synthesize cellHeightList;
@synthesize currentIndex;
@synthesize nodeId = _nodeId;
@synthesize dataKey = _dataKey;
@synthesize dataClass;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)setDataList:(NSMutableArray *)list {
if (!_dataList || _dataList.count == 0) {
self.tableView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
}
_dataList = list;
if ([[TPUserDefault instance].readModeStr intValue] == imageMode) {
[self setTableDataSource:list];
}else if ([[TPUserDefault instance].readModeStr intValue] == textMode) {
[self setTableDataSourceWithoutImage:list];
}else {
if ([Remote IsEnableWIFI]) {
[self setTableDataSource:list];
}else {
[self setTableDataSourceWithoutImage:list];
}
}
}
- (void)setTableDataSource:(NSMutableArray*)list{
self.cellHeightList = [NSMutableArray array];
self.titleHeightList = [NSMutableArray array];
self.hotInfoHeightList = [NSMutableArray array];
__block CGFloat imageHeight = 0;
[list enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
CGFloat cellHeight = 0;
if ([obj isKindOfClass:[NSString class]]) {
cellHeight = 40;
[self.titleHeightList addObject:@"0"];
[self.hotInfoHeightList addObject:@"0"];
}else if ([obj isKindOfClass:[listContObjectVO class]]){
listContObjectVO *listBO = obj;
if (!isBlankString(listBO.isChildList) && [listBO.isChildList intValue] == 1) {//推广childList
[self.titleHeightList addObject:@"0"];
[self.hotInfoHeightList addObject:@"0"];
cellHeight = 80;
}else {
if ([listBO.cardMode intValue] == HeadCardType) {
imageHeight = 185*rectScale();
CGFloat titleHeight = heightForAttributeStringWithLabel(getLineSpaceAttributedString(listBO.name?listBO.name:@"",//bug:5666
[iphoneLineSpaceAndParaSpace returnLevel7LineSpace],
appFont([iphoneLineSpaceAndParaSpace returnLevel7FontSize], NO)),
CGRectGetWidth(self.view.bounds)-20,
appFont([iphoneLineSpaceAndParaSpace returnLevel7FontSize], NO));
[self.titleHeightList addObject:[NSString stringWithFormat:@"%f",titleHeight]];
cellHeight = imageHeight + 10+ 25/2-3+titleHeight+25/2-3+10;
}else if ([listBO.cardMode intValue] == BigCardType) {
imageHeight = 125*rectScale();
CGFloat titleHeight = heightForAttributeStringWithLabel(getLineSpaceAttributedString(listBO.name?listBO.name:@"",
[iphoneLineSpaceAndParaSpace returnLevel5LineSpace],
appFont([iphoneLineSpaceAndParaSpace returnLevel5FontSize], NO)),
CGRectGetWidth(self.view.bounds)-40,
appFont([iphoneLineSpaceAndParaSpace returnLevel5FontSize], NO));
[self.titleHeightList addObject:[NSString stringWithFormat:@"%f",titleHeight]];
cellHeight = 10+imageHeight+10+25/2+titleHeight+25/2-3+10;
}else if ([listBO.cardMode intValue] == SmallCardType) {
CGFloat titleHeight = heightForAttributeStringWithLabel(getLineSpaceAttributedString(listBO.name?listBO.name:@"",
[iphoneLineSpaceAndParaSpace returnLevel5LineSpace],
appFont([iphoneLineSpaceAndParaSpace returnLevel5FontSize], NO)),
rect_screen.size.width-120,
appFont([iphoneLineSpaceAndParaSpace returnLevel5FontSize], NO));
[self.titleHeightList addObject:[NSString stringWithFormat:@"%f",titleHeight]];
cellHeight = 120-5;
/**
* bug:4988(首页列表界面中的推广卡片显示不对,且瀑布流中广告与新闻的间距过大)
*/
}else if ([listBO.cardMode intValue] == HotAskCardType) {
[self.titleHeightList addObject:@"0"];
cellHeight = 125*rectScale()+10;
}else if ([listBO.cardMode intValue] == AdCardType) {
[self.titleHeightList addObject:@"0"];
if ([listBO.isLoadAdSuccess intValue] == 1) {
cellHeight = (rect_screen.size.width-20)*channelListAdScale+10;
}else {
cellHeight = 0;
}
}
if (listBO.hotQaInfo.allKeys.count > 0) {
commentObjectVO *commentBO = setJsonDicToDataModel(listBO.hotQaInfo, [commentObjectVO class]);
NSAttributedString* hotInfoText = getLineSpaceAttributedString(commentBO.content?commentBO.content:@"",
[iphoneLineSpaceAndParaSpace returnLevel2Plus5LineSpace],
appFont([iphoneLineSpaceAndParaSpace returnLevel2Plus5FontSize], NO));
CGFloat hotHeight = 0;
if ([listBO.cardMode intValue] == HeadCardType) {
hotHeight = heightForAttributeStringWithLabel(hotInfoText,
CGRectGetWidth(self.view.bounds)-60,
appFont([iphoneLineSpaceAndParaSpace returnLevel2Plus5FontSize], NO));
}else {
hotHeight = heightForAttributeStringWithLabel(hotInfoText,
CGRectGetWidth(self.view.bounds)-80,
appFont([iphoneLineSpaceAndParaSpace returnLevel2Plus5FontSize], NO));
}
/**
* bug:5902(首页瀑布流:新闻卡片下方挂的【追问】【问吧】右侧间距过小,要扩大)
*/
[self.hotInfoHeightList addObject:[NSString stringWithFormat:@"%f",hotHeight]];
cellHeight = cellHeight + hotHeight+20;
}else if (listBO.hotTopic.allKeys.count > 0) {
TopicInfoBO *topicBO = setJsonDicToDataModel(listBO.hotTopic, [TopicInfoBO class]);
NSAttributedString* hotInfoText = getLineSpaceAttributedString(topicBO.title?topicBO.title:@"",
[iphoneLineSpaceAndParaSpace returnLevel2Plus5LineSpace],
appFont([iphoneLineSpaceAndParaSpace returnLevel2Plus5FontSize], NO));
CGFloat hotHeight = 0;
if ([listBO.cardMode intValue] == HeadCardType) {
hotHeight = heightForAttributeStringWithLabel(hotInfoText,
CGRectGetWidth(self.view.bounds)-60,
appFont([iphoneLineSpaceAndParaSpace returnLevel2Plus5FontSize], NO));
}else {
hotHeight = heightForAttributeStringWithLabel(hotInfoText,
CGRectGetWidth(self.view.bounds)-80,
appFont([iphoneLineSpaceAndParaSpace returnLevel2Plus5FontSize], NO));
}
/**
* bug:5902(首页瀑布流:新闻卡片下方挂的【追问】【问吧】右侧间距过小,要扩大)
*/
[self.hotInfoHeightList addObject:[NSString stringWithFormat:@"%f",hotHeight]];
cellHeight = cellHeight + hotHeight+20;
}else {
[self.hotInfoHeightList addObject:@"0"];
}
}
}else if ([obj isKindOfClass:[TopicInfoBO class]]) {
[self.titleHeightList addObject:@"0"];
[self.hotInfoHeightList addObject:@"0"];
cellHeight = 80;
}
[self.cellHeightList addObject:[NSString stringWithFormat:@"%f",cellHeight]];
}];
if (self.needReload) {
[self.tableView reloadData];
}
}
- (void)setTableDataSourceWithoutImage:(NSMutableArray*)list {
self.cellHeightList = [NSMutableArray array];
self.titleHeightList = [NSMutableArray array];
self.hotInfoHeightList = [NSMutableArray array];
__block CGFloat imageHeight = 0;
[list enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
CGFloat cellHeight = 0;
if ([obj isKindOfClass:[NSString class]]) {
cellHeight = 40;
[self.titleHeightList addObject:@"0"];
[self.hotInfoHeightList addObject:@"0"];
}else if ([obj isKindOfClass:[listContObjectVO class]]){
listContObjectVO *listBO = obj;
if (!isBlankString(listBO.isChildList) && [listBO.isChildList intValue] == 1) {//推广childList
[self.titleHeightList addObject:@"0"];
[self.hotInfoHeightList addObject:@"0"];
cellHeight = 80;
}else {
if ([listBO.cardMode intValue] == HeadCardType) {
imageHeight = 0;
CGFloat titleHeight = heightForAttributeStringWithLabel(getLineSpaceAttributedString(listBO.name?listBO.name:@"",
[iphoneLineSpaceAndParaSpace returnLevel5LineSpace],
appFont([iphoneLineSpaceAndParaSpace returnLevel5FontSize], NO)),
CGRectGetWidth(self.view.bounds)-40,
appFont([iphoneLineSpaceAndParaSpace returnLevel5FontSize], NO));
[self.titleHeightList addObject:[NSString stringWithFormat:@"%f",titleHeight]];
cellHeight = 10+imageHeight+10+25/2+titleHeight+25/2-3+10;
}else if ([listBO.cardMode intValue] == BigCardType) {
imageHeight = 0;
CGFloat titleHeight = heightForAttributeStringWithLabel(getLineSpaceAttributedString(listBO.name?listBO.name:@"",
[iphoneLineSpaceAndParaSpace returnLevel5LineSpace],
appFont([iphoneLineSpaceAndParaSpace returnLevel5FontSize], NO)),
CGRectGetWidth(self.view.bounds)-40,
appFont([iphoneLineSpaceAndParaSpace returnLevel5FontSize], NO));
[self.titleHeightList addObject:[NSString stringWithFormat:@"%f",titleHeight]];
cellHeight = 10+imageHeight+10+25/2+titleHeight+25/2-3+10;
}else if ([listBO.cardMode intValue] == SmallCardType) {
CGFloat titleHeight = heightForAttributeStringWithLabel(getLineSpaceAttributedString(listBO.name?listBO.name:@"",
[iphoneLineSpaceAndParaSpace returnLevel5LineSpace],
appFont([iphoneLineSpaceAndParaSpace returnLevel5FontSize], NO)),
rect_screen.size.width-120,
appFont([iphoneLineSpaceAndParaSpace returnLevel5FontSize], NO));
[self.titleHeightList addObject:[NSString stringWithFormat:@"%f",titleHeight]];
cellHeight = 120-75+titleHeight;
}else if ([listBO.cardMode intValue] == HotAskCardType) {
[self.titleHeightList addObject:@"0"];
cellHeight = 125*rectScale()+10;
}else if ([listBO.cardMode intValue] == AdCardType) {
[self.titleHeightList addObject:@"0"];
if ([listBO.isLoadAdSuccess intValue] == 1) {
cellHeight = (rect_screen.size.width-20)*channelListAdScale+10;
}else {
cellHeight = 0;
}
}
if (listBO.hotQaInfo.allKeys.count > 0) {
commentObjectVO *commentBO = setJsonDicToDataModel(listBO.hotQaInfo, [commentObjectVO class]);
NSAttributedString* hotInfoText = getLineSpaceAttributedString(commentBO.content?commentBO.content:@"",
[iphoneLineSpaceAndParaSpace returnLevel2Plus5LineSpace],
appFont([iphoneLineSpaceAndParaSpace returnLevel2Plus5FontSize], NO));
CGFloat hotHeight = heightForAttributeStringWithLabel(hotInfoText,
CGRectGetWidth(self.view.bounds)-60,
appFont([iphoneLineSpaceAndParaSpace returnLevel2Plus5FontSize], NO));
[self.hotInfoHeightList addObject:[NSString stringWithFormat:@"%f",hotHeight]];
cellHeight = cellHeight + hotHeight+20;
/**
* bug:5902(首页瀑布流:新闻卡片下方挂的【追问】【问吧】右侧间距过小,要扩大)
*/
}else if (listBO.hotTopic.allKeys.count > 0) {
TopicInfoBO *topicBO = setJsonDicToDataModel(listBO.hotTopic, [TopicInfoBO class]);
NSAttributedString* hotInfoText = getLineSpaceAttributedString(topicBO.title?topicBO.title:@"",
[iphoneLineSpaceAndParaSpace returnLevel2Plus5LineSpace],
appFont([iphoneLineSpaceAndParaSpace returnLevel2Plus5FontSize], NO));
CGFloat hotHeight = heightForAttributeStringWithLabel(hotInfoText,
CGRectGetWidth(self.view.bounds)-60,
appFont([iphoneLineSpaceAndParaSpace returnLevel2Plus5FontSize], NO));
[self.hotInfoHeightList addObject:[NSString stringWithFormat:@"%f",hotHeight]];
cellHeight = cellHeight + hotHeight+20;
/**
* bug:5902(首页瀑布流:新闻卡片下方挂的【追问】【问吧】右侧间距过小,要扩大)
*/
}else {
[self.hotInfoHeightList addObject:@"0"];
}
}
}else if ([obj isKindOfClass:[TopicInfoBO class]]) {
[self.titleHeightList addObject:@"0"];
[self.hotInfoHeightList addObject:@"0"];
cellHeight = 80;
}
[self.cellHeightList addObject:[NSString stringWithFormat:@"%f",cellHeight]];
}];
if (self.needReload) {
[self.tableView reloadData];
}}
//- (void)setLineSpace:(UILabel*)label text:(NSString*)text linceSpace:(NSInteger)lineSpace{
// NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:text];
// NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
//
// [paragraphStyle setLineSpacing:lineSpace];//调整行间距
// [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [text length])];
// label.attributedText = attributedString;
// [label sizeToFit];
//}
- (UIFont*)songFont:(CGFloat)size {
return [UIFont fontWithName:@"FZBIAOYSK--GBK1-0" size:size];
}
#pragma mark - load view
- (void)viewDidLoad
{
[super viewDidLoad];
if (IS_IPHONE_6P) {
titleTopPadding = 40/3.f;
titleLeftAndRightPadding = 40/3.f;
titleBottomPadding = 40/3.f;
cardPadding = 40/3.f;
}else {
titleTopPadding = 15;
titleLeftAndRightPadding = 10;
titleBottomPadding = 15;
cardPadding = 10;
}
self.needReload = YES;
self.isUseSystemFont = [TPUserDefault instance].isUseSystemFont;
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR];
self.dataList = [NSMutableArray array];
[self configCanRefresh:YES canLoad:YES];
needManualRefresh = NO;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(reachabilityChanged:)
name:kReachabilityChangedNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshFrontPage) name:NEEDREFRESHENTERFORGROUND object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(needrefreshNightMode:) name:REFRESHAFTERNIGHTMODE object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(needRefreshReadMode:) name:NEEDREFRESHCHANGEREADMODE object:nil];
}
- (void)setDataKey:(NSString *)key {
_dataKey = key;
if ([key isEqualToString:@"contList"]) {
self.dataClass = [listContObjectVO class];
}else self.dataClass = [commentObjectVO class];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
if ([self.isUseSystemFont intValue] != [[TPUserDefault instance].isUseSystemFont intValue]) {
self.isUseSystemFont = [TPUserDefault instance].isUseSystemFont;
[self reloadData];
}
}
- (void)setNodeId:(NSString *)nodeIdStr {
[self manualRefresh];
/**
* bug:6024(【需求】无缓存数据时,瀑布流自动刷新机制)
*/
_nodeId = nodeIdStr;
if (self.dataList.count == 0) {
if ([nodeIdStr isEqualToString:@"-1"] && ![TPUserDefault instance].userBO) {
return;
}
NSError *error;
if (![nodeIdStr isEqualToString:@"-2"]) { //普通文章列表
NSFetchRequest *request = [[NSFetchRequest alloc]init];
//为已创建好的实体利用检索到的上下文创建一个实体描述
NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"ListContPageDB"
inManagedObjectContext:[CoreDataManager shareInstance].managedObjectContext];
[request setEntity:entityDescription];
//确定持久库中是否存在与此字段相对应的托管对象,所以穿件一个谓词来确定字段的正确对象:
NSPredicate *pred = [NSPredicate predicateWithFormat:@"nodeId == %@",nodeIdStr];
[request setPredicate:pred];
ListContPageDB *listContPageDB = nil;
NSArray *objs = [[CoreDataManager shareInstance].managedObjectContext executeFetchRequest:request error:&error];
if (objs == nil) {
TPLOG(@"there was an error!!");
}
if (objs.count > 0) {
listContPageDB = [objs objectAtIndex:0];
NSDictionary *coreDataDic = makeCoreDataModelToDic(listContPageDB, [ListContPageDB class]);
[self getRefreshDataFromDic:coreDataDic sourceKey:self.dataKey contentClass:self.dataClass];
}
}else { //热追问
NSFetchRequest *request = [[NSFetchRequest alloc]init];
//为已创建好的实体利用检索到的上下文创建一个实体描述
NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"HotQaListPageDB"
inManagedObjectContext:[CoreDataManager shareInstance].managedObjectContext];
[request setEntity:entityDescription];
//确定持久库中是否存在与此字段相对应的托管对象,所以创建一个谓词来确定字段的正确对象:
NSPredicate *pred = [NSPredicate predicateWithFormat:@"nodeId == %@",nodeIdStr];
[request setPredicate:pred];
HotQaListPageDB *listContPageDB = nil;
NSArray *objs = [[CoreDataManager shareInstance].managedObjectContext executeFetchRequest:request error:&error];
if (objs == nil) {
TPLOG(@"there was an error!!");
}
if (objs.count > 0) {
listContPageDB = [objs objectAtIndex:0];
NSDictionary *coreDataDic = makeCoreDataModelToDic(listContPageDB, [HotQaListPageDB class]);
[self getRefreshDataFromDic:coreDataDic sourceKey:self.dataKey contentClass:self.dataClass];
}
}
}
}
- (void)saveRemoteDataToCoreData:(id)resData {
NSError *error;
NSFetchRequest *request = [[NSFetchRequest alloc]init];
//为已创建好的实体利用检索到的上下文创建一个实体描述
NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"ListContPageDB"
inManagedObjectContext:[CoreDataManager shareInstance].managedObjectContext];
[request setEntity:entityDescription];
//确定持久库中是否存在与此字段相对应的托管对象,所以穿件一个谓词来确定字段的正确对象:
NSPredicate *pred = [NSPredicate predicateWithFormat:@"nodeId == %@",self.nodeId];
[request setPredicate:pred];
ListContPageDB *listContPageDB = nil;
NSArray *objs = [[CoreDataManager shareInstance].managedObjectContext executeFetchRequest:request error:&error];
if (objs == nil) {
TPLOG(@"there was an error!!");
}
if (objs.count > 0) {
listContPageDB = [objs objectAtIndex:0];
[[CoreDataManager shareInstance].managedObjectContext deleteObject:listContPageDB];
}
ListContPageDB *listDB = nil;
listDB = [NSEntityDescription insertNewObjectForEntityForName:@"ListContPageDB"
inManagedObjectContext:[CoreDataManager shareInstance].managedObjectContext];
listDB = makeDicToCoreDataModel(resData, listDB);
listDB.date = getLocalDate();
listDB.nodeId = self.nodeId;
[[CoreDataManager shareInstance] saveContext];
}
- (void)saveQaListRemoteDataToCoreData:(id)resData {
// NSError *error;
// NSFetchRequest *request = [[NSFetchRequest alloc]init];
// //为已创建好的实体利用检索到的上下文创建一个实体描述
// NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"HotQaListPageDB"
// inManagedObjectContext:[CoreDataManager shareInstance].managedObjectContext];
// [request setEntity:entityDescription];
// //确定持久库中是否存在与此字段相对应的托管对象,所以穿件一个谓词来确定字段的正确对象:
// NSPredicate *pred = [NSPredicate predicateWithFormat:@"nodeId == %@",self.nodeId];
// [request setPredicate:pred];
//
// HotQaListPageDB *listContPageDB = nil;
// NSArray *objs = [[CoreDataManager shareInstance].managedObjectContext executeFetchRequest:request error:&error];
//
// if (objs == nil) {
// TPLOG(@"there was an error!!");
// }
//
// if (objs.count > 0) {
// listContPageDB = [objs objectAtIndex:0];
// [[CoreDataManager shareInstance].managedObjectContext deleteObject:listContPageDB];
// }
//
// HotQaListPageDB *listDB = nil;
// listDB = [NSEntityDescription insertNewObjectForEntityForName:@"HotQaListPageDB"
// inManagedObjectContext:[CoreDataManager shareInstance].managedObjectContext];
//
// listDB = makeDicToCoreDataModel(resData, listDB);
// listDB.date = getLocalDate();
//
// [[CoreDataManager shareInstance] saveContext];
}
#pragma mark - table view delegate and datasource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.dataList.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (self.cellHeightList.count>0) {
return [self.cellHeightList[indexPath.row] floatValue];
}else return 0;
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
id item = self.dataList[indexPath.row];
if ([item isKindOfClass:[listContObjectVO class]]) {
listContObjectVO* listBO = item;
if ([listBO.isChildList intValue] == 1) {//推广子卡片
return [self getChennelProMoteCell:tableView cellForRowAtIndexPath:indexPath];
}else {
if ([listBO.cardMode intValue] == HeadCardType) {//头条
if ([[TPUserDefault instance].readModeStr intValue] == imageMode) {
return [self getChennelListHeadCell:tableView cellForRowAtIndexPath:indexPath];
}else if ([[TPUserDefault instance].readModeStr intValue] == textMode) {
return [self getChennelListCell:tableView cellForRowAtIndexPath:indexPath];
}else {
if ([Remote IsEnableWIFI]) {
return [self getChennelListHeadCell:tableView cellForRowAtIndexPath:indexPath];
}else {
return [self getChennelListCell:tableView cellForRowAtIndexPath:indexPath];
}
}
}else if([listBO.cardMode intValue] == BigCardType){
return [self getChennelListCell:tableView cellForRowAtIndexPath:indexPath];
}else if([listBO.cardMode intValue] == SmallCardType){
return [self getChennelListSmallCell:tableView cellForRowAtIndexPath:indexPath];
}else if([listBO.cardMode intValue] == HotAskCardType){
return [self getHotAskCardCell:tableView cellForRowAtIndexPath:indexPath];
}else if([listBO.cardMode intValue] == AdCardType){
return [self getBannerCell:tableView cellForRowAtIndexPath:indexPath];
}else {
return nil;
}
}
}else if ([item isKindOfClass:[NSString class]]){//推广标题
return [self getChennelProMoteTitleCell:tableView cellForRowAtIndexPath:indexPath];
}else if ([item isKindOfClass:[TopicInfoBO class]]) {
return [self getHotTopicListCardCell:tableView cellForRowAtIndexPath:indexPath];
}else {
return nil;
}
}
- (channnelListHeadCell*)getChennelListHeadCell:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellId = @"myHeadCell";
channnelListHeadCell* cell = (channnelListHeadCell*)[tableView dequeueReusableCellWithIdentifier:cellId];
if (nil == cell) {
cell = [[channnelListHeadCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
cell.delegate = self;
/**
* bug:5016(首页,频道头条下挂的【追问】或【问吧】点击不了)
*/
}
cell.titleHeight = [self.titleHeightList[indexPath.row] floatValue];
cell.hotInfoHeight = [self.hotInfoHeightList[indexPath.row] floatValue];
cell.dataBO = self.dataList[indexPath.row];
return cell;
}
- (channelListCell*)getChennelListCell:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellId = @"myCell";
channelListCell* cell = (channelListCell*)[tableView dequeueReusableCellWithIdentifier:cellId];
if (nil == cell) {
cell = [[channelListCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
}
if (self.imagePath) {
cell.imagePath = self.imagePath;
}
cell.titleHeight = [self.titleHeightList[indexPath.row] floatValue];
cell.hotInfoHeight = [self.hotInfoHeightList[indexPath.row] floatValue];
cell.dataBO = self.dataList[indexPath.row];
cell.delegate = self;
return cell;
}
- (channelSmallListCell*)getChennelListSmallCell:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellId = @"mySmallCell";
channelSmallListCell* cell = (channelSmallListCell*)[tableView dequeueReusableCellWithIdentifier:cellId];
if (nil == cell) {
cell = [[channelSmallListCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
cell.delegate = self;
}
cell.titleHeight = [self.titleHeightList[indexPath.row] floatValue];
cell.hotInfoHeight = [self.hotInfoHeightList[indexPath.row] floatValue];
cell.dataBO = self.dataList[indexPath.row];
return cell;
}
- (channelPromoteCell*)getChennelProMoteCell:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellId = @"promoteCell";
channelPromoteCell* cell = (channelPromoteCell*)[tableView dequeueReusableCellWithIdentifier:cellId];
if (nil == cell) {
cell = [[channelPromoteCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
}
cell.listBO = self.dataList[indexPath.row];
return cell;
}
- (channelPromoteTitleCell*)getChennelProMoteTitleCell:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellId = @"promoteTitleCell";
channelPromoteTitleCell* cell = (channelPromoteTitleCell*)[tableView dequeueReusableCellWithIdentifier:cellId];
if (nil == cell) {
cell = [[channelPromoteTitleCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
}
cell.titleText = self.dataList[indexPath.row];
return cell;
}
- (hotAskCardCell*)getHotAskCardCell:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellId = @"hotAskCardCell";
hotAskCardCell* cell = (hotAskCardCell*)[tableView dequeueReusableCellWithIdentifier:cellId];
if (nil == cell) {
cell = [[hotAskCardCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
}
cell.listBO = self.dataList[indexPath.row];
return cell;
}
- (channelPromoteCell*)getHotTopicListCardCell:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellId = @"promoteCell";
channelPromoteCell* cell = (channelPromoteCell*)[tableView dequeueReusableCellWithIdentifier:cellId];
if (nil == cell) {
cell = [[channelPromoteCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
}
cell.topicBO = self.dataList[indexPath.row];
return cell;
}
- (channelListBannerCell*)getBannerCell:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellId = @"bannerCellID";
channelListBannerCell* cell = (channelListBannerCell*)[tableView dequeueReusableCellWithIdentifier:cellId];
if (nil == cell) {
cell = [[channelListBannerCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
cell.delegate = self;
}
listContObjectVO *listBO = self.dataList[indexPath.row];
cell.indexPath = indexPath;
cell.adUrl = listBO.adUrl;
CGFloat scale = (CGFloat)channelListAdScale;
/**
* bug:5204(首页瀑布流,广告图显示扁了)
*/
cell.imageScale = scale;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[self.tableView deselectRowAtIndexPath:indexPath animated:NO];
/**
* bug:5231(首页推荐条,回来不要点击效果,包括夜间模式)
*/
if ([[tableView cellForRowAtIndexPath:indexPath] isKindOfClass:[channelListCell class]]) {
channelListCell *cell = (channelListCell*)[tableView cellForRowAtIndexPath:indexPath];
[UIView animateWithDuration:0.15 animations:^{
if (isNotIOS8) {
cell.transform = CGAffineTransformMakeScale(0.97, 0.97);
}else {
cell.backView.transform = CGAffineTransformMakeScale(0.97, 0.97);
}
/**
* bug:5170(【适配性】ios7,4s,点击瀑布流上的卡片,效果错误)
*/
} completion:^(BOOL finished) {
if (isNotIOS8) {
cell.transform = CGAffineTransformMakeScale(1.00, 1.00);
}else {
cell.backView.transform = CGAffineTransformMakeScale(1.00, 1.00);
}
pushContentWithListContentObject(self.navigationController, self.dataList[indexPath.row]);
NSArray *array = [NSArray arrayWithObject:indexPath];
[self.tableView reloadRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationAutomatic];
}];
}else if ([[tableView cellForRowAtIndexPath:indexPath] isKindOfClass:[hotAskCardCell class]]) {
hotAskCardCell *cell = (hotAskCardCell*)[tableView cellForRowAtIndexPath:indexPath];
[UIView animateWithDuration:0.15 animations:^{
if (isNotIOS8) {
cell.transform = CGAffineTransformMakeScale(0.97, 0.97);
}else {
cell.cardImageView.transform = CGAffineTransformMakeScale(0.97, 0.97);
}
} completion:^(BOOL finished) {
if (isNotIOS8) {
cell.transform = CGAffineTransformMakeScale(1.00, 1.00);
}else {
cell.cardImageView.transform = CGAffineTransformMakeScale(1.00, 1.00);
}
pushContentWithListContentObject(self.navigationController, self.dataList[indexPath.row]);
NSArray *array = [NSArray arrayWithObject:indexPath];
[self.tableView reloadRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationAutomatic];
}];
}else if ([[tableView cellForRowAtIndexPath:indexPath] isKindOfClass:[channelPromoteCell class]]) {
id data = self.dataList[indexPath.row];
if ([data isKindOfClass:[listContObjectVO class]]) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
pushContentWithListContentObject(self.navigationController, self.dataList[indexPath.row]);
NSArray *array = [NSArray arrayWithObject:indexPath];
[self.tableView reloadRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationAutomatic];
});
}else {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
pushTopicPageWithTopicInfo(self.navigationController, self.dataList[indexPath.row]);
NSArray *array = [NSArray arrayWithObject:indexPath];
[self.tableView reloadRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationAutomatic];
});
}
}else if ([[tableView cellForRowAtIndexPath:indexPath] isKindOfClass:[hotTopicListCardCell class]]) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
pushTopicPageWithTopicInfo(self.navigationController, self.dataList[indexPath.row]);
NSArray *array = [NSArray arrayWithObject:indexPath];
[self.tableView reloadRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationAutomatic];
});
}
}
- (void)selectItemBlock:(void (^)(id ))block {
selectItemBlock = [block copy];
}
- (void)reloadWithFontChange {
self.needReload = YES;
self.dataList = [NSMutableArray arrayWithArray:self.dataList];
}
- (void)reloadData {
[self.tableView reloadData];
}
//页面切换
- (void)pageChangeBegin:(NSInteger)index {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
self.currentIndex = [NSString stringWithFormat:@"%ld",(long)index];
if (self.dataList.count == 0) {
NSDictionary *channelDic = [TPUserDefault instance].channldataList[[self.currentIndex intValue]];
self.nodeId = channelDic[@"nodeId"];
}
[self firstAutoRefreshHandler];
if (needManualRefresh) {//切换到页面检查是否需要刷新
[self manualRefresh];
needManualRefresh = NO;
}
});
// if (![TPUserDefault instance].pushBO || [[TPUserDefault instance].pushBO.linkType intValue] == linkToFrontPage
// || [[TPUserDefault instance].pushBO.isComeFromRemote intValue] == 0) {
// [self firstAutoRefreshHandler];
// }else {
// [self needNoFirstAutoRefresh];
// }
}
- (void)remoteAction {
}
- (void)getRefreshDataFromDic:(NSDictionary*)sourceDic sourceKey:(NSString*)sourceKey contentClass:(Class)contentClass{
NSArray *contList = sourceDic[sourceKey];
if (contList && contList.count > 0) {
NSMutableArray *tempArray = [NSMutableArray array];
[contList enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
id contentBO = setJsonDicToDataModel(obj, contentClass);
if ([contentBO isKindOfClass:[listContObjectVO class]]) {
listContObjectVO *list = contentBO;
if ([list.cardMode intValue] != ChildListCardType) {
if ([list.cardMode intValue] == HeadCardType
|| [list.cardMode intValue] == BigCardType
|| [list.cardMode intValue] == SmallCardType
|| [list.cardMode intValue] == HotAskCardType
|| [list.cardMode intValue] == AdCardType){
// if ([list.cardMode intValue] == AdCardType) {
// list.adUrl = @"http://ad.thepaper.cn/s?z=paper&c=1104&op=1";
// }
if ([[TPUserDefault instance].readModeStr intValue] == imageMode) {
[tempArray addObject:list];
}else if ([[TPUserDefault instance].readModeStr intValue] == textMode) {
if ([list.forwordType intValue] != imageNewsForwardType) {
[tempArray addObject:list];
}
}else {
if ([Remote IsEnableWIFI]) {
[tempArray addObject:list];
}else {
if ([list.forwordType intValue] != imageNewsForwardType) {
[tempArray addObject:list];
}
}
}
}else if ([list.cardMode intValue] == HotTopicListType){
[tempArray addObject:list.title?list.title:@""];
[list.childList enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
TopicInfoBO *topicInfoBO = setJsonDicToDataModel(obj, [TopicInfoBO class]);
[tempArray addObject:topicInfoBO];
}];
}
}else if ([list.cardMode intValue] == ChildListCardType){
[tempArray addObject:list.title?list.title:@""];
[list.childList enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
listContObjectVO *childListBO = setJsonDicToDataModel(obj, [listContObjectVO class]);
childListBO.isChildList = @"1";
if ([[TPUserDefault instance].readModeStr intValue] == imageMode) {
[tempArray addObject:childListBO];
}else if ([[TPUserDefault instance].readModeStr intValue] == textMode) {
if (![list.forwordType intValue] == imageNewsForwardType) {
[tempArray addObject:childListBO];
}
}else {
if ([Remote IsEnableWIFI]) {
[tempArray addObject:childListBO];
}else {
if (![list.forwordType intValue] == imageNewsForwardType) {
[tempArray addObject:childListBO];
}
}
}
}];
}
}else {
[tempArray addObject:contentBO];
}
}];
self.needReload = YES;
self.dataList = tempArray;
NSString *url = sourceDic[@"nextUrl"];
self.nextUrl = url;
}else {
self.needReload = YES;
self.dataList = [NSMutableArray array];
TPLOG(@"文章列表为空");
}
}
- (void)getContentOffset:(CGPoint)contentOffset {
// if (contentOffset.y > 0) {
// CGFloat offset = self.contentInsetTop;
//
// CGRect rect = headRect;
// rect.origin.y = rect.origin.y -offset;
// self.columnHeader.frame = rect;
// return;
// }
//
// if (contentOffset.y < 0-self.contentInsetTop) {
// self.columnHeader.frame = headRect;
//
// return;
// }
// // NSLog(@"contentOffsetY:%f",contentOffset.y);
//
// CGFloat offset = self.contentInsetTop + contentOffset.y;
//
// CGRect rect = headRect;
// rect.origin.y = rect.origin.y -offset;
// self.columnHeader.frame = rect;
}
#pragma mark - TPTableView delegate
- (void)pullRefreshHandler {
[self remoteAction];
}
- (void)pullLoadMoreHander {
}
- (void)scrollTableViewToTop {
[self.tableView setContentOffset:CGPointZero animated:YES];
}
//进入后台后回到前台的间隔时间大于一小时
- (void)refreshFrontPage {
needManualRefresh = YES;
if (self.currentIndex && [self.currentIndex intValue] == [TPUserDefault instance].currentPageIndex) {
needManualRefresh = NO;
[self manualRefresh];
}
}
//- (void)willPopBack{
// if (!self.currentIndex || [self.currentIndex intValue] != [TPUserDefault instance].currentPageIndex) {
// return;
// }
// if ([TPUserDefault instance].pushBO && [[TPUserDefault instance].pushBO.isHavePushed intValue] == 1) {
// needManualRefresh = YES;
// [TPUserDefault instance].pushBO = nil;
// needManualRefresh = NO;
// [self manualRefresh];
// }
//}
#pragma mark - banner delegate
- (void)loadAdSuccess:(NSIndexPath *)indexPath isHeadCell:(BOOL)isHeadCell {
listContObjectVO *listBO = self.dataList[indexPath.row];
if ([listBO.isLoadAdSuccess intValue] == 1) {
return;
}
listBO.isLoadAdSuccess = @"1";
[self.dataList replaceObjectAtIndex:indexPath.row withObject:listBO];
CGFloat cellHeight = (rect_screen.size.width-20)*channelListAdScale+10;
[cellHeightList replaceObjectAtIndex:indexPath.row withObject:[NSString stringWithFormat:@"%f",cellHeight]];
[self.tableView beginUpdates];
[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
[self.tableView endUpdates];
}
- (void)loadAdFailed:(NSIndexPath *)indexPath isHeadCell:(BOOL)isHeadCell {
}
- (void)clickAdd:(remotePushBO *)pushBO indexPath:(NSIndexPath *)indexPath{
bannerCell *cell = (bannerCell*)[self.tableView cellForRowAtIndexPath:indexPath];
[UIView animateWithDuration:0.15 animations:^{
if (isNotIOS8) {
cell.transform = CGAffineTransformMakeScale(0.97, 0.97);
}else {
cell.bannerView.transform = CGAffineTransformMakeScale(0.97, 0.97);
}
} completion:^(BOOL finished) {
if (isNotIOS8) {
cell.transform = CGAffineTransformMakeScale(1.00, 1.00);
}else {
cell.bannerView.transform = CGAffineTransformMakeScale(1.00, 1.00);
}
[TPUserDefault instance].pushBO = pushBO;
}];
}
#pragma mark - cell delegate
- (void)channelGotoHotTopic:(TopicInfoBO *)topicInfoBO {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
pushTopicPageWithTopicInfo(self.navigationController, topicInfoBO);
});
}
- (void)channelGotoHotAsk:(commentObjectVO *)commentBO {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
if([commentBO.objectType isEqualToString:@"3"]){//【需求】问答详情页(bug:3921)
//话题
topicDeatilController *topic = [[topicDeatilController alloc] init];
topic.commentBO = commentBO;
[self.navigationController pushViewController:topic animated:YES];
}else{
//新闻
askDetailController *askDetailVC = [[askDetailController alloc] init];
askDetailVC.commentBO = commentBO;
[self.navigationController pushViewController:askDetailVC animated:YES];
}
});
}
- (void)needrefreshNightMode:(id)sender{
self.view.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR];
}
- (void)needRefreshReadMode:(id)sender {
self.needReload = YES;
self.dataList = [NSMutableArray arrayWithArray:self.dataList];
}
- (void) reachabilityChanged:(NSNotification *)note
{
self.needReload = YES;
self.dataList = [NSMutableArray arrayWithArray:self.dataList];
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver: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
|