316 lines
11 KiB
Objective-C
316 lines
11 KiB
Objective-C
//
|
|
// QXIntimateContentView.m
|
|
// QXLive
|
|
//
|
|
// Created by 启星 on 2025/11/21.
|
|
//
|
|
|
|
#import "QXIntimateContentView.h"
|
|
#import "QXRoomBestFriendModel.h"
|
|
#import "QXMineNetwork.h"
|
|
#import "QXMoreIntimateViewController.h"
|
|
#import "QXButton.h"
|
|
#import "QXIntimateCpCell.h"
|
|
#import "QXIntimateNoCpCell.h"
|
|
#import "QXIntimateListCell.h"
|
|
#import "QXIntimateMoreListCell.h"
|
|
#import "QXUserCpCardView.h"
|
|
|
|
@interface QXIntimateContentView()<UITableViewDataSource,UITableViewDelegate>
|
|
@property (nonatomic,strong)UIView *tableHeaderView;
|
|
@property (nonatomic,strong)UIImageView *topImageView;
|
|
@property (nonatomic,strong)QXUserCpCardView *cpCardView;
|
|
@property (nonatomic,strong)UIView *noCpView;
|
|
@property (nonatomic,strong)UITableView *tableView;
|
|
@property (nonatomic,assign)NSInteger page;
|
|
@property (nonatomic,strong)NSMutableArray *dataArray;
|
|
@property (nonatomic,strong)QXRoomBestFriendModel *model;
|
|
@property (nonatomic, copy) void(^scrollCallback)(UIScrollView *scrollView);
|
|
@end
|
|
|
|
@implementation QXIntimateContentView
|
|
|
|
- (instancetype)initWithFrame:(CGRect)frame
|
|
{
|
|
self = [super initWithFrame:frame];
|
|
if (self) {
|
|
[self initSubviews];
|
|
}
|
|
return self;
|
|
}
|
|
-(void)initSubviews{
|
|
self.backgroundColor = RGB16(0xF5E8FF);
|
|
|
|
self.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.width, ScaleWidth(188))];
|
|
self.topImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"mine_intimate_top_bg"]];
|
|
self.topImageView.frame = CGRectMake(0, 0, self.width, ScaleWidth(241));
|
|
[self.tableHeaderView addSubview:self.topImageView];
|
|
[self.topImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.top.right.equalTo(self.tableHeaderView);
|
|
make.height.mas_equalTo(ScaleWidth(241));
|
|
}];
|
|
|
|
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"mine_intimate_title_bg"]];
|
|
UILabel *titleLabel = [[UILabel alloc] init];
|
|
titleLabel.font = [UIFont boldSystemFontOfSize:16];
|
|
titleLabel.textColor = RGB16(0xffffff);
|
|
titleLabel.text = @"心动";
|
|
[self.tableHeaderView addSubview:imageView];
|
|
[self.tableHeaderView addSubview:titleLabel];
|
|
[imageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.width.mas_equalTo(132);
|
|
make.height.mas_equalTo(36);
|
|
make.centerX.equalTo(self.tableHeaderView);
|
|
make.top.mas_equalTo(ScaleWidth(152));
|
|
}];
|
|
[titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.centerX.equalTo(imageView);
|
|
make.centerY.equalTo(imageView).offset(2);
|
|
}];
|
|
self.cpCardView = [[QXUserCpCardView alloc] init];
|
|
self.cpCardView.hidden = YES;
|
|
[self.tableHeaderView addSubview:self.cpCardView];
|
|
[self.cpCardView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.equalTo(imageView.mas_bottom).offset(16);
|
|
make.height.mas_equalTo(ScaleWidth(100));
|
|
make.left.mas_equalTo(24);
|
|
make.right.mas_equalTo(-24);
|
|
}];
|
|
|
|
self.noCpView = [[UIView alloc] init];
|
|
self.noCpView.hidden = YES;
|
|
[self.tableHeaderView addSubview:self.noCpView];
|
|
[self.noCpView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.mas_equalTo(24);
|
|
make.right.mas_equalTo(-24);
|
|
make.height.mas_equalTo(36);
|
|
make.top.equalTo(imageView.mas_bottom).offset(16);
|
|
}];
|
|
UIImageView *noCpImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"mine_intimate_no_cp_bg"]];
|
|
[self.noCpView addSubview:noCpImageView];
|
|
[noCpImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.edges.equalTo(self.noCpView);
|
|
}];
|
|
|
|
UILabel *noCpLabel = [[UILabel alloc] init];
|
|
noCpLabel.textAlignment = NSTextAlignmentCenter;
|
|
noCpLabel.font = [UIFont systemFontOfSize:12];
|
|
noCpLabel.text = @"暂无关系,前往房间互送特殊礼物达成关系吧";
|
|
noCpLabel.textColor = RGB16(0x624E79);
|
|
[self.noCpView addSubview:noCpLabel];
|
|
[noCpLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.edges.equalTo(self.noCpView);
|
|
}];
|
|
self.tableView.tableHeaderView = self.tableHeaderView;
|
|
[self addSubview:self.tableView];
|
|
}
|
|
-(void)layoutSubviews{
|
|
[super layoutSubviews];
|
|
self.tableView.frame = CGRectMake(0, 0, self.width, self.height);
|
|
}
|
|
-(void)setIsTopFloating:(BOOL)isTopFloating{
|
|
_isTopFloating = isTopFloating;
|
|
if (isTopFloating) {
|
|
[self addSubview:self.topImageView];
|
|
}else{
|
|
self.tableView.tableHeaderView = self.topImageView;
|
|
}
|
|
}
|
|
|
|
-(void)setUserId:(NSString *)userId{
|
|
_userId = userId;
|
|
self.cpCardView.userId = userId;
|
|
self.page = 1;
|
|
[self getList];
|
|
}
|
|
-(void)getList{
|
|
MJWeakSelf
|
|
[QXMineNetwork userBestFriendsListWithUserId:self.userId page:self.page successBlock:^(QXRoomBestFriendModel * _Nonnull model) {
|
|
weakSelf.model = model;
|
|
if (model.cp == nil) {
|
|
self.noCpView.hidden = NO;
|
|
self.cpCardView.hidden = YES;
|
|
self.tableHeaderView.width = SCREEN_WIDTH;
|
|
self.tableHeaderView.height = ScaleWidth(188)+16+ScaleWidth(36);
|
|
}else{
|
|
self.noCpView.hidden = YES;
|
|
self.cpCardView.hidden = NO;
|
|
self.tableHeaderView.width = SCREEN_WIDTH;
|
|
self.tableHeaderView.height = ScaleWidth(188)+16+ScaleWidth(100);
|
|
self.cpCardView.model = model.cp;
|
|
}
|
|
if (weakSelf.page == 1) {
|
|
[weakSelf.dataArray removeAllObjects];
|
|
}
|
|
[weakSelf.dataArray addObjectsFromArray:model.no_cp];
|
|
[weakSelf.tableView reloadData];
|
|
if (model.no_cp.count == 0) {
|
|
weakSelf.tableView.mj_footer.state = MJRefreshStateNoMoreData;
|
|
}else{
|
|
[weakSelf.tableView.mj_footer endRefreshing];
|
|
}
|
|
[weakSelf.tableView.mj_header endRefreshing];
|
|
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
|
|
|
|
}];
|
|
}
|
|
|
|
-(void)moreAction:(QXButton*)btn{
|
|
QXRoomBestFriendListModel *md = btn.object;
|
|
QXMoreIntimateViewController *vc = [[QXMoreIntimateViewController alloc] init];
|
|
vc.userId = self.userId;
|
|
vc.relation_id = md.relation_list.firstObject.relation_id;
|
|
vc.relation_name = md.relation_name;
|
|
[self.viewController.navigationController pushViewController:vc animated:YES];
|
|
}
|
|
|
|
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
|
|
return self.dataArray.count;
|
|
}
|
|
|
|
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
|
|
return 1;
|
|
}
|
|
|
|
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
|
|
QXRoomBestFriendListModel *md = self.dataArray[indexPath.section];
|
|
if (md.relation_list.count > 1) {
|
|
QXIntimateListCell*cell = [QXIntimateListCell cellWithTableView:tableView];
|
|
QXRoomBestFriendListModel *md = self.dataArray[indexPath.section];
|
|
cell.userId = self.userId;
|
|
cell.model = md;
|
|
return cell;
|
|
}else{
|
|
MJWeakSelf
|
|
QXIntimateMoreListCell *cell = [QXIntimateMoreListCell cellWithTableView:tableView];
|
|
cell.userId = self.userId;
|
|
cell.model = md.relation_list.firstObject;
|
|
cell.deleteSuccessBlock = ^(QXRelationshipListModel * _Nonnull model) {
|
|
weakSelf.page = 1;
|
|
[weakSelf getList];
|
|
};
|
|
return cell;
|
|
}
|
|
|
|
}
|
|
|
|
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
|
|
UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.width, 50)];
|
|
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"mine_intimate_title_bg"]];
|
|
UILabel *titleLabel = [[UILabel alloc] init];
|
|
titleLabel.font = [UIFont boldSystemFontOfSize:16];
|
|
titleLabel.textColor = RGB16(0xffffff);
|
|
QXButton *btn = [[QXButton alloc] init];
|
|
[btn setTitle:@"更多>>" forState:(UIControlStateNormal)];
|
|
[btn setTitleColor:RGB16(0xE973FC) forState:(UIControlStateNormal)];
|
|
btn.titleLabel.font = [UIFont systemFontOfSize:12];
|
|
[btn addTarget:self action:@selector(moreAction:) forControlEvents:(UIControlEventTouchUpInside)];
|
|
[header addSubview:btn];
|
|
[header addSubview:imageView];
|
|
[header addSubview:titleLabel];
|
|
[imageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.width.mas_equalTo(132);
|
|
make.height.mas_equalTo(36);
|
|
make.centerX.centerY.equalTo(header);
|
|
}];
|
|
[titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.centerX.equalTo(header);
|
|
make.centerY.equalTo(header).offset(2);
|
|
}];
|
|
[btn mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.right.mas_equalTo(-23);
|
|
make.top.bottom.equalTo(header);
|
|
make.width.mas_equalTo(40);
|
|
}];
|
|
|
|
QXRoomBestFriendListModel *md = self.dataArray[section];
|
|
titleLabel.text = md.relation_name;
|
|
if (md.relation_list.count>1) {
|
|
btn.hidden = NO;
|
|
btn.object = md;
|
|
}else{
|
|
btn.hidden = YES;
|
|
}
|
|
return header;
|
|
}
|
|
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
|
|
return 50;
|
|
}
|
|
|
|
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
|
|
QXRoomBestFriendListModel *md = self.dataArray[indexPath.section];
|
|
if (md.relation_list.count == 1) {
|
|
return ScaleWidth(92)+18;
|
|
}else{
|
|
if (md.relation_list.count == 0) {
|
|
return 0;
|
|
}else{
|
|
return ScaleWidth(125);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
|
|
UIView *footer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.width, 15)];
|
|
return footer;
|
|
}
|
|
|
|
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
|
|
return 15;
|
|
}
|
|
|
|
-(UITableView *)tableView{
|
|
if (!_tableView) {
|
|
_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.width, self.height) style:(UITableViewStyleGrouped)];
|
|
_tableView.dataSource = self;
|
|
_tableView.delegate = self;
|
|
_tableView.backgroundColor = [UIColor clearColor];
|
|
_tableView.tableFooterView = [UIView new];
|
|
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
|
|
if (@available(iOS 15.0, *)) {
|
|
_tableView.sectionHeaderTopPadding = 0;
|
|
} else {
|
|
// Fallback on earlier versions
|
|
}
|
|
MJWeakSelf
|
|
_tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
|
|
weakSelf.page = 1;
|
|
[weakSelf getList];
|
|
}];
|
|
_tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
|
|
weakSelf.page++;
|
|
[weakSelf getList];
|
|
}];
|
|
}
|
|
return _tableView;
|
|
}
|
|
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
|
|
if (self.scrollCallback != nil) {
|
|
self.scrollCallback(scrollView);
|
|
}
|
|
if (self.listScrollCallback != nil) {
|
|
self.listScrollCallback(scrollView);
|
|
}
|
|
}
|
|
#pragma mark - JXPagingViewListViewDelegate
|
|
|
|
- (UIScrollView *)listScrollView {
|
|
return self.tableView;
|
|
}
|
|
|
|
- (void)listViewDidScrollCallback:(void (^)(UIScrollView *))callback {
|
|
self.scrollCallback = callback;
|
|
}
|
|
|
|
- (UIView *)listView {
|
|
return self;
|
|
}
|
|
-(NSMutableArray *)dataArray{
|
|
if (!_dataArray) {
|
|
_dataArray = [NSMutableArray array];
|
|
}
|
|
return _dataArray;
|
|
}
|
|
@end
|