myVideoV.m 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. //
  2. // myVideoV.m
  3. // YBVideo
  4. //
  5. // Created by 王敏欣 on 2017/8/4.
  6. // Copyright © 2017年 cat. All rights reserved.
  7. //
  8. #import "myVideoV.h"
  9. #import <MJRefresh/MJRefresh.h>
  10. #import "YBGetVideoObj.h"
  11. #import "NearbyVideoModel.h"
  12. #import "VideoCollectionCell.h"
  13. #import "AFNetworking.h"
  14. @interface myVideoV ()<UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>
  15. @property(nonatomic,strong)NSMutableArray *allArray;
  16. @property(nonatomic,strong)NSArray *modelrray;
  17. @property(nonatomic,strong)UICollectionView *collectionView;
  18. @end
  19. @implementation myVideoV
  20. {
  21. NSInteger _page;
  22. }
  23. - (void)viewDidLoad {
  24. [super viewDidLoad];
  25. self.naviView.hidden = YES;
  26. _modelrray = [NSArray array];
  27. _page = 1;
  28. self.navigationController.interactivePopGestureRecognizer.delegate = (id) self;
  29. self.allArray = [NSMutableArray array];
  30. UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc]init];
  31. flow.scrollDirection = UICollectionViewScrollDirectionVertical;
  32. flow.itemSize = CGSizeMake(_window_width/2-1, (_window_width/2-1) * 1.4);
  33. flow.minimumLineSpacing = 2;
  34. flow.minimumInteritemSpacing = 2;
  35. self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0,64+statusbarHeight, _window_width, _window_height-64-statusbarHeight-ShowDiff-49) collectionViewLayout:flow];
  36. [self.collectionView registerNib:[UINib nibWithNibName:@"VideoCollectionCell" bundle:nil] forCellWithReuseIdentifier:@"VideoCollectionCell"];
  37. self.collectionView.delegate =self;
  38. self.collectionView.dataSource = self;
  39. self.collectionView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
  40. _page ++;
  41. [self pullInternetforNew:_page];
  42. }];
  43. self.collectionView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  44. _page = 1;
  45. [self pullInternetforNew:_page];
  46. }];
  47. [self.view addSubview:self.collectionView];
  48. self.collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  49. self.view.backgroundColor = Normal_Color;
  50. self.collectionView.backgroundColor = [UIColor blackColor];
  51. [self pullInternetforNew:1];
  52. //在视频页面输出视频后返回
  53. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getLiveList:) name:@"delete" object:nil];
  54. //发布视频成功之后返回首页刷新列表
  55. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pullInternetforNewDown) name:@"reloadlist" object:nil];
  56. }
  57. //在视频页面删除视频回来后删除
  58. -(void)getLiveList:(NSNotification *)nsnitofition{
  59. NSString *videoid = [NSString stringWithFormat:@"%@",[[nsnitofition userInfo] valueForKey:@"videoid"]];
  60. NSDictionary *deletedic = [NSDictionary dictionary];
  61. for (NSDictionary *subdic in self.allArray) {
  62. NSString *videoids = [NSString stringWithFormat:@"%@",[subdic valueForKey:@"id"]];
  63. if ([videoid isEqual:videoids]) {
  64. deletedic = subdic;
  65. break;
  66. }
  67. }
  68. if (deletedic) {
  69. [self.allArray removeObject:deletedic];
  70. [self.collectionView reloadData];
  71. }
  72. }
  73. -(void)refreshNear{
  74. }
  75. //down
  76. -(void)pullInternetforNewDown{
  77. self.allArray = [NSMutableArray array];
  78. _page = 1;
  79. [self pullInternetforNew:_page];
  80. }
  81. -(void)getDataByFooterup{
  82. _page ++;
  83. [self pullInternetforNew:_page];
  84. }
  85. -(void)pullInternetforNew:(NSInteger)pages{
  86. self.collectionView.userInteractionEnabled = NO;
  87. NSString *url = [NSString stringWithFormat:@"%@&p=%ld",_url,(long)pages];
  88. YBWeakSelf;
  89. [YBNetworking postWithUrl:url Dic:nil Suc:^(int code, id info, NSString *msg) {
  90. [weakSelf.collectionView.mj_header endRefreshing];
  91. [weakSelf.collectionView.mj_footer endRefreshing];
  92. weakSelf.collectionView.userInteractionEnabled = YES;
  93. if (code == 0) {
  94. NSArray *infoA = [NSArray arrayWithArray:info];
  95. if (_page == 1) {
  96. [self.allArray removeAllObjects];
  97. }
  98. [self.allArray addObjectsFromArray:infoA];
  99. //加载成功 停止刷新
  100. [self.collectionView.mj_header endRefreshing];
  101. [self.collectionView.mj_footer endRefreshing];
  102. [self.collectionView reloadData];
  103. if (self.allArray.count > 0) {
  104. [PublicView hiddenTextNoData:_collectionView];
  105. }else{
  106. [PublicView showTextNoData:_collectionView text1:@"" text2:YZMsg(@"暂无热门视频哦~") centerY:0.8];
  107. }
  108. if (infoA.count <= 0) {
  109. [self.collectionView.mj_footer endRefreshingWithNoMoreData];
  110. }
  111. }else{
  112. if (self.allArray) {
  113. [self.allArray removeAllObjects];
  114. }
  115. [self.collectionView reloadData];
  116. [PublicView showTextNoData:_collectionView text1:@"" text2:YZMsg(@"暂无热门视频哦~") centerY:0.8];
  117. }
  118. } Fail:^(id fail) {
  119. weakSelf.collectionView.userInteractionEnabled = YES;
  120. self.collectionView.userInteractionEnabled = YES;
  121. if (self.allArray) {
  122. [self.allArray removeAllObjects];
  123. }
  124. [self.collectionView reloadData];
  125. [PublicView showTextNoData:_collectionView text1:@"" text2:YZMsg(@"暂无热门视频哦~") centerY:0.8];
  126. [self.collectionView.mj_header endRefreshing];
  127. [self.collectionView.mj_footer endRefreshing];
  128. }];
  129. }
  130. #pragma mark - Table view data source
  131. //-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
  132. // return CGSizeMake((_window_width - 6)/2,(_window_width - 6)/2 * 1.4);
  133. //}
  134. //-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
  135. //{
  136. // return UIEdgeInsetsMake(2,2,2,2);
  137. //}
  138. -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
  139. return self.allArray.count;
  140. }
  141. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
  142. return 2;
  143. }
  144. -(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
  145. return 1;
  146. }
  147. -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  148. NSString *vidoeID = minstr([_allArray[indexPath.row] valueForKey:@"id"]);
  149. [YBGetVideoObj lookManeger].fromWhere = @"myVideoV";
  150. [YBGetVideoObj lookManeger].videoID = vidoeID;
  151. [YBGetVideoObj lookManeger].playIndex = (int)indexPath.row;
  152. [YBGetVideoObj lookManeger].videoList = [_allArray mutableCopy];
  153. [YBGetVideoObj lookManeger].paging = (int)_page;
  154. [YBGetVideoObj lookManeger].baseUrl = _url;
  155. [[YBGetVideoObj lookManeger]goLookVC];
  156. }
  157. -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
  158. VideoCollectionCell *cell = (VideoCollectionCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"VideoCollectionCell" forIndexPath:indexPath];
  159. // cell.layer.cornerRadius = 5.0;
  160. // cell.layer.masksToBounds = YES;
  161. NSDictionary *subdic = _allArray[indexPath.row];
  162. cell.isList = @"1";
  163. cell.model = [[NearbyVideoModel alloc] initWithDic:subdic];
  164. return cell;
  165. }
  166. @end