JxChatGetNoticePersonGVc.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  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 "JxChatGetNoticePersonGVc.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 JxChatGetNoticePersonGVc ()<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 JxChatGetNoticePersonGVc
  33. - (void)gclick{
  34. [g_navigation dismissViewController:self animated:YES];
  35. }
  36. - (void)defineNavBarXXX:(NSString *)title andRinghtBtnImg:(NSString *)image
  37. {
  38. UIView *navView = [[UIView alloc] init];
  39. [self.view addSubview:navView];
  40. navView.frame = CGRectMake(0, 0, JX_SCREEN_WIDTH,JX_SCREEN_TOP);
  41. UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  42. backBtn.frame = CGRectMake(0,JX_SCREEN_HEIGHT>812?44:20,44, 44);
  43. [backBtn setImage:[UIImage imageNamed:@"photo_title_back_black"] forState:0];
  44. backBtn.tag = 1001;
  45. [backBtn addTarget:self action:@selector(gclick) forControlEvents:UIControlEventTouchUpInside];
  46. [navView addSubview:backBtn];
  47. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(50,(JX_SCREEN_HEIGHT>812?44:20), JX_SCREEN_WIDTH-100, 44)];
  48. label.text = title;
  49. label.textColor = kRGBColor51;
  50. navView.backgroundColor = [UIColor whiteColor];
  51. label.font = [UIFont systemFontOfSize:18 weight:UIFontWeightRegular];
  52. label.textAlignment = NSTextAlignmentCenter;
  53. [navView addSubview:label];
  54. UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  55. rightBtn.frame = CGRectMake(JX_SCREEN_WIDTH-64,(JX_SCREEN_HEIGHT>812?44:20), 64, 36);
  56. [rightBtn setTitle:@"完成" forState:UIControlStateNormal];
  57. rightBtn.layer.cornerRadius=5;
  58. rightBtn.layer.masksToBounds=YES;
  59. rightBtn.backgroundColor=[UIColor redColor];
  60. rightBtn.tag =1002;
  61. [rightBtn addTarget:self action:@selector(compleClick) forControlEvents:UIControlEventTouchUpInside];
  62. [navView addSubview:rightBtn];
  63. }
  64. - (void)viewDidLoad {
  65. [super viewDidLoad];
  66. self.view.backgroundColor=[UIColor whiteColor];
  67. self.navigationItem.title=@"选择联系人";
  68. [self defineNavBarXXX:@"选择联系人" andRinghtBtnImg:@"1000"];
  69. _dataArr2=[NSMutableArray array];
  70. _dataArrUserId=[NSMutableArray array];
  71. _chatVc=[JXChatViewController new];
  72. _dataArrUserIdIndex=[NSMutableArray array];
  73. _selectDictM=[NSMutableDictionary dictionary];
  74. //新选中的UIserId
  75. _selectUserIdArr=[NSMutableArray array];
  76. //初始化数据
  77. // [self initDataSource];
  78. self.sectionTitleView = ({
  79. UILabel *sectionTitleView = [[UILabel alloc] initWithFrame:CGRectMake((APP_WIDTH-100)/2, (APP_HEIGHT-100)/2,100,100)];
  80. sectionTitleView.textAlignment = NSTextAlignmentCenter;
  81. sectionTitleView.font = [UIFont boldSystemFontOfSize:60];
  82. sectionTitleView.textColor = [UIColor blueColor];
  83. sectionTitleView.backgroundColor = [UIColor greenColor];
  84. sectionTitleView.layer.cornerRadius = 6;
  85. sectionTitleView.layer.borderWidth = 1.f/[UIScreen mainScreen].scale;
  86. _sectionTitleView.layer.borderColor = [UIColor groupTableViewBackgroundColor].CGColor;
  87. sectionTitleView;
  88. });
  89. [self.navigationController.view addSubview:self.sectionTitleView];
  90. self.sectionTitleView.hidden = YES;
  91. __block NSUInteger aaa=0;
  92. NSMutableArray *tempArr=[NSMutableArray array];
  93. [_dataArr enumerateObjectsUsingBlock:^(memberData * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  94. if (obj.userId==[g_server.myself.userId longLongValue]) {
  95. aaa=idx;
  96. }else{
  97. [tempArr addObject:obj];
  98. }
  99. NSString *nameL=obj.userNickName;
  100. [_dataArr2 addObject:nameL];
  101. }];
  102. NSArray *stringsToSort = [NSArray arrayWithObjects: @"world",@"b1", nil];
  103. stringsToSort=[_dataArr2 copy];
  104. //数组模型拼音分组
  105. _dataArr=tempArr;
  106. _letterResultArr = [JXChatChineseString LetterSortArray:_dataArr];
  107. _indexArray=[NSMutableArray array];
  108. [_letterResultArr enumerateObjectsUsingBlock:^(NSArray * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  109. [obj enumerateObjectsUsingBlock:^(NSDictionary * _Nonnull dict, NSUInteger idx, BOOL * _Nonnull stop) {
  110. [_indexArray addObject:dict[@"title"]];
  111. }];
  112. }];
  113. _indexArray = [JXChatChineseString IndexArray:_indexArray];
  114. UITableView *tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, JX_SCREEN_TOP, JX_SCREEN_WIDTH, JX_SCREEN_HEIGHT-JX_SCREEN_TOP) style:UITableViewStylePlain];
  115. tableView.delegate=self;
  116. tableView.dataSource=self;
  117. [self.view addSubview:tableView];
  118. self.tableView=tableView;
  119. tableView.tableFooterView=[UIView new];
  120. [tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"];
  121. // -(void)UserRoomAttentionLookattention:(NSString *)salt userId:(NSString *)userId jid:(NSString *)jid attentionUserId:(NSString *)attentionUserId andToView:(id)toView;
  122. long time = (long)[[NSDate date] timeIntervalSince1970];
  123. time = (time *1000 + g_server.timeDifference);
  124. NSString *salt = [NSString stringWithFormat:@"%ld", time];
  125. [g_server UserRoomAttentionLookattention:salt userId:g_server.myself.userId jid:_roomID andToView:self];
  126. }
  127. /**
  128. * tableView Data
  129. */
  130. -(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
  131. {
  132. return self.indexArray;
  133. }
  134. - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
  135. NSString *key = [self.indexArray objectAtIndex:section];
  136. return key;
  137. }
  138. - (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index {
  139. [self showSectionTitle:title];
  140. return index;
  141. }
  142. #pragma mark - private
  143. - (void)setBlock:(successBtcaaaBlock)block{
  144. _block = block;
  145. }
  146. - (void)timerHandler:(NSTimer *)sender
  147. {
  148. dispatch_async(dispatch_get_main_queue(), ^{
  149. [UIView animateWithDuration:.3 animations:^{
  150. self.sectionTitleView.alpha = 0;
  151. } completion:^(BOOL finished) {
  152. self.sectionTitleView.hidden = YES;
  153. }];
  154. });
  155. }
  156. -(void)showSectionTitle:(NSString*)title{
  157. [self.sectionTitleView setText:title];
  158. self.sectionTitleView.hidden = NO;
  159. self.sectionTitleView.alpha = 1;
  160. [self.timer invalidate];
  161. self.timer = nil;
  162. self.timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timerHandler:) userInfo:nil repeats:NO];
  163. [[NSRunLoop currentRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes];
  164. }
  165. -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  166. {
  167. UIView *titleView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH, 20)];
  168. titleView.backgroundColor = kRGBColor246;
  169. UILabel *lab = [[UILabel alloc]initWithFrame:CGRectMake(20, 5, JX_SCREEN_WIDTH-40, 20)];
  170. lab.text = [self.indexArray objectAtIndex:section];
  171. lab.font=[UIFont systemFontOfSize:15 weight:UIFontWeightMedium];
  172. lab.textColor = kRGBColor51;
  173. [titleView addSubview:lab];
  174. return titleView;
  175. }
  176. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  177. {
  178. return 65.0;
  179. }
  180. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  181. {
  182. return [self.indexArray count];
  183. }
  184. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  185. {
  186. NSArray *secondArr = [self.letterResultArr objectAtIndex:section];
  187. return secondArr.count;
  188. }
  189. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  190. {
  191. JXChatGuanZhuCell *cell = [JXChatGuanZhuCell cellWithTableView:tableView];
  192. NSDictionary *dict= [[self.letterResultArr objectAtIndex:indexPath.section]objectAtIndex:indexPath.row];
  193. memberData *dictUser=dict[@"model"];
  194. if ([_UserId longLongValue]==dictUser.userId) {
  195. [tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:indexPath.row inSection:0] animated:YES scrollPosition:UITableViewScrollPositionNone];
  196. _selctIndexPath=[NSString stringWithFormat:@"%ld",dictUser.userId];
  197. _dictUser=dictUser;
  198. }
  199. cell.model = dictUser;
  200. return cell;
  201. }
  202. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  203. {
  204. JXChatGuanZhuCell *cell = [tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section]];
  205. NSDictionary *dictM= [[self.letterResultArr objectAtIndex:indexPath.section]objectAtIndex:indexPath.row];
  206. memberData *dictUser=dictM[@"model"];
  207. _selctIndexPath=[NSString stringWithFormat:@"%ld",dictUser.userId];
  208. dictUser.clicked = !dictUser.clicked;
  209. _dictUser=dictUser;
  210. // cell.model = dictUser;
  211. _selctIndexPath=[NSString stringWithFormat:@"%ld",dictUser.userId];
  212. }
  213. /** 完成*/
  214. - (void)compleClick{
  215. if (_selctIndexPath.length==0) {
  216. [SVProgressHUD showWithStatus:@"您还没有选择关心的好友呢"];
  217. [SVProgressHUD dismissWithDelay:0.8];
  218. return;
  219. }
  220. // JXChatViewController *vcha=[JXChatViewController new];
  221. // [vcha showBack:_dictUser];
  222. [SVProgressHUD show];
  223. long time = (long)[[NSDate date] timeIntervalSince1970];
  224. time = (time *1000 + g_server.timeDifference);
  225. NSString *salt = [NSString stringWithFormat:@"%ld", time];
  226. [g_server UserRoomAttentionListion:salt userId:g_server.myself.userId jid:_roomID attentionUserId:_selctIndexPath andToView:self];
  227. }
  228. #pragma mark -------------------服务器返回数据--------------------
  229. -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{
  230. [SVProgressHUD dismiss];
  231. if ([aDownload.action isEqualToString:act_UserRoomListAttenion])
  232. {
  233. if (_block) {
  234. _block(_dictUser);
  235. }
  236. [g_navigation dismissViewController:self animated:NO];
  237. }
  238. if ([aDownload.action isEqualToString:act_UserRoomManyLookAttenion])
  239. {
  240. NSArray *userIDArr=dict[@"attentionUserIds"];
  241. NSLog(@"--- %@ - userId %@",dict,userIDArr);
  242. [_dataArr enumerateObjectsUsingBlock:^(memberData * _Nonnull dataModel, NSUInteger idx, BOOL * _Nonnull stop) {
  243. [userIDArr enumerateObjectsUsingBlock:^(NSString *_Nonnull objStr, NSUInteger idx, BOOL * _Nonnull stop) {
  244. if (dataModel.userId == [objStr longLongValue]) {
  245. dataModel.clicked = !dataModel.clicked;
  246. //cell.model = dictUser;
  247. [_dataArrUserId addObject:objStr];
  248. }
  249. }];
  250. }];
  251. [self.tableView reloadData];
  252. }
  253. }
  254. -(int) didServerResultFailed:(JXConnection*)aDownload dict:(NSDictionary*)dict{
  255. [SVProgressHUD dismiss];
  256. NSString * errorCode = [NSString stringWithFormat:@"%@",[dict objectForKey:@"resultMsg"]];
  257. if([errorCode isEqualToString:@"权限验证失败"])
  258. {
  259. if ([aDownload.action isEqualToString:act_UserRoomAttentionattention])
  260. {
  261. }
  262. }
  263. return [errorCode intValue];
  264. }
  265. @end