结构调整
This commit is contained in:
418
QXLive/Room(房间)/View/排行榜/QXRoomRankSubView.m
Normal file
418
QXLive/Room(房间)/View/排行榜/QXRoomRankSubView.m
Normal file
@@ -0,0 +1,418 @@
|
||||
//
|
||||
// QXRoomRankSubView.m
|
||||
// QXLive
|
||||
//
|
||||
// Created by 启星 on 2025/6/9.
|
||||
//
|
||||
|
||||
#import "QXRoomRankSubView.h"
|
||||
#import "QXBlackListCell.h"
|
||||
#import "QXMineNetwork.h"
|
||||
|
||||
@interface QXRoomRankSubView()<UITableViewDataSource,UITableViewDelegate,QXRoomSeatDelegate>
|
||||
@property (nonatomic,strong)UIView *topBgView;
|
||||
@property (nonatomic,strong)UIButton *hourBtn;
|
||||
@property (nonatomic,strong)UIButton *dayBtn;
|
||||
@property (nonatomic,strong)UIButton *weekBtn;
|
||||
@property (nonatomic,strong)UIButton *selectedBtn;
|
||||
|
||||
@property (nonatomic,strong)UIView *tableHeaderView;
|
||||
@property (nonatomic,strong)QXRoomRankTopThreeView *firstView;
|
||||
@property (nonatomic,strong)QXRoomRankTopThreeView *secondView;
|
||||
@property (nonatomic,strong)QXRoomRankTopThreeView *thirdView;
|
||||
@property (nonatomic,strong)UITableView *tableView;
|
||||
@property (nonatomic,strong)NSMutableArray *dataArray;
|
||||
@property (nonatomic,strong)NSMutableArray *topArray;
|
||||
@property (nonatomic,assign)NSInteger page;
|
||||
@end
|
||||
@implementation QXRoomRankSubView
|
||||
|
||||
-(UIView *)listView{
|
||||
return self;
|
||||
}
|
||||
- (instancetype)initWithFrame:(CGRect)frame
|
||||
{
|
||||
self = [super initWithFrame:frame];
|
||||
if (self) {
|
||||
[self initSubviews];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void)initSubviews{
|
||||
self.page = 1;
|
||||
self.topBgView = [[UIView alloc] initWithFrame:CGRectMake(16, 8, self.width-32, 40)];
|
||||
self.topBgView.backgroundColor = RGB16(0x2B2482);
|
||||
[self.topBgView addRoundedCornersWithRadius:20];
|
||||
[self addSubview:self.topBgView];
|
||||
|
||||
|
||||
self.hourBtn = [[UIButton alloc] init];
|
||||
[self.hourBtn setTitle:QXText(@"小时榜") forState:(UIControlStateNormal)];
|
||||
[self.hourBtn setBackgroundImage:[UIImage imageWithColor:[UIColor clearColor]] forState:(UIControlStateNormal)];
|
||||
[self.hourBtn setBackgroundImage:[UIImage imageWithColor:[UIColor whiteColor]] forState:(UIControlStateSelected)];
|
||||
[self.hourBtn setTitleColor:RGB16(0xACA3ED) forState:(UIControlStateNormal)];
|
||||
[self.hourBtn setTitleColor:QXConfig.textColor forState:(UIControlStateSelected)];
|
||||
[self.hourBtn addRoundedCornersWithRadius:15];
|
||||
self.hourBtn.titleLabel.font = [UIFont boldSystemFontOfSize:14];
|
||||
[self.hourBtn addTarget:self action:@selector(typeAction:) forControlEvents:(UIControlEventTouchUpInside)];
|
||||
|
||||
[self.topBgView addSubview:self.hourBtn];
|
||||
|
||||
self.dayBtn = [[UIButton alloc] init];
|
||||
[self.dayBtn setTitle:QXText(@"日榜") forState:(UIControlStateNormal)];
|
||||
[self.dayBtn setBackgroundImage:[UIImage imageWithColor:[UIColor clearColor]] forState:(UIControlStateNormal)];
|
||||
[self.dayBtn setBackgroundImage:[UIImage imageWithColor:[UIColor whiteColor]] forState:(UIControlStateSelected)];
|
||||
[self.dayBtn setTitleColor:RGB16(0xACA3ED) forState:(UIControlStateNormal)];
|
||||
[self.dayBtn setTitleColor:QXConfig.textColor forState:(UIControlStateSelected)];
|
||||
[self.dayBtn addRoundedCornersWithRadius:15];
|
||||
self.dayBtn.titleLabel.font = [UIFont boldSystemFontOfSize:14];
|
||||
[self.dayBtn addTarget:self action:@selector(typeAction:) forControlEvents:(UIControlEventTouchUpInside)];
|
||||
[self.topBgView addSubview:self.dayBtn];
|
||||
|
||||
self.weekBtn = [[UIButton alloc] init];
|
||||
[self.weekBtn setTitle:QXText(@"周榜") forState:(UIControlStateNormal)];
|
||||
[self.weekBtn setBackgroundImage:[UIImage imageWithColor:[UIColor clearColor]] forState:(UIControlStateNormal)];
|
||||
[self.weekBtn setBackgroundImage:[UIImage imageWithColor:[UIColor whiteColor]] forState:(UIControlStateSelected)];
|
||||
[self.weekBtn setTitleColor:RGB16(0xACA3ED) forState:(UIControlStateNormal)];
|
||||
[self.weekBtn setTitleColor:QXConfig.textColor forState:(UIControlStateSelected)];
|
||||
[self.weekBtn addRoundedCornersWithRadius:15];
|
||||
self.weekBtn.titleLabel.font = [UIFont boldSystemFontOfSize:14];
|
||||
[self.weekBtn addTarget:self action:@selector(typeAction:) forControlEvents:(UIControlEventTouchUpInside)];
|
||||
[self.topBgView addSubview:self.weekBtn];
|
||||
|
||||
CGFloat btnWidth = ScaleWidth(72);
|
||||
|
||||
[self.dayBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.centerX.equalTo(self.topBgView);
|
||||
make.height.mas_equalTo(30);
|
||||
make.width.mas_equalTo(btnWidth);
|
||||
make.centerY.equalTo(self.topBgView);
|
||||
}];
|
||||
|
||||
[self.hourBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.right.equalTo(self.dayBtn.mas_left).offset(-16);
|
||||
make.height.mas_equalTo(30);
|
||||
make.width.mas_equalTo(btnWidth);
|
||||
make.centerY.equalTo(self.topBgView);
|
||||
}];
|
||||
|
||||
[self.weekBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.equalTo(self.dayBtn.mas_right).offset(16);
|
||||
make.height.mas_equalTo(30);
|
||||
make.width.mas_equalTo(btnWidth);
|
||||
make.centerY.equalTo(self.topBgView);
|
||||
}];
|
||||
|
||||
self.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, self.topBgView.bottom+38, self.width, 220)];
|
||||
CGFloat itemWidth = (self.width-36)/3;
|
||||
|
||||
|
||||
self.secondView = [[QXRoomRankTopThreeView alloc] initWithFrame:CGRectMake(18, 50, itemWidth, 135)];
|
||||
self.secondView.number = 2;
|
||||
self.secondView.delegate = self;
|
||||
[self.tableHeaderView addSubview:self.secondView];
|
||||
|
||||
|
||||
self.firstView = [[QXRoomRankTopThreeView alloc] initWithFrame:CGRectMake(self.secondView.right, 0, itemWidth, 161)];
|
||||
self.firstView.number = 1;
|
||||
self.firstView.delegate = self;
|
||||
[self.tableHeaderView addSubview:self.firstView];
|
||||
|
||||
self.thirdView = [[QXRoomRankTopThreeView alloc] initWithFrame:CGRectMake(self.firstView.right, 50, itemWidth, 135)];
|
||||
self.thirdView.number = 3;
|
||||
self.thirdView.delegate = self;
|
||||
[self.tableHeaderView addSubview:self.thirdView];
|
||||
[self addSubview:self.tableHeaderView];
|
||||
|
||||
|
||||
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, self.tableHeaderView.bottom, self.width, self.height-self.tableHeaderView.bottom) style:(UITableViewStylePlain)];
|
||||
self.tableView.delegate = self;
|
||||
self.tableView.dataSource = self;
|
||||
self.tableView.backgroundColor = [UIColor clearColor];
|
||||
self.tableView.rowHeight = 60;
|
||||
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
|
||||
MJWeakSelf
|
||||
self.tableView.mj_footer = [MJRefreshBackStateFooter footerWithRefreshingBlock:^{
|
||||
weakSelf.page++;
|
||||
[weakSelf getRankList];
|
||||
}];
|
||||
self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
|
||||
weakSelf.page = 1;
|
||||
[weakSelf getRankList];
|
||||
}];
|
||||
[self addSubview:self.tableView];
|
||||
|
||||
// self.tableView.tableHeaderView = self.tableHeaderView;
|
||||
|
||||
self.hourBtn.selected = YES;
|
||||
self.selectedBtn = self.hourBtn;
|
||||
}
|
||||
-(void)setRoomId:(NSString *)roomId{
|
||||
_roomId = roomId;
|
||||
self.page = 1;
|
||||
[self getRankList];
|
||||
}
|
||||
-(void)getRankList{
|
||||
NSString *time_type = @"1";
|
||||
if (self.selectedBtn == self.hourBtn) {
|
||||
time_type = @"1";
|
||||
}else if(self.selectedBtn == self.dayBtn){
|
||||
time_type = @"2";
|
||||
}else if(self.selectedBtn == self.weekBtn){
|
||||
time_type = @"3";
|
||||
}
|
||||
|
||||
MJWeakSelf
|
||||
[QXMineNetwork roomRankListWithRoomId:self.roomId type:self.type time_type:time_type page:self.page successBlock:^(NSArray<QXRoomOnlineList *> * _Nonnull list) {
|
||||
if (weakSelf.page == 1) {
|
||||
weakSelf.firstView.md = nil;
|
||||
weakSelf.secondView.md = nil;
|
||||
weakSelf.thirdView.md = nil;
|
||||
[weakSelf.dataArray removeAllObjects];
|
||||
[weakSelf.topArray removeAllObjects];
|
||||
for (int i = 0 ; i < list.count; i++) {
|
||||
QXRoomOnlineList*md = list[i];
|
||||
if (i == 0) {
|
||||
// [weakSelf.topArray addObject:md];
|
||||
weakSelf.firstView.md = md;
|
||||
}else if (i == 1) {
|
||||
weakSelf.secondView.md = md;
|
||||
}else if (i == 2) {
|
||||
weakSelf.thirdView.md = md;
|
||||
}else{
|
||||
[weakSelf.dataArray addObject:md];
|
||||
}
|
||||
}
|
||||
}else{
|
||||
[weakSelf.dataArray addObjectsFromArray:list];
|
||||
}
|
||||
[self.tableView reloadData];
|
||||
if (list.count == 0) {
|
||||
self.tableView.mj_footer.state = MJRefreshStateNoMoreData;
|
||||
}else{
|
||||
[self.tableView.mj_footer endRefreshing];
|
||||
}
|
||||
[self.tableView.mj_header endRefreshing];
|
||||
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
|
||||
[self.tableView.mj_header endRefreshing];
|
||||
[self.tableView.mj_footer endRefreshing];
|
||||
}];
|
||||
|
||||
}
|
||||
-(void)previewUserInfoWithUserId:(NSString *)userId{
|
||||
if (self.delegate && [self.delegate respondsToSelector:@selector(previewUserInfoWithUserId:)]) {
|
||||
[self.delegate previewUserInfoWithUserId:userId];
|
||||
}
|
||||
}
|
||||
|
||||
-(void)typeAction:(UIButton*)sender{
|
||||
self.selectedBtn.selected = !self.selectedBtn.selected;
|
||||
sender.selected = !sender.selected;
|
||||
self.selectedBtn = sender;
|
||||
[self getRankList];
|
||||
}
|
||||
|
||||
|
||||
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
|
||||
return self.dataArray.count;
|
||||
}
|
||||
|
||||
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
|
||||
QXBlackListCell *cell = [QXBlackListCell cellWithTableView:tableView];
|
||||
cell.cellType = QXBlackListCellTypeRank;
|
||||
cell.backgroundColor = [UIColor clearColor];
|
||||
cell.titleLabel.text = [NSString stringWithFormat:@"%ld",indexPath.row+4];
|
||||
cell.rankModel = self.dataArray[indexPath.row];
|
||||
return cell;
|
||||
}
|
||||
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
|
||||
QXRoomOnlineList *model = self.dataArray[indexPath.row];
|
||||
if (self.delegate && [self.delegate respondsToSelector:@selector(previewUserInfoWithUserId:)]) {
|
||||
[self.delegate previewUserInfoWithUserId:model.user_id];
|
||||
}
|
||||
}
|
||||
-(NSMutableArray *)dataArray{
|
||||
if (!_dataArray) {
|
||||
_dataArray = [NSMutableArray array];
|
||||
}
|
||||
return _dataArray;
|
||||
}
|
||||
-(NSMutableArray *)topArray{
|
||||
if (!_topArray) {
|
||||
_topArray = [NSMutableArray array];
|
||||
}
|
||||
return _topArray;
|
||||
}
|
||||
@end
|
||||
|
||||
|
||||
@implementation QXRoomRankTopThreeView
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame
|
||||
{
|
||||
self = [super initWithFrame:frame];
|
||||
if (self) {
|
||||
[self initSubviews];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
-(void)setNumber:(NSInteger)number{
|
||||
_number = number;
|
||||
if (number == 1) {
|
||||
self.borderImageView.image = [UIImage imageNamed:@"room_rank_first"];
|
||||
}else if(number == 2){
|
||||
self.borderImageView.image = [UIImage imageNamed:@"room_rank_second"];
|
||||
[self.headerImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
|
||||
make.centerX.equalTo(self);
|
||||
make.top.equalTo(self).offset(10);
|
||||
make.size.mas_equalTo(CGSizeMake(50, 50));
|
||||
}];
|
||||
[self.borderImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
|
||||
make.centerX.centerY.equalTo(self.headerImageView);
|
||||
make.size.mas_equalTo(CGSizeMake(64, 64));
|
||||
}];
|
||||
[self.nameLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.equalTo(self.borderImageView.mas_bottom).offset(12);
|
||||
make.left.right.equalTo(self);
|
||||
make.height.mas_equalTo(21);
|
||||
}];
|
||||
}else{
|
||||
self.borderImageView.image = [UIImage imageNamed:@"room_rank_third"];
|
||||
[self.headerImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
|
||||
make.centerX.equalTo(self);
|
||||
make.top.equalTo(self).offset(10);
|
||||
make.size.mas_equalTo(CGSizeMake(50, 50));
|
||||
}];
|
||||
[self.borderImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
|
||||
make.centerX.centerY.equalTo(self.headerImageView);
|
||||
make.size.mas_equalTo(CGSizeMake(64, 64));
|
||||
}];
|
||||
[self.nameLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.equalTo(self.borderImageView.mas_bottom).offset(12);
|
||||
make.left.right.equalTo(self);
|
||||
make.height.mas_equalTo(21);
|
||||
}];
|
||||
}
|
||||
}
|
||||
-(void)setMd:(QXRoomOnlineList *)md{
|
||||
_md = md;
|
||||
if (md == nil) {
|
||||
self.headerImageView.image = [UIImage imageNamed:@"user_header_placehoulder"];
|
||||
self.nameLabel.text = @"虚位以待";
|
||||
[self.rankBtn setTitle:@"0" forState:(UIControlStateNormal)];
|
||||
[self.iconBgView removeAllSubviews];
|
||||
return;
|
||||
}
|
||||
[self.headerImageView sd_setImageWithURL:[NSURL URLWithString:md.avatar] placeholderImage:[UIImage imageNamed:@"user_header_placehoulder"]];
|
||||
self.nameLabel.text = md.nickname?md.nickname:@"";
|
||||
[self.iconBgView removeAllSubviews];
|
||||
[self.rankBtn setTitle:[NSString stringWithFormat:@" %@",md.total?md.total:md.gift_prices] forState:(UIControlStateNormal)];
|
||||
CGFloat iconWidth = UserIconWidth;
|
||||
CGFloat iconHeight = UserIconHeight;
|
||||
CGFloat margin = 6;
|
||||
for (int i = 0 ; i < md.icon.count; i++) {
|
||||
UIImageView *iconImageView = [[UIImageView alloc] init];
|
||||
[iconImageView sd_setImageWithURL:[NSURL URLWithString:md.icon[i]]];
|
||||
[self.iconBgView addSubview:iconImageView];
|
||||
if (md.icon.count == 1) {
|
||||
[iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.width.mas_equalTo(iconWidth);
|
||||
make.height.mas_equalTo(iconHeight);
|
||||
make.centerY.centerX.equalTo(self.iconBgView);
|
||||
}];
|
||||
}else if(md.icon.count == 2){
|
||||
[iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.width.mas_equalTo(iconWidth);
|
||||
make.height.mas_equalTo(iconHeight);
|
||||
make.centerY.equalTo(self.iconBgView);
|
||||
make.centerX.equalTo(self.iconBgView).offset(-UserIconWidth/2+(margin+iconWidth)*i);
|
||||
}];
|
||||
}else{
|
||||
[iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(i*(iconWidth+margin));
|
||||
make.width.mas_equalTo(iconWidth);
|
||||
make.height.mas_equalTo(iconHeight);
|
||||
make.centerY.equalTo(self.iconBgView);
|
||||
}];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
-(void)initSubviews{
|
||||
self.headerImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"user_header_placehoulder"]];
|
||||
[self.headerImageView addRoundedCornersWithRadius:32];
|
||||
self.headerImageView.contentMode = UIViewContentModeScaleAspectFill;
|
||||
[self addSubview:self.headerImageView];
|
||||
MJWeakSelf
|
||||
[self.headerImageView addTapBlock:^(id _Nonnull obj) {
|
||||
if ([weakSelf.md.user_id isExist]) {
|
||||
if (weakSelf.delegate && [weakSelf.delegate respondsToSelector:@selector(previewUserInfoWithUserId:)]) {
|
||||
[weakSelf.delegate previewUserInfoWithUserId:weakSelf.md.user_id];
|
||||
}
|
||||
}
|
||||
}];
|
||||
[self.headerImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.centerX.equalTo(self);
|
||||
make.top.equalTo(self).offset(10);
|
||||
make.size.mas_equalTo(CGSizeMake(64, 64));
|
||||
}];
|
||||
|
||||
self.borderImageView = [[UIImageView alloc] init];
|
||||
self.borderImageView.contentMode = UIViewContentModeScaleToFill;
|
||||
[self addSubview:self.borderImageView];
|
||||
[self.borderImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.centerX.centerY.equalTo(self.headerImageView);
|
||||
make.size.mas_equalTo(CGSizeMake(80, 80));
|
||||
}];
|
||||
|
||||
self.onlineLabel = [[UILabel alloc] init];
|
||||
self.onlineLabel.textColor = UIColor.whiteColor;
|
||||
self.onlineLabel.font = [UIFont systemFontOfSize:10];
|
||||
self.onlineLabel.textAlignment = NSTextAlignmentCenter;
|
||||
self.onlineLabel.backgroundColor = RGB16(0x472ABF);
|
||||
[self.onlineLabel addRoundedCornersWithRadius:7];
|
||||
self.onlineLabel.text = QXText(@"在线");
|
||||
[self addSubview:self.onlineLabel];
|
||||
[self.onlineLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.centerX.equalTo(self);
|
||||
make.bottom.equalTo(self.borderImageView);
|
||||
make.height.mas_equalTo(14);
|
||||
make.width.mas_equalTo(32);
|
||||
}];
|
||||
|
||||
self.nameLabel = [[UILabel alloc] init];
|
||||
self.nameLabel.textColor = [UIColor whiteColor];
|
||||
self.nameLabel.font = [UIFont systemFontOfSize:14];
|
||||
self.nameLabel.text = QXText(@"虚位以待");
|
||||
self.nameLabel.textAlignment = NSTextAlignmentCenter;
|
||||
[self addSubview:self.nameLabel];
|
||||
[self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.equalTo(self.borderImageView.mas_bottom).offset(25);
|
||||
make.left.right.equalTo(self);
|
||||
make.height.mas_equalTo(21);
|
||||
}];
|
||||
|
||||
self.iconBgView = [[UIView alloc] init];
|
||||
[self addSubview:self.iconBgView];
|
||||
[self.iconBgView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.right.equalTo(self);
|
||||
make.top.equalTo(self.nameLabel.mas_bottom);
|
||||
make.height.mas_equalTo(16);
|
||||
}];
|
||||
|
||||
self.rankBtn = [[UIButton alloc] init];
|
||||
[self.rankBtn setImage:[UIImage imageNamed:@"room_rank_value_icon"] forState:(UIControlStateNormal)];
|
||||
[self.rankBtn setTitle:@" 0" forState:(UIControlStateNormal)];
|
||||
self.rankBtn.titleLabel.font = [UIFont systemFontOfSize:14];
|
||||
[self.rankBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
|
||||
[self addSubview:self.rankBtn];
|
||||
[self.rankBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.right.equalTo(self);
|
||||
make.top.equalTo(self.iconBgView.mas_bottom);
|
||||
make.height.mas_equalTo(16);
|
||||
}];
|
||||
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user