GroupSettingBodyView.m 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  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, strong) GroupOwnerTagView *tagView;
  17. @property (nonatomic, copy) ChooseMemberCallback callback;
  18. - (void)configMemberWithUrl:(NSString *)url name:(NSString *)name targetId:(NSString *)targetId isOwner:(BOOL)isOwner callback:(ChooseMemberCallback)callback;
  19. - (void)configMemberWithNativeImage:(NSString *)imageName name:(NSString *)name callback:(ChooseMemberCallback)callback;
  20. @end
  21. @implementation MemberView
  22. - (instancetype)initWithFrame:(CGRect)frame {
  23. self = [super initWithFrame:frame];
  24. if (self) {
  25. [self initView];
  26. }
  27. return self;
  28. }
  29. - (void)initView {
  30. self.memberLabel = [[UILabel alloc] init];
  31. self.memberLabel.textColor = HexRGB(0x777777);
  32. [self.memberLabel setFont:[UIFont systemFontOfSize:14.0f]];
  33. [self.memberLabel setTextAlignment:NSTextAlignmentCenter];
  34. [self addSubview:self.memberLabel];
  35. [self.memberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  36. make.width.mas_equalTo(45);
  37. make.centerX.mas_equalTo(self.mas_centerX);
  38. make.height.mas_equalTo(20);
  39. make.bottom.mas_equalTo(self.mas_bottom).offset(-19);
  40. }];
  41. self.memberLogo = [[UIImageView alloc] init];
  42. self.memberLogo.layer.cornerRadius = 22.5;
  43. self.memberLogo.layer.masksToBounds = YES;
  44. self.memberLogo.contentMode = UIViewContentModeScaleAspectFill;
  45. [self addSubview:self.memberLogo];
  46. [self.memberLogo mas_makeConstraints:^(MASConstraintMaker *make) {
  47. make.centerX.mas_equalTo(self.mas_centerX);
  48. make.width.height.mas_equalTo(45);
  49. make.bottom.mas_equalTo(self.memberLabel.mas_top).offset(-2);
  50. }];
  51. UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
  52. [self addGestureRecognizer:tapGesture];
  53. self.tagView = [GroupOwnerTagView shareInstance];
  54. [self addSubview:self.tagView];
  55. [self.tagView mas_makeConstraints:^(MASConstraintMaker *make) {
  56. make.width.mas_equalTo(40);
  57. make.height.mas_equalTo(15);
  58. make.centerX.mas_equalTo(self.memberLogo.mas_centerX);
  59. make.bottom.mas_equalTo(self.memberLogo.mas_bottom).offset(2);
  60. }];
  61. self.tagView.hidden = YES;
  62. }
  63. - (void)tapAction:(UITapGestureRecognizer *)gesture {
  64. if (self.callback) {
  65. self.callback(self.targetId);
  66. }
  67. }
  68. - (void)configMemberWithUrl:(NSString *)url name:(NSString *)name targetId:(NSString *)targetId isOwner:(BOOL)isOwner callback:(ChooseMemberCallback)callback {
  69. if (callback) {
  70. self.callback = callback;
  71. }
  72. [self.memberLogo sd_setImageWithURL:[NSURL URLWithString:[url getUrlEndcodeString]] placeholderImage:[UIImage imageNamed:CHAT_USER_DEFAULT_LOGO]];
  73. self.memberLabel.text = [NSString returnNoNullStringWithString:name];
  74. self.targetId = targetId;
  75. if (isOwner) {
  76. self.tagView.hidden = NO;
  77. }
  78. else {
  79. self.tagView.hidden = YES;
  80. }
  81. }
  82. - (void)configMemberWithNativeImage:(NSString *)imageName name:(NSString *)name callback:(ChooseMemberCallback)callback {
  83. if (callback) {
  84. self.callback = callback;
  85. }
  86. [self.memberLogo setImage:[UIImage imageNamed:imageName]];
  87. self.memberLabel.text = name;
  88. }
  89. @end
  90. @interface GroupSettingBodyView ()
  91. @property (weak, nonatomic) IBOutlet UIImageView *groupImage;
  92. @property (weak, nonatomic) IBOutlet UILabel *groupName;
  93. @property (weak, nonatomic) IBOutlet UILabel *memberCount;
  94. @property (weak, nonatomic) IBOutlet UILabel *applyCount;
  95. @property (weak, nonatomic) IBOutlet UILabel *groupRemark;
  96. @property (weak, nonatomic) IBOutlet UIButton *switchButton;
  97. @property (weak, nonatomic) IBOutlet UIView *memberView;
  98. @property (weak, nonatomic) IBOutlet UILabel *groupMemberDesc;
  99. @property (weak, nonatomic) IBOutlet UIView *applyView;
  100. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *applyViewHeight;
  101. @property (nonatomic, copy) GroupSettingBlock callback;
  102. @property (nonatomic, assign) BOOL canAddMember;
  103. @property (nonatomic, strong) UIScrollView *memberScrollView;
  104. @property (weak, nonatomic) IBOutlet UIView *fullbannedView;
  105. @property (weak, nonatomic) IBOutlet UIButton *muteButton;
  106. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *fullBanHeight;
  107. @property (weak, nonatomic) IBOutlet UIView *banListView;
  108. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *banListHeight;
  109. @property (weak, nonatomic) IBOutlet UILabel *groupDesc;
  110. @end
  111. @implementation GroupSettingBodyView
  112. - (void)awakeFromNib {
  113. [super awakeFromNib];
  114. self.isOn = NO;
  115. [self.memberView addSubview:self.memberScrollView];
  116. [self.memberScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
  117. make.left.right.top.bottom.mas_equalTo(self.memberView);
  118. }];
  119. }
  120. + (instancetype)shareInstance {
  121. GroupSettingBodyView *view = [[[NSBundle mainBundle] loadNibNamed:@"GroupSettingBodyView" owner:nil options:nil] firstObject];
  122. return view;
  123. }
  124. - (void)configApplyViewDisplay:(BOOL)isDisplay {
  125. if (isDisplay) {
  126. self.applyView.hidden = NO;
  127. self.applyViewHeight.constant = 55.0f;
  128. self.canAddMember = NO;
  129. }
  130. else {
  131. self.applyView.hidden = YES;
  132. self.applyViewHeight.constant = 0.0f;
  133. self.canAddMember = YES;
  134. }
  135. }
  136. - (void)configWithSource:(id)source callback:(GroupSettingBlock)callback {
  137. if (callback) {
  138. self.callback = callback;
  139. }
  140. if ([source isKindOfClass:[GroupListModel class]]) {
  141. GroupListModel *model = source;
  142. NSString *defaultLogo = @"";
  143. if ([model.type isEqualToString:@"FAN"]) {
  144. defaultLogo = GROUP_FAN_LOGO;
  145. [self configApplyViewDisplay:YES];
  146. }
  147. else if ([model.type isEqualToString:@"ORG"]) {
  148. defaultLogo = GROUP_TENANT_LOGO;
  149. [self configApplyViewDisplay:NO];
  150. }
  151. else {
  152. defaultLogo = GROUP_COURSE_LOGO;
  153. [self configApplyViewDisplay:YES];
  154. }
  155. if ([NSString isEmptyString:model.img]) {
  156. [self.groupImage setImage:[UIImage imageNamed:defaultLogo]];
  157. }
  158. else {
  159. [self.groupImage sd_setImageWithURL:[NSURL URLWithString:[model.img getUrlEndcodeString]] placeholderImage:[UIImage imageNamed:defaultLogo]];
  160. }
  161. self.groupName.text = [NSString returnNoNullStringWithString:model.name];
  162. self.groupRemark.text = [NSString returnNoNullStringWithString:model.name];
  163. NSInteger groupLimit = model.groupMemberLimit;
  164. if (model.groupMemberLimit <= 0) {
  165. groupLimit = 2000;
  166. }
  167. self.groupMemberDesc.text = [NSString stringWithFormat:@"%.0f/%zd",model.memberNum,groupLimit];
  168. if ([NSString isEmptyString:model.introduce]) {
  169. self.groupDesc.text = @"暂无群简介";
  170. }
  171. else {
  172. self.groupDesc.text = model.introduce;
  173. }
  174. }
  175. }
  176. - (void)setApplyMember:(NSInteger)applyMember {
  177. _applyMember = applyMember;
  178. self.applyCount.text = [NSString stringWithFormat:@"%ld人",applyMember];
  179. }
  180. - (void)evaluateStudentArray:(NSArray *)studentArray {
  181. if (studentArray.count == 0) {
  182. self.memberCount.text = @"查看全部群成员";
  183. }
  184. else {
  185. self.memberCount.text = [NSString stringWithFormat:@"查看全部%zd名群成员", studentArray.count];
  186. }
  187. [self removeAllSubviews:self.memberScrollView];
  188. NSInteger maxCount = IS_IPAD ? 9 : 5;
  189. CGFloat width = KPortraitWidth / maxCount;
  190. NSInteger maxDisplay = maxCount;
  191. NSInteger count = 0;
  192. if (self.canAddMember) {
  193. maxDisplay = maxCount - 1;
  194. }
  195. if (studentArray.count < maxDisplay) {
  196. count = studentArray.count;
  197. }
  198. else {
  199. count = maxDisplay;
  200. }
  201. for (NSInteger i = 0; i < count; i++) {
  202. CGRect frame = CGRectMake(width * i, 0, width, 100);
  203. GroupMemberModel *model = [studentArray objectAtIndex:i];
  204. MemberView *view = [[MemberView alloc] initWithFrame:frame];
  205. [view configMemberWithUrl:model.avatar name:model.nickname targetId:model.imUserId isOwner:model.isAdmin callback:^(NSString *targetId) {
  206. }];
  207. [self.memberScrollView addSubview:view];
  208. [view mas_makeConstraints:^(MASConstraintMaker *make) {
  209. make.top.bottom.mas_equalTo(self.memberScrollView);
  210. make.left.mas_equalTo(self.memberScrollView.mas_left).offset(width * i);
  211. make.width.mas_equalTo(width);
  212. make.height.mas_equalTo(100);
  213. if (i == count -1 && self.canAddMember == NO) {
  214. make.right.mas_equalTo(self.memberScrollView.mas_right);
  215. }
  216. }];
  217. }
  218. // 添加按钮
  219. if (self.canAddMember) {
  220. CGRect frame = CGRectMake(width * count, 0, width, 100);
  221. MemberView *view = [[MemberView alloc] initWithFrame:frame];
  222. MJWeakSelf;
  223. [view configMemberWithNativeImage:@"group_memberAdd" name:@"添加" callback:^(NSString *targetId) {
  224. [weakSelf addMember];
  225. }];
  226. [self.memberScrollView addSubview:view];
  227. [view mas_makeConstraints:^(MASConstraintMaker *make) {
  228. make.top.bottom.mas_equalTo(self.memberScrollView);
  229. make.left.mas_equalTo(self.memberScrollView.mas_left).offset(width * count);
  230. make.width.mas_equalTo(width);
  231. make.height.mas_equalTo(100);
  232. make.right.mas_equalTo(self.memberScrollView.mas_right);
  233. }];
  234. }
  235. }
  236. - (void)removeAllSubviews:(UIView *)view {
  237. while (view.subviews.count) {
  238. [view.subviews.lastObject removeFromSuperview];
  239. }
  240. }
  241. - (void)addMember {
  242. if (self.callback) {
  243. self.callback(GROUPSETTING_ADDMENBER);
  244. }
  245. }
  246. // 群联系人
  247. - (IBAction)contractPerson:(id)sender {
  248. if (self.callback) {
  249. self.callback(GROUPSETTING_PERSON);
  250. }
  251. }
  252. // 群申请列表
  253. - (IBAction)groupApply:(id)sender {
  254. if (self.callback) {
  255. self.callback(GROUPSETTING_APPLY);
  256. }
  257. }
  258. // 修改群名称
  259. - (IBAction)modifyGroupName:(id)sender {
  260. if (self.callback) {
  261. self.callback(GROUPSETTING_GROUP);
  262. }
  263. }
  264. // 查找聊天内容
  265. - (IBAction)messageSearch:(id)sender {
  266. if (self.callback) {
  267. self.callback(GROUPSETTING_MESSAGESEARCH);
  268. }
  269. }
  270. // 群通知设置
  271. - (IBAction)notiferAction:(id)sender {
  272. self.isOn = !self.isOn;
  273. if (self.callback) {
  274. self.callback(GROUPSETTING_SETTING);
  275. }
  276. }
  277. // 群简介
  278. - (IBAction)groupIntroduce:(id)sender {
  279. if (self.callback) {
  280. self.callback(GROUPSETTING_GROUPINTRODUCE);
  281. }
  282. }
  283. // 群公告
  284. - (IBAction)groupNotice:(id)sender {
  285. if (self.callback) {
  286. self.callback(GROUPSETTING_NOTICE);
  287. }
  288. }
  289. // 投诉
  290. - (IBAction)feedBack:(id)sender {
  291. if (self.callback) {
  292. self.callback(GROUPSETTING_FEEDBACK);
  293. }
  294. }
  295. // 解散群聊
  296. - (IBAction)dismissGroup:(id)sender {
  297. if (self.callback) {
  298. self.callback(GROUPSETTING_DISMISS);
  299. }
  300. }
  301. - (IBAction)muteAction:(id)sender {
  302. self.isMute = !self.isMute;
  303. if (self.callback) {
  304. self.callback(GROUPSETTING_MUTE);
  305. }
  306. }
  307. - (IBAction)displayBanList:(id)sender {
  308. if (self.callback) {
  309. self.callback(GROUPSETTING_BANLIST);
  310. }
  311. }
  312. - (UIScrollView *)memberScrollView {
  313. if (!_memberScrollView) {
  314. _memberScrollView = [[UIScrollView alloc] init];
  315. }
  316. return _memberScrollView;
  317. }
  318. - (void)setIsOn:(BOOL)isOn {
  319. _isOn = isOn;
  320. NSString *imageName = isOn ? @"switch_on" : @"switch_off";
  321. [self.switchButton setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
  322. }
  323. - (void)setIsMute:(BOOL)isMute {
  324. _isMute = isMute;
  325. NSString *imageName = isMute ? @"switch_on" : @"switch_off";
  326. [self.muteButton setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
  327. }
  328. /***
  329. Owner("群主"),
  330. Admin("管理员"),
  331. Member("群成员"),
  332. */
  333. - (BOOL)hasManageGroupLimit {
  334. if ([self.groupRoleType isEqualToString:@"Owner"] || [self.groupRoleType isEqualToString:@"Admin"]) {
  335. return YES;
  336. }
  337. return NO;
  338. }
  339. - (void)setGroupRoleType:(NSString *)groupRoleType {
  340. _groupRoleType = groupRoleType;
  341. if ([groupRoleType isEqualToString:@"Owner"]) {
  342. self.fullbannedView.hidden = NO;
  343. self.fullBanHeight.constant = 55.0f;
  344. self.banListView.hidden = NO;
  345. self.banListHeight.constant = 55.0f;
  346. }
  347. else if ([groupRoleType isEqualToString:@"Admin"]) {
  348. self.fullbannedView.hidden = NO;
  349. self.fullBanHeight.constant = 55.0f;
  350. self.banListView.hidden = NO;
  351. self.banListHeight.constant = 55.0f;
  352. }
  353. else {
  354. self.fullbannedView.hidden = YES;
  355. self.fullBanHeight.constant = 0.0f;
  356. self.banListView.hidden = YES;
  357. self.banListHeight.constant = 0.0f;
  358. }
  359. }
  360. - (CGFloat)getViewHeight:(NSString *)roleType {
  361. CGFloat bottomSpace = IS_iPhoneX ? iPhoneXSafeBottomMargin : 20;
  362. if ([self.groupRoleType isEqualToString:@"Owner"] || [self.groupRoleType isEqualToString:@"Admin"]) {
  363. return 857 + bottomSpace;
  364. }
  365. else {
  366. return 747 + bottomSpace;
  367. }
  368. }
  369. /*
  370. // Only override drawRect: if you perform custom drawing.
  371. // An empty implementation adversely affects performance during animation.
  372. - (void)drawRect:(CGRect)rect {
  373. // Drawing code
  374. }
  375. */
  376. @end