YBLiveListVC.m 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. //
  2. // YBLiveListVC.m
  3. // YBVideo
  4. //
  5. // Created by YB007 on 2019/12/4.
  6. // Copyright © 2019 cat. All rights reserved.
  7. //
  8. #import "YBLiveListVC.h"
  9. #import "YBLiveListCell.h"
  10. #import "YBCheckLiveObj.h"
  11. #import "SPPageMenu.h"
  12. @interface YBLiveListVC ()<UICollectionViewDelegate,UICollectionViewDataSource,SPPageMenuDelegate>
  13. {
  14. int _paging;
  15. NSArray *classArray;
  16. NSArray *liveClass;
  17. NSString *classid;
  18. NSInteger currentPageIndex;
  19. }
  20. @property(nonatomic,strong)UICollectionView *collectionView;
  21. @property(nonatomic,strong)NSMutableArray *dataArray;
  22. @property (nonatomic, weak) SPPageMenu *pageMenu;
  23. @end
  24. @implementation YBLiveListVC
  25. - (void)viewWillAppear:(BOOL)animated {
  26. [super viewWillAppear:animated];
  27. [self pullData];
  28. [_pageMenu setSelectedItemIndex:0];
  29. if ([YBYoungManager shareInstance].youngSwitch == 1) {
  30. [[YBYoungManager shareInstance] checkYoungStatus:YoungFrom_Home];
  31. }
  32. }
  33. - (void)viewDidLoad {
  34. [super viewDidLoad];
  35. self.titleL.text = YZMsg(@"直播广场");
  36. _paging = 1;
  37. _dataArray = [NSMutableArray array];
  38. classid = @"";
  39. currentPageIndex = 0;
  40. liveClass = [common liveclass];
  41. NSMutableArray *class = [NSMutableArray array];
  42. for (NSDictionary *dic in liveClass) {
  43. [class addObject:minstr([dic valueForKey:@"name"])];
  44. }
  45. classArray = class;
  46. SPPageMenu *pageMenu = [SPPageMenu pageMenuWithFrame:CGRectMake(0, 64+statusbarHeight, _window_width, 40) trackerStyle:SPPageMenuTrackerStyleNothing];
  47. [pageMenu setItems:classArray selectedItemIndex:0];
  48. pageMenu.delegate = self;
  49. pageMenu.dividingLine.hidden = YES;
  50. pageMenu.selectedItemTitleColor = [UIColor whiteColor];
  51. pageMenu.unSelectedItemTitleColor = Normal_TextColor;
  52. pageMenu.selectedItemTitleFont = [UIFont systemFontOfSize:14];
  53. pageMenu.unSelectedItemTitleFont = [UIFont systemFontOfSize:14];
  54. pageMenu.backgroundColor = Normal_SubColor;
  55. pageMenu.permutationWay = SPPageMenuPermutationWayScrollAdaptContent;
  56. [self.view addSubview:pageMenu];
  57. _pageMenu = pageMenu;
  58. [self.view addSubview:self.collectionView];
  59. }
  60. - (void)pageMenu:(SPPageMenu *)pageMenu itemSelectedAtIndex:(NSInteger)index {
  61. NSLog(@"sssssss::::%zd",index);
  62. currentPageIndex = index;
  63. //
  64. if (index != 0) {
  65. classid = minstr([liveClass[index] valueForKey:@"id"]);
  66. _paging = 1;
  67. [self requstLiveClass:classid];
  68. }else{
  69. _paging = 1;
  70. [self pullData];
  71. }
  72. }
  73. -(void)requstLiveClass:(NSString *)classID{
  74. [YBNetworking postWithUrl:@"Live.getClassLive" Dic:@{@"liveclassid":classID,@"p":@(_paging)} Suc:^(int code, id info, NSString *msg) {
  75. [_collectionView.mj_header endRefreshing];
  76. [_collectionView.mj_footer endRefreshing];
  77. if (code == 0) {
  78. NSArray *infoA = [NSArray arrayWithArray:info];
  79. if (_paging == 1) {
  80. [_dataArray removeAllObjects];
  81. }
  82. if (infoA.count <= 0 ) {
  83. [_collectionView.mj_footer endRefreshingWithNoMoreData];
  84. }else {
  85. [_dataArray addObjectsFromArray:infoA];
  86. }
  87. if (_dataArray.count<=0) {
  88. [PublicView showTextNoData:_collectionView text1:@"" text2:YZMsg(@"暂时没有主播开播") centerY:0.8];
  89. }else {
  90. [PublicView hiddenTextNoData:_collectionView];
  91. }
  92. [_collectionView reloadData];
  93. }else {
  94. [MBProgressHUD showPop:msg];
  95. }
  96. } Fail:^(id fail) {
  97. [_collectionView.mj_header endRefreshing];
  98. [_collectionView.mj_footer endRefreshing];
  99. }];
  100. }
  101. -(void)pullData {
  102. [YBNetworking postWithUrl:@"Live.getRecommendLists" Dic:@{@"p":@(_paging)} Suc:^(int code, id info, NSString *msg) {
  103. [_collectionView.mj_header endRefreshing];
  104. [_collectionView.mj_footer endRefreshing];
  105. if (code == 0) {
  106. NSArray *infoA = [NSArray arrayWithArray:info];
  107. if (_paging == 1) {
  108. [_dataArray removeAllObjects];
  109. }
  110. if (infoA.count <= 0 ) {
  111. [_collectionView.mj_footer endRefreshingWithNoMoreData];
  112. }else {
  113. [_dataArray addObjectsFromArray:infoA];
  114. }
  115. if (_dataArray.count<=0) {
  116. [PublicView showTextNoData:_collectionView text1:@"" text2:YZMsg(@"暂时没有主播开播") centerY:0.8];
  117. }else {
  118. [PublicView hiddenTextNoData:_collectionView];
  119. }
  120. [_collectionView reloadData];
  121. }else {
  122. [MBProgressHUD showPop:msg];
  123. }
  124. } Fail:^(id fail) {
  125. [_collectionView.mj_header endRefreshing];
  126. [_collectionView.mj_footer endRefreshing];
  127. }];
  128. }
  129. #pragma mark - CollectionView 代理
  130. /*
  131. * minimumLineSpacing、minimumInteritemSpacing去设置
  132. -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
  133. return CGSizeMake(0,0);
  134. }
  135. */
  136. -(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
  137. return UIEdgeInsetsMake(5,5,5,5);
  138. }
  139. /*
  140. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
  141. return 0.01;
  142. }
  143. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
  144. return 0.01;
  145. }
  146. */
  147. -(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
  148. return 1;
  149. }
  150. -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  151. return _dataArray.count;
  152. }
  153. -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
  154. YBLiveListCell *cell = (YBLiveListCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"YBLiveListCell" forIndexPath:indexPath];
  155. cell.dataDic = _dataArray[indexPath.row];
  156. return cell;
  157. }
  158. -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  159. NSDictionary *subDic = _dataArray[indexPath.row];
  160. [YBCheckLiveObj checkLiveManeger].liveUid = minstr([subDic valueForKey:@"uid"]);
  161. [YBCheckLiveObj checkLiveManeger].liveStream = minstr([subDic valueForKey:@"stream"]);
  162. [YBCheckLiveObj checkLiveManeger].currentIndex = indexPath.row;
  163. [YBCheckLiveObj checkLiveManeger].listArray = _dataArray.copy;
  164. [[YBCheckLiveObj checkLiveManeger] checkLiving];
  165. }
  166. #pragma mark - set/get
  167. - (UICollectionView *)collectionView {
  168. if (!_collectionView) {
  169. UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc]init];
  170. flow.scrollDirection = UICollectionViewScrollDirectionVertical;
  171. flow.itemSize = CGSizeMake((_window_width-15)/2, (_window_width-15)/2);
  172. flow.minimumLineSpacing = 5;
  173. flow.minimumInteritemSpacing = 5;
  174. _collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0,statusbarHeight+64+40, _window_width, _window_height-statusbarHeight-64-40) collectionViewLayout:flow];
  175. [_collectionView registerNib:[UINib nibWithNibName:@"YBLiveListCell" bundle:nil] forCellWithReuseIdentifier:@"YBLiveListCell"];
  176. _collectionView.delegate = self;
  177. _collectionView.dataSource = self;
  178. _collectionView.backgroundColor = Normal_Color;
  179. _collectionView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
  180. _paging ++;
  181. if (currentPageIndex == 0) {
  182. [self pullData];
  183. }else{
  184. [self requstLiveClass:classid];
  185. }
  186. }];
  187. _collectionView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  188. _paging = 1;
  189. if (currentPageIndex == 0) {
  190. [self pullData];
  191. }else{
  192. [self requstLiveClass:classid];
  193. }
  194. }];
  195. _collectionView.contentInset = UIEdgeInsetsMake(0, 0, ShowDiff, 0);
  196. }
  197. return _collectionView;
  198. }
  199. @end