// // JXCsHomeVc.m // shiku_im // // Created by 123 on 2020/4/28. // Copyright © 2020 Reese. All rights reserved. // (@"JXMainViewController_Message") PSMyViewController #import "JXCsHomeVc.h" #import "UIView+LK.h" #import "CYWebAddPointVC.h" #import "XMGMainViewController.h" #import "JXShowMainView.h" #import "YPTabBarController.h" #import "JXProgressVC.h" #import "JXLabelObject.h" #import "JXXMPP.h" #import "JXProgressVC.h" #import "JXGroupViewController.h" #import "OrganizTreeViewController.h" #import "JXLabelObject.h" #import "JXBlogRemind.h" #import "JXRoomPool.h" #import "JXDeviceAuthController.h" #import "UIColor+Util.h" #import "UIColor+XQColor.h" #import "JXBlogRemind.h" @interface JXCsHomeVc () /** 标签栏底部的红色指示器 */ @property (nonatomic, weak) UIView *indicatorView; /** 当前选中的按钮 */ @property (nonatomic, weak) UIButton *selectedButton; @property (nonatomic, weak) UIButton *button_n; @property (nonatomic,copy) NSString *linkName1; @property (nonatomic,copy) NSString *linkURL1; @property (nonatomic,copy) NSString *imgUrl1; @property (weak, nonatomic) UIView *sliderView; @property (strong, nonatomic) MASConstraint *sliderViewCenterX; @property (weak, nonatomic) UIButton *refreshButton; @property (weak, nonatomic) UIButton *homeButton; @property (nonatomic,strong) NSString *indexGhome; @end @implementation JXCsHomeVc -(instancetype)init{ if (self=[super init]) { [g_notify addObserver:self selector:@selector(onXmppLoginChanged:) name:kXmppLoginNotifaction object:nil]; [g_notify addObserver:self selector:@selector(newMsgCome:) name:kXMPPNewMsgNotifaction object:nil];//收到了一条新消息 [g_notify addObserver:self selector:@selector(hiddenTipLabel:) name:@"hiddenTip" object:nil];//收到了一条新消息 [g_notify addObserver:self selector:@selector(goBack:) name:@"longGoback" object:nil]; } return self; } - (void)hiddenTipLabel:(NSNotification *)note{ self.countTipL.hidden=YES; } - (void)newMsgCome:(NSNotification *)note{ self.countTipL.hidden=NO; } -(void)setStrURL:(NSString *)strURL{ self.countTipL.hidden=YES; } - (void)viewDidAppear:(BOOL)animated{ [super viewDidAppear:animated]; } - (void)viewDidLoad { [super viewDidLoad]; // 获取服务器时间 // [g_server getCurrentTimeToView:self]; // [g_server offlineOperation:(g_server.lastOfflineTime *1000 + g_server.timeDifference)/1000 toView:self]; //NSLog(@"login_%@",g_server.myself.userId); // [g_server getUser:g_server.myself.userId toView:self]; //CGFloat lastOffLineTime=(g_server.lastOfflineTime *1000 + 0)/1000; // CGFloat lastOffLineTime2=(g_server.timeDifference)/1000; [self setupChildViewControllers]; [self setupNavBar]; [self setupContentView]; [self setupTitlesView]; // [self.topButton addTarget:self action:@selector(topBtnClick) forControlEvents:UIControlEventTouchUpInside]; [g_notify addObserver:self selector:@selector(showAD) name:kLaunchAdShowFinishNotifaction object:nil]; [g_notify addObserver:self selector:@selector(changeNodeTitle:) name:@"changeNodeTitleNotifaction" object:nil]; // self.contentView.delaysContentTouches=NO; // self.contentView.canCancelContentTouches=NO; } -(void)onXmppLoginChanged:(NSNumber*)isLogin{ if([JXXMPP sharedInstance].isLogined == login_status_yes){ // 获取离线调用接口列表 //CGFloat lastOffLineTime=(g_server.lastOfflineTime *1000 + 0)/1000; // CGFloat lastOffLineTime2=(g_server.timeDifference)/1000; [g_server offlineOperation:(g_server.lastOfflineTime *1000 + g_server.timeDifference)/1000 toView:self]; [self onAfterLogin]; } } -(void)onAfterLogin{ // [_msgVc scrollToPageUp]; } - (void)showAD { [JXShowMainView showView]; } - (void)dealloc { [g_notify removeObserver:self]; } - (void)setupContentView { UIScrollView *contentView = [[UIScrollView alloc] init]; contentView.backgroundColor = kRGBColor(250, 250, 250); contentView.frame = CGRectMake(0, JX_SCREEN_TOP, self.view.bounds.size.width, self.view.bounds.size.height-JX_SCREEN_TOP); contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; contentView.delegate = self; contentView.showsHorizontalScrollIndicator = NO; contentView.showsVerticalScrollIndicator = NO; contentView.pagingEnabled = YES; contentView.bounces=NO; contentView.contentSize = CGSizeMake(contentView.xmg_width * self.childViewControllers.count, 0); [self.view addSubview:contentView]; self.contentView = contentView; return; id traget = self.navigationController.interactivePopGestureRecognizer.delegate; UIPanGestureRecognizer * pan = [[UIPanGestureRecognizer alloc]initWithTarget:traget action:nil]; [contentView addGestureRecognizer:pan]; UISwipeGestureRecognizer * swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeAction:)]; swipeRight.direction = UISwipeGestureRecognizerDirectionLeft; [contentView addGestureRecognizer:swipeRight]; UISwipeGestureRecognizer * swipeleft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeAction:)]; swipeleft.direction = UISwipeGestureRecognizerDirectionRight; [contentView addGestureRecognizer:swipeleft]; // 手势的优先级 优先响应swipe手势 [pan requireGestureRecognizerToFail:swipeRight]; [pan requireGestureRecognizerToFail:swipeleft]; } -(void)swipeAction:(UISwipeGestureRecognizer *)sender { if (sender.direction ==UISwipeGestureRecognizerDirectionLeft) { int index =1; [self titleClick:self.titlesView.subviews[index]]; [self switchController:index]; }else if(sender.direction ==UISwipeGestureRecognizerDirectionRight){ int index =0; [self titleClick:self.titlesView.subviews[index]]; [self switchController:index]; } } - (void)goBack:(NSNotification *)note{ [self.contentView setContentOffset:CGPointMake(0 * JX_SCREEN_WIDTH, self.contentView.contentOffset.y) animated:YES]; self.selectedButton.enabled = YES; _topButton.enabled = NO; self.selectedButton = _topButton; // 消除约束 [self.sliderViewCenterX uninstall]; self.sliderViewCenterX = nil; // 添加约束 [self.sliderView mas_makeConstraints:^(MASConstraintMaker *make) { self.sliderViewCenterX = make.centerX.equalTo(_topButton); }]; [UIView animateWithDuration:0.25 animations:^{ [self.sliderView layoutIfNeeded]; }]; } -(void)setBlcokBTb:(shuaxinBtn)blcokBTb{ //获取说有群信息 // [g_server listHisRoom:0 pageSize:1000 toView:self]; [self setupChildViewControllers]; [self setupNavBar]; [self setupContentView]; [self setupTitlesView]; _indexGhome=@"1"; int index =0; [self titleClick:self.topButton]; [self switchController:index]; } - (void)goHomeWebPage { [g_notify postNotificationName:KGoHomeWebPageNotification object:nil]; } - (void)goRefreshWebPage { [g_notify postNotificationName:KGoRefreshWebPageNotification object:nil]; } - (void)setupTitlesView { UIView *backView = [[UIView alloc] init]; backView.backgroundColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0]; backView.autoresizingMask = UIViewAutoresizingFlexibleWidth; backView.frame = CGRectMake(0, 0, self.view.frame.size.width, JX_SCREEN_TOP); backView.userInteractionEnabled=YES; [self.view addSubview:backView]; UIButton *homeButton = [UIButton buttonWithType:(UIButtonTypeCustom)]; homeButton.frame =CGRectMake(10, JX_STATUSBAR_H, 30, 30); [homeButton setImage:[UIImage imageNamed:@"home_home"] forState:(UIControlStateNormal)]; [backView addSubview:homeButton]; [homeButton addTarget:self action:@selector(goHomeWebPage) forControlEvents:(UIControlEventTouchUpInside)]; _homeButton = homeButton; UIButton *refreshButton = [UIButton buttonWithType:(UIButtonTypeCustom)]; refreshButton.frame =CGRectMake(JX_SCREEN_WIDTH-100, JX_STATUSBAR_H, 90, 30); [refreshButton setImage:[UIImage imageNamed:@"home_refresh"] forState:(UIControlStateNormal)]; [refreshButton setTitleColor:[UIColor blueColor] forState:(UIControlStateNormal)]; refreshButton.contentMode=UIViewContentModeScaleAspectFit; [backView addSubview:refreshButton]; NSString *selectUrl = [g_default objectForKey:@"selectNodeName"]; if (selectUrl.length>0) { [refreshButton setTitle:selectUrl forState:(UIControlStateNormal)]; }else{ [refreshButton setTitle:@" 节点1 " forState:(UIControlStateNormal)]; } //[refreshButton setTitleEdgeInsets:UIEdgeInsetsMake(0, 60, 0, 0)]; //[refreshButton setImageEdgeInsets:UIEdgeInsetsMake(0, 50, 0, 0)]; //[refreshButton setTitleEdgeInsets:UIEdgeInsetsMake(0, 0,0,60)]; [refreshButton addTarget:self action:@selector(goRefreshWebPage) forControlEvents:(UIControlEventTouchUpInside)]; _refreshButton = refreshButton; UIView *titlesView = [[UIView alloc] init]; titlesView.backgroundColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0]; titlesView.autoresizingMask = UIViewAutoresizingFlexibleWidth; titlesView.frame = CGRectMake(self.view.frame.size.width/3, 0, self.view.frame.size.width/3, JX_SCREEN_TOP); [backView addSubview:titlesView]; self.titlesView = titlesView; // 5个按钮 XMGTitleButton *button = [self setupTitleButton:@"购彩"]; [self setupTitleButton:@"聊天"]; [self titleClick:button]; [self switchController:0]; self.topButton=button; // 底部滑条 UIView *sliderView = [[UIView alloc] init]; sliderView.backgroundColor = [UIColor redColor]; [self.titlesView addSubview:sliderView]; self.sliderView = sliderView; [sliderView mas_makeConstraints:^(MASConstraintMaker *make) { make.size.mas_equalTo(CGSizeMake([[button titleForState:UIControlStateNormal] sizeWithAttributes:@{NSFontAttributeName : button.titleLabel.font}].width/1.5, 3)); make.bottom.mas_equalTo(self.titlesView.mas_bottom).mas_offset(-4); self.sliderViewCenterX = make.centerX.equalTo(button); }]; UILabel *tipLable=[[UILabel alloc]init]; tipLable.backgroundColor=[UIColor redColor]; tipLable.layer.cornerRadius=4; tipLable.layer.masksToBounds=YES; [titlesView addSubview:tipLable]; tipLable.hidden=YES; self.countTipL=tipLable; [tipLable mas_makeConstraints:^(MASConstraintMaker *make) { make.width.mas_equalTo(8); make.height.mas_equalTo(8); make.top.mas_equalTo(JX_SCREEN_HEIGHT>=812?49:25); make.left.mas_equalTo(self.titlesView.xmg_width-15); }]; } - (void)changeNodeTitle:(NSNotification *)note{ NSString *nodeStr=note.object; _refreshButton.frame =CGRectMake(JX_SCREEN_WIDTH-100, JX_STATUSBAR_H, 90, 30); [_refreshButton setImage:[UIImage imageNamed:@"home_refresh"] forState:(UIControlStateNormal)]; _refreshButton.contentMode=UIViewContentModeScaleAspectFit; [_refreshButton setTitle:[NSString stringWithFormat:@" %@ ",nodeStr] forState:(UIControlStateNormal)]; } - (XMGTitleButton *)setupTitleButton:(NSString *)title { XMGTitleButton *button = [XMGTitleButton buttonWithType:UIButtonTypeCustom]; [button setTitle:title forState:UIControlStateNormal]; [button addTarget:self action:@selector(titleClick:) forControlEvents:UIControlEventTouchUpInside]; [self.titlesView addSubview:button]; self.topButton=button; [button mas_makeConstraints:^(MASConstraintMaker *make) { make.width.mas_equalTo(self.titlesView.xmg_width/2); make.top.mas_equalTo(JX_SCREEN_HEIGHT>=812?44:20); NSUInteger index = self.titlesView.subviews.count - 1; if (index == 0) { make.left.mas_equalTo(self.titlesView); } else { make.left.mas_equalTo(self.titlesView.xmg_width/2); } }]; return button; } - (void)titleClick:(UIButton *)button { self.selectedButton.enabled = YES; button.enabled = NO; self.selectedButton = button; // 消除约束 [self.sliderViewCenterX uninstall]; self.sliderViewCenterX = nil; // 添加约束 [self.sliderView mas_makeConstraints:^(MASConstraintMaker *make) { self.sliderViewCenterX = make.centerX.equalTo(button); }]; [UIView animateWithDuration:0.25 animations:^{ [self.sliderView layoutIfNeeded]; }]; if ([_indexGhome isEqualToString:@"1"]) { [self.contentView setContentOffset:CGPointMake(0 * self.contentView.frame.size.width, self.contentView.contentOffset.y) animated:YES]; }else{ int index = (int)[self.titlesView.subviews indexOfObject:button]; [self.contentView setContentOffset:CGPointMake(index * self.contentView.frame.size.width, self.contentView.contentOffset.y) animated:YES]; } } - (void)setupNavBar { self.automaticallyAdjustsScrollViewInsets = NO; } - (void)setupChildViewControllers { CYWebAddPointVC *vc = [[CYWebAddPointVC alloc] init]; NSString *memberAcc=[[NSUserDefaults standardUserDefaults] objectForKey:@"www_url"]; NSString *selectNodeUrl=[[NSUserDefaults standardUserDefaults] objectForKey:@"selectNodeUrl"]; if (selectNodeUrl.length>0) { vc.strURL=selectNodeUrl; }else{ vc.strURL=memberAcc; } [self addChildViewController:vc]; [self addChildViewController:[XMGMainViewController new]]; return; [self setupOneChildViewController:vc]; [self setupOneChildViewController:[XMGMainViewController new]]; } - (void)setupOneChildViewController:(UIViewController *)type { if([type isKindOfClass:[CYWebAddPointVC class]]){ CYWebAddPointVC *vc = [[CYWebAddPointVC alloc] init]; NSString *memberAcc=[[NSUserDefaults standardUserDefaults] objectForKey:@"www_url"]; NSString *selectNodeUrl=[[NSUserDefaults standardUserDefaults] objectForKey:@"selectNodeUrl"]; if (selectNodeUrl.length>0) { vc.strURL=selectNodeUrl; }else{ vc.strURL=memberAcc; } [self addChildViewController:vc]; }else{ // XMGTabarVC JXXMMainVc。XMGMainViewController JXXMMainVc XMGMainViewController *vc = [[XMGMainViewController alloc] init]; [self addChildViewController:vc]; } } - (void)switchController:(int)index { [g_notify postNotificationName:@"KOPENLONG" object:@(index)]; if (index == 1) { _homeButton.hidden = YES; _refreshButton.hidden = YES; }else { _homeButton.hidden = NO; _refreshButton.hidden = NO; } CYWebAddPointVC *vc = self.childViewControllers[index]; vc.view.xmg_y = 0; vc.view.xmg_width = self.contentView.xmg_width; vc.view.xmg_height = self.contentView.xmg_height; vc.view.xmg_x = vc.view.xmg_width * index; [self.contentView addSubview:vc.view]; } #pragma mark - - (void)scrollViewDidEndDecelerating:(nonnull UIScrollView *)scrollView { int index = scrollView.contentOffset.x / scrollView.frame.size.width; // NSString *msgStr=[g_default objectForKey:@"refushMsgHistoryxxx"]; // if (msgStr.length>0) { // // }else{ // // [g_notify postNotificationName:@"refushMsgHistoryxxx" object:nil]; // // [g_default setObject:@"refushMsgHistoryxxx" forKey:@"refushMsgHistoryxxx"]; // [g_default synchronize]; // } [self titleClick:self.titlesView.subviews[index]]; [self switchController:index]; } - (void)scrollViewDidEndScrollingAnimation:(nonnull UIScrollView *)scrollView { int a=(int)(scrollView.contentOffset.x / scrollView.frame.size.width); // NSString *msgStr=[g_default objectForKey:@"refushMsgHistoryxxx"]; // if (msgStr.length>0) { // // }else{ // // [g_notify postNotificationName:@"refushMsgHistoryxxx" object:nil]; // // [g_default setObject:@"refushMsgHistoryxxx" forKey:@"refushMsgHistoryxxx"]; // [g_default synchronize]; // } [self switchController:a]; // } -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{ //更新本地好友 if ([aDownload.action isEqualToString:act_UserGet]) { NSString *memberAcc= dict[@"membershipAccount"]; [[NSUserDefaults standardUserDefaults] setObject:memberAcc forKey:@"membershipAccount_ID"]; [[NSUserDefaults standardUserDefaults] synchronize]; } if ([aDownload.action isEqualToString:act_AttentionList]) { JXProgressVC * pv = [JXProgressVC alloc]; pv.dataArray = array1; pv = [pv init]; if (array1.count > 300) { [g_navigation pushViewController:pv animated:YES]; } // [self.view addSubview:pv.view]; } // 同步标签 if ([aDownload.action isEqualToString:act_FriendGroupList]) { for (NSInteger i = 0; i < array1.count; i ++) { NSDictionary *dict = array1[i]; JXLabelObject *labelObj = [[JXLabelObject alloc] init]; labelObj.groupId = dict[@"groupId"]; labelObj.groupName = dict[@"groupName"]; labelObj.userId = dict[@"userId"]; NSArray *userIdList = dict[@"userIdList"]; NSString *userIdListStr = [userIdList componentsJoinedByString:@","]; if (userIdListStr.length > 0) { labelObj.userIdList = [NSString stringWithFormat:@"%@", userIdListStr]; } [labelObj insert]; } // 删除服务器上已经删除的 NSArray *arr = [[JXLabelObject sharedInstance] fetchAllLabelsFromLocal]; for (NSInteger i = 0; i < arr.count; i ++) { JXLabelObject *locLabel = arr[i]; BOOL flag = NO; for (NSInteger j = 0; j < array1.count; j ++) { NSDictionary * dict = array1[j]; if ([locLabel.groupId isEqualToString:dict[@"groupId"]]) { flag = YES; break; } } if (!flag) { [locLabel delete]; } } } if ([aDownload.action isEqualToString:act_offlineOperation]) { for (NSDictionary *dict in array1) { if ([[dict objectForKey:@"tag"] isEqualToString:@"label"]) { [g_notify postNotificationName:kOfflineOperationUpdateLabelList object:nil]; } else if ([[dict objectForKey:@"tag"] isEqualToString:@"friend"]) { [g_server getUser:[dict objectForKey:@"friendId"] toView:self]; } else if ([[dict objectForKey:@"tag"] isEqualToString:@"room"]) { [g_server getRoom:[dict objectForKey:@"friendId"] toView:self]; } } } if ([aDownload.action isEqualToString:act_UserGet]) { JXUserObject *user = [[JXUserObject alloc] init]; [user getDataFromDict:dict]; NSString *gradeIndexcc= dict[@"gradeIndex"]; [[NSUserDefaults standardUserDefaults] setObject:gradeIndexcc forKey:@"gradeIndexcc"]; [[NSUserDefaults standardUserDefaults] synchronize]; if ([user.userId intValue] == [MY_USER_ID intValue]) { [g_server doSaveUser:dict]; user.bubbleFontId = [dict objectForKey:@"bubbleFontId"]; user.gradeIndex = [dict objectForKey:@"gradeIndex"]; // 保存自己 [user insert]; [user update]; }else { JXUserObject *user1 = [[JXUserObject sharedInstance] getUserById:user.userId]; user.content = user1.content; user.timeSend = user1.timeSend; [user update]; } [g_notify postNotificationName:kOfflineOperationUpdateUserSet object:user]; } if ([aDownload.action isEqualToString:act_roomGet]) { JXUserObject *user = [[JXUserObject alloc] init]; [user getDataFromDict:dict]; user.userId = [dict objectForKey:@"jid"]; user.roomId = [dict objectForKey:@"id"]; user.userNickname = [dict objectForKey:@"name"]; if(![g_xmpp.roomPool getRoom:user.userId] || ![user haveTheUser]){ user.userDescription = [dict objectForKey:@"desc"]; user.showRead = [dict objectForKey:@"showRead"]; user.showMember = [dict objectForKey:@"showMember"]; user.allowSendCard = [dict objectForKey:@"allowSendCard"]; user.chatRecordTimeOut = [dict objectForKey:@"chatRecordTimeOut"]; user.talkTime = [dict objectForKey:@"talkTime"]; user.allowInviteFriend = [dict objectForKey:@"allowInviteFriend"]; user.allowUploadFile = [dict objectForKey:@"allowUploadFile"]; user.allowConference = [dict objectForKey:@"allowConference"]; user.allowSpeakCourse = [dict objectForKey:@"allowSpeakCourse"]; user.offlineNoPushMsg = [(NSDictionary *)[dict objectForKey:@"member"] objectForKey:@"offlineNoPushMsg"]; user.isNeedVerify = [dict objectForKey:@"isNeedVerify"]; user.createUserId = [dict objectForKey:@"userId"]; user.content = @" "; user.topTime = nil; [user insertRoom]; // [g_xmpp.roomPool joinRoom:user.userId title:user.userNickname lastDate:nil isNew:NO]; }else { NSDictionary * groupDict = [user toDictionary]; roomData * roomdata = [[roomData alloc] init]; [roomdata getDataFromDict:groupDict]; [roomdata getDataFromDict:dict]; JXUserObject *user1 = [[JXUserObject sharedInstance] getUserById:roomdata.roomJid]; user.content = user1.content; user.status = user1.status; user.offlineNoPushMsg = [NSNumber numberWithBool:roomdata.offlineNoPushMsg]; user.msgsNew = user1.msgsNew; [user update]; } [g_notify postNotificationName:kOfflineOperationUpdateUserSet object:user]; } } -(int) didServerResultFailed:(JXConnection*)aDownload dict:(NSDictionary*)dict{ return hide_error; } -(int) didServerConnectError:(JXConnection*)aDownload error:(NSError *)error{//error为空时,代表超时 return hide_error; } @end