GroupMemberViewController.m 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. //
  2. // GroupMemberViewController.m
  3. // KulexiuForTeacher
  4. //
  5. // Created by Kyle on 2022/3/24.
  6. //
  7. #import "GroupMemberViewController.h"
  8. #import "SCIndexView.h"
  9. #import "UITableView+SCIndexView.h"
  10. #import "GroupMemberListCell.h"
  11. #import "GroupMemberModel.h"
  12. #import <RongIMKit/RongIMKit.h>
  13. #import "KSChatConversationViewController.h"
  14. @interface GroupMemberViewController ()<UITableViewDelegate,UITableViewDataSource>
  15. @property (nonatomic, strong) UITableView *tableView;
  16. @property (nonatomic, strong) NSMutableArray *sourceIndexArray;
  17. @property (nonatomic, strong) NSMutableArray *sourceArray;
  18. @end
  19. @implementation GroupMemberViewController
  20. - (void)viewDidLoad {
  21. [super viewDidLoad];
  22. // Do any additional setup after loading the view.
  23. [self allocTitle:@"群成员"];
  24. [self configUI];
  25. [self requestData];
  26. }
  27. - (void)resetSource {
  28. [self setPromptString:@"暂无内容" imageName:@"wd_img_zwsj" inView:self.tableView];
  29. [self.sourceArray removeAllObjects];
  30. [self.dataArray removeAllObjects];
  31. self.sourceIndexArray = [NSMutableArray array];
  32. self.tableView.sc_indexViewDataSource = self.sourceIndexArray;
  33. [self.tableView reloadData];
  34. }
  35. - (void)requestData {
  36. [self.sourceArray removeAllObjects];
  37. [KSNetworkingManager imGroupMemberAllRequest:KS_POST groupId:self.groupId success:^(NSDictionary * _Nonnull dic) {
  38. if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
  39. NSArray *sourceArray = [dic ks_arrayValueForKey:@"data"];
  40. for (NSDictionary *parm in sourceArray) {
  41. if ([parm isKindOfClass:[NSNull class]]) {
  42. continue;
  43. }
  44. GroupMemberModel *model = [[GroupMemberModel alloc] initWithDictionary:parm];
  45. [self.sourceArray addObject:model];
  46. // 刷新缓存
  47. RCUserInfo *user = [[RCUserInfo alloc] initWithUserId:model.imUserId name:model.nickname portrait:model.avatar];
  48. // 附加字段
  49. NSMutableDictionary *extraDic = [NSMutableDictionary dictionary];
  50. if (model.isAdmin) {
  51. [extraDic setValue:@"owner" forKey:@"groupOwner"];
  52. }
  53. [extraDic setValue:model.roleType forKey:@"role"];
  54. user.extra = [extraDic mj_JSONString];
  55. [[RCIM sharedRCIM] refreshGroupUserInfoCache:user withUserId:model.imUserId withGroupId:self.groupId];
  56. }
  57. [self evaluateMessge];
  58. }
  59. else {
  60. [LOADING_MANAGER MBShowAUTOHidingInWindow:MESSAGEKEY];
  61. }
  62. } faliure:^(NSError * _Nonnull error) {
  63. }];
  64. }
  65. - (void)evaluateMessge {
  66. [LOADING_MANAGER MBShowInWindow:@"数据加载中......"];
  67. // 异步线程处理数据
  68. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  69. NSMutableArray *sortArr = [NSMutableArray array];
  70. for (GroupMemberModel *model in self.sourceArray) {
  71. NSString *firstLetter = [NSString getFirstLetterFromString:model.nickname];
  72. model.firstLetter = firstLetter;
  73. if (![sortArr containsObject:firstLetter]) {
  74. [sortArr addObject:firstLetter];
  75. }
  76. }
  77. // 排序
  78. [sortArr sortUsingComparator:^NSComparisonResult(id _Nonnull obj1, id _Nonnull obj2) {
  79. return [obj1 compare:obj2 options:NSCaseInsensitiveSearch];
  80. }];
  81. // 将#移动到最后
  82. for (NSString *letterStr in sortArr) {
  83. if ([letterStr isEqualToString:@"#"]) {
  84. [sortArr removeObject:letterStr];
  85. [sortArr addObject:@"#"];
  86. break;
  87. }
  88. }
  89. for (NSString *sortStr in sortArr) {
  90. NSMutableArray *filterArray = [NSMutableArray array];
  91. for (GroupMemberModel *subModel in self.sourceArray) {
  92. if ([sortStr isEqualToString:subModel.firstLetter]) {
  93. [filterArray addObject:subModel];
  94. }
  95. }
  96. [self.dataArray addObject:filterArray];
  97. }
  98. self.sourceIndexArray = sortArr;
  99. // 主线程刷新
  100. dispatch_async(dispatch_get_main_queue(), ^{
  101. [LOADING_MANAGER removeHUD];
  102. self.tableView.sc_indexViewDataSource = self.sourceIndexArray;
  103. [self.tableView reloadData];
  104. [self changePromptLabelState];
  105. });
  106. });
  107. }
  108. - (void)configUI {
  109. [self.scrollView removeFromSuperview];
  110. [self.view addSubview:self.tableView];
  111. SCIndexViewConfiguration *indexConfiguration = [SCIndexViewConfiguration configuration];
  112. indexConfiguration.indexItemSelectedBackgroundColor = CLIENT_THEMESORTCOLOR;
  113. indexConfiguration.indicatorBackgroundColor = CLIENT_THEMESORTCOLOR;
  114. self.tableView.sc_indexViewConfiguration = indexConfiguration;
  115. self.tableView.sc_translucentForTableViewInNavigationBar = YES;
  116. }
  117. #pragma mark -- table data source
  118. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  119. if (self.dataArray.count > section) {
  120. NSArray *filterArray = self.dataArray[section];
  121. return filterArray.count;
  122. }
  123. return 0;
  124. }
  125. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  126. return self.sourceIndexArray.count;
  127. }
  128. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  129. GroupMemberListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"GroupMemberListCell"];
  130. NSArray *filterArray = self.dataArray[indexPath.section];
  131. GroupMemberModel *model = filterArray[indexPath.row];
  132. MJWeakSelf;
  133. [cell configWithSource:model callback:^(NSString * _Nonnull targetId, NSString * _Nonnull name) {
  134. TUIChatConversationModel *model = [[TUIChatConversationModel alloc] init];
  135. model.userID = targetId;
  136. KSChatConversationViewController *ctrl = [[KSChatConversationViewController alloc] init];
  137. ctrl.conversation = model;
  138. [weakSelf.navigationController pushViewController:ctrl animated:YES];
  139. }];
  140. return cell;
  141. }
  142. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  143. }
  144. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  145. return 30;
  146. }
  147. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  148. UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 30)];
  149. view.backgroundColor = [UIColor clearColor];
  150. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(24, 0, kScreenWidth - 48, 30)];
  151. label.textColor = HexRGB(0x999999);
  152. label.font = [UIFont systemFontOfSize:16.0f weight:UIFontWeightMedium];
  153. [view addSubview:label];
  154. label.textAlignment = NSTextAlignmentLeft;
  155. NSString *titleStr = self.sourceIndexArray[section];
  156. label.text = titleStr;
  157. return view;
  158. }
  159. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  160. return CGFLOAT_MIN;
  161. }
  162. #pragma mark ---- lazying
  163. - (UITableView *)tableView {
  164. if (!_tableView) {
  165. _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight - kNaviBarHeight - iPhoneXSafeBottomMargin) style:UITableViewStylePlain];
  166. _tableView.delegate = self;
  167. _tableView.dataSource = self;
  168. _tableView.rowHeight = 80;
  169. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  170. _tableView.showsVerticalScrollIndicator = NO;
  171. _tableView.backgroundColor = [UIColor clearColor];
  172. [_tableView registerNib:[UINib nibWithNibName:@"GroupMemberListCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"GroupMemberListCell"];
  173. UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 10)];
  174. bottomView.backgroundColor = [UIColor clearColor];
  175. _tableView.tableFooterView = bottomView;
  176. }
  177. return _tableView;
  178. }
  179. - (NSMutableArray *)sourceIndexArray {
  180. if (!_sourceIndexArray) {
  181. _sourceIndexArray = [NSMutableArray array];
  182. }
  183. return _sourceIndexArray;
  184. }
  185. - (NSMutableArray *)sourceArray {
  186. if (!_sourceArray) {
  187. _sourceArray = [NSMutableArray array];
  188. }
  189. return _sourceArray;
  190. }
  191. /*
  192. #pragma mark - Navigation
  193. // In a storyboard-based application, you will often want to do a little preparation before navigation
  194. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  195. // Get the new view controller using [segue destinationViewController].
  196. // Pass the selected object to the new view controller.
  197. }
  198. */
  199. @end