123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- //
- // YOUPAILZPersonalVideoVC.m
- // VQU
- //
- // Created by CY on 2021/7/10.
- // Copyright © 2021 leo. All rights reserved.
- //
- #import "YOUPAILZPersonalVideoVC.h"
- #import "UIScrollView+LZRefresh.h"
- #import "YOUPAIZYVideoModel.h"
- #import "YOUPAIZYSeeVideosVC.h"
- #import "YOUPAIZYDynamicVideoCell.h"
- @interface YOUPAILZPersonalVideoVC () <UICollectionViewDelegate,UICollectionViewDataSource>
- @property (nonatomic,strong)UICollectionView *youpaipcollectionView;
- @property(nonatomic,assign)NSInteger youpaippage;//代表当前页码
- @property(nonatomic,assign)NSInteger youpaiptotalPage;//总页码
- @property(nonatomic,strong)NSMutableArray *youpaipvideoDataArray;
- @property (nonatomic, strong) NSMutableArray *youpaipmp4UrlArray;
- @property (nonatomic, copy) void(^scrollCallback)(UIScrollView *scrollView);
- @end
- @implementation YOUPAILZPersonalVideoVC
- -(void)viewWillAppear:(BOOL)animated{
- [super viewWillAppear:animated];
- [self youpaifrequestListWithStatus:kRefreshHeader];
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- /// 关注状态改变,接收通知
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youpaifchangeFollowStateNotification:) name:@"ChangeFollowState" object:nil];
- [self youpaifinitUI];
- [self.youpaipcollectionView.mj_header beginRefreshing];
- }
- - (void)youpaifchangeFollowStateNotification:(NSNotification *)notification{
- NSDictionary *dict = [notification userInfo];
- NSString *idStr = dict[@"follow_uid"];
- NSInteger isfollow = [dict[@"is_follow"] intValue];
- NSArray *arr = self.youpaipvideoDataArray;
- NSMutableArray *arrM = [NSMutableArray new];
- if (arr.count>0) {
- NSIndexPath *index;
- for (int i = 0; i<arr.count; i++) {
- YOUPAIZYVideoModel *model = arr[i];
- if ([model.youpaipuser_id isEqualToString:idStr]) {
- model.youpaipis_follow = isfollow;
- index = [NSIndexPath indexPathForRow:i inSection:0];
- [arrM addObject:index];
- }
-
- }
- [self.youpaipcollectionView reloadItemsAtIndexPaths:arrM];
- }
-
- NSLog(@"%@",dict[@"follow_uid"]);
- }
- -(void)dealloc{
-
- [[NSNotificationCenter defaultCenter]removeObserver:self];
- }
- - (void)youpaifinitUI{
- UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
- layout.scrollDirection = UICollectionViewScrollDirectionVertical;
- CGFloat margin = 7.0f;
- CGFloat itemW = (KScreenWidth - 28.0f - margin) / 2.0f;
- layout.itemSize = CGSizeMake(itemW,itemW*(226.0f/170.0f));
- layout.minimumInteritemSpacing = margin;
- layout.minimumLineSpacing = margin;
- layout.sectionInset = UIEdgeInsetsMake(14.0f, 14.0f, 14.0f, 14.0f);
-
- UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
- collectionView.alwaysBounceVertical = YES;
- collectionView.backgroundColor = LCBkgColor;
- collectionView.dataSource = self;
- collectionView.delegate = self;
- collectionView.scrollEnabled = YES;
- collectionView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
- [collectionView registerClass:[YOUPAIZYDynamicVideoCell class] forCellWithReuseIdentifier:@"YOUPAIZYDynamicVideoCell"];
- [self.view addSubview:collectionView];
- self.youpaipcollectionView = collectionView;
- WeakSelf;
- [collectionView setRefreshHeaderWithBlock:^{
- [weakSelf youpaifrequestListWithStatus:kRefreshHeader];
- }];
- [collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.top.bottom.offset(0.0f);
- }];
- }
- /// 置顶
- - (void)youpaiftoTopAction{
- CGFloat offsetY = [self.youpaipcollectionView layoutAttributesForSupplementaryElementOfKind:UICollectionElementKindSectionHeader atIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]].frame.origin.y;
- CGFloat contentInsetY = self.youpaipcollectionView.contentInset.top;
- CGFloat sectionInsetY = ((UICollectionViewFlowLayout *)self.youpaipcollectionView.collectionViewLayout).sectionInset.top;
- [self.youpaipcollectionView setContentOffset:CGPointMake(self.youpaipcollectionView.contentOffset.x, offsetY - contentInsetY - sectionInsetY) animated:YES];
- }
- #pragma mark - UICollectionViewDataSource
- - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
- return self.youpaipvideoDataArray.count;
- }
- - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
- YOUPAIZYVideoModel *model = [_youpaipvideoDataArray objectAtIndex:indexPath.row];
- YOUPAIZYDynamicVideoCell *cell = (YOUPAIZYDynamicVideoCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"YOUPAIZYDynamicVideoCell" forIndexPath:indexPath];
- cell.youpaipmodel = model;
- return cell;
- }
- #pragma mark - UICollectionViewDelegate
- - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
- if (self.youpaipvideoDataArray.count != 0) {
- YOUPAIZYSeeVideosVC *vc = [[YOUPAIZYSeeVideosVC alloc] init];
- YOUPAIZYVideoModel *model = [_youpaipvideoDataArray objectAtIndex:indexPath.row];
- vc.youpaipuserId = model.youpaipuser_id;
- vc.youpaipindexPath = indexPath;
- vc.youpaipmp4UrlArray = self.youpaipmp4UrlArray.mutableCopy;
- vc.youpaipvideoDataArray = self.youpaipvideoDataArray.mutableCopy;
- [self.navigationController pushViewController:vc animated:YES];
- }
- // else{
- // [self.collectionView reloadData];
- // }
-
- }
- - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
- !self.scrollCallback ?: self.scrollCallback(scrollView);
- }
- #pragma mark - JXPagingViewListViewDelegate
- - (UIView *)listView{
- return self.view;
- }
- - (UIScrollView *)listScrollView{
- return self.youpaipcollectionView;
- }
- - (void)listViewDidScrollCallback:(void (^)(UIScrollView *))callback {
- self.scrollCallback = callback;
- }
- /// 设置加载更多
- - (void)youpaifrefreshFooterWithHidden:(BOOL)hidden{
- __weak typeof(self) weakSelf = self;
- [self.youpaipcollectionView setRefreshFooter:hidden withBlock:^{
- [weakSelf youpaifrequestListWithStatus:kRefreshFooter];
- }];
- }
- /// 获取列表数据
- - (void)youpaifrequestListWithStatus:(kRefreshStatus)status{
- if (status == kRefreshFooter) {
- self.youpaippage ++;
- }else{
- self.youpaippage = 1;
- }
- WeakSelf;
- [LCHttpHelper requestWithURLString:TrendsLists parameters:@{@"page":@(self.youpaippage),@"user_id":self.youpaipuserId} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
- [weakSelf.youpaipcollectionView endRefreshing:kRefreshAll];
- NSDictionary* dict = (NSDictionary*)responseObject;
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- if (code == 0) {//成功
- if (status != kRefreshFooter) {
- [weakSelf.youpaipvideoDataArray removeAllObjects];
- [weakSelf.youpaipmp4UrlArray removeAllObjects];
- }
- [weakSelf.youpaipvideoDataArray addObjectsFromArray:[YOUPAIZYVideoModel mj_objectArrayWithKeyValuesArray:[[dict objectForKey:@"data"] objectForKey:@"list"]]];
- for (YOUPAIZYVideoModel *model in self.youpaipvideoDataArray) {
- [weakSelf.youpaipmp4UrlArray addObject:[NSURL URLWithString:model.youpaipfile_url]];
- }
- NSInteger totalPage = [[[dict objectForKey:@"data"] objectForKey:@"total_page"] integerValue];
- weakSelf.youpaiptotalPage = totalPage;
- [weakSelf.youpaipcollectionView lz_hideEmptyView];
- if (weakSelf.youpaipvideoDataArray.count == 0) {
- [weakSelf.youpaipcollectionView lz_showEmptyViewWithImage:[UIImage imageNamed:@"vqu_images_not_dynamic_data"] content:@"TA还没有发布过作品呢~"];
- }else{
- [weakSelf.youpaipcollectionView lz_hideEmptyView];
- }
- [weakSelf.youpaipcollectionView reloadData];
- [weakSelf youpaifrefreshFooterWithHidden:weakSelf.youpaippage >= totalPage];
- }
- } failure:^(NSError *error) {
- [weakSelf.youpaipcollectionView endRefreshing:kRefreshAll];
- }];
- }
- -(NSMutableArray *)youpaipvideoDataArray{
- if (!_youpaipvideoDataArray) {
- _youpaipvideoDataArray = [NSMutableArray array];
- }
- return _youpaipvideoDataArray;
- }
- -(NSMutableArray *)youpaipmp4UrlArray{
- if (!_youpaipmp4UrlArray) {
- _youpaipmp4UrlArray = [NSMutableArray array];
- }
- return _youpaipmp4UrlArray;
- }
- @end
|