XYVoiceLiveMainViewController.m 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. //
  2. // XYVoiceLiveMainViewController.m
  3. // Timi
  4. //
  5. // Created by 翟玉磊 on 2021/10/27.
  6. //
  7. #import "XYVoiceLiveMainViewController.h"
  8. #import "XYVoiceLiveMainNavigationView.h"
  9. #import <JXCategoryView/JXCategoryView.h>
  10. #import "JXCategoryTitleBackgroundView.h"
  11. #import "XYVoiceLiveListViewController.h"
  12. #import "XYChatRoomCategoriesModel.h"
  13. #import "XYSearchMainViewController.h"
  14. @interface XYVoiceLiveMainViewController ()<JXCategoryViewDelegate, JXCategoryListContainerViewDelegate>
  15. @property (nonatomic, strong) XYVoiceLiveMainNavigationView *customNavigationView;
  16. @property (nonatomic, strong) JXCategoryTitleBackgroundView *categoryTitleView;
  17. @property (nonatomic, strong) JXCategoryListContainerView *listContainerView;
  18. // 语音分类数组
  19. @property (nonatomic, readwrite, strong) NSArray *voiceCategoryArray;
  20. // 分类控制器数组
  21. @property (nonatomic, readwrite, strong) NSArray *categoryControllers;
  22. @property (nonatomic, strong) NSMutableArray *titles;
  23. @end
  24. @implementation XYVoiceLiveMainViewController
  25. - (instancetype)init
  26. {
  27. self = [super init];
  28. if (self) {
  29. self.prefersNavigationBarHidden = YES;
  30. }
  31. return self;
  32. }
  33. - (void)viewDidLoad {
  34. [super viewDidLoad];
  35. // Do any additional setup after loading the view.
  36. [self setupNavigationView];
  37. [self setupUI];
  38. }
  39. - (void)setupNavigationView {
  40. [self.view addSubview:self.customNavigationView];
  41. }
  42. - (void)setupUI {
  43. [self getLiveCategoryData];
  44. [self getVoiceLiveCategoryControllers];
  45. self.categoryTitleView = [[JXCategoryTitleBackgroundView alloc] initWithFrame:CGRectMake(0.0f, NAVGATION_HEIGHT, SCREEN_WIDTH, 48.0f)];
  46. self.categoryTitleView.titles = self.titles;
  47. self.categoryTitleView.delegate = self;
  48. self.categoryTitleView.titleFont = Font(14);
  49. self.categoryTitleView.titleColor = Color_Nakaguro;
  50. self.categoryTitleView.titleSelectedColor = Color_White;
  51. self.categoryTitleView.averageCellSpacingEnabled = NO;
  52. self.categoryTitleView.cellWidthIncrement = 20;
  53. self.categoryTitleView.contentEdgeInsetLeft = 10.0f;
  54. self.categoryTitleView.contentEdgeInsetRight = 10.0f;
  55. self.categoryTitleView.cellSpacing = 12;
  56. self.categoryTitleView.normalBackgroundColor = ColorFromHexString(@"#F7F7FA");
  57. self.categoryTitleView.selectedBackgroundColor = Color_TextRed;
  58. self.categoryTitleView.normalBorderColor = Color_Clear;
  59. self.categoryTitleView.selectedBorderColor = Color_Clear;
  60. self.categoryTitleView.borderLineWidth = 1;
  61. self.categoryTitleView.backgroundCornerRadius = 14;
  62. self.categoryTitleView.backgroundWidth = JXCategoryViewAutomaticDimension;
  63. self.categoryTitleView.backgroundHeight = 28;
  64. self.categoryTitleView.backgroundColor = Color_White;
  65. [self.view addSubview:self.categoryTitleView];
  66. // 列表容器
  67. self.listContainerView = [[JXCategoryListContainerView alloc] initWithType:JXCategoryListContainerType_ScrollView delegate:self];
  68. self.listContainerView.frame = CGRectMake(0, self.categoryTitleView.f_top, SCREEN_WIDTH, SCREEN_HEIGHT - self.categoryTitleView.f_top);
  69. [self.view addSubview:self.listContainerView];
  70. self.categoryTitleView.listContainer = self.listContainerView;
  71. }
  72. - (void)getLiveCategoryData {
  73. NSMutableArray *tempTitles = [NSMutableArray new];
  74. NSArray *rtcRoomCategories = [ApplicationDelegate.appConfigModel.channelConfig.singleRtcRoomCategories copy];
  75. XYChatRoomCategoriesModel *hotModel = XYChatRoomCategoriesModel.new;
  76. hotModel.categoryName = kLocalizedString(@"热门");
  77. hotModel.categoryId = @"";
  78. hotModel.chatRoom_Type = XYChatRoom_Type_Hot;
  79. hotModel.layout = XYVoiceRoomListLayoutTwoBigImage;
  80. hotModel.autoLoad = YES;
  81. [tempTitles addObject:hotModel];
  82. for (NSDictionary *dict in rtcRoomCategories) {
  83. XYChatRoomCategoriesModel *defaultModel = XYChatRoomCategoriesModel.new;
  84. [defaultModel yy_modelSetWithDictionary:dict];
  85. defaultModel.chatRoom_Type = XYChatRoom_Type_Default;
  86. defaultModel.autoLoad = YES;
  87. if (defaultModel.makeFriend) {
  88. defaultModel.chatRoom_Type = XYChatRoom_Type_Friends;
  89. }
  90. [tempTitles addObject:defaultModel];
  91. }
  92. self.voiceCategoryArray = [NSArray arrayWithArray:tempTitles];
  93. }
  94. - (void)getVoiceLiveCategoryControllers {
  95. [self.titles removeAllObjects];
  96. NSMutableArray *controllers = [NSMutableArray array];
  97. for (XYChatRoomCategoriesModel *model in self.voiceCategoryArray) {
  98. [self.titles addObject:model.categoryName];
  99. XYVoiceLiveListViewController *vc = [XYVoiceLiveListViewController new];
  100. vc.categoriesModel = model;
  101. [controllers addObject:vc];
  102. }
  103. self.categoryControllers = [NSArray arrayWithArray:controllers];
  104. }
  105. #pragma mark — JXCategoryViewDelegate
  106. /**
  107. 点击选中或者滚动选中都会调用该方法。适用于只关心选中事件,不关心具体是点击还是滚动选中的。
  108. @param categoryView categoryView对象
  109. @param index 选中的index
  110. */
  111. - (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
  112. }
  113. #pragma mark — JXCategoryListContainerViewDelegate
  114. /**
  115. 返回list的数量
  116. @param listContainerView 列表的容器视图
  117. @return list的数量
  118. */
  119. - (NSInteger)numberOfListsInlistContainerView:(JXCategoryListContainerView *)listContainerView {
  120. return self.categoryTitleView.titles.count;
  121. }
  122. /**
  123. 根据index返回一个对应列表实例,需要是遵从`JXCategoryListContentViewDelegate`协议的对象。
  124. 你可以代理方法调用的时候初始化对应列表,达到懒加载的效果。这也是默认推荐的初始化列表方法。你也可以提前创建好列表,等该代理方法回调的时候再返回也可以,达到预加载的效果。
  125. 如果列表是用自定义UIView封装的,就让自定义UIView遵从`JXCategoryListContentViewDelegate`协议,该方法返回自定义UIView即可。
  126. 如果列表是用自定义UIViewController封装的,就让自定义UIViewController遵从`JXCategoryListContentViewDelegate`协议,该方法返回自定义UIViewController即可。
  127. @param listContainerView 列表的容器视图
  128. @param index 目标下标
  129. @return 遵从JXCategoryListContentViewDelegate协议的list实例
  130. */
  131. - (id<JXCategoryListContentViewDelegate>)listContainerView:(JXCategoryListContainerView *)listContainerView initListForIndex:(NSInteger)index {
  132. if (index == 0) {
  133. // 直播-分类-热门点击量
  134. [StatisticsManager event:@"live_sort_hot_click"];
  135. }else {
  136. // 直播-直播分类-点击量
  137. [StatisticsManager event:@"live_livesort_click"];
  138. }
  139. return [self.categoryControllers objectAtIndex:index];
  140. }
  141. #pragma mark - Setter & Getter
  142. - (XYVoiceLiveMainNavigationView *)customNavigationView {
  143. if (!_customNavigationView) {
  144. _customNavigationView = [[XYVoiceLiveMainNavigationView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, NAVGATION_HEIGHT)];
  145. WeakSelf
  146. ////index 1=搜索 2=排名
  147. _customNavigationView.XYVoiceLiveMainNavigationViewActionBlock = ^(NSInteger index) {
  148. if (index == 1){
  149. XYSearchMainViewController *controller = [XYSearchMainViewController new];
  150. controller.searchType = XYSearchTypeVoiceRoom;
  151. [weakSelf.navigationController pushViewController:controller animated:NO];
  152. }else if (index == 2){
  153. BaseWebViewController *controller = [BaseWebViewController new];
  154. controller.navigationBarHeight = 0;
  155. controller.requestUrl = [NSString stringWithFormat:@"%@?roomId=0", [XYAppConfigModel getUrlRtcRank]];
  156. [weakSelf.navigationController pushViewController:controller animated:YES];
  157. }
  158. };
  159. }
  160. return _customNavigationView;
  161. }
  162. - (NSMutableArray *)titles {
  163. if (_titles == nil) {
  164. _titles = [NSMutableArray array];
  165. }
  166. return _titles;
  167. }
  168. @end