123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367 |
- //
- // 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 ()<UITableViewDelegate,UITableViewDataSource>
- @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 (dictUser.clicked) {
- [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
|