123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450 |
- //
- // GroupSettingBodyView.m
- // KulexiuForTeacher
- //
- // Created by Kyle on 2022/3/24.
- //
- #import "GroupSettingBodyView.h"
- #import "GroupMemberModel.h"
- #import "GroupListModel.h"
- #import "GroupOwnerTagView.h"
- typedef void(^ChooseMemberCallback)(NSString *targetId);
- @interface MemberView : UIView
- @property (nonatomic, strong) UIImageView *memberLogo;
- @property (nonatomic, strong) UILabel *memberLabel;
- @property (nonatomic, strong) NSString *targetId;
- @property (nonatomic, strong) GroupOwnerTagView *tagView;
- @property (nonatomic, copy) ChooseMemberCallback callback;
- - (void)configMemberWithUrl:(NSString *)url name:(NSString *)name targetId:(NSString *)targetId isOwner:(BOOL)isOwner callback:(ChooseMemberCallback)callback;
- - (void)configMemberWithNativeImage:(NSString *)imageName name:(NSString *)name callback:(ChooseMemberCallback)callback;
- @end
- @implementation MemberView
- - (instancetype)initWithFrame:(CGRect)frame {
- self = [super initWithFrame:frame];
- if (self) {
- [self initView];
- }
- return self;
- }
- - (void)initView {
-
- self.memberLabel = [[UILabel alloc] init];
- self.memberLabel.textColor = HexRGB(0x777777);
- [self.memberLabel setFont:[UIFont systemFontOfSize:14.0f]];
- [self.memberLabel setTextAlignment:NSTextAlignmentCenter];
- [self addSubview:self.memberLabel];
- [self.memberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.width.mas_equalTo(45);
- make.centerX.mas_equalTo(self.mas_centerX);
- make.height.mas_equalTo(20);
- make.bottom.mas_equalTo(self.mas_bottom).offset(-19);
- }];
-
- self.memberLogo = [[UIImageView alloc] init];
- self.memberLogo.layer.cornerRadius = 22.5;
- self.memberLogo.layer.masksToBounds = YES;
- self.memberLogo.contentMode = UIViewContentModeScaleAspectFill;
-
- [self addSubview:self.memberLogo];
- [self.memberLogo mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.mas_equalTo(self.mas_centerX);
- make.width.height.mas_equalTo(45);
- make.bottom.mas_equalTo(self.memberLabel.mas_top).offset(-2);
- }];
- UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
- [self addGestureRecognizer:tapGesture];
-
- self.tagView = [GroupOwnerTagView shareInstance];
- [self addSubview:self.tagView];
- [self.tagView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.width.mas_equalTo(40);
- make.height.mas_equalTo(15);
- make.centerX.mas_equalTo(self.memberLogo.mas_centerX);
- make.bottom.mas_equalTo(self.memberLogo.mas_bottom).offset(2);
- }];
- self.tagView.hidden = YES;
-
- }
- - (void)tapAction:(UITapGestureRecognizer *)gesture {
- if (self.callback) {
- self.callback(self.targetId);
- }
- }
- - (void)configMemberWithUrl:(NSString *)url name:(NSString *)name targetId:(NSString *)targetId isOwner:(BOOL)isOwner callback:(ChooseMemberCallback)callback {
- if (callback) {
- self.callback = callback;
- }
- [self.memberLogo sd_setImageWithURL:[NSURL URLWithString:[url getUrlEndcodeString]] placeholderImage:[UIImage imageNamed:CHAT_USER_DEFAULT_LOGO]];
- self.memberLabel.text = [NSString returnNoNullStringWithString:name];
- self.targetId = targetId;
-
- if (isOwner) {
- self.tagView.hidden = NO;
- }
- else {
- self.tagView.hidden = YES;
- }
- }
- - (void)configMemberWithNativeImage:(NSString *)imageName name:(NSString *)name callback:(ChooseMemberCallback)callback {
- if (callback) {
- self.callback = callback;
- }
- [self.memberLogo setImage:[UIImage imageNamed:imageName]];
- self.memberLabel.text = name;
- }
- @end
- @interface GroupSettingBodyView ()
- @property (weak, nonatomic) IBOutlet UIImageView *groupImage;
- @property (weak, nonatomic) IBOutlet UILabel *groupName;
- @property (weak, nonatomic) IBOutlet UILabel *memberCount;
- @property (weak, nonatomic) IBOutlet UILabel *applyCount;
- @property (weak, nonatomic) IBOutlet UILabel *groupRemark;
- @property (weak, nonatomic) IBOutlet UIButton *switchButton;
- @property (weak, nonatomic) IBOutlet UIView *memberView;
- @property (weak, nonatomic) IBOutlet UILabel *groupMemberDesc;
- @property (weak, nonatomic) IBOutlet UIView *applyView;
- @property (weak, nonatomic) IBOutlet NSLayoutConstraint *applyViewHeight;
- @property (nonatomic, copy) GroupSettingBlock callback;
- @property (nonatomic, assign) BOOL canAddMember;
- @property (nonatomic, strong) UIScrollView *memberScrollView;
- @property (weak, nonatomic) IBOutlet UIView *fullbannedView;
- @property (weak, nonatomic) IBOutlet UIButton *muteButton;
- @property (weak, nonatomic) IBOutlet NSLayoutConstraint *fullBanHeight;
- @property (weak, nonatomic) IBOutlet UIView *banListView;
- @property (weak, nonatomic) IBOutlet NSLayoutConstraint *banListHeight;
- @property (weak, nonatomic) IBOutlet UILabel *groupDesc;
- @end
- @implementation GroupSettingBodyView
- - (void)awakeFromNib {
- [super awakeFromNib];
- self.isOn = NO;
- [self.memberView addSubview:self.memberScrollView];
- [self.memberScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.top.bottom.mas_equalTo(self.memberView);
- }];
- }
- + (instancetype)shareInstance {
- GroupSettingBodyView *view = [[[NSBundle mainBundle] loadNibNamed:@"GroupSettingBodyView" owner:nil options:nil] firstObject];
- return view;
- }
- - (void)configApplyViewDisplay:(BOOL)isDisplay {
- if (isDisplay) {
- self.applyView.hidden = NO;
- self.applyViewHeight.constant = 55.0f;
- self.canAddMember = NO;
- }
- else {
- self.applyView.hidden = YES;
- self.applyViewHeight.constant = 0.0f;
- self.canAddMember = YES;
- }
- }
- - (void)configWithSource:(id)source callback:(GroupSettingBlock)callback {
- if (callback) {
- self.callback = callback;
- }
-
- if ([source isKindOfClass:[GroupListModel class]]) {
- GroupListModel *model = source;
- NSString *defaultLogo = @"";
-
- if ([model.type isEqualToString:@"FAN"]) {
- defaultLogo = GROUP_FAN_LOGO;
- [self configApplyViewDisplay:YES];
- }
- else if ([model.type isEqualToString:@"ORG"]) {
- defaultLogo = GROUP_TENANT_LOGO;
- [self configApplyViewDisplay:NO];
- }
- else {
- defaultLogo = GROUP_COURSE_LOGO;
- [self configApplyViewDisplay:YES];
- }
-
- if ([NSString isEmptyString:model.img]) {
- [self.groupImage setImage:[UIImage imageNamed:defaultLogo]];
- }
- else {
- [self.groupImage sd_setImageWithURL:[NSURL URLWithString:[model.img getUrlEndcodeString]] placeholderImage:[UIImage imageNamed:defaultLogo]];
- }
-
- self.groupName.text = [NSString returnNoNullStringWithString:model.name];
- self.groupRemark.text = [NSString returnNoNullStringWithString:model.name];
- NSInteger groupLimit = model.groupMemberLimit;
- if (model.groupMemberLimit <= 0) {
- groupLimit = 2000;
- }
- self.groupMemberDesc.text = [NSString stringWithFormat:@"%.0f/%zd",model.memberNum,groupLimit];
-
- if ([NSString isEmptyString:model.introduce]) {
- self.groupDesc.text = @"暂无群简介";
- }
- else {
- self.groupDesc.text = model.introduce;
- }
- }
- }
- - (void)setApplyMember:(NSInteger)applyMember {
- _applyMember = applyMember;
- self.applyCount.text = [NSString stringWithFormat:@"%ld人",applyMember];
- }
- - (void)evaluateStudentArray:(NSArray *)studentArray {
- if (studentArray.count == 0) {
- self.memberCount.text = @"查看全部群成员";
- }
- else {
- self.memberCount.text = [NSString stringWithFormat:@"查看全部%zd名群成员", studentArray.count];
- }
- [self removeAllSubviews:self.memberScrollView];
- NSInteger maxCount = IS_IPAD ? 9 : 5;
- CGFloat width = KPortraitWidth / maxCount;
- NSInteger maxDisplay = maxCount;
-
- NSInteger count = 0;
- if (self.canAddMember) {
- maxDisplay = maxCount - 1;
- }
- if (studentArray.count < maxDisplay) {
- count = studentArray.count;
- }
- else {
- count = maxDisplay;
- }
- for (NSInteger i = 0; i < count; i++) {
- CGRect frame = CGRectMake(width * i, 0, width, 100);
- GroupMemberModel *model = [studentArray objectAtIndex:i];
- MemberView *view = [[MemberView alloc] initWithFrame:frame];
- [view configMemberWithUrl:model.avatar name:model.nickname targetId:model.imUserId isOwner:model.isAdmin callback:^(NSString *targetId) {
-
- }];
- [self.memberScrollView addSubview:view];
- [view mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.bottom.mas_equalTo(self.memberScrollView);
- make.left.mas_equalTo(self.memberScrollView.mas_left).offset(width * i);
- make.width.mas_equalTo(width);
- make.height.mas_equalTo(100);
- if (i == count -1 && self.canAddMember == NO) {
- make.right.mas_equalTo(self.memberScrollView.mas_right);
- }
- }];
- }
-
- // 添加按钮
- if (self.canAddMember) {
- CGRect frame = CGRectMake(width * count, 0, width, 100);
- MemberView *view = [[MemberView alloc] initWithFrame:frame];
- MJWeakSelf;
- [view configMemberWithNativeImage:@"group_memberAdd" name:@"添加" callback:^(NSString *targetId) {
- [weakSelf addMember];
- }];
- [self.memberScrollView addSubview:view];
-
- [view mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.bottom.mas_equalTo(self.memberScrollView);
- make.left.mas_equalTo(self.memberScrollView.mas_left).offset(width * count);
- make.width.mas_equalTo(width);
- make.height.mas_equalTo(100);
- make.right.mas_equalTo(self.memberScrollView.mas_right);
- }];
- }
-
- }
- - (void)removeAllSubviews:(UIView *)view {
- while (view.subviews.count) {
- [view.subviews.lastObject removeFromSuperview];
- }
- }
- - (void)addMember {
- if (self.callback) {
- self.callback(GROUPSETTING_ADDMENBER);
- }
- }
- // 群联系人
- - (IBAction)contractPerson:(id)sender {
- if (self.callback) {
- self.callback(GROUPSETTING_PERSON);
- }
- }
- // 群申请列表
- - (IBAction)groupApply:(id)sender {
- if (self.callback) {
- self.callback(GROUPSETTING_APPLY);
- }
- }
- // 修改群名称
- - (IBAction)modifyGroupName:(id)sender {
- if (self.callback) {
- self.callback(GROUPSETTING_GROUP);
- }
- }
- // 查找聊天内容
- - (IBAction)messageSearch:(id)sender {
- if (self.callback) {
- self.callback(GROUPSETTING_MESSAGESEARCH);
- }
- }
- // 群通知设置
- - (IBAction)notiferAction:(id)sender {
- self.isOn = !self.isOn;
- if (self.callback) {
- self.callback(GROUPSETTING_SETTING);
- }
- }
- // 群简介
- - (IBAction)groupIntroduce:(id)sender {
- if (self.callback) {
- self.callback(GROUPSETTING_GROUPINTRODUCE);
- }
- }
- // 群公告
- - (IBAction)groupNotice:(id)sender {
- if (self.callback) {
- self.callback(GROUPSETTING_NOTICE);
- }
- }
- // 投诉
- - (IBAction)feedBack:(id)sender {
- if (self.callback) {
- self.callback(GROUPSETTING_FEEDBACK);
- }
- }
- // 解散群聊
- - (IBAction)dismissGroup:(id)sender {
- if (self.callback) {
- self.callback(GROUPSETTING_DISMISS);
- }
- }
- - (IBAction)muteAction:(id)sender {
- self.isMute = !self.isMute;
- if (self.callback) {
- self.callback(GROUPSETTING_MUTE);
- }
- }
- - (IBAction)displayBanList:(id)sender {
- if (self.callback) {
- self.callback(GROUPSETTING_BANLIST);
- }
- }
- - (UIScrollView *)memberScrollView {
- if (!_memberScrollView) {
- _memberScrollView = [[UIScrollView alloc] init];
- }
- return _memberScrollView;
- }
- - (void)setIsOn:(BOOL)isOn {
- _isOn = isOn;
- NSString *imageName = isOn ? @"switch_on" : @"switch_off";
- [self.switchButton setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
- }
- - (void)setIsMute:(BOOL)isMute {
- _isMute = isMute;
- NSString *imageName = isMute ? @"switch_on" : @"switch_off";
- [self.muteButton setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
- }
- /***
- Owner("群主"),
- Admin("管理员"),
- Member("群成员"),
- */
- - (BOOL)hasManageGroupLimit {
- if ([self.groupRoleType isEqualToString:@"Owner"] || [self.groupRoleType isEqualToString:@"Admin"]) {
- return YES;
- }
- return NO;
- }
- - (void)setGroupRoleType:(NSString *)groupRoleType {
- _groupRoleType = groupRoleType;
-
- if ([groupRoleType isEqualToString:@"Owner"]) {
- self.fullbannedView.hidden = NO;
- self.fullBanHeight.constant = 55.0f;
- self.banListView.hidden = NO;
- self.banListHeight.constant = 55.0f;
- }
- else if ([groupRoleType isEqualToString:@"Admin"]) {
- self.fullbannedView.hidden = NO;
- self.fullBanHeight.constant = 55.0f;
- self.banListView.hidden = NO;
- self.banListHeight.constant = 55.0f;
-
- }
- else {
- self.fullbannedView.hidden = YES;
- self.fullBanHeight.constant = 0.0f;
- self.banListView.hidden = YES;
- self.banListHeight.constant = 0.0f;
- }
- }
- - (CGFloat)getViewHeight:(NSString *)roleType {
- CGFloat bottomSpace = IS_iPhoneX ? iPhoneXSafeBottomMargin : 20;
- if ([self.groupRoleType isEqualToString:@"Owner"] || [self.groupRoleType isEqualToString:@"Admin"]) {
- return 857 + bottomSpace;
- }
- else {
- return 747 + bottomSpace;
- }
- }
- /*
- // Only override drawRect: if you perform custom drawing.
- // An empty implementation adversely affects performance during animation.
- - (void)drawRect:(CGRect)rect {
- // Drawing code
- }
- */
- @end
|