HMHomeViewController.m 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800
  1. //
  2. // HMHomeViewController.m
  3. // BuguLive
  4. //
  5. // Created by xfg on 2017/6/29.
  6. // Copyright © 2017年 xfg. All rights reserved.
  7. //
  8. #import "HMHomeViewController.h"
  9. #import "SSearchVC.h"
  10. #import "UpgradeTipView.h"
  11. #import "SHomePageVC.h"
  12. #import "BGConversationSegmentController.h"
  13. #import "VideoViewController.h"
  14. #import "SocietyDetailVC.h"
  15. #import "SociatyListModel.h"
  16. #import "SocietyHomePageVC.h"
  17. #import "SChooseAreaView.h"
  18. #import "EveryDayFirstLoginPopView.h"/**<每日首次登录奖励*/
  19. // 动态项,便于后期拓展以及灵活组装
  20. static NSString const *kFocusOnStr = @"关注";
  21. static NSString const *kHotStr = @"热门";
  22. static NSString const *kNearbyStr = @"附近";
  23. static float const kSegmentLeftEdge = 10; // segmentedControl左边边距
  24. static float const kSegmentTitleFont = 15; // segmentedControl字体大小
  25. static NSInteger const kSelectedSegmentIndex = 1; // segmentedControl默认选中的index
  26. @interface HMHomeViewController ()<UIScrollViewDelegate, handleMainDelegate, PushToLiveControllerDelegate, HMHotViewControllerDelegate, SocietyHomePageVCDelegate>
  27. {
  28. JSBadgeView *_badge;
  29. BOOL _isFirstLoad; // 是否首次加载
  30. NSString *_oldSocietyListName; // 公会名称可以修改,修改前的公会名字
  31. NSString *_societyListName; // 公会名称
  32. UIButton *_addressBtn;
  33. }
  34. @property (nonatomic, strong) HMHotViewController *hotViewController; // 热门
  35. @property (nonatomic, strong) FocusOnViewController *focusOnViewController; // 关注
  36. @property (nonatomic, strong) NewestViewController *livingListViewController; // 最新
  37. @property (nonatomic, strong) NewestViewController *news_hotViewController; // 最新
  38. @property (nonatomic, strong) SocietyHomePageVC *societyHomePage; // 公会
  39. @property (nonatomic, strong) UIScrollView *scrollView; // ScrollView
  40. @property (nonatomic, strong) HMSegmentedControl *segmentedControl; // Segmented
  41. @property (nonatomic, strong) NSTimer *refreshHomeTimer; // 首页定时刷新
  42. @property (nonatomic, assign) BOOL isRefreshing; // 是否正在刷新
  43. @property (nonatomic, assign) NSInteger startPage; // Segmented的滑块起始页
  44. @property (nonatomic, assign) BOOL isClickedSegmented; // 是否点击了Segmented的滑块
  45. @property (nonatomic, strong) SChooseAreaView *chooseAreaView; // 地区选择
  46. @property (nonatomic, assign) int sexType; // 性别
  47. @property (nonatomic, strong) NSMutableArray *itemTitleMutableArray; // 完整的分类标题容器
  48. @property (nonatomic, strong) NSMutableArray<VideoClassifiedModel *> *classifiedModelMutableArray; // 服务端下发分类的模型容器
  49. @property (nonatomic, strong) NSMutableArray<VideoViewController *> *videoVCMutableArray; // 服务端下发分类的对应的控制器容器
  50. @end
  51. @implementation HMHomeViewController
  52. - (void)viewWillAppear:(BOOL)animated
  53. {
  54. [super viewWillAppear:animated];
  55. [self loadClassifiedVC];
  56. [self loadBtnBadageData];
  57. [self.navigationController setNavigationBarHidden:YES animated:NO];
  58. // 加载礼物列表
  59. [[GiftListManager sharedInstance] reloadGiftList];
  60. [self setupTimer];
  61. }
  62. - (void)viewDidAppear:(BOOL)animated
  63. {
  64. [super viewDidAppear:animated];
  65. if (!_isFirstLoad)
  66. {
  67. [self refreshOfTime];
  68. }
  69. _isFirstLoad = NO;
  70. }
  71. - (void)viewWillDisappear:(BOOL)animated
  72. {
  73. [super viewWillDisappear:animated];
  74. [self.navigationController setNavigationBarHidden:NO animated:NO];
  75. [self invalidateTimer];
  76. }
  77. - (void)viewDidLoad
  78. {
  79. [super viewDidLoad];
  80. // self.navigationController.navigationBar.hidden = YES;
  81. }
  82. - (void)initFWUI
  83. {
  84. [super initFWUI];
  85. [BGIMMsgHandler sharedInstance];
  86. self.navigationItem.title = @"";
  87. self.BuguLive.appNavigationBarHeight = self.navigationController.navigationBar.frame.size.height;
  88. self.BuguLive.appTabBarHeight = self.tabBarController.tabBar.frame.size.height;
  89. _startPage = kSelectedSegmentIndex;
  90. _videoVCMutableArray = [NSMutableArray array];
  91. _oldSocietyListName = self.BuguLive.appModel.society_list_name;
  92. CGFloat viewWidth = CGRectGetWidth(self.view.frame);
  93. CGFloat viewHeight = CGRectGetHeight(self.view.frame);
  94. #if kSupportH5Shopping
  95. self.itemTitleMutableArray = [NSMutableArray arrayWithObjects:kFocusOnStr, kHotStr, nil];
  96. #else
  97. // 配置本地分类
  98. self.itemTitleMutableArray = [NSMutableArray arrayWithObjects:kFocusOnStr, kHotStr, kNearbyStr, nil];
  99. #endif
  100. self.segmentedControl = [[HMSegmentedControl alloc] initWithFrame:CGRectMake(60, kStatusBarHeight, viewWidth - 60 - 80 , kSegmentedHeight)];
  101. self.segmentedControl.sectionTitles = self.itemTitleMutableArray;
  102. self.segmentedControl.selectedSegmentIndex = kSelectedSegmentIndex;
  103. self.segmentedControl.backgroundColor = kWhiteColor;
  104. self.segmentedControl.titleTextAttributes = @{NSForegroundColorAttributeName : kAppGrayColor3, NSFontAttributeName : [UIFont systemFontOfSize:kSegmentTitleFont]};
  105. self.segmentedControl.selectedTitleTextAttributes = @{NSForegroundColorAttributeName : kAppMainColor, NSBackgroundColorAttributeName : kClearColor, NSFontAttributeName : [UIFont systemFontOfSize:kSegmentTitleFont]};
  106. self.segmentedControl.selectionIndicatorColor = kAppMainColor;
  107. self.segmentedControl.selectionIndicatorHeight = 3;
  108. self.segmentedControl.selectionIndicatorBoxColor = kClearColor;
  109. self.segmentedControl.selectionStyle = HMSegmentedControlSelectionStyleTextWidthStripe;
  110. self.segmentedControl.selectionIndicatorLocation = HMSegmentedControlSelectionIndicatorLocationDown;
  111. self.segmentedControl.segmentEdgeInset = UIEdgeInsetsMake(0, kSegmentLeftEdge, 0, kSegmentLeftEdge);
  112. self.segmentedControl.segmentWidthStyle = HMSegmentedControlSegmentWidthStyleDynamicFixedSuperView;
  113. self.segmentedControl.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth;
  114. FWWeakify(self)
  115. [self.segmentedControl setIndexChangeBlock:^(NSInteger index) {
  116. FWStrongify(self)
  117. [self.scrollView scrollRectToVisible:CGRectMake(viewWidth * index, 0, viewWidth, CGRectGetHeight(self.scrollView.frame)) animated:YES];
  118. [self loadClassifiedVC];
  119. [self refreshClassifiedVC:index];
  120. if (index == 1) {
  121. if (self.chooseAreaView) {
  122. [self removeChooseView];
  123. }
  124. }
  125. self.isClickedSegmented = YES;
  126. }];
  127. [self.view addSubview:self.segmentedControl];
  128. self.navigationController.navigationBar.hidden = YES;
  129. // [self.navigationController setNavigationBarHidden:<#(BOOL)#>]
  130. // [self.navigationController.navigationBar addSubview:_segmentedControl];
  131. self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, _segmentedControl.bottom, viewWidth, viewHeight - kSegmentedHeight-kTabBarHeight - 20)];
  132. self.scrollView.delegate = self;
  133. self.scrollView.backgroundColor = kClearColor;
  134. self.scrollView.pagingEnabled = YES;
  135. self.scrollView.showsHorizontalScrollIndicator = NO;
  136. self.scrollView.bounces = NO;
  137. self.scrollView.contentSize = CGSizeMake(viewWidth * [self.itemTitleMutableArray count], CGRectGetHeight(self.scrollView.frame));
  138. [self.scrollView scrollRectToVisible:CGRectMake(kSelectedSegmentIndex * viewWidth, 0, viewWidth, CGRectGetHeight(self.scrollView.frame)) animated:NO];
  139. [self.view addSubview:self.scrollView];
  140. // 关注
  141. if ([self.itemTitleMutableArray containsObject:kFocusOnStr])
  142. {
  143. _focusOnViewController = [[FocusOnViewController alloc]init];
  144. _focusOnViewController.collectionViewFrame = CGRectMake(0, 0, viewWidth, _scrollView.frame.size.height);
  145. _focusOnViewController.view.frame = CGRectMake(viewWidth * [self.itemTitleMutableArray indexOfObject:kFocusOnStr], 0, viewWidth, _scrollView.bounds.size.height);
  146. _focusOnViewController.delegate = self;
  147. [_scrollView addSubview:_focusOnViewController.view];
  148. }
  149. // 热门
  150. if ([self.itemTitleMutableArray containsObject:kHotStr])
  151. {
  152. _news_hotViewController = [[NewestViewController alloc]init];
  153. _news_hotViewController.types = @"1";
  154. _news_hotViewController.collectionViewFrame = CGRectMake(0, 0, viewWidth, _scrollView.bounds.size.height);
  155. _news_hotViewController.view.frame = CGRectMake(viewWidth * [self.itemTitleMutableArray indexOfObject:kHotStr], 0, viewWidth, _scrollView.bounds.size.height);
  156. _news_hotViewController.delegate = self;
  157. [_scrollView addSubview:_news_hotViewController.view];
  158. // _hotViewController = [[HMHotViewController alloc]init];
  159. // _hotViewController.tableViewFrame = CGRectMake(0, 0, viewWidth, _scrollView.bounds.size.height);
  160. // _hotViewController.view.frame = CGRectMake(viewWidth * [self.itemTitleMutableArray indexOfObject:kHotStr], 0, viewWidth, _scrollView.bounds.size.height);
  161. // _hotViewController.delegate = self;
  162. // _hotViewController.areaString = [NSString stringWithFormat:@"%@",kHotStr];
  163. // [_scrollView addSubview:_hotViewController.view];
  164. }
  165. // 附近
  166. if ([self.itemTitleMutableArray containsObject:kNearbyStr])
  167. {
  168. _livingListViewController = [[NewestViewController alloc]init];
  169. _livingListViewController.collectionViewFrame = CGRectMake(0, 0, viewWidth, _scrollView.bounds.size.height);
  170. _livingListViewController.types = @"2";
  171. _livingListViewController.view.frame = CGRectMake(viewWidth * [self.itemTitleMutableArray indexOfObject:kNearbyStr], 0, viewWidth, _scrollView.bounds.size.height);
  172. _livingListViewController.delegate = self;
  173. [_scrollView addSubview:_livingListViewController.view];
  174. }
  175. [self loadClassifiedVC];
  176. [self leftOrRightNavItem];
  177. [self.BuguLive addObserver:self forKeyPath:@"appModel.video_classified" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:nil];
  178. // 升级提示等
  179. UpgradeTipView *upgradeTipView = [[UpgradeTipView alloc] init];
  180. [upgradeTipView initRewards];
  181. }
  182. - (void)initFWData
  183. {
  184. [super initFWData];
  185. _isFirstLoad = YES;
  186. _isRefreshing = YES;
  187. //
  188. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateTitleName:) name:@"updateTitleName" object:nil];
  189. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(invalidateTimer) name:kInvalidateHomeTimer object:nil];
  190. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshHome) name:kRefreshHome object:nil];
  191. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  192. [self loadBtnBadageData];
  193. });
  194. }
  195. - (void)leftOrRightNavItem
  196. {
  197. #if kSupportH5Shopping
  198. UIButton *rightButton = [[UIButton alloc]initWithFrame:CGRectMake(6, 22, 20, 20)];
  199. [rightButton setImage:[UIImage imageNamed:@"hm_search"] forState:UIControlStateNormal];
  200. [rightButton addTarget:self action:@selector(goSearch) forControlEvents:UIControlEventTouchUpInside];
  201. UIBarButtonItem *leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightButton];
  202. self.navigationItem.rightBarButtonItem = leftBarButtonItem;
  203. #else
  204. // 左上角按钮
  205. UIButton *leftButton = [[UIButton alloc]initWithFrame:CGRectMake(20, kStatusBarHeight, 35, kNavigationBarHeight)];
  206. [leftButton setImage:[UIImage imageNamed:@"hm_search"] forState:UIControlStateNormal];
  207. [leftButton addTarget:self action:@selector(goSearch) forControlEvents:UIControlEventTouchUpInside];
  208. leftButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  209. UIBarButtonItem *leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
  210. // self.navigationItem.leftBarButtonItem = leftBarButtonItem;
  211. [self.view addSubview:leftButton];
  212. // 右上角按钮
  213. UIView *rightViewContrainer = [[UIView alloc] initWithFrame:CGRectMake(kScreenW - 70 - 10, kStatusBarHeight, 70, kNavigationBarHeight)];
  214. rightViewContrainer.backgroundColor = kClearColor;
  215. UIButton *rightButton = [[UIButton alloc]initWithFrame:CGRectMake(CGRectGetWidth(rightViewContrainer.frame)-35, 0, 35, rightViewContrainer.frame.size.height)];
  216. [rightButton setImage:[UIImage imageNamed:@"hm_private_message"] forState:UIControlStateNormal];
  217. [rightButton addTarget:self action:@selector(clickRightHeadBtn:) forControlEvents:UIControlEventTouchUpInside];
  218. rightButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
  219. [rightViewContrainer addSubview:rightButton];
  220. _addressBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 35, rightViewContrainer.frame.size.height)];
  221. [_addressBtn setImage:[UIImage imageNamed:@"hm_address"] forState:UIControlStateNormal];
  222. [_addressBtn addTarget:self action:@selector(clickRightHeadBtn:) forControlEvents:UIControlEventTouchUpInside];
  223. _addressBtn.tag = 1;
  224. _addressBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
  225. [rightViewContrainer addSubview:_addressBtn];
  226. [self.view addSubview:rightViewContrainer];
  227. [self.view addSubview:leftButton];
  228. // UIBarButtonItem *rightButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightViewContrainer];
  229. // self.navigationItem.rightBarButtonItem = rightButtonItem;
  230. // 设置角标
  231. [self initBadgeBtn:rightButton];
  232. #endif
  233. }
  234. #pragma mark 动态加载初始化接口下发的分类、公会等
  235. - (void)loadClassifiedVC
  236. {
  237. CGFloat viewWidth = CGRectGetWidth(self.view.frame);
  238. // 动态添加、删除公会
  239. if (self.BuguLive.appModel.open_society_module.intValue == 1 && ![BGUtils isBlankString:self.BuguLive.appModel.society_list_name])
  240. {
  241. _societyListName = self.BuguLive.appModel.society_list_name;
  242. if (![_societyListName isEqualToString:_oldSocietyListName] && [self.itemTitleMutableArray containsObject:_oldSocietyListName])//修改了公会名字并且原来有公会就替换
  243. {
  244. NSInteger index = [self.itemTitleMutableArray indexOfObject:_oldSocietyListName];
  245. [self.itemTitleMutableArray replaceObjectAtIndex:index withObject:_societyListName];
  246. _oldSocietyListName = _societyListName;
  247. }else if(![_societyListName isEqualToString:_oldSocietyListName] && ![self.itemTitleMutableArray containsObject:_oldSocietyListName])//修改了公会名字并且原来没有公会加上去
  248. {
  249. [self.itemTitleMutableArray addObject:_societyListName];
  250. _oldSocietyListName = _societyListName;
  251. }else
  252. {
  253. if (![self.itemTitleMutableArray containsObject:_societyListName])
  254. {
  255. [self.itemTitleMutableArray addObject:_societyListName];
  256. }
  257. }
  258. if (!self.societyHomePage.view.superview)
  259. {
  260. self.societyHomePage.view.frame = CGRectMake(viewWidth * [self.itemTitleMutableArray indexOfObject:_societyListName], 0, viewWidth, _scrollView.bounds.size.height);
  261. [self.scrollView addSubview:self.societyHomePage.view];
  262. }
  263. }
  264. else if (self.BuguLive.appModel.open_society_module.intValue == 0 && [self.itemTitleMutableArray containsObject:_societyListName])
  265. {
  266. [self.itemTitleMutableArray removeObject:_societyListName];
  267. [self.societyHomePage.view removeFromSuperview];
  268. }
  269. if (![self.BuguLive.appModel.video_classified isEqual:self.classifiedModelMutableArray])
  270. {
  271. [self updateClassiFiedVC];
  272. }
  273. }
  274. - (void)updateClassiFiedVC
  275. {
  276. CGFloat viewWidth = CGRectGetWidth(self.view.frame);
  277. @synchronized (self)
  278. {
  279. if (self.classifiedModelMutableArray.count > 0)
  280. {
  281. // 获取到本地暂存的服务端下发的分类的在完整的分类容器中的起点与终点,进行移除视频分类相关视图和视图控制器的操作
  282. VideoClassifiedModel *tmpModel = [self.classifiedModelMutableArray firstObject];
  283. NSInteger tmpIndex = [self.itemTitleMutableArray indexOfObject:tmpModel.title];
  284. VideoClassifiedModel *lastVideoModel = [self.classifiedModelMutableArray lastObject];
  285. NSInteger lastIndex = [self.itemTitleMutableArray indexOfObject:lastVideoModel.title];
  286. [self.videoVCMutableArray removeAllObjects];
  287. for (NSInteger i = tmpIndex; i <= lastIndex; i++)
  288. {
  289. if (self.scrollView.subviews.count > i)
  290. {
  291. [self.scrollView.subviews[i] removeFromSuperview];
  292. }
  293. }
  294. // 动态删除视频分类
  295. for (VideoClassifiedModel *tmpModel in self.classifiedModelMutableArray)
  296. {
  297. [self.itemTitleMutableArray removeObject:tmpModel.title];
  298. }
  299. }
  300. // 动态添加视频分类
  301. for (VideoClassifiedModel *model in self.BuguLive.appModel.video_classified)
  302. {
  303. [self.itemTitleMutableArray addObject:model.title];
  304. }
  305. self.classifiedModelMutableArray = self.BuguLive.appModel.video_classified;
  306. self.segmentedControl.sectionTitles = self.itemTitleMutableArray;
  307. self.scrollView.contentSize = CGSizeMake(viewWidth * [self.itemTitleMutableArray count], CGRectGetHeight(self.scrollView.frame));
  308. for (NSInteger i = 0; i < self.classifiedModelMutableArray.count; ++i)
  309. {
  310. // 服务端下发的分类的在完整的分类容器中的起点
  311. VideoClassifiedModel *tmpModel = [self.classifiedModelMutableArray firstObject];
  312. NSUInteger tmpIndex = [self.itemTitleMutableArray indexOfObject:tmpModel.title];
  313. VideoViewController *videoVC = [[VideoViewController alloc] init];
  314. VideoClassifiedModel * model = [self.BuguLive.appModel.video_classified objectAtIndex:i];
  315. videoVC.viewFrame = CGRectMake(0, 0, viewWidth, self.scrollView.bounds.size.height);
  316. videoVC.view.frame = CGRectMake(viewWidth * (i+tmpIndex), 0, viewWidth, self.scrollView.bounds.size.height);
  317. videoVC.classified_id = model.classified_id;
  318. [self.scrollView addSubview:videoVC.view];
  319. [self.videoVCMutableArray addObject:videoVC];
  320. }
  321. }
  322. }
  323. #pragma mark 刷新分类VC的数据
  324. - (void)refreshClassifiedVC:(NSInteger)page
  325. {
  326. if (self.classifiedModelMutableArray.count > 0)
  327. {
  328. // 服务端下发的分类的在完整的分类容器中的起点
  329. VideoClassifiedModel *tmpModel = [self.classifiedModelMutableArray firstObject];
  330. NSUInteger tmpIndex = [self.itemTitleMutableArray indexOfObject:tmpModel.title];
  331. // 服务端下发的分类的在完整的分类容器中的终点
  332. VideoClassifiedModel *tmpModel2 = [self.classifiedModelMutableArray lastObject];
  333. NSUInteger tmpIndex2 = [self.itemTitleMutableArray indexOfObject:tmpModel2.title];
  334. if (page >= tmpIndex && page <= tmpIndex2)
  335. {
  336. VideoViewController *videoVC = self.videoVCMutableArray[page-tmpIndex];
  337. [videoVC setNetworing:1];
  338. }
  339. }
  340. NSString *tmpStr = [BGUtils isBlankString:self.news_hotViewController.areaString] ? kHotStr : self.news_hotViewController.areaString;
  341. [self isShowAddressBtn:(page==[self.itemTitleMutableArray indexOfObject:tmpStr] ? YES : NO)];
  342. }
  343. #pragma mark - ----------------------- 事件处理 -----------------------
  344. - (void)isShowAddressBtn:(BOOL)isShow
  345. {
  346. if (isShow)
  347. {
  348. _addressBtn.hidden = NO;
  349. }
  350. else
  351. {
  352. _addressBtn.hidden = YES;
  353. }
  354. }
  355. #pragma mark 搜索
  356. - (void)goSearch
  357. {
  358. [self removeChooseView];
  359. SSearchVC *searchVC = [[SSearchVC alloc]init];
  360. searchVC.searchType = @"0";
  361. [[AppDelegate sharedAppDelegate] pushViewController:searchVC animated:YES];
  362. }
  363. #pragma mark 右上角地区、IM按钮事件
  364. - (void)clickRightHeadBtn:(UIButton *)btn
  365. {
  366. if (btn.tag == 1)
  367. {
  368. if (!self.chooseAreaView)
  369. {
  370. self.chooseAreaView = [[SChooseAreaView alloc]initWithFrame:CGRectMake(0, kScreenH, kScreenW, kScreenH-kStatusBarHeight-kNavigationBarHeight) andChooseType:[self.news_hotViewController.sexString intValue] andAreaStr:self.news_hotViewController.areaString];
  371. FWWeakify(self)
  372. [self.chooseAreaView setAreaBlock:^(NSString *areStr, int sexType){
  373. FWStrongify(self)
  374. if (areStr) {
  375. [self.itemTitleMutableArray replaceObjectAtIndex:1 withObject:areStr];
  376. self.segmentedControl.sectionTitles = self.itemTitleMutableArray;
  377. self.news_hotViewController.areaString = areStr;
  378. self.news_hotViewController.sexString = [NSString stringWithFormat:@"%d",sexType];
  379. [self.news_hotViewController loadDataFromNet:1];
  380. [self removeChooseView];
  381. }
  382. }];
  383. [[[UIApplication sharedApplication] keyWindow] addSubview:self.chooseAreaView];
  384. [UIView animateWithDuration:0.6 animations:^{
  385. CGRect rect = self.chooseAreaView.frame;
  386. rect.origin.y = kStatusBarHeight+kNavigationBarHeight;
  387. self.chooseAreaView.frame = rect;
  388. }];
  389. }
  390. else
  391. {
  392. [self removeChooseView];
  393. }
  394. }
  395. else
  396. {
  397. [self removeChooseView];
  398. BGConversationSegmentController *chatListVC = [[BGConversationSegmentController alloc]init];
  399. [[AppDelegate sharedAppDelegate] pushViewController:chatListVC animated:YES];
  400. }
  401. }
  402. - (void)removeChooseView
  403. {
  404. [UIView animateWithDuration:0.6 animations:^{
  405. CGRect rect = self.chooseAreaView.frame;
  406. rect.origin.y = kScreenH;
  407. self.chooseAreaView.frame = rect;
  408. } completion:^(BOOL finished) {
  409. [self.chooseAreaView removeFromSuperview];
  410. self.chooseAreaView = nil;
  411. }];
  412. }
  413. #pragma mark 通知处理事件
  414. - (void)updateTitleName:(NSNotification *)noti
  415. {
  416. if ([[noti.object objectForKey:@"name"] length])
  417. {
  418. [self.itemTitleMutableArray replaceObjectAtIndex:1 withObject:[noti.object objectForKey:@"name"]];
  419. self.segmentedControl.sectionTitles = self.itemTitleMutableArray;
  420. }
  421. }
  422. #pragma mark - ----------------------- 首页刷新机制 -----------------------
  423. - (void)refreshHome
  424. {
  425. [self setupTimer];
  426. [self refreshOfTime];
  427. }
  428. - (void)setupTimer
  429. {
  430. @synchronized (self)
  431. {
  432. if (!_refreshHomeTimer)
  433. {
  434. _refreshHomeTimer = [NSTimer scheduledTimerWithTimeInterval:kRefreshWithNewaTimeInterval target:self selector:@selector(refreshOfTime) userInfo:nil repeats:YES];
  435. [[NSRunLoop currentRunLoop] addTimer:_refreshHomeTimer forMode:NSRunLoopCommonModes];
  436. }
  437. }
  438. }
  439. - (void)invalidateTimer
  440. {
  441. [_refreshHomeTimer invalidate];
  442. _refreshHomeTimer = nil;
  443. }
  444. #pragma mark 最新和最热20秒定时刷新
  445. - (void)refreshOfTime
  446. {
  447. // 防止短时间内重复刷新
  448. if (self.isRefreshing && [[[BGTabBarController sharedInstance] selectedViewController].childViewControllers[0] isKindOfClass:[HMHomeViewController class]])
  449. {
  450. self.isRefreshing = NO;
  451. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(4.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  452. self.isRefreshing = YES;
  453. });
  454. }
  455. else
  456. {
  457. return;
  458. }
  459. NSDateFormatter *dateformatter = [[NSDateFormatter alloc] init];
  460. [dateformatter setDateFormat:@"HH:mm:ss"];
  461. NSLog(ASLocalizedString(@"============调起首页刷新机制时间点:%@"),[dateformatter stringFromDate:[NSDate date]]);
  462. if (_focusOnViewController)
  463. {
  464. [_focusOnViewController requestNetWorking];
  465. }
  466. if (_hotViewController)
  467. {
  468. [_hotViewController loadDataFromNet:1];
  469. }
  470. if (_livingListViewController)
  471. {
  472. [_livingListViewController loadDataWithPage:1];
  473. }
  474. // 当 open_society_module == 1 开启公会功能,公会名称根据字段 society_list_name 由服务器下发
  475. if (self.BuguLive.appModel.open_society_module.intValue == 1)
  476. {
  477. [_societyHomePage loadDataWithPage:1];
  478. }
  479. }
  480. #pragma mark - ----------------------- 代理 -----------------------
  481. #pragma mark 解决Segmented的滑块快速滑动时的延迟,同时把点击滑块的情况排除在外
  482. - (void)scrollViewDidScroll:(UIScrollView *)scrollView
  483. {
  484. if (!self.isClickedSegmented)
  485. {
  486. CGFloat pageWidth = scrollView.frame.size.width;
  487. NSInteger tmpPage = scrollView.contentOffset.x / pageWidth;
  488. float tmpPage2 = scrollView.contentOffset.x / pageWidth;
  489. NSInteger page = tmpPage2-tmpPage>=0.5 ? tmpPage+1 : tmpPage;
  490. if (_startPage != page)
  491. {
  492. [self.segmentedControl setSelectedSegmentIndex:page animated:YES];
  493. _startPage = page;
  494. }
  495. }
  496. }
  497. #pragma mark 页面滚动,同时调起Segmented的滑块滑动起来等
  498. - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
  499. {
  500. CGFloat pageWidth = scrollView.frame.size.width;
  501. NSInteger page = scrollView.contentOffset.x / pageWidth;
  502. [self loadClassifiedVC];
  503. [self refreshClassifiedVC:page];
  504. self.isClickedSegmented = NO;
  505. [self.segmentedControl setSelectedSegmentIndex:page animated:YES];
  506. }
  507. #pragma mark 跳转HomePageController页面
  508. - (void)goToMainPage:(NSString *)userID
  509. {
  510. SHomePageVC *tmpController= [[SHomePageVC alloc]init];
  511. tmpController.user_id = userID;
  512. tmpController.type = 0;
  513. [[AppDelegate sharedAppDelegate] pushViewController:tmpController animated:YES];
  514. }
  515. - (void)goToNewestView
  516. {
  517. if ([self.itemTitleMutableArray containsObject:kHotStr])
  518. {
  519. NSUInteger tmpIndex = [self.itemTitleMutableArray indexOfObject:kHotStr];
  520. self.segmentedControl.selectedSegmentIndex = tmpIndex;
  521. [self.scrollView scrollRectToVisible:CGRectMake(kScreenW * tmpIndex, 0, kScreenW, CGRectGetHeight(self.scrollView.frame)-10) animated:NO];
  522. }
  523. }
  524. #pragma mark 跳转到话题页面和hotTopicViewController二级页面
  525. - (void)pushToNextControllerWithModel:(cuserModel *)model
  526. {
  527. if ([model.cate_id isEqualToString:@"0"])
  528. {
  529. // 暂时不能跳转
  530. }
  531. else
  532. {
  533. NewestViewController *tmpController = [[NewestViewController alloc]init];
  534. tmpController.topicName = model.title;
  535. tmpController.cate_id = model.cate_id;
  536. tmpController.types = @"1";
  537. [[AppDelegate sharedAppDelegate] pushViewController:tmpController animated:YES];
  538. }
  539. }
  540. #pragma mark NewestViewController跳转到直播
  541. -(void)pushToLiveController:(LivingModel *)model modelArr:(NSArray *)modelArr isFirstJump:(BOOL)isFirstJump
  542. {
  543. if (![BGUtils isNetConnected])
  544. {
  545. return;
  546. }
  547. [self.BuguLive.newestLivingMArray removeAllObjects];
  548. [self.BuguLive.newestLivingMArray addObject:model];
  549. if ([self checkUser:[IMAPlatform sharedInstance].host])
  550. {
  551. TCShowLiveListItem *item = [[TCShowLiveListItem alloc]init];
  552. item.chatRoomId = model.group_id;
  553. item.avRoomId = model.room_id;
  554. item.title = StringFromInt(model.room_id);
  555. item.vagueImgUrl = model.head_image;
  556. item.is_voice = model.is_voice;
  557. TCShowUser *showUser = [[TCShowUser alloc]init];
  558. showUser.uid = model.user_id;
  559. showUser.avatar = model.head_image;
  560. item.host = showUser;
  561. if (model.live_in == FW_LIVE_STATE_ING)
  562. {
  563. item.liveType = FW_LIVE_TYPE_AUDIENCE;
  564. }
  565. // else if (model.live_in == FW_LIVE_STATE_RELIVE)
  566. // {
  567. // item.liveType = FW_LIVE_TYPE_RELIVE;
  568. // }
  569. //2020-1-7 小直播变大
  570. [LiveCenterManager sharedInstance].itemModel=item;
  571. BOOL isSusWindow = [[LiveCenterManager sharedInstance] judgeIsSusWindow];
  572. [[LiveCenterManager sharedInstance] showLiveOfAudienceLiveofTCShowLiveListItem:item modelArr:modelArr isSusWindow:isSusWindow isSmallScreen:NO block:^(BOOL isFinished) {
  573. }];
  574. [self invalidateTimer];
  575. }
  576. else
  577. {
  578. [[BGHUDHelper sharedInstance] loading:@"" delay:2 execute:^{
  579. [[BGIMLoginManager sharedInstance] loginImSDK:YES succ:nil failed:nil];
  580. } completion:^{
  581. }];
  582. }
  583. }
  584. - (BOOL)checkUser:(id<IMHostAble>)user
  585. {
  586. if (![user conformsToProtocol:@protocol(AVUserAble)])
  587. {
  588. return NO;
  589. }
  590. return YES;
  591. }
  592. #pragma mark 跳转到天团详情页面
  593. - (void)pushSocietyDetail:(SociatyListModel *)listModel
  594. {
  595. SocietyDetailVC *tianTuanVC = [[SocietyDetailVC alloc] init];
  596. tianTuanVC.mySocietyID = [listModel.society_id intValue];
  597. tianTuanVC.type = [listModel.type intValue];
  598. [[AppDelegate sharedAppDelegate] pushViewController:tianTuanVC animated:YES];
  599. }
  600. #pragma mark - ----------------------- 私信消息、角标 -----------------------
  601. #pragma mark IM
  602. - (void)iMChatHaveNotification:(NSNotification*)notification
  603. {
  604. //all 角标数据
  605. [self loadBtnBadageData];
  606. }
  607. /**
  608. 获取角标的数据: 注意:调All未读/调好友&&非好友方法 算All时,别调后者2各和来算,里面有耗时操作
  609. 使用:1.在willApperar 2.SDK监听会发通知,通知的方法/block 里调用
  610. 给控件初始化一个角标
  611. badage的 数据 获取(个人页面获取所有未读的条数)
  612. 1.在willApear里调用一次 2.SDk消息变化,接受通知,在通知方法还要调用 用于更新 角标数据
  613. */
  614. - (void)loadBtnBadageData
  615. {
  616. [SFriendObj getAllUnReadCountComplete:^(int num) {
  617. //all
  618. int scount = num;
  619. if( scount )
  620. {
  621. if(scount > 98)
  622. {
  623. _badge.badgeText = @"99+";
  624. }
  625. else
  626. {
  627. _badge.badgeText = [NSString stringWithFormat:@"%d",scount];
  628. }
  629. }
  630. else
  631. {
  632. _badge.badgeText = nil;
  633. }
  634. }];
  635. }
  636. /**
  637. 设置 角标
  638. @param sender 对应的控件
  639. */
  640. - (void)initBadgeBtn:(UIButton *)sender
  641. {
  642. //-好友
  643. _badge = [[JSBadgeView alloc]initWithParentView:sender alignment:JSBadgeViewAlignmentTopRight];
  644. _badge.badgePositionAdjustment = CGPointMake(0, 12);
  645. }
  646. #pragma mark - ----------------------- GET -----------------------
  647. - (SocietyHomePageVC *)societyHomePage
  648. {
  649. if (!_societyHomePage)
  650. {
  651. _societyHomePage = [[SocietyHomePageVC alloc] init];
  652. _societyHomePage.societyFrame = CGRectMake(0, 0, CGRectGetWidth(self.view.frame), _scrollView.bounds.size.height);
  653. _societyHomePage.delegate = self;
  654. }
  655. return _societyHomePage;
  656. }
  657. - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context
  658. {
  659. [self updateClassiFiedVC];
  660. }
  661. - (void)dealloc
  662. {
  663. [self.BuguLive removeObserver:self forKeyPath:@"appModel.video_classified" context:nil];
  664. [[NSNotificationCenter defaultCenter] removeObserver:self];
  665. }
  666. @end