|
//
// 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];
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 *label = [UILabel new];
// label.font = appFont(TEXT_SIX_LEVELSIZE, NO);
// label.numberOfLines = 0;
// label.lineBreakMode = NSLineBreakByWordWrapping;
// label.textColor = [UIColor colorWithHexString:LIGHTGRAY];
// label.text = str;
// titleHeight = 6 +[label sizeThatFits:CGSizeMake(rect_screen.size.width-40, 0)].height;
titleHeight = returnTextHeightWithRTLabel(str, rect_screen.size.width-43, appFont(TEXT_SIX_LEVELSIZE, NO), 2);
// label = nil;
contentHeight = returnTextHeightWithRTLabel(comment.content, rect_screen.size.width-40, appFont(TEXT_FOUR_LEVELSIZE, NO), 7);
// contentHeight = heightForString(comment.content, appFont(TEXT_FOUR_LEVELSIZE, NO), rect_screen.size.width-40, NSLineBreakByWordWrapping);
[heightArray addObject:@(titleHeight+contentHeight+65)];
}else{
TopicInfoBO *topicInfo = list[i];
// contentHeight = heightForString(topicInfo.title, appFont(TEXT_FOUR_LEVELSIZE, NO), rect_screen.size.width-40, NSLineBreakByWordWrapping);
contentHeight = returnTextHeightWithRTLabel(topicInfo.title, rect_screen.size.width-40, appFont(TEXT_FOUR_LEVELSIZE, NO), 7);
[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 *topicInfo = setJsonDicToDataModel(obj[@"object"], [TopicInfoBO class]);
// [allList addObject:topicInfo];
// }else{
// commentObjectVO *commentBO = setJsonDicToDataModel(obj[@"object"], [commentObjectVO class]);
// [allList addObject:commentBO];
// }
// }];
// self.dataList = allList;
NSDictionary *infoDict = responsData[@"userInfo"];
self.userBo = setJsonDicToDataModel(infoDict, [userBO class]);
NSString *url = responsData[@"nextUrl"];
if ([self.otherDele respondsToSelector:@selector(returnDataList:nextUrl:)]) {
[self.otherDele returnDataList:responsData[@"dataList"] 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 *topicInfo = setJsonDicToDataModel(obj[@"object"], [TopicInfoBO class]);
// [allList addObject:topicInfo];
// }else{
// commentObjectVO *commentBO = setJsonDicToDataModel(obj[@"object"], [commentObjectVO class]);
// [allList addObject:commentBO];
// }
// }];
// self.dataList = allList;
// NSDictionary *infoDict = responsData[@"userInfo"];
// self.userBo = setJsonDicToDataModel(infoDict, [userBO class]);
NSString *url = responsData[@"nextUrl"];
if ([self.otherDele respondsToSelector:@selector(returnNextUrlData:nextUrl:)]) {
[self.otherDele returnNextUrlData:responsData[@"dataList"] nextUrl:url];
}
}
@end
|