|
//
// channelTopicContentCell.m
// ThePaperBase
//
// Created by YoungLee on 15/8/4.
// Copyright (c) 2015年 scar1900. All rights reserved.
//
#import "channelTopicContentCell.h"
#import "AsyncImageView.h"
#import "SDWebImageManager.h"
@interface channelTopicContentCell(){
CGFloat contentHeight;
CGFloat typeWidth;
CGFloat praiseWidth;
CGFloat statusWidth;
CGFloat leftPadding;
}
//@property(nonatomic, strong)UIImageView *corImg;
@end
@implementation channelTopicContentCell
@synthesize topic = _topic;
@synthesize indexPath = _indexPath;
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.selectionStyle = UITableViewCellSelectionStyleNone;
self.backgroundColor = [UIColor clearColor];
self.gotoInfo.hidden = YES;
self.corImg.hidden = YES;
self.corLabel.hidden = YES;
[self setLayoutSubviews];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(needrefreshNightMode:) name:REFRESHAFTERNIGHTMODE object:nil];
}
return self;
}
- (void)needrefreshNightMode:(id)sender{
self.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR];
}
-(void)setIndexPath:(NSIndexPath *)index{
_indexPath = index;
// if (_indexPath.row == 0) {
// [self.backView remakeConstraints:^(MASConstraintMaker *make) {
// make.left.equalTo(self.contentView.left).offset(leftPadding);
// make.right.equalTo(self.contentView.right).offset(0-leftPadding);
// make.top.equalTo(self.contentView.top);
// make.bottom.equalTo(self.contentView.bottom).offset(-5);
// }];
// }else{
// [self.backView remakeConstraints:^(MASConstraintMaker *make) {
// make.left.equalTo(self.contentView.left).offset(leftPadding);
// make.right.equalTo(self.contentView.right).offset(0-leftPadding);
// make.top.equalTo(self.contentView.top).offset(5);
// make.bottom.equalTo(self.contentView.bottom).offset(-5);
// }];
// }
}
-(UILabel *)corLabel{
if (!_corLabel) {
_corLabel = [[UILabel alloc]initWithFrame:CGRectZero];
_corLabel.textColor = [UIColor whiteColor];
_corLabel.font = appFont(TEXT_SIX_LEVELSIZE, NO);
_corLabel.textAlignment = NSTextAlignmentCenter;
_corLabel.backgroundColor = [UIColor clearColor];
// _corLabel.layer.borderColor = [UIColor whiteColor].CGColor;
// _corLabel.layer.cornerRadius = 3;
// _corLabel.layer.borderWidth = 1;
}
return _corLabel;
}
-(UIImageView *)corImg{
if (!_corImg) {
_corImg = [[UIImageView alloc] initWithFrame:CGRectZero];
_corImg.image = Image(@"topic/topCorner.png");
}
return _corImg;
}
-(void)setTopic:(TopicInfoBO *)topicInfo{
_topic = topicInfo;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
typeWidth = widthForString(_topic.categoryName, self.type.font, 10, self.type.lineBreakMode);
userBO *user = setJsonDicToDataModel(_topic.userInfo, [userBO class]);
NSString *backImageID = getImageNameFromURL(_topic.pic);
praiseWidth = widthForString(_topic.praiseTimes, self.praiseNum.font, 12, self.praiseNum.lineBreakMode);
NSString *statusText = [self statuName:_topic];
statusWidth = widthForString(statusText, self.status.font, TEXT_SEVEN_LEVELSIZE + 2, self.status.lineBreakMode)+30;
NSAttributedString *attributeStr = getLineSpaceAttributedString(_topic.title?_topic.title:@"", [iphoneLineSpaceAndParaSpace returnLevel5LineSpace], appFont([iphoneLineSpaceAndParaSpace returnLevel5FontSize],NO));
dispatch_async(dispatch_get_main_queue(), ^{
self.type.text = _topic.categoryName;
self.content.attributedText = attributeStr;
if ([[TPUserDefault instance].readModeStr intValue] == imageMode) {
self.backView.imageView.hidden = NO;
self.backView.imageUrl = _topic.pic;
self.backView.imageId = backImageID;
}else if ([[TPUserDefault instance].readModeStr intValue] == textMode) {
self.backView.imageView.hidden = YES;
}else {
if ([Remote IsEnableWIFI]) {
self.backView.imageView.hidden = NO;
self.backView.imageUrl = _topic.pic;
self.backView.imageId = backImageID;
}else {
self.backView.imageView.hidden = YES;
}
}
if (isBlankString(user.pic)) {
self.userImg.image = Image(@"login/loginIcon_s.png");
}else {
if ([[TPUserDefault instance].readModeStr intValue] == imageMode) {
[self updateUserHeadImage:user];
}else if ([[TPUserDefault instance].readModeStr intValue] == textMode) {
self.userImg.image = Image(@"login/loginIcon_s.png");
}else {
if ([Remote IsEnableWIFI]) {
[self updateUserHeadImage:user];
}else {
self.userImg.image = Image(@"login/loginIcon_s.png");
}
}
}
if ([user.isAuth integerValue] == 0) {
self.vImg.hidden = YES;
}else{
self.vImg.hidden = NO;
}
self.userName.text = user.sname;
if (isBlankString(_topic.cornerLabel)) {
self.corLabel.text = _topic.cornerLabel;
self.corImg.hidden = YES;
self.corLabel.hidden = YES;
}else{
self.corImg.hidden = NO;
self.corLabel.hidden = NO;
if ([_topic.cornerLabel intValue] ==1) {
self.corLabel.text = @"置顶";
}else if([_topic.cornerLabel intValue] ==2){
self.corLabel.text = @"热门";
}else if([_topic.cornerLabel intValue] == 3){
self.corLabel.text = @"最新";
}
}
if ([topicInfo.isFirstCard intValue] == 1) {
leftPadding = 0;
}else {
leftPadding = 10;
}
self.praiseNum.text = _topic.praiseTimes;
self.status.text = [self statuName:_topic];
[self remakeSubviews];
});
});
}
-(void)setLayoutSubviews{
contentHeight = heightForAttributeStringWithLabel(self.content.attributedText, rect_screen.size.width-20-32, appFont([iphoneLineSpaceAndParaSpace returnLevel5FontSize], NO));
[self.backView makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentView.left).offset(leftPadding);
make.right.equalTo(self.contentView.right).offset(0-leftPadding);
make.top.equalTo(self.contentView.top).offset(5);
make.bottom.equalTo(self.contentView.bottom).offset(-5);
}];
[self.tempView makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.backView.left);
make.right.equalTo(self.backView.right);
make.top.equalTo(self.backView.top);
make.bottom.equalTo(self.backView.bottom);
}];
[self.type makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.backView.left).offset(16);
make.top.equalTo(self.backView.bottom).offset(-25);
make.width.mas_equalTo(typeWidth);
make.height.mas_equalTo(10);
}];
[self.userImg makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.backView.left).offset(16);
make.top.equalTo(self.backView.top).offset(16);
make.width.mas_equalTo(28);
make.height.mas_equalTo(28);
}];
[self.baiquan makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self.userImg);
make.centerY.equalTo(self.userImg);
make.size.mas_equalTo(CGSizeMake(30, 30));
}];
/**
* bug:5077 5079(新闻详情页,相关话题卡片用户头像要加白圈)
*/
[self.vImg makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.userImg.right).offset(-10);
make.top.equalTo(self.userImg.bottom).offset(-10);
make.width.mas_equalTo(11);
make.height.mas_equalTo(11);
}];
[self.userName makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.userImg.right).offset(10);
make.top.equalTo(self.backView.top).offset(24);
make.width.mas_equalTo(250);
make.height.mas_equalTo(17);
}];
[self.praiseImg makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.type.right).offset(10);
make.top.equalTo(self.type.top).offset(-2);
make.width.mas_equalTo(10);
make.height.mas_equalTo(11);
}];
[self.praiseNum makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.praiseImg.right).offset(5);
make.top.equalTo(self.type.top);
make.width.mas_equalTo(praiseWidth);
make.height.mas_equalTo(11);
}];
[self.status makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.praiseNum.right).offset(10);
make.top.equalTo(self.type.top);
make.width.mas_equalTo(statusWidth);
make.height.mas_equalTo(11);
}];
[self.content makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.backView.bottom).offset(-(40+contentHeight));
make.left.equalTo(self.backView.left).offset(16);
make.right.equalTo(self.backView.right).offset(-16);
make.height.mas_equalTo(contentHeight);
}];
[self.backView addSubview:self.corImg];
[self.corImg addSubview:self.corLabel];
[self.corImg makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.backView.right).offset(-86);
make.width.equalTo(@56);
make.top.equalTo(self.backView.bottom).offset(-42);
make.height.equalTo(@29);
}];
[self.corLabel makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.corImg.left);
make.right.equalTo(self.corImg.right);
make.top.equalTo(self.corImg.top);
make.bottom.equalTo(self.corImg.bottom);
// make.left.equalTo(self.backView.right).offset(-50);
// make.width.equalTo(@30);
// make.top.equalTo(self.backView.bottom).offset(-28);
// make.height.equalTo(@15);
}];
}
- (void)remakeSubviews {
self.corLabel.font = appFont(TEXT_SIX_LEVELSIZE, NO);
self.praiseNum.font = appFont(TEXT_SEVEN_LEVELSIZE, NO);
self.type.font = appFont(TEXT_SEVEN_LEVELSIZE, NO);
self.status.font = appFont(TEXT_SEVEN_LEVELSIZE, NO);
self.content.font = appFont([iphoneLineSpaceAndParaSpace returnLevel5FontSize], NO);
contentHeight = heightForAttributeStringWithLabel(self.content.attributedText, rect_screen.size.width-20-32, appFont([iphoneLineSpaceAndParaSpace returnLevel5FontSize], NO));
if ([self.topic.isFirstCard isEqualToString:@"1"]) {
[self.backView remakeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentView.left).offset(leftPadding);
make.right.equalTo(self.contentView.right).offset(0-leftPadding);
make.top.equalTo(self.contentView.top);
make.bottom.equalTo(self.contentView.bottom).offset(-5);
}];
}else{
[self.backView remakeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentView.left).offset(leftPadding);
make.right.equalTo(self.contentView.right).offset(0-leftPadding);
make.top.equalTo(self.contentView.top).offset(5);
make.bottom.equalTo(self.contentView.bottom).offset(-5);
}];
}
[self.tempView remakeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.backView.left);
make.right.equalTo(self.backView.right);
make.top.equalTo(self.backView.top);
make.bottom.equalTo(self.backView.bottom);
}];
[self.type remakeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.backView.left).offset(16);
make.top.equalTo(self.backView.bottom).offset(-25);
make.width.mas_equalTo(typeWidth);
make.height.mas_equalTo(10);
}];
[self.praiseNum remakeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.praiseImg.right).offset(5);
make.top.equalTo(self.type.top);
make.width.mas_equalTo(praiseWidth);
make.height.mas_equalTo(11);
}];
[self.status remakeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.praiseNum.right).offset(10);
make.top.equalTo(self.type.top);
make.width.mas_equalTo(statusWidth);
make.height.mas_equalTo(11);
}];
[self.content remakeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.backView.bottom).offset(-(40+contentHeight));
make.left.equalTo(self.backView.left).offset(16);
make.right.equalTo(self.backView.right).offset(-16);
make.height.mas_equalTo(contentHeight);
}];
[self.corImg remakeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.backView.right).offset(-50);
make.width.equalTo(@30);
make.top.equalTo(self.backView.bottom).offset(-28);
make.height.equalTo(@15);
}];
}
@end
|