313 lines
11 KiB
Objective-C
313 lines
11 KiB
Objective-C
//
|
|
// XPHomeLikeViewController.m
|
|
// xplan-ios
|
|
//
|
|
// Created by 冯硕 on 2022/3/2.
|
|
//
|
|
|
|
#import "XPHomeLikeViewController.h"
|
|
///Third
|
|
#import <Masonry/Masonry.h>
|
|
#import <MJRefresh/MJRefresh.h>
|
|
///Tool
|
|
#import "XPMacro.h"
|
|
#import "ThemeColor.h"
|
|
#import "NSArray+Safe.h"
|
|
///Model
|
|
#import "HomeLiveRoomModel.h"
|
|
#import "HomeCollectRoomModel.h"
|
|
///View
|
|
#import "XPHomeAttentionTableViewCell.h"
|
|
#import "XPHomeCollectRoomTableViewCell.h"
|
|
#import "XPHomeLikeEmptyTableViewCell.h"
|
|
#import "XPHomeSectionView.h"
|
|
#import "XPMineAttentionViewController.h"
|
|
#import "XPRoomViewController.h"
|
|
#import "XPMineUserInfoViewController.h"
|
|
///P
|
|
#import "XPHomeLikePresenter.h"
|
|
#import "XPHomeLikeProtocol.h"
|
|
|
|
@interface XPHomeLikeViewController ()<UITableViewDataSource, UITableViewDelegate, XPHomeSectionViewDelegate, XPHomeLikeProtocol, XPHomeAttentionTableViewCellDelegate, XPHomeLikeEmptyTableViewCellDelegate>
|
|
///列表
|
|
@property (nonatomic,strong) UITableView *tableView;
|
|
///关注列表
|
|
@property (nonatomic,strong) NSArray *attentionList;
|
|
///收藏的房间
|
|
@property (nonatomic,strong) NSMutableArray *collectRoomList;
|
|
///当前的页数
|
|
@property (nonatomic,assign) int page;
|
|
@end
|
|
|
|
@implementation XPHomeLikeViewController
|
|
|
|
- (BOOL)isHiddenNavBar {
|
|
return YES;
|
|
}
|
|
|
|
- (XPHomeLikePresenter *)createPresenter {
|
|
return [[XPHomeLikePresenter alloc] init];
|
|
}
|
|
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
self.view.backgroundColor = [UIColor clearColor];
|
|
[self initHeaderAndFooterRrfresh];
|
|
[self initSubViews];
|
|
[self initSubViewConstraints];
|
|
}
|
|
|
|
- (void)viewWillAppear:(BOOL)animated {
|
|
[super viewWillAppear:animated];
|
|
[self headerRefresh];
|
|
}
|
|
|
|
#pragma mark - Private Method
|
|
- (void)initSubViews {
|
|
[self.view addSubview:self.tableView];
|
|
}
|
|
|
|
- (void)initSubViewConstraints {
|
|
[self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.edges.mas_equalTo(self.view);
|
|
}];
|
|
}
|
|
|
|
- (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.tableView.mj_header = header;
|
|
|
|
MJRefreshBackNormalFooter *footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(footerRefresh)];
|
|
footer.stateLabel.textColor = [ThemeColor secondTextColor];
|
|
footer.stateLabel.font = [UIFont systemFontOfSize:10.0];
|
|
self.tableView.mj_footer = footer;
|
|
|
|
[self headerRefresh];
|
|
}
|
|
|
|
- (void)headerRefresh {
|
|
self.page = 1;
|
|
[self.presenter getHomeAttectionList];
|
|
[self.presenter getHomeCollectRoomList:self.page state:0];
|
|
}
|
|
|
|
- (void)footerRefresh {
|
|
self.page++;
|
|
[self.presenter getHomeCollectRoomList:self.page state:1];
|
|
}
|
|
|
|
//去掉UItableview headerview黏性
|
|
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
|
|
CGFloat sectionHeaderHeight = 38;
|
|
if (scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=0) {
|
|
scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
|
|
} else if (scrollView.contentOffset.y>=sectionHeaderHeight) {
|
|
scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
|
|
}
|
|
}
|
|
|
|
#pragma mark - UITableViewDelegate And UITableViewDataSource
|
|
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
|
|
/// 关注的人 收藏的房间 空的展位图
|
|
return 3;
|
|
}
|
|
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
|
if (section == 0) {
|
|
return self.attentionList.count > 0 ? 1 : 0;
|
|
} else if(section == 1) {
|
|
return self.collectRoomList.count> 0 ? self.collectRoomList.count : 0;
|
|
} else {
|
|
return (self.collectRoomList.count <=0 && self.attentionList.count <=0) ? 1 : 0;
|
|
}
|
|
}
|
|
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
if (indexPath.section == 0) {
|
|
return 56 + 24 + 12 * 2;
|
|
} else if(indexPath.section == 1) {
|
|
return 66 + 8 + 10;
|
|
} else {
|
|
return KScreenHeight - kNavigationHeight - 49 - kSafeAreaBottomHeight - 50;
|
|
}
|
|
}
|
|
|
|
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
|
|
if (section == 0) {
|
|
return self.attentionList.count > 0 ? 38 : 0;
|
|
} else if(section == 1) {
|
|
return self.collectRoomList.count > 0 ? 38 : 0;
|
|
}
|
|
return 0.01f;
|
|
}
|
|
|
|
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
|
|
if (section == 0) {
|
|
XPHomeSectionView * sectionView = [[XPHomeSectionView alloc] init];
|
|
sectionView.frame = CGRectMake(0, 0, KScreenWidth, 38);
|
|
sectionView.tag = 1000 + section;
|
|
sectionView.isHiddenLogo = YES;
|
|
sectionView.title = @"关注的人";
|
|
sectionView.delegate= self;
|
|
return sectionView;
|
|
} else if (section == 1) {
|
|
XPHomeSectionView * sectionView = [[XPHomeSectionView alloc] init];
|
|
sectionView.frame = CGRectMake(0, 0, KScreenWidth, 38);
|
|
sectionView.isHiddenLogo = YES;
|
|
sectionView.title = @"收藏的房间";
|
|
sectionView.tag = 1000 + section;
|
|
sectionView.isHiddenMore = YES;
|
|
return sectionView;
|
|
}
|
|
return [UIView new];
|
|
}
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
|
|
return 0.01f;
|
|
}
|
|
|
|
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
|
|
return [[UIView alloc]init];
|
|
}
|
|
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
if (indexPath.section == 0) {
|
|
XPHomeAttentionTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPHomeAttentionTableViewCell class])];
|
|
if (cell == nil) {
|
|
cell = [[XPHomeAttentionTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([XPHomeAttentionTableViewCell class])];
|
|
}
|
|
cell.attentionList = self.attentionList;
|
|
cell.delegate = self;
|
|
return cell;
|
|
} else if(indexPath.section == 1) {
|
|
XPHomeCollectRoomTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPHomeCollectRoomTableViewCell class])];
|
|
if (cell == nil) {
|
|
cell = [[XPHomeCollectRoomTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([XPHomeCollectRoomTableViewCell class])];
|
|
}
|
|
cell.roomInfo = [self.collectRoomList safeObjectAtIndex1:indexPath.row];
|
|
return cell;
|
|
} else {
|
|
XPHomeLikeEmptyTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPHomeLikeEmptyTableViewCell class])];
|
|
if (cell == nil) {
|
|
cell = [[XPHomeLikeEmptyTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([XPHomeLikeEmptyTableViewCell class])];
|
|
}
|
|
cell.delegate = self;
|
|
return cell;
|
|
}
|
|
}
|
|
|
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
[tableView deselectRowAtIndexPath:indexPath animated:YES];
|
|
if (indexPath.section == 1 && self.collectRoomList.count > 0) {
|
|
HomeCollectRoomModel * roomInfo = [self.collectRoomList safeObjectAtIndex1:indexPath.row];
|
|
if (roomInfo.roomUid.integerValue > 0) {
|
|
[XPRoomViewController openRoom:roomInfo.roomUid viewController:self];
|
|
}
|
|
}
|
|
}
|
|
|
|
#pragma mark - XPHomeLikeProtocol
|
|
- (void)getHomeCollectRoomListFail:(NSString *)message state:(int)state {
|
|
if (state == 0) {
|
|
[self.tableView.mj_header endRefreshing];
|
|
} else {
|
|
[self.tableView.mj_footer endRefreshing];
|
|
}
|
|
}
|
|
|
|
- (void)getHomeCollectRoomListSuccess:(NSArray *)roomList state:(int)state {
|
|
if (state == 0) {
|
|
[self.collectRoomList removeAllObjects];
|
|
}
|
|
|
|
if (roomList.count > 0) {
|
|
[self.collectRoomList addObjectsFromArray:roomList];
|
|
}
|
|
|
|
if (state == 0) {
|
|
[self.tableView.mj_header endRefreshing];
|
|
} else {
|
|
if (roomList.count > 0) {
|
|
[self.tableView.mj_footer endRefreshing];
|
|
} else {
|
|
[self.tableView.mj_footer endRefreshingWithNoMoreData];
|
|
}
|
|
}
|
|
[self.tableView reloadData];
|
|
}
|
|
|
|
- (void)getHomeAttentionListSuccess:(NSArray *)liveList {
|
|
self.attentionList = liveList;
|
|
[self.tableView.mj_header endRefreshing];
|
|
[self.tableView reloadData];
|
|
}
|
|
|
|
- (void)getHomeAttentionListFail:(NSString *)message {
|
|
[self.tableView.mj_header endRefreshing];
|
|
}
|
|
|
|
#pragma mark - XPHomeSectionViewDelegate
|
|
- (void)didClickXPHomeSectionView:(XPHomeSectionView *)view {
|
|
XPMineAttentionViewController * attentionVC = [[XPMineAttentionViewController alloc] init];
|
|
[self.navigationController pushViewController:attentionVC animated:YES];
|
|
}
|
|
|
|
#pragma mark - XPHomeAttentionTableViewCellDelegate
|
|
- (void)xPHomeAttentionTableViewCell:(XPHomeAttentionTableViewCell *)view didClickItem:(HomeLiveRoomModel *)model {
|
|
if (model.roomUid > 0) {
|
|
[XPRoomViewController openRoom:[NSString stringWithFormat:@"%ld", model.uid] fromNick:model.nick fromType:UserEnterRoomFromType_Follow_User fromUid:[NSString stringWithFormat:@"%ld", model.roomUid] viewController:self];
|
|
} else {
|
|
if (model.uid > 0) {
|
|
XPMineUserInfoViewController * userInfoVC = [[XPMineUserInfoViewController alloc] init];
|
|
userInfoVC.uid = model.uid;
|
|
[self.navigationController pushViewController:userInfoVC animated:YES];
|
|
}
|
|
}
|
|
}
|
|
|
|
#pragma mark - XPHomeLikeEmptyTableViewCellDelegate
|
|
- (void)xPHomeLikeEmptyTableViewCell:(XPHomeLikeEmptyTableViewCell *)view didClickFriendChat:(UIButton *)sender {
|
|
if (self.delegate && [self.delegate respondsToSelector:@selector(xPHomeLikeViewControllerToFriendTab:)]) {
|
|
[self.delegate xPHomeLikeViewControllerToFriendTab:self];
|
|
}
|
|
}
|
|
|
|
#pragma mark - JXCategoryListContentViewDelegate
|
|
- (UIView *)listView {
|
|
return self.view;
|
|
}
|
|
|
|
#pragma mark - Getters And Setters
|
|
- (UITableView *)tableView {
|
|
if (!_tableView) {
|
|
_tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
|
|
_tableView.delegate = self;
|
|
_tableView.dataSource = self;
|
|
_tableView.tableHeaderView = [UIView new];
|
|
_tableView.tableFooterView = [UIView new];
|
|
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
|
|
_tableView.backgroundColor = [UIColor clearColor];
|
|
if (@available(iOS 11.0, *)) {
|
|
_tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
|
|
}
|
|
[_tableView registerClass:[XPHomeAttentionTableViewCell class] forCellReuseIdentifier:NSStringFromClass([XPHomeAttentionTableViewCell class])];
|
|
[_tableView registerClass:[XPHomeCollectRoomTableViewCell class] forCellReuseIdentifier:NSStringFromClass([XPHomeCollectRoomTableViewCell class])];
|
|
[_tableView registerClass:[XPHomeLikeEmptyTableViewCell class] forCellReuseIdentifier:NSStringFromClass([XPHomeLikeEmptyTableViewCell class])];
|
|
}
|
|
return _tableView;
|
|
}
|
|
|
|
- (NSMutableArray *)collectRoomList {
|
|
if (!_collectRoomList) {
|
|
_collectRoomList = [NSMutableArray array];
|
|
}
|
|
return _collectRoomList;
|
|
}
|
|
|
|
|
|
|
|
@end
|