LVCUGCLivePlayerCell.m 6.44 KB
//
//  LVCUGCLivePlayerCell.m
//  LiveVideoCloud
//
//  Created by cnliveJunBo on 17/3/28.
//  Copyright © 2017年 cnlive. All rights reserved.
//

#import "LVCUGCLivePlayerCell.h"

@interface LVCUGCLivePlayerCell()

@property (nonatomic, strong) UIImageView *iconView;

@property (nonatomic, strong) UILabel *nameLabel;

@property (nonatomic, strong) UILabel *locationLabel;

@property (nonatomic, strong) UILabel *countLabel;

@property (nonatomic, strong) UILabel *lookLabel;

@property (nonatomic, strong) UIImageView *imageView;

@property (nonatomic, strong) UILabel *stateLabel;

@property (nonatomic, strong) UILabel *titleLabel;

@property (nonatomic, strong) UIView *lineView;

@end

@implementation LVCUGCLivePlayerCell

- (instancetype)initWithFrame:(CGRect)frame {
    
    self = [super initWithFrame:frame];
    if (self) {
        self.contentView.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:self.iconView];
        [self.contentView addSubview:self.nameLabel];
        [self.contentView addSubview:self.locationLabel];
        [self.contentView addSubview:self.countLabel];
        [self.contentView addSubview:self.lookLabel];
        [self.contentView addSubview:self.imageView];
        [self.contentView addSubview:self.titleLabel];
        [self.contentView addSubview:self.lineView];
    }
    return self;
}

#pragma mark - SetMethod !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- (void)setModel:(LVCUGCLivePlayerModel *)model {
    
    if (_model != model) {
        _model = model;
    }
    _titleLabel.text = model.activityName;    // 标题
    
    NSString *path = [[NSBundle mainBundle] pathForResource:@"timg" ofType:@"jpeg"];// 封面图
    UIImage *image = [UIImage imageWithContentsOfFile:path];
    [_imageView sd_setImageWithURL:[NSURL URLWithString:model.coverImgUrl] placeholderImage:image];
    
    if (model.extensionName.length > 0) {
        _nameLabel.text = model.extensionName;
    } else {
        _nameLabel.text = @"我的昵称";
    }
//    NSString *iconPath = [[NSBundle mainBundle] pathForResource:@"头像" ofType:@"jpg"];
//    UIImage *iconImage = [UIImage imageWithContentsOfFile:iconPath];
    UIImage *iconImage = [UIImage imageWithData:[NSData
                                             dataWithContentsOfURL:[NSURL URLWithString:[UserInformationModel manager].faceUrl]]];
    [_iconView sd_setImageWithURL:[NSURL URLWithString:model.extensionIcon] placeholderImage:iconImage];
    
    switch ([model.activityStatus intValue]) {
        case -2: // 异常
            _stateLabel.text = @"异常";
            break;
        case 0: // 未开始
            _stateLabel.text = @"未开始";
            break;
        case 1: // 已开始
            _stateLabel.text = @"正直播";
            break;
        case 2: // 已结束
            _stateLabel.text = @"已结束";
            break;
        case 4: // 已离线
            _stateLabel.text = @"已离线";
            break;
            
        default:
            break;
    }
}

#pragma mark - SetMethod !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- (UIImageView *)iconView {
    
    if (!_iconView) {
        _iconView = [[UIImageView alloc] init];
        _iconView.frame = CGRectMake(10, 10, 50, 50);
        _iconView.contentMode = UIViewContentModeScaleAspectFit;
        _iconView.layer.cornerRadius = 25;
        _iconView.layer.masksToBounds = YES;
    }
    return _iconView;
}

- (UILabel *)nameLabel {
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(70, 15, SCREEN_WIDTH - 140, 20)];
        _nameLabel.text = @"这是我的昵称";
        _nameLabel.textColor = [UIColor grayColor];
    }
    return _nameLabel;
}

- (UILabel *)locationLabel {
    if (!_locationLabel) {
        _locationLabel = [[UILabel alloc] initWithFrame:CGRectMake(70, 40, SCREEN_WIDTH - 140, 20)];
        _locationLabel.text = @"这是我的地址";
        _locationLabel.font = [UIFont systemFontOfSize:13];
        _locationLabel.textColor = [UIColor grayColor];
    }
    return _locationLabel;
}

- (UILabel *)countLabel {
    if (!_countLabel) {
        _countLabel = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - 65, 15, 60, 20)];
        _countLabel.text = @"13244";
        _countLabel.textAlignment = NSTextAlignmentRight;
        _countLabel.textColor = [UIColor orangeColor];
    }
    return _countLabel;
}

- (UILabel *)lookLabel {
    if (!_lookLabel) {
        _lookLabel = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - 45, 35, 40, 20)];
        _lookLabel.text = @"在看";
        _lookLabel.font = [UIFont systemFontOfSize:13];
        _lookLabel.textAlignment = NSTextAlignmentRight;
        _lookLabel.textColor = [UIColor grayColor];
    }
    return _lookLabel;
}

- (UIImageView *)imageView {
    if (!_imageView) {
        _imageView = [[UIImageView alloc] init];
        _imageView.frame = CGRectMake(0, 70, SCREEN_WIDTH, SCREEN_WIDTH);
        _imageView.contentMode = UIViewContentModeScaleAspectFill;
        _imageView.backgroundColor = [UIColor colorWithRed:(230/255) green:(241/255) blue:(243/255) alpha:1];
        _imageView.clipsToBounds = YES;
        [_imageView addSubview:self.stateLabel];
    }
    return _imageView;
}

- (UILabel *)stateLabel {
    if (!_stateLabel) {
        _stateLabel = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - 70, 10, 60, 20)];
        _stateLabel.font = [UIFont systemFontOfSize:13];
        _stateLabel.textAlignment = NSTextAlignmentCenter;
        _stateLabel.textColor = [UIColor whiteColor];
        _stateLabel.backgroundColor = [UIColor colorWithRed:(250/255) green:(246/255) blue:(246/255) alpha:0.3];
        _stateLabel.layer.cornerRadius = 10;
        _stateLabel.layer.masksToBounds = YES;
        _stateLabel.text = @"直播";
        _stateLabel.layer.borderColor = [UIColor whiteColor].CGColor;
        _stateLabel.layer.borderWidth = 1;
    }
    return _stateLabel;
}

- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, SCREEN_WIDTH + 75, SCREEN_WIDTH, 20)];
        _titleLabel.textColor = [UIColor grayColor];
        _titleLabel.text = @"这是一个标题";
    }
    return _titleLabel;
}

- (UIView *)lineView {
    if (!_lineView) {
        _lineView = [[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_WIDTH + 100, SCREEN_WIDTH, 10)];
        _lineView.backgroundColor = [UIColor colorWithRed:(217/255.0) green:(255/255.0) blue:(239/255.0) alpha:1.0];
    }
    return _lineView;
}

@end