LoginRecommendVC.m 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. //
  2. // LoginRecommendVC.m
  3. // BuguLive
  4. //
  5. // Created by bugu on 2019/12/11.
  6. // Copyright © 2019 xfg. All rights reserved.
  7. //
  8. #import "LoginRecommendVC.h"
  9. #import "LoginRecomCollectCell.h"
  10. #import "LoginRecomHeaderCollectReusView.h"
  11. #import "LoginRecomFooterCollectReusView.h"
  12. @interface LoginRecommendVC ()<UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>
  13. @property(nonatomic, strong) UICollectionView *collectionView;
  14. @property(nonatomic, strong) NSMutableArray *hotDataArray;
  15. @property(nonatomic, strong) NSMutableArray *bgDataArray;
  16. @property(nonatomic, strong) UILabel *titleLabel;
  17. @property(nonatomic, strong) UIButton *goBtn;
  18. @end
  19. @implementation LoginRecommendVC
  20. - (void)viewDidLoad {
  21. [super viewDidLoad];
  22. // Do any additional setup after loading the view.
  23. self.view.backgroundColor = kWhiteColor;
  24. [self initNavView];
  25. [self.view addSubview:self.collectionView];
  26. [self requestData];
  27. }
  28. - (void)initNavView{
  29. _titleLabel= ({
  30. UILabel * label = [[UILabel alloc]init];
  31. label.textColor = [UIColor colorWithHexString:@"#333333"];
  32. label.font = [UIFont systemFontOfSize:20];
  33. label.text = ASLocalizedString(@"为您推荐的主播");
  34. label;
  35. });
  36. [self.view addSubview:_titleLabel];
  37. [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  38. // make.top.mas_equalTo(kTopHeight - 30);
  39. make.top.mas_equalTo(MG_TOP_MARGIN+20);
  40. make.centerX.mas_equalTo(0);
  41. }];
  42. _goBtn = ({
  43. UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
  44. [btn setTitleColor:[UIColor colorWithHexString:@"#666666"] forState:UIControlStateNormal];
  45. btn.titleLabel.font = [UIFont systemFontOfSize:16];
  46. [btn setTitle:ASLocalizedString(@"跳过")forState:UIControlStateNormal];
  47. [btn addTarget:self action:@selector(goAction) forControlEvents:UIControlEventTouchUpInside];
  48. btn;
  49. });
  50. [self.view addSubview:_goBtn];
  51. [_goBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  52. make.centerY.equalTo(_titleLabel);
  53. make.right.equalTo(@(-10));
  54. }];
  55. }
  56. - (void)requestData{
  57. [self.bgDataArray removeAllObjects];
  58. NSString * uid = [BGIMLoginManager sharedInstance].loginParam.identifier;
  59. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  60. [parmDict setObject:@"index" forKey:@"ctl"];
  61. [parmDict setObject:@"recomme_user" forKey:@"act"];
  62. [parmDict setObject:uid forKey:@"uid"];
  63. [parmDict setObject:@"1" forKey:@"first"];
  64. [[NetHttpsManager manager] POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson) {
  65. NSArray * array = [responseJson[@"data"]valueForKey:@"list"];
  66. for (id obj in array)
  67. {
  68. HMHotItemModel *model =[HMHotItemModel mj_objectWithKeyValues:obj];
  69. [self.bgDataArray addObject:model];
  70. }
  71. [self.collectionView reloadData];
  72. } FailureBlock:^(NSError *error) {
  73. }];
  74. }
  75. - (void)goAction{
  76. //跳过
  77. // [self showMyHud];
  78. [[BGIMLoginManager sharedInstance] getUserSig:^{
  79. [[AppDelegate sharedAppDelegate] enterMainUI];
  80. // [self hideMyHud];
  81. //
  82. } failed:^(int errId, NSString *errMsg) {
  83. // [self hideMyHud];
  84. }];
  85. }
  86. //- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
  87. //
  88. // return CGSizeMake(kScreenW, 50);
  89. //
  90. //}
  91. - (void)followUsers{
  92. NSMutableArray * arrUid = [NSMutableArray array];
  93. for (int i = 0; i < self.bgDataArray.count; i ++) {
  94. HMHotItemModel * model = self.bgDataArray[i];
  95. if (model.selected == YES) {
  96. [arrUid addObject:model.id];
  97. }
  98. }
  99. if (arrUid.count == 0) {
  100. [self goAction];
  101. } else {
  102. NSString * strIDAll = [arrUid componentsJoinedByString:@","];
  103. NSString * uid = [BGIMLoginManager sharedInstance].loginParam.identifier;
  104. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  105. [parmDict setObject:@"user" forKey:@"ctl"];
  106. [parmDict setObject:@"follow_all" forKey:@"act"];
  107. [parmDict setObject:strIDAll forKey:@"to_user_id"];
  108. [[NetHttpsManager manager] POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson) {
  109. if ([responseJson toInt:@"status"] == 1) {
  110. NSLog(ASLocalizedString(@"成功responseJson:%@"),responseJson);
  111. [self goAction];
  112. }else{
  113. NSLog(ASLocalizedString(@"失败responseJson:%@"),responseJson);
  114. }
  115. } FailureBlock:^(NSError *error) {
  116. }];
  117. }
  118. }
  119. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section{
  120. return CGSizeMake(kScreenW, 160);
  121. }
  122. - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
  123. if ([kind isEqualToString:UICollectionElementKindSectionHeader]) {
  124. LoginRecomHeaderCollectReusView * headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:NSStringFromClass([LoginRecomHeaderCollectReusView class]) forIndexPath:indexPath];
  125. if (indexPath.section == 0) {
  126. headerView.titleLabel.text = ASLocalizedString(@"—— 热门主播 ——");
  127. } else {
  128. headerView.titleLabel.text = ASLocalizedString(@"—— 官方推荐 ——");
  129. }
  130. return headerView;
  131. }
  132. if (indexPath.section == 0) {
  133. LoginRecomFooterCollectReusView * footerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:NSStringFromClass([LoginRecomFooterCollectReusView class]) forIndexPath:indexPath];
  134. __weak __typeof(self)weakSelf = self;
  135. //换一批
  136. footerView.changeBlock = ^{
  137. [weakSelf requestData];
  138. };
  139. //开启布谷直播
  140. footerView.goBlock = ^{
  141. //关注主播后进入app
  142. [self followUsers];
  143. };
  144. return footerView;
  145. }
  146. return nil;
  147. }
  148. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
  149. return 1;
  150. }
  151. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  152. // if (section == 0) {
  153. // return 4;
  154. // return self.hotDataArray.count;
  155. //
  156. // }
  157. // return 3;
  158. return self.bgDataArray.count;
  159. }
  160. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  161. LoginRecomCollectCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([LoginRecomCollectCell class]) forIndexPath:indexPath];
  162. cell.model = self.bgDataArray[indexPath.item];
  163. return cell;
  164. }
  165. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
  166. return CGSizeMake((kScreenW-10*2)/3, kRealValue(100));
  167. }
  168. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
  169. return 0;
  170. }
  171. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
  172. return 0;
  173. }
  174. - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
  175. return UIEdgeInsetsMake(0, 0, 0, 0);
  176. // if (section == 0) {
  177. // return UIEdgeInsetsMake(0, 14, 0, 14);
  178. //
  179. // }
  180. //
  181. // return UIEdgeInsetsMake(0, 59, 0, 59);
  182. }
  183. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  184. HMHotItemModel * model = self.bgDataArray[indexPath.item];
  185. model.selected = !model.selected;
  186. [collectionView reloadItemsAtIndexPaths:@[indexPath]];
  187. }
  188. - (void)viewWillAppear:(BOOL)animated
  189. {
  190. [super viewWillAppear:animated];
  191. // [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
  192. }
  193. #pragma mark - setter
  194. - (UICollectionView *)collectionView{
  195. if (!_collectionView) {
  196. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
  197. _collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0,MG_TOP_MARGIN+70, kScreenW , kScreenH-(MG_TOP_MARGIN+70)) collectionViewLayout:layout];
  198. _collectionView.delegate = self;
  199. _collectionView.backgroundColor = [UIColor whiteColor];
  200. _collectionView.dataSource = self;
  201. [_collectionView registerClass:[LoginRecomCollectCell class] forCellWithReuseIdentifier:NSStringFromClass([LoginRecomCollectCell class])];
  202. // [_collectionView registerClass:[LoginRecomHeaderCollectReusView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader
  203. // withReuseIdentifier:NSStringFromClass([LoginRecomHeaderCollectReusView class])];
  204. [_collectionView registerClass:[LoginRecomFooterCollectReusView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter
  205. withReuseIdentifier:NSStringFromClass([LoginRecomFooterCollectReusView class])];
  206. }
  207. return _collectionView;
  208. }
  209. - (NSMutableArray *)hotDataArray{
  210. if (!_hotDataArray) {
  211. _hotDataArray = [NSMutableArray array];
  212. }
  213. return _hotDataArray;
  214. }
  215. - (NSMutableArray *)bgDataArray{
  216. if (!_bgDataArray) {
  217. _bgDataArray = [NSMutableArray array];
  218. }
  219. return _bgDataArray;
  220. }
  221. @end