JXCsHomeVc.m 17 KB

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