JxChatGetNoticePersonVc.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. //
  2. // JxChatGetNoticePersonVc.m
  3. // shiku_im
  4. //
  5. // Created by 123 on 2020/5/22.
  6. // Copyright © 2020 Reese. All rights reserved.
  7. //
  8. #import "JxChatGetNoticePersonVc.h"
  9. #import "JXChatGuanZhuCell.h"
  10. #import "UIBarButtonItem+XMGExtension.h"
  11. #import "JXChatGuanZhuCell.h"
  12. #import "JXChatViewController.h"
  13. #define APP_WIDTH [[UIScreen mainScreen]applicationFrame].size.width
  14. #define APP_HEIGHT [[UIScreen mainScreen]applicationFrame].size.height
  15. #import "JXChatChineseString.h"
  16. @interface JxChatGetNoticePersonVc ()<UITableViewDelegate,UITableViewDataSource>
  17. @property(nonatomic,strong)NSMutableArray *indexArray;
  18. @property(nonatomic,strong)NSMutableArray *letterResultArr;
  19. @property (nonatomic, strong) UILabel *sectionTitleView;
  20. @property (nonatomic, strong) NSTimer *timer;
  21. @property (nonatomic,weak) UITableView *tableView;
  22. @property (nonatomic,strong) NSMutableArray *dataArr2;
  23. /** 勾选关注的 数组 */
  24. @property (nonatomic,strong) memberData *dictUser;
  25. @property (nonatomic,strong) JXChatViewController *chatVc;
  26. @property (nonatomic,strong) NSMutableArray *dataArrUserId;
  27. @property (nonatomic,strong) NSMutableArray *dataArrUserIdIndex;
  28. @property (nonatomic,strong) NSMutableArray *selectUserIdArr;
  29. @property (nonatomic,strong) NSMutableDictionary *selectDictM;
  30. @property (nonatomic,copy) NSString *selctIndexPath;
  31. @end
  32. @implementation JxChatGetNoticePersonVc
  33. - (void)viewDidLoad {
  34. [super viewDidLoad];
  35. self.view.backgroundColor=[UIColor whiteColor];
  36. self.navigationItem.title=@"选择联系人";
  37. [self defineNavBarXXX:@"选择联系人" andRinghtBtnImg:@"1000"];
  38. _dataArr2=[NSMutableArray array];
  39. _dataArrUserId=[NSMutableArray array];
  40. _chatVc=[JXChatViewController new];
  41. _dataArrUserIdIndex=[NSMutableArray array];
  42. _selectDictM=[NSMutableDictionary dictionary];
  43. //新选中的UIserId
  44. _selectUserIdArr=[NSMutableArray array];
  45. //初始化数据
  46. // [self initDataSource];
  47. self.sectionTitleView = ({
  48. UILabel *sectionTitleView = [[UILabel alloc] initWithFrame:CGRectMake((APP_WIDTH-100)/2, (APP_HEIGHT-100)/2,100,100)];
  49. sectionTitleView.textAlignment = NSTextAlignmentCenter;
  50. sectionTitleView.font = [UIFont boldSystemFontOfSize:60];
  51. sectionTitleView.textColor = [UIColor blueColor];
  52. sectionTitleView.backgroundColor = [UIColor greenColor];
  53. sectionTitleView.layer.cornerRadius = 6;
  54. sectionTitleView.layer.borderWidth = 1.f/[UIScreen mainScreen].scale;
  55. _sectionTitleView.layer.borderColor = [UIColor groupTableViewBackgroundColor].CGColor;
  56. sectionTitleView;
  57. });
  58. [self.navigationController.view addSubview:self.sectionTitleView];
  59. self.sectionTitleView.hidden = YES;
  60. self.navigationItem.rightBarButtonItem=[UIBarButtonItem xmg_itemSearchNavTitleX:@"完成" andNum:0 target:self action:@selector(compleClick)];
  61. __block NSUInteger aaa=0;
  62. NSMutableArray *tempArr=[NSMutableArray array];
  63. [_dataArr enumerateObjectsUsingBlock:^(memberData * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  64. if (obj.userId==[g_server.myself.userId longLongValue]) {
  65. aaa=idx;
  66. }else{
  67. [tempArr addObject:obj];
  68. }
  69. NSString *nameL=obj.userNickName;
  70. [_dataArr2 addObject:nameL];
  71. }];
  72. NSArray *stringsToSort = [NSArray arrayWithObjects: @"world",@"b1", nil];
  73. stringsToSort=[_dataArr2 copy];
  74. //数组模型拼音分组
  75. _dataArr=tempArr;
  76. _letterResultArr = [JXChatChineseString LetterSortArray:_dataArr];
  77. _indexArray=[NSMutableArray array];
  78. [_letterResultArr enumerateObjectsUsingBlock:^(NSArray * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  79. [obj enumerateObjectsUsingBlock:^(NSDictionary * _Nonnull dict, NSUInteger idx, BOOL * _Nonnull stop) {
  80. [_indexArray addObject:dict[@"title"]];
  81. }];
  82. }];
  83. _indexArray = [JXChatChineseString IndexArray:_indexArray];
  84. UITableView *tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH, JX_SCREEN_HEIGHT-JX_SCREEN_TOP-44) style:UITableViewStylePlain];
  85. tableView.delegate=self;
  86. tableView.dataSource=self;
  87. [self.view addSubview:tableView];
  88. self.tableView=tableView;
  89. tableView.tableFooterView=[UIView new];
  90. [tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"];
  91. // -(void)UserRoomAttentionLookattention:(NSString *)salt userId:(NSString *)userId jid:(NSString *)jid attentionUserId:(NSString *)attentionUserId andToView:(id)toView;
  92. long time = (long)[[NSDate date] timeIntervalSince1970];
  93. time = (time *1000 + g_server.timeDifference);
  94. NSString *salt = [NSString stringWithFormat:@"%ld", time];
  95. [g_server UserRoomAttentionLookattention:salt userId:g_server.myself.userId jid:_roomID andToView:self];
  96. }
  97. /**
  98. * tableView Data
  99. */
  100. -(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
  101. {
  102. return self.indexArray;
  103. }
  104. - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
  105. NSString *key = [self.indexArray objectAtIndex:section];
  106. return key;
  107. }
  108. - (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index {
  109. [self showSectionTitle:title];
  110. return index;
  111. }
  112. #pragma mark - private
  113. - (void)setBlock:(successBlock)block {
  114. _block = block;
  115. }
  116. - (void)timerHandler:(NSTimer *)sender
  117. {
  118. dispatch_async(dispatch_get_main_queue(), ^{
  119. [UIView animateWithDuration:.3 animations:^{
  120. self.sectionTitleView.alpha = 0;
  121. } completion:^(BOOL finished) {
  122. self.sectionTitleView.hidden = YES;
  123. }];
  124. });
  125. }
  126. -(void)showSectionTitle:(NSString*)title{
  127. [self.sectionTitleView setText:title];
  128. self.sectionTitleView.hidden = NO;
  129. self.sectionTitleView.alpha = 1;
  130. [self.timer invalidate];
  131. self.timer = nil;
  132. self.timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timerHandler:) userInfo:nil repeats:NO];
  133. [[NSRunLoop currentRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes];
  134. }
  135. -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  136. {
  137. UIView *titleView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH, 20)];
  138. titleView.backgroundColor = kRGBColor246;
  139. UILabel *lab = [[UILabel alloc]initWithFrame:CGRectMake(20, 5, JX_SCREEN_WIDTH-40, 20)];
  140. lab.text = [self.indexArray objectAtIndex:section];
  141. lab.font=[UIFont systemFontOfSize:15 weight:UIFontWeightMedium];
  142. lab.textColor = kRGBColor51;
  143. [titleView addSubview:lab];
  144. return titleView;
  145. }
  146. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  147. {
  148. return 65.0;
  149. }
  150. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  151. {
  152. return [self.indexArray count];
  153. }
  154. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  155. {
  156. NSArray *secondArr = [self.letterResultArr objectAtIndex:section];
  157. return secondArr.count;
  158. }
  159. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  160. {
  161. JXChatGuanZhuCell *cell = [JXChatGuanZhuCell cellWithTableView:tableView];
  162. NSDictionary *dict= [[self.letterResultArr objectAtIndex:indexPath.section]objectAtIndex:indexPath.row];
  163. memberData *dictUser=dict[@"model"];
  164. if (dictUser.clicked) {
  165. [tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:indexPath.row inSection:0] animated:YES scrollPosition:UITableViewScrollPositionNone];
  166. _selctIndexPath=[NSString stringWithFormat:@"%ld",dictUser.userId];
  167. _dictUser=dictUser;
  168. }
  169. cell.model = dictUser;
  170. return cell;
  171. }
  172. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  173. {
  174. JXChatGuanZhuCell *cell = [tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section]];
  175. NSDictionary *dictM= [[self.letterResultArr objectAtIndex:indexPath.section]objectAtIndex:indexPath.row];
  176. memberData *dictUser=dictM[@"model"];
  177. _selctIndexPath=[NSString stringWithFormat:@"%ld",dictUser.userId];
  178. dictUser.clicked = !dictUser.clicked;
  179. _dictUser=dictUser;
  180. // cell.model = dictUser;
  181. _selctIndexPath=[NSString stringWithFormat:@"%ld",dictUser.userId];
  182. }
  183. /** 完成*/
  184. - (void)compleClick{
  185. if (_selctIndexPath.length==0) {
  186. [SVProgressHUD showWithStatus:@"您还没有选择关心的好友呢"];
  187. [SVProgressHUD dismissWithDelay:0.8];
  188. return;
  189. }
  190. // JXChatViewController *vcha=[JXChatViewController new];
  191. // [vcha showBack:_dictUser];
  192. [SVProgressHUD show];
  193. long time = (long)[[NSDate date] timeIntervalSince1970];
  194. time = (time *1000 + g_server.timeDifference);
  195. NSString *salt = [NSString stringWithFormat:@"%ld", time];
  196. [g_server UserRoomAttentionListion:salt userId:g_server.myself.userId jid:_roomID attentionUserId:_selctIndexPath andToView:self];
  197. }
  198. #pragma mark -------------------服务器返回数据--------------------
  199. -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{
  200. [SVProgressHUD dismiss];
  201. if ([aDownload.action isEqualToString:act_UserRoomListAttenion])
  202. {
  203. if (_block) {
  204. _block(_dictUser);
  205. }
  206. [self.navigationController popViewControllerAnimated:YES];
  207. }
  208. if ([aDownload.action isEqualToString:act_UserRoomManyLookAttenion])
  209. {
  210. NSArray *userIDArr=dict[@"attentionUserIds"];
  211. NSLog(@"--- %@ - userId %@",dict,userIDArr);
  212. [_dataArr enumerateObjectsUsingBlock:^(memberData * _Nonnull dataModel, NSUInteger idx, BOOL * _Nonnull stop) {
  213. [userIDArr enumerateObjectsUsingBlock:^(NSString *_Nonnull objStr, NSUInteger idx, BOOL * _Nonnull stop) {
  214. if (dataModel.userId == [objStr longLongValue]) {
  215. dataModel.clicked = !dataModel.clicked;
  216. //cell.model = dictUser;
  217. [_dataArrUserId addObject:objStr];
  218. }
  219. }];
  220. }];
  221. [self.tableView reloadData];
  222. }
  223. }
  224. -(int) didServerResultFailed:(JXConnection*)aDownload dict:(NSDictionary*)dict{
  225. [SVProgressHUD dismiss];
  226. NSString * errorCode = [NSString stringWithFormat:@"%@",[dict objectForKey:@"resultMsg"]];
  227. if([errorCode isEqualToString:@"权限验证失败"])
  228. {
  229. if ([aDownload.action isEqualToString:act_UserRoomAttentionattention])
  230. {
  231. }
  232. }
  233. return [errorCode intValue];
  234. }
  235. @end