JXCsHomeVc.m 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  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 "JXHomeScrollView.h"
  15. @interface JXCsHomeVc ()<UIScrollViewDelegate>
  16. /** 标签栏底部的红色指示器 */
  17. @property (nonatomic, weak) UIView *indicatorView;
  18. /** 当前选中的按钮 */
  19. @property (nonatomic, weak) UIButton *selectedButton;
  20. @property (nonatomic, weak) UIButton *button_n;
  21. @property (nonatomic,copy) NSString *linkName1;
  22. @property (nonatomic,copy) NSString *linkURL1;
  23. @property (nonatomic,copy) NSString *imgUrl1;
  24. @property (weak, nonatomic) UIView *sliderView;
  25. @property (strong, nonatomic) MASConstraint *sliderViewCenterX;
  26. @property (weak, nonatomic) UIButton *refreshButton;
  27. @property (weak, nonatomic) UIButton *homeButton;
  28. @property (nonatomic,strong) NSString *indexGhome;
  29. @end
  30. @implementation JXCsHomeVc
  31. -(instancetype)init{
  32. if (self=[super init]) {
  33. [g_notify addObserver:self selector:@selector(newMsgCome:) name:kXMPPNewMsgNotifaction object:nil];//收到了一条新消息
  34. [g_notify addObserver:self selector:@selector(hiddenTipLabel:) name:@"hiddenTip" object:nil];//收到了一条新消息
  35. [g_notify addObserver:self selector:@selector(goBack:) name:@"longGoback" object:nil];
  36. }
  37. return self;
  38. }
  39. - (void)hiddenTipLabel:(NSNotification *)note{
  40. self.countTipL.hidden=YES;
  41. }
  42. - (void)newMsgCome:(NSNotification *)note{
  43. self.countTipL.hidden=NO;
  44. }
  45. -(void)setStrURL:(NSString *)strURL{
  46. self.countTipL.hidden=YES;
  47. }
  48. - (void)viewDidLoad {
  49. [super viewDidLoad];
  50. [self setupChildViewControllers];
  51. [self setupNavBar];
  52. [self setupContentView];
  53. [self setupTitlesView];
  54. // [self.topButton addTarget:self action:@selector(topBtnClick) forControlEvents:UIControlEventTouchUpInside];
  55. [g_notify addObserver:self selector:@selector(showAD) name:kLaunchAdShowFinishNotifaction 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. JXHomeScrollView *contentView = [[JXHomeScrollView 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. [self.view addSubview:backView];
  145. UIButton *homeButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
  146. homeButton.frame =CGRectMake(10, JX_STATUSBAR_H+5, 20, 20);
  147. [homeButton setImage:[UIImage imageNamed:@"home_home"] forState:(UIControlStateNormal)];
  148. [backView addSubview:homeButton];
  149. [homeButton addTarget:self action:@selector(goHomeWebPage) forControlEvents:(UIControlEventTouchUpInside)];
  150. _homeButton = homeButton;
  151. UIButton *refreshButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
  152. refreshButton.frame =CGRectMake(JX_SCREEN_WIDTH-20-10, JX_STATUSBAR_H+5, 20, 20);
  153. [refreshButton setImage:[UIImage imageNamed:@"home_refresh"] forState:(UIControlStateNormal)];
  154. [backView addSubview:refreshButton];
  155. [refreshButton addTarget:self action:@selector(goRefreshWebPage) forControlEvents:(UIControlEventTouchUpInside)];
  156. _refreshButton = refreshButton;
  157. UIView *titlesView = [[UIView alloc] init];
  158. titlesView.backgroundColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0];
  159. titlesView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  160. titlesView.frame = CGRectMake(self.view.frame.size.width/3, 0, self.view.frame.size.width/3, JX_SCREEN_TOP);
  161. [backView addSubview:titlesView];
  162. self.titlesView = titlesView;
  163. // 5个按钮
  164. XMGTitleButton *button = [self setupTitleButton:@"购彩"];
  165. [self setupTitleButton:@"聊天"];
  166. [self titleClick:button];
  167. [self switchController:0];
  168. self.topButton=button;
  169. // 底部滑条
  170. UIView *sliderView = [[UIView alloc] init];
  171. sliderView.backgroundColor = [UIColor redColor];
  172. [self.titlesView addSubview:sliderView];
  173. self.sliderView = sliderView;
  174. [sliderView mas_makeConstraints:^(MASConstraintMaker *make) {
  175. make.size.mas_equalTo(CGSizeMake([[button titleForState:UIControlStateNormal] sizeWithAttributes:@{NSFontAttributeName : button.titleLabel.font}].width/1.5, 3));
  176. make.bottom.mas_equalTo(self.titlesView.mas_bottom).mas_offset(-4);
  177. self.sliderViewCenterX = make.centerX.equalTo(button);
  178. }];
  179. UILabel *tipLable=[[UILabel alloc]init];
  180. tipLable.backgroundColor=[UIColor redColor];
  181. tipLable.layer.cornerRadius=4;
  182. tipLable.layer.masksToBounds=YES;
  183. [titlesView addSubview:tipLable];
  184. tipLable.hidden=YES;
  185. self.countTipL=tipLable;
  186. [tipLable mas_makeConstraints:^(MASConstraintMaker *make) {
  187. make.width.mas_equalTo(8);
  188. make.height.mas_equalTo(8);
  189. make.top.mas_equalTo(JX_SCREEN_HEIGHT>=812?49:25);
  190. make.left.mas_equalTo(self.titlesView.xmg_width-15);
  191. }];
  192. }
  193. - (XMGTitleButton *)setupTitleButton:(NSString *)title
  194. {
  195. XMGTitleButton *button = [XMGTitleButton buttonWithType:UIButtonTypeCustom];
  196. [button setTitle:title forState:UIControlStateNormal];
  197. [button addTarget:self action:@selector(titleClick:) forControlEvents:UIControlEventTouchUpInside];
  198. [self.titlesView addSubview:button];
  199. self.topButton=button;
  200. [button mas_makeConstraints:^(MASConstraintMaker *make) {
  201. make.width.mas_equalTo(self.titlesView.xmg_width/2);
  202. make.top.mas_equalTo(JX_SCREEN_HEIGHT>=812?44:20);
  203. NSUInteger index = self.titlesView.subviews.count - 1;
  204. if (index == 0) {
  205. make.left.mas_equalTo(self.titlesView);
  206. } else {
  207. make.left.mas_equalTo(self.titlesView.xmg_width/2);
  208. }
  209. }];
  210. return button;
  211. }
  212. - (void)titleClick:(UIButton *)button
  213. {
  214. self.selectedButton.enabled = YES;
  215. button.enabled = NO;
  216. self.selectedButton = button;
  217. // 消除约束
  218. [self.sliderViewCenterX uninstall];
  219. self.sliderViewCenterX = nil;
  220. // 添加约束
  221. [self.sliderView mas_makeConstraints:^(MASConstraintMaker *make) {
  222. self.sliderViewCenterX = make.centerX.equalTo(button);
  223. }];
  224. [UIView animateWithDuration:0.25 animations:^{
  225. [self.sliderView layoutIfNeeded];
  226. }];
  227. if ([_indexGhome isEqualToString:@"1"]) {
  228. [self.contentView setContentOffset:CGPointMake(0 * self.contentView.frame.size.width, self.contentView.contentOffset.y) animated:YES];
  229. }else{
  230. int index = (int)[self.titlesView.subviews indexOfObject:button];
  231. [self.contentView setContentOffset:CGPointMake(index * self.contentView.frame.size.width, self.contentView.contentOffset.y) animated:YES];
  232. }
  233. }
  234. - (void)setupNavBar
  235. {
  236. self.automaticallyAdjustsScrollViewInsets = NO;
  237. }
  238. - (void)setupChildViewControllers
  239. {
  240. CYWebAddPointVC *vc = [[CYWebAddPointVC alloc] init];
  241. [self setupOneChildViewController:vc];
  242. [self setupOneChildViewController:[XMGMainViewController new]];
  243. }
  244. - (void)setupOneChildViewController:(UIViewController *)type
  245. {
  246. if([type isKindOfClass:[CYWebAddPointVC class]]){
  247. CYWebAddPointVC *vc = [[CYWebAddPointVC alloc] init];
  248. NSString *memberAcc=[[NSUserDefaults standardUserDefaults] objectForKey:@"www_url"];
  249. vc.strURL=memberAcc;
  250. [self addChildViewController:vc];
  251. }else{
  252. // XMGTabarVC JXXMMainVc。XMGMainViewController JXXMMainVc
  253. XMGMainViewController *vc = [[XMGMainViewController alloc] init];
  254. [self addChildViewController:vc];
  255. }
  256. }
  257. - (void)switchController:(int)index
  258. {
  259. [g_notify postNotificationName:@"KOPENLONG" object:@(index)];
  260. if (index == 1) {
  261. _homeButton.hidden = YES;
  262. _refreshButton.hidden = YES;
  263. }else {
  264. _homeButton.hidden = NO;
  265. _refreshButton.hidden = NO;
  266. }
  267. if ([_indexGhome isEqualToString:@"1"]) {
  268. CYWebAddPointVC *vc=[CYWebAddPointVC new];
  269. vc.view.xmg_y = 0;
  270. vc.view.xmg_width = self.contentView.xmg_width;
  271. vc.view.xmg_height = self.contentView.xmg_height;
  272. vc.view.xmg_x = vc.view.xmg_width * index;
  273. [self.contentView addSubview:vc.view];
  274. }else{
  275. CYWebAddPointVC *vc = self.childViewControllers[index];
  276. vc.view.xmg_y = 0;
  277. vc.view.xmg_width = self.contentView.xmg_width;
  278. vc.view.xmg_height = self.contentView.xmg_height;
  279. vc.view.xmg_x = vc.view.xmg_width * index;
  280. [self.contentView addSubview:vc.view];
  281. }
  282. }
  283. #pragma mark - <UIScrollViewDelegate>
  284. - (void)scrollViewDidEndDecelerating:(nonnull UIScrollView *)scrollView
  285. {
  286. int index = scrollView.contentOffset.x / scrollView.frame.size.width;
  287. [self titleClick:self.titlesView.subviews[index]];
  288. [self switchController:index];
  289. }
  290. - (void)scrollViewDidEndScrollingAnimation:(nonnull UIScrollView *)scrollView
  291. {
  292. int a=(int)(scrollView.contentOffset.x / scrollView.frame.size.width);
  293. [self switchController:a];
  294. // [g_notify postNotificationName:@"closeLong" object:nil userInfo:@{@"aa":[NSString stringWithFormat:@"%d",a]}];
  295. }
  296. -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{
  297. if([aDownload.action isEqualToString:act_roomList] || [aDownload.action isEqualToString:act_roomListHis] ){
  298. for (int i = 0; i < [array1 count]; i++) {
  299. NSDictionary *dict=array1[i];
  300. JXUserObject* user = [[JXUserObject alloc]init];
  301. user.userNickname = [dict objectForKey:@"name"];
  302. user.userId = [dict objectForKey:@"jid"];
  303. user.userDescription = [dict objectForKey:@"desc"];
  304. user.roomId = [dict objectForKey:@"id"];
  305. user.showRead = [dict objectForKey:@"showRead"];
  306. user.showMember = [dict objectForKey:@"showMember"];
  307. user.allowSendCard = [dict objectForKey:@"allowSendCard"];
  308. user.chatRecordTimeOut = [NSString stringWithFormat:@"%@", [dict objectForKey:@"chatRecordTimeOut"]];
  309. user.offlineNoPushMsg = [(NSDictionary *)[dict objectForKey:@"member"] objectForKey:@"offlineNoPushMsg"];
  310. user.talkTime = [dict objectForKey:@"talkTime"];
  311. user.allowInviteFriend = [dict objectForKey:@"allowInviteFriend"];
  312. user.allowUploadFile = [dict objectForKey:@"allowUploadFile"];
  313. user.allowConference = [dict objectForKey:@"allowConference"];
  314. user.allowSpeakCourse = [dict objectForKey:@"allowSpeakCourse"];
  315. user.category = [dict objectForKey:@"category"];
  316. user.createUserId = [dict objectForKey:@"userId"];
  317. user.timeCreate = [NSDate dateWithTimeIntervalSince1970:[[dict objectForKey:@"createTime"] longLongValue]];
  318. user.isNeedVerify = [dict objectForKey:@"isNeedVerify"];
  319. if([[dict allKeys] containsObject:@"groupType"])
  320. {
  321. NSDictionary *dictby=[dict objectForKey:@"groupType"];
  322. user.groupType = [dictby objectForKey:@"typeName"];
  323. }else{
  324. user.groupType = @"100000";
  325. }
  326. NSDictionary *member = [dict objectForKey:@"member"];
  327. #ifdef IS_MsgEncrypt
  328. if ([member objectForKey:@"chatKeyGroup"]) {
  329. user.chatKeyGroup = [g_msgUtil encryptRoomMsgKey:user.roomId randomKey:[member objectForKey:@"chatKeyGroup"]];
  330. }
  331. #endif
  332. if ([aDownload.action isEqualToString:act_roomListHis]) {
  333. if (![user haveTheUser]){
  334. [user insertRoom];
  335. }else {
  336. [user updateUserNickname];
  337. [user update];
  338. }
  339. }
  340. }
  341. }
  342. }
  343. @end