YBVideosVC.m 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. //
  2. // YBVideosVC.m
  3. // YBVideo
  4. //
  5. // Created by YB007 on 2019/12/6.
  6. // Copyright © 2019 cat. All rights reserved.
  7. //
  8. #import "YBVideosVC.h"
  9. #import "NearbyVideoModel.h"
  10. #import "VideoCollectionCell.h"
  11. #import "YBGetVideoObj.h"
  12. @interface YBVideosVC ()<UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>
  13. {
  14. NSInteger _paging;
  15. NSString *_url;
  16. }
  17. @property(nonatomic,strong)NSMutableArray *dataArray;
  18. @property(nonatomic,strong)NSArray *models;
  19. @property(nonatomic,strong)UICollectionView *collectionView;
  20. @end
  21. @implementation YBVideosVC
  22. - (void)viewWillAppear:(BOOL)animated {
  23. [super viewWillAppear:animated];
  24. if (self.dataArray.count <= 0 ) {
  25. [self pullData];
  26. }
  27. }
  28. - (void)viewDidLoad {
  29. [super viewDidLoad];
  30. self.naviView.hidden = YES;
  31. self.navigationController.interactivePopGestureRecognizer.delegate = (id) self;
  32. self.view.backgroundColor = Normal_Color;
  33. self.dataArray = [NSMutableArray array];
  34. self.models = [NSArray array];
  35. _paging = 1;
  36. _url = [NSString stringWithFormat:@"Video.getVideoListByClass&classid=%@",_classID];
  37. [self.view addSubview:self.collectionView];
  38. self.collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  39. }
  40. - (NSArray *)models {
  41. NSMutableArray *m_array = [NSMutableArray array];
  42. for (NSDictionary *dic in _dataArray) {
  43. NearbyVideoModel *model = [NearbyVideoModel modelWithDic:dic];
  44. [m_array addObject:model];
  45. }
  46. _models = m_array;
  47. return _models;
  48. }
  49. -(void)pullData {
  50. _collectionView.userInteractionEnabled = NO;
  51. NSString *url = [NSString stringWithFormat:@"%@&p=%ld",_url,(long)_paging];
  52. [YBNetworking postWithUrl:url Dic:nil Suc:^(int code, id info, NSString *msg) {
  53. [_collectionView.mj_header endRefreshing];
  54. [_collectionView.mj_footer endRefreshing];
  55. _collectionView.userInteractionEnabled = YES;
  56. if (code == 0) {
  57. NSArray *infoA = [NSArray arrayWithArray:info];
  58. if (_paging == 1) {
  59. [_dataArray removeAllObjects];
  60. }
  61. if (infoA.count <= 0) {
  62. [_collectionView.mj_footer endRefreshingWithNoMoreData];
  63. }else{
  64. [_dataArray addObjectsFromArray:infoA];
  65. }
  66. if (_dataArray.count > 0) {
  67. [PublicView hiddenTextNoData:_collectionView];
  68. }else{
  69. [PublicView showTextNoData:_collectionView text1:@"" text2:YZMsg(@"暂无视频哦~") centerY:0.8];
  70. }
  71. [_collectionView reloadData];
  72. }else{
  73. if (_dataArray) {
  74. [_dataArray removeAllObjects];
  75. }
  76. [_collectionView reloadData];
  77. [PublicView showTextNoData:_collectionView text1:@"" text2:YZMsg(@"暂无视频哦~") centerY:0.8];
  78. }
  79. } Fail:^(id fail) {
  80. _collectionView.userInteractionEnabled = YES;
  81. _collectionView.userInteractionEnabled = YES;
  82. if (_dataArray) {
  83. [_dataArray removeAllObjects];
  84. }
  85. [_collectionView reloadData];
  86. [PublicView showTextNoData:_collectionView text1:@"" text2:YZMsg(@"暂无视频哦~") centerY:0.8];
  87. [_collectionView.mj_header endRefreshing];
  88. [_collectionView.mj_footer endRefreshing];
  89. }];
  90. }
  91. #pragma mark - CollectionView 代理
  92. /*
  93. * minimumLineSpacing、minimumInteritemSpacing去设置
  94. -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
  95. return CGSizeMake(0,0);
  96. }
  97. -(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
  98. {
  99. return UIEdgeInsetsMake(0,0,0,0);
  100. }
  101. */
  102. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
  103. return 2;
  104. }
  105. -(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
  106. return 1;
  107. }
  108. -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
  109. return self.models.count;
  110. }
  111. -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
  112. VideoCollectionCell *cell = (VideoCollectionCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"VideoCollectionCell" forIndexPath:indexPath];
  113. NearbyVideoModel *model = _models[indexPath.row];
  114. cell.isList = @"1";
  115. cell.model = model;
  116. return cell;
  117. }
  118. -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  119. NSString *vidoeID = minstr([_dataArray[indexPath.row] valueForKey:@"id"]);
  120. [YBGetVideoObj lookManeger].fromWhere = @"YBVideoClassVC";
  121. [YBGetVideoObj lookManeger].videoID = vidoeID;
  122. [YBGetVideoObj lookManeger].playIndex = (int)indexPath.row;
  123. [YBGetVideoObj lookManeger].videoList = [_dataArray mutableCopy];
  124. [YBGetVideoObj lookManeger].paging = (int)_paging;
  125. [YBGetVideoObj lookManeger].baseUrl = _url;
  126. [[YBGetVideoObj lookManeger]goLookVC];
  127. }
  128. #pragma mark - set/get
  129. - (UICollectionView *)collectionView {
  130. if (!_collectionView) {
  131. UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc]init];
  132. flow.scrollDirection = UICollectionViewScrollDirectionVertical;
  133. flow.itemSize = CGSizeMake(_window_width/2-1, (_window_width/2-1) * 1.4);
  134. flow.minimumLineSpacing = 2;
  135. flow.minimumInteritemSpacing = 2;
  136. _collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0,64+statusbarHeight, _window_width, _window_height-64-statusbarHeight-ShowDiff-49) collectionViewLayout:flow];
  137. [_collectionView registerNib:[UINib nibWithNibName:@"VideoCollectionCell" bundle:nil] forCellWithReuseIdentifier:@"VideoCollectionCell"];
  138. _collectionView.delegate =self;
  139. _collectionView.dataSource = self;
  140. _collectionView.backgroundColor = Normal_Color;
  141. _collectionView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
  142. _paging ++;
  143. [self pullData];
  144. }];
  145. _collectionView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  146. _paging = 1;
  147. [self pullData];
  148. }];
  149. }
  150. return _collectionView;
  151. }
  152. - (void)didReceiveMemoryWarning {
  153. [super didReceiveMemoryWarning];
  154. }
  155. @end