CenterListVC.m 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. //
  2. // CenterListVC.m
  3. // YBVideo
  4. //
  5. // Created by YunBao on 2018/6/14.
  6. // Copyright © 2018年 cat. All rights reserved.
  7. //
  8. #import "CenterListVC.h"
  9. #import "NearbyVideoModel.h"
  10. #import "CenterListCell.h"
  11. #import "YBGetVideoObj.h"
  12. @interface CenterListVC ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout,DZNEmptyDataSetSource,DZNEmptyDataSetDelegate>
  13. {
  14. BOOL canBackTop;
  15. NSString *pullurl;
  16. }
  17. @property(nonatomic,assign)int paging;
  18. @property(nonatomic,strong)UIImageView *backimage;
  19. @property(nonatomic,strong)NSMutableArray *videoArray;
  20. @property(nonatomic,strong)NSArray *models;
  21. @end
  22. @implementation CenterListVC
  23. -(void)viewWillDisappear:(BOOL)animated {
  24. [super viewWillDisappear:animated];
  25. if (_listType == ListType_Normal) {
  26. [PublicView hideCenterGif:nil];
  27. }
  28. }
  29. - (void)viewWillAppear:(BOOL)animated {
  30. [super viewWillAppear:animated];
  31. if ([[Config getOwnID] intValue] <= 0) {
  32. }else{
  33. [self pullData];
  34. }
  35. }
  36. -(NSArray *)models{
  37. NSMutableArray *m_array = [NSMutableArray array];
  38. for (NSDictionary *dic in self.videoArray) {
  39. NearbyVideoModel *model = [NearbyVideoModel modelWithDic:dic];
  40. [m_array addObject:model];
  41. }
  42. _models = m_array;
  43. return _models;
  44. }
  45. -(void)pullData {
  46. if (_listType == ListType_Normal) {
  47. pullurl = [NSString stringWithFormat:@"Video.getHomeVideo&touid=%@&p=%d",_otherUid,_paging];
  48. }else if(_listType == ListType_Likes){
  49. pullurl = [NSString stringWithFormat:@"User.getLikeVideos&touid=%@&p=%d",_otherUid,_paging];
  50. }else{
  51. pullurl = [NSString stringWithFormat:@"User.getCollectionVideos&touid=%@&p=%d",_otherUid,_paging];
  52. }
  53. [YBNetworking postWithUrl:pullurl Dic:nil Suc:^(int code, id info, NSString *msg) {
  54. [_collectionView.mj_footer endRefreshing];
  55. [_collectionView.mj_header endRefreshing];
  56. if (code == 0) {
  57. NSArray *infoA = [NSArray arrayWithArray:info];
  58. if (_paging==1) {
  59. [_videoArray removeAllObjects];
  60. }
  61. if (infoA.count>0) {
  62. [_videoArray addObjectsFromArray:infoA];
  63. }else{
  64. [_collectionView.mj_footer endRefreshingWithNoMoreData];
  65. }
  66. [self pubNoData];
  67. [_collectionView reloadData];
  68. }else{
  69. [MBProgressHUD showError:msg];
  70. }
  71. } Fail:^(id fail) {
  72. [_collectionView.mj_footer endRefreshing];
  73. [_collectionView.mj_header endRefreshing];
  74. [self pubNoData];
  75. }];
  76. }
  77. -(void)pubNoData {
  78. if (_listType == ListType_Normal && [_otherUid isEqual:[Config getOwnID]]) {
  79. if (_videoArray.count > 0) {
  80. [PublicView hideCenterGif:nil];
  81. }else{
  82. [PublicView showCenterGif:nil];
  83. }
  84. }
  85. }
  86. - (void)viewDidLoad {
  87. [super viewDidLoad];
  88. self.naviView.hidden = YES;
  89. self.view.backgroundColor = RGB(245, 245, 245);
  90. _paging = 1;
  91. self.videoArray = [NSMutableArray array];
  92. [self.view addSubview:self.collectionView];
  93. canBackTop = NO;
  94. }
  95. - (void)didReceiveMemoryWarning {
  96. [super didReceiveMemoryWarning];
  97. }
  98. #pragma mark - UICollectionViewDataSource
  99. - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
  100. if (kind == UICollectionElementKindSectionFooter){
  101. UICollectionReusableView *view = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"space_footer" forIndexPath:indexPath];
  102. view.backgroundColor = UIColor.whiteColor;
  103. return view;
  104. }
  105. return nil;
  106. }
  107. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section;{
  108. return CGSizeMake(_window_width,ShowDiff);
  109. }
  110. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  111. return self.models.count;
  112. }
  113. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
  114. return 1;
  115. }
  116. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  117. CenterListCell *cell = (CenterListCell*)[collectionView dequeueReusableCellWithReuseIdentifier:@"CenterListCell" forIndexPath:indexPath];
  118. cell.model = _models[indexPath.row];
  119. return cell;
  120. }
  121. #pragma mark - UICollectionViewDelegate
  122. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  123. NSDictionary *videoDic = _videoArray[indexPath.row];
  124. NSString *vidoeID = minstr([videoDic valueForKey:@"id"]);
  125. [YBGetVideoObj lookManeger].fromWhere = @"CenterVC";
  126. [YBGetVideoObj lookManeger].videoID = vidoeID;
  127. [YBGetVideoObj lookManeger].playIndex = (int)indexPath.row;
  128. [YBGetVideoObj lookManeger].videoList = [_videoArray mutableCopy];
  129. [YBGetVideoObj lookManeger].paging = _paging;
  130. [YBGetVideoObj lookManeger].baseUrl = pullurl;
  131. [[YBGetVideoObj lookManeger]goLookVC];
  132. }
  133. -(void)scrollViewDidScroll:(UIScrollView *)scrollView{
  134. NSLog(@"lsitvc=====%f===%d",scrollView.contentOffset.y,_collectionView.scrollEnabled);
  135. if (scrollView.contentOffset.y<=-50) {
  136. canBackTop = YES;
  137. }else{
  138. canBackTop = NO;
  139. }
  140. }
  141. - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset{
  142. if (canBackTop == YES) {
  143. [self.delegate listScrollToTop:velocity.y];
  144. }
  145. }
  146. #pragma mark - set/get
  147. - (UICollectionView *)collectionView {
  148. if (!_collectionView) {
  149. UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc]init];
  150. flow.scrollDirection = UICollectionViewScrollDirectionVertical;
  151. flow.itemSize = CGSizeMake(_window_width/3-1, _window_width/3*4/3);
  152. flow.minimumLineSpacing = 1;
  153. flow.minimumInteritemSpacing = 0.5;
  154. CGFloat HH = _window_height-44-64-49-statusbarHeight;
  155. if (!_isTabbar) {
  156. HH = _window_height-44-64-statusbarHeight;
  157. }
  158. _collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0,0, _window_width, HH) collectionViewLayout:flow];
  159. [self.collectionView registerNib:[UINib nibWithNibName:@"CenterListCell" bundle:nil] forCellWithReuseIdentifier:@"CenterListCell"];
  160. _collectionView.showsVerticalScrollIndicator = NO;
  161. _collectionView.delegate =self;
  162. _collectionView.dataSource = self;
  163. _collectionView.backgroundColor = UIColor.whiteColor;
  164. _collectionView.scrollEnabled = NO;
  165. [_collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"space_footer"];
  166. _collectionView.emptyDataSetSource = self;
  167. _collectionView.emptyDataSetDelegate = self;
  168. _collectionView.mj_insetB = -ShowDiff;
  169. YBWeakSelf;
  170. _collectionView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
  171. weakSelf.paging = 1;
  172. [self pullData];
  173. }];
  174. self.collectionView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
  175. weakSelf.paging +=1;
  176. [self pullData];
  177. }];
  178. }
  179. return _collectionView;
  180. }
  181. - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView {
  182. NSString *text = @"";
  183. if (_listType == ListType_Normal && ![_otherUid isEqual:[Config getOwnID]]) {
  184. text = YZMsg(@"TA还没有作品");
  185. }else if (_listType == ListType_Likes && ![_otherUid isEqual:[Config getOwnID]]){
  186. text = YZMsg(@"TA还没有喜欢的视频");
  187. }else if (_listType == ListType_Likes && [_otherUid isEqual:[Config getOwnID]]){
  188. text = YZMsg(@"你赞过的作品都会放到这里");
  189. }else if (_listType == ListType_Collection){
  190. text = YZMsg(@"你收藏的作品都会放到这里");
  191. }
  192. NSDictionary *attributes = @{NSFontAttributeName: ybNodataFont,
  193. NSForegroundColorAttributeName: ybNodataCol};
  194. return [[NSAttributedString alloc] initWithString:text attributes:attributes];
  195. }
  196. - (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView{
  197. CGFloat moveY = -(statusbarHeight+64+44);
  198. return moveY;
  199. }
  200. - (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView{
  201. return NO;
  202. }
  203. @end