FocusOnViewController.m 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  1. //
  2. // FocusOnViewController.m
  3. // BuguLive
  4. //
  5. // Created by GuoMs on 16/7/4.
  6. // Copyright © 2016年 xfg. All rights reserved.
  7. //
  8. #import "FocusOnViewController.h"
  9. #import "HMHotItemModel.h"
  10. #import "HMHotTableViewCell.h"
  11. #import "cuserModel.h"
  12. #import "LivingModel.h"
  13. #import "HMHotModel.h"
  14. #import "OneSectionCell.h"
  15. #import "WebModels.h"
  16. #import <QMapKit/QMapKit.h>
  17. #import <QMapSearchKit/QMapSearchKit.h>
  18. #import "DistanceModel.h"
  19. #import "NewestItemCell.h"
  20. #import "SDCycleScrollView.h"
  21. #import "AdJumpViewModel.h"
  22. #import "PlayBackCell.h"
  23. #import "NewestViewController.h"
  24. #import "FocusHeaderCollectReusView.h"
  25. #import "FocusOnCollectCell.h"
  26. NS_ENUM(NSInteger ,FocusOnViewTableView)
  27. {
  28. FWFocusOnZeroSection, //广告图
  29. FWFocusOnFirstSection, //热门定位
  30. FWFocusOnTab_Count,
  31. };
  32. static NSString *const cellReuseIdentifier0 = @"cellReuseIdentifie0";
  33. static NSString *const cellReuseIdentifier1 = @"cellReuseIdentifier1";
  34. static NSString *const cellReuseIdentifier2 = @"cellReuseIdentifier2";
  35. @interface FocusOnViewController ()<HMHotTableViewCellDelegate,playToMainDelegate,UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>
  36. {
  37. NSString *_sexString;
  38. NSString *_areaString;
  39. }
  40. @property (nonatomic, strong) NSMutableArray *dataArray;
  41. @property (nonatomic, strong) NSMutableArray *recommendArray;/**<目前推荐array假数据*/
  42. @property (nonatomic, assign) CGFloat heigth;
  43. @property ( nonatomic,strong) UICollectionView *collectionView; //CollectionView
  44. @property ( nonatomic,strong) UICollectionViewFlowLayout *layout;
  45. @end
  46. @implementation FocusOnViewController
  47. - (void)viewDidLoad
  48. {
  49. [super viewDidLoad];
  50. self.view.backgroundColor = kClearColor;
  51. [self creatView];
  52. }
  53. - (void)creatView
  54. {
  55. _layout = [[UICollectionViewFlowLayout alloc]init];
  56. _layout.scrollDirection = UICollectionViewScrollDirectionVertical;
  57. CGRect tmpFrame;
  58. if (_collectionViewFrame.size.height)
  59. {
  60. tmpFrame = _collectionViewFrame;
  61. }
  62. else
  63. {
  64. tmpFrame = CGRectMake(0, 0, kScreenW, kScreenH-kStatusBarHeight-kTabBarHeight - 22 - 50);
  65. }
  66. _collectionView = [[UICollectionView alloc]initWithFrame:tmpFrame collectionViewLayout:_layout];
  67. [_collectionView registerClass:[FocusHeaderCollectReusView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader
  68. withReuseIdentifier:NSStringFromClass([FocusHeaderCollectReusView class])];
  69. [_collectionView registerClass:[FocusOnCollectCell class] forCellWithReuseIdentifier:NSStringFromClass([FocusOnCollectCell class])];
  70. [_collectionView registerNib:[UINib nibWithNibName:@"NewestItemCell" bundle:nil] forCellWithReuseIdentifier:@"NewestItemCell"];
  71. [_collectionView registerNib:[UINib nibWithNibName:@"PlayBackCell" bundle:nil] forCellWithReuseIdentifier:@"PlayBackCell"];
  72. _collectionView.backgroundColor = kClearColor;
  73. _collectionView.dataSource =self;
  74. _collectionView.delegate = self;
  75. _collectionView.showsHorizontalScrollIndicator = NO;
  76. [self.view addSubview:_collectionView];
  77. [BGMJRefreshManager refresh:_collectionView target:self headerRereshAction:@selector(refresherOfFocusOn) footerRereshAction:nil];
  78. // 刷新该页面(主要为了删除最新页已经退出的直播间)
  79. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshHome:) name:kRefreshHomeItem object:nil];
  80. [self requestRandomRecommend];
  81. }
  82. #pragma mark 刷新
  83. - (void)refresherOfFocusOn
  84. {
  85. [self requestNetWorking];
  86. [self requestRandomRecommend];
  87. }
  88. #pragma mark ========================通知=========================
  89. - (void)willViewApprer:(NSNotification *)not
  90. {
  91. NSMutableDictionary *dict = [NSMutableDictionary new];
  92. dict = [not valueForKey:@"userInfo"];
  93. NSString *str = dict[@"refresh"];
  94. if ( [str isEqualToString:@"yes"])
  95. {
  96. [self requestNetWorking];
  97. }
  98. }
  99. - (void)refreshHome:(NSNotification *)noti{
  100. if (noti)
  101. {
  102. NSDictionary *tmpDict = (NSDictionary *)noti.object;
  103. NSString *room_id = [tmpDict toString:@"room_id"];
  104. @synchronized (self.dataArray)
  105. {
  106. NSMutableArray *tmpArray = self.dataArray;
  107. for (HMHotItemModel *model in tmpArray)
  108. {
  109. if ([[NSString stringWithFormat:@"%d",model.room_id] isEqualToString:room_id])
  110. {
  111. [tmpArray removeObject:model];
  112. self.dataArray = tmpArray;
  113. [_collectionView reloadData];
  114. return;
  115. }
  116. }
  117. }
  118. }
  119. }
  120. #pragma mark NetWorking
  121. - (void)requestNetWorking{
  122. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  123. [parmDict setObject:@"index" forKey:@"ctl"];
  124. [parmDict setObject:@"focus_video" forKey:@"act"];
  125. FWWeakify(self)
  126. [self.httpsManager POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson)
  127. {
  128. FWStrongify(self)
  129. //关注好友的直播
  130. if ([responseJson toInt:@"status"] == 1)
  131. {
  132. NSMutableArray *arr = [NSMutableArray arrayWithCapacity:0];
  133. [self.dataArray removeAllObjects];
  134. arr = responseJson[@"data"];
  135. if ([arr isKindOfClass:[NSArray class]])
  136. {
  137. if (arr.count > 0)
  138. {
  139. for (NSDictionary *dic in arr)
  140. {
  141. HMHotItemModel *model = [HMHotItemModel mj_objectWithKeyValues:dic];
  142. model.isPlayBack = NO;
  143. [self.dataArray addObject:model];
  144. }
  145. }
  146. }
  147. //精彩回放
  148. NSMutableArray *sourcearr = [NSMutableArray arrayWithCapacity:0];
  149. sourcearr = responseJson[@"playback"];
  150. if ([sourcearr isKindOfClass:[NSArray class]])
  151. {
  152. if (sourcearr.count > 0)
  153. {
  154. for (NSDictionary *dic in sourcearr)
  155. {
  156. HMHotItemModel *model = [HMHotItemModel mj_objectWithKeyValues:dic];
  157. model.isPlayBack = YES;
  158. [self.dataArray addObject:model];
  159. }
  160. }
  161. }
  162. [self.collectionView reloadData];
  163. [self judgeNoContentView];
  164. }
  165. [BGMJRefreshManager endRefresh:self.collectionView];
  166. } FailureBlock:^(NSError *error){
  167. FWStrongify(self)
  168. [BGMJRefreshManager endRefresh:self.collectionView];
  169. }];
  170. }
  171. - (void)judgeNoContentView{
  172. if ((self.dataArray.count == 0) && (self.recommendArray.count == 0))
  173. {
  174. [self showNoContentView];
  175. }
  176. else
  177. {
  178. [self hideNoContentView];
  179. }
  180. }
  181. - (void)requestRandomRecommend{
  182. [self.recommendArray removeAllObjects];
  183. NSString * uid = [BGIMLoginManager sharedInstance].loginParam.identifier;
  184. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  185. [parmDict setObject:@"index" forKey:@"ctl"];
  186. [parmDict setObject:@"recomme_user" forKey:@"act"];
  187. [parmDict setObject:@"1" forKey:@"first"];//0获取所有的 1是获取没有关注的
  188. [parmDict setObject:uid forKey:@"uid"];
  189. [[NetHttpsManager manager] POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson) {
  190. NSArray * array = [responseJson[@"data"]valueForKey:@"list"];
  191. for (id obj in array)
  192. {
  193. HMHotItemModel *model =[HMHotItemModel mj_objectWithKeyValues:obj];
  194. [self.recommendArray addObject:model];
  195. }
  196. [self.collectionView reloadData];
  197. [self judgeNoContentView];
  198. } FailureBlock:^(NSError *error) {
  199. }];
  200. }
  201. - (void)requestFollowAction:(NSInteger)index{
  202. HMHotItemModel *model = self.recommendArray[index];
  203. NSMutableDictionary *dictM = [[NSMutableDictionary alloc]init];
  204. [dictM setObject:@"user" forKey:@"ctl"];
  205. [dictM setObject:@"follow" forKey:@"act"];
  206. [dictM setObject:[NSString stringWithFormat:@"%@",model.id] forKey:@"to_user_id"];
  207. // [[BGHUDHelper sharedInstance]syncLoading];
  208. [self.httpsManager POSTWithParameters:dictM SuccessBlock:^(NSDictionary *responseJson)
  209. {
  210. [[BGHUDHelper sharedInstance]syncStopLoading];
  211. if ([responseJson toInt:@"status"] == 1)
  212. {
  213. // NSMutableDictionary *mDict = [[NSMutableDictionary alloc]init];
  214. NSInteger _has_focus = [responseJson toInt:@"has_focus"];
  215. [FanweMessage alertHUD:ASLocalizedString(@"关注成功")];
  216. if ([responseJson toInt:@"status"] == 1)
  217. {
  218. if (_has_focus == 1)//已关注
  219. {
  220. [self.recommendArray removeObject:model];
  221. //如果都关注了,就要重新请求推荐主播
  222. if (self.recommendArray.count == 0) {
  223. [self requestRandomRecommend];
  224. }else{
  225. [self.collectionView reloadData];
  226. }
  227. // //刷新下面关注主播列表
  228. // [self requestNetWorking];
  229. }
  230. }
  231. }
  232. } FailureBlock:^(NSError *error)
  233. {
  234. [[BGHUDHelper sharedInstance]syncStopLoading];
  235. }];
  236. }
  237. #pragma mark - ----------------------- 代理 -----------------------
  238. #pragma mark - 点击跳转到话题
  239. - (void)pushToTopic:(NSInteger)rowIndex{
  240. if ([self.dataArray count] > rowIndex)
  241. {
  242. HMHotItemModel *tmpModel = [self.dataArray objectAtIndex:rowIndex];
  243. NewestViewController *tmpController = [[NewestViewController alloc]init];
  244. tmpController.topicName = tmpModel.title;
  245. tmpController.cate_id = tmpModel.cate_id;
  246. tmpController.types = @"1";
  247. [[AppDelegate sharedAppDelegate] pushViewController:tmpController animated:YES];
  248. }
  249. }
  250. #pragma mark 点击用户头像
  251. - (void)clickUserIcon:(NSInteger)rowIndex{
  252. if ([self.delegate respondsToSelector:@selector(goToMainPage:)])
  253. {
  254. if ([self.dataArray count] > rowIndex)
  255. {
  256. HMHotItemModel *tmpModel = [self.dataArray objectAtIndex:rowIndex];
  257. [self.delegate goToMainPage:tmpModel.user_id];
  258. }
  259. }
  260. }
  261. #pragma mark 回放点击头像进入主页
  262. - (void)handleWithPlayBackMainPage:(UITapGestureRecognizer *)sender index:(NSInteger)tag{
  263. if ([self.delegate respondsToSelector:@selector(goToMainPage:)])
  264. {
  265. HMHotItemModel *tmpModel = [self.dataArray objectAtIndex:tag];
  266. [self.delegate goToMainPage:tmpModel.user_id];
  267. }
  268. }
  269. #pragma mark push到最新直播的点击事件
  270. - (void)clickToNewsAction:(UIButton *)sender{
  271. if (_delegate && [_delegate respondsToSelector:@selector(goToNewestView)])
  272. {
  273. [_delegate goToNewestView];
  274. }
  275. }
  276. #pragma mark - UICollectionViewDataSource UICollectionViewDelegate
  277. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
  278. return CGSizeMake(kScreenW, kRealValue(55));
  279. }
  280. - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
  281. FocusHeaderCollectReusView * headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:NSStringFromClass([FocusHeaderCollectReusView class]) forIndexPath:indexPath];
  282. headerView.section = indexPath.section;
  283. FWWeakify(self)
  284. headerView.backgroundColor = kClearColor;
  285. headerView.randomBlock = ^{
  286. FWStrongify(self)
  287. [self requestRandomRecommend];
  288. };
  289. return headerView;
  290. }
  291. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
  292. {
  293. return 2;
  294. }
  295. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  296. {
  297. if (section == 0) {
  298. NSLog(@"recommendArray%@",self.recommendArray);
  299. if (self.recommendArray.count > 3) {
  300. return 3;
  301. }
  302. return self.recommendArray.count;
  303. }
  304. if (self.dataArray.count)
  305. {
  306. return self.dataArray.count;
  307. }
  308. return 0;
  309. }
  310. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  311. {
  312. if (indexPath.section == 0) {
  313. FocusOnCollectCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([FocusOnCollectCell class]) forIndexPath:indexPath];
  314. cell.user = self.recommendArray[indexPath.item];
  315. FWWeakify(self)
  316. cell.followBlock = ^{
  317. FWStrongify(self)
  318. [self requestFollowAction:indexPath.item];
  319. };
  320. cell.clickImgBlock = ^(NSString * _Nonnull str) {
  321. SHomePageVC *tmpController= [[SHomePageVC alloc]init];
  322. tmpController.user_id = str;
  323. tmpController.type = 0;
  324. [[AppDelegate sharedAppDelegate]pushViewController:tmpController animated:YES];
  325. };
  326. return cell;
  327. }
  328. HMHotItemModel *tmpModel = [self.dataArray objectAtIndex:indexPath.row];
  329. if (!tmpModel.isPlayBack) {
  330. NewestItemCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"NewestItemCell" forIndexPath:indexPath];
  331. cell.backgroundColor = [UIColor whiteColor];
  332. [cell setModel:tmpModel];
  333. return cell;
  334. }else{
  335. PlayBackCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"PlayBackCell" forIndexPath:indexPath];
  336. cell.backgroundColor = [UIColor whiteColor];
  337. [cell setModel:tmpModel];
  338. return cell;
  339. }
  340. }
  341. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
  342. {
  343. if (indexPath.section == 0) {
  344. return CGSizeMake((kScreenW-4)/3.0f, kRealValue(131));
  345. }
  346. return CGSizeMake((kScreenW-30)/2.0f,(kScreenW-30)/2.0f + kRealValue(30));
  347. // (kScreenW-30)/2.0f);
  348. }
  349. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
  350. if (section == 0) {
  351. return 0;
  352. }
  353. return 10;
  354. }
  355. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
  356. if (section == 0) {
  357. return 0;
  358. }
  359. return 0;
  360. }
  361. - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
  362. {
  363. if (section == 0) {
  364. return UIEdgeInsetsMake(0, 2, 0, 2);
  365. }
  366. return UIEdgeInsetsMake(10, 10, 0, 10);
  367. }
  368. #pragma mark - 跳转到在线直播
  369. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  370. if (indexPath.section == 0) {
  371. //暂时没做跳转
  372. }else{
  373. // HMHotItemModel *model = self.dataArray[indexPath.row];
  374. // if (model.isPlayBack) {
  375. // model.live_in = FW_LIVE_STATE_RELIVE;
  376. // }
  377. // LivingModel *model = _dataArray[indexPath.row];
  378. // if (self.delegate)
  379. // {
  380. // if ([self.delegate respondsToSelector:@selector(pushToLiveController:modelArr:)])
  381. // {
  382. // [self.delegate pushToLiveController:model modelArr:self.dataArray];
  383. // }
  384. // }
  385. HMHotItemModel *model = self.dataArray[indexPath.item];
  386. if(model.password.length > 0)
  387. {
  388. }
  389. else
  390. {
  391. [self joinOtherLivingRoom:self.dataArray[indexPath.item]];
  392. return;
  393. }
  394. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:ASLocalizedString(@"请输入房间密码")preferredStyle:UIAlertControllerStyleAlert];
  395. [alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
  396. textField.placeholder = ASLocalizedString(@"请输入密码");
  397. textField.delegate = self;
  398. textField.keyboardType = UIKeyboardTypeNumberPad;
  399. }];
  400. UIAlertAction *actionCacel = [UIAlertAction actionWithTitle:ASLocalizedString(@"取消")style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  401. }];
  402. [alertController addAction:actionCacel];
  403. UIAlertAction *actionConfirm = [UIAlertAction actionWithTitle:ASLocalizedString(@"确定")style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  404. NSString *password = alertController.textFields.firstObject.text;
  405. NSString *md5Str = [[NSString md5String:password] uppercaseString];
  406. //转化为大写
  407. NSLog(@"%@",md5Str);
  408. if ([md5Str isEqualToString:model.password]) {
  409. [self joinOtherLivingRoom:self.dataArray[indexPath.item]];
  410. }else{
  411. [FanweMessage alertHUD:ASLocalizedString(@"密码不正确")];
  412. }
  413. }];
  414. [alertController addAction:actionConfirm];
  415. [self presentViewController:alertController animated:YES completion:nil];
  416. // [self joinOtherLivingRoom:model];
  417. }
  418. }
  419. #pragma mark - 加入直播间
  420. - (void)joinOtherLivingRoom:(HMHotItemModel *)model{
  421. if (![BGUtils isNetConnected])
  422. {
  423. return;
  424. }
  425. if ([IMAPlatform sharedInstance].host)
  426. {
  427. TCShowLiveListItem *liveRoom = [[TCShowLiveListItem alloc]init];
  428. liveRoom.chatRoomId = model.group_id;
  429. liveRoom.avRoomId = model.room_id;
  430. liveRoom.title = [NSString stringWithFormat:@"%d",model.room_id];
  431. liveRoom.vagueImgUrl = model.head_image;
  432. TCShowUser *showUser = [[TCShowUser alloc]init];
  433. showUser.uid = model.user_id;
  434. showUser.avatar = model.head_image;
  435. showUser.username = model.nick_name;
  436. liveRoom.host = showUser;
  437. if (model.live_in == FW_LIVE_STATE_ING)
  438. {
  439. liveRoom.liveType = FW_LIVE_TYPE_AUDIENCE;
  440. }
  441. // else if (model.live_in == FW_LIVE_STATE_RELIVE)
  442. // {
  443. // liveRoom.liveType = FW_LIVE_TYPE_RELIVE;
  444. // [GlobalVariables sharedInstance].appModel.spear_live = @"0";
  445. // }
  446. if ([LiveCenterManager sharedInstance].itemModel) {
  447. [[NSNotificationCenter defaultCenter]postNotificationName:@"clickLiveRoomNotification" object:nil];
  448. }
  449. //2020-1-7 小直播变大
  450. [LiveCenterManager sharedInstance].itemModel=liveRoom;
  451. BOOL isSusWindow = [[LiveCenterManager sharedInstance] judgeIsSusWindow];
  452. [[LiveCenterManager sharedInstance] showLiveOfAudienceLiveofTCShowLiveListItem:liveRoom modelArr:self.dataArray isSusWindow:isSusWindow isSmallScreen:NO block:^(BOOL finished) {
  453. }];
  454. }
  455. else
  456. {
  457. [[BGHUDHelper sharedInstance] loading:@"" delay:2 execute:^{
  458. [[BGIMLoginManager sharedInstance] loginImSDK:YES succ:nil failed:nil];
  459. } completion:^{
  460. }];
  461. }
  462. }
  463. #pragma mark - Lazy Load
  464. - (NSMutableArray *)dataArray{
  465. if (!_dataArray) {
  466. _dataArray = [[NSMutableArray alloc]init];
  467. }
  468. return _dataArray;
  469. }
  470. - (NSMutableArray *)recommendArray{
  471. if (!_recommendArray) {
  472. _recommendArray = [[NSMutableArray alloc]init];
  473. }
  474. return _recommendArray;
  475. }
  476. - (UIStatusBarStyle)preferredStatusBarStyle{
  477. if (@available(iOS 13, *)) {
  478. return UIStatusBarStyleDarkContent;
  479. }
  480. return UIStatusBarStyleDefault;
  481. }
  482. @end