XYChatRoomNewMainViewController.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. //
  2. // XYChatRoomNewMainViewController.m
  3. // Starbuds
  4. //
  5. // Created by 翟玉磊 on 2020/8/19.
  6. // Copyright © 2020 翟玉磊. All rights reserved.
  7. //
  8. #import "XYChatRoomNewMainViewController.h"
  9. #import "XYChatRoomMainNavigationView.h"
  10. #import "MLMSegmentManager.h"
  11. #import "XYChatRoomMainViewController.h"
  12. #import "XYChatRoomCategoriesModel.h"
  13. #import "XYSearchMainViewController.h"
  14. #import "XYPublicChatHallViewController.h"
  15. #import "XYSearchDefaultKeywordsManager.h"
  16. @interface XYChatRoomNewMainViewController () <MLMSegmentHeadDelegate>
  17. @property (nonatomic, strong) XYChatRoomMainNavigationView *customNavigationView;
  18. @property (nonatomic, strong) MLMSegmentHead *segmentHead;
  19. @property (nonatomic, strong) MLMSegmentScroll *segmentScroll;
  20. // 语音分类数组
  21. @property (nonatomic, readwrite, strong) NSArray *voiceCategoryArray;
  22. @property (nonatomic, readwrite, strong) NSArray *categoryControllers;
  23. @end
  24. @implementation XYChatRoomNewMainViewController
  25. - (void)dealloc {
  26. [NotificationCenter removeObserver:self name:USER_LOGIN_STATUS_NOTIFICATION object:nil];
  27. }
  28. /// 重写init方法,配置你想要的属性
  29. - (instancetype)init
  30. {
  31. self = [super init];
  32. if (self) {
  33. self.prefersNavigationBarHidden = YES;
  34. }
  35. return self;
  36. }
  37. - (void)viewDidLoad {
  38. [super viewDidLoad];
  39. /// 设置
  40. [self _setup];
  41. /// 设置导航栏
  42. [self _setupNavigationItem];
  43. /// 设置子控件
  44. [self _setupSubViews];
  45. /// 布局子空间
  46. [self _makeSubViewsConstraints];
  47. [NotificationCenter addObserver:self selector:@selector(userLoginStatusChangeNotification:) name:USER_LOGIN_STATUS_NOTIFICATION object:nil];
  48. }
  49. - (void)userLoginStatusChangeNotification:(NSNotification *)info {
  50. if ([XYUserInfoManager nowUser]) {
  51. // 登录状态则刷新列表
  52. for (BaseViewController *vc in self.categoryControllers) {
  53. [vc base_reloadListData];
  54. }
  55. }
  56. }
  57. - (void)base_reloadListData {
  58. for (BaseViewController *vc in self.categoryControllers) {
  59. [vc base_reloadListData];
  60. }
  61. }
  62. /**
  63. * selected
  64. *
  65. * @param index index
  66. */
  67. - (void)didSelectedIndex:(NSInteger)index {
  68. // 派对-派对分类点击量
  69. [StatisticsManager event:@"party_partysort_click"];
  70. }
  71. #pragma mark - 事件处理Or辅助方法
  72. #pragma mark - 初始化
  73. - (void)_setup{
  74. // 获取分类数据
  75. [self getLiveCategoryData];
  76. }
  77. #pragma mark - 设置导航栏
  78. - (void)_setupNavigationItem{
  79. [self.view addSubview:self.customNavigationView];
  80. }
  81. #pragma mark - 设置子控件
  82. - (void)_setupSubViews{
  83. // 初始化分类列表
  84. [self addLiveCategoriesView];
  85. }
  86. - (void)addLiveCategoriesView {
  87. if (self.segmentHead) {
  88. [self.segmentHead removeFromSuperview];
  89. self.segmentHead = nil;
  90. }
  91. if (self.segmentScroll) {
  92. [self.segmentScroll removeFromSuperview];
  93. self.segmentScroll = nil;
  94. }
  95. NSMutableArray *titles = [NSMutableArray array];
  96. NSMutableArray *controllers = [NSMutableArray array];
  97. // for (XYChatRoomCategoriesModel *model in self.voiceCategoryArray) {
  98. // [titles addObject:model.categoryName];
  99. // if (controllers.count == 0) {
  100. // XYPublicChatHallViewController *vc = XYPublicChatHallViewController.new;
  101. // [controllers addObject:vc];
  102. // }else {
  103. // XYChatRoomMainViewController *vc = XYChatRoomMainViewController.new;
  104. // [controllers addObject:vc];
  105. // }
  106. // }
  107. if (self.chatRoomType == 1) {//tab首页
  108. XYPublicChatHallViewController *vc = XYPublicChatHallViewController.new;
  109. [controllers addObject:vc];
  110. }else if (self.chatRoomType == 2){//tab派对
  111. XYChatRoomMainViewController *vc = XYChatRoomMainViewController.new;
  112. [controllers addObject:vc];
  113. }
  114. self.categoryControllers = [NSArray arrayWithArray:controllers];
  115. if (_segmentHead == nil) {
  116. _segmentHead = [[MLMSegmentHead alloc] initWithFrame:CGRectMake(10.0f, STATUS_HEIGHT, SCREEN_WIDTH - 20.0f - 200.0f, 44.0f) titles:titles headStyle:SegmentHeadStyleLine layoutStyle:MLMSegmentLayoutLeft];
  117. _segmentHead.headColor = Color_Clear;
  118. _segmentHead.fontSize = 18;
  119. _segmentHead.selectColor = Color_TextFont;
  120. _segmentHead.deSelectColor = Color_TextGray;
  121. if (self.voiceCategoryArray.count == 1) {
  122. _segmentHead.lineWidth = 8;
  123. _segmentHead.lineHeight = 4;
  124. _segmentHead.lineColor = Color_Clear;
  125. }else {
  126. _segmentHead.lineWidth = 8;
  127. _segmentHead.lineHeight = 4;
  128. _segmentHead.lineColor = Color_TextRed;
  129. }
  130. _segmentHead.isNearLine = NO;
  131. _segmentHead.singleW_Add = 10.0f;
  132. _segmentHead.equalSize = NO;
  133. _segmentHead.bottomLineHeight = 0;
  134. // 默认显示推荐模块
  135. _segmentHead.showIndex = 0;
  136. _segmentHead.delegate = self;
  137. _segmentHead.hidden = YES;
  138. }
  139. if (_segmentScroll == nil) {
  140. _segmentScroll = [[MLMSegmentScroll alloc] initWithFrame:CGRectMake(0, self.customNavigationView.f_top, SCREEN_WIDTH, SCREEN_HEIGHT- NAVGATION_HEIGHT) vcOrViews:controllers];
  141. _segmentScroll.backgroundColor = Color_Clear;
  142. }
  143. [MLMSegmentManager associateHead:_segmentHead withScroll:_segmentScroll completion:^{
  144. [self.customNavigationView addSubview:self.segmentHead];
  145. [self.view addSubview:self.segmentScroll];
  146. }];
  147. [self reloadLeftBtnAndSegmentScroll:0];
  148. }
  149. - (void)selectItemType:(XYPublicChatHallViewType )type{
  150. for (UIViewController *vc in self.categoryControllers) {
  151. if ([vc isKindOfClass:[XYChatRoomMainViewController class]]) {
  152. XYChatRoomMainViewController *tempVc = (XYChatRoomMainViewController *)vc;
  153. [tempVc selectItemType:type];
  154. }
  155. }
  156. }
  157. - (void)getLiveCategoryData {
  158. NSMutableArray *tempTitles = [NSMutableArray new];
  159. XYChatRoomCategoriesModel *collectModel = XYChatRoomCategoriesModel.new;
  160. collectModel.categoryName = kLocalizedString(@"公聊大厅");
  161. collectModel.categoryId = @"";
  162. collectModel.chatRoom_Type = XYChatRoom_Type_Collect;
  163. collectModel.layout = XYVoiceRoomListLayoutOneGraphic;
  164. collectModel.makeFriend = NO;
  165. [tempTitles addObject:collectModel];
  166. XYChatRoomCategoriesModel *friendModel = XYChatRoomCategoriesModel.new;
  167. friendModel.categoryName = kLocalizedString(@"聊天室");
  168. friendModel.categoryId = @"";
  169. friendModel.chatRoom_Type = XYChatRoom_Type_Friends;
  170. friendModel.layout = XYVoiceRoomListLayoutOneGraphic;
  171. friendModel.makeFriend = YES;
  172. [tempTitles addObject:friendModel];
  173. self.voiceCategoryArray = [NSArray arrayWithArray:tempTitles];
  174. }
  175. - (void)reloadLeftBtnAndSegmentScroll:(NSInteger )index{
  176. [self.segmentHead changeIndex:index completion:YES];
  177. [self.customNavigationView reloadLeftBtn:index];
  178. }
  179. #pragma mark - 布局子控件
  180. - (void)_makeSubViewsConstraints{
  181. }
  182. #pragma mark - Setter & Getter
  183. - (XYChatRoomMainNavigationView *)customNavigationView {
  184. if (!_customNavigationView) {
  185. _customNavigationView = [[XYChatRoomMainNavigationView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, NAVGATION_HEIGHT)];
  186. _customNavigationView.hidden = YES; _customNavigationView.alpha = 0;
  187. [_customNavigationView setupDefaultKeywords:[XYSearchDefaultKeywordsManager sharedInstance].defaultKeyword];
  188. WeakSelf
  189. ////index 1=大厅 2=聊天室 3=搜索 4=排名
  190. _customNavigationView.XYChatRoomMainNavigationViewActionBlock = ^(NSInteger index) {
  191. if (index == 1) {
  192. [weakSelf reloadLeftBtnAndSegmentScroll:0];
  193. }else if (index == 2){
  194. [weakSelf reloadLeftBtnAndSegmentScroll:1];
  195. }else if (index == 3){
  196. XYSearchMainViewController *controller = [XYSearchMainViewController new];
  197. controller.searchType = XYSearchTypeVoiceRoom;
  198. [weakSelf.navigationController pushViewController:controller animated:NO];
  199. }else if (index == 4){
  200. BaseWebViewController *controller = [BaseWebViewController new];
  201. controller.navigationBarHeight = 0;
  202. controller.requestUrl = [NSString stringWithFormat:@"%@?roomId=0", [XYAppConfigModel getUrlRtcRank]];
  203. [weakSelf.navigationController pushViewController:controller animated:YES];
  204. }
  205. };
  206. UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, NAVGATION_HEIGHT)];
  207. contentView.backgroundColor = [UIColor clearColor];
  208. [self.view addSubview:contentView];
  209. UILabel *partyLab = [[UILabel alloc] init];
  210. partyLab.text = @"派对";
  211. partyLab.textAlignment = NSTextAlignmentCenter;
  212. partyLab.textColor = [UIColor colorWithHexString:@"#3E3752" alpha:1];
  213. partyLab.font = [UIFont fontWithName:kPFSCMediumFont size:22];
  214. [partyLab sizeToFit];
  215. [contentView addSubview:partyLab];
  216. [partyLab mas_makeConstraints:^(MASConstraintMaker *make) {
  217. make.left.equalTo(contentView.mas_left).offset(16);
  218. make.top.equalTo(contentView.mas_top).offset(21+kiPhoneXTopEdge);
  219. }];
  220. UIButton *searchBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  221. [searchBtn setImage:[UIImage imageNamed:@"icon_partynav_search"] forState:UIControlStateNormal];
  222. [searchBtn addTarget:self action:@selector(searchBtnAction) forControlEvents:UIControlEventTouchUpInside];
  223. [contentView addSubview:searchBtn];
  224. [searchBtn mas_makeConstraints:^(MASConstraintMaker *make) {;
  225. make.centerY.equalTo(partyLab.mas_centerY).offset(0);
  226. make.right.equalTo(contentView.mas_right).offset(-56);
  227. make.width.offset(24);
  228. make.height.offset(24);
  229. }];
  230. UIButton *rankBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  231. [rankBtn setImage:[UIImage imageNamed:@"icon_partynav_rank"] forState:UIControlStateNormal];
  232. [rankBtn addTarget:self action:@selector(rankBtnAction) forControlEvents:UIControlEventTouchUpInside];
  233. [contentView addSubview:rankBtn];
  234. [rankBtn mas_makeConstraints:^(MASConstraintMaker *make) {;
  235. make.centerY.equalTo(partyLab.mas_centerY).offset(0);
  236. make.right.equalTo(contentView.mas_right).offset(-16);
  237. make.width.offset(24);
  238. make.height.offset(24);
  239. }];
  240. }
  241. return _customNavigationView;
  242. }
  243. - (void)searchBtnAction{
  244. XYSearchMainViewController *controller = [XYSearchMainViewController new];
  245. controller.searchType = XYSearchTypeVoiceRoom;
  246. [self.navigationController pushViewController:controller animated:NO];
  247. }
  248. - (void)rankBtnAction{
  249. BaseWebViewController *controller = [BaseWebViewController new];
  250. controller.navigationBarHeight = 0;
  251. controller.requestUrl = [NSString stringWithFormat:@"%@?roomId=0", [XYAppConfigModel getUrlRtcRank]];
  252. [self.navigationController pushViewController:controller animated:YES];
  253. }
  254. @end