// // JxChatGetNoticePersonVc.m // shiku_im // // Created by 123 on 2020/5/22. // Copyright © 2020 Reese. All rights reserved. // #import "JxChatGetNoticePersonGVc.h" #import "JXChatGuanZhuCell.h" #import "UIBarButtonItem+XMGExtension.h" #import "JXChatGuanZhuCell.h" #import "JXChatViewController.h" #define APP_WIDTH [[UIScreen mainScreen]applicationFrame].size.width #define APP_HEIGHT [[UIScreen mainScreen]applicationFrame].size.height #import "JXChatChineseString.h" @interface JxChatGetNoticePersonGVc () @property(nonatomic,strong)NSMutableArray *indexArray; @property(nonatomic,strong)NSMutableArray *letterResultArr; @property (nonatomic, strong) UILabel *sectionTitleView; @property (nonatomic, strong) NSTimer *timer; @property (nonatomic,weak) UITableView *tableView; @property (nonatomic,strong) NSMutableArray *dataArr2; /** 勾选关注的 数组 */ @property (nonatomic,strong) memberData *dictUser; @property (nonatomic,strong) JXChatViewController *chatVc; @property (nonatomic,strong) NSMutableArray *dataArrUserId; @property (nonatomic,strong) NSMutableArray *dataArrUserIdIndex; @property (nonatomic,strong) NSMutableArray *selectUserIdArr; @property (nonatomic,strong) NSMutableDictionary *selectDictM; @property (nonatomic,copy) NSString *selctIndexPath; @end @implementation JxChatGetNoticePersonGVc - (void)gclick{ [g_navigation dismissViewController:self animated:YES]; } - (void)defineNavBarXXX:(NSString *)title andRinghtBtnImg:(NSString *)image { UIView *navView = [[UIView alloc] init]; [self.view addSubview:navView]; navView.frame = CGRectMake(0, 0, JX_SCREEN_WIDTH,JX_SCREEN_TOP); UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom]; backBtn.frame = CGRectMake(0,JX_SCREEN_HEIGHT>812?44:20,44, 44); [backBtn setImage:[UIImage imageNamed:@"photo_title_back_black"] forState:0]; backBtn.tag = 1001; [backBtn addTarget:self action:@selector(gclick) forControlEvents:UIControlEventTouchUpInside]; [navView addSubview:backBtn]; UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(50,(JX_SCREEN_HEIGHT>812?44:20), JX_SCREEN_WIDTH-100, 44)]; label.text = title; label.textColor = kRGBColor51; navView.backgroundColor = [UIColor whiteColor]; label.font = [UIFont systemFontOfSize:18 weight:UIFontWeightRegular]; label.textAlignment = NSTextAlignmentCenter; [navView addSubview:label]; UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom]; rightBtn.frame = CGRectMake(JX_SCREEN_WIDTH-64,(JX_SCREEN_HEIGHT>812?44:20), 64, 36); [rightBtn setTitle:@"完成" forState:UIControlStateNormal]; rightBtn.layer.cornerRadius=5; rightBtn.layer.masksToBounds=YES; rightBtn.backgroundColor=[UIColor redColor]; rightBtn.tag =1002; [rightBtn addTarget:self action:@selector(compleClick) forControlEvents:UIControlEventTouchUpInside]; [navView addSubview:rightBtn]; } - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor=[UIColor whiteColor]; self.navigationItem.title=@"选择联系人"; [self defineNavBarXXX:@"选择联系人" andRinghtBtnImg:@"1000"]; _dataArr2=[NSMutableArray array]; _dataArrUserId=[NSMutableArray array]; _chatVc=[JXChatViewController new]; _dataArrUserIdIndex=[NSMutableArray array]; _selectDictM=[NSMutableDictionary dictionary]; //新选中的UIserId _selectUserIdArr=[NSMutableArray array]; //初始化数据 // [self initDataSource]; self.sectionTitleView = ({ UILabel *sectionTitleView = [[UILabel alloc] initWithFrame:CGRectMake((APP_WIDTH-100)/2, (APP_HEIGHT-100)/2,100,100)]; sectionTitleView.textAlignment = NSTextAlignmentCenter; sectionTitleView.font = [UIFont boldSystemFontOfSize:60]; sectionTitleView.textColor = [UIColor blueColor]; sectionTitleView.backgroundColor = [UIColor greenColor]; sectionTitleView.layer.cornerRadius = 6; sectionTitleView.layer.borderWidth = 1.f/[UIScreen mainScreen].scale; _sectionTitleView.layer.borderColor = [UIColor groupTableViewBackgroundColor].CGColor; sectionTitleView; }); [self.navigationController.view addSubview:self.sectionTitleView]; self.sectionTitleView.hidden = YES; __block NSUInteger aaa=0; NSMutableArray *tempArr=[NSMutableArray array]; [_dataArr enumerateObjectsUsingBlock:^(memberData * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { if (obj.userId==[g_server.myself.userId longLongValue]) { aaa=idx; }else{ [tempArr addObject:obj]; } NSString *nameL=obj.userNickName; [_dataArr2 addObject:nameL]; }]; NSArray *stringsToSort = [NSArray arrayWithObjects: @"world",@"b1", nil]; stringsToSort=[_dataArr2 copy]; //数组模型拼音分组 _dataArr=tempArr; _letterResultArr = [JXChatChineseString LetterSortArray:_dataArr]; _indexArray=[NSMutableArray array]; [_letterResultArr enumerateObjectsUsingBlock:^(NSArray * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { [obj enumerateObjectsUsingBlock:^(NSDictionary * _Nonnull dict, NSUInteger idx, BOOL * _Nonnull stop) { [_indexArray addObject:dict[@"title"]]; }]; }]; _indexArray = [JXChatChineseString IndexArray:_indexArray]; UITableView *tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, JX_SCREEN_TOP, JX_SCREEN_WIDTH, JX_SCREEN_HEIGHT-JX_SCREEN_TOP) style:UITableViewStylePlain]; tableView.delegate=self; tableView.dataSource=self; [self.view addSubview:tableView]; self.tableView=tableView; tableView.tableFooterView=[UIView new]; [tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"]; // -(void)UserRoomAttentionLookattention:(NSString *)salt userId:(NSString *)userId jid:(NSString *)jid attentionUserId:(NSString *)attentionUserId andToView:(id)toView; long time = (long)[[NSDate date] timeIntervalSince1970]; time = (time *1000 + g_server.timeDifference); NSString *salt = [NSString stringWithFormat:@"%ld", time]; [g_server UserRoomAttentionLookattention:salt userId:g_server.myself.userId jid:_roomID andToView:self]; } /** * tableView Data */ -(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView { return self.indexArray; } - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { NSString *key = [self.indexArray objectAtIndex:section]; return key; } - (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index { [self showSectionTitle:title]; return index; } #pragma mark - private - (void)setBlock:(successBtcaaaBlock)block{ _block = block; } - (void)timerHandler:(NSTimer *)sender { dispatch_async(dispatch_get_main_queue(), ^{ [UIView animateWithDuration:.3 animations:^{ self.sectionTitleView.alpha = 0; } completion:^(BOOL finished) { self.sectionTitleView.hidden = YES; }]; }); } -(void)showSectionTitle:(NSString*)title{ [self.sectionTitleView setText:title]; self.sectionTitleView.hidden = NO; self.sectionTitleView.alpha = 1; [self.timer invalidate]; self.timer = nil; self.timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timerHandler:) userInfo:nil repeats:NO]; [[NSRunLoop currentRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes]; } -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { UIView *titleView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH, 20)]; titleView.backgroundColor = kRGBColor246; UILabel *lab = [[UILabel alloc]initWithFrame:CGRectMake(20, 5, JX_SCREEN_WIDTH-40, 20)]; lab.text = [self.indexArray objectAtIndex:section]; lab.font=[UIFont systemFontOfSize:15 weight:UIFontWeightMedium]; lab.textColor = kRGBColor51; [titleView addSubview:lab]; return titleView; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 65.0; } -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return [self.indexArray count]; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { NSArray *secondArr = [self.letterResultArr objectAtIndex:section]; return secondArr.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { JXChatGuanZhuCell *cell = [JXChatGuanZhuCell cellWithTableView:tableView]; NSDictionary *dict= [[self.letterResultArr objectAtIndex:indexPath.section]objectAtIndex:indexPath.row]; memberData *dictUser=dict[@"model"]; if ([_UserId longLongValue]==dictUser.userId) { [tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:indexPath.row inSection:0] animated:YES scrollPosition:UITableViewScrollPositionNone]; _selctIndexPath=[NSString stringWithFormat:@"%ld",dictUser.userId]; _dictUser=dictUser; } cell.model = dictUser; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { JXChatGuanZhuCell *cell = [tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section]]; NSDictionary *dictM= [[self.letterResultArr objectAtIndex:indexPath.section]objectAtIndex:indexPath.row]; memberData *dictUser=dictM[@"model"]; _selctIndexPath=[NSString stringWithFormat:@"%ld",dictUser.userId]; dictUser.clicked = !dictUser.clicked; _dictUser=dictUser; // cell.model = dictUser; _selctIndexPath=[NSString stringWithFormat:@"%ld",dictUser.userId]; } /** 完成*/ - (void)compleClick{ if (_selctIndexPath.length==0) { [SVProgressHUD showWithStatus:@"您还没有选择关心的好友呢"]; [SVProgressHUD dismissWithDelay:0.8]; return; } // JXChatViewController *vcha=[JXChatViewController new]; // [vcha showBack:_dictUser]; [SVProgressHUD show]; long time = (long)[[NSDate date] timeIntervalSince1970]; time = (time *1000 + g_server.timeDifference); NSString *salt = [NSString stringWithFormat:@"%ld", time]; [g_server UserRoomAttentionListion:salt userId:g_server.myself.userId jid:_roomID attentionUserId:_selctIndexPath andToView:self]; } #pragma mark -------------------服务器返回数据-------------------- -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{ [SVProgressHUD dismiss]; if ([aDownload.action isEqualToString:act_UserRoomListAttenion]) { if (_block) { _block(_dictUser); } [g_navigation dismissViewController:self animated:NO]; } if ([aDownload.action isEqualToString:act_UserRoomManyLookAttenion]) { NSArray *userIDArr=dict[@"attentionUserIds"]; NSLog(@"--- %@ - userId %@",dict,userIDArr); [_dataArr enumerateObjectsUsingBlock:^(memberData * _Nonnull dataModel, NSUInteger idx, BOOL * _Nonnull stop) { [userIDArr enumerateObjectsUsingBlock:^(NSString *_Nonnull objStr, NSUInteger idx, BOOL * _Nonnull stop) { if (dataModel.userId == [objStr longLongValue]) { dataModel.clicked = !dataModel.clicked; //cell.model = dictUser; [_dataArrUserId addObject:objStr]; } }]; }]; [self.tableView reloadData]; } } -(int) didServerResultFailed:(JXConnection*)aDownload dict:(NSDictionary*)dict{ [SVProgressHUD dismiss]; NSString * errorCode = [NSString stringWithFormat:@"%@",[dict objectForKey:@"resultMsg"]]; if([errorCode isEqualToString:@"权限验证失败"]) { if ([aDownload.action isEqualToString:act_UserRoomAttentionattention]) { } } return [errorCode intValue]; } @end