al
liurenjie
2021-07-03 1b73d5d0b495f2d643c2523e1b8399f925b4f702
BuWanVideo2.0/Recommend/ListControlelr/ListController.m
@@ -71,7 +71,7 @@
    dispatch_group_t group = dispatch_group_create();
    dispatch_group_async(group, queue, ^{
        [[YTHNetInterface startInterface] getRecommendCategoryVideoBannerWithUid:[YTHsharedManger startManger].Uid vtid:_parms[@"Id"] withSystem:@"1" withBlock:^(BOOL isSuccessful, id result, NSString *error) {
            if (isSuccessful) {
                NSDictionary *dic = (NSDictionary *)result;
                self.dictionaryBanaer = dic[@"Data"];
@@ -82,7 +82,7 @@
    
    dispatch_group_async(group, queue, ^{
        [[YTHNetInterface startInterface] getRecommendCategoryVideoListWithUid:[YTHsharedManger startManger].Uid withVideoType:_parms[@"Id"] withSystem:@"1" withBlock:^(BOOL isSuccessful, id result, NSString *error) {
            if (isSuccessful) {
                if (_page == 1) {
                    [self.arrayContent removeAllObjects];
@@ -90,15 +90,6 @@
                self.arrayTemp = result[@"Data"][@"data"];
                self.count = [result[@"Data"][@"count"] integerValue];
                self.page++;
                if (self.count == self.arrayContent.count) {
                    [self hideFooger];
                } else {
                    if (!self.collectionView.mj_footer) {
                        [self setFooterRefresh];
                    }
                }
            }
            dispatch_semaphore_signal(semaphore);
        }];
@@ -111,6 +102,15 @@
        dispatch_async(dispatch_get_main_queue(), ^{
            [self.arrayContent addObjectsFromArray:self.arrayTemp];
            [self.collectionView reloadData];
            if (self.count == self.arrayContent.count) {
                [self hideFooger];
            } else {
                if (!self.collectionView.mj_footer) {
                    [self setFooterRefresh];
                }
            }
        });
    });
}
@@ -184,60 +184,64 @@
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return self.arrayContent.count+1;
    if (self.dictionaryBanaer && [self.dictionaryBanaer allKeys].count != 0) {
        return 2;
    }
    return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    if (section == 0) {
        return 1;
    if (self.dictionaryBanaer && [self.dictionaryBanaer allKeys].count != 0) {
        if (section == 0) {
            return 1;
        } else {
            return self.arrayContent.count;
        }
        
    } else {
        NSUInteger Columns = [self.arrayContent[section-1][@"Columns"] integerValue];
        if (Columns == 2 || Columns == 3) {
            BOOL BigPicture = [self.arrayContent[section-1][@"HomeVideoList"][0][@"BigPicture"] boolValue];
            if (BigPicture) {
                return [self.arrayContent[section-1][@"HomeVideoList"] count]-1;
            }
            return [self.arrayContent[section-1][@"HomeVideoList"] count];
        }
        return self.arrayContent.count;
    }
    return 1;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        if (!self.cellRecommendHeader) {
            self.cellRecommendHeader = [collectionView dequeueReusableCellWithReuseIdentifier:@"RecommendHeaderViewCell" forIndexPath:indexPath];
    if (self.dictionaryBanaer && [self.dictionaryBanaer allKeys].count != 0) {
        if (indexPath.section == 0) {
            if (!self.cellRecommendHeader) {
                self.cellRecommendHeader = [collectionView dequeueReusableCellWithReuseIdentifier:@"RecommendHeaderViewCell" forIndexPath:indexPath];
            }
            self.cellRecommendHeader.arrayImageNormolData = self.dictionaryBanaer;
            return self.cellRecommendHeader;
        } else {
            NSUInteger ids = [_parms[@"Id"] integerValue];
            if (ids == 150 || ids == 151 || ids == 152 ||ids == 153) {
                RecommendThreeColumnCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"RecommendThreeColumnCell" forIndexPath:indexPath];
                cell.data = self.arrayContent[indexPath.row];
                return cell;
            } else {
                RecommendTwoColumnCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"RecommendTwoColumnCell" forIndexPath:indexPath];
                cell.dataNormol = self.arrayContent[indexPath.row];
                return cell;
            }
        }
        self.cellRecommendHeader.arrayImageData = self.dictionaryBanaer;
        return self.cellRecommendHeader;
    } else {
        NSUInteger Columns = [self.arrayContent[indexPath.section-1][@"Columns"] integerValue];
        if (Columns > 3) {
            ToDayHotCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ToDayHotCell" forIndexPath:indexPath];
            cell.data = self.arrayContent[indexPath.section-1];
            return cell;
        } else if (Columns == 2) {
            RecommendTwoColumnCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"RecommendTwoColumnCell" forIndexPath:indexPath];
            BOOL BigPicture = [self.arrayContent[indexPath.section-1][@"HomeVideoList"][0][@"BigPicture"] boolValue];
            if (BigPicture) {
                cell.data = self.arrayContent[indexPath.section-1][@"HomeVideoList"][indexPath.row+1][@"Video"];
            } else {
                cell.data = self.arrayContent[indexPath.section-1][@"HomeVideoList"][indexPath.row][@"Video"];
            }
            return cell;
        } else if (Columns == 3) {
        NSUInteger ids = [_parms[@"Id"] integerValue];
        if (ids == 150 || ids == 151 || ids == 152 ||ids == 153) {
            RecommendThreeColumnCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"RecommendThreeColumnCell" forIndexPath:indexPath];
            BOOL BigPicture = [self.arrayContent[indexPath.section-1][@"HomeVideoList"][0][@"BigPicture"] boolValue];
            if (BigPicture) {
                cell.data = self.arrayContent[indexPath.section-1][@"HomeVideoList"][indexPath.row+1][@"Video"];
            } else {
                cell.data = self.arrayContent[indexPath.section-1][@"HomeVideoList"][indexPath.row][@"Video"];
            }
            cell.data = self.arrayContent[indexPath.row];
            return cell;
        } else {
            RecommendTwoColumnCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"RecommendTwoColumnCell" forIndexPath:indexPath];
            cell.dataNormol = self.arrayContent[indexPath.row];
            return cell;
        }
    }
@@ -249,28 +253,37 @@
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
    
    if (kind == UICollectionElementKindSectionHeader) {
        if (indexPath.section > 0) {
            RecpmmendTitleView *view = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"RecpmmendTitleView" forIndexPath:indexPath];
            view.delegate = self;
            BOOL BigPicture = [self.arrayContent[indexPath.section-1][@"HomeVideoList"][0][@"BigPicture"] boolValue];
            view.isBanaer = BigPicture;
            view.data = self.arrayContent[indexPath.section-1];
            view.index = indexPath.section;
            return view;
        }
    } else {
        if (indexPath.section > 1) {
            NSDictionary *data = self.arrayContent[indexPath.section-1];
            if ([data[@"RefreshPosition"] integerValue] == 2) {
                RecommendChangeFooterView *view = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"RecommendChangeFooterView" forIndexPath:indexPath];
        if (self.dictionaryBanaer && [self.dictionaryBanaer allKeys].count != 0) {
            if (indexPath.section > 0) {
                RecpmmendTitleView *view = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"RecpmmendTitleView" forIndexPath:indexPath];
                view.delegate = self;
                view.data = data;
                view.position = indexPath.section;
                //BOOL BigPicture = [self.arrayContent[indexPath.section-1][@"HomeVideoList"][0][@"BigPicture"] boolValue];
                view.isBanaer = NO;
                view.titleName = @"热播推荐";
                return view;
            }
        } else {
            RecpmmendTitleView *view = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"RecpmmendTitleView" forIndexPath:indexPath];
            view.delegate = self;
            //BOOL BigPicture = [self.arrayContent[indexPath.section-1][@"HomeVideoList"][0][@"BigPicture"] boolValue];
            view.isBanaer = NO;
            view.titleName = @"热播推荐";
            return view;
        }
    }
    //    else {
    //        if (indexPath.section > 1) {
    //            NSDictionary *data = self.arrayContent[indexPath.section-1];
    //            if ([data[@"RefreshPosition"] integerValue] == 2) {
    //                RecommendChangeFooterView *view = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"RecommendChangeFooterView" forIndexPath:indexPath];
    //                view.delegate = self;
    //                view.data = data;
    //                view.position = indexPath.section;
    //                return view;
    //            }
    //        }
    //    }
    
    UICollectionReusableView *view = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"UICollectionReusableView" forIndexPath:indexPath];
    return view;
@@ -279,44 +292,32 @@
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
    //宽度随便定,系统会自动取collectionView的宽度
    //高度为分组头的高度
    if (section > 0) {
        BOOL BigPicture = [self.arrayContent[section-1][@"HomeVideoList"][0][@"BigPicture"] boolValue];
        if (BigPicture) {
            return CGSizeMake(KScreenW, 216 + 40 + 30);
    if (self.dictionaryBanaer && [self.dictionaryBanaer allKeys].count != 0) {
        if (section > 0) {
            return CGSizeMake(KScreenW, 47);
        }
    } else {
        return CGSizeMake(KScreenW, 47);
    }
    return CGSizeMake(0, 0);
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section {
    if (section == 0) {
        return CGSizeMake(CGFLOAT_MIN, CGFLOAT_MIN);
    }
    NSUInteger Columns = [self.arrayContent[section-1][@"RefreshPosition"] integerValue];
    if (Columns == 2) {
        return CGSizeMake(KScreenW, 41);
    } else {
        return CGSizeMake(CGFLOAT_MIN, CGFLOAT_MIN);
    }
  }
    return CGSizeMake(CGFLOAT_MIN, CGFLOAT_MIN);
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        CGFloat bannerSizeRate = [self.dictionaryBanaer[@"bannerSizeRate"] doubleValue];
        return  CGSizeMake(KScreenW, 5 + (156 * bannerSizeRate));
        return  CGSizeMake(KScreenW, 5 + 156);
        
    } else {
        NSUInteger Columns = [self.arrayContent[indexPath.section-1][@"Columns"] integerValue];
        if (Columns > 3) {
            return  CGSizeMake(KScreenW, 140);
        } else if (Columns == 2) {
            return  CGSizeMake((KScreenW - 9 - 9 - 8) / 2, 140);
        } else if (Columns == 3) {
        NSUInteger ids = [_parms[@"Id"] integerValue];
        if (ids == 150 || ids == 151 || ids == 152 ||ids == 153) {
            return  CGSizeMake((KScreenW - 9 - 9 - 6 - 6) / 3, 201);
        } else {
            return  CGSizeMake((KScreenW - 9 - 9 - 8) / 2, 140);
        }
    }
    return  CGSizeMake(KScreenW, 35);
@@ -324,16 +325,16 @@
//协议中的方法,用于返回整个CollectionView上、左、下、右距四边的间距
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
    if (section == 0) {
        return UIEdgeInsetsMake(0, 0, 0, 0);
        
    } else {
        NSUInteger Columns = [self.arrayContent[section-1][@"Columns"] integerValue];
        if (Columns == 2 || Columns == 3) {
        NSUInteger ids = [_parms[@"Id"] integerValue];
        if (ids == 150 || ids == 151 || ids == 152 ||ids == 153) {
            return UIEdgeInsetsMake(5, 9, 0, 9);
            
        } else if (Columns == 3) {
        } else {
            return UIEdgeInsetsMake(0, 9, 0, 9);
        }
    }
@@ -346,12 +347,12 @@
        return 0;
        
    } else {
        NSUInteger Columns = [self.arrayContent[section-1][@"Columns"] integerValue];
        if (Columns == 2) {
            return 12;
        } else if (Columns == 3) {
        NSUInteger ids = [_parms[@"Id"] integerValue];
        if (ids == 150 || ids == 151 || ids == 152 ||ids == 153) {
            return 10;
        } else {
            return 12;
        }
    }
    return 0;;
@@ -363,12 +364,12 @@
        return 0;
        
    } else {
        NSUInteger Columns = [self.arrayContent[section-1][@"Columns"] integerValue];
        if (Columns == 2) {
            return 8;
        } else if (Columns == 3) {
        NSUInteger ids = [_parms[@"Id"] integerValue];
        if (ids == 150 || ids == 151 || ids == 152 ||ids == 153) {
            return 6;
        } else {
            return 8;
        }
    }
    return 0;
@@ -388,18 +389,18 @@
        _collectionView.delegate = self;
        _collectionView.delaysContentTouches = NO;
        _collectionView.showsVerticalScrollIndicator = NO;
        [_collectionView registerClass:[RecommendHeaderViewCell class] forCellWithReuseIdentifier:@"RecommendHeaderViewCell"];
        [_collectionView registerClass:[ToDayHotCell class] forCellWithReuseIdentifier:@"ToDayHotCell"];
        [_collectionView registerClass:[RecommendTwoColumnCell class] forCellWithReuseIdentifier:@"RecommendTwoColumnCell"];
        [_collectionView registerClass:[RecommendThreeColumnCell class] forCellWithReuseIdentifier:@"RecommendThreeColumnCell"];
        
        [_collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"UICollectionViewCell"];
         [_collectionView registerClass:[RecpmmendTitleView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"RecpmmendTitleView"];
        [_collectionView registerClass:[RecpmmendTitleView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"RecpmmendTitleView"];
        
        [_collectionView registerClass:[RecommendChangeFooterView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"RecommendChangeFooterView"];
        
         [_collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"UICollectionReusableView"];
        [_collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"UICollectionReusableView"];
    }
    return _collectionView;
}