IVTMeLiveListCell.m 8.81 KB
//
//  IVTMeLiveListCell.m
//  IVTMeLive
//
//  Created by XRG on 16/4/15.
//  Copyright © 2016年 Joky. All rights reserved.
//

#import "IVTMeLiveListCell.h"
#import "XMPPFramework.h"

@interface IVTMeLiveListCell()<UIGestureRecognizerDelegate>



@end


@implementation IVTMeLiveListCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        _headIcon = [[UIImageView alloc] init];
        _headIcon.image = [UIImage imageNamed:@"占位头像"];
        _headIcon.clipsToBounds = YES;

//        _headIcon.layer.cornerRadius = 34 / 2;
//        _headIcon.userInteractionEnabled = YES;

        [self.contentView addSubview:_headIcon];
        __unsafe_unretained typeof (self) wself = self;
        [_headIcon mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.equalTo(wself.contentView.mas_leading).with.offset(12);
            make.top.equalTo(wself.contentView.mas_top).with.offset(10);
            make.size.mas_equalTo(CGSizeMake(34, 34));
        }];
        
        UIButton *head = [UIButton buttonWithType:UIButtonTypeCustom];
        head.backgroundColor  =[UIColor clearColor];
        [_headIcon addSubview:head];
        [head mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.edges.equalTo(_headIcon);
        }];
        
        _name = [[UILabel alloc]init];
        [self.contentView addSubview:_name];
        _name.backgroundColor = [UIColor clearColor];
        _name.textColor = [UIColor YXColorWithHexCode:@"#282828"];
        _name.font = [UIFont YXFontOfSize:15];
        _name.textAlignment = NSTextAlignmentLeft;
        [_name mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(wself.contentView.mas_top).with.offset(12);
            make.left.equalTo(_headIcon.mas_right).with.offset(11);
            make.size.mas_equalTo(CGSizeMake(300, 14));
        }];
        
        _mark = [[UILabel alloc]init];
        [self.contentView addSubview:_mark];
        _mark.backgroundColor = [UIColor clearColor];
        _mark.textColor = [UIColor  YXColorWithHexCode:@"#8d8d8d"];
        _mark.font = [UIFont YXFontOfSize:11];
        _mark.textAlignment = NSTextAlignmentLeft;
        [_mark mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_name.mas_bottom).with.offset(4);
            make.left.equalTo(_headIcon.mas_right).with.offset(11);
            make.size.mas_equalTo(CGSizeMake(210, 15));
        }];

        
        _imageVBig = [[UIImageView alloc]init];
        _imageVBig.backgroundColor = [UIColor whiteColor];
        _imageVBig.clipsToBounds = YES;
        _imageVBig.layer.cornerRadius = 15;
        _imageVBig.image  = [UIImage imageNamed:@"占位头像"];
        _imageVBig.frame = CGRectMake(13, 51, kScreenWidth - 26, kScreenWidth -30);
        [self.contentView addSubview:_imageVBig];

        
        
        _live = [[UIImageView alloc]init];
        _live.image = [UIImage imageNamed:@"LIVE"];
        [self.contentView addSubview:_live];
        [_live mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(51, 19));
            make.top.equalTo(_imageVBig.mas_top).with.offset(9);
            make.leading.equalTo(_imageVBig.mas_leading).with.offset(20);
            
        }];
        
        
        _locationIcon = [[UIImageView alloc]init];
        _locationIcon.image = [UIImage imageNamed:@"MeLocation"];
        [self.contentView addSubview:_locationIcon];
        [_locationIcon mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(8, 10));
            make.leading.equalTo(wself.contentView.mas_leading).with.offset(14);
            make.top.equalTo(_imageVBig.mas_bottom).with.offset(12);
        }];
        
        _loaction = [[UILabel alloc]init];
        [self.contentView addSubview:_loaction];
         _loaction.backgroundColor = [UIColor clearColor];
         _loaction.textColor = [UIColor YXColorWithHexCode:@"#000000" alpha:0.4];
         _loaction.font = [UIFont YXFontOfSize:12];
         _loaction.text = @"北京SOHO现代城";
         _loaction.textAlignment = NSTextAlignmentLeft;
        [_loaction mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_imageVBig.mas_bottom).with.offset(11);
            make.left.equalTo(_locationIcon.mas_right).with.offset(5);
            make.size.mas_equalTo(CGSizeMake(120, 13));
        }];
        
        _audienceIcon = [[UIImageView alloc]init];
         _audienceIcon.image = [UIImage imageNamed:@"MeDedult"];
        [self.contentView addSubview: _audienceIcon];
        [ _audienceIcon mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(8.5, 8.5));
            make.leading.equalTo(wself.contentView.mas_trailing).with.offset(-24);
            make.top.equalTo(_imageVBig.mas_bottom).with.offset(14);
        }];
        
        _audienceNum = [[UILabel alloc]init];
        [self.contentView addSubview:_audienceNum];
         _audienceNum.backgroundColor = [UIColor clearColor];
         _audienceNum.textColor = [UIColor YXColorWithHexCode:@"#a3a3a3"];
         _audienceNum.font = [UIFont YXFontOfSize:12];

         _audienceNum.textAlignment = 2;
        [ _audienceNum mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_imageVBig.mas_bottom).with.offset(13);
            make.right.equalTo(_audienceIcon.mas_right).with.offset(-10);
            make.size.mas_equalTo(CGSizeMake(35, 11));
        }];
        
        UILabel *spaceLine = [[UILabel alloc] init];
        spaceLine.backgroundColor = [UIColor IVTBackgroundColor];
        [self.contentView addSubview:spaceLine];
        [ spaceLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(wself.contentView.mas_bottom).with.offset(0);
            make.left.equalTo(wself.contentView.mas_left).with.offset(0);
            make.size.mas_equalTo(CGSizeMake(kScreenWidth, 10));
        }];
        
    }
    return self;
}


