|
//
// channelPromoteCell.m
// ThePaperBase
//
// Created by scar1900 on 15/7/26.
// Copyright (c) 2015年 scar1900. All rights reserved.
//
#import "channelPromoteCell.h"
#import "AsyncImageView.h"
#import "channelListMethodModel.h"
@interface channelPromoteCell() {
}
@property(nonatomic, strong)UIView *backView;
@property(nonatomic, strong)UILabel *promoteTextLabel;
@property(nonatomic, strong)AsyncImageView *imgView;
@property(nonatomic, strong)UIView *lineView;
@property(nonatomic, strong)UIImageView *videoImg;
@end
@implementation channelPromoteCell
@synthesize listBO = _listBO;
@synthesize topicBO = _topicBO;
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.contentView.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR];
// self.selectionStyle = UITableViewCellSelectionStyleGray;
[self.contentView addSubview:self.backView];
[self.backView addSubview:self.imgView];
[self.backView addSubview:self.promoteTextLabel];
[self.backView addSubview:self.lineView];
[self.imgView addSubview:self.videoImg];
UIView *selectView = [[UIView alloc]initWithFrame:CGRectMake(10, 0, CGRectGetWidth(self.bounds)-20, CGRectGetHeight(self.bounds))];
selectView.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR];
self.selectedBackgroundView = selectView;
[self setLayoutSubviews];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(needrefreshNightMode:) name:REFRESHAFTERNIGHTMODE object:nil];
}
return self;
}
- (void)setListBO:(listContObjectVO *)data {
_listBO = data;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSString *imageID = getImageNameFromURL(data.pic);
NSAttributedString *attributeStr = getLineSpaceAttributedString(data.name,
[iphoneLineSpaceAndParaSpace returnLevel5LineSpace],
appFont([iphoneLineSpaceAndParaSpace returnLevel5FontSize], NO));
dispatch_async(dispatch_get_main_queue(), ^{
CGFloat imageHeight = 60;
CGFloat imageWidth = 60;
if (isBlankString(data.pic)) {
imageWidth = 0;
imageHeight = 0;
}
if ([[TPUserDefault instance].readModeStr intValue] == imageMode) {
self.imgView.hidden = NO;
self.imgView.imageUrl = data.pic;
self.imgView.imageId = imageID;
}else if ([[TPUserDefault instance].readModeStr intValue] == textMode) {
self.imgView.hidden = YES;
imageHeight = 0;
imageWidth = 0;
}else {
if ([Remote IsEnableWIFI]) {
self.imgView.hidden = NO;
self.imgView.imageUrl = data.pic;
self.imgView.imageId = imageID;
}else {
self.imgView.hidden = YES;
imageHeight = 0;
imageWidth = 0;
}
}
[self.imgView remakeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.backView.right);
make.centerY.equalTo(self.backView.centerY);
make.width.equalTo(imageWidth);
make.height.mas_equalTo(imageHeight);
}];
self.promoteTextLabel.attributedText = attributeStr;
if ([channelListMethodModel checkIsHaveRead:data.forwordNodeId]) {
self.promoteTextLabel.textColor = [UIColor colorWithHexString:LIGHTGRAY];
}else {
self.promoteTextLabel.textColor = [UIColor colorWithHexString:TextBlack];
}
if (data.watermark) {
if ([data.watermark intValue] == 1) {//视频
self.videoImg.hidden = NO;
}else {
self.videoImg.hidden = YES;
}
}else {
self.videoImg.hidden = YES;
}
});
});
}
- (void)setTopicBO:(TopicInfoBO *)data {
_topicBO = data;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSString *imageID = getImageNameFromURL(data.pic);
NSAttributedString *attributeStr = getLineSpaceAttributedString(data.title,
[iphoneLineSpaceAndParaSpace returnLevel5LineSpace],
appFont([iphoneLineSpaceAndParaSpace returnLevel5FontSize], NO));
dispatch_async(dispatch_get_main_queue(), ^{
CGFloat imageWidth = 60;
CGFloat imageHeight = 60;
if (isBlankString(data.pic)) {
imageWidth = 0;
imageHeight = 0;
}
if ([[TPUserDefault instance].readModeStr intValue] == imageMode) {
self.imgView.hidden = NO;
self.imgView.imageUrl = data.pic;
self.imgView.imageId = imageID;
}else if ([[TPUserDefault instance].readModeStr intValue] == textMode) {
self.imgView.hidden = YES;
imageHeight = 0;
imageWidth = 0;
}else {
if ([Remote IsEnableWIFI]) {
self.imgView.hidden = NO;
self.imgView.imageUrl = data.pic;
self.imgView.imageId = imageID;
}else {
self.imgView.hidden = YES;
imageHeight = 0;
imageWidth = 0;
}
}
[self.imgView remakeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.backView.right);
make.centerY.equalTo(self.backView.centerY);
make.width.equalTo(imageWidth);
make.height.mas_equalTo(imageHeight);
}];
self.promoteTextLabel.attributedText = attributeStr;
self.promoteTextLabel.textColor = [UIColor colorWithHexString:TextBlack];
self.videoImg.hidden = YES;
// if ([channelListMethodModel checkIsHaveRead:data.topicId]) {
// self.promoteTextLabel.textColor = [UIColor colorWithHexString:LIGHTGRAY];
// }else {
// self.promoteTextLabel.textColor = [UIColor colorWithHexString:TextBlack];
// }
});
});
}
- (UIView*)backView {
if (!_backView) {
_backView = [UIView new];
_backView.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
}
return _backView;
}
- (UILabel*)promoteTextLabel {
if (!_promoteTextLabel) {
_promoteTextLabel = [UILabel new];
_promoteTextLabel.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
_promoteTextLabel.textColor = [UIColor colorWithHexString:TextBlack];
_promoteTextLabel.textAlignment = NSTextAlignmentLeft;
_promoteTextLabel.lineBreakMode = NSLineBreakByWordWrapping;
_promoteTextLabel.numberOfLines = 0;
}
return _promoteTextLabel;
}
- (AsyncImageView*)imgView {
if (!_imgView) {
_imgView = [[AsyncImageView alloc]initWithFrame:CGRectZero];
_imgView.backgroundColor = [UIColor clearColor];
}
return _imgView;
}
- (UIView*)lineView {
if (!_lineView) {
_lineView = [UIView new];
_lineView.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
}
return _lineView;
}
- (UIImageView*)videoImg {
if (!_videoImg) {
_videoImg = [[UIImageView alloc]initWithImage:Image(@"detailPage/vedioIcon_detail.png")];
_videoImg.hidden = YES;
// _videoImg.alpha = 0.6;
}
return _videoImg;
}
- (void)setLayoutSubviews {
[self.backView makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentView.left).offset(10);
make.right.equalTo(self.contentView.right).offset(-10);
make.top.equalTo(self.contentView.top);
make.bottom.equalTo(self.contentView.bottom);
}];
[self.imgView makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.backView.right);
make.centerY.equalTo(self.backView.centerY);
make.width.equalTo(@60);
make.height.equalTo(@60);
}];
[self.promoteTextLabel makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.backView.left).offset(10);
make.right.equalTo(self.imgView.left).offset(-10);
make.top.equalTo(self.backView.top);
make.bottom.equalTo(self.backView.bottom);
}];
[self.lineView makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.backView.left);
make.right.equalTo(self.backView.right);
make.bottom.equalTo(self.backView.bottom);
make.height.equalTo(@1);
}];
[self.videoImg makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self.imgView.centerX);
make.centerY.equalTo(self.imgView.centerY);
make.size.mas_equalTo(CGSizeMake(30, 30));
}];
}
- (void)needrefreshNightMode:(id)sender{
self.contentView.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR];
self.backView.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
UIView *selectView = [[UIView alloc]initWithFrame:CGRectMake(10, 0, CGRectGetWidth(self.bounds)-20, CGRectGetHeight(self.bounds))];
selectView.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR];
self.selectedBackgroundView = selectView;
self.promoteTextLabel.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
if ([channelListMethodModel checkIsHaveRead:self.listBO.forwordNodeId]) {
self.promoteTextLabel.textColor = [UIColor colorWithHexString:LIGHTGRAY];
}else {
self.promoteTextLabel.textColor = [UIColor colorWithHexString:TextBlack];
}
/**
* bug:5332(新闻详情页切换为夜间模式再切换回来,返回到新闻列表页,已读新闻未显示成已读状态(即字体置灰))
*/
self.lineView.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)layoutSubviews {
[super layoutSubviews];
}
@end
|