澎湃iPad上线版本

otherPersonModel.m 8.1KB

    // // otherPersonModel.m // ThePaperHD // // Created by liyuan on 15/7/14. // Copyright (c) 2015年 scar1900. All rights reserved. // #define OTHERTAG 1001 #define NEXTURLTAG 1002 #import "otherPersonModel.h" @interface otherPersonModel()<RemoteDelegate>{ NSMutableArray *heightArray; } @property(nonatomic, strong) NSMutableArray *dataList; @property(nonatomic, strong) userBO *userBo; @end @implementation otherPersonModel @synthesize dataDict = _dataDict; @synthesize dataList = _dataList; @synthesize userBo = _userBo; @synthesize oldArray = _oldArray; -(void)setDataDict:(NSMutableDictionary *)dict{ _dataDict = dict; [Remote doJsonAction:OTHERTAG requestUrl:userNewsPageURL parameter:_dataDict delegate:self]; } -(void)startWaitCursor:(int)actionTag{ } -(void)stopWaitCursor:(int)actionTag{ } #pragma mark -- set data -(void)setDataList:(NSMutableArray *)list{ _dataList = list; if (list.count > 0 ) { heightArray = [NSMutableArray array]; for (int i =0; i < list.count; i++) { CGFloat titleHeight; CGFloat contentHeight; if ([list[i] isKindOfClass:[commentObjectVO class]]) { commentObjectVO *comment = list[i]; if([comment.askOrAnswer isEqualToString:@"1"]){ NSString *str; NSString *contName = comment.contName; NSString *contentName = comment.parent[@"content"]; if([comment.type isEqualToString:@"1"]){//如果是评论,后面只能是原提问 str = [NSString stringWithFormat:@"【原新闻】%@",contName]; }else if ([comment.type isEqualToString:@"2"]){//如果是提问,后面只有两种:原话题,原新闻 if([comment.objectType isEqualToString:@"3"]){ str = [NSString stringWithFormat:@"【原话题】%@",contName]; }else{ str = [NSString stringWithFormat:@"【原新闻】%@",contName]; } }else{ str = [NSString stringWithFormat:@"【原提问】%@",contentName]; } // UILabel *_title = [[UILabel alloc] init]; // _title.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR]; // _title.font = appFont(TEXT_SIX_LEVELSIZE, NO); // _title.numberOfLines = 0; // _title.lineBreakMode = NSLineBreakByWordWrapping; // _title.text = str; // titleHeight = [_title sizeThatFits:CGSizeMake(688, 0)].height; // _title = nil; titleHeight = heightForAttributeStringWithLabel(getLineSpaceAttributedString(str, 2, appFont(TEXT_SIX_LEVELSIZE, NO)), 688, appFont(TEXT_SIX_LEVELSIZE, NO)); if(titleHeight <20){ titleHeight = 20; } [heightArray addObject:@(titleHeight+10)]; }else{ contentHeight = returnTextHeightWithRTLabel(comment.content, 730, appFont(TEXT_TWO_LEVELSIZE, NO), 6); [heightArray addObject:@(contentHeight+60)]; } }else{ TopicInfoBO *topicInfo = list[i]; if ([topicInfo.askOrAnswer isEqualToString:@"1"]) { [heightArray addObject:@(30)]; }else{ contentHeight = returnTextHeightWithRTLabel(topicInfo.title, 730, appFont(TEXT_TWO_LEVELSIZE, NO), 6); [heightArray addObject:@(contentHeight+75)]; } } } } } -(void)setUserBo:(userBO *)bo{ _userBo = bo; bool isMale; bool isAuth; if ([_userBo.userId isEqualToString:@"-1"]) { isMale = YES; }else{ if ([_userBo.sex integerValue] ==0) { isMale = YES; }else{ isMale = NO; } } if ([_userBo.isAuth integerValue] == 1) { isAuth = YES; }else{ isAuth = NO; } if ([self.otherDele respondsToSelector:@selector(returnUserBo:sname:imageUrl:ismale:isAuth:sign:userBo:)]) { [self.otherDele returnUserBo:bo.sname sname:bo.sname imageUrl:bo.pic ismale:isMale isAuth:isAuth sign:bo.perDesc userBo:_userBo]; } } -(void)setOldArray:(NSMutableArray *)array{ _oldArray = array; } -(void)setNextUrl:(NSString *)url{ [Remote doJsonAction:NEXTURLTAG requestUrl:url parameter:nil delegate:self]; } #pragma mark -- remote success -(void)remoteResponsSuccess:(int)actionTag withResponsData:(id)responsData{ if (actionTag == OTHERTAG) { [self saveDataList:responsData]; }else if (actionTag == NEXTURLTAG){ [self saveNextUrlData:responsData]; } } -(void)remoteResponsFailed:(int)actionTag withMessage:(NSString *)message resultCode:(NSString *)code{ ShowTextMessage(message); if ([self.otherDele respondsToSelector:@selector(returnNoData)]) { [self.otherDele returnNoData]; } } #pragma mark -- save remote data -(void) saveDataList:(id)responsData{ NSMutableArray *allTempList = responsData[@"dataList"]; NSMutableArray *allList = [NSMutableArray array]; [allTempList enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { if ([allTempList[idx][@"objectType"] isEqualToString:@"4"]) { TopicInfoBO *topicTop = setJsonDicToDataModel(obj[@"object"], [TopicInfoBO class]); topicTop.askOrAnswer = @"1"; [allList addObject:topicTop]; TopicInfoBO *content = setJsonDicToDataModel(obj[@"object"], [TopicInfoBO class]); content.askOrAnswer = @"2"; [allList addObject:content]; }else{ commentObjectVO *commentBO = setJsonDicToDataModel(obj[@"object"], [commentObjectVO class]); //原评论,原提问...askOrAnswer == 1 commentBO.askOrAnswer = @"1"; [allList addObject:commentBO]; //提问部分 askOrAnswer == 2; commentObjectVO *askComment = setJsonDicToDataModel(obj[@"object"], [commentObjectVO class]); askComment.askOrAnswer = @"2"; [allList addObject:askComment]; } }]; self.dataList = allList; NSDictionary *infoDict = responsData[@"userInfo"]; self.userBo = setJsonDicToDataModel(infoDict, [userBO class]); NSString *url = responsData[@"nextUrl"]; if([self.otherDele respondsToSelector:@selector(returnDataList:heightArray:nextUrl:)]){ [self.otherDele returnDataList:self.dataList heightArray:heightArray nextUrl:url]; } } -(void) saveNextUrlData:(id)responsData{ NSMutableArray *allTempList = responsData[@"dataList"]; NSMutableArray *allList = [NSMutableArray array]; [allTempList enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { if ([allTempList[idx][@"objectType"] isEqualToString:@"4"]) { TopicInfoBO *topicTop = setJsonDicToDataModel(obj[@"object"], [TopicInfoBO class]); topicTop.askOrAnswer = @"1"; [allList addObject:topicTop]; TopicInfoBO *content = setJsonDicToDataModel(obj[@"object"], [TopicInfoBO class]); content.askOrAnswer = @"2"; [allList addObject:content]; }else{ commentObjectVO *commentBO = setJsonDicToDataModel(obj[@"object"], [commentObjectVO class]); //原评论,原提问...askOrAnswer == 1 commentBO.askOrAnswer = @"1"; [allList addObject:commentBO]; //提问部分 askOrAnswer == 2; commentObjectVO *askComment = setJsonDicToDataModel(obj[@"object"], [commentObjectVO class]); askComment.askOrAnswer = @"2"; [allList addObject:askComment]; } }]; self.dataList = allList; NSString *url = responsData[@"nextUrl"]; if ([self.otherDele respondsToSelector:@selector(returnNextUrlData:heightArray:nextUrl:)]) { [self.otherDele returnNextUrlData:self.dataList heightArray:heightArray nextUrl:url]; } } @end