123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307 |
- //
- // XYChatRoomNewMainViewController.m
- // Starbuds
- //
- // Created by 翟玉磊 on 2020/8/19.
- // Copyright © 2020 翟玉磊. All rights reserved.
- //
- #import "XYChatRoomNewMainViewController.h"
- #import "XYChatRoomMainNavigationView.h"
- #import "MLMSegmentManager.h"
- #import "XYChatRoomMainViewController.h"
- #import "XYChatRoomCategoriesModel.h"
- #import "XYSearchMainViewController.h"
- #import "XYPublicChatHallViewController.h"
- #import "XYSearchDefaultKeywordsManager.h"
- @interface XYChatRoomNewMainViewController () <MLMSegmentHeadDelegate>
- @property (nonatomic, strong) XYChatRoomMainNavigationView *customNavigationView;
- @property (nonatomic, strong) MLMSegmentHead *segmentHead;
- @property (nonatomic, strong) MLMSegmentScroll *segmentScroll;
- // 语音分类数组
- @property (nonatomic, readwrite, strong) NSArray *voiceCategoryArray;
- @property (nonatomic, readwrite, strong) NSArray *categoryControllers;
- @end
- @implementation XYChatRoomNewMainViewController
- - (void)dealloc {
- [NotificationCenter removeObserver:self name:USER_LOGIN_STATUS_NOTIFICATION object:nil];
- }
- /// 重写init方法,配置你想要的属性
- - (instancetype)init
- {
- self = [super init];
- if (self) {
- self.prefersNavigationBarHidden = YES;
- }
- return self;
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- /// 设置
- [self _setup];
-
- /// 设置导航栏
- [self _setupNavigationItem];
-
- /// 设置子控件
- [self _setupSubViews];
-
- /// 布局子空间
- [self _makeSubViewsConstraints];
-
- [NotificationCenter addObserver:self selector:@selector(userLoginStatusChangeNotification:) name:USER_LOGIN_STATUS_NOTIFICATION object:nil];
-
- }
- - (void)userLoginStatusChangeNotification:(NSNotification *)info {
- if ([XYUserInfoManager nowUser]) {
- // 登录状态则刷新列表
- for (BaseViewController *vc in self.categoryControllers) {
- [vc base_reloadListData];
- }
- }
- }
- - (void)base_reloadListData {
- for (BaseViewController *vc in self.categoryControllers) {
- [vc base_reloadListData];
- }
- }
- /**
- * selected
- *
- * @param index index
- */
- - (void)didSelectedIndex:(NSInteger)index {
- // 派对-派对分类点击量
- [StatisticsManager event:@"party_partysort_click"];
- }
- #pragma mark - 事件处理Or辅助方法
- #pragma mark - 初始化
- - (void)_setup{
- // 获取分类数据
- [self getLiveCategoryData];
- }
- #pragma mark - 设置导航栏
- - (void)_setupNavigationItem{
- [self.view addSubview:self.customNavigationView];
- }
- #pragma mark - 设置子控件
- - (void)_setupSubViews{
- // 初始化分类列表
- [self addLiveCategoriesView];
- }
- - (void)addLiveCategoriesView {
- if (self.segmentHead) {
- [self.segmentHead removeFromSuperview];
- self.segmentHead = nil;
- }
- if (self.segmentScroll) {
- [self.segmentScroll removeFromSuperview];
- self.segmentScroll = nil;
- }
-
- NSMutableArray *titles = [NSMutableArray array];
- NSMutableArray *controllers = [NSMutableArray array];
- // for (XYChatRoomCategoriesModel *model in self.voiceCategoryArray) {
- // [titles addObject:model.categoryName];
- // if (controllers.count == 0) {
- // XYPublicChatHallViewController *vc = XYPublicChatHallViewController.new;
- // [controllers addObject:vc];
- // }else {
- // XYChatRoomMainViewController *vc = XYChatRoomMainViewController.new;
- // [controllers addObject:vc];
- // }
- // }
-
- if (self.chatRoomType == 1) {//tab首页
- XYPublicChatHallViewController *vc = XYPublicChatHallViewController.new;
- [controllers addObject:vc];
-
- }else if (self.chatRoomType == 2){//tab派对
- XYChatRoomMainViewController *vc = XYChatRoomMainViewController.new;
- [controllers addObject:vc];
- }
-
- self.categoryControllers = [NSArray arrayWithArray:controllers];
-
- if (_segmentHead == nil) {
- _segmentHead = [[MLMSegmentHead alloc] initWithFrame:CGRectMake(10.0f, STATUS_HEIGHT, SCREEN_WIDTH - 20.0f - 200.0f, 44.0f) titles:titles headStyle:SegmentHeadStyleLine layoutStyle:MLMSegmentLayoutLeft];
- _segmentHead.headColor = Color_Clear;
- _segmentHead.fontSize = 18;
- _segmentHead.selectColor = Color_TextFont;
- _segmentHead.deSelectColor = Color_TextGray;
- if (self.voiceCategoryArray.count == 1) {
- _segmentHead.lineWidth = 8;
- _segmentHead.lineHeight = 4;
- _segmentHead.lineColor = Color_Clear;
- }else {
- _segmentHead.lineWidth = 8;
- _segmentHead.lineHeight = 4;
- _segmentHead.lineColor = Color_TextRed;
- }
- _segmentHead.isNearLine = NO;
- _segmentHead.singleW_Add = 10.0f;
-
- _segmentHead.equalSize = NO;
- _segmentHead.bottomLineHeight = 0;
- // 默认显示推荐模块
- _segmentHead.showIndex = 0;
- _segmentHead.delegate = self;
- _segmentHead.hidden = YES;
- }
- if (_segmentScroll == nil) {
- _segmentScroll = [[MLMSegmentScroll alloc] initWithFrame:CGRectMake(0, self.customNavigationView.f_top, SCREEN_WIDTH, SCREEN_HEIGHT- NAVGATION_HEIGHT) vcOrViews:controllers];
- _segmentScroll.backgroundColor = Color_Clear;
- }
-
- [MLMSegmentManager associateHead:_segmentHead withScroll:_segmentScroll completion:^{
- [self.customNavigationView addSubview:self.segmentHead];
- [self.view addSubview:self.segmentScroll];
- }];
-
- [self reloadLeftBtnAndSegmentScroll:0];
- }
- - (void)selectItemType:(XYPublicChatHallViewType )type{
- for (UIViewController *vc in self.categoryControllers) {
- if ([vc isKindOfClass:[XYChatRoomMainViewController class]]) {
- XYChatRoomMainViewController *tempVc = (XYChatRoomMainViewController *)vc;
- [tempVc selectItemType:type];
- }
- }
- }
- - (void)getLiveCategoryData {
-
- NSMutableArray *tempTitles = [NSMutableArray new];
- XYChatRoomCategoriesModel *collectModel = XYChatRoomCategoriesModel.new;
- collectModel.categoryName = kLocalizedString(@"公聊大厅");
- collectModel.categoryId = @"";
- collectModel.chatRoom_Type = XYChatRoom_Type_Collect;
- collectModel.layout = XYVoiceRoomListLayoutOneGraphic;
- collectModel.makeFriend = NO;
- [tempTitles addObject:collectModel];
-
- XYChatRoomCategoriesModel *friendModel = XYChatRoomCategoriesModel.new;
- friendModel.categoryName = kLocalizedString(@"聊天室");
- friendModel.categoryId = @"";
- friendModel.chatRoom_Type = XYChatRoom_Type_Friends;
- friendModel.layout = XYVoiceRoomListLayoutOneGraphic;
- friendModel.makeFriend = YES;
- [tempTitles addObject:friendModel];
-
- self.voiceCategoryArray = [NSArray arrayWithArray:tempTitles];
- }
- - (void)reloadLeftBtnAndSegmentScroll:(NSInteger )index{
- [self.segmentHead changeIndex:index completion:YES];
- [self.customNavigationView reloadLeftBtn:index];
- }
- #pragma mark - 布局子控件
- - (void)_makeSubViewsConstraints{
-
- }
- #pragma mark - Setter & Getter
- - (XYChatRoomMainNavigationView *)customNavigationView {
- if (!_customNavigationView) {
- _customNavigationView = [[XYChatRoomMainNavigationView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, NAVGATION_HEIGHT)];
- _customNavigationView.hidden = YES; _customNavigationView.alpha = 0;
- [_customNavigationView setupDefaultKeywords:[XYSearchDefaultKeywordsManager sharedInstance].defaultKeyword];
- WeakSelf
- ////index 1=大厅 2=聊天室 3=搜索 4=排名
- _customNavigationView.XYChatRoomMainNavigationViewActionBlock = ^(NSInteger index) {
- if (index == 1) {
- [weakSelf reloadLeftBtnAndSegmentScroll:0];
-
- }else if (index == 2){
- [weakSelf reloadLeftBtnAndSegmentScroll:1];
-
- }else if (index == 3){
- XYSearchMainViewController *controller = [XYSearchMainViewController new];
- controller.searchType = XYSearchTypeVoiceRoom;
- [weakSelf.navigationController pushViewController:controller animated:NO];
-
- }else if (index == 4){
- BaseWebViewController *controller = [BaseWebViewController new];
- controller.navigationBarHeight = 0;
- controller.requestUrl = [NSString stringWithFormat:@"%@?roomId=0", [XYAppConfigModel getUrlRtcRank]];
- [weakSelf.navigationController pushViewController:controller animated:YES];
-
- }
- };
-
- UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, NAVGATION_HEIGHT)];
- contentView.backgroundColor = [UIColor clearColor];
- [self.view addSubview:contentView];
-
- UILabel *partyLab = [[UILabel alloc] init];
- partyLab.text = @"派对";
- partyLab.textAlignment = NSTextAlignmentCenter;
- partyLab.textColor = [UIColor colorWithHexString:@"#3E3752" alpha:1];
- partyLab.font = [UIFont fontWithName:kPFSCMediumFont size:22];
- [partyLab sizeToFit];
- [contentView addSubview:partyLab];
- [partyLab mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(contentView.mas_left).offset(16);
- make.top.equalTo(contentView.mas_top).offset(21+kiPhoneXTopEdge);
- }];
-
-
- UIButton *searchBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [searchBtn setImage:[UIImage imageNamed:@"icon_partynav_search"] forState:UIControlStateNormal];
- [searchBtn addTarget:self action:@selector(searchBtnAction) forControlEvents:UIControlEventTouchUpInside];
- [contentView addSubview:searchBtn];
- [searchBtn mas_makeConstraints:^(MASConstraintMaker *make) {;
- make.centerY.equalTo(partyLab.mas_centerY).offset(0);
- make.right.equalTo(contentView.mas_right).offset(-56);
- make.width.offset(24);
- make.height.offset(24);
- }];
-
- UIButton *rankBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [rankBtn setImage:[UIImage imageNamed:@"icon_partynav_rank"] forState:UIControlStateNormal];
- [rankBtn addTarget:self action:@selector(rankBtnAction) forControlEvents:UIControlEventTouchUpInside];
- [contentView addSubview:rankBtn];
- [rankBtn mas_makeConstraints:^(MASConstraintMaker *make) {;
- make.centerY.equalTo(partyLab.mas_centerY).offset(0);
- make.right.equalTo(contentView.mas_right).offset(-16);
- make.width.offset(24);
- make.height.offset(24);
- }];
-
- }
- return _customNavigationView;
- }
- - (void)searchBtnAction{
- XYSearchMainViewController *controller = [XYSearchMainViewController new];
- controller.searchType = XYSearchTypeVoiceRoom;
- [self.navigationController pushViewController:controller animated:NO];
- }
- - (void)rankBtnAction{
- BaseWebViewController *controller = [BaseWebViewController new];
- controller.navigationBarHeight = 0;
- controller.requestUrl = [NSString stringWithFormat:@"%@?roomId=0", [XYAppConfigModel getUrlRtcRank]];
- [self.navigationController pushViewController:controller animated:YES];
- }
- @end
|