123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- //
- // XYVoiceLiveMainViewController.m
- // Timi
- //
- // Created by 翟玉磊 on 2021/10/27.
- //
- #import "XYVoiceLiveMainViewController.h"
- #import "XYVoiceLiveMainNavigationView.h"
- #import <JXCategoryView/JXCategoryView.h>
- #import "JXCategoryTitleBackgroundView.h"
- #import "XYVoiceLiveListViewController.h"
- #import "XYChatRoomCategoriesModel.h"
- #import "XYSearchMainViewController.h"
- @interface XYVoiceLiveMainViewController ()<JXCategoryViewDelegate, JXCategoryListContainerViewDelegate>
- @property (nonatomic, strong) XYVoiceLiveMainNavigationView *customNavigationView;
- @property (nonatomic, strong) JXCategoryTitleBackgroundView *categoryTitleView;
- @property (nonatomic, strong) JXCategoryListContainerView *listContainerView;
- // 语音分类数组
- @property (nonatomic, readwrite, strong) NSArray *voiceCategoryArray;
- // 分类控制器数组
- @property (nonatomic, readwrite, strong) NSArray *categoryControllers;
- @property (nonatomic, strong) NSMutableArray *titles;
- @end
- @implementation XYVoiceLiveMainViewController
- - (instancetype)init
- {
- self = [super init];
- if (self) {
- self.prefersNavigationBarHidden = YES;
- }
- return self;
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
-
- [self setupNavigationView];
- [self setupUI];
- }
- - (void)setupNavigationView {
- [self.view addSubview:self.customNavigationView];
- }
- - (void)setupUI {
-
- [self getLiveCategoryData];
- [self getVoiceLiveCategoryControllers];
-
- self.categoryTitleView = [[JXCategoryTitleBackgroundView alloc] initWithFrame:CGRectMake(0.0f, NAVGATION_HEIGHT, SCREEN_WIDTH, 48.0f)];
- self.categoryTitleView.titles = self.titles;
- self.categoryTitleView.delegate = self;
- self.categoryTitleView.titleFont = Font(14);
- self.categoryTitleView.titleColor = Color_Nakaguro;
- self.categoryTitleView.titleSelectedColor = Color_White;
- self.categoryTitleView.averageCellSpacingEnabled = NO;
- self.categoryTitleView.cellWidthIncrement = 20;
- self.categoryTitleView.contentEdgeInsetLeft = 10.0f;
- self.categoryTitleView.contentEdgeInsetRight = 10.0f;
- self.categoryTitleView.cellSpacing = 12;
-
- self.categoryTitleView.normalBackgroundColor = ColorFromHexString(@"#F7F7FA");
- self.categoryTitleView.selectedBackgroundColor = Color_TextRed;
- self.categoryTitleView.normalBorderColor = Color_Clear;
- self.categoryTitleView.selectedBorderColor = Color_Clear;
- self.categoryTitleView.borderLineWidth = 1;
- self.categoryTitleView.backgroundCornerRadius = 14;
- self.categoryTitleView.backgroundWidth = JXCategoryViewAutomaticDimension;
- self.categoryTitleView.backgroundHeight = 28;
- self.categoryTitleView.backgroundColor = Color_White;
-
- [self.view addSubview:self.categoryTitleView];
-
- // 列表容器
- self.listContainerView = [[JXCategoryListContainerView alloc] initWithType:JXCategoryListContainerType_ScrollView delegate:self];
- self.listContainerView.frame = CGRectMake(0, self.categoryTitleView.f_top, SCREEN_WIDTH, SCREEN_HEIGHT - self.categoryTitleView.f_top);
- [self.view addSubview:self.listContainerView];
- self.categoryTitleView.listContainer = self.listContainerView;
-
- }
- - (void)getLiveCategoryData {
-
- NSMutableArray *tempTitles = [NSMutableArray new];
- NSArray *rtcRoomCategories = [ApplicationDelegate.appConfigModel.channelConfig.singleRtcRoomCategories copy];
-
- XYChatRoomCategoriesModel *hotModel = XYChatRoomCategoriesModel.new;
- hotModel.categoryName = kLocalizedString(@"热门");
- hotModel.categoryId = @"";
- hotModel.chatRoom_Type = XYChatRoom_Type_Hot;
- hotModel.layout = XYVoiceRoomListLayoutTwoBigImage;
- hotModel.autoLoad = YES;
- [tempTitles addObject:hotModel];
-
- for (NSDictionary *dict in rtcRoomCategories) {
- XYChatRoomCategoriesModel *defaultModel = XYChatRoomCategoriesModel.new;
- [defaultModel yy_modelSetWithDictionary:dict];
- defaultModel.chatRoom_Type = XYChatRoom_Type_Default;
- defaultModel.autoLoad = YES;
- if (defaultModel.makeFriend) {
- defaultModel.chatRoom_Type = XYChatRoom_Type_Friends;
- }
- [tempTitles addObject:defaultModel];
- }
-
- self.voiceCategoryArray = [NSArray arrayWithArray:tempTitles];
- }
- - (void)getVoiceLiveCategoryControllers {
- [self.titles removeAllObjects];
- NSMutableArray *controllers = [NSMutableArray array];
- for (XYChatRoomCategoriesModel *model in self.voiceCategoryArray) {
- [self.titles addObject:model.categoryName];
- XYVoiceLiveListViewController *vc = [XYVoiceLiveListViewController new];
- vc.categoriesModel = model;
- [controllers addObject:vc];
- }
-
- self.categoryControllers = [NSArray arrayWithArray:controllers];
- }
- #pragma mark — JXCategoryViewDelegate
- /**
- 点击选中或者滚动选中都会调用该方法。适用于只关心选中事件,不关心具体是点击还是滚动选中的。
- @param categoryView categoryView对象
- @param index 选中的index
- */
- - (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
-
- }
- #pragma mark — JXCategoryListContainerViewDelegate
- /**
- 返回list的数量
- @param listContainerView 列表的容器视图
- @return list的数量
- */
- - (NSInteger)numberOfListsInlistContainerView:(JXCategoryListContainerView *)listContainerView {
- return self.categoryTitleView.titles.count;
- }
- /**
- 根据index返回一个对应列表实例,需要是遵从`JXCategoryListContentViewDelegate`协议的对象。
- 你可以代理方法调用的时候初始化对应列表,达到懒加载的效果。这也是默认推荐的初始化列表方法。你也可以提前创建好列表,等该代理方法回调的时候再返回也可以,达到预加载的效果。
- 如果列表是用自定义UIView封装的,就让自定义UIView遵从`JXCategoryListContentViewDelegate`协议,该方法返回自定义UIView即可。
- 如果列表是用自定义UIViewController封装的,就让自定义UIViewController遵从`JXCategoryListContentViewDelegate`协议,该方法返回自定义UIViewController即可。
- @param listContainerView 列表的容器视图
- @param index 目标下标
- @return 遵从JXCategoryListContentViewDelegate协议的list实例
- */
- - (id<JXCategoryListContentViewDelegate>)listContainerView:(JXCategoryListContainerView *)listContainerView initListForIndex:(NSInteger)index {
-
- if (index == 0) {
- // 直播-分类-热门点击量
- [StatisticsManager event:@"live_sort_hot_click"];
- }else {
- // 直播-直播分类-点击量
- [StatisticsManager event:@"live_livesort_click"];
- }
- return [self.categoryControllers objectAtIndex:index];
- }
- #pragma mark - Setter & Getter
- - (XYVoiceLiveMainNavigationView *)customNavigationView {
- if (!_customNavigationView) {
- _customNavigationView = [[XYVoiceLiveMainNavigationView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, NAVGATION_HEIGHT)];
- WeakSelf
- ////index 1=搜索 2=排名
- _customNavigationView.XYVoiceLiveMainNavigationViewActionBlock = ^(NSInteger index) {
- if (index == 1){
-
- XYSearchMainViewController *controller = [XYSearchMainViewController new];
- controller.searchType = XYSearchTypeVoiceRoom;
- [weakSelf.navigationController pushViewController:controller animated:NO];
-
- }else if (index == 2){
-
- BaseWebViewController *controller = [BaseWebViewController new];
- controller.navigationBarHeight = 0;
- controller.requestUrl = [NSString stringWithFormat:@"%@?roomId=0", [XYAppConfigModel getUrlRtcRank]];
- [weakSelf.navigationController pushViewController:controller animated:YES];
- }
- };
- }
- return _customNavigationView;
- }
- - (NSMutableArray *)titles {
- if (_titles == nil) {
- _titles = [NSMutableArray array];
- }
- return _titles;
- }
- @end
|