Files
yinmeng-ios/xplan-ios/Main/Message/View/Session/SessionNavView.m
2023-08-25 14:48:58 +08:00

282 lines
9.2 KiB
Objective-C

//
// SessionNavView.m
// xplan-ios
//
// Created by 冯硕 on 2022/4/25.
//
#import "SessionNavView.h"
///Third
#import <SVGA.h>
#import <Masonry/Masonry.h>
#import <NIMSDK/NIMSDK.h>
///Tool
#import "ThemeColor.h"
#import "XPMacro.h"
#import "XPConstant.h"
#import "ClientConfig.h"
@interface SessionNavView ()
///返回按钮
@property (nonatomic,strong) UIButton *backButton;
///用户信息的容器
@property (nonatomic,strong) UIStackView *infoStackView;
///标题
@property (nonatomic,strong) UILabel *nickLabel;
///是否关注
@property (nonatomic,strong) UIButton *likeButton;
///加入黑名单
@property (nonatomic,strong) UILabel *subTitleLabel;
///举报
@property (nonatomic,strong) UIButton *reportButton;
///直播中
@property (nonatomic, strong) SVGAPlayer *livingView;
@property(nonatomic,strong) UILabel *livingTitleView;
@property(nonatomic,strong) UIButton *livingBtn;
@end
@implementation SessionNavView
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
[self initSubViews];
[self initSubViewConstraints];
SVGAParser *parser = [[SVGAParser alloc] init];
[parser parseWithNamed:@"home_living" inBundle:nil completionBlock:^(SVGAVideoEntity * _Nonnull videoItem) {
if (videoItem != nil) {
self.livingView.videoItem = videoItem;
[self.livingView startAnimation];
}
} failureBlock:nil];
}
return self;
}
#pragma mark - Private Method
- (void)initSubViews {
self.backgroundColor = [ThemeColor appCellBackgroundColor];
[self addSubview:self.backButton];
[self addSubview:self.infoStackView];
[self addSubview:self.reportButton];
[self addSubview:self.likeButton];
[self addSubview:self.nickLabel];
[self.infoStackView addArrangedSubview:self.livingView];
[self.infoStackView addArrangedSubview:self.livingTitleView];
[self.infoStackView addArrangedSubview:self.subTitleLabel];
[self addSubview:self.livingBtn];
}
- (void)initSubViewConstraints {
[self.backButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(22, 22));
make.left.mas_equalTo(self).offset(8);
make.top.mas_equalTo(statusbarHeight + 14);
}];
[self.nickLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self);
make.top.mas_equalTo(statusbarHeight + 4);
make.height.mas_equalTo(22);
}];
[self.infoStackView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self);
make.top.equalTo(self.nickLabel.mas_bottom).mas_offset(3);
}];
[self.reportButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(30, 30 ));
make.right.mas_equalTo(self).offset(-15);
make.centerY.mas_equalTo(self.backButton);
}];
[self.likeButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(48);
make.height.mas_equalTo(21);
make.centerY.equalTo(self.reportButton);
make.right.equalTo(self.reportButton.mas_left).mas_offset(-14);
}];
[self.livingView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(13);
make.height.mas_equalTo(9);
}];
[self.livingBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.top.bottom.equalTo(self.infoStackView);
make.width.mas_equalTo(57);
}];
}
- (BOOL)isSystemAccount {
return [[ClientConfig shareConfig].configInfo.officialMsgUids containsObject:_userId] || [[ClientConfig shareConfig].configInfo.officialAccountUids containsObject:_userId] || [KeyWithType(KeyType_SecretaryUidKey) isEqualToString:self.userId] || [KeyWithType(KeyType_SystemNotifiUidKey) isEqualToString:self.userId] || [KeyWithType(KeyType_GuildUidKey) isEqualToString:self.userId];
}
#pragma mark - Event Response
- (void)reportButtonAction:(UIButton *)sender {
if (self.delegate && [self.delegate respondsToSelector:@selector(sessionNavView:didClickReport:)]) {
[self.delegate sessionNavView:self didClickReport:sender];
}
}
- (void)backButtonAction:(UIButton *)sender {
if (self.delegate && [self.delegate respondsToSelector:@selector(sessionNavView:didClickBack:)]) {
[self.delegate sessionNavView:self didClickBack:sender];
}
}
- (void)likeButtonAction:(UIButton *)sender {
if (self.delegate && [self.delegate respondsToSelector:@selector(sessionNavView:didClickLike:)]) {
[self.delegate sessionNavView:self didClickLike:sender];
}
}
#pragma mark - Getters And Setters
- (void)setUserId:(NSString *)userId {
_userId = userId;
if (_userId.length > 0) {
[[NIMSDK sharedSDK].userManager fetchUserInfos:@[self.userId] completion:^(NSArray<NIMUser *> * _Nullable users, NSError * _Nullable error) {
if (!error) {
self.title = users[0].userInfo.nickName;
}
}];
self.subTitleLabel.hidden = ![[NIMSDK sharedSDK].userManager isUserInBlackList:self.userId];
self.reportButton.hidden = [self isSystemAccount] || self.isInRoom;
}
}
-(void)livingBtnAction{
if(self.delegate && [self.delegate respondsToSelector:@selector(sessionNavView:didClickToRoom:)]){
[self.delegate sessionNavView:self didClickToRoom:self.livingBtn];
}
}
- (void)setTitle:(NSString *)title {
_title = title;
if (_title) {
NSString * nick = title;
if (nick.length > 10 ) {
nick = [nick substringToIndex:10];
}
self.nickLabel.text = nick;
}
}
- (void)setIsLike:(BOOL)isLike {
_isLike = isLike;
self.likeButton.hidden = _isLike;
}
- (void)setIsInRoom:(BOOL)isInRoom {
_isInRoom = isInRoom;
self.reportButton.hidden = _isInRoom;
if (_isInRoom) {
[self.backButton mas_updateConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self).offset(11);
}];
}
}
-(void)setIsShowLive:(BOOL)isShowLive{
_isShowLive = isShowLive;
if(_isShowLive){
self.livingView.hidden = NO;
self.livingBtn.hidden = NO;
self.livingTitleView.hidden = NO;
}
}
- (UIButton *)backButton {
if (!_backButton) {
_backButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_backButton setImage:[UIImage imageNamed:@"common_nav_back"] forState:UIControlStateNormal];
[_backButton setImage:[UIImage imageNamed:@"common_nav_back"] forState:UIControlStateSelected];
[_backButton addTarget:self action:@selector(backButtonAction:) forControlEvents:UIControlEventTouchUpInside];
[_backButton setEnlargeEdgeWithTop:10 right:10 bottom:10 left:10];
}
return _backButton;
}
- (UIStackView *)infoStackView {
if (!_infoStackView) {
_infoStackView = [[UIStackView alloc] init];
_infoStackView.axis = UILayoutConstraintAxisHorizontal;
_infoStackView.distribution = UIStackViewDistributionFill;
_infoStackView.alignment = UIStackViewAlignmentFill;
_infoStackView.spacing = 4;
}
return _infoStackView;
}
- (UILabel *)nickLabel {
if (!_nickLabel) {
_nickLabel = [[UILabel alloc] init];
_nickLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
_nickLabel.textColor = [ThemeColor mainTextColor];
_nickLabel.textAlignment = NSTextAlignmentCenter;
}
return _nickLabel;
}
- (UIButton *)likeButton {
if (!_likeButton) {
_likeButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_likeButton setTitle:@"关注" forState:UIControlStateNormal];
_likeButton.titleLabel.font = [UIFont systemFontOfSize:12 weight:UIFontWeightMedium];
_likeButton.layer.cornerRadius = 21/2;
_likeButton.layer.masksToBounds = YES;
[_likeButton setTitleColor:UIColorFromRGB(0xFFDA24) forState:UIControlStateNormal];
_likeButton.layer.borderWidth = 0.5;
_likeButton.layer.borderColor = UIColorFromRGB(0xFFDA24).CGColor;
[_likeButton addTarget:self action:@selector(likeButtonAction:) forControlEvents:UIControlEventTouchUpInside];
_likeButton.hidden = NO;
}
return _likeButton;
}
- (UILabel *)subTitleLabel {
if (!_subTitleLabel) {
_subTitleLabel = [[UILabel alloc] init];
_subTitleLabel.font = [UIFont systemFontOfSize:11];
_subTitleLabel.textColor = [ThemeColor secondTextColor];
_subTitleLabel.text = @"已经加入黑名单";
_subTitleLabel.hidden = YES;
_subTitleLabel.textAlignment = NSTextAlignmentCenter;
}
return _subTitleLabel;
}
- (UIButton *)reportButton {
if (!_reportButton) {
_reportButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_reportButton setImage:[UIImage imageNamed:@"message_session_nav_report"] forState:UIControlStateNormal];
[_reportButton setImage:[UIImage imageNamed:@"message_session_nav_report"] forState:UIControlStateSelected];
[_reportButton addTarget:self action:@selector(reportButtonAction:) forControlEvents:UIControlEventTouchUpInside];
}
return _reportButton;
}
- (SVGAPlayer *)livingView {
if (!_livingView) {
_livingView = [[SVGAPlayer alloc] init];
_livingView.hidden = YES;
}
return _livingView;
}
- (UILabel *)livingTitleView{
if(!_livingTitleView){
_livingTitleView = [UILabel labelInitWithText:@"直播中 >" font:[UIFont systemFontOfSize:10 weight:UIFontWeightRegular] textColor:UIColorFromRGB(0xA2A7B8)];
_livingTitleView.hidden = YES;
}
return _livingTitleView;
}
-(UIButton *)livingBtn{
if(!_livingBtn){
_livingBtn = [UIButton new];
[_livingBtn addTarget:self action:@selector(livingBtnAction) forControlEvents:UIControlEventTouchUpInside];
}
return _livingBtn;
}
@end