CNTopImageView.m 11.3 KB
//
//  CNTopImageView.m
//  AFNetworking
//
//  Created by CNLive on 2022/1/17.
//

#import "CNTopImageView.h"
#import <DSBaseModule/DSBaseModule.h>
#import "CNMinePersonInfoController.h"

// 我的公会信息中公会成员类型
#ifndef CNLiveUnionUserStatusWithSourceForKey
#define CNLiveUnionUserStatusWithSourceForKey @"CNLiveUnionUserStatusWithSourceForKey"
#endif

@interface CNTopImageView()
@property (nonatomic, strong) UILabel *titleLabel;//用户名
@property (nonatomic, strong) UIButton *unionBtn;//我的工会
@property (nonatomic, strong) UIButton *homelandBtn;//我的家园
@property (nonatomic, strong) UIButton *myCommuintyBtn;//我的社区
@property (nonatomic, strong) UIButton *myImage;
@property (nonatomic, strong) CNListCollectionView *mineListView;//我的视频、我的收藏、生活圈、付费记录
@end

@implementation CNTopImageView
- (instancetype)init
{
    if (self = [super init]) {
        [self addSubview:self.codesView];
        [self addSubview:self.iconImage];
        [self addSubview:self.titleLabel];
        if (![CNLiveEnvironmentManager manager].isNewHomePage) {
            [self addSubview:self.homelandBtn];
            NSString *userStatus = [[NSUserDefaults standardUserDefaults] valueForKey:CNLiveUnionUserStatusWithSourceForKey];
            if ([userStatus isNotBlank] && ([userStatus isEqualToString:@"3"]||[userStatus isEqualToString:@"2"])) {
                [self addSubview:self.unionBtn];
            }
            [self addSubview:self.myCommuintyBtn];
        }else{
            [self addSubview:self.backBtn];
            [self addSubview:self.myImage];
        }
        [self addSubview:self.mineListView];
        [self uploadViewLayout];
        weakself
        [CNMinePresent requestCommunitySucceed:^(BOOL isCommunity) {
            weakSelf.myCommuintyBtn.hidden = !isCommunity;
        }];
    }
    return self;
}
- (void)uploadViewLayout
{
    [self.iconImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(kStatusHeight+DS_adapt_length(35));
        make.left.equalTo(self).offset(DS_adapt_length(12));
        make.width.height.mas_equalTo(DS_adapt_length(60));
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(DS_adapt_length(82.5));
        make.right.equalTo(self).offset(-10);
        make.top.mas_equalTo(kStatusHeight+DS_adapt_length(39));
    }];
    if ([CNLiveEnvironmentManager manager].isNewHomePage) {
        [self.codesView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self).offset(kStatusHeight);
            make.right.equalTo(self).offset(-DS_adapt_length(10) );
            make.height.mas_equalTo(DS_adapt_length(35));
            make.width.mas_equalTo(DS_adapt_length(70));
        }];
        [self.backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(DS_adapt_length(16));
            make.centerY.equalTo(self.codesView);
            make.width.mas_equalTo(DS_adapt_length(11));
            make.height.mas_equalTo(DS_adapt_length(18));
        }];
        [self.mineListView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.myImage.mas_bottom).offset(DS_adapt_length(15));
            make.left.equalTo(self).offset(DS_adapt_length(10));
            make.right.equalTo(self).offset(-DS_adapt_length(10));
            make.height.mas_equalTo(DS_adapt_length(70));
        }];
        [self.myImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.titleLabel);
            make.top.mas_equalTo(kStatusHeight+DS_adapt_length( 35+30));
            make.height.mas_equalTo(DS_adapt_length(26));
            make.width.mas_equalTo(DS_adapt_length(86.5));
        }];
    }else{
        [self.codesView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self).offset(kStatusHeight);
            make.right.equalTo(self).offset(-DS_adapt_length(10) );
            make.height.mas_equalTo(DS_adapt_length(35));
            make.width.mas_equalTo(DS_adapt_length(105));
        }];
        [self.homelandBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.titleLabel);
            make.top.mas_equalTo(kStatusHeight+DS_adapt_length( 35+30));
            make.height.mas_equalTo(DS_adapt_length(26));
            make.width.mas_equalTo(DS_adapt_length(86.5));
        }];
        NSString *userStatus = [[NSUserDefaults standardUserDefaults] valueForKey:CNLiveUnionUserStatusWithSourceForKey];
        if ([userStatus isNotBlank] && ([userStatus isEqualToString:@"3"]||[userStatus isEqualToString:@"2"])) {
            [self.unionBtn mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(self.homelandBtn.mas_right).offset(10);
                make.top.equalTo(self.homelandBtn);
                make.height.mas_equalTo(DS_adapt_length(26));
                make.width.mas_equalTo(DS_adapt_length(86.5));
            }];
            [self.myCommuintyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(self.unionBtn.mas_right).offset(10);
                make.top.equalTo(self.homelandBtn);
                make.height.mas_equalTo(DS_adapt_length(26));
                make.width.mas_equalTo(DS_adapt_length(86.5));
            }];
        }else{
            [self.myCommuintyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(self.homelandBtn.mas_right).offset(10);
                make.top.equalTo(self.homelandBtn);
                make.height.mas_equalTo(DS_adapt_length(26));
                make.width.mas_equalTo(DS_adapt_length(86.5));
            }];
        }
        [self.mineListView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.homelandBtn.mas_bottom).offset(DS_adapt_length(15));
            make.left.equalTo(self).offset(DS_adapt_length(10));
            make.right.equalTo(self).offset(-DS_adapt_length(10));
            make.height.mas_equalTo(DS_adapt_length(70));
        }];
    }
  
  
}
- (void)uploadViews
{
    _titleLabel.font = UIFontCNMake(17);
    [self.iconImage sd_setImageWithURL:[NSURL URLWithString:CNUserShareModel.faceUrl] placeholderImage:[UIImage imageNamed:@"mine_no_Avatar"]];
    if (![NSString isEmpty:CNUserShareModel.nickname]) {
        [self.titleLabel setText:CNUserShareModel.nickname];
    } else {
        self.titleLabel.text = @"昵称";
    }
}
#pragma mark - Action
- (void)buttonAction:(UIButton *)sender{
    switch (sender.tag - 1001) {
        case 0:
        {
            [[CNLiveCMineService shareMineProtocol] pushCMineContentForCMainPlatWithType:18 param:@{} contentVC:[self displayViewController]];
        }
            break;
        case 1:
        {
            [[CNLiveCMineService shareMineProtocol] pushCMineContentForCMainPlatWithType:19 param:@{} contentVC:[self displayViewController]];
        }
            break;
        case 2:
        {
            [[CNLiveCMineService shareMineProtocol] pushCMineContentForCMainPlatWithType:20 param:@{} contentVC:[self displayViewController]];
        } 
            break;
        case 3:{
            [[BaseAppDelegate sharedAppDelegate] popViewController];
        }
            break;
        case 4:{
            [[CNLiveCMineService shareMineProtocol] pushCMineContentForCMainPlatWithType:27 param:@{} contentVC:[self displayViewController]];
            break;
        }
        default:
            break;
    };
}
#pragma mark - Setting&&getting

