| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669 |
- //
- // MORankListTableView.m
- // MiMoLive
- //
- // Created by SuperC on 2023/11/30.
- //
- //一页的size
- #define kPageSize 100
- #import "MORankListTableView.h"
- #import "MORankTopView.h"
- #import "MORankCurrentView.h"
- #import "YYTimer.h"
- #import "MORankCountdownTopView.h"
- #import "MORankNoDataView.h"
- @interface MORankListTableView ()<UITableViewDelegate,UITableViewDataSource>
- @property (nonatomic, strong) MORankTopView *topView;//三排名顶部
- @property (nonatomic, strong) MORankCountdownTopView *topTwoView;//倒计时View
- @property (nonatomic, strong) UITableView *tableView;
- @property (nonatomic, strong) MORankCurrentView *bottomView;
- @property (nonatomic, strong) MORankBasedata *baseData;
- /** 游标 */
- @property (nonatomic, copy) NSString *next;
- @property (nonatomic, strong) YYTimer *liveTimer;
- @property (nonatomic, strong) MORankNoDataView *noDataView;
- @property (nonatomic, assign) BOOL needAddTimer;//是否添加定时器
- @end
- @implementation MORankListTableView
- - (instancetype)init{
- self = [super init];
- if (self)
- {
- [self setupUI];
- }
-
- return self;
- }
- - (instancetype)initWithFrame:(CGRect)frame
- {
- self = [super initWithFrame:frame];
- if (self)
- {
- [self setupUI];
- }
-
- return self;
- }
- - (void)setupUI{
- self.next = @"";
- self.isNeedUpdata = NO;
- // [self addSubview:self.bgExtImgView];
- // [self.bgExtImgView mas_makeConstraints:^(MASConstraintMaker *make) {
- // make.top.equalTo(self).offset(280.0);
- // make.left.right.equalTo(self);
- // make.bottom.equalTo(self);
- // }];
- //
- // UIImage *extImg = [MOTools createImageWithColor:[MOTools colorWithHexString:@"#FBF8F8" alpha:1.0]];
- // [self.bgExtImgView setImage:extImg];
-
- [self addSubview:self.tableView];
- [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.left.right.bottom.equalTo(self);
- }];
-
- [self addSubview:self.bottomView];
- [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.bottom.mas_equalTo(0);
- make.height.mas_equalTo(68 + kBottomSafeAreaInset);
- }];
- }
- #pragma mark - JXCategoryListContentViewDelegate
- - (void)listWillAppear{
- if(self.dataArr.count == 0 || self.isNeedUpdata)
- {
- if(self.typeNum == 1){
- //直播间贡献榜
- self.next = @"";
-
- if(self.roomId.length == 0){
- return;
- }
-
- NSDictionary *basePage = @{@"size":@(kPageSize),@"next":self.next};
- NSDictionary *baseDict = @{@"type":@(self.typeTime),
- @"page":basePage,
- @"id":self.roomId};
- [self toGetRankOutcomeAboutRoomWith:baseDict];
-
- }
- else if (self.typeNum == 2){
- //总贡献榜
- self.next = @"";
- NSDictionary *basePage = @{@"size":@(kPageSize),@"next":self.next};
- NSDictionary *baseDict;
-
- if(self.countryStr.length > 0){
- baseDict = @{@"type":@(self.typeTime),
- @"page":basePage,
- @"country":self.countryStr};
- }
- else{
- baseDict = @{@"type":@(self.typeTime),
- @"page":basePage};
- }
- [self toGetRankOutcomeListWith:baseDict];
- }
- else{
- //收益榜
- self.next = @"";
- NSDictionary *basePage = @{@"size":@(kPageSize),@"next":self.next};
- NSDictionary *baseDict ;
-
- if(self.countryStr.length > 0){
- baseDict = @{@"type":@(self.typeTime),
- @"page":basePage,
- @"country":self.countryStr,
- @"roomId":self.roomId ?: @"",
- @"newer": @(self.isNewer)};
- }
- else{
- baseDict = @{@"type":@(self.typeTime),
- @"page":basePage,
- @"roomId":self.roomId ?: @"",
- @"newer": @(self.isNewer)};
- }
-
- [self toGetRankIncomeListWith:baseDict];
- }
- }
- else{
-
- [self.tableView reloadData];
- }
-
- if (self.needAddTimer) {
- [self.liveTimer fire];
- }
- }
- - (void)listDidDisappear {
- if (self.needAddTimer && _liveTimer) {
- [_liveTimer invalidate];
- _liveTimer = nil;
- }
- }
- - (void)setTypeTime:(NSInteger)typeTime{
- _typeTime = typeTime;
-
- if(typeTime == 4 && self.typeNum == 3){//直播间收益榜 && 小时榜
-
- if(self.isNewer){
- self.tableView.tableHeaderView = self.topTwoView;
- [self.topTwoView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.top.offset(0);
- make.left.offset(0.0);
- make.height.mas_equalTo(32.0);
- make.width.mas_equalTo(SCREENWIDTH);
- }];
- }
- else{
- self.topView.isShowCountDownLab = YES;
-
- CGFloat topViewHeigth = [MORankTopView theViewHeight] + 24.0;
- self.tableView.tableHeaderView = self.topView;
- [self.topView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.top.offset(0);
- make.left.offset(0.0);
- make.height.mas_equalTo(topViewHeigth);
- make.width.mas_equalTo(SCREENWIDTH);
- }];
- }
- }
- }
- - (void)setCountryStr:(NSString *)countryStr{
- _countryStr = countryStr;
- }
- - (void)setupNoDataView {
- self.tableView.backgroundView.hidden = YES;
- if (self.dataArr.count > 0) {
- return;
- }
- self.tableView.backgroundView.hidden = NO;
- self.tableView.tableHeaderView = nil;
- self.tableView.backgroundView = self.noDataView;
-
- self.noDataView.sendButton.hidden = YES;
- if (self.baseData.rankHit && !self.outSideRoom) {
- self.noDataView.sendButton.hidden = NO;
- [self.noDataView.sendButton configureWithCount:[NSString stringWithFormat:@"x %@", [MOTextTools numberToStringWith:self.baseData.rankHit.hitAmount]] desc:NSLocalString(@"C60020") isGradient:YES];
- [self.noDataView.sendButton.iconView sd_setImageWithURL:[NSURL URLWithString:self.baseData.rankHit.giftImg]];
- [self.noDataView.sendButton addTarget:self action:@selector(sendGiftAction) forControlEvents:UIControlEventTouchUpInside];
- }
- }
- - (void)sendGiftAction {
- if (self.hitBlock) {
- self.hitBlock(self.baseData.rankHit);
- }
- }
- /// 排行榜 - 直播间贡献榜
- - (void)toGetRankOutcomeAboutRoomWith:(NSDictionary *)dict{
- WEAKSELF
- [kHttpManager toGetRankOutcomeRoomWithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
- [weakSelf.tableView.mj_header endRefreshing];
- if(kCode_Success){
- MOLogV(@"toGetRankOutcome: %@",[[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:data options:0 error:nil] encoding:NSUTF8StringEncoding]);
- MORankBasedata *baseData = [MORankBasedata modelObjectWithDictionary:data[@"data"]];
- weakSelf.baseData = baseData;
- if (weakSelf.getTopBlock) {
- weakSelf.getTopBlock(baseData.newerTops);
- }
- weakSelf.dataArr = [baseData.ranklist mutableCopy];
- [weakSelf setTopView];
- [weakSelf.tableView reloadData];
-
- [weakSelf.bottomView setupContribute:baseData];
- [weakSelf checkTableViewcontentInset];
- [weakSelf setupNoDataView];
- }
- else{
- kShowNetError(data)
- }
- }];
- }
- /// 排行榜 - 贡献榜
- - (void)toGetRankOutcomeListWith:(NSDictionary *)dict{
- WEAKSELF
- [kHttpManager toGetRankOutcomeListWithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
- [weakSelf.tableView.mj_header endRefreshing];
- if(kCode_Success){
- MOLogV(@"toGetRankOutcomeList: %@",[[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:data options:0 error:nil] encoding:NSUTF8StringEncoding]);
- MORankBasedata *baseData = [MORankBasedata modelObjectWithDictionary:data[@"data"]];
- weakSelf.baseData = baseData;
- if (weakSelf.getTopBlock) {
- weakSelf.getTopBlock(baseData.newerTops);
- }
- weakSelf.dataArr = [baseData.ranklist mutableCopy];
- [weakSelf setTopView];
- [weakSelf.tableView reloadData];
- weakSelf.isNeedUpdata = NO;
-
- [weakSelf checkTableViewcontentInset];
- [weakSelf setupNoDataView];
- }
- else{
- kShowNetError(data)
- }
- }];
- }
- /// 排行榜 - 收益榜
- - (void)toGetRankIncomeListWith:(NSDictionary *)dict{
- WEAKSELF
- [kHttpManager toGetRankIncomeListWithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
- [weakSelf.tableView.mj_header endRefreshing];
- if(kCode_Success){
- MOLogV(@"toGetRankIncomeList: %@",[[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:data options:0 error:nil] encoding:NSUTF8StringEncoding]);
- MORankBasedata *baseData = [MORankBasedata modelObjectWithDictionary:data[@"data"]];
- weakSelf.baseData = baseData;
- if (weakSelf.getTopBlock) {
- weakSelf.getTopBlock(baseData.newerTops);
- }
- if (weakSelf.typeTime == 4) {//小时榜才回调出去
- if (weakSelf.getCurrentIndexBlock) {
- weakSelf.getCurrentIndexBlock(baseData.rankFooter);
- }
- }
- weakSelf.dataArr = [baseData.ranklist mutableCopy];
- [weakSelf checkIfNeedAddTimer];
- [weakSelf setTopView];
- weakSelf.topView.endTime = baseData.endTime;
-
- [weakSelf.tableView reloadData];
- weakSelf.isNeedUpdata = NO;
- [weakSelf.bottomView setupRevenue:baseData];
- [weakSelf checkTableViewcontentInset];
- [weakSelf setupNoDataView];
- }
- else{
- kShowNetError(data)
- }
- }];
- }
- - (void)checkIfNeedAddTimer {
- if(self.typeTime == 4 && self.typeNum == 3 && self.dataArr.count > 0) {
- self.needAddTimer = YES;
- if(!_liveTimer){
- [self.liveTimer fire];//打开定时器
- }
- }
- }
- - (void)checkTableViewcontentInset {
- if (self.outSideRoom) {
- self.bottomView.hidden = YES;
- self.tableView.contentInset = UIEdgeInsetsMake(0, 0, (kBottomSafeAreaInset > 0 ? kBottomSafeAreaInset : 20) , 0);
- return;
- }
-
- if (self.dataArr.count == 0) {
- self.bottomView.hidden = YES;
- //显示没有榜单,显示上榜
-
-
- return;
- }
-
- if (self.dataArr.count >= 6) {
- self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 86 + kBottomSafeAreaInset, 0);
- }
- }
- - (void)setTopView{
-
- if (self.isNewer) {
- if(self.typeTime == 4 && self.typeNum == 3){//直播间收益榜 && 小时榜
- self.topTwoView.endTime = self.baseData.endTime;
- return;
- }
-
- self.tableView.tableHeaderView = nil;
- return;
- }
-
- self.topView.hidden = (self.dataArr.count == 0);
-
- NSMutableArray *tempArr = [NSMutableArray array];
-
- int x = 0;
- for (MORanklist *model in self.dataArr) {
-
- if(x >= 3){
- break;
- }
- else{
- [tempArr addObject:model];
- }
- x++;
- }
-
- self.topView.typeNum = self.typeNum;
- self.topView.roomId = self.roomId;
- self.topView.dataArr = tempArr;
- }
- - (UIView *)listView{
- return self;
- }
- #pragma mark - UITableViewDelegate,UITableViewDataSource
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
-
- if (self.isNewer) {
- return self.dataArr.count;
- }
-
- if(self.dataArr.count > 3){
- return self.dataArr.count - 3;
- }
- else{
- return 1;
- }
-
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
-
- if (self.isNewer) {
- return 68.0;
- }
-
- if(self.dataArr.count > 3){
- return 68.0;
- }
- else
- {
- return 0.01;
- }
-
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
-
- WEAKSELF
-
- if (self.isNewer) {
- MORanklist *model = self.dataArr[indexPath.row];
- MORankListCell *cell = [tableView dequeueReusableCellWithIdentifier:MORankLIstCell_ID];
- if (cell == nil){
- cell = [[MORankListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MORankLIstCell_ID];
- }
- NSInteger num = indexPath.row + 1;
- if (num <= 3) {
- cell.numLab.hidden = YES;
- cell.numImgView.hidden = NO;
- cell.numImgView.image = [UIImage imageNamed:[NSString stringWithFormat:@"icon_rank_%zd", num]];
- } else {
- cell.numLab.hidden = NO;
- cell.numImgView.hidden = YES;
- cell.numLab.text = [NSString stringWithFormat:@"%zd",num];
- }
-
- cell.isShowLiving = YES;
- cell.typeNum = self.typeNum;
- cell.cellIndexPath = indexPath;
- cell.cellModel = model;
- cell.roomId = self.roomId;
-
- cell.followBtnBlock = ^(MORanklist * _Nonnull cellModel, NSIndexPath *cellIndexPath) {
- cellModel.userBase.follow = YES;
-
- for (MORanklist *tempModel in weakSelf.dataArr) {
- if([tempModel.userBase.userProfile.id isEqualToString:cellModel.userBase.userProfile.id]){
- tempModel.userBase.follow = YES;
- break;
- }
- }
-
- [weakSelf.tableView reloadRowsAtIndexPaths:@[cellIndexPath] withRowAnimation:UITableViewRowAnimationNone];
- };
- cell.headBtnBlock = ^(MORanklist * _Nonnull model) {
- weakSelf.headBtnBlock ? weakSelf.headBtnBlock(model.userBase) : nil;
- };
-
- return cell;
- }
-
- if(self.dataArr.count > 3){
- MORanklist *model = self.dataArr[indexPath.row + 3];
- MORankListCell *cell = [tableView dequeueReusableCellWithIdentifier:MORankLIstCell_ID];
- if (cell == nil){
- cell = [[MORankListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MORankLIstCell_ID];
- }
- NSInteger num = indexPath.row + 4;
- cell.numLab.text = [NSString stringWithFormat:@"%zd",num];
-
- cell.isShowLiving = YES;
- cell.typeNum = self.typeNum;
- cell.cellIndexPath = indexPath;
- cell.cellModel = model;
- cell.roomId = self.roomId;
-
- cell.followBtnBlock = ^(MORanklist * _Nonnull cellModel, NSIndexPath *cellIndexPath) {
- cellModel.userBase.follow = YES;
-
- for (MORanklist *tempModel in weakSelf.dataArr) {
- if([tempModel.userBase.userProfile.id isEqualToString:cellModel.userBase.userProfile.id]){
- tempModel.userBase.follow = YES;
- break;
- }
- }
-
- [weakSelf.tableView reloadRowsAtIndexPaths:@[cellIndexPath] withRowAnimation:UITableViewRowAnimationNone];
- };
- cell.headBtnBlock = ^(MORanklist * _Nonnull model) {
- weakSelf.headBtnBlock ? weakSelf.headBtnBlock(model.userBase) : nil;
- };
-
- return cell;
- }
- else {
- MORankNoDataCell *cell = [tableView dequeueReusableCellWithIdentifier:MORankNoDataCell_ID];
-
- cell.bgView.layer.cornerRadius = 16.0;
- cell.bgView.layer.maskedCorners = kCALayerMinXMinYCorner | kCALayerMaxXMinYCorner;
- cell.bgView.layer.masksToBounds = YES;
- cell.bgView.backgroundColor = [MOTools colorWithHexString:@"#FFFFFF" alpha:1.0];
- cell.titleLab.hidden = YES;
-
- return cell;
- }
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
- [tableView deselectRowAtIndexPath:indexPath animated:YES];
-
- // if (self.isNewer){
- // MORanklist *model = self.dataArr[indexPath.row];
- // self.headBtnBlock ? self.headBtnBlock(model.userBase) : nil;
- // }
- // else{
- // if(self.dataArr.count > 3){
- // MORanklist *model = self.dataArr[indexPath.row + 3];
- // self.headBtnBlock ? self.headBtnBlock(model.userBase) : nil;
- // }
- // }
- }
- #pragma mark - Lazy
- - (UITableView *)tableView{
- if (!_tableView)
- {
- _tableView= [[UITableView alloc] init];
- if (@available(iOS 11.0, *))
- {
- _tableView.estimatedRowHeight = 0;
- _tableView.estimatedSectionFooterHeight = 0;
- _tableView.estimatedSectionHeaderHeight = 0;
- _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- }
-
- //iOS15适配
- if (@available(iOS 15.0, *))
- {
- _tableView.sectionHeaderTopPadding = 0;
- }
-
- _tableView.backgroundColor = [UIColor clearColor];
- _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- _tableView.dataSource = self;
- _tableView.delegate = self;
- _tableView.showsVerticalScrollIndicator = NO;
- _tableView.showsHorizontalScrollIndicator = NO;
- [_tableView registerClass:[MORankListCell class] forCellReuseIdentifier:MORankLIstCell_ID];
- [_tableView registerNib:[UINib nibWithNibName:@"MORankNoDataCell" bundle:nil] forCellReuseIdentifier:MORankNoDataCell_ID];
- CGFloat topViewHeigth = [MORankTopView theViewHeight];
- _tableView.tableHeaderView = self.topView;
- [self.topView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.offset(0);
- make.left.offset(0.0);
- make.height.mas_equalTo(topViewHeigth);
- make.width.mas_equalTo(SCREENWIDTH);
- }];
-
- WEAKSELF
- MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
- weakSelf.isNeedUpdata = YES;
- [weakSelf listWillAppear];
- }];
- header.lastUpdatedTimeLabel.hidden = YES;
- header.stateLabel.hidden = YES;
- _tableView.mj_header = header;
-
- }
- return _tableView;
- }
- - (MORankTopView *)topView{
- if (!_topView) {
- _topView = [MORankTopView moRankTopView];
- _topView.hidden = YES;
- CGFloat topViewHeigth = [MORankTopView theViewHeight];
- _topView.height = topViewHeigth;
-
- WEAKSELF
- _topView.followSomeOneBlock = ^(MORanklist * _Nonnull listModel) {
- for (MORanklist *model in weakSelf.dataArr) {
- if([model.userBase.userProfile.id isEqualToString:listModel.userBase.userProfile.id]){
- model.userBase.follow = YES;
- }
- }
- };
- _topView.headBtnClickBlock = ^(MOUserBase * _Nonnull userBase) {
- weakSelf.headBtnBlock ? weakSelf.headBtnBlock(userBase) : nil;
- };
- _topView.backgroundColor = [MOTools colorWithHexString:@"#FFFFFF"];
-
- _topView.timeEndBlock = ^{
- weakSelf.isNeedUpdata = YES;
- [weakSelf listWillAppear];
- };
- }
- return _topView;
- }
- - (MORankCountdownTopView *)topTwoView{
- if(!_topTwoView){
- WEAKSELF
- _topTwoView = [[MORankCountdownTopView alloc] init];
- _topTwoView.timeEndBlock = ^{
- weakSelf.isNeedUpdata = YES;
- [weakSelf listWillAppear];
- };
- }
- return _topTwoView;
- }
- - (NSMutableArray *)dataArr{
- if(!_dataArr){
- _dataArr = [NSMutableArray array];
- }
- return _dataArr;
- }
- - (MORankCurrentView *)bottomView {
- if (!_bottomView) {
- _bottomView = [[MORankCurrentView alloc] init];
-
- WEAKSELF
- _bottomView.hitBlock = ^(MORankHit * _Nonnull model) {
- if (weakSelf.hitBlock) {
- weakSelf.hitBlock(model);
- }
- };
- }
- return _bottomView;
- }
- - (void)dealloc{
- MOLogV(@"MORankListTableView dealloc");
-
- if(_liveTimer){
- [_liveTimer invalidate];
- _liveTimer = nil;
- }
- }
- - (YYTimer *)liveTimer{
- if(!_liveTimer){
- _liveTimer = [YYTimer timerWithTimeInterval:1 target:self selector:@selector(oneSecondPassed) repeats:YES];
- }
- return _liveTimer;
- }
- - (MORankNoDataView *)noDataView {
- if (!_noDataView) {
- _noDataView = [[MORankNoDataView alloc] initWithFrame:CGRectMake(0, 0, SCREENWIDTH, SCREENWIDTH)];
- }
- return _noDataView;
- }
- - (void)oneSecondPassed{
- MOLogV(@"MORankListTableView tenSecondPassed");
-
- if(self.typeTime == 4 && self.typeNum == 3){//直播间收益榜 && 小时榜
-
- if(self.isNewer){
- [self.topTwoView oneSecondPassed];
- }
- else{
- [self.topView oneSecondPassed];
- }
- }
- }
- @end
|