307 lines
11 KiB
Objective-C
307 lines
11 KiB
Objective-C
//
|
|
// XPHomeLivesViewController.m
|
|
// xplan-ios
|
|
//
|
|
// Created by GreenLand on 2022/7/15.
|
|
//
|
|
|
|
#import "XPHomeLivesViewController.h"
|
|
///Third
|
|
#import <Masonry/Masonry.h>
|
|
#import <JXCategoryView/JXCategoryView.h>
|
|
#import <JXCategoryView/JXCategoryIndicatorBackgroundView.h>
|
|
#import <JXCategoryView/JXCategoryListContainerView.h>
|
|
#import <JXPagingView/JXPagerView.h>
|
|
#import <MJRefresh/MJRefresh.h>
|
|
///Tool
|
|
#import "XPMacro.h"
|
|
#import "ThemeColor.h"
|
|
#import "XPHtmlUrl.h"
|
|
#import "StatisticsServiceHelper.h"
|
|
#import "XPWeakTimer.h"
|
|
#import "NSMutableDictionary+Saft.h"
|
|
///Model
|
|
#import "HomeLiveTagModel.h"
|
|
#import "HomeLiveLookRecordModel.h"
|
|
#import "HomeRecommendRoomModel.h"
|
|
///View
|
|
#import "XPRoomSearchContainerViewController.h"
|
|
#import "XPHomePartyViewController.h"
|
|
#import "XPWebViewController.h"
|
|
#import "XPHomeLikeViewController.h"
|
|
#import "XPHomeLittleGameViewController.h"
|
|
#import "XPHomeLiveHeadView.h"
|
|
#import "XPHomeHappyViewController.h"
|
|
#import "XPHomeLivePageViewController.h"
|
|
#import "XPMineUserInfoViewController.h"
|
|
#import "XPRoomViewController.h"
|
|
///P
|
|
#import "XPHomeLivePresenter.h"
|
|
#import "XPHomeLiveProtocol.h"
|
|
|
|
@interface XPHomeLivesViewController ()<JXCategoryViewDelegate, JXPagerViewDelegate, JXPagerMainTableViewGestureDelegate, XPHomeLiveProtocol, XPHomeLiveHeadViewDelegate>
|
|
{
|
|
NSTimer * timer;
|
|
}
|
|
|
|
@property (nonatomic,strong) UIView *customNavigationBar;
|
|
@property (nonatomic,strong) UILabel *titleLabel;
|
|
|
|
///分页标题
|
|
@property (nonatomic, strong) NSArray<NSString *> *titles;
|
|
@property (nonatomic, strong) JXPagerView *pagingView;
|
|
///分页控件
|
|
@property (nonatomic, strong) JXCategoryTitleView *titleView;
|
|
///分页lineView
|
|
@property (nonatomic, strong) JXCategoryListContainerView *contentView;
|
|
///tag的列表
|
|
@property (nonatomic,copy) NSArray<HomeLiveTagModel *> *tagList;
|
|
///头部浏览记录
|
|
@property (nonatomic, strong) XPHomeLiveHeadView *headerView;
|
|
///浏览记录房间列表
|
|
@property (nonatomic, strong) NSArray<HomeRecommendRoomModel *> *roomList;
|
|
|
|
@end
|
|
|
|
@implementation XPHomeLivesViewController
|
|
|
|
- (XPHomeLivePresenter *)createPresenter {
|
|
return [[XPHomeLivePresenter alloc] init];
|
|
}
|
|
|
|
- (BOOL)isHiddenNavBar {
|
|
return YES;
|
|
}
|
|
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
[self initHeaderAndFooterRrfresh];
|
|
[self initSubViews];
|
|
[self addTimer];
|
|
if (!self.noTabbarVc) {
|
|
self.view.backgroundColor = [ThemeColor appBackgroundColor];
|
|
}
|
|
}
|
|
|
|
- (void)viewDidLayoutSubviews {
|
|
[super viewDidLayoutSubviews];
|
|
if (!self.noTabbarVc) {
|
|
self.pagingView.frame = CGRectMake(0, kNavigationHeight, KScreenWidth, KScreenHeight - kNavigationHeight);
|
|
} else {
|
|
self.pagingView.frame = self.view.bounds;
|
|
}
|
|
}
|
|
|
|
- (void)viewWillAppear:(BOOL)animated {
|
|
[super viewWillAppear:animated];
|
|
if (timer) {
|
|
[timer setFireDate:[NSDate distantPast]]; //很远的过去
|
|
}
|
|
}
|
|
|
|
- (void)viewWillDisappear:(BOOL)animated {
|
|
[super viewWillDisappear:animated];
|
|
if (timer) {
|
|
//关闭定时器
|
|
[timer setFireDate:[NSDate distantFuture]]; //很远的将来
|
|
}
|
|
}
|
|
|
|
- (void)addTimer {
|
|
timer = [XPWeakTimer scheduledTimerWithTimeInterval:15 block:^(id userInfo) {
|
|
[self headerRefresh];
|
|
} userInfo:nil repeats:YES];
|
|
}
|
|
|
|
#pragma mark - InitHttp
|
|
- (void)headerRefresh {
|
|
[self.presenter getOnceLookRoom];
|
|
[self.presenter getHomeLiveTagList];
|
|
}
|
|
|
|
- (void)initHeaderAndFooterRrfresh {
|
|
MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(headerRefresh)];
|
|
header.stateLabel.font = [UIFont systemFontOfSize:10.0];
|
|
header.lastUpdatedTimeLabel.font = [UIFont systemFontOfSize:10.0];
|
|
header.stateLabel.textColor = [ThemeColor secondTextColor];
|
|
header.lastUpdatedTimeLabel.textColor = [ThemeColor secondTextColor];
|
|
self.pagingView.mainTableView.mj_header = header;
|
|
}
|
|
|
|
#pragma mark - Private Method
|
|
- (void)initSubViews {
|
|
self.view.backgroundColor = [UIColor clearColor];
|
|
if (!self.noTabbarVc) {
|
|
[self.view addSubview:self.customNavigationBar];
|
|
[self.customNavigationBar addSubview:self.titleLabel];
|
|
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.center.mas_equalTo(self.customNavigationBar);
|
|
}];
|
|
}
|
|
[self.view addSubview:self.pagingView];
|
|
}
|
|
|
|
#pragma mark - XPHomeRecommendProtocol
|
|
- (void)getOnceLookRoomListSuccess:(HomeLiveLookRecordModel *)data {
|
|
self.headerView.hadHistoryRecord = data.onceLookStatus;
|
|
self.headerView.roomList = [NSMutableArray arrayWithArray:data.singleRoomList];
|
|
self.roomList = data.singleRoomList;
|
|
}
|
|
|
|
- (void)getHomeLiveTagListSuccess:(NSArray<HomeLiveTagModel *> *)array {
|
|
self.tagList = array;
|
|
NSMutableArray * titles = [NSMutableArray array];
|
|
[array enumerateObjectsUsingBlock:^(HomeLiveTagModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
|
if (obj.sortName.length > 0) {
|
|
[titles addObject:obj.sortName];
|
|
}
|
|
}];
|
|
self.titles = titles.copy;
|
|
self.titleView.titles = self.titles;
|
|
[self.titleView reloadData];
|
|
[self.pagingView.mainTableView.mj_header endRefreshing];
|
|
}
|
|
|
|
- (void)getHomeLiveTagListFail:(NSArray<HomeLiveTagModel *> *)array {
|
|
self.tagList = array;
|
|
NSMutableArray * titles = [NSMutableArray array];
|
|
[array enumerateObjectsUsingBlock:^(HomeLiveTagModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
|
if (obj.sortName.length > 0) {
|
|
[titles addObject:obj.sortName];
|
|
}
|
|
}];
|
|
self.titles = titles.copy;
|
|
self.titleView.titles = self.titles;
|
|
[self.titleView reloadData];
|
|
[self.pagingView.mainTableView.mj_header endRefreshing];
|
|
}
|
|
|
|
#pragma mark - JXCategoryListContentViewDelegate
|
|
- (UIView *)listView {
|
|
return self.view;
|
|
}
|
|
|
|
#pragma mark - JXCategoryViewDelegate
|
|
- (NSUInteger)tableHeaderViewHeightInPagerView:(JXPagerView *)pagerView {
|
|
return [XPHomeLiveHeadView getHomeLiveHeaderViewHeight:self.roomList];
|
|
}
|
|
|
|
- (UIView *)tableHeaderViewInPagerView:(JXPagerView *)pagerView {
|
|
return self.headerView;
|
|
}
|
|
|
|
- (NSUInteger)heightForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
|
|
return 50;
|
|
}
|
|
|
|
- (UIView *)viewForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
|
|
return self.titleView;
|
|
}
|
|
|
|
- (NSInteger)numberOfListsInPagerView:(JXPagerView *)pagerView {
|
|
return self.titles.count;
|
|
}
|
|
|
|
- (id<JXPagerViewListViewDelegate>)pagerView:(JXPagerView *)pagerView initListAtIndex:(NSInteger)index {
|
|
XPHomeLivePageViewController * homeVC = [[XPHomeLivePageViewController alloc] init];
|
|
HomeLiveTagModel *tag = self.tagList[index];
|
|
homeVC.tabId = tag.tid;
|
|
return homeVC;
|
|
}
|
|
|
|
- (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
|
|
HomeLiveTagModel *tag = self.tagList[index];
|
|
NSMutableDictionary * dic = [NSMutableDictionary dictionary];
|
|
[dic safeSetObject: tag.sortName forKey:@"geboTagName"];
|
|
[StatisticsServiceHelper trackEventWithKey:StatisticsServiceEventGebo_tab_click eventAttributes:dic];
|
|
}
|
|
|
|
#pragma mark - JXPagerMainTableViewGestureDelegate
|
|
- (BOOL)mainTableViewGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
|
|
///1000是外部的scrollView 1001是人气主播中的collectionView
|
|
if (otherGestureRecognizer.view.tag == 1000 || otherGestureRecognizer.view == self.headerView || otherGestureRecognizer.view.tag == 1001) {
|
|
return NO;
|
|
}
|
|
return [gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]] && [otherGestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]];
|
|
}
|
|
|
|
#pragma mark - XPHomeLiveHeadViewDelegate
|
|
- (void)xPHomeLiveHeadViewDidClickItem:(HomeRecommendRoomModel *)model {
|
|
NSString *roomUid = model.uid;
|
|
if (roomUid.length > 0) {
|
|
[XPRoomViewController openRoom:roomUid viewController:self];
|
|
}
|
|
}
|
|
|
|
#pragma mark - Getters And Setters
|
|
- (JXCategoryTitleView *)titleView {
|
|
if (!_titleView) {
|
|
_titleView = [[JXCategoryTitleView alloc] init];
|
|
_titleView.delegate = self;
|
|
_titleView.backgroundColor = [UIColor clearColor];
|
|
_titleView.titleColor = [ThemeColor textThirdColor];
|
|
_titleView.titleSelectedColor = [ThemeColor mainTextColor];
|
|
_titleView.titleFont = [UIFont fontWithName:@"PingFang-SC-Medium" size:14];
|
|
_titleView.titleSelectedFont = [UIFont fontWithName:@"PingFang-SC-Medium" size:14];
|
|
_titleView.titleLabelAnchorPointStyle = JXCategoryTitleLabelAnchorPointStyleCenter;
|
|
_titleView.contentScrollViewClickTransitionAnimationEnabled = NO;
|
|
_titleView.defaultSelectedIndex = 0;
|
|
_titleView.averageCellSpacingEnabled = NO;
|
|
_titleView.titles = self.titles;
|
|
_titleView.cellSpacing = 25;
|
|
_titleView.titles = self.titles;
|
|
_titleView.listContainer = (id<JXCategoryViewListContainer>)self.pagingView.listContainerView;
|
|
|
|
JXCategoryIndicatorBackgroundView * indocator = [[JXCategoryIndicatorBackgroundView alloc] init];
|
|
indocator.indicatorColor = [ThemeColor appMainColor];
|
|
indocator.indicatorHeight = 24;
|
|
indocator.indicatorWidthIncrement = 20;
|
|
indocator.indicatorCornerRadius = 12;
|
|
_titleView.indicators = @[indocator];
|
|
}
|
|
return _titleView;
|
|
}
|
|
|
|
- (JXPagerView *)pagingView {
|
|
if (!_pagingView) {
|
|
_pagingView = [[JXPagerView alloc] initWithDelegate:self];
|
|
_pagingView.backgroundColor = [UIColor clearColor];
|
|
_pagingView.listContainerView.backgroundColor = [UIColor clearColor];
|
|
_pagingView.mainTableView.backgroundColor = [UIColor clearColor];
|
|
_pagingView.mainTableView.gestureDelegate = self;
|
|
_pagingView.listContainerView.listCellBackgroundColor = UIColor.clearColor;
|
|
}
|
|
return _pagingView;
|
|
}
|
|
|
|
- (XPHomeLiveHeadView *)headerView {
|
|
if (!_headerView) {
|
|
_headerView = [[XPHomeLiveHeadView alloc] init];
|
|
_headerView.backgroundColor = [UIColor clearColor];
|
|
_headerView.currenViewController = self;
|
|
_headerView.delegate = self;
|
|
}
|
|
return _headerView;
|
|
}
|
|
|
|
- (UIView *)customNavigationBar {
|
|
if (!_customNavigationBar) {
|
|
CGRect frame = CGRectMake(0, kStatusBarHeight, KScreenWidth, 44);
|
|
_customNavigationBar = [[UIView alloc]initWithFrame:frame];
|
|
}
|
|
return _customNavigationBar;
|
|
}
|
|
|
|
- (UILabel *)titleLabel {
|
|
if (!_titleLabel) {
|
|
_titleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
|
|
_titleLabel.backgroundColor = [UIColor clearColor];
|
|
_titleLabel.font = [UIFont systemFontOfSize:18.f weight:UIFontWeightMedium];
|
|
_titleLabel.textColor = ThemeColor.mainTextColor;
|
|
_titleLabel.text = @"直播";
|
|
}
|
|
return _titleLabel;
|
|
}
|
|
|
|
@end
|