JXCsHomeVc.m 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769
  1. //
  2. // JXCsHomeVc.m
  3. // shiku_im
  4. //
  5. // Created by 123 on 2020/4/28.
  6. // Copyright © 2020 Reese. All rights reserved.
  7. // (@"JXMainViewController_Message") PSMyViewController
  8. #import "JXCsHomeVc.h"
  9. #import "UIView+LK.h"
  10. #import "CYWebAddPointVC.h"
  11. #import "XMGMainViewController.h"
  12. #import "JXShowMainView.h"
  13. #import "YPTabBarController.h"
  14. #import "JXProgressVC.h"
  15. #import "JXLabelObject.h"
  16. #import "JXXMPP.h"
  17. #import "JXProgressVC.h"
  18. #import "JXGroupViewController.h"
  19. #import "OrganizTreeViewController.h"
  20. #import "JXLabelObject.h"
  21. #import "JXBlogRemind.h"
  22. #import "JXRoomPool.h"
  23. #import "JXDeviceAuthController.h"
  24. #import "UIColor+Util.h"
  25. #import "UIColor+XQColor.h"
  26. #import "JXBlogRemind.h"
  27. @interface JXCsHomeVc ()<UIScrollViewDelegate>
  28. /** 标签栏底部的红色指示器 */
  29. @property (nonatomic, weak) UIView *indicatorView;
  30. /** 当前选中的按钮 */
  31. @property (nonatomic, weak) UIButton *selectedButton;
  32. @property (nonatomic, weak) UIButton *button_n;
  33. @property (nonatomic,copy) NSString *linkName1;
  34. @property (nonatomic,copy) NSString *linkURL1;
  35. @property (nonatomic,copy) NSString *imgUrl1;
  36. @property (weak, nonatomic) UIView *sliderView;
  37. @property (strong, nonatomic) MASConstraint *sliderViewCenterX;
  38. @property (weak, nonatomic) UIButton *refreshButton;
  39. @property (weak, nonatomic) UIButton *homeButton;
  40. @property (nonatomic,strong) NSString *indexGhome;
  41. @end
  42. @implementation JXCsHomeVc
  43. -(instancetype)init{
  44. if (self=[super init]) {
  45. NSInteger fectfriends = [g_server.myself fetchAllFriends].count;
  46. self.isLoadFriendAndGroup = [g_server.myself fetchAllFriends].count < 6;
  47. [g_notify addObserver:self selector:@selector(onXmppLoginChanged:) name:kXmppLoginNotifaction object:nil];
  48. [g_notify addObserver:self selector:@selector(newMsgCome:) name:kXMPPNewMsgNotifaction object:nil];//收到了一条新消息
  49. [g_notify addObserver:self selector:@selector(hiddenTipLabel:) name:@"hiddenTip" object:nil];//收到了一条新消息
  50. [g_notify addObserver:self selector:@selector(goBack:) name:@"longGoback" object:nil];
  51. [g_notify addObserver:self selector:@selector(loginSynchronizeFriends:) name:kXmppClickLoginNotifaction object:nil];
  52. [g_notify addObserver:self selector:@selector(appDidEnterForeground) name:kApplicationWillEnterForeground object:nil];
  53. [g_notify addObserver:self selector:@selector(getUserInfo:) name:kXMPPMessageUpadteUserInfoNotification object:nil];
  54. [g_notify addObserver:self selector:@selector(getRoomSet:) name:kXMPPMessageUpadteGroupNotification object:nil];
  55. [g_notify addObserver:self selector:@selector(onXmppLoginChanged:) name:kXmppLoginNotifaction object:nil];
  56. [g_notify addObserver:self selector:@selector(hasLoginOther:) name:kXMPPLoginOtherNotification object:nil];
  57. [g_notify addObserver:self selector:@selector(showDeviceAuth:) name:kDeviceAuthNotification object:nil];
  58. }
  59. return self;
  60. }
  61. - (void)appDidEnterForeground {
  62. // 获取服务器时间
  63. [g_server getCurrentTimeToView:self];
  64. }
  65. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
  66. if (alertView.tag == 10002) {
  67. [g_server performSelector:@selector(showLogin) withObject:nil afterDelay:0.5];
  68. return;
  69. }else if (buttonIndex == 1) {
  70. [g_server listAttention:0 userId:MY_USER_ID toView:self];
  71. }
  72. }
  73. - (void)showDeviceAuth:(NSNotification *)notification{
  74. JXMessageObject *msg = notification.object;
  75. JXDeviceAuthController *authCon = [[JXDeviceAuthController alloc] initWithMsg:msg];
  76. // [self presentViewController:authCon animated:YES completion:nil];
  77. UIViewController *lastVC = (UIViewController *)g_navigation.subViews.lastObject;
  78. [lastVC presentViewController:authCon animated:YES completion:nil];
  79. }
  80. -(void)hasLoginOther:(NSNotification *)notifcation{
  81. [g_App showAlert:Localized(@"JXXMPP_Other") delegate:self tag:10002 onlyConfirm:YES];
  82. }
  83. - (void)appEnterForegroundNotif:(NSNotification *)noti {
  84. // [g_server offlineOperation:(g_server.lastOfflineTime *1000 + g_server.timeDifference)/1000 toView:self];
  85. }
  86. - (void)getUserInfo:(NSNotification *)noti {
  87. JXMessageObject *msg = noti.object;
  88. [g_server getUser:msg.toUserId toView:self];
  89. }
  90. - (void)getRoomSet:(NSNotification *)noti {
  91. JXMessageObject *msg = noti.object;
  92. [g_server getRoom:msg.toUserId toView:self];
  93. }
  94. - (void)hiddenTipLabel:(NSNotification *)note{
  95. self.countTipL.hidden=YES;
  96. }
  97. - (void)newMsgCome:(NSNotification *)note{
  98. self.countTipL.hidden=NO;
  99. }
  100. -(void)setStrURL:(NSString *)strURL{
  101. self.countTipL.hidden=YES;
  102. }
  103. - (void)viewDidAppear:(BOOL)animated{
  104. [super viewDidAppear:animated];
  105. }
  106. - (void)viewDidLoad {
  107. [super viewDidLoad];
  108. //[self loginSynchronizeFriends:nil];
  109. if (g_server.loginOfflineTime>0) {
  110. [g_server offlineOperation:g_server.loginOfflineTime toView:self];
  111. }else{
  112. NSTimeInterval interval = [[NSDate date] timeIntervalSince1970];
  113. int intervalll = (int)interval;
  114. [g_server offlineOperation:intervalll toView:self];
  115. }
  116. if (g_server.isManualLogin) {
  117. if (self.isLoadFriendAndGroup) {
  118. NSArray *array = [[JXLabelObject sharedInstance] fetchAllLabelsFromLocal];
  119. if (array.count <= 0) {
  120. // 同步标签
  121. [g_server friendGroupListToView:self];
  122. }
  123. }
  124. }
  125. // 获取服务器时间
  126. [g_server getCurrentTimeToView:self];
  127. // 获取自己的用户信息
  128. [g_server getUser:MY_USER_ID toView:self];
  129. // [self.topButton addTarget:self action:@selector(topBtnClick) forControlEvents:UIControlEventTouchUpInside];
  130. [g_notify addObserver:self selector:@selector(showAD) name:kLaunchAdShowFinishNotifaction object:nil];
  131. [g_notify addObserver:self selector:@selector(changeNodeTitle:) name:@"changeNodeTitleNotifaction" object:nil];
  132. [self setupChildViewControllers];
  133. [self setupNavBar];
  134. [self setupContentView];
  135. [self setupTitlesView];
  136. }
  137. - (void)loginSynchronizeFriends:(NSNotification*)notification{
  138. //判断服务器好友数量是否与本地一致
  139. // _friendArray = [g_server.myself fetchAllFriendsOrNotFromLocal];
  140. // NSLog(@"%d -------%ld",[g_server.myself.friendCount intValue] , [_friendArray count]);
  141. // if ([g_server.myself.friendCount intValue] > [_friendArray count] && [g_server.myself.friendCount intValue] >0) {
  142. // [g_App showAlert:Localized(@"JXAlert_SynchFirendOK") delegate:self];
  143. if (self.isLoadFriendAndGroup) {
  144. [g_server listAttention:0 userId:MY_USER_ID toView:self];
  145. }else{
  146. [[JXXMPP sharedInstance] performSelector:@selector(login) withObject:nil afterDelay:2];//2秒后执行xmpp登录
  147. }
  148. //[[JXXMPP sharedInstance] performSelector:@selector(login) withObject:nil afterDelay:2];//2秒后执行xmpp登录
  149. // }
  150. }
  151. -(void)onXmppLoginChanged:(NSNumber*)isLogin{
  152. if([JXXMPP sharedInstance].isLogined == login_status_yes){
  153. // 获取离线调用接口列表
  154. //CGFloat lastOffLineTime=(g_server.lastOfflineTime *1000 + 0)/1000;
  155. // CGFloat lastOffLineTime2=(g_server.timeDifference)/1000;
  156. // [g_server offlineOperation:(g_server.lastOfflineTime *1000 + g_server.timeDifference)/1000 toView:self];
  157. [self onAfterLogin];
  158. }
  159. }
  160. -(void)onAfterLogin{
  161. // [_msgVc scrollToPageUp];
  162. }
  163. - (void)showAD {
  164. [JXShowMainView showView];
  165. }
  166. - (void)setupContentView
  167. {
  168. UIScrollView *contentView = [[UIScrollView alloc] init];
  169. contentView.backgroundColor = kRGBColor(250, 250, 250);
  170. contentView.frame = CGRectMake(0, JX_SCREEN_TOP, self.view.bounds.size.width, self.view.bounds.size.height-JX_SCREEN_TOP);
  171. contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  172. contentView.delegate = self;
  173. contentView.showsHorizontalScrollIndicator = NO;
  174. contentView.showsVerticalScrollIndicator = NO;
  175. contentView.pagingEnabled = YES;
  176. contentView.bounces=NO;
  177. contentView.contentSize = CGSizeMake(contentView.xmg_width * self.childViewControllers.count, 0);
  178. [self.view addSubview:contentView];
  179. self.contentView = contentView;
  180. return;
  181. id traget = self.navigationController.interactivePopGestureRecognizer.delegate;
  182. UIPanGestureRecognizer * pan = [[UIPanGestureRecognizer alloc]initWithTarget:traget action:nil];
  183. [contentView addGestureRecognizer:pan];
  184. UISwipeGestureRecognizer * swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeAction:)];
  185. swipeRight.direction = UISwipeGestureRecognizerDirectionLeft;
  186. [contentView addGestureRecognizer:swipeRight];
  187. UISwipeGestureRecognizer * swipeleft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeAction:)];
  188. swipeleft.direction = UISwipeGestureRecognizerDirectionRight;
  189. [contentView addGestureRecognizer:swipeleft];
  190. // 手势的优先级 优先响应swipe手势
  191. [pan requireGestureRecognizerToFail:swipeRight];
  192. [pan requireGestureRecognizerToFail:swipeleft];
  193. }
  194. -(void)swipeAction:(UISwipeGestureRecognizer *)sender {
  195. if (sender.direction ==UISwipeGestureRecognizerDirectionLeft) {
  196. int index =1;
  197. [self titleClick:self.titlesView.subviews[index]];
  198. [self switchController:index];
  199. }else if(sender.direction ==UISwipeGestureRecognizerDirectionRight){
  200. int index =0;
  201. [self titleClick:self.titlesView.subviews[index]];
  202. [self switchController:index];
  203. }
  204. }
  205. - (void)goBack:(NSNotification *)note{
  206. [self.contentView setContentOffset:CGPointMake(0 * JX_SCREEN_WIDTH, self.contentView.contentOffset.y) animated:YES];
  207. self.selectedButton.enabled = YES;
  208. _topButton.enabled = NO;
  209. self.selectedButton = _topButton;
  210. // 消除约束
  211. [self.sliderViewCenterX uninstall];
  212. self.sliderViewCenterX = nil;
  213. // 添加约束
  214. [self.sliderView mas_makeConstraints:^(MASConstraintMaker *make) {
  215. self.sliderViewCenterX = make.centerX.equalTo(_topButton);
  216. }];
  217. [UIView animateWithDuration:0.25 animations:^{
  218. [self.sliderView layoutIfNeeded];
  219. }];
  220. }
  221. -(void)setBlcokBTb:(shuaxinBtn)blcokBTb{
  222. //获取说有群信息
  223. // [g_server listHisRoom:0 pageSize:1000 toView:self];
  224. [self setupChildViewControllers];
  225. [self setupNavBar];
  226. [self setupContentView];
  227. [self setupTitlesView];
  228. _indexGhome=@"1";
  229. int index =0;
  230. [self titleClick:self.topButton];
  231. [self switchController:index];
  232. }
  233. - (void)goHomeWebPage {
  234. [g_notify postNotificationName:KGoHomeWebPageNotification object:nil];
  235. }
  236. - (void)goRefreshWebPage {
  237. [g_notify postNotificationName:KGoRefreshWebPageNotification object:nil];
  238. }
  239. - (void)setupTitlesView
  240. {
  241. UIView *backView = [[UIView alloc] init];
  242. backView.backgroundColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0];
  243. backView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  244. backView.frame = CGRectMake(0, 0, self.view.frame.size.width, JX_SCREEN_TOP);
  245. backView.userInteractionEnabled=YES;
  246. [self.view addSubview:backView];
  247. UIButton *homeButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
  248. homeButton.frame =CGRectMake(10, JX_STATUSBAR_H, 30, 30);
  249. [homeButton setImage:[UIImage imageNamed:@"home_home"] forState:(UIControlStateNormal)];
  250. [backView addSubview:homeButton];
  251. [homeButton addTarget:self action:@selector(goHomeWebPage) forControlEvents:(UIControlEventTouchUpInside)];
  252. _homeButton = homeButton;
  253. UIButton *refreshButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
  254. refreshButton.frame =CGRectMake(JX_SCREEN_WIDTH-100, JX_STATUSBAR_H, 90, 30);
  255. [refreshButton setImage:[UIImage imageNamed:@"home_refresh"] forState:(UIControlStateNormal)];
  256. [refreshButton setTitleColor:[UIColor blueColor] forState:(UIControlStateNormal)];
  257. refreshButton.contentMode=UIViewContentModeScaleAspectFit;
  258. [backView addSubview:refreshButton];
  259. NSString *selectUrl = [g_default objectForKey:@"selectNodeName"];
  260. if (selectUrl.length>0) {
  261. [refreshButton setTitle:selectUrl forState:(UIControlStateNormal)];
  262. }else{
  263. [refreshButton setTitle:@" 节点1 " forState:(UIControlStateNormal)];
  264. }
  265. //[refreshButton setTitleEdgeInsets:UIEdgeInsetsMake(0, 60, 0, 0)];
  266. //[refreshButton setImageEdgeInsets:UIEdgeInsetsMake(0, 50, 0, 0)];
  267. //[refreshButton setTitleEdgeInsets:UIEdgeInsetsMake(0, 0,0,60)];
  268. [refreshButton addTarget:self action:@selector(goRefreshWebPage) forControlEvents:(UIControlEventTouchUpInside)];
  269. _refreshButton = refreshButton;
  270. UIView *titlesView = [[UIView alloc] init];
  271. titlesView.backgroundColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0];
  272. titlesView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  273. titlesView.frame = CGRectMake(self.view.frame.size.width/3, 0, self.view.frame.size.width/3, JX_SCREEN_TOP);
  274. [backView addSubview:titlesView];
  275. self.titlesView = titlesView;
  276. // 5个按钮
  277. XMGTitleButton *button = [self setupTitleButton:@"购彩"];
  278. [self setupTitleButton:@"聊天"];
  279. [self titleClick:button];
  280. [self switchController:0];
  281. self.topButton=button;
  282. // 底部滑条
  283. UIView *sliderView = [[UIView alloc] init];
  284. sliderView.backgroundColor = [UIColor redColor];
  285. [self.titlesView addSubview:sliderView];
  286. self.sliderView = sliderView;
  287. [sliderView mas_makeConstraints:^(MASConstraintMaker *make) {
  288. make.size.mas_equalTo(CGSizeMake([[button titleForState:UIControlStateNormal] sizeWithAttributes:@{NSFontAttributeName : button.titleLabel.font}].width/1.5, 3));
  289. make.bottom.mas_equalTo(self.titlesView.mas_bottom).mas_offset(-4);
  290. self.sliderViewCenterX = make.centerX.equalTo(button);
  291. }];
  292. UILabel *tipLable=[[UILabel alloc]init];
  293. tipLable.backgroundColor=[UIColor redColor];
  294. tipLable.layer.cornerRadius=4;
  295. tipLable.layer.masksToBounds=YES;
  296. [titlesView addSubview:tipLable];
  297. tipLable.hidden=YES;
  298. self.countTipL=tipLable;
  299. [tipLable mas_makeConstraints:^(MASConstraintMaker *make) {
  300. make.width.mas_equalTo(8);
  301. make.height.mas_equalTo(8);
  302. make.top.mas_equalTo(JX_SCREEN_HEIGHT>=812?49:25);
  303. make.left.mas_equalTo(self.titlesView.xmg_width-15);
  304. }];
  305. }
  306. - (void)changeNodeTitle:(NSNotification *)note{
  307. NSString *nodeStr=note.object;
  308. _refreshButton.frame =CGRectMake(JX_SCREEN_WIDTH-100, JX_STATUSBAR_H, 90, 30);
  309. [_refreshButton setImage:[UIImage imageNamed:@"home_refresh"] forState:(UIControlStateNormal)];
  310. _refreshButton.contentMode=UIViewContentModeScaleAspectFit;
  311. [_refreshButton setTitle:[NSString stringWithFormat:@" %@ ",nodeStr] forState:(UIControlStateNormal)];
  312. }
  313. - (XMGTitleButton *)setupTitleButton:(NSString *)title
  314. {
  315. XMGTitleButton *button = [XMGTitleButton buttonWithType:UIButtonTypeCustom];
  316. [button setTitle:title forState:UIControlStateNormal];
  317. [button addTarget:self action:@selector(titleClick:) forControlEvents:UIControlEventTouchUpInside];
  318. [self.titlesView addSubview:button];
  319. self.topButton=button;
  320. [button mas_makeConstraints:^(MASConstraintMaker *make) {
  321. make.width.mas_equalTo(self.titlesView.xmg_width/2);
  322. make.top.mas_equalTo(JX_SCREEN_HEIGHT>=812?44:20);
  323. NSUInteger index = self.titlesView.subviews.count - 1;
  324. if (index == 0) {
  325. make.left.mas_equalTo(self.titlesView);
  326. } else {
  327. make.left.mas_equalTo(self.titlesView.xmg_width/2);
  328. }
  329. }];
  330. return button;
  331. }
  332. - (void)titleClick:(UIButton *)button
  333. {
  334. self.selectedButton.enabled = YES;
  335. button.enabled = NO;
  336. self.selectedButton = button;
  337. // 消除约束
  338. [self.sliderViewCenterX uninstall];
  339. self.sliderViewCenterX = nil;
  340. // 添加约束
  341. [self.sliderView mas_makeConstraints:^(MASConstraintMaker *make) {
  342. self.sliderViewCenterX = make.centerX.equalTo(button);
  343. }];
  344. [UIView animateWithDuration:0.25 animations:^{
  345. [self.sliderView layoutIfNeeded];
  346. }];
  347. if ([_indexGhome isEqualToString:@"1"]) {
  348. [self.contentView setContentOffset:CGPointMake(0 * self.contentView.frame.size.width, self.contentView.contentOffset.y) animated:YES];
  349. }else{
  350. int index = (int)[self.titlesView.subviews indexOfObject:button];
  351. [self.contentView setContentOffset:CGPointMake(index * self.contentView.frame.size.width, self.contentView.contentOffset.y) animated:YES];
  352. }
  353. }
  354. - (void)setupNavBar
  355. {
  356. self.automaticallyAdjustsScrollViewInsets = NO;
  357. }
  358. - (void)setupChildViewControllers
  359. {
  360. CYWebAddPointVC *vc = [[CYWebAddPointVC alloc] init];
  361. NSString *memberAcc=[[NSUserDefaults standardUserDefaults] objectForKey:@"www_url"];
  362. NSString *selectNodeUrl=[[NSUserDefaults standardUserDefaults] objectForKey:@"selectNodeUrl"];
  363. if (selectNodeUrl.length>0) {
  364. vc.strURL=selectNodeUrl;
  365. }else{
  366. vc.strURL=memberAcc;
  367. }
  368. [self addChildViewController:vc];
  369. [self addChildViewController:[XMGMainViewController new]];
  370. }
  371. - (void)setupOneChildViewController:(UIViewController *)type
  372. {
  373. if([type isKindOfClass:[CYWebAddPointVC class]]){
  374. CYWebAddPointVC *vc = [[CYWebAddPointVC alloc] init];
  375. NSString *memberAcc=[[NSUserDefaults standardUserDefaults] objectForKey:@"www_url"];
  376. NSString *selectNodeUrl=[[NSUserDefaults standardUserDefaults] objectForKey:@"selectNodeUrl"];
  377. if (selectNodeUrl.length>0) {
  378. vc.strURL=selectNodeUrl;
  379. }else{
  380. vc.strURL=memberAcc;
  381. }
  382. [self addChildViewController:vc];
  383. }else{
  384. // XMGTabarVC JXXMMainVc。XMGMainViewController JXXMMainVc
  385. XMGMainViewController *vc = [[XMGMainViewController alloc] init];
  386. [self addChildViewController:vc];
  387. }
  388. }
  389. - (void)switchController:(int)index
  390. {
  391. [g_notify postNotificationName:@"KOPENLONG" object:@(index)];
  392. if (index == 1) {
  393. _homeButton.hidden = YES;
  394. _refreshButton.hidden = YES;
  395. }else {
  396. _homeButton.hidden = NO;
  397. _refreshButton.hidden = NO;
  398. }
  399. CYWebAddPointVC *vc = self.childViewControllers[index];
  400. vc.view.xmg_y = 0;
  401. vc.view.xmg_width = self.contentView.xmg_width;
  402. vc.view.xmg_height = self.contentView.xmg_height;
  403. vc.view.xmg_x = vc.view.xmg_width * index;
  404. [self.contentView addSubview:vc.view];
  405. }
  406. #pragma mark - <UIScrollViewDelegate>
  407. - (void)scrollViewDidEndDecelerating:(nonnull UIScrollView *)scrollView
  408. {
  409. int index = scrollView.contentOffset.x / scrollView.frame.size.width;
  410. [self titleClick:self.titlesView.subviews[index]];
  411. [self switchController:index];
  412. }
  413. - (void)scrollViewDidEndScrollingAnimation:(nonnull UIScrollView *)scrollView
  414. {
  415. int a=(int)(scrollView.contentOffset.x / scrollView.frame.size.width);
  416. // NSString *msgStr=[g_default objectForKey:@"refushMsgHistoryxxx"];
  417. // if (msgStr.length>0) {
  418. //
  419. // }else{
  420. //
  421. // [g_notify postNotificationName:@"refushMsgHistoryxxx" object:nil];
  422. //
  423. // [g_default setObject:@"refushMsgHistoryxxx" forKey:@"refushMsgHistoryxxx"];
  424. // [g_default synchronize];
  425. // }
  426. [self switchController:a];
  427. }
  428. -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{
  429. if ([aDownload.action isEqualToString:act_AttentionList]) {
  430. JXProgressVC * pv = [JXProgressVC alloc];
  431. pv.dataArray = array1;
  432. pv = [pv init];
  433. if (array1.count > 300) {
  434. [g_navigation pushViewController:pv animated:YES];
  435. }
  436. // [self.view addSubview:pv.view];
  437. }
  438. // 同步标签
  439. if ([aDownload.action isEqualToString:act_FriendGroupList]) {
  440. for (NSInteger i = 0; i < array1.count; i ++) {
  441. NSDictionary *dict = array1[i];
  442. JXLabelObject *labelObj = [[JXLabelObject alloc] init];
  443. labelObj.groupId = dict[@"groupId"];
  444. labelObj.groupName = dict[@"groupName"];
  445. labelObj.userId = dict[@"userId"];
  446. NSArray *userIdList = dict[@"userIdList"];
  447. NSString *userIdListStr = [userIdList componentsJoinedByString:@","];
  448. if (userIdListStr.length > 0) {
  449. labelObj.userIdList = [NSString stringWithFormat:@"%@", userIdListStr];
  450. }
  451. [labelObj insert];
  452. }
  453. // 删除服务器上已经删除的
  454. NSArray *arr = [[JXLabelObject sharedInstance] fetchAllLabelsFromLocal];
  455. for (NSInteger i = 0; i < arr.count; i ++) {
  456. JXLabelObject *locLabel = arr[i];
  457. BOOL flag = NO;
  458. for (NSInteger j = 0; j < array1.count; j ++) {
  459. NSDictionary * dict = array1[j];
  460. if ([locLabel.groupId isEqualToString:dict[@"groupId"]]) {
  461. flag = YES;
  462. break;
  463. }
  464. }
  465. if (!flag) {
  466. [locLabel delete];
  467. }
  468. }
  469. }
  470. if ([aDownload.action isEqualToString:act_offlineOperation]) {
  471. for (NSDictionary *dict in array1) {
  472. if ([[dict objectForKey:@"tag"] isEqualToString:@"label"]) {
  473. [g_notify postNotificationName:kOfflineOperationUpdateLabelList object:nil];
  474. }
  475. if ([[dict objectForKey:@"tag"] isEqualToString:@"friend"]) {
  476. [g_server getUser:[dict objectForKey:@"friendId"] toView:self];
  477. }
  478. if ([[dict objectForKey:@"tag"] isEqualToString:@"room"]) {
  479. [g_server getRoom:[dict objectForKey:@"friendId"] toView:self];
  480. }
  481. }
  482. }
  483. if ([aDownload.action isEqualToString:act_UserGet]) {
  484. JXUserObject *user = [[JXUserObject alloc] init];
  485. [user getDataFromDict:dict];
  486. if ([user.userId intValue] == [MY_USER_ID intValue]) {
  487. [g_server doSaveUser:dict];
  488. user.bubbleFontId = [dict objectForKey:@"bubbleFontId"];
  489. user.gradeIndex = [dict objectForKey:@"gradeIndex"];
  490. // 保存自己
  491. [user insert];
  492. [user update];
  493. }else {
  494. JXUserObject *user1 = [[JXUserObject sharedInstance] getUserById:user.userId];
  495. user.content = user1.content;
  496. user.timeSend = user1.timeSend;
  497. [user update];
  498. }
  499. [g_notify postNotificationName:kOfflineOperationUpdateUserSet object:user];
  500. }
  501. if ([aDownload.action isEqualToString:act_roomGet]) {
  502. JXUserObject *user = [[JXUserObject alloc] init];
  503. [user getDataFromDict:dict];
  504. user.userId = [dict objectForKey:@"jid"];
  505. user.roomId = [dict objectForKey:@"id"];
  506. user.userNickname = [dict objectForKey:@"name"];
  507. if(![g_xmpp.roomPool getRoom:user.userId] || ![user haveTheUser]){
  508. user.userDescription = [dict objectForKey:@"desc"];
  509. user.showRead = [dict objectForKey:@"showRead"];
  510. user.showMember = [dict objectForKey:@"showMember"];
  511. user.allowSendCard = [dict objectForKey:@"allowSendCard"];
  512. user.chatRecordTimeOut = [dict objectForKey:@"chatRecordTimeOut"];
  513. user.talkTime = [dict objectForKey:@"talkTime"];
  514. user.allowInviteFriend = [dict objectForKey:@"allowInviteFriend"];
  515. user.allowUploadFile = [dict objectForKey:@"allowUploadFile"];
  516. user.allowConference = [dict objectForKey:@"allowConference"];
  517. user.allowSpeakCourse = [dict objectForKey:@"allowSpeakCourse"];
  518. user.offlineNoPushMsg = [(NSDictionary *)[dict objectForKey:@"member"] objectForKey:@"offlineNoPushMsg"];
  519. user.isNeedVerify = [dict objectForKey:@"isNeedVerify"];
  520. user.createUserId = [dict objectForKey:@"userId"];
  521. user.content = @" ";
  522. user.topTime = nil;
  523. [user insertRoom];
  524. [g_xmpp.roomPool joinRoom:user.userId title:user.userNickname lastDate:nil isNew:NO];
  525. }else {
  526. NSDictionary * groupDict = [user toDictionary];
  527. roomData * roomdata = [[roomData alloc] init];
  528. [roomdata getDataFromDict:groupDict];
  529. [roomdata getDataFromDict:dict];
  530. JXUserObject *user1 = [[JXUserObject sharedInstance] getUserById:roomdata.roomJid];
  531. user.content = user1.content;
  532. user.status = user1.status;
  533. user.offlineNoPushMsg = [NSNumber numberWithBool:roomdata.offlineNoPushMsg];
  534. user.msgsNew = user1.msgsNew;
  535. [user update];
  536. }
  537. [g_notify postNotificationName:kOfflineOperationUpdateUserSet object:user];
  538. }
  539. }
  540. -(int) didServerResultFailed:(JXConnection*)aDownload dict:(NSDictionary*)dict{
  541. return hide_error;
  542. }
  543. -(int) didServerConnectError:(JXConnection*)aDownload error:(NSError *)error{//error为空时,代表超时
  544. return hide_error;
  545. }
  546. -(void)dealloc{
  547. [g_notify removeObserver:self name:kXmppLoginNotifaction object:nil];
  548. [g_notify removeObserver:self name:kSystemLoginNotifaction object:nil];
  549. [g_notify removeObserver:self name:kXmppClickLoginNotifaction object:nil];
  550. [g_notify removeObserver:self name:kXMPPLoginOtherNotification object:nil];
  551. [g_notify removeObserver:self name:kApplicationWillEnterForeground object:nil];
  552. [g_notify removeObserver:self name:kXMPPMessageUpadteUserInfoNotification object:nil];
  553. [g_notify removeObserver:self name:kDeviceAuthNotification object:nil];
  554. }
  555. @end