YOUPAILZPersonalVideoVC.m 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. //
  2. // YOUPAILZPersonalVideoVC.m
  3. // VQU
  4. //
  5. // Created by CY on 2021/7/10.
  6. // Copyright © 2021 leo. All rights reserved.
  7. //
  8. #import "YOUPAILZPersonalVideoVC.h"
  9. #import "UIScrollView+LZRefresh.h"
  10. #import "YOUPAIZYVideoModel.h"
  11. #import "YOUPAIZYSeeVideosVC.h"
  12. #import "YOUPAIZYDynamicVideoCell.h"
  13. @interface YOUPAILZPersonalVideoVC () <UICollectionViewDelegate,UICollectionViewDataSource>
  14. @property (nonatomic,strong)UICollectionView *youpaipcollectionView;
  15. @property(nonatomic,assign)NSInteger youpaippage;//代表当前页码
  16. @property(nonatomic,assign)NSInteger youpaiptotalPage;//总页码
  17. @property(nonatomic,strong)NSMutableArray *youpaipvideoDataArray;
  18. @property (nonatomic, strong) NSMutableArray *youpaipmp4UrlArray;
  19. @property (nonatomic, copy) void(^scrollCallback)(UIScrollView *scrollView);
  20. @end
  21. @implementation YOUPAILZPersonalVideoVC
  22. -(void)viewWillAppear:(BOOL)animated{
  23. [super viewWillAppear:animated];
  24. [self youpaifrequestListWithStatus:kRefreshHeader];
  25. }
  26. - (void)viewDidLoad {
  27. [super viewDidLoad];
  28. /// 关注状态改变,接收通知
  29. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youpaifchangeFollowStateNotification:) name:@"ChangeFollowState" object:nil];
  30. [self youpaifinitUI];
  31. [self.youpaipcollectionView.mj_header beginRefreshing];
  32. }
  33. - (void)youpaifchangeFollowStateNotification:(NSNotification *)notification{
  34. NSDictionary *dict = [notification userInfo];
  35. NSString *idStr = dict[@"follow_uid"];
  36. NSInteger isfollow = [dict[@"is_follow"] intValue];
  37. NSArray *arr = self.youpaipvideoDataArray;
  38. NSMutableArray *arrM = [NSMutableArray new];
  39. if (arr.count>0) {
  40. NSIndexPath *index;
  41. for (int i = 0; i<arr.count; i++) {
  42. YOUPAIZYVideoModel *model = arr[i];
  43. if ([model.youpaipuser_id isEqualToString:idStr]) {
  44. model.youpaipis_follow = isfollow;
  45. index = [NSIndexPath indexPathForRow:i inSection:0];
  46. [arrM addObject:index];
  47. }
  48. }
  49. [self.youpaipcollectionView reloadItemsAtIndexPaths:arrM];
  50. }
  51. NSLog(@"%@",dict[@"follow_uid"]);
  52. }
  53. -(void)dealloc{
  54. [[NSNotificationCenter defaultCenter]removeObserver:self];
  55. }
  56. - (void)youpaifinitUI{
  57. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  58. layout.scrollDirection = UICollectionViewScrollDirectionVertical;
  59. CGFloat margin = 7.0f;
  60. CGFloat itemW = (KScreenWidth - 28.0f - margin) / 2.0f;
  61. layout.itemSize = CGSizeMake(itemW,itemW*(226.0f/170.0f));
  62. layout.minimumInteritemSpacing = margin;
  63. layout.minimumLineSpacing = margin;
  64. layout.sectionInset = UIEdgeInsetsMake(14.0f, 14.0f, 14.0f, 14.0f);
  65. UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
  66. collectionView.alwaysBounceVertical = YES;
  67. collectionView.backgroundColor = LCBkgColor;
  68. collectionView.dataSource = self;
  69. collectionView.delegate = self;
  70. collectionView.scrollEnabled = YES;
  71. collectionView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  72. [collectionView registerClass:[YOUPAIZYDynamicVideoCell class] forCellWithReuseIdentifier:@"YOUPAIZYDynamicVideoCell"];
  73. [self.view addSubview:collectionView];
  74. self.youpaipcollectionView = collectionView;
  75. WeakSelf;
  76. [collectionView setRefreshHeaderWithBlock:^{
  77. [weakSelf youpaifrequestListWithStatus:kRefreshHeader];
  78. }];
  79. [collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
  80. make.left.right.top.bottom.offset(0.0f);
  81. }];
  82. }
  83. /// 置顶
  84. - (void)youpaiftoTopAction{
  85. CGFloat offsetY = [self.youpaipcollectionView layoutAttributesForSupplementaryElementOfKind:UICollectionElementKindSectionHeader atIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]].frame.origin.y;
  86. CGFloat contentInsetY = self.youpaipcollectionView.contentInset.top;
  87. CGFloat sectionInsetY = ((UICollectionViewFlowLayout *)self.youpaipcollectionView.collectionViewLayout).sectionInset.top;
  88. [self.youpaipcollectionView setContentOffset:CGPointMake(self.youpaipcollectionView.contentOffset.x, offsetY - contentInsetY - sectionInsetY) animated:YES];
  89. }
  90. #pragma mark - UICollectionViewDataSource
  91. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  92. return self.youpaipvideoDataArray.count;
  93. }
  94. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  95. YOUPAIZYVideoModel *model = [_youpaipvideoDataArray objectAtIndex:indexPath.row];
  96. YOUPAIZYDynamicVideoCell *cell = (YOUPAIZYDynamicVideoCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"YOUPAIZYDynamicVideoCell" forIndexPath:indexPath];
  97. cell.youpaipmodel = model;
  98. return cell;
  99. }
  100. #pragma mark - UICollectionViewDelegate
  101. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  102. if (self.youpaipvideoDataArray.count != 0) {
  103. YOUPAIZYSeeVideosVC *vc = [[YOUPAIZYSeeVideosVC alloc] init];
  104. YOUPAIZYVideoModel *model = [_youpaipvideoDataArray objectAtIndex:indexPath.row];
  105. vc.youpaipuserId = model.youpaipuser_id;
  106. vc.youpaipindexPath = indexPath;
  107. vc.youpaipmp4UrlArray = self.youpaipmp4UrlArray.mutableCopy;
  108. vc.youpaipvideoDataArray = self.youpaipvideoDataArray.mutableCopy;
  109. [self.navigationController pushViewController:vc animated:YES];
  110. }
  111. // else{
  112. // [self.collectionView reloadData];
  113. // }
  114. }
  115. - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  116. !self.scrollCallback ?: self.scrollCallback(scrollView);
  117. }
  118. #pragma mark - JXPagingViewListViewDelegate
  119. - (UIView *)listView{
  120. return self.view;
  121. }
  122. - (UIScrollView *)listScrollView{
  123. return self.youpaipcollectionView;
  124. }
  125. - (void)listViewDidScrollCallback:(void (^)(UIScrollView *))callback {
  126. self.scrollCallback = callback;
  127. }
  128. /// 设置加载更多
  129. - (void)youpaifrefreshFooterWithHidden:(BOOL)hidden{
  130. __weak typeof(self) weakSelf = self;
  131. [self.youpaipcollectionView setRefreshFooter:hidden withBlock:^{
  132. [weakSelf youpaifrequestListWithStatus:kRefreshFooter];
  133. }];
  134. }
  135. /// 获取列表数据
  136. - (void)youpaifrequestListWithStatus:(kRefreshStatus)status{
  137. if (status == kRefreshFooter) {
  138. self.youpaippage ++;
  139. }else{
  140. self.youpaippage = 1;
  141. }
  142. WeakSelf;
  143. [LCHttpHelper requestWithURLString:TrendsLists parameters:@{@"page":@(self.youpaippage),@"user_id":self.youpaipuserId} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  144. [weakSelf.youpaipcollectionView endRefreshing:kRefreshAll];
  145. NSDictionary* dict = (NSDictionary*)responseObject;
  146. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  147. if (code == 0) {//成功
  148. if (status != kRefreshFooter) {
  149. [weakSelf.youpaipvideoDataArray removeAllObjects];
  150. [weakSelf.youpaipmp4UrlArray removeAllObjects];
  151. }
  152. [weakSelf.youpaipvideoDataArray addObjectsFromArray:[YOUPAIZYVideoModel mj_objectArrayWithKeyValuesArray:[[dict objectForKey:@"data"] objectForKey:@"list"]]];
  153. for (YOUPAIZYVideoModel *model in self.youpaipvideoDataArray) {
  154. [weakSelf.youpaipmp4UrlArray addObject:[NSURL URLWithString:model.youpaipfile_url]];
  155. }
  156. NSInteger totalPage = [[[dict objectForKey:@"data"] objectForKey:@"total_page"] integerValue];
  157. weakSelf.youpaiptotalPage = totalPage;
  158. [weakSelf.youpaipcollectionView lz_hideEmptyView];
  159. if (weakSelf.youpaipvideoDataArray.count == 0) {
  160. [weakSelf.youpaipcollectionView lz_showEmptyViewWithImage:[UIImage imageNamed:@"vqu_images_not_dynamic_data"] content:@"TA还没有发布过作品呢~"];
  161. }else{
  162. [weakSelf.youpaipcollectionView lz_hideEmptyView];
  163. }
  164. [weakSelf.youpaipcollectionView reloadData];
  165. [weakSelf youpaifrefreshFooterWithHidden:weakSelf.youpaippage >= totalPage];
  166. }
  167. } failure:^(NSError *error) {
  168. [weakSelf.youpaipcollectionView endRefreshing:kRefreshAll];
  169. }];
  170. }
  171. -(NSMutableArray *)youpaipvideoDataArray{
  172. if (!_youpaipvideoDataArray) {
  173. _youpaipvideoDataArray = [NSMutableArray array];
  174. }
  175. return _youpaipvideoDataArray;
  176. }
  177. -(NSMutableArray *)youpaipmp4UrlArray{
  178. if (!_youpaipmp4UrlArray) {
  179. _youpaipmp4UrlArray = [NSMutableArray array];
  180. }
  181. return _youpaipmp4UrlArray;
  182. }
  183. @end