GroupSettingBodyView.m 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. //
  2. // GroupSettingBodyView.m
  3. // KulexiuForTeacher
  4. //
  5. // Created by Kyle on 2022/3/24.
  6. //
  7. #import "GroupSettingBodyView.h"
  8. #import "GroupMemberModel.h"
  9. #import "GroupListModel.h"
  10. #import "GroupOwnerTagView.h"
  11. typedef void(^ChooseMemberCallback)(NSString *targetId);
  12. @interface MemberView : UIView
  13. @property (nonatomic, strong) UIImageView *memberLogo;
  14. @property (nonatomic, strong) UILabel *memberLabel;
  15. @property (nonatomic, strong) NSString *targetId;
  16. @property (nonatomic, copy) ChooseMemberCallback callback;
  17. @property (nonatomic, strong) GroupOwnerTagView *tagView;
  18. - (void)configMemberWithUrl:(NSString *)url name:(NSString *)name targetId:(NSString *)targetId isOwner:(BOOL)isOwner callback:(ChooseMemberCallback)callback;
  19. @end
  20. @implementation MemberView
  21. - (instancetype)initWithFrame:(CGRect)frame {
  22. self = [super initWithFrame:frame];
  23. if (self) {
  24. [self initView];
  25. }
  26. return self;
  27. }
  28. - (void)initView {
  29. self.memberLabel = [[UILabel alloc] init];
  30. self.memberLabel.textColor = HexRGB(0x777777);
  31. [self.memberLabel setFont:[UIFont systemFontOfSize:13.0f]];
  32. [self.memberLabel setTextAlignment:NSTextAlignmentCenter];
  33. [self addSubview:self.memberLabel];
  34. [self.memberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  35. make.width.mas_equalTo(45);
  36. make.centerX.mas_equalTo(self.mas_centerX);
  37. make.height.mas_equalTo(20);
  38. make.bottom.mas_equalTo(self.mas_bottom).offset(-19);
  39. }];
  40. self.memberLogo = [[UIImageView alloc] init];
  41. self.memberLogo.layer.cornerRadius = 4;
  42. self.memberLogo.layer.masksToBounds = YES;
  43. self.memberLogo.contentMode = UIViewContentModeScaleAspectFill;
  44. [self addSubview:self.memberLogo];
  45. [self.memberLogo mas_makeConstraints:^(MASConstraintMaker *make) {
  46. make.centerX.mas_equalTo(self.mas_centerX);
  47. make.width.height.mas_equalTo(45);
  48. make.bottom.mas_equalTo(self.memberLabel.mas_top).offset(-2);
  49. }];
  50. UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
  51. [self addGestureRecognizer:tapGesture];
  52. self.tagView = [GroupOwnerTagView shareInstance];
  53. [self addSubview:self.tagView];
  54. [self.tagView mas_makeConstraints:^(MASConstraintMaker *make) {
  55. make.width.mas_equalTo(40);
  56. make.height.mas_equalTo(15);
  57. make.centerX.mas_equalTo(self.memberLogo.mas_centerX);
  58. make.bottom.mas_equalTo(self.memberLogo.mas_bottom).offset(2);
  59. }];
  60. self.tagView.hidden = YES;
  61. }
  62. - (void)tapAction:(UITapGestureRecognizer *)gesture {
  63. if (self.callback) {
  64. self.callback(self.targetId);
  65. }
  66. }
  67. - (void)configMemberWithUrl:(NSString *)url name:(NSString *)name targetId:(NSString *)targetId isOwner:(BOOL)isOwner callback:(ChooseMemberCallback)callback {
  68. if (callback) {
  69. self.callback = callback;
  70. }
  71. [self.memberLogo sd_setImageWithURL:[NSURL URLWithString:[url getUrlEndcodeString]] placeholderImage:[UIImage imageNamed:CHAT_USER_DEFAULT_LOGO]];
  72. self.memberLabel.text = [NSString returnNoNullStringWithString:name];
  73. self.targetId = targetId;
  74. if (isOwner) {
  75. self.tagView.hidden = NO;
  76. }
  77. else {
  78. self.tagView.hidden = YES;
  79. }
  80. }
  81. @end
  82. @interface GroupSettingBodyView ()
  83. @property (weak, nonatomic) IBOutlet UIImageView *groupImage;
  84. @property (weak, nonatomic) IBOutlet UILabel *groupName;
  85. @property (weak, nonatomic) IBOutlet UILabel *memberCount;
  86. @property (weak, nonatomic) IBOutlet UILabel *applyCount;
  87. @property (weak, nonatomic) IBOutlet UILabel *groupRemark;
  88. @property (weak, nonatomic) IBOutlet UIButton *switchButton;
  89. @property (weak, nonatomic) IBOutlet UIView *memberView;
  90. @property (weak, nonatomic) IBOutlet UILabel *groupMemberDesc;
  91. @property (weak, nonatomic) IBOutlet UIButton *sureButton;
  92. @property (nonatomic, copy) GroupSettingBlock callback;
  93. @end
  94. @implementation GroupSettingBodyView
  95. - (void)awakeFromNib {
  96. [super awakeFromNib];
  97. self.isOn = NO;
  98. [self.sureButton setBackgroundColor:CLIENT_THEMECOLOR];
  99. }
  100. + (instancetype)shareInstance {
  101. GroupSettingBodyView *view = [[[NSBundle mainBundle] loadNibNamed:@"GroupSettingBodyView" owner:nil options:nil] firstObject];
  102. return view;
  103. }
  104. - (void)configWithSource:(id)source callback:(GroupSettingBlock)callback {
  105. if (callback) {
  106. self.callback = callback;
  107. }
  108. if ([source isKindOfClass:[GroupListModel class]]) {
  109. GroupListModel *model = source;
  110. NSString *groupPlaceHolder = self.isCourseGroup ? GROUP_COURSE_LOGO : GROUP_FAN_LOGO;
  111. if ([NSString isEmptyString:model.img]) {
  112. [self.groupImage setImage:[UIImage imageNamed:groupPlaceHolder]];
  113. }
  114. else {
  115. [self.groupImage sd_setImageWithURL:[NSURL URLWithString:[model.img getUrlEndcodeString]] placeholderImage:[UIImage imageNamed:groupPlaceHolder]];
  116. }
  117. self.groupName.text = [NSString returnNoNullStringWithString:model.name];
  118. self.groupRemark.text = [NSString returnNoNullStringWithString:model.name];
  119. self.groupMemberDesc.text = [NSString stringWithFormat:@"%.0f/500",model.memberNum];
  120. }
  121. }
  122. - (void)setApplyMember:(NSInteger)applyMember {
  123. _applyMember = applyMember;
  124. self.applyCount.text = [NSString stringWithFormat:@"%ld人",applyMember];
  125. }
  126. - (void)evaluateStudentArray:(NSArray *)studentArray {
  127. if (studentArray.count == 0) {
  128. self.memberCount.text = @"查看全部群成员";
  129. }
  130. else {
  131. self.memberCount.text = [NSString stringWithFormat:@"查看%zd名群成员", studentArray.count];
  132. }
  133. [self removeAllSubviews:self.memberView];
  134. CGFloat width = kScreenWidth / 5;
  135. NSInteger count = 0;
  136. if (studentArray.count < 5) {
  137. count = studentArray.count;
  138. }
  139. else {
  140. count = 5;
  141. }
  142. for (NSInteger i = 0; i < count; i++) {
  143. CGRect frame = CGRectMake(width * i, 0, width, 100);
  144. GroupMemberModel *model = [studentArray objectAtIndex:i];
  145. MemberView *view = [[MemberView alloc] initWithFrame:frame];
  146. [view configMemberWithUrl:model.avatar name:model.nickname targetId:model.imUserId isOwner:model.isAdmin callback:^(NSString *targetId) {
  147. }];
  148. [self.memberView addSubview:view];
  149. }
  150. }
  151. - (void)removeAllSubviews:(UIView *)view {
  152. while (view.subviews.count) {
  153. [view.subviews.lastObject removeFromSuperview];
  154. }
  155. }
  156. // 群联系人
  157. - (IBAction)contractPerson:(id)sender {
  158. if (self.callback) {
  159. self.callback(GROUPSETTING_PERSON);
  160. }
  161. }
  162. // 群申请列表
  163. - (IBAction)groupApply:(id)sender {
  164. if (self.callback) {
  165. self.callback(GROUPSETTING_APPLY);
  166. }
  167. }
  168. // 修改群名称
  169. - (IBAction)modifyGroupName:(id)sender {
  170. if (self.callback) {
  171. self.callback(GROUPSETTING_GROUP);
  172. }
  173. }
  174. // 查找聊天内容
  175. - (IBAction)messageSearch:(id)sender {
  176. if (self.callback) {
  177. self.callback(GROUPSETTING_MESSAGESEARCH);
  178. }
  179. }
  180. // 群通知设置
  181. - (IBAction)notiferAction:(id)sender {
  182. self.isOn = !self.isOn;
  183. if (self.callback) {
  184. self.callback(GROUPSETTING_SETTING);
  185. }
  186. }
  187. // 群公告
  188. - (IBAction)groupNotice:(id)sender {
  189. if (self.callback) {
  190. self.callback(GROUPSETTING_NOTICE);
  191. }
  192. }
  193. // 投诉
  194. - (IBAction)feedBack:(id)sender {
  195. if (self.callback) {
  196. self.callback(GROUPSETTING_FEEDBACK);
  197. }
  198. }
  199. // 解散群聊
  200. - (IBAction)dismissGroup:(id)sender {
  201. if (self.callback) {
  202. self.callback(GROUPSETTING_DISMISS);
  203. }
  204. }
  205. - (void)setIsOn:(BOOL)isOn {
  206. _isOn = isOn;
  207. NSString *imageName = isOn ? CLIENT_SWITCH_ON : @"switch_off";
  208. [self.switchButton setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
  209. }
  210. /*
  211. // Only override drawRect: if you perform custom drawing.
  212. // An empty implementation adversely affects performance during animation.
  213. - (void)drawRect:(CGRect)rect {
  214. // Drawing code
  215. }
  216. */
  217. @end