|
//
// topicListController.m
// ThePaperHD
//
// Created by scar1900 on 15/4/23.
// Copyright (c) 2015年 scar1900. All rights reserved.
//
#import "topicListController.h"
#import "customFlowLayout.h"
#import "topicListCell.h"
#import "topicFilterControlelr.h"
#import "topicContentController.h"
#import "gambitCenterHomeController.h"
#import "loginPopUpController.h"
#import "creatTopicController.h"
#import "topicSearchController.h"
#import "channalView.h"
#import "topicListTopView.h"
#import "topicListViewModel.h"
#import "topciCoverView.h"
#import "iCarousel.h"
#import "topicBannersController.h"
#import "MLNavigationController.h"
#define PADDING 35
@interface topicListController ()<topicFilterDelegate,myGambitCenterHomeDelegate,topicSearchDelegate,topicListViewDelegate,iCarouselDataSource,iCarouselDelegate,topciCoverViewDelegate> {
UIInterfaceOrientation lastOrientation;
NSInteger remoteCount;
NSString *catagory;
NSString* isHot;
BOOL firstInto;
NSInteger *bennerIndex;
}
@property(nonatomic, strong)topicFilterControlelr *filterController;
@property(nonatomic, strong)UIView *topicView;
@property(nonatomic, strong)gambitCenterHomeController *gambitVC;
@property(nonatomic, strong)topicSearchController *topicSearchVC;
@property(nonatomic, strong)channalView *titleView;
@property(nonatomic, strong)iCarousel *coverFlow;
@property(nonatomic, strong)UIButton *bannerLeft;
@property(nonatomic, strong)UIButton *bannerRight;
@property(nonatomic, strong)topicListTopView *topicListTopView;
@property(nonatomic, strong)topicListViewModel *listViewModel;
@property(nonatomic, strong)UIScrollView *topScroll;
@end
@implementation topicListController
@synthesize dataList = _dataList;
@synthesize cateList;
@synthesize filterController;
@synthesize catagoryInfo;
@synthesize sort = _sort;
@synthesize coverFlow = _coverFlow;
@synthesize bannerList = _bannerList;
@synthesize orientation = _orientation;
static NSString * const topicListCellIdentifer = @"topicListCellIdentifer";
static NSString *headViewCellID = @"topciCoverView";
- (void)viewDidLoad {
[super viewDidLoad];
isHot = @"1";
self.listViewModel = topicListViewModel.new;
self.listViewModel.delegate = self;
remoteCount = 0;
bennerIndex = 0;
firstInto = YES;
[self.collectionView registerClass:[topicListCell class] forCellWithReuseIdentifier:topicListCellIdentifer];
//添加头部
[self.collectionView registerClass:[topciCoverView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:headViewCellID];
self.collectionView.alwaysBounceVertical = YES;
[self configCanRefresh:YES canLoad:YES];
[self enablePopBackGesture];
}
- (void)setDataList:(NSMutableArray *)list {
_dataList = list;
[self.collectionView reloadData];
if (remoteCount == 2 && _dataList.count > 0) {
[self loadMoreMethod];
}
}
-(void)setBannerList:(NSMutableArray *)list{
_bannerList = list;
if (list.count >0) {
self.topScroll.hidden = NO;
CGFloat scale = (CGFloat)341/143;
[_bannerList enumerateObjectsUsingBlock:^(listContObjectVO *bo, NSUInteger idx, BOOL *stop) {
topciCoverView *view = [topciCoverView new];
view.frame = CGRectMake(idx*153*scale, 0, 153*scale, 153);
view.listBo = bo;
view.delegate = self;
[self.topScroll addSubview:view];
}];
self.topScroll.contentSize = CGSizeMake(153*scale*_bannerList.count+1, 296/2);
bennerIndex = 0;
}else{
self.topScroll.hidden = YES;
}
// [self.collectionView reloadData];
// self.coverFlow.currentItemIndex = 0;
// [self.coverFlow reloadData];
}
-(void)setOrientation:(UIInterfaceOrientation)ori{
_orientation = ori;
[self.coverFlow reloadData];
}
-(void)setSort:(NSString *)index{
_sort = index;
}
- (void)remoteMethod {
remoteCount = remoteCount + 1;
if (self.catagoryInfo) {
catagory = self.catagoryInfo.category;
}else {
catagory = @"";
}
if (!self.sort) {
self.sort = @"2";
}
NSDictionary *dic = @{@"sort":self.sort,@"category":catagory};
self.listViewModel.firstDict = dic;
}
- (void)backButtonHandler:(id)sender {
if (!self.isPresent) {
[self.navigationController popViewControllerAnimated:YES];
}else {
[self dismissViewControllerAnimated:YES completion:nil];
}
}
- (void)viewWillLayoutSubviews {
[super viewWillLayoutSubviews];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self.topicView removeFromSuperview];
}
//- (UIEdgeInsets)HorizontalInsets {
// UIEdgeInsets top = {PADDING+64,PADDING,PADDING,PADDING};
// if (isNotIOS7) {
// UIEdgeInsets top_ios6 = {PADDING+44,PADDING,PADDING,PADDING};
// return top_ios6;
// }
// return top;
//}
//
//- (UIEdgeInsets)VercalInsets {
// UIEdgeInsets top = {PADDING+64,PADDING,PADDING,PADDING};
// if (isNotIOS7) {
// UIEdgeInsets top_ios6 = {PADDING+44,PADDING,PADDING,PADDING};
// return top_ios6;
// }
// return top;
//}
- (UIEdgeInsets)HorizontalInsets {
UIEdgeInsets top = {PADDING,PADDING,PADDING,PADDING};
return top;
}
- (UIEdgeInsets)VercalInsets {
UIEdgeInsets top = {PADDING,PADDING,PADDING,PADDING};
return top;
}
//
//- (iCarousel*)coverFlow {
// if (!_coverFlow) {
// _coverFlow = [[iCarousel alloc]initWithFrame:CGRectZero];
// _coverFlow.type = iCarouselTypeLinear;
// _coverFlow.delegate = self;
// _coverFlow.dataSource = self;
// _coverFlow.clipsToBounds = YES;
// _coverFlow.backgroundColor = [UIColor clearColor];
// }
// return _coverFlow;
//}
-(UIScrollView *)topScroll{
if (!_topScroll) {
_topScroll = [[UIScrollView alloc] initWithFrame:CGRectZero];
_topScroll.alwaysBounceHorizontal = YES;
_topScroll.directionalLockEnabled = YES;
_topScroll.scrollEnabled = YES;
_topScroll.pagingEnabled = YES;
_topScroll.showsVerticalScrollIndicator = NO;
_topScroll.showsHorizontalScrollIndicator = NO;
_topScroll.autoresizingMask = AutoresizingFull;
_topScroll.backgroundColor = [UIColor clearColor];
_topScroll.delegate = self;
}
return _topScroll;
}
-(UIButton *)bannerLeft{
if (!_bannerLeft) {
_bannerLeft = [UIButton buttonWithType:UIButtonTypeCustom];
[_bannerLeft setBackgroundImage:Image(@"topic/topicBannerLeft.png") forState:UIControlStateNormal];
}
return _bannerLeft;
}
-(UIButton *)bannerRight{
if (!_bannerRight) {
_bannerRight = [UIButton buttonWithType:UIButtonTypeCustom];
[_bannerRight setBackgroundImage:Image(@"topic/topicBannerRight.png") forState:UIControlStateNormal];
}
return _bannerRight;
}
#pragma mark - collection delegate and datasource
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
if (self.dataList) {
return self.dataList.count;
}else return 0;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
topicListCell *cell = (topicListCell*)[collectionView dequeueReusableCellWithReuseIdentifier:topicListCellIdentifer forIndexPath:indexPath];
TopicInfoBO *topic = self.dataList[indexPath.row];
cell.topicBO = topic;
return cell;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
CGFloat width = 0;
if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {
width = (768-35*3)/2;
CGFloat viewScale = width/600;
return CGSizeMake(width, 450*viewScale);
}else {
width = (1024-35*4)/3;
CGFloat viewScale = width/600;
return CGSizeMake(width, 450*viewScale);
}
}
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {
return [self VercalInsets];
}else {
return [self HorizontalInsets];
}
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
[[UIApplication sharedApplication] beginIgnoringInteractionEvents];
if (ISNotRETINA) {
topicContentController *vc = [[topicContentController alloc]init];
TopicInfoBO *topic = self.dataList[indexPath.row];
vc.preTopicInfo = topic;
userBO *user = setJsonDicToDataModel(topic.userInfo, [userBO class]);
vc.creatUser = user;
[self.navigationController pushViewController:vc animated:YES];
[[UIApplication sharedApplication] endIgnoringInteractionEvents];
}else {
topicListCell *cell = (topicListCell*)[collectionView cellForItemAtIndexPath:indexPath];
[UIView animateWithDuration:0.25 animations:^{
cell.transform = CGAffineTransformMakeScale(0.95, 0.95);
} completion:^(BOOL finished) {
cell.transform = CGAffineTransformMakeScale(1.00, 1.00);
topicContentController *vc = [[topicContentController alloc]init];
TopicInfoBO *topic = self.dataList[indexPath.row];
vc.preTopicInfo = topic;
userBO *user = setJsonDicToDataModel(topic.userInfo, [userBO class]);
vc.creatUser = user;
[self.navigationController pushViewController:vc animated:YES];
[[UIApplication sharedApplication] endIgnoringInteractionEvents];
}];
}
}
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
if(self.bannerList.count >0){
return CGSizeMake(CGRectGetWidth(collectionView.bounds), 153);
}else{
return CGSizeMake(0,0);
}
}
-(UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
UICollectionReusableView *reusableview = nil;
if (kind == UICollectionElementKindSectionHeader) {
topciCoverView* headView = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:headViewCellID forIndexPath:indexPath];
// UIButton *leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
// leftBtn.backgroundColor = [UIColor clearColor];
// [leftBtn addTarget:self action:@selector(leftSelector:) forControlEvents:UIControlEventTouchUpInside];
//
// UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
// rightBtn.backgroundColor = [UIColor clearColor];
// [rightBtn addTarget:self action:@selector(rightSelector:) forControlEvents:UIControlEventTouchUpInside];
[headView addSubview:self.topScroll];
// [headView addSubview:self.bannerLeft];
// [headView addSubview:self.bannerRight];
// [headView addSubview:leftBtn];
// [headView addSubview:rightBtn];
[self.topScroll makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(headView.left);
make.right.equalTo(headView.right);
make.top.equalTo(headView.top);
make.height.mas_equalTo(296/2);
}];
// [self.bannerLeft makeConstraints:^(MASConstraintMaker *make) {
// make.left.equalTo(headView.left).offset(15);
// make.width.mas_equalTo(15/2);
// make.centerY.equalTo(headView.centerY);
// make.height.mas_equalTo(14);
// }];
// [leftBtn makeConstraints:^(MASConstraintMaker *make) {
// make.left.equalTo(headView.left).offset(5);
// make.width.mas_equalTo(40);
// make.top.equalTo(headView.top);
// make.bottom.equalTo(headView.bottom);
// }];
// [self.bannerRight makeConstraints:^(MASConstraintMaker *make) {
// make.left.equalTo(headView.right).offset(-15-15/2);
// make.width.mas_equalTo(15/2);
// make.centerY.equalTo(headView.centerY);
// make.height.mas_equalTo(14);
// }];
//
// [rightBtn makeConstraints:^(MASConstraintMaker *make) {
// make.left.equalTo(headView.right).offset(-45);
// make.width.mas_equalTo(40);
// make.top.equalTo(headView.top);
// make.bottom.equalTo(headView.bottom);
// }];
reusableview = headView;
}else if (kind == UICollectionElementKindSectionFooter && isCanLoad){
collectLoadView *footerview = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:collectLoadIndentfier forIndexPath:indexPath];
if (!self.loadFooter) {
self.loadFooter = footerview;
self.loadFooter.hidden = YES;
}
reusableview = footerview;
self.loadFooter.delegate = self;
}
return reusableview;
}
#pragma mark -- btn handler
//-(void) leftSelector:(UIButton *)btn{
// CGPoint oldPoint = self.topScroll.contentOffset;
// if (oldPoint.x > 314) {
// CGPoint newPoint = CGPointMake(oldPoint.x - (float)682/2, oldPoint.y);
// [self.topScroll setContentOffset:newPoint animated:YES];
// bennerIndex--;
// }else{
// [self.topScroll setContentOffset:CGPointMake(0, 0) animated:YES];
// bennerIndex = 0;
// }
//
//}
//
//-(void) rightSelector:(UIButton *)btn{
// CGPoint oldPoint = self.topScroll.contentOffset;
// UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
// int index = bennerIndex;
// if (orientation == UIInterfaceOrientationPortrait
// || orientation == UIInterfaceOrientationPortraitUpsideDown) {
// index++;
// if (index < self.bannerList.count - 1) {
// if (index == self.bannerList.count -2) {
// CGPoint newPoint = CGPointMake(oldPoint.x + 682+682/2-rect_screen.size.width, oldPoint.y);
// [self.topScroll setContentOffset:newPoint animated:YES];
// }else{
// CGPoint newPoint = CGPointMake(oldPoint.x +(float)682/2, oldPoint.y);
// [self.topScroll setContentOffset:newPoint animated:YES];
// }
//
// bennerIndex = index;
// }
// }else if(orientation == UIInterfaceOrientationLandscapeLeft
// || orientation == UIInterfaceOrientationLandscapeRight){
// index++;
// if (index< self.bannerList.count-2) {
// CGPoint newPoint = CGPointMake(oldPoint.x +(float)682/2, oldPoint.y);
// [self.topScroll setContentOffset:newPoint animated:YES];
// bennerIndex = index;
// }
// }
//
//
//}
#pragma mark - refresh and load method
- (void)pullRefreshHandler{
[self remoteMethod];
}
- (void)pullLoadMoreHander {
[self loadMoreMethod];
}
- (void)loadMoreMethod {
if (isBlankString(self.nextUrl)) {
return;
}
self.listViewModel.nextUrl = self.nextUrl;
}
-(void) goToCreateList:(TopicInfoBO *)topicInfo tag:(NSString *)tag{
__weak typeof(self) Self = self;
[self.gambitVC dismissControllerAnimated:YES completion:^{
if (!Self.gambitVC.isNeedHold) {
Self.gambitVC = nil;
}
creatTopicController *creatTopicVC = [[creatTopicController alloc]init];
if (topicInfo) {
creatTopicVC.topicBO = topicInfo;
}
creatTopicVC.tag = tag;
[Self.navigationController pushViewController:creatTopicVC animated:YES];
}];
}
-(void)goTopicInfo:(TopicInfoBO *)topicInfo{
__weak typeof(self) Self = self;
[self.gambitVC dismissControllerAnimated:YES completion:^{
if (!Self.gambitVC.isNeedHold) {
Self.gambitVC = nil;
}
topicContentController *topicControllerVC = [[topicContentController alloc]init];
if (topicInfo) {
topicControllerVC.preTopicInfo = topicInfo;
topicControllerVC.creatUser = setJsonDicToDataModel(topicInfo.userInfo, [userBO class]);
}
topicControllerVC.currentIndex = @"1";
[Self.navigationController pushViewController:topicControllerVC animated:YES];
}];
}
-(void)gotoTopicContent:(listContObjectVO *)topic{
[MobClick event:@"58"];//【需求】统计-iPad(bug:5645)
topicBannersController *bannerVC = [topicBannersController new];
bannerVC.contentBo = topic;
[self.navigationController pushViewController:bannerVC animated:YES];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end
|