MyFollowViewController.m 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. //
  2. // MyFollowViewController.m
  3. // YBVideo
  4. //
  5. // Created by YangBiao on 2017/9/7.
  6. // Copyright © 2017年 cat. All rights reserved.
  7. //
  8. #import "MyFollowViewController.h"
  9. #import "searchVC.h"
  10. #import "VideoCollectionCell.h"
  11. #import "NearbyVideoModel.h"
  12. #import <MJRefresh/MJRefresh.h>
  13. #import "YBGetVideoObj.h"
  14. @interface MyFollowViewController () <UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout,UIAlertViewDelegate>
  15. @property(nonatomic,strong)NSString *MD5;
  16. @property(nonatomic,strong)NSMutableArray *videoArray;
  17. @property(nonatomic,strong)UICollectionView *videoCollection;
  18. @end
  19. @implementation MyFollowViewController
  20. {
  21. UIImageView *_noVideoImage;
  22. NSDictionary *selectedDic;
  23. int selected;
  24. MJRefreshAutoNormalFooter *footer;
  25. NSInteger _page;
  26. }
  27. -(void)viewWillAppear:(BOOL)animated{
  28. [super viewWillAppear:animated];
  29. [[PublicObj publicInstance]addCusDelayedRemove];
  30. }
  31. - (void)viewDidLoad {
  32. [super viewDidLoad];
  33. self.navigationController.navigationBar.hidden = YES;
  34. self.view.backgroundColor = Normal_Color;
  35. self.leftBtn.hidden = YES;
  36. self.rightBtn.hidden = YES;
  37. //self.titleL.text = @"关注";
  38. self.naviView.hidden = YES;
  39. _page = 1;
  40. self.videoArray = [NSMutableArray array];
  41. [self setCollectionView];
  42. [self getNewVideo];
  43. //返回后如果有删除
  44. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getLiveList:) name:@"delete" object:nil];
  45. }
  46. //在视频页面删除视频回来后删除
  47. -(void)getLiveList:(NSNotification *)nsnitofition{
  48. NSString *videoid = [NSString stringWithFormat:@"%@",[[nsnitofition userInfo] valueForKey:@"videoid"]];
  49. NSDictionary *deletedic = [NSDictionary dictionary];
  50. for (NSDictionary *subdic in _videoArray) {
  51. NSString *videoids = [NSString stringWithFormat:@"%@",[subdic valueForKey:@"id"]];
  52. if ([videoid isEqual:videoids]) {
  53. deletedic = subdic;
  54. break;
  55. }
  56. }
  57. if (deletedic) {
  58. [_videoArray removeObject:deletedic];
  59. [_videoCollection reloadData];
  60. }
  61. }
  62. - (void)getMoreVideo{
  63. _page ++;
  64. [self getVideoListWithPage:_page];
  65. }
  66. - (void)getNewVideo{
  67. _videoArray = [NSMutableArray array];
  68. _page = 1;
  69. [self getVideoListWithPage:_page];
  70. }
  71. - (void)getVideoListWithPage:(NSInteger)page{
  72. if ([[Config getOwnID] intValue] <= 0) {
  73. [PublicView showTextNoData:_videoCollection text1:YZMsg(@"你还没有关注任何人") text2:YZMsg(@"赶快去关注自己感兴趣的人吧") centerY:0.8];
  74. return;
  75. }
  76. [PublicView hiddenTextNoData:_videoCollection];
  77. YBWeakSelf;
  78. [YBNetworking postWithUrl:_url Dic:@{@"p":@(page)} Suc:^(int code, id info, NSString *msg) {
  79. [weakSelf.videoCollection.mj_header endRefreshing];
  80. [weakSelf.videoCollection.mj_footer endRefreshing];
  81. if (code == 0) {
  82. NSArray *infoA = [NSArray arrayWithArray:info];
  83. if (_page == 1) {
  84. [_videoArray removeAllObjects];
  85. }
  86. if (infoA.count <= 0) {
  87. [weakSelf.videoCollection.mj_footer endRefreshingWithNoMoreData];
  88. }else {
  89. [weakSelf.videoArray addObjectsFromArray:infoA];
  90. }
  91. [weakSelf.videoCollection reloadData];
  92. if (weakSelf.videoArray.count > 0) {
  93. footer.hidden = NO;
  94. [PublicView hiddenTextNoData:weakSelf.videoCollection];
  95. }else{
  96. footer.hidden = YES;
  97. [PublicView showTextNoData:weakSelf.videoCollection text1:YZMsg(@"你还没有关注任何人") text2:YZMsg(@"赶快去关注自己感兴趣的人吧") centerY:0.8];
  98. }
  99. }else{
  100. if (weakSelf.videoArray) {
  101. [weakSelf.videoArray removeAllObjects];
  102. }
  103. [weakSelf.videoCollection reloadData];
  104. [PublicView showTextNoData:weakSelf.videoCollection text1:YZMsg(@"你还没有关注任何人") text2:YZMsg(@"赶快去关注自己感兴趣的人吧") centerY:0.8];
  105. [MBProgressHUD showError:msg];
  106. }
  107. } Fail:^(id fail) {
  108. if (weakSelf.videoArray) {
  109. [weakSelf.videoArray removeAllObjects];
  110. }
  111. [weakSelf.videoCollection reloadData];
  112. [PublicView showTextNoData:weakSelf.videoCollection text1:YZMsg(@"你还没有关注任何人") text2:YZMsg(@"赶快去关注自己感兴趣的人吧") centerY:0.8];
  113. [weakSelf.videoCollection.mj_header endRefreshing];
  114. [weakSelf.videoCollection.mj_footer endRefreshing];
  115. }];
  116. }
  117. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  118. NSString *vidoeID = minstr([_videoArray[indexPath.row] valueForKey:@"id"]);
  119. [YBGetVideoObj lookManeger].fromWhere = @"MyFollowViewController";
  120. [YBGetVideoObj lookManeger].videoID = vidoeID;
  121. [YBGetVideoObj lookManeger].playIndex = (int)indexPath.row;
  122. [YBGetVideoObj lookManeger].videoList = [_videoArray mutableCopy];
  123. [YBGetVideoObj lookManeger].paging = (int)_page;
  124. NSString *basUrl = [NSString stringWithFormat:@"video.getAttentionVideo&uid=%@&token=%@",[Config getOwnID],[Config getOwnToken]];
  125. [YBGetVideoObj lookManeger].baseUrl = basUrl;
  126. [[YBGetVideoObj lookManeger]goLookVC];
  127. }
  128. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
  129. return 1;
  130. }
  131. //- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
  132. // return CGSizeMake((_window_width - 3) / 2, (_window_width - 3) / 2 * 1.3);
  133. //}
  134. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
  135. return 1;
  136. }
  137. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
  138. return 1;
  139. }
  140. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
  141. return _videoArray.count;
  142. }
  143. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
  144. VideoCollectionCell *cell = (VideoCollectionCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"VideoCollectionCell" forIndexPath:indexPath];
  145. NSDictionary *dic = _videoArray[indexPath.row];
  146. cell.isAtten = @"1";
  147. NearbyVideoModel *model = [[NearbyVideoModel alloc] initWithDic:dic];
  148. cell.model = model;
  149. return cell;
  150. }
  151. - (void)setCollectionView{
  152. UICollectionViewFlowLayout *layout2 = [[UICollectionViewFlowLayout alloc] init];
  153. layout2.scrollDirection = UICollectionViewScrollDirectionVertical;
  154. layout2.itemSize = CGSizeMake(_window_width/2-1, (_window_width/2-1) * 1.4);
  155. layout2.minimumLineSpacing = 2;
  156. layout2.minimumInteritemSpacing = 2;
  157. _videoCollection = [[UICollectionView alloc] initWithFrame:CGRectMake(0,64+statusbarHeight, _window_width, _window_height-64-statusbarHeight-ShowDiff-49) collectionViewLayout:layout2];
  158. _videoCollection.backgroundColor = Normal_Color;//[UIColor whiteColor];
  159. _videoCollection.delegate = self;
  160. _videoCollection.dataSource = self;
  161. _videoCollection.alwaysBounceVertical = YES;
  162. [self.view addSubview:_videoCollection];
  163. _videoCollection.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  164. [_videoCollection registerNib:[UINib nibWithNibName:@"VideoCollectionCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"VideoCollectionCell"];
  165. _videoCollection.mj_header = ({
  166. MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(getNewVideo)];
  167. header.lastUpdatedTimeLabel.hidden = YES;
  168. header.stateLabel.hidden = YES;
  169. header;
  170. });
  171. footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(getMoreVideo)];
  172. [footer setTitle:@"" forState:MJRefreshStateRefreshing];
  173. [footer setTitle:@"" forState:MJRefreshStateNoMoreData];
  174. footer.stateLabel.font = [UIFont systemFontOfSize:15.0f];
  175. _videoCollection.mj_footer = footer;
  176. }
  177. @end