CNLiveGroupQrCodeView.m 5.38 KB
//
//  CNLiveGroupQrCodeView.m
//  CNLiveQrCodeModule
//
//  Created by 153993236@qq.com on 11/12/2019.
//  Copyright © 2019 153993236@qq.com. All rights reserved.
//

#import "CNLiveGroupQrCodeView.h"
#import <Masonry/Masonry.h>
#import <SDWebImage/SDWebImage.h>
#import "QMUIKit.h"
#import "SGQRCode.h"//二维码库

#import "CNUserInfoManager.h"
#import "CNLiveCategory.h"

// IM
#import "TIMAdapter.h"
#import "CommonLibrary.h"

@interface CNLiveGroupQrCodeView()
@property (nonatomic, strong) UIImageView *groupHead;
@property (nonatomic, strong) UILabel *groupName;
@property (nonatomic, strong) UIImageView *qrcode;
@property (nonatomic, strong) UILabel *desc;

@end
@implementation CNLiveGroupQrCodeView
static const NSInteger margin = 15;

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor whiteColor];
        [self createUI];
    }
    return self;
}

#pragma mark - UI
- (void)createUI{
    [self addSubview:self.groupHead];
    [self.groupHead mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self).mas_offset(margin);
        make.top.mas_equalTo(self).mas_offset(margin);
        make.width.mas_equalTo(36);
        make.height.mas_equalTo(36);
    }];
    
    [self addSubview:self.groupName];
    [self.groupName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.groupHead.mas_right).mas_offset(margin);
        make.right.mas_equalTo(self.mas_right).mas_offset(-margin);
        make.top.mas_equalTo(self.groupHead.mas_top);
        make.height.mas_equalTo(self.groupHead.mas_height);

    }];
    
    [self addSubview:self.qrcode];
    [self.qrcode mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.mas_centerX);
        make.top.mas_equalTo(self.groupName.mas_bottom).mas_offset(margin);
        make.width.mas_equalTo(220.0);
        make.height.mas_equalTo(220.0);
    }];
    
    [self addSubview:self.desc];
    [self.desc mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.mas_left).mas_offset(margin);
        make.right.mas_equalTo(self.mas_right).mas_offset(-margin);
        make.top.mas_equalTo(self.qrcode.mas_bottom).mas_offset(0);
        make.bottom.mas_equalTo(self.mas_bottom).mas_offset(-0);

   }];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

#pragma mark - Setter
- (void)setGroup:(IMAGroup *)group{
    _group = group;
    if(group.avatorIcon){
        _groupHead.image = group.avatorIcon;
    }else{
//        [_groupHead setImageWithGroupId:group.groupInfo.groupId];

    }
    _groupName.text = group.groupInfo.groupName;

//    [QMUITips showLoadingInView:self];
//    [[CNGroupActiveViewModel sharedCNGroupActiveViewModel] requestServerForDownloadAppActionUrlSourceCompleterBlock:^(NSString *shareUrl) {
//        [QMUITips hideAllTipsInView:self];
//        NSString *wjjQr = [EncryptAndDecrypt base64StringFromText:[@{@"content":[@{@"groupId":CNLiveStringIsEmpty(group.groupInfo.groupId)?@"":group.groupInfo.groupId,@"groupName":group.groupInfo.groupName} mj_JSONString],@"type":@"groupQrType"} mj_JSONString] encryptKey:@"cnliveIm"];
//        NSString *qrCode = [NSString stringWithFormat:@"%@wjjQrSkipType=wjjQrPublicGroupType&isWjjQr=%@",shareUrl,wjjQr];
//        self.qrcode.image = [SGQRCodeGenerateManager generateWithLogoQRCodeData:qrCode logoImageName:nil logoScaleToSuperView:0.2];
//
//        UIImage *xw_image = [self getImageWithImageName:@"qr_code_icon" bundleName:@"CNLiveQrCodeModule" targetClass:[self class]];
//        [strongSelf.qrCode sd_setImageWithURL:nil placeholderImage:[SGQRCodeObtain generateQRCodeWithData:jsonStr size:SCREEN_WIDTH-12*margin logoImage:xw_image ratio:0.2]];
//
//    }];
}

#pragma mark - Getter
- (UIImageView *)groupHead {
    if (!_groupHead) {
        _groupHead = [[UIImageView alloc] init];
        _groupHead.backgroundColor = [UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1.0];
        UIImage *xw_image = [self getImageWithImageName:@"default_avatar_f" bundleName:@"CNLiveQrCodeModule" targetClass:[self class]];
        [_groupHead sd_setImageWithURL:[NSURL URLWithString:CNUserShareModel.faceUrl] placeholderImage:xw_image];

    }
    return _groupHead;
}

- (UILabel *)groupName {
    if (!_groupName) {
        _groupName = [[UILabel alloc] init];
        _groupName.textColor = [UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1.0];
        _groupName.font = UIFontMake(15);
        _groupName.numberOfLines = 1;
        _groupName.text = @"张晓文";
    }
    return _groupName;
}

- (UIImageView *)qrcode {
    if (!_qrcode) {
        _qrcode = [[UIImageView alloc] init];
        _qrcode.backgroundColor = [UIColor greenColor];
        _qrcode.image = [SGQRCodeObtain generateQRCodeWithData:@"群组id" size:220.0 logoImage:nil ratio:0.2];
    }
    return _qrcode;
}

- (UILabel *)desc {
    if (!_desc) {
        _desc = [[UILabel alloc] init];
        _desc.textColor = [UIColor colorWithRed:153/255.0 green:153/255.0 blue:153/255.0 alpha:1.0];
        _desc.font = UIFontMake(15);
        _desc.numberOfLines = 1;
        _desc.text = @"用“网家家”扫描二维码,加入该群";
        _desc.textAlignment = NSTextAlignmentCenter;
    }
    return _desc;
}

@end