JXCsHomeVc.m 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  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. @interface JXCsHomeVc ()<UIScrollViewDelegate>
  15. /** 标签栏底部的红色指示器 */
  16. @property (nonatomic, weak) UIView *indicatorView;
  17. /** 当前选中的按钮 */
  18. @property (nonatomic, weak) UIButton *selectedButton;
  19. @property (nonatomic, weak) UIButton *button_n;
  20. @property (nonatomic,copy) NSString *linkName1;
  21. @property (nonatomic,copy) NSString *linkURL1;
  22. @property (nonatomic,copy) NSString *imgUrl1;
  23. @property (weak, nonatomic) UIView *sliderView;
  24. @property (strong, nonatomic) MASConstraint *sliderViewCenterX;
  25. @property (weak, nonatomic) UIButton *refreshButton;
  26. @property (weak, nonatomic) UIButton *homeButton;
  27. @property (nonatomic,strong) NSString *indexGhome;
  28. @end
  29. @implementation JXCsHomeVc
  30. -(instancetype)init{
  31. if (self=[super init]) {
  32. [g_notify addObserver:self selector:@selector(newMsgCome:) name:kXMPPNewMsgNotifaction object:nil];//收到了一条新消息
  33. [g_notify addObserver:self selector:@selector(hiddenTipLabel:) name:@"hiddenTip" object:nil];//收到了一条新消息
  34. [g_notify addObserver:self selector:@selector(goBack:) name:@"longGoback" object:nil];
  35. }
  36. return self;
  37. }
  38. - (void)hiddenTipLabel:(NSNotification *)note{
  39. self.countTipL.hidden=YES;
  40. }
  41. - (void)newMsgCome:(NSNotification *)note{
  42. self.countTipL.hidden=NO;
  43. }
  44. -(void)setStrURL:(NSString *)strURL{
  45. self.countTipL.hidden=YES;
  46. }
  47. - (void)viewDidAppear:(BOOL)animated{
  48. [super viewDidAppear:animated];
  49. }
  50. - (void)viewDidLoad {
  51. [super viewDidLoad];
  52. [self setupChildViewControllers];
  53. [self setupNavBar];
  54. [self setupContentView];
  55. [self setupTitlesView];
  56. // [self.topButton addTarget:self action:@selector(topBtnClick) forControlEvents:UIControlEventTouchUpInside];
  57. [g_notify addObserver:self selector:@selector(showAD) name:kLaunchAdShowFinishNotifaction object:nil];
  58. [g_notify addObserver:self selector:@selector(changeNodeTitle:) name:@"changeNodeTitleNotifaction" object:nil];
  59. // self.contentView.delaysContentTouches=NO;
  60. // self.contentView.canCancelContentTouches=NO;
  61. }
  62. - (void)showAD {
  63. [JXShowMainView showView];
  64. }
  65. - (void)dealloc {
  66. [g_notify removeObserver:self];
  67. }
  68. - (void)setupContentView
  69. {
  70. UIScrollView *contentView = [[UIScrollView alloc] init];
  71. contentView.backgroundColor = kRGBColor(250, 250, 250);
  72. contentView.frame = CGRectMake(0, JX_SCREEN_TOP, self.view.bounds.size.width, self.view.bounds.size.height-JX_SCREEN_TOP);
  73. contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  74. contentView.delegate = self;
  75. contentView.showsHorizontalScrollIndicator = NO;
  76. contentView.showsVerticalScrollIndicator = NO;
  77. contentView.pagingEnabled = YES;
  78. contentView.bounces=NO;
  79. contentView.contentSize = CGSizeMake(contentView.xmg_width * self.childViewControllers.count, 0);
  80. [self.view addSubview:contentView];
  81. self.contentView = contentView;
  82. return;
  83. id traget = self.navigationController.interactivePopGestureRecognizer.delegate;
  84. UIPanGestureRecognizer * pan = [[UIPanGestureRecognizer alloc]initWithTarget:traget action:nil];
  85. [contentView addGestureRecognizer:pan];
  86. UISwipeGestureRecognizer * swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeAction:)];
  87. swipeRight.direction = UISwipeGestureRecognizerDirectionLeft;
  88. [contentView addGestureRecognizer:swipeRight];
  89. UISwipeGestureRecognizer * swipeleft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeAction:)];
  90. swipeleft.direction = UISwipeGestureRecognizerDirectionRight;
  91. [contentView addGestureRecognizer:swipeleft];
  92. // 手势的优先级 优先响应swipe手势
  93. [pan requireGestureRecognizerToFail:swipeRight];
  94. [pan requireGestureRecognizerToFail:swipeleft];
  95. }
  96. -(void)swipeAction:(UISwipeGestureRecognizer *)sender {
  97. if (sender.direction ==UISwipeGestureRecognizerDirectionLeft) {
  98. int index =1;
  99. [self titleClick:self.titlesView.subviews[index]];
  100. [self switchController:index];
  101. }else if(sender.direction ==UISwipeGestureRecognizerDirectionRight){
  102. int index =0;
  103. [self titleClick:self.titlesView.subviews[index]];
  104. [self switchController:index];
  105. }
  106. }
  107. - (void)goBack:(NSNotification *)note{
  108. [self.contentView setContentOffset:CGPointMake(0 * JX_SCREEN_WIDTH, self.contentView.contentOffset.y) animated:YES];
  109. self.selectedButton.enabled = YES;
  110. _topButton.enabled = NO;
  111. self.selectedButton = _topButton;
  112. // 消除约束
  113. [self.sliderViewCenterX uninstall];
  114. self.sliderViewCenterX = nil;
  115. // 添加约束
  116. [self.sliderView mas_makeConstraints:^(MASConstraintMaker *make) {
  117. self.sliderViewCenterX = make.centerX.equalTo(_topButton);
  118. }];
  119. [UIView animateWithDuration:0.25 animations:^{
  120. [self.sliderView layoutIfNeeded];
  121. }];
  122. }
  123. -(void)setBlcokBTb:(shuaxinBtn)blcokBTb{
  124. //获取说有群信息
  125. [g_server listHisRoom:0 pageSize:1000 toView:self];
  126. [self setupChildViewControllers];
  127. [self setupNavBar];
  128. [self setupContentView];
  129. [self setupTitlesView];
  130. _indexGhome=@"1";
  131. int index =0;
  132. [self titleClick:self.topButton];
  133. [self switchController:index];
  134. }
  135. - (void)goHomeWebPage {
  136. [g_notify postNotificationName:KGoHomeWebPageNotification object:nil];
  137. }
  138. - (void)goRefreshWebPage {
  139. [g_notify postNotificationName:KGoRefreshWebPageNotification object:nil];
  140. }
  141. - (void)setupTitlesView
  142. {
  143. UIView *backView = [[UIView alloc] init];
  144. backView.backgroundColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0];
  145. backView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  146. backView.frame = CGRectMake(0, 0, self.view.frame.size.width, JX_SCREEN_TOP);
  147. backView.userInteractionEnabled=YES;
  148. [self.view addSubview:backView];
  149. UIButton *homeButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
  150. homeButton.frame =CGRectMake(10, JX_STATUSBAR_H, 30, 30);
  151. [homeButton setImage:[UIImage imageNamed:@"home_home"] forState:(UIControlStateNormal)];
  152. [backView addSubview:homeButton];
  153. [homeButton addTarget:self action:@selector(goHomeWebPage) forControlEvents:(UIControlEventTouchUpInside)];
  154. _homeButton = homeButton;
  155. UIButton *refreshButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
  156. refreshButton.frame =CGRectMake(JX_SCREEN_WIDTH-100, JX_STATUSBAR_H, 90, 30);
  157. [refreshButton setImage:[UIImage imageNamed:@"home_refresh"] forState:(UIControlStateNormal)];
  158. [refreshButton setTitleColor:[UIColor blueColor] forState:(UIControlStateNormal)];
  159. refreshButton.contentMode=UIViewContentModeScaleAspectFit;
  160. [backView addSubview:refreshButton];
  161. NSString *selectUrl = [g_default objectForKey:@"selectNodeName"];
  162. if (selectUrl.length>0) {
  163. [refreshButton setTitle:selectUrl forState:(UIControlStateNormal)];
  164. }else{
  165. [refreshButton setTitle:@" 节点1 " forState:(UIControlStateNormal)];
  166. }
  167. //[refreshButton setTitleEdgeInsets:UIEdgeInsetsMake(0, 60, 0, 0)];
  168. //[refreshButton setImageEdgeInsets:UIEdgeInsetsMake(0, 50, 0, 0)];
  169. //[refreshButton setTitleEdgeInsets:UIEdgeInsetsMake(0, 0,0,60)];
  170. [refreshButton addTarget:self action:@selector(goRefreshWebPage) forControlEvents:(UIControlEventTouchUpInside)];
  171. _refreshButton = refreshButton;
  172. UIView *titlesView = [[UIView alloc] init];
  173. titlesView.backgroundColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0];
  174. titlesView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  175. titlesView.frame = CGRectMake(self.view.frame.size.width/3, 0, self.view.frame.size.width/3, JX_SCREEN_TOP);
  176. [backView addSubview:titlesView];
  177. self.titlesView = titlesView;
  178. // 5个按钮
  179. XMGTitleButton *button = [self setupTitleButton:@"购彩"];
  180. [self setupTitleButton:@"聊天"];
  181. [self titleClick:button];
  182. [self switchController:0];
  183. self.topButton=button;
  184. // 底部滑条
  185. UIView *sliderView = [[UIView alloc] init];
  186. sliderView.backgroundColor = [UIColor redColor];
  187. [self.titlesView addSubview:sliderView];
  188. self.sliderView = sliderView;
  189. [sliderView mas_makeConstraints:^(MASConstraintMaker *make) {
  190. make.size.mas_equalTo(CGSizeMake([[button titleForState:UIControlStateNormal] sizeWithAttributes:@{NSFontAttributeName : button.titleLabel.font}].width/1.5, 3));
  191. make.bottom.mas_equalTo(self.titlesView.mas_bottom).mas_offset(-4);
  192. self.sliderViewCenterX = make.centerX.equalTo(button);
  193. }];
  194. UILabel *tipLable=[[UILabel alloc]init];
  195. tipLable.backgroundColor=[UIColor redColor];
  196. tipLable.layer.cornerRadius=4;
  197. tipLable.layer.masksToBounds=YES;
  198. [titlesView addSubview:tipLable];
  199. tipLable.hidden=YES;
  200. self.countTipL=tipLable;
  201. [tipLable mas_makeConstraints:^(MASConstraintMaker *make) {
  202. make.width.mas_equalTo(8);
  203. make.height.mas_equalTo(8);
  204. make.top.mas_equalTo(JX_SCREEN_HEIGHT>=812?49:25);
  205. make.left.mas_equalTo(self.titlesView.xmg_width-15);
  206. }];
  207. }
  208. - (void)changeNodeTitle:(NSNotification *)note{
  209. NSString *nodeStr=note.object;
  210. _refreshButton.frame =CGRectMake(JX_SCREEN_WIDTH-100, JX_STATUSBAR_H, 90, 30);
  211. [_refreshButton setImage:[UIImage imageNamed:@"home_refresh"] forState:(UIControlStateNormal)];
  212. _refreshButton.contentMode=UIViewContentModeScaleAspectFit;
  213. [_refreshButton setTitle:[NSString stringWithFormat:@" %@ ",nodeStr] forState:(UIControlStateNormal)];
  214. }
  215. - (XMGTitleButton *)setupTitleButton:(NSString *)title
  216. {
  217. XMGTitleButton *button = [XMGTitleButton buttonWithType:UIButtonTypeCustom];
  218. [button setTitle:title forState:UIControlStateNormal];
  219. [button addTarget:self action:@selector(titleClick:) forControlEvents:UIControlEventTouchUpInside];
  220. [self.titlesView addSubview:button];
  221. self.topButton=button;
  222. [button mas_makeConstraints:^(MASConstraintMaker *make) {
  223. make.width.mas_equalTo(self.titlesView.xmg_width/2);
  224. make.top.mas_equalTo(JX_SCREEN_HEIGHT>=812?44:20);
  225. NSUInteger index = self.titlesView.subviews.count - 1;
  226. if (index == 0) {
  227. make.left.mas_equalTo(self.titlesView);
  228. } else {
  229. make.left.mas_equalTo(self.titlesView.xmg_width/2);
  230. }
  231. }];
  232. return button;
  233. }
  234. - (void)titleClick:(UIButton *)button
  235. {
  236. self.selectedButton.enabled = YES;
  237. button.enabled = NO;
  238. self.selectedButton = button;
  239. // 消除约束
  240. [self.sliderViewCenterX uninstall];
  241. self.sliderViewCenterX = nil;
  242. // 添加约束
  243. [self.sliderView mas_makeConstraints:^(MASConstraintMaker *make) {
  244. self.sliderViewCenterX = make.centerX.equalTo(button);
  245. }];
  246. [UIView animateWithDuration:0.25 animations:^{
  247. [self.sliderView layoutIfNeeded];
  248. }];
  249. if ([_indexGhome isEqualToString:@"1"]) {
  250. [self.contentView setContentOffset:CGPointMake(0 * self.contentView.frame.size.width, self.contentView.contentOffset.y) animated:YES];
  251. }else{
  252. int index = (int)[self.titlesView.subviews indexOfObject:button];
  253. [self.contentView setContentOffset:CGPointMake(index * self.contentView.frame.size.width, self.contentView.contentOffset.y) animated:YES];
  254. }
  255. }
  256. - (void)setupNavBar
  257. {
  258. self.automaticallyAdjustsScrollViewInsets = NO;
  259. }
  260. - (void)setupChildViewControllers
  261. {
  262. CYWebAddPointVC *vc = [[CYWebAddPointVC alloc] init];
  263. NSString *memberAcc=[[NSUserDefaults standardUserDefaults] objectForKey:@"www_url"];
  264. NSString *selectNodeUrl=[[NSUserDefaults standardUserDefaults] objectForKey:@"selectNodeUrl"];
  265. if (selectNodeUrl.length>0) {
  266. vc.strURL=selectNodeUrl;
  267. }else{
  268. vc.strURL=memberAcc;
  269. }
  270. [self addChildViewController:vc];
  271. [self addChildViewController:[XMGMainViewController new]];
  272. return;
  273. [self setupOneChildViewController:vc];
  274. [self setupOneChildViewController:[XMGMainViewController new]];
  275. }
  276. - (void)setupOneChildViewController:(UIViewController *)type
  277. {
  278. if([type isKindOfClass:[CYWebAddPointVC class]]){
  279. CYWebAddPointVC *vc = [[CYWebAddPointVC alloc] init];
  280. NSString *memberAcc=[[NSUserDefaults standardUserDefaults] objectForKey:@"www_url"];
  281. NSString *selectNodeUrl=[[NSUserDefaults standardUserDefaults] objectForKey:@"selectNodeUrl"];
  282. if (selectNodeUrl.length>0) {
  283. vc.strURL=selectNodeUrl;
  284. }else{
  285. vc.strURL=memberAcc;
  286. }
  287. [self addChildViewController:vc];
  288. }else{
  289. // XMGTabarVC JXXMMainVc。XMGMainViewController JXXMMainVc
  290. XMGMainViewController *vc = [[XMGMainViewController alloc] init];
  291. [self addChildViewController:vc];
  292. }
  293. }
  294. - (void)switchController:(int)index
  295. {
  296. [g_notify postNotificationName:@"KOPENLONG" object:@(index)];
  297. if (index == 1) {
  298. _homeButton.hidden = YES;
  299. _refreshButton.hidden = YES;
  300. }else {
  301. _homeButton.hidden = NO;
  302. _refreshButton.hidden = NO;
  303. }
  304. CYWebAddPointVC *vc = self.childViewControllers[index];
  305. vc.view.xmg_y = 0;
  306. vc.view.xmg_width = self.contentView.xmg_width;
  307. vc.view.xmg_height = self.contentView.xmg_height;
  308. vc.view.xmg_x = vc.view.xmg_width * index;
  309. [self.contentView addSubview:vc.view];
  310. }
  311. #pragma mark - <UIScrollViewDelegate>
  312. - (void)scrollViewDidEndDecelerating:(nonnull UIScrollView *)scrollView
  313. {
  314. int index = scrollView.contentOffset.x / scrollView.frame.size.width;
  315. // NSString *msgStr=[g_default objectForKey:@"refushMsgHistoryxxx"];
  316. // if (msgStr.length>0) {
  317. //
  318. // }else{
  319. //
  320. // [g_notify postNotificationName:@"refushMsgHistoryxxx" object:nil];
  321. //
  322. // [g_default setObject:@"refushMsgHistoryxxx" forKey:@"refushMsgHistoryxxx"];
  323. // [g_default synchronize];
  324. // }
  325. [self titleClick:self.titlesView.subviews[index]];
  326. [self switchController:index];
  327. }
  328. - (void)scrollViewDidEndScrollingAnimation:(nonnull UIScrollView *)scrollView
  329. {
  330. int a=(int)(scrollView.contentOffset.x / scrollView.frame.size.width);
  331. // NSString *msgStr=[g_default objectForKey:@"refushMsgHistoryxxx"];
  332. // if (msgStr.length>0) {
  333. //
  334. // }else{
  335. //
  336. // [g_notify postNotificationName:@"refushMsgHistoryxxx" object:nil];
  337. //
  338. // [g_default setObject:@"refushMsgHistoryxxx" forKey:@"refushMsgHistoryxxx"];
  339. // [g_default synchronize];
  340. // }
  341. [self switchController:a];
  342. //
  343. }
  344. -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{
  345. if([aDownload.action isEqualToString:act_roomList] || [aDownload.action isEqualToString:act_roomListHis] ){
  346. for (int i = 0; i < [array1 count]; i++) {
  347. NSDictionary *dict=array1[i];
  348. JXUserObject* user = [[JXUserObject alloc]init];
  349. user.userNickname = [dict objectForKey:@"name"];
  350. user.userId = [dict objectForKey:@"jid"];
  351. user.userDescription = [dict objectForKey:@"desc"];
  352. user.roomId = [dict objectForKey:@"id"];
  353. user.showRead = [dict objectForKey:@"showRead"];
  354. user.showMember = [dict objectForKey:@"showMember"];
  355. user.allowSendCard = [dict objectForKey:@"allowSendCard"];
  356. user.chatRecordTimeOut = [NSString stringWithFormat:@"%@", [dict objectForKey:@"chatRecordTimeOut"]];
  357. user.offlineNoPushMsg = [(NSDictionary *)[dict objectForKey:@"member"] objectForKey:@"offlineNoPushMsg"];
  358. user.talkTime = [dict objectForKey:@"talkTime"];
  359. user.allowInviteFriend = [dict objectForKey:@"allowInviteFriend"];
  360. user.allowUploadFile = [dict objectForKey:@"allowUploadFile"];
  361. user.allowConference = [dict objectForKey:@"allowConference"];
  362. user.allowSpeakCourse = [dict objectForKey:@"allowSpeakCourse"];
  363. user.category = [dict objectForKey:@"category"];
  364. user.createUserId = [dict objectForKey:@"userId"];
  365. user.timeCreate = [NSDate dateWithTimeIntervalSince1970:[[dict objectForKey:@"createTime"] longLongValue]];
  366. user.isNeedVerify = [dict objectForKey:@"isNeedVerify"];
  367. if([[dict allKeys] containsObject:@"groupType"])
  368. {
  369. NSDictionary *dictby=[dict objectForKey:@"groupType"];
  370. user.groupType = [dictby objectForKey:@"typeName"];
  371. }else{
  372. user.groupType = @"100000";
  373. }
  374. NSDictionary *member = [dict objectForKey:@"member"];
  375. #ifdef IS_MsgEncrypt
  376. if ([member objectForKey:@"chatKeyGroup"]) {
  377. user.chatKeyGroup = [g_msgUtil encryptRoomMsgKey:user.roomId randomKey:[member objectForKey:@"chatKeyGroup"]];
  378. }
  379. #endif
  380. if ([aDownload.action isEqualToString:act_roomListHis]) {
  381. if (![user haveTheUser]){
  382. [user insertRoom];
  383. }else {
  384. [user updateUserNickname];
  385. [user update];
  386. }
  387. }
  388. }
  389. }
  390. }
  391. @end