MyAdvertVC.m 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. //
  2. // MyAdvertVC.m
  3. // YBVideo
  4. //
  5. // Created by ybRRR on 2021/12/22.
  6. // Copyright © 2021 cat. All rights reserved.
  7. //
  8. #import "MyAdvertVC.h"
  9. #import "MyAdvertCell.h"
  10. #import "YBGetVideoObj.h"
  11. @interface MyAdvertVC ()<UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>
  12. {
  13. int _page;
  14. }
  15. @property(nonatomic,strong)UICollectionView *collectionView;
  16. @property(nonatomic,strong)NSMutableArray *dataArr;
  17. @end
  18. @implementation MyAdvertVC
  19. -(void)getUserAdVideos{
  20. [YBNetworking postWithUrl:@"Video.getUserAdVideos" Dic:@{@"uid":[Config getOwnID],@"token":[Config getOwnToken],@"p":@(_page)} Suc:^(int code, id info, NSString *msg) {
  21. [_collectionView.mj_header endRefreshing];
  22. [_collectionView.mj_footer endRefreshing];
  23. if (code == 0) {
  24. NSArray *infos = info;
  25. if (_page == 1) {
  26. [_dataArr removeAllObjects];
  27. }
  28. [_dataArr addObjectsFromArray:infos];
  29. if (_dataArr.count > 0) {
  30. [PublicView hiddenTextNoData:_collectionView];
  31. }else{
  32. [PublicView showTextNoData:_collectionView text1:YZMsg(@"暂无数据") text2:@"" centerY:0.8];
  33. }
  34. [_collectionView reloadData];
  35. }
  36. } Fail:^(id fail) {
  37. }];
  38. }
  39. -(void)viewWillAppear:(BOOL)animated
  40. {
  41. [super viewWillAppear:YES];
  42. [self getUserAdVideos];
  43. }
  44. - (void)viewDidLoad {
  45. [super viewDidLoad];
  46. self.titleL.text = YZMsg(@"我的广告");
  47. _page = 1;
  48. _dataArr = [NSMutableArray array];
  49. UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc]init];
  50. flow.scrollDirection = UICollectionViewScrollDirectionVertical;
  51. flow.itemSize = CGSizeMake(_window_width/3-2, (_window_width/3-2) * 1.4);
  52. flow.minimumLineSpacing = 2;
  53. flow.minimumInteritemSpacing = 2;
  54. self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0,64+statusbarHeight, _window_width, _window_height-64-statusbarHeight-ShowDiff) collectionViewLayout:flow];
  55. [self.collectionView registerNib:[UINib nibWithNibName:@"MyAdvertCell" bundle:nil] forCellWithReuseIdentifier:@"MyAdvertCell"];
  56. self.collectionView.delegate =self;
  57. self.collectionView.dataSource = self;
  58. self.collectionView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
  59. _page ++;
  60. [self getUserAdVideos];
  61. }];
  62. self.collectionView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  63. _page = 1;
  64. [self getUserAdVideos];
  65. }];
  66. [self.view addSubview:self.collectionView];
  67. self.view.backgroundColor = Normal_Color;
  68. self.collectionView.backgroundColor = [UIColor clearColor];
  69. }
  70. -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
  71. return _dataArr.count;
  72. }
  73. -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  74. [collectionView deselectItemAtIndexPath:indexPath animated:YES];
  75. NSString *basUrl = [NSString stringWithFormat:@"Video.getUserAdVideos&uid=%@&token=%@&p=%@",[Config getOwnID],[Config getOwnToken],@(_page)];
  76. NSDictionary *videoDic = _dataArr[indexPath.item];
  77. NSString *vidoeID = minstr([videoDic valueForKey:@"id"]);
  78. [YBGetVideoObj lookManeger].fromWhere = @"CenterVC";
  79. [YBGetVideoObj lookManeger].videoID = vidoeID;
  80. [YBGetVideoObj lookManeger].playIndex = (int)indexPath.item;
  81. [YBGetVideoObj lookManeger].videoList = [_dataArr mutableCopy];
  82. [YBGetVideoObj lookManeger].paging = _page;
  83. [YBGetVideoObj lookManeger].baseUrl = basUrl;
  84. [[YBGetVideoObj lookManeger]goLookVC];
  85. }
  86. -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
  87. MyAdvertCell *cell = (MyAdvertCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"MyAdvertCell" forIndexPath:indexPath];
  88. cell.dataDic = _dataArr[indexPath.item];
  89. return cell;
  90. }
  91. @end