澎湃iPad上线版本

topicListViewModel.m 7.2KB

    // // topicListViewModel.m // ThePaperHD // // Created by liyuan on 15/7/3. // Copyright (c) 2015年 scar1900. All rights reserved. // #import "topicListViewModel.h" #define CATEGORYTAG 1001 #define ALLDATATAG 1002 #define CATEDATATAG 1003 #define NEXTURLTAG 1004 #define FIRSTTAG 1005 @implementation topicListViewModel @synthesize dict = _dict; @synthesize firstDict = _firstDict; @synthesize nextUrl = _nextUrl; -(instancetype)init{ self = [super init]; if (self) { // [self remoteAction]; // [Remote ] } return self; } #pragma mark - public method && private method -(void)setCateDic:(NSDictionary *)cateDic{ [Remote doJsonAction:CATEGORYTAG requestUrl:getTopicCategorysURL parameter:nil delegate:self]; } -(void)setDict:(NSMutableDictionary *)dictionary{ _dict = dictionary; if ([self.delegate respondsToSelector:@selector(returnCateData:nextUrl:)]) { [self.delegate returnCateData:nil nextUrl:nil]; } } -(void)setFirstDict:(NSDictionary *)dic{ _firstDict = dic; [Remote doJsonAction:ALLDATATAG requestUrl:topicListURL parameter:_firstDict delegate:self]; } -(void)setNextUrl:(NSString *)url{ _nextUrl = url; [Remote doJsonAction:NEXTURLTAG requestUrl:_nextUrl parameter:nil delegate:self]; } #pragma mark -- remote data - (void)startWaitCursor:(int)actionTag { //问吧频道,上拉加载动作非常容易出现侧滑(bug:4708) if (actionTag == NEXTURLTAG || actionTag == ALLDATATAG) { return; } if ([self.delegate respondsToSelector:@selector(startWaitWithViewModel)]) { [self.delegate startWaitWithViewModel]; } } - (void)stopWaitCursor:(int)actionTag { //问吧频道,上拉加载动作非常容易出现侧滑(bug:4708) if (actionTag == NEXTURLTAG || actionTag == ALLDATATAG) { return; } if ([self.delegate respondsToSelector:@selector(stopWaitWithViewModel)]) { [self.delegate stopWaitWithViewModel]; } } - (void)remoteResponsSuccess:(int)actionTag withResponsData:(id)responsData { if(actionTag == CATEGORYTAG){ [self saveCategoryData:responsData]; }else if(actionTag == ALLDATATAG){ [self saveAllListData:responsData]; }else if(actionTag == CATEDATATAG){ [self saveCateData:responsData]; }else if (actionTag == NEXTURLTAG){ [self saveNextUrlData:responsData]; } } -(void)remoteResponsFailed:(int)actionTag withMessage:(NSString *)message resultCode:(NSString *)code{ } #pragma mark -- save data -(void) saveCategoryData:(id) data{//分类数据 NSMutableArray *cateArray = [NSMutableArray array]; NSArray *tempCataList = data[@"dataList"]; categoryBO *allCata = categoryBO.new; allCata.name = @"精选"; allCata.enname = @"FRONT PAGE"; allCata.category = @""; [cateArray addObject:allCata]; [tempCataList enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { categoryBO *cate = setJsonDicToDataModel(obj, [categoryBO class]); [cateArray addObject:cate]; }]; if ([self.delegate respondsToSelector:@selector(returnCategory:)]) { [self.delegate returnCategory:cateArray]; } } -(void) saveAllListData:(id) data{//所有数据 NSArray *topicList = data[@"topicList"]; NSString *url = data[@"nextUrl"]; if (topicList.count>0) { NSMutableArray *tempArray = [NSMutableArray array]; [topicList enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { if (isPad ) { if (![obj[@"forwordType"] isEqualToString:@"4"]) { TopicInfoBO *topicBO = setJsonDicToDataModel(obj, [TopicInfoBO class]); NSString *desc = obj[@"description"]; topicBO.desc = desc; [tempArray addObject:topicBO]; } }else{ TopicInfoBO *topicBO = setJsonDicToDataModel(obj, [TopicInfoBO class]); NSString *desc = obj[@"description"]; topicBO.desc = desc; [tempArray addObject:topicBO]; } }]; if ([self.delegate respondsToSelector:@selector(returnBannerData:)]) { [self.delegate returnBannerData:data[@"banners"]]; } if ([self.delegate respondsToSelector:@selector(returnAlldata:nextUrl:)]) { [self.delegate returnAlldata:tempArray nextUrl:url]; } }else { if ([self.delegate respondsToSelector:@selector(returnBannerData:)]) { [self.delegate returnBannerData:data[@"banners"]]; } if ([self.delegate respondsToSelector:@selector(returnAlldata:nextUrl:)]) { [self.delegate returnAlldata:nil nextUrl:url]; } } } -(void) saveCateData:(id) data{ NSArray *topicList = data[@"topicList"]; NSString *url = data[@"nextUrl"]; if (topicList.count>0) { NSMutableArray *tempArray = [NSMutableArray array]; [topicList enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { TopicInfoBO *topicBO = setJsonDicToDataModel(obj, [TopicInfoBO class]); NSString *desc = obj[@"description"]; topicBO.desc = desc; [tempArray addObject:topicBO]; }]; if ([self.delegate respondsToSelector:@selector(returnCateData:nextUrl:)]) { [self.delegate returnCateData:tempArray nextUrl:url]; } }else { if ([self.delegate respondsToSelector:@selector(returnCateData:nextUrl:)]) { [self.delegate returnCateData:nil nextUrl:url]; } } } -(void) saveNextUrlData:(id) data{ NSArray *contList = data[@"topicList"]; NSString *url = data[@"nextUrl"]; if (contList && contList.count >0) { NSMutableArray *tempArray = [NSMutableArray array]; [contList enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { // TopicInfoBO *topicBO = setJsonDicToDataModel(obj, [TopicInfoBO class]); if (isPad ) { if (![obj[@"forwordType"] isEqualToString:@"4"]) { TopicInfoBO *topicBO = setJsonDicToDataModel(obj, [TopicInfoBO class]); NSString *desc = obj[@"description"]; topicBO.desc = desc; [tempArray addObject:topicBO]; } }else{ TopicInfoBO *topicBO = setJsonDicToDataModel(obj, [TopicInfoBO class]); NSString *desc = obj[@"description"]; topicBO.desc = desc; [tempArray addObject:topicBO]; } // NSString *desc = obj[@"description"]; // topicBO.desc = desc; // [tempArray addObject:topicBO]; }]; if ([self.delegate respondsToSelector:@selector(returnNextUrlData:nextUrl:)]) { [self.delegate returnNextUrlData:tempArray nextUrl:url]; } }else{ if ([self.delegate respondsToSelector:@selector(returnNextUrlData:nextUrl:)]) { [self.delegate returnNextUrlData:nil nextUrl:url]; } } } @end