|
//
// TopicAnserIconCell.m
// ThePaperBase
//
// Created by zhousan on 15/11/23.
// Copyright © 2015年 scar1900. All rights reserved.
//
#import "TopicAnserIconCell.h"
#import "SDWebImageManager.h"
@implementation TopicAnserIconCell
@synthesize commentBO;
- (void)setCommentBO:(commentObjectVO *)data {
commentBO = data;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
userBO *user = setJsonDicToDataModel(data.userInfo, [userBO class]);
NSString *nameStr = user.sname?[NSString stringWithFormat:@"%@:",user.sname]:@"";
NSString *praiseNum = data.praiseTimes;
dispatch_async(dispatch_get_main_queue(), ^{
if (isBlankString(user.pic)) {
self.answerIcon.image = Image(@"login/loginIcon_s.png");
}else {
if ([[TPUserDefault instance].readModeStr intValue] == imageMode) {
[self updateUserHeadImage:user];
}else if ([[TPUserDefault instance].readModeStr intValue] == textMode) {
self.answerIcon.image = Image(@"login/loginIcon_s.png");
}else {
if ([Remote IsEnableWIFI]) {
[self updateUserHeadImage:user];
}else {
self.answerIcon.image = Image(@"login/loginIcon_s.png");
}
}
}
if ([user.isAuth integerValue] ==1) {//认证用户提问或回答,头像不显示加”V“(bug:4116)
self.verifyTag.hidden = NO;
}else{
self.verifyTag.hidden = YES;
}
self.anserNameLabel.text = nameStr;
self.timeLabel.text = data.pubTime;
if (!isBlankString(praiseNum)) {
self.OkButton.text = praiseNum;
}
if (data.isPraised && [data.isPraised intValue] == 1) {
[self.OkButton setSelected:YES];
}else {
[self.OkButton setSelected:NO];
}
if ([self.topicHostId isEqualToString:user.userId]) {
self.hostLabel.hidden = NO;
}else self.hostLabel.hidden = YES;
[self reLayoutSubViews];
});
});
self.OkButton.text = data.praiseTimes;
[self reLayoutSubViews];
}
- (void)updateUserHeadImage:(userBO*)user{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
SDWebImageManager *imageManager = [SDWebImageManager sharedManager];
[imageManager downloadImageWithURL:[NSURL URLWithString:user.pic]
options:SDWebImageLowPriority
progress:^(NSInteger receivedSize, NSInteger expectedSize) {
} completed:^(UIImage *img, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
// UIImage *roundImage = [UIImage circleImage:img withParam:28];
dispatch_async(dispatch_get_main_queue(), ^{
self.answerIcon.image = img;
});
}];
});
}
- (void)reLayoutSubViews {
CGFloat nameWidth = returnTextWidthWithRTLabel(self.anserNameLabel.text, 12, appFont(TEXT_SIX_LEVELSIZE, NO), 0)+5;
if (nameWidth > rect_screen.size.width - 120) {
nameWidth = rect_screen.size.width - 120;
}
[self.anserNameLabel remakeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.backView.top).offset(14);
make.left.equalTo(self.iconBack.right).offset(10);
make.width.mas_equalTo(nameWidth);
make.height.mas_equalTo(14);
}];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/
@end
|