JXCsHomeVc.m 15 KB

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