Files
featherVoice/QXLive/Message(音信)/View/群聊设置/QXIMGroupSettingView.m
2026-01-04 14:01:30 +08:00

225 lines
9.9 KiB
Objective-C

//
// QXIMGroupSettingView.m
// QXLive
//
// Created by 启星 on 2026/1/2.
//
#import "QXIMGroupSettingView.h"
#import "QXTextView.h"
@interface QXIMGroupSettingView()<UICollectionViewDelegate,UICollectionViewDataSource>
@property (nonatomic,strong)UIImageView *guildImageView;
@property (nonatomic,strong)UILabel *guildLabel;
@property (nonatomic,strong)UILabel *groupMemberTitleLabel;
@property (nonatomic,strong)UIButton *moreMemberBtn;
@property (nonatomic,strong)UICollectionView *collectionView;
@property (nonatomic,strong)UIView *editGroupNameView;
@property (nonatomic,strong)UITextField *editGroupTextField;
@property (nonatomic,strong)UILabel *noticeTitleLabel;
@property (nonatomic,strong)QXTextView *textView;
@property (nonatomic,strong)UILabel *muteLabel;
@property (nonatomic,strong)UISwitch *muteSwitch;
@property (nonatomic,strong)NSMutableArray *dataArray;
@property (nonatomic,strong)UIButton *saveBtn;
@end
@implementation QXIMGroupSettingView
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self initSubviews];
}
return self;
}
-(void)initSubviews{
self.guildImageView = [[UIImageView alloc] initWithFrame:CGRectMake(16, 0, 60, 60)];
self.guildImageView.contentMode = UIViewContentModeScaleAspectFill;
[self.guildImageView addRoundedCornersWithRadius:30];
[self addSubview:self.guildImageView];
self.guildLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.guildImageView.right+10, self.guildLabel.top, self.width-self.guildImageView.right-10-16, self.guildImageView.height)];
self.guildLabel.textColor = [UIColor colorWithHexString:@"#333333"];
self.guildLabel.font = [UIFont systemFontOfSize:14];
[self addSubview:self.guildLabel];
self.groupMemberTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.guildImageView.left, self.guildImageView.bottom+15, 100, 20)];
self.groupMemberTitleLabel.textColor = RGB16(0x000000);
self.groupMemberTitleLabel.font = [UIFont boldSystemFontOfSize:16];
self.groupMemberTitleLabel.text = @"群组成员";
[self addSubview:self.groupMemberTitleLabel];
self.moreMemberBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.width-100-16, self.groupMemberTitleLabel.top, 100, 20)];
[self.moreMemberBtn setTitle:@"查看成员>" forState:(UIControlStateNormal)];
[self.moreMemberBtn setTitleColor:RGB16(0x333333) forState:(UIControlStateNormal)];
self.moreMemberBtn.titleLabel.font = [UIFont systemFontOfSize:14];
[self.moreMemberBtn addTarget:self action:@selector(moreAction:) forControlEvents:(UIControlEventTouchUpInside)];
[self addSubview:self.moreMemberBtn];
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
int itemWidth = 60;
layout.itemSize = CGSizeMake(itemWidth, itemWidth+20);
layout.minimumLineSpacing = 12;
layout.minimumInteritemSpacing = 12;
// layout.sectionInset = UIEdgeInsetsMake(0, 16, 0, 16);
layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(self.guildImageView.left, self.groupMemberTitleLabel.bottom+15, self.width-32, itemWidth+20) collectionViewLayout:layout];
[self.collectionView registerClass:[QXIMGroupMemberCell class] forCellWithReuseIdentifier:@"QXIMGroupMemberCell"];
self.collectionView.delegate = self;
self.collectionView.dataSource = self;
self.collectionView.showsHorizontalScrollIndicator = NO;
self.collectionView.bounces = NO;
self.collectionView.pagingEnabled = NO;
self.collectionView.backgroundColor = [UIColor clearColor];
[self addSubview:self.collectionView];
self.editGroupNameView = [[UIView alloc] initWithFrame:CGRectMake(16, self.collectionView.bottom+10, self.width-32, 44)];
self.editGroupNameView.backgroundColor = RGB(236, 240, 246);
[self.editGroupNameView addRoundedCornersWithRadius:8];
[self addSubview:self.editGroupNameView];
self.editGroupTextField = [[UITextField alloc] initWithFrame:CGRectMake(16, 0, self.editGroupNameView.width-32, 44)];
self.editGroupTextField.font = [UIFont systemFontOfSize:14];
self.editGroupTextField.textColor = RGB16(0x333333);
self.editGroupTextField.placeholder = @"请输入群聊名称";
[self.editGroupNameView addSubview:self.editGroupTextField];
self.noticeTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.guildImageView.left, self.editGroupNameView.bottom+10, self.width-32, 30)];
self.noticeTitleLabel.text = @"群聊公告";
self.noticeTitleLabel.font = [UIFont boldSystemFontOfSize:16];
self.noticeTitleLabel.textColor = RGB16(0x000000);
[self addSubview:self.noticeTitleLabel];
self.textView = [[QXTextView alloc] initWithFrame:CGRectMake(self.guildImageView.left, self.noticeTitleLabel.bottom+10, self.width-32, 120)];
self.textView.placehoulder = @"请输入群聊公告";
self.textView.placehoulderFont = [UIFont systemFontOfSize:14];
self.textView.font = [UIFont systemFontOfSize:14];
self.textView.backgroundColor = RGB(236, 240, 246);
[self.textView addRoundedCornersWithRadius:8];
self.textView.maxLength = 300;
[self addSubview:self.textView];
self.muteLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.guildImageView.left, self.textView.bottom+10, 200, 40)];
self.muteLabel.text = @"全员禁言";
self.muteLabel.textColor = RGB16(0x000000);
self.muteLabel.font = [UIFont boldSystemFontOfSize:16];
self.muteLabel.hidden = YES;
[self addSubview:self.muteLabel];
self.muteSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(self.width-60-16, self.muteLabel.top+5, 60, 40)];
[self.muteSwitch addTarget:self action:@selector(muteAction) forControlEvents:(UIControlEventValueChanged)];
self.muteSwitch.hidden = YES;
[self addSubview:self.muteSwitch];
self.saveBtn = [[UIButton alloc] initWithFrame:CGRectMake((self.width-300)/2, self.muteLabel.bottom+10, 300, 40)];
[self.saveBtn setTitle:@"确认保存" forState:(UIControlStateNormal)];
[self.saveBtn setTitleColor:RGB16(0xffffff) forState:(UIControlStateNormal)];
self.saveBtn.titleLabel.font = [UIFont systemFontOfSize:14];
[self.saveBtn addRoundedCornersWithRadius:20];
self.saveBtn.backgroundColor = QXConfig.themeColor;
[self.saveBtn addTarget:self action:@selector(saveAction) forControlEvents:(UIControlEventTouchUpInside)];
[self addSubview:self.saveBtn];
self.saveBtn.hidden = YES;
}
-(void)setModel:(QXGroupSettingInfoModel *)model{
_model = model;
[self.guildImageView sd_setImageWithURL:[NSURL URLWithString:model.guild_cover]];
self.guildLabel.text = model.name;
self.editGroupTextField.text = model.name;
self.textView.text = model.notification;
[self.muteSwitch setOn:model.mute_all_member.intValue==1];
[self.collectionView reloadData];
if (model.is_deacon.intValue == 2) {
self.muteSwitch.hidden = YES;
self.muteLabel.hidden = YES;
self.saveBtn.hidden = YES;
self.editGroupTextField.userInteractionEnabled = NO;
self.textView.userInteractionEnabled = NO;
}else{
self.muteSwitch.hidden = NO;
self.muteLabel.hidden = NO;
self.saveBtn.hidden = NO;
self.editGroupTextField.userInteractionEnabled = YES;
self.textView.userInteractionEnabled = YES;
}
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return self.model.user_list.count;
}
-(__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
QXIMGroupMemberCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"QXIMGroupMemberCell" forIndexPath:indexPath];
QXUserModel *model = self.model.user_list[indexPath.row];
cell.model = model;
return cell;
}
-(void)moreAction:(UIButton*)sender{
if (self.delegate && [self.delegate respondsToSelector:@selector(previewMemberList)]) {
[self.delegate previewMemberList];
}
}
-(void)saveAction{
if (self.delegate && [self.delegate respondsToSelector:@selector(saveGroupInfoWithGroupId:notice:name:)]) {
[self.delegate saveGroupInfoWithGroupId:self.model.guild_id notice:self.textView.text name:self.editGroupTextField.text];
}
}
-(void)muteAction{
if (self.muteSwitch.isOn) {
QXLOG(@"打开全局禁言");
}else{
QXLOG(@"关闭全局禁言");
}
if (self.delegate && [self.delegate respondsToSelector:@selector(groupSetMute:muteSwitch:)]) {
[self.delegate groupSetMute:self.muteSwitch.isOn muteSwitch:self.muteSwitch];
}
}
-(NSMutableArray *)dataArray{
if (!_dataArray) {
_dataArray = [NSMutableArray array];
}
return _dataArray;
}
@end
@implementation QXIMGroupMemberCell
-(instancetype)initWithFrame:(CGRect)frame{
if (self = [super initWithFrame:frame]) {
[self initSubviews];
}
return self;
}
-(void)setModel:(QXUserModel *)model{
_model = model;
[self.headerImageView sd_setImageWithURL:[NSURL URLWithString:model.avatar]];
self.nameLabel.text = model.nickname;
}
-(void)initSubviews{
self.headerImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.width, self.width)];
self.headerImageView.contentMode = UIViewContentModeScaleAspectFill;
self.headerImageView.image = [UIImage imageNamed:@"user_header_placehoulder"];
[self.headerImageView addRoundedCornersWithRadius:self.width/2];
[self.contentView addSubview:self.headerImageView];
self.nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, self.headerImageView.bottom, self.width, 20)];
self.nameLabel.textColor = RGB16(0x666666);
self.nameLabel.font = [UIFont systemFontOfSize:14];
self.nameLabel.textAlignment = NSTextAlignmentCenter;
self.nameLabel.text = @"夏末";
[self.contentView addSubview:self.nameLabel];
}
@end