|
//
// UITestViewController.m
// ThePaperDemo
//
// Created by Scar on 14-9-3.
// Copyright (c) 2014年 scar1900. All rights reserved.
//
#import "channalCollectController.h"
#import "CustomIOSAlertView.h"
@interface channalCollectController () {
}
@end
@implementation channalCollectController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.dataKey = @"contList";
BOOL isNeedShowAlert = NO;
if ([[TPUserDefault instance].readModeStr intValue] == imageMode) {
if (![Remote IsEnableWIFI] && [Remote IsEableNetwork]) {
isNeedShowAlert = YES;
}
}
/**
* bug:5029(无网络环境,有图模式,冷启动app,无网络下不应提示是否切换无图模式)
*/
if ([[TPUserDefault instance].noMoreReadModeAlert intValue] == 1) {
isNeedShowAlert = NO;
}
if (isNeedShowAlert) {
CustomIOSAlertView *customAlert = [[CustomIOSAlertView alloc]init];
UIView *containerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 250, 130)];
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetWidth(containerView.bounds)/2-165/2, CGRectGetHeight(containerView.bounds)/2-76/4, 180, 76/2)];
label.text = @"澎友,您正在使用手机流量,是否切换到智能无图模式。";
label.textColor = [UIColor colorWithHexString:TextBlack];
label.font = appFont(TEXT_FIVE_LEVELSIZE, NO);
label.numberOfLines = 0;
label.textAlignment = NSTextAlignmentLeft;
label.lineBreakMode = NSLineBreakByWordWrapping;
[containerView addSubview:label];
UIButton* selectButton = [UIButton buttonWithType:UIButtonTypeCustom];
[selectButton setImage:Image(@"login/selectedIcon.png") forState:UIControlStateSelected];
[selectButton setImage:Image(@"login/unselectedIcon.png") forState:UIControlStateNormal];
selectButton.backgroundColor = [UIColor clearColor];
[selectButton addTarget:self action:@selector(ignoreVersion:) forControlEvents:UIControlEventTouchUpInside];
[selectButton setImageEdgeInsets:UIEdgeInsetsMake(15/4, 15/4, 15/4, 15/4)];
selectButton.frame = CGRectMake(CGRectGetMinX(label.frame),CGRectGetMaxY(label.frame)+15 , 46/2, 46/2);
[containerView addSubview:selectButton];
UILabel *ignoreLabel = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(selectButton.frame), CGRectGetMinY(selectButton.frame), 90, 23)];
ignoreLabel.text = @"不再提示";
ignoreLabel.textColor = [UIColor colorWithHexString:LIGHTGRAY];
ignoreLabel.font = appFont(TEXT_SIX_LEVELSIZE, NO);
[containerView addSubview:ignoreLabel];
[customAlert setButtonTitles:[NSMutableArray arrayWithObjects:@"不用了",@"马上切换", nil]];
[customAlert setContainerView:containerView];
__block UIButton *btn = selectButton;
[customAlert setOnButtonTouchUpInside:^(CustomIOSAlertView *alertView, int buttonIndex) {
if (buttonIndex == 0) {
[MobClick event:@"47"];
}else{
[MobClick event:@"46"];
[TPUserDefault instance].readModeStr = @"2";
}
if (btn.selected) {
[TPUserDefault instance].noMoreReadModeAlert = @"1";
}
}];
[customAlert show];
}
}
- (void)ignoreVersion:(UIButton*)btn {
btn.selected = !btn.selected;
}
- (void)pullRefreshHandler {
[self remoteAction];
}
- (void)remoteAction {
NSDictionary *dic = @{@"n":self.nodeId};
[Remote doJsonAction:1
requestUrl:channelNodeListURL
parameter:dic
delegate:self];
}
- (void)pullLoadMoreHander {
[Remote doJsonAction:2
requestUrl:self.nextUrl
parameter:nil
delegate:self];
}
- (void)startWaitCursor:(int)actionTag {
}
- (void)stopWaitCursor:(int)actionTag {
}
- (void)remoteResponsSuccess:(int)actionTag withResponsData:(id)responsData {
if (actionTag == 1) {
[self getRefreshDataFromDic:responsData sourceKey:self.dataKey contentClass:self.dataClass];
[self saveRemoteDataToCoreData:responsData];
[self endRefresh];
}else {
NSArray *contList = responsData[@"contList"];
if (contList && contList.count > 0) {
NSMutableArray *oriListData = [NSMutableArray arrayWithArray:self.dataList];
NSMutableArray *tempArray = [NSMutableArray array];
[contList enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
listContObjectVO *contentBO = setJsonDicToDataModel(obj, [listContObjectVO class]);
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];
}
}];
NSInteger firstIndex = self.dataList.count;
[oriListData addObjectsFromArray:tempArray];
self.needReload = NO;
self.dataList = oriListData;
NSMutableArray *indexList = [NSMutableArray array];
for (NSInteger i = firstIndex;i<self.dataList.count;i++) {
[indexList addObject:[NSIndexPath indexPathForRow:i inSection:0]];
}
[self.tableView beginUpdates];
[self.tableView insertRowsAtIndexPaths:indexList withRowAnimation:UITableViewRowAnimationFade];
[self.tableView endUpdates];
/**
* bug:5028(瀑布流:瀑布流加载的时候,loading后的图片会突然显示一下之前的卡片(规律:倒数第三张)
*/
[self loadSuccess];
NSString *url = responsData[@"nextUrl"];
self.nextUrl = url;
}else {
TPLOG(@"加载数据为空");
[self loadFailed];
}
}
}
- (void)dealloc {
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
|