- (void)setPlayerModel:(IVTHotAndFollowVideoModel *)playerModel
{
    _playerModel = playerModel;
    // 用户名
    _name.text = [playerModel.name base64DecodedToString];
    _mark.text = [playerModel.liveRoomName base64DecodedToString];
    // 用户所在城市
    if (playerModel.city == nil) {
        _loaction.text = @"难道在火星?";
    }else{
        _loaction.text = playerModel.city;
    }
    // 用户Image
    [_headIcon sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",playerModel.portrait]] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:_headIcon.bounds byRoundingCorners:UIRectCornerAllCorners cornerRadii:_headIcon.bounds.size];
        
        CAShapeLayer *maskLayer = [[CAShapeLayer alloc]init];
        //设置大小
        maskLayer.frame = _headIcon.bounds;
        //设置图形样子
        maskLayer.path = maskPath.CGPath;
        _headIcon.layer.mask = maskLayer;
        _headIcon.alpha = 0.0;
        [UIView transitionWithView:_headIcon
                          duration:1.0
                           options:UIViewAnimationOptionTransitionCrossDissolve
                        animations:^{
                            [_headIcon setImage:image];
                            _headIcon.alpha = 1.0;
                        } completion:NULL];
    }];

    // 封面Image
    [_imageVBig sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",playerModel.portrait]] placeholderImage:[UIImage imageNamed:@"直播大厅展位图"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        [_imageVBig.image circleImage:_imageVBig CGSize:CGSizeMake(15, 15)];
        _imageVBig.alpha = 0.0;
        [UIView transitionWithView:_imageVBig
                          duration:1.0
                           options:UIViewAnimationOptionTransitionCrossDissolve
                        animations:^{
                            [_imageVBig setImage:image];
                            _imageVBig.alpha = 1.0;
                        } completion:NULL];
    }];
    

    // 观看人数
    _audienceNum.text = [NSString stringWithFormat:@"%d",playerModel.online_users];
  
    //  xmppRoomJid
    _chatRoomAddr = playerModel.chatRoomJid;
    
    //  xmppUserJid
    _userid = playerModel.userid;

}



//-(void)headClick:(id)sender{
//    
//    if (self.delegate && [self.delegate respondsToSelector:@selector(userIconClick:)]) {
//        [self.delegate userIconClick:self.userid];
//    }
//}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
}

@end