- (UIImageView *)iconImage
{
    if (!_iconImage) {
        _iconImage = [[UIImageView alloc] init];
        _iconImage.layer.cornerRadius = DS_adapt_length(30);
        _iconImage.contentMode = UIViewContentModeScaleAspectFill;
        [_iconImage sd_setImageWithURL:[NSURL URLWithString:CNUserShareModel.faceUrl] placeholderImage:[UIImage imageNamed:@"mine_no_Avatar"]];
        _iconImage.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithActionBlock:^(id  _Nonnull sender) {
            CNMinePersonInfoController *infoVC = [[CNMinePersonInfoController alloc] init];
            [[BaseAppDelegate sharedAppDelegate] pushViewController:infoVC withBackTitle:@" "];
            
        }];
        [_iconImage addGestureRecognizer:tap];
    }
    return _iconImage;
}
- (CNListCollectionView *)codesView
{
    if (!_codesView) {
        _codesView = [[CNListCollectionView alloc] init];
        _codesView.backgroundColor = kClearColor;
        _codesView.model = [CNMinePresent dataSourceCodesModel:@"0"];
    }
    return _codesView;
}
- (UIButton *)backBtn
{
    if (!_backBtn) {
        _backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _backBtn.tag = 1004;
        [_backBtn setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
        [_backBtn addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _backBtn;
}
- (UIButton *)homelandBtn
{
    if (!_homelandBtn) {
        _homelandBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _homelandBtn.tag = 1001;
        [_homelandBtn setBackgroundImage:[UIImage imageNamed:@"mine_my_home"] forState:UIControlStateNormal];
        [_homelandBtn addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _homelandBtn;
}
- (UIButton *)unionBtn
{
    if (!_unionBtn) {
        _unionBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _unionBtn.tag = 1002;
        [_unionBtn setBackgroundImage:[UIImage imageNamed:@"mine_my_union"] forState:UIControlStateNormal];
        [_unionBtn addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _unionBtn;
}
- (UIButton *)myCommuintyBtn
{
    if (!_myCommuintyBtn) {
        _myCommuintyBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _myCommuintyBtn.exclusiveTouch = YES;
        _myCommuintyBtn.tag = 1003;
        [_myCommuintyBtn setBackgroundImage:[UIImage imageNamed:@"mine_my_community"] forState:UIControlStateNormal];
        [_myCommuintyBtn addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _myCommuintyBtn;
}
- (UIButton *)myImage
{
    if (!_myImage) {
        _myImage = [UIButton buttonWithType:UIButtonTypeCustom];
        _myImage.exclusiveTouch = YES;
        _myImage.tag = 1005;
        [_myImage setBackgroundImage:[UIImage imageNamed:@"mine_image"] forState:UIControlStateNormal];
        [_myImage addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _myImage;
}
- (UILabel *)titleLabel{
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.textColor = kWhiteColor;
        _titleLabel.textAlignment = NSTextAlignmentLeft;
        _titleLabel.font = UIFontCNMake(17);
        if (![NSString isEmpty:CNUserShareModel.nickname]) {
            [_titleLabel setText:CNUserShareModel.nickname];
        } else {
            _titleLabel.text = @"昵称";
        }
    }
    return _titleLabel;
}
- (CNListCollectionView *)mineListView{
    if (!_mineListView) {
        _mineListView = [[CNListCollectionView alloc] initWithFrame:CGRectZero];
        _mineListView.backgroundColor = kClearColor;
        _mineListView.model = [CNMinePresent dataSourceMineModel];
    }
    return _mineListView;
}
@end