hotViewControllerHJ.m 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. #import "hotViewControllerHJ.h"
  2. #import "UIImageView+WebCache.h"
  3. #import "AppDelegate.h"
  4. #import <SDCycleScrollView/SDCycleScrollView.h>
  5. #import "Classification_view.h"
  6. #import "Classification_Alertview.h"
  7. #import "NewestItemCell.h"
  8. #import "HMHotBannerModel.h"
  9. #import "DistanceModel.h"
  10. #import "AdJumpViewModel.h"
  11. #import "VideoViewController.h"
  12. #import "SocietyHomePageVC.h"
  13. #import "UpgradeTipView.h"
  14. // 广告图默认滚动时间
  15. @interface hotViewControllerHJ ()<ClassificationDelegate,ClassificationDelegate2,UIScrollViewDelegate,PushToLiveControllerDelegate>
  16. {
  17. UIView *_nothingView;
  18. int selected;
  19. UIImageView *NoInternetImageV;
  20. CGSize collectionSize;
  21. NSString *stream;
  22. NSString *_oldSocietyListName; // 公会名称可以修改,修改前的公会名字
  23. NSString *_societyListName; // 公会名称
  24. }
  25. @property(nonatomic,strong) Classification_view *choose_view;
  26. @property(nonatomic,strong) Classification_Alertview *choose_Alert;
  27. @property (nonatomic, strong) NewestViewController *hotVC;
  28. @property (nonatomic, strong) SocietyHomePageVC *societyHomePage; // 公会
  29. @property (nonatomic, strong) UIScrollView *scrollView; // ScrollView
  30. @property (nonatomic, strong) NSMutableArray *itemTitleMutableArray; // 完整的分类标题容器
  31. @property (nonatomic, strong) NSMutableArray<VideoClassifiedModel *> *classifiedModelMutableArray; // 服务端下发分类的模型容器
  32. @property (nonatomic, strong) NSMutableArray<VideoViewController *> *videoVCMutableArray; // 服务端下发分类的对应的控制器容器
  33. @end
  34. @implementation hotViewControllerHJ
  35. -(void)viewDidAppear:(BOOL)animated{
  36. [super viewDidAppear:animated];
  37. }
  38. - (void)viewDidLoad {
  39. [super viewDidLoad];
  40. self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];
  41. self.automaticallyAdjustsScrollViewInsets = NO;
  42. self.itemTitleMutableArray = [NSMutableArray array];
  43. self.classifiedModelMutableArray = [NSMutableArray array];
  44. self.videoVCMutableArray = [NSMutableArray array];
  45. [self.itemTitleMutableArray setArray:@[ASLocalizedString(@"热门")]];
  46. [self.view addSubview:self.choose_view];
  47. [_choose_view mas_makeConstraints:^(MASConstraintMaker *make) {
  48. make.top.left.right.equalTo(self.view);
  49. make.height.equalTo(@45);
  50. }];
  51. self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 45, kScreenW, kScreenH - 45-kTabBarHeight - 20 - kNavigationBarHeight)];
  52. self.scrollView.delegate = self;
  53. self.scrollView.backgroundColor = kClearColor;
  54. self.scrollView.pagingEnabled = YES;
  55. self.scrollView.showsHorizontalScrollIndicator = NO;
  56. self.scrollView.bounces = NO;
  57. self.scrollView.contentSize = CGSizeMake(kScreenW * [self.itemTitleMutableArray count], CGRectGetHeight(self.scrollView.frame));
  58. [self.scrollView scrollRectToVisible:CGRectMake(0 * kScreenW, 0, kScreenW, CGRectGetHeight(self.scrollView.frame)) animated:NO];
  59. [self.view addSubview:self.scrollView];
  60. _hotVC = [[NewestViewController alloc]init];
  61. _hotVC.types = @"1";
  62. _hotVC.collectionViewFrame = CGRectMake(0, 0, _scrollView.width, _scrollView.bounds.size.height);
  63. _hotVC.view.frame = CGRectMake(self.scrollView.width * [self.itemTitleMutableArray indexOfObject:ASLocalizedString(@"热门")], 0, self.scrollView.width, _scrollView.bounds.size.height);
  64. _hotVC.delegate = self;
  65. [_scrollView addSubview:_hotVC.view];
  66. [self.choose_Alert setClassWithAry:self.itemTitleMutableArray];
  67. [self.choose_view setClassWithAry:self.itemTitleMutableArray];
  68. [self.choose_view selectWithIndex:0];
  69. self.scrollView.contentSize = CGSizeMake(self.scrollView.width * [self.itemTitleMutableArray count], CGRectGetHeight(self.scrollView.frame));
  70. // 升级提示等
  71. UpgradeTipView *upgradeTipView = [[UpgradeTipView alloc] init];
  72. [upgradeTipView initRewards];
  73. //赠送钻石奖励提示
  74. }
  75. - (void)viewWillAppear:(BOOL)animated
  76. {
  77. [super viewWillAppear:animated];
  78. self.navigationController.navigationBarHidden = YES;
  79. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  80. [parmDict setObject:@"app" forKey:@"ctl"];
  81. [parmDict setObject:@"init" forKey:@"act"];
  82. [[NetHttpsManager manager] POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson) {
  83. if ([responseJson toInt:@"status"] == 1) {
  84. [self loadClassifiedVC];
  85. }
  86. } FailureBlock:^(NSError *error) {
  87. }];
  88. }
  89. - (Classification_view *)choose_view
  90. {
  91. if (!_choose_view)
  92. {
  93. _choose_view =[[Classification_view alloc]init];
  94. _choose_view.delegate =self;
  95. }
  96. return _choose_view;
  97. }
  98. - (Classification_Alertview *)choose_Alert
  99. {
  100. if (!_choose_Alert)
  101. {
  102. _choose_Alert =[[Classification_Alertview alloc]init];
  103. [self.view addSubview:_choose_Alert];
  104. [_choose_Alert mas_makeConstraints:^(MASConstraintMaker *make) {
  105. make.centerX.top.width.height.equalTo(self.view);
  106. }];
  107. _choose_Alert.alpha =0;
  108. UITapGestureRecognizer *tap =[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(alertWillHidden)];
  109. _choose_Alert.userInteractionEnabled =YES;
  110. _choose_Alert.delegate =self;
  111. [_choose_Alert addGestureRecognizer:tap];
  112. }
  113. return _choose_Alert;
  114. }
  115. //分类view代理方法
  116. - (void)didSelectWith:(id)obj andxiabiao:(NSInteger)index
  117. {
  118. [self.choose_Alert selectWithIndex:index];
  119. [self.scrollView scrollRectToVisible:CGRectMake(index*self.scrollView.width, 0, self.scrollView.width, self.scrollView.height) animated:YES];
  120. if (index == 0) {
  121. [self.hotVC loadDataFromNet:1];
  122. }else{
  123. [self refreshClassifiedVC:index];
  124. }
  125. }
  126. - (void)showAllClass
  127. {
  128. [self alertWillHidden];
  129. }
  130. //Alert代理
  131. - (void)didSelectWithAlert:(id)obj
  132. {
  133. [self.choose_view selectWithIndex:[obj integerValue]];
  134. [self alertWillHidden];
  135. [self.scrollView scrollRectToVisible:CGRectMake([obj integerValue]*self.scrollView.width, 0, self.scrollView.width, self.scrollView.height) animated:YES];
  136. if ([obj integerValue] == 0) {
  137. [self.hotVC loadDataFromNet:1];
  138. }else{
  139. [self refreshClassifiedVC:[obj integerValue]];
  140. }
  141. }
  142. //实例方法
  143. - (void)alertWillHidden
  144. {
  145. __block typeof(self)blockself =self;
  146. if (self.choose_Alert.alpha ==0)
  147. {
  148. [UIView animateWithDuration:.4 animations:^{
  149. blockself.choose_Alert.alpha =1.;
  150. [blockself.view layoutIfNeeded];
  151. }];
  152. }else
  153. {
  154. [UIView animateWithDuration:.4 animations:^{
  155. blockself.choose_Alert.alpha =0.;
  156. [blockself.view layoutIfNeeded];
  157. }];
  158. }
  159. }
  160. #pragma mark - 上下滑动隐藏/显示导航栏
  161. - (void)didReceiveMemoryWarning {
  162. [super didReceiveMemoryWarning];
  163. // Dispose of any resources that can be recreated.
  164. }
  165. #pragma mark 动态加载初始化接口下发的分类、公会等
  166. - (void)loadClassifiedVC
  167. {
  168. CGFloat viewWidth = CGRectGetWidth(self.view.frame);
  169. // 动态添加、删除公会
  170. if ([GlobalVariables sharedInstance].appModel.open_society_module.intValue == 1 && ![BGUtils isBlankString:[GlobalVariables sharedInstance].appModel.society_list_name])
  171. {
  172. _societyListName = [GlobalVariables sharedInstance].appModel.society_list_name;
  173. if (![_societyListName isEqualToString:_oldSocietyListName] && [self.itemTitleMutableArray containsObject:_oldSocietyListName])//修改了公会名字并且原来有公会就替换
  174. {
  175. NSInteger index = [self.itemTitleMutableArray indexOfObject:_oldSocietyListName];
  176. [self.itemTitleMutableArray replaceObjectAtIndex:index withObject:_societyListName];
  177. _oldSocietyListName = _societyListName;
  178. }else if(![_societyListName isEqualToString:_oldSocietyListName] && ![self.itemTitleMutableArray containsObject:_oldSocietyListName])//修改了公会名字并且原来没有公会加上去
  179. {
  180. [self.itemTitleMutableArray addObject:_societyListName];
  181. _oldSocietyListName = _societyListName;
  182. }else
  183. {
  184. if (![self.itemTitleMutableArray containsObject:_societyListName])
  185. {
  186. [self.itemTitleMutableArray addObject:_societyListName];
  187. }
  188. }
  189. if (!self.societyHomePage.view.superview)
  190. {
  191. self.societyHomePage.view.frame = CGRectMake(viewWidth * [self.itemTitleMutableArray indexOfObject:_societyListName], 0, viewWidth, _scrollView.bounds.size.height);
  192. [self.scrollView addSubview:self.societyHomePage.view];
  193. }
  194. }
  195. else if ([GlobalVariables sharedInstance].appModel.open_society_module.intValue == 0 && [self.itemTitleMutableArray containsObject:_societyListName])
  196. {
  197. [self.itemTitleMutableArray removeObject:_societyListName];
  198. [self.societyHomePage.view removeFromSuperview];
  199. }
  200. if (![[GlobalVariables sharedInstance].appModel.video_classified isEqual:self.classifiedModelMutableArray])
  201. {
  202. [self updateClassiFiedVC];
  203. }
  204. }
  205. - (void)updateClassiFiedVC
  206. {
  207. CGFloat viewWidth = CGRectGetWidth(self.view.frame);
  208. @synchronized (self)
  209. {
  210. if (self.classifiedModelMutableArray.count > 0)
  211. {
  212. // 获取到本地暂存的服务端下发的分类的在完整的分类容器中的起点与终点,进行移除视频分类相关视图和视图控制器的操作
  213. VideoClassifiedModel *tmpModel = [self.classifiedModelMutableArray firstObject];
  214. NSInteger tmpIndex = [self.itemTitleMutableArray indexOfObject:tmpModel.title];
  215. VideoClassifiedModel *lastVideoModel = [self.classifiedModelMutableArray lastObject];
  216. NSInteger lastIndex = [self.itemTitleMutableArray indexOfObject:lastVideoModel.title];
  217. [self.videoVCMutableArray removeAllObjects];
  218. for (NSInteger i = tmpIndex; i <= lastIndex; i++)
  219. {
  220. if (self.scrollView.subviews.count > i)
  221. {
  222. [self.scrollView.subviews[i] removeFromSuperview];
  223. }
  224. }
  225. // 动态删除视频分类
  226. for (VideoClassifiedModel *tmpModel in self.classifiedModelMutableArray)
  227. {
  228. [self.itemTitleMutableArray removeObject:tmpModel.title];
  229. }
  230. }
  231. // 动态添加视频分类
  232. for (VideoClassifiedModel *model in [GlobalVariables sharedInstance].appModel.video_classified)
  233. {
  234. [self.itemTitleMutableArray addObject:model.title];
  235. }
  236. self.classifiedModelMutableArray = [GlobalVariables sharedInstance].appModel.video_classified;
  237. [self.choose_Alert setClassWithAry:self.itemTitleMutableArray];
  238. [self.choose_view setClassWithAry:self.itemTitleMutableArray];
  239. [self.choose_view selectWithIndex:0];
  240. self.scrollView.contentSize = CGSizeMake(self.scrollView.width * [self.itemTitleMutableArray count], CGRectGetHeight(self.scrollView.frame));
  241. for (NSInteger i = 0; i < self.classifiedModelMutableArray.count; ++i)
  242. {
  243. // 服务端下发的分类的在完整的分类容器中的起点
  244. VideoClassifiedModel *tmpModel = [self.classifiedModelMutableArray firstObject];
  245. NSUInteger tmpIndex = [self.itemTitleMutableArray indexOfObject:tmpModel.title];
  246. VideoViewController *videoVC = [[VideoViewController alloc] init];
  247. VideoClassifiedModel * model = [[GlobalVariables sharedInstance].appModel.video_classified objectAtIndex:i];
  248. videoVC.viewFrame = CGRectMake(0, 0, viewWidth, self.scrollView.bounds.size.height);
  249. videoVC.view.frame = CGRectMake(viewWidth * (i+tmpIndex), 0, viewWidth, self.scrollView.bounds.size.height);
  250. videoVC.classified_id = model.classified_id;
  251. [self.scrollView addSubview:videoVC.view];
  252. [self.videoVCMutableArray addObject:videoVC];
  253. }
  254. }
  255. }
  256. #pragma mark 刷新分类VC的数据
  257. - (void)refreshClassifiedVC:(NSInteger)page
  258. {
  259. if (self.classifiedModelMutableArray.count > 0)
  260. {
  261. // 服务端下发的分类的在完整的分类容器中的起点
  262. VideoClassifiedModel *tmpModel = [self.classifiedModelMutableArray firstObject];
  263. NSUInteger tmpIndex = [self.itemTitleMutableArray indexOfObject:tmpModel.title];
  264. // 服务端下发的分类的在完整的分类容器中的终点
  265. VideoClassifiedModel *tmpModel2 = [self.classifiedModelMutableArray lastObject];
  266. NSUInteger tmpIndex2 = [self.itemTitleMutableArray indexOfObject:tmpModel2.title];
  267. if (page >= tmpIndex && page <= tmpIndex2)
  268. {
  269. VideoViewController *videoVC = self.videoVCMutableArray[page-tmpIndex];
  270. [videoVC setNetworing:1];
  271. }
  272. }
  273. }
  274. #pragma mark 解决Segmented的滑块快速滑动时的延迟,同时把点击滑块的情况排除在外
  275. - (void)scrollViewDidScroll:(UIScrollView *)scrollView
  276. {
  277. CGFloat pageWidth = scrollView.frame.size.width;
  278. NSInteger tmpPage = scrollView.contentOffset.x / pageWidth;
  279. float tmpPage2 = scrollView.contentOffset.x / pageWidth;
  280. NSInteger page = tmpPage2-tmpPage>=0.5 ? tmpPage+1 : tmpPage;
  281. // [self.choose_view selectWithIndex:page];
  282. // [self.choose_Alert selectWithIndex:page];
  283. }
  284. #pragma mark 页面滚动,同时调起Segmented的滑块滑动起来等
  285. - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
  286. {
  287. CGFloat pageWidth = scrollView.frame.size.width;
  288. NSInteger page = scrollView.contentOffset.x / pageWidth;
  289. [self.choose_view selectWithIndex:page];
  290. [self.choose_Alert selectWithIndex:page];
  291. }
  292. #pragma mark 跳转到话题页面和hotTopicViewController二级页面
  293. - (void)pushToNextControllerWithModel:(cuserModel *)model
  294. {
  295. if ([model.cate_id isEqualToString:@"0"])
  296. {
  297. // 暂时不能跳转
  298. }
  299. else
  300. {
  301. NewestViewController *tmpController = [[NewestViewController alloc]init];
  302. tmpController.topicName = model.title;
  303. tmpController.cate_id = model.cate_id;
  304. tmpController.types = @"1";
  305. [[AppDelegate sharedAppDelegate]pushViewController:tmpController animated:YES];
  306. }
  307. }
  308. #pragma mark NewestViewController跳转到直播
  309. - (void)pushToLiveController:(LivingModel *)model modelArr:(NSArray *)modelArr isFirstJump:(BOOL)isFirstJump{
  310. if (![BGUtils isNetConnected])
  311. {
  312. return;
  313. }
  314. [[GlobalVariables sharedInstance].newestLivingMArray removeAllObjects];
  315. [[GlobalVariables sharedInstance].newestLivingMArray addObject:model];
  316. if ([self checkUser:[IMAPlatform sharedInstance].host])
  317. {
  318. TCShowLiveListItem *item = [[TCShowLiveListItem alloc]init];
  319. item.chatRoomId = model.group_id;
  320. item.avRoomId = model.room_id;
  321. item.title = StringFromInt(model.room_id);
  322. item.vagueImgUrl = model.head_image;
  323. TCShowUser *showUser = [[TCShowUser alloc]init];
  324. showUser.uid = model.user_id;
  325. showUser.avatar = model.head_image;
  326. item.host = showUser;
  327. item.is_voice = model.is_voice;
  328. if (model.live_in == FW_LIVE_STATE_ING)
  329. {
  330. item.liveType = FW_LIVE_TYPE_AUDIENCE;
  331. }
  332. // else if (model.live_in == FW_LIVE_STATE_RELIVE)
  333. // {
  334. // //
  335. // item.liveType = FW_LIVE_TYPE_RELIVE;
  336. // [GlobalVariables sharedInstance].appModel.spear_live = @"0";
  337. //// SHomePageVC *tmpController= [[SHomePageVC alloc]init];
  338. //// tmpController.user_id = model.user_id;
  339. //// tmpController.type = 0;
  340. //// [[AppDelegate sharedAppDelegate]pushViewController:tmpController];
  341. ////
  342. ////
  343. //// return;
  344. // }
  345. //2020-1-7 小直播变大
  346. [LiveCenterManager sharedInstance].itemModel=item;
  347. BOOL isSusWindow = [[LiveCenterManager sharedInstance] judgeIsSusWindow];
  348. [[LiveCenterManager sharedInstance] showLiveOfAudienceLiveofTCShowLiveListItem:item modelArr:modelArr isSusWindow:isSusWindow isSmallScreen:NO block:^(BOOL isFinished) {
  349. }];
  350. }
  351. else
  352. {
  353. [[BGHUDHelper sharedInstance] loading:@"" delay:2 execute:^{
  354. [[BGIMLoginManager sharedInstance] loginImSDK:YES succ:nil failed:nil];
  355. } completion:^{
  356. }];
  357. }
  358. }
  359. - (BOOL)checkUser:(id<IMHostAble>)user
  360. {
  361. if (![user conformsToProtocol:@protocol(AVUserAble)])
  362. {
  363. return NO;
  364. }
  365. return YES;
  366. }
  367. @end