|
//
// liveVideoCell.m
// ThePaperHD
//
// Created by scar1900 on 15/3/11.
// Copyright (c) 2015年 scar1900. All rights reserved.
//
#import "liveVideoCell.h"
#import "AsyncImageView.h"
#define CONTENTWIDTH 1060/2
@interface liveVideoCell() {
}
@property(nonatomic, strong)AsyncImageView *imgView;
@property(nonatomic, strong)UILabel *destLabel;
@property(nonatomic, strong)imageObjectBO *imageBO;
@property(nonatomic, strong)videoObjectBO *videoBO;
@property(nonatomic, strong)UIView *lineView;
@property(nonatomic, strong)UIImageView *videoImage;
@end
@implementation liveVideoCell
@synthesize dataDic = _dataDic;
@synthesize imageBO = _imageBO;
@synthesize videoBO = _videoBO;
@synthesize delegate;
@synthesize indexPath;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
self.selectionStyle = UITableViewCellSelectionStyleNone;
[self.contentView addSubview:self.imgView];
[self.contentView addSubview:self.destLabel];
[self.imgView addSubview:self.videoImage];
[self.contentView addSubview:self.lineView];
[self setLayoutViews];
}
return self;
}
- (UIImageView*)videoImage {
if (!_videoImage) {
_videoImage = [[UIImageView alloc]initWithImage:Image(@"detailPage/videoBack.png")];
}
return _videoImage;
}
- (void)setDataDic:(NSDictionary *)dic {
_dataDic = dic;
videoObjectBO *video = dic[@"video"];
imageObjectBO *image = dic[@"image"];
self.imageBO = image;
self.videoBO = video;
NSString *type = dic[@"type"];
if ([type isMatchedByRegex:@"top"]) {
self.lineView.hidden = YES;
}else self.lineView.hidden = NO;
[self setLayoutViews];
}
- (void)setImageBO:(imageObjectBO *)data {
_imageBO = data;
if ([data.tags isEqualToString:@"www_video"] || [data.tags isEqualToString:@"www_big"]) {
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickVideo:)];
[self.imgView addGestureRecognizer:tapGesture];
self.videoImage.hidden = NO;
}else {
self.videoImage.hidden = YES;
}
self.imgView.imageUrl = data.url;
}
- (void)setVideoBO:(videoObjectBO *)video {
_videoBO = video;
self.destLabel.text = video.name;
[self.destLabel setNeedsDisplay];
}
- (UIView*)lineView {
if (!_lineView) {
_lineView = [[UIView alloc]initWithFrame:CGRectZero];
_lineView.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
}
return _lineView;
}
- (AsyncImageView*)imgView {
if (!_imgView) {
_imgView = [[AsyncImageView alloc]initWithFrame:CGRectZero];
_imgView.backgroundColor = [UIColor clearColor];
_imgView.hidden = YES;
}
return _imgView;
}
- (UILabel*)destLabel {
if (!_destLabel) {
_destLabel = [[UILabel alloc]initWithFrame:CGRectZero];
_destLabel.backgroundColor = [UIColor clearColor];
_destLabel.textAlignment = NSTextAlignmentLeft;
_destLabel.textColor = [UIColor colorWithHexString:TextGray];
_destLabel.lineBreakMode = NSLineBreakByWordWrapping;
_destLabel.numberOfLines = 0;
}
_destLabel.font = appFont(imageDescFontSize, NO);
return _destLabel;
}
- (void)clickVideo:(UITapGestureRecognizer*)tapGesture {
if ([delegate conformsToProtocol:@protocol(liveVideoCellDelegate)] &&
[delegate respondsToSelector:@selector(clickToPlayVideo:indexPath:videoBO:)]) {
[delegate clickToPlayVideo:self.imgView.bounds indexPath:self.indexPath videoBO:self.videoBO];
}
}
- (void)setLayoutViews {
// CGFloat descHeight = returnTextHeightWithRTLabel(self.videoBO.name, CONTENTWIDTH, appFont(imageDescFontSize, NO), 5);
CGFloat descHeight = [self.destLabel sizeThatFits:CGSizeMake(CONTENTWIDTH, CGFLOAT_MAX)].height;
CGFloat padding = 0;
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) {
padding = 125;
}
if (self.imageBO) {
self.imgView.frame = CGRectMake(padding+226/2, 0, CONTENTWIDTH, 300);
}
self.destLabel.frame = CGRectMake(padding+226/2,
CGRectGetMaxY(self.imgView.bounds)+5,
CONTENTWIDTH,
descHeight);
if (self.imgView.hidden) {
self.imgView.hidden = NO;
}
[self.lineView remakeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentView.left).offset(padding+7);
make.width.mas_equalTo(1);
make.top.equalTo(self.top);
make.bottom.equalTo(self.bottom);
}];
// self.lineView.frame = CGRectMake(padding+7, 0, 1, CGRectGetHeight(self.bounds));
self.videoImage.frame = CGRectMake(CGRectGetWidth(self.imgView.bounds)-118,
CGRectGetHeight(self.imgView.bounds)-113,
75, 75);//【需求】视频:水印修改(bug:4353)
}
- (void)awakeFromNib {
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end
|