CNLiveSubSegmentController.m 7.32 KB
//
//  CNLiveSubSegmentController.m
//  CNLiveVideoClassifyKit
//
//  Created by CNLive on 2021/8/30.
//

#import "CNLiveSubSegmentController.h"
#import "CNCategoryGetChannelModel.h"
#import "CNLiveListManager.h"

@interface CNLiveSubSegmentController ()
@property (nonatomic, strong)JXCategoryTitleView *myCategoryView;
@property (nonatomic, strong) QMUIButton              *searchBtn;

@property (nonatomic, strong)NSArray<CNCategoryGetChannelModel*> *pageListArr;
@property (nonatomic, strong)UIColor *textColor;
@property (nonatomic, strong)NSString *backgroundColor;
@property (nonatomic, strong)NSString *backImage;
@property (nonatomic, strong)NSString *backImageH5;


@end

@implementation CNLiveSubSegmentController
-(void)dealloc
{
    
}
-(instancetype)initWithModel:(CNCategoryGetChannelModel *)model
{
    self = [super init];
    if(self){
        self.pageListArr = model.pageStyleList;
        if (!CNLiveStringIsEmpty(model.textColor)) {
            self.textColor = CNLiveColorWithHexString(model.textColor);
        }else
        {
            self.textColor = CNLiveColorWithHexString(@"#848494");
        }
        if (!CNLiveStringIsEmpty(model.backgroundColor)) {
            self.backgroundColor = model.backgroundColor;
        }else
        {
            self.backgroundColor = @"#FFFFFF";
        }
        self.backImageH5 = model.backgroundImgH5;
        self.backImage = model.backgroundImg;
        
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // 添加二级频道右侧的搜索按钮
    [self.view addSubview:self.searchBtn];
    self.view.backgroundColor = [UIColor clearColor];
    [self handleDateWithChannelsArray];
    self.myCategoryView.titles = self.titles;
    if (CNLiveStringIsEmpty(self.backImage)) {
        self.view.backgroundColor = CNLiveColorWithHexString(self.backgroundColor);
    }
    self.myCategoryView.titleColor = self.textColor;
    self.myCategoryView.titleSelectedColor = self.textColor;
    self.myCategoryView.cellSpacing = 32;
    self.myCategoryView.contentEdgeInsetLeft = 25;
    self.myCategoryView.averageCellSpacingEnabled = NO;
    self.myCategoryView.titleFont = [UIFont fontWithName:@"PingFangSC-Medium" size:14];
    JXCategoryIndicatorLineView *lineView = [[JXCategoryIndicatorLineView alloc] init];
    lineView.indicatorWidth = 18;
    lineView.indicatorColor = self.textColor;
    self.myCategoryView.indicators = @[lineView];
    [self.categoryView reloadData];
    self.listContainerView.scrollView.scrollEnabled = NO;
    // Do any additional setup after loading the view.
}
-(void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];
    self.searchBtn.right = KScreenWidth-12;
    self.searchBtn.centerY = self.myCategoryView.height/2;
    self.myCategoryView.top = 0;
    self.myCategoryView.width = self.searchBtn.left;
    self.listContainerView.frame = CGRectMake(0, [self preferredCategoryViewHeight]+10, self.view.bounds.size.width, self.view.bounds.size.height - [self preferredCategoryViewHeight]);
    
}
#pragma mark - Method
-(void)handleDateWithChannelsArray{
    [self.titles removeAllObjects];

    for (CNCategoryGetChannelModel *model in self.pageListArr) {
        [self.titles addObject:model.name];
    }
}
// 一级频道显示隐藏时二级频道右侧的搜索按钮变宽变窄控制
- (void)layoutRightSubViewWithShow:(BOOL)show {
    
    self.listContainerView.scrollView.scrollEnabled = !show;
    if (show) {
        // 正常
            
            self.searchBtn.width = 66;
            self.searchBtn.right = KScreenWidth-12;
            [self.searchBtn setTitle:@"搜索" forState:UIControlStateNormal];
            
//            if ([self.channelModel.id isEqualToString:@"219"]) {
//                self.moreBtn.right = KScreenWidth-12-66-15;
//                self.progressView.right = KScreenWidth-93-18-15;
//            } else if ([self.channelModel.id isEqualToString:@"11"]) {
//                self.historyBtn.right = KScreenWidth-93;
//            }
            
            self.myCategoryView.width = self.searchBtn.left;
    } else {
        // 变窄

            self.searchBtn.width = 30;
            self.searchBtn.right = KScreenWidth-12;
            [self.searchBtn setTitle:nil forState:UIControlStateNormal];
            
//            if ([self.channelModel.id isEqualToString:@"219"]) {
//                self.moreBtn.right = KScreenWidth-12-66-15+30;
//                self.progressView.right = KScreenWidth-93-18-15+30;
//            } else if ([self.channelModel.id isEqualToString:@"11"]) {
//                self.historyBtn.right = KScreenWidth-93+30;
//            }
            self.myCategoryView.width = self.searchBtn.left;
    }
}

#pragma mark - Public
-(JXCategoryTitleView *)preferredCategoryView{
    return [[JXCategoryTitleView alloc] init];
}
-(CGFloat)preferredCategoryViewHeight
{
    return 40;
}
#pragma mark - JXCategoryListContainerViewDelegate

-(id<JXCategoryListContentViewDelegate>)listContainerView:(JXCategoryListContainerView *)listContainerView initListForIndex:(NSInteger)index
{
    CNCategoryGetChannelModel *model = self.pageListArr[index];
    CNLiveListManager *list = [CNLiveListManager shareListManager];
    [list model:model black:_isBlack bgImage:self.backImage bgColor:self.backgroundColor bgImageH5:self.backImageH5];
    list.contentVC = self;
    weakself
    list.scrollViewDidScrollBlock = ^(BOOL isUp) {
        !weakSelf.scrollViewDidScrollBlock ?: weakSelf.scrollViewDidScrollBlock(isUp);
    };

    return list;
}
#pragma mark - JXCategoryListContentViewDelegate

/**
 实现 <JXCategoryListContentViewDelegate> 协议方法,返回该视图控制器所拥有的「视图」
 */
- (UIView *)listView {
    return self.view;
}

#pragma mark - Getting&&Setting
-(JXCategoryTitleView *)myCategoryView
{
    return (JXCategoryTitleView *)self.categoryView;
}

- (QMUIButton *)searchBtn {
    if (!_searchBtn) {
        _searchBtn = [QMUIButton buttonWithType:UIButtonTypeCustom];
        _searchBtn.frame = CGRectMake(0, 0, 66, 30);
        [_searchBtn setTitle:@"搜索" forState:UIControlStateNormal];
        _searchBtn.titleLabel.font = [UIFont systemFontOfSize:14.0];
        if (self.isBlack) {
            _searchBtn.backgroundColor = RGBA(245, 245, 245, 0.3);
            [_searchBtn setTitleColor:KGray153Color forState:UIControlStateNormal];
            [_searchBtn setImage:[UIImage loadBundleImage:@"ClassifySearchBlack"] forState:UIControlStateNormal];
        }else
        {
            _searchBtn.backgroundColor = RGBA(249, 249, 249, 0.14);
            [_searchBtn setTitleColor:kWhiteColor forState:UIControlStateNormal];
            [_searchBtn setImage:[UIImage loadBundleImage:@"ClassifySearch"] forState:UIControlStateNormal];
        }
        _searchBtn.imagePosition = QMUIButtonImagePositionLeft;
        _searchBtn.spacingBetweenImageAndTitle = 5;
        _searchBtn.layer.cornerRadius = 15;
        _searchBtn.layer.masksToBounds = YES;
        [_searchBtn addTarget:self action:@selector(searchAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _searchBtn;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end