BogoSearchListView.m 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. //
  2. // BogoSearchTableView.m
  3. // BuguLive
  4. //
  5. // Created by 宋晨光 on 2021/4/6.
  6. // Copyright © 2021 xfg. All rights reserved.
  7. //
  8. #import "BogoSearchListView.h"
  9. static NSString const *kBogoSearchHeadView = @"kBogoSearchHeadView";
  10. @implementation BogoSearchListView
  11. - (instancetype)initWithFrame:(CGRect)frame
  12. {
  13. self = [super initWithFrame:frame];
  14. if (self) {
  15. self.backgroundColor = kWhiteColor;
  16. [self setUpView];
  17. [self setModel];
  18. }
  19. return self;
  20. }
  21. -(void)setUpView{
  22. BogoSearchTableHeadView *headView = [[BogoSearchTableHeadView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kRealValue(160))];
  23. _headView = headView;
  24. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
  25. layout.scrollDirection = UICollectionViewScrollDirectionVertical;
  26. layout.headerReferenceSize=CGSizeMake(kScreenW, kRealValue(166));//头视图的大小
  27. _collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, self.height) collectionViewLayout:layout];
  28. _collectionView.delegate = self;
  29. _collectionView.dataSource = self;
  30. _collectionView.backgroundColor = kWhiteColor;
  31. // [_collectionView registerClass:[BogoSearchTableHeadView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"BogoSearchTableHeadView"];
  32. [_collectionView registerClass:[BogoSearchTableHeadView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader
  33. withReuseIdentifier:NSStringFromClass([BogoSearchTableHeadView class])];
  34. [_collectionView registerNib:[UINib nibWithNibName:@"NewestItemCell" bundle:nil] forCellWithReuseIdentifier:@"NewestItemCell"];
  35. [self addSubview:self.collectionView];
  36. }
  37. -(void)setModel{
  38. self.listArr = [NSMutableArray array];
  39. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  40. [parmDict setObject:@"index" forKey:@"ctl"];
  41. [parmDict setObject:@"index" forKey:@"act"];
  42. [[NetHttpsManager manager] POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson)
  43. {
  44. if ([responseJson toInt:@"status"] == 1)
  45. {
  46. NSArray *recommandArr = [responseJson objectForKey:@"recommend_list"];
  47. if (recommandArr && [recommandArr isKindOfClass:[NSArray class]])
  48. {
  49. if (recommandArr.count > 0)
  50. {
  51. for (NSDictionary *dict in recommandArr)
  52. {
  53. LivingModel *model = [LivingModel mj_objectWithKeyValues:dict];
  54. model.xponit = [dict toFloat:@"xpoint"];
  55. model.yponit = [dict toFloat:@"ypoint"];
  56. [self.listArr addObject:model];
  57. }
  58. }
  59. }
  60. [_collectionView reloadData];
  61. // [self hideNoContentView];
  62. }
  63. [BGMJRefreshManager endRefresh:_collectionView];
  64. } FailureBlock:^(NSError *error)
  65. {
  66. [BGMJRefreshManager endRefresh:_collectionView];
  67. }];
  68. }
  69. // 返回头视图
  70. - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
  71. {
  72. //如果是头视图
  73. if ([kind isEqualToString:UICollectionElementKindSectionHeader]) {
  74. if (indexPath.section == 0) {
  75. BogoSearchTableHeadView *header = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:NSStringFromClass([BogoSearchTableHeadView class]) forIndexPath:indexPath];
  76. UILabel *titleL = [[UILabel alloc]initWithFrame:CGRectMake(kRealValue(10), self.headView.height - kRealValue(20), kScreenW / 2, kRealValue(20))];
  77. titleL.text =ASLocalizedString( @"热门直播");
  78. titleL.font = [UIFont systemFontOfSize:16];
  79. titleL.textColor = [UIColor colorWithHexString:@"#333333"];
  80. [header addSubview:titleL];
  81. return header;
  82. }
  83. }
  84. return nil;
  85. }
  86. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
  87. return 1;
  88. }
  89. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  90. return self.listArr.count;
  91. }
  92. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  93. NewestItemCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"NewestItemCell" forIndexPath:indexPath];
  94. if (_listArr.count > 0) {
  95. LivingModel *LModel = _listArr[indexPath.row];
  96. [cell setCellContent:LModel Type:[@"1" intValue]];
  97. }
  98. return cell;
  99. }
  100. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  101. LivingModel *LModel = _listArr[indexPath.row];
  102. [self clickLivingModel:LModel];
  103. }
  104. #pragma mark NewestViewController跳转到直播
  105. -(void)clickLivingModel:(LivingModel *)model{
  106. if (![BGUtils isNetConnected])
  107. {
  108. return;
  109. }
  110. // [self.BuguLive.newestLivingMArray removeAllObjects];
  111. // [self.BuguLive.newestLivingMArray addObject:model];
  112. if ([self checkUser:[IMAPlatform sharedInstance].host])
  113. {
  114. TCShowLiveListItem *item = [[TCShowLiveListItem alloc]init];
  115. //点击左边主播
  116. item.chatRoomId = model.group_id;
  117. item.avRoomId = model.room_id;
  118. item.title = [NSString stringWithFormat:@"%d",model.room_id];
  119. item.vagueImgUrl = model.head_image;
  120. TCShowUser *showUser = [[TCShowUser alloc]init];
  121. showUser.uid = model.user_id;
  122. showUser.avatar = model.head_image;
  123. item.host = showUser;
  124. item.is_voice = model.is_voice;
  125. item.liveType = FW_LIVE_TYPE_AUDIENCE;
  126. //2020-1-7 小直播变大
  127. [LiveCenterManager sharedInstance].itemModel=item;
  128. BOOL isSusWindow = [[LiveCenterManager sharedInstance] judgeIsSusWindow];
  129. [[LiveCenterManager sharedInstance] showLiveOfAudienceLiveofTCShowLiveListItem:item modelArr:nil isSusWindow:isSusWindow isSmallScreen:NO block:^(BOOL isFinished) {
  130. }];
  131. }
  132. else
  133. {
  134. [[BGHUDHelper sharedInstance] loading:@"" delay:2 execute:^{
  135. [[BGIMLoginManager sharedInstance] loginImSDK:YES succ:nil failed:nil];
  136. } completion:^{
  137. }];
  138. }
  139. }
  140. - (BOOL)checkUser:(id<IMHostAble>)user
  141. {
  142. if (![user conformsToProtocol:@protocol(AVUserAble)])
  143. {
  144. return NO;
  145. }
  146. return YES;
  147. }
  148. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
  149. {
  150. return CGSizeMake((kScreenW-30)/2.0f, (kScreenW-30) / 2.0f + kRealValue(30));
  151. }
  152. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
  153. return 10;
  154. }
  155. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
  156. return 0;
  157. }
  158. - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
  159. {
  160. return UIEdgeInsetsMake(10, 10, 0, 10);
  161. }
  162. @end