|
//
// topicCollectionListController.m
// ThePaperBase
//
// Created by Huixin on 15/10/12.
// Copyright © 2015年 scar1900. All rights reserved.
//
#import "topicCollectionListController.h"
#import "topicCollectionListCell.h"
#import "topicIntroductionCell.h"
@interface topicCollectionListController () {
NSMutableArray *heightList;
}
@end
@implementation topicCollectionListController
static NSString *topicCollectionCellID = @"topicCollectionCell";
static NSString *topicIntroductionCellID = @"topicIntroductionCell";
- (void)viewDidLoad {
[super viewDidLoad];
self.tableView.clipsToBounds = YES;
self.tableView.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
[self configCanRefresh:NO canLoad:YES];
[self needNoFirstAutoRefresh];
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
[self.tableView registerClass:[topicCollectionListCell class] forCellReuseIdentifier:topicCollectionCellID];
[self.tableView registerClass:[topicIntroductionCell class] forCellReuseIdentifier:topicIntroductionCellID];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(needrefreshNightMode) name:REFRESHAFTERNIGHTMODE object:nil];
// Do any additional setup after loading the view.
self.tableView.hidden = YES;
}
- (void)needrefreshNightMode {
self.tableView.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
}
#pragma mark - set method
-(void)setDataList:(NSMutableArray *)data{
self.tableView.hidden = NO;
_dataList = data;
heightList = [NSMutableArray array];
[data enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
if ([obj isKindOfClass:[NSString class]]) {
NSString *name = obj;
// CGFloat height = returnTextHeightWithRTLabel(name, rect_screen.size.width-20, appFont(TEXT_FIVE_LEVELSIZE, NO), 10) + 37;
CGFloat height = heightForAttributeStringWithLabel(getLineSpaceAttributedString(name, 10, appFont(TEXT_FIVE_LEVELSIZE, NO)), rect_screen.size.width-20, appFont(TEXT_FIVE_LEVELSIZE, NO)) + 37;
[heightList addObject:[NSString stringWithFormat:@"%f",height]];
}
else if ([obj isKindOfClass:[TopicInfoBO class]]) {
CGFloat scale = 0.75;
CGFloat height = (rect_screen.size.width-20)*scale+10;
[heightList addObject:[NSString stringWithFormat:@"%f",height]];
}
}];
[self.tableView reloadData];
}
- (void)pullLoadMoreHander {
if (isBlankString(self.nextUrl)) {
[self loadFailed];
return;
}
NSString *url = [self.nextUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[Remote doJsonAction:1
requestUrl:url
parameter:nil
delegate:self];
}
- (void)remoteResponsSuccess:(int)actionTag withResponsData:(id)responsData{
NSMutableArray *oldArray = [NSMutableArray arrayWithArray:self.dataList];
NSMutableArray *tempList = responsData[@"topicList"];
[tempList enumerateObjectsUsingBlock:^(NSDictionary *dic, NSUInteger idx, BOOL *stop) {
if (![dic[@"forwordType"] isEqualToString:@"4"]) {
TopicInfoBO *bo = setJsonDicToDataModel(dic, [TopicInfoBO class]);
bo.isFirstCard = @"0";
[oldArray addObject:bo];
}
}];
self.dataList = oldArray;
[self loadSuccess];
NSString *url = responsData[@"nextUrl"];
self.nextUrl = url;
}
#pragma mark - tableView 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 {
return [heightList[indexPath.row] floatValue];
}
- (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 0) {
return [self getIntroductionCell:table cellForRowAtIndexPath:indexPath];
}
else
return [self getContentCell:table cellForRowAtIndexPath:indexPath];
}
- (topicIntroductionCell *)getIntroductionCell:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
topicIntroductionCell *cell = [tableView dequeueReusableCellWithIdentifier:topicIntroductionCellID];
if (nil == cell) {
cell = [[topicIntroductionCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:topicIntroductionCellID];
cell.userInteractionEnabled = false;
}
cell.content = self.dataList[indexPath.row];
return cell;
}
- (topicCollectionListCell *)getContentCell:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
topicCollectionListCell *cell = [tableView dequeueReusableCellWithIdentifier:topicCollectionCellID];
if (nil == cell) {
cell = [[topicCollectionListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:topicCollectionCellID];
}
cell.indexPath = indexPath;
TopicInfoBO *topicInfo = self.dataList[indexPath.row];
cell.topic = topicInfo;
[cell reLayout];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:NO];
if ([[tableView cellForRowAtIndexPath:indexPath] isKindOfClass:[topicCollectionListCell class]]) {
topicCollectionListCell *cell = (topicCollectionListCell*)[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);
}
} completion:^(BOOL finished) {
if (isNotIOS8) {
cell.transform = CGAffineTransformMakeScale(1.00, 1.00);
}else {
cell.backView.transform = CGAffineTransformMakeScale(1.00, 1.00);
}
if ([self.delegate respondsToSelector:@selector(gotoInfo:)]) {
[self.delegate gotoInfo:self.dataList[indexPath.row]];
}
}];
}
}
- (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
|