2023-03-06 18:41:25 +08:00
|
|
|
|
//
|
|
|
|
|
// XPFindNewFriendViewController.m
|
|
|
|
|
// xplan-ios
|
|
|
|
|
//
|
|
|
|
|
// Created by XY on 2023/3/6.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#import "XPFindNewFriendViewController.h"
|
|
|
|
|
///Third
|
|
|
|
|
#import <Masonry/Masonry.h>
|
2023-03-09 21:44:59 +08:00
|
|
|
|
#import <MJRefresh.h>
|
|
|
|
|
///Tool
|
2023-03-06 18:41:25 +08:00
|
|
|
|
#import "NSArray+Safe.h"
|
2023-03-09 21:44:59 +08:00
|
|
|
|
#import "ThemeColor.h"
|
2023-03-06 18:41:25 +08:00
|
|
|
|
///View
|
|
|
|
|
#import "XPFindNewFriendTableViewCell.h"
|
|
|
|
|
#import "XPHomeListEmptyTableViewCell.h"
|
|
|
|
|
#import "XPHomeBannerTableViewCell.h"
|
|
|
|
|
///VC
|
|
|
|
|
#import "XPWebViewController.h"
|
|
|
|
|
#import "XPRoomViewController.h"
|
2023-03-13 19:50:02 +08:00
|
|
|
|
#import "SessionViewController.h"
|
2023-03-06 18:41:25 +08:00
|
|
|
|
///Model
|
2023-03-09 21:44:59 +08:00
|
|
|
|
#import "HomeRecommendRoomModel.h"
|
|
|
|
|
///P
|
|
|
|
|
#import "XPHomePresenter.h"
|
|
|
|
|
#import "XPHomeProtocol.h"
|
2023-03-06 18:41:25 +08:00
|
|
|
|
|
2023-03-13 19:50:02 +08:00
|
|
|
|
@interface XPFindNewFriendViewController ()<UITableViewDelegate, UITableViewDataSource, XPHomeBannerTableViewCellDelegate, XPHomeProtocol, XPFindNewFriendTableViewCellDelegate>
|
2023-03-06 18:41:25 +08:00
|
|
|
|
///列表
|
|
|
|
|
@property (nonatomic,strong) UITableView *tableView;
|
|
|
|
|
@property (nonatomic, copy) void(^scrollCallback)(UIScrollView *scrollView);
|
2023-03-09 21:44:59 +08:00
|
|
|
|
|
|
|
|
|
/// 数据源
|
|
|
|
|
@property (nonatomic, strong) NSMutableArray *dataSource;
|
|
|
|
|
|
|
|
|
|
///当前的页数
|
|
|
|
|
@property (nonatomic,assign) int page;
|
|
|
|
|
/// 没有新的数据了
|
|
|
|
|
@property (nonatomic,assign) BOOL hasNoMoreData;
|
|
|
|
|
@property (nonatomic,assign) NSString *tabId;
|
|
|
|
|
|
2023-03-06 18:41:25 +08:00
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@implementation XPFindNewFriendViewController
|
|
|
|
|
|
2023-03-09 21:44:59 +08:00
|
|
|
|
- (XPHomePresenter *)createPresenter {
|
|
|
|
|
return [[XPHomePresenter alloc] init];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (BOOL)isHiddenNavBar {
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-06 18:41:25 +08:00
|
|
|
|
- (void)viewDidLoad {
|
|
|
|
|
[super viewDidLoad];
|
|
|
|
|
[self initSubViews];
|
|
|
|
|
[self initSubViewConstraints];
|
2023-03-09 21:44:59 +08:00
|
|
|
|
self.tabId = @"3";
|
|
|
|
|
[self initHeaderAndFooterRrfresh];
|
2023-03-06 18:41:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-03-09 21:44:59 +08:00
|
|
|
|
/// 刷新数据,可见时才调用
|
|
|
|
|
- (void)refreshData {
|
|
|
|
|
if (self.isViewLoaded && self.view.window) {
|
|
|
|
|
[self headerRefresh];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (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];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma mark - 刷新的fangfa
|
|
|
|
|
- (void)headerRefresh {
|
|
|
|
|
self.page = 1;
|
|
|
|
|
[self.presenter getRecommendRoomList:self.tabId page:self.page pageSize:20 state:0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)footerRefresh {
|
|
|
|
|
if (self.hasNoMoreData) {
|
|
|
|
|
[self showErrorToast:@"没有更多房间了"];
|
|
|
|
|
[self.tableView.mj_footer endRefreshing];
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
self.page++;
|
|
|
|
|
[self.presenter getRecommendRoomList:self.tabId page:self.page pageSize:20 state:1];
|
2023-03-06 18:41:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma mark - Private Method
|
|
|
|
|
- (void)initSubViews {
|
|
|
|
|
self.view.backgroundColor = [UIColor clearColor];
|
|
|
|
|
[self.view addSubview:self.tableView];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)initSubViewConstraints {
|
|
|
|
|
[self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
|
|
make.edges.mas_equalTo(self.view);
|
|
|
|
|
}];
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-13 19:50:02 +08:00
|
|
|
|
#pragma mark - XPFindNewFriendTableViewCellDelegate
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-03-09 21:44:59 +08:00
|
|
|
|
#pragma mark - XPHomeProtocol
|
|
|
|
|
- (void)getHomeRecommendRoomListSuccess:(NSArray *)list state:(BOOL)state {
|
|
|
|
|
if (state == 0) {
|
|
|
|
|
self.hasNoMoreData = NO;
|
|
|
|
|
[self.dataSource removeAllObjects];
|
|
|
|
|
[self.tableView.mj_header endRefreshing];
|
|
|
|
|
} else {
|
|
|
|
|
[self.tableView.mj_footer endRefreshing];
|
|
|
|
|
}
|
|
|
|
|
if (list.count > 0) {
|
|
|
|
|
self.hasNoMoreData = NO;
|
|
|
|
|
[self.dataSource addObjectsFromArray:list];
|
|
|
|
|
} else {
|
|
|
|
|
self.hasNoMoreData = YES;
|
|
|
|
|
}
|
|
|
|
|
[self.tableView reloadData];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)getHomeRecommendRoomListFail:(NSString *)message state:(BOOL)state {
|
|
|
|
|
if (state == 0) {
|
|
|
|
|
[self.tableView.mj_header endRefreshing];
|
|
|
|
|
} else {
|
|
|
|
|
[self.tableView.mj_footer endRefreshing];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-06 18:41:25 +08:00
|
|
|
|
#pragma mark - UITableViewDelegate And UITableViewDataSource
|
|
|
|
|
|
|
|
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
2023-03-09 21:44:59 +08:00
|
|
|
|
return self.dataSource.count > 0 ? self.dataSource.count : 1;
|
2023-03-06 18:41:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
|
2023-03-09 21:44:59 +08:00
|
|
|
|
if (self.dataSource.count > 0) {
|
2023-03-06 18:41:25 +08:00
|
|
|
|
return 105;
|
|
|
|
|
}
|
|
|
|
|
return 300;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
2023-03-09 21:44:59 +08:00
|
|
|
|
if (self.dataSource.count > 0) {
|
|
|
|
|
HomeRecommendRoomModel * model = [self.dataSource safeObjectAtIndex1:indexPath.row];
|
2023-03-06 18:41:25 +08:00
|
|
|
|
XPFindNewFriendTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPFindNewFriendTableViewCell class])];
|
|
|
|
|
cell.roomInfo = model;
|
2023-03-13 19:50:02 +08:00
|
|
|
|
cell.delegate = self;
|
2023-03-06 18:41:25 +08:00
|
|
|
|
return cell;
|
|
|
|
|
}
|
|
|
|
|
XPHomeListEmptyTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPHomeListEmptyTableViewCell class])];
|
|
|
|
|
if (cell == nil) {
|
|
|
|
|
cell = [[XPHomeListEmptyTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([XPHomeListEmptyTableViewCell class])];
|
|
|
|
|
}
|
|
|
|
|
return cell;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
|
|
[tableView deselectRowAtIndexPath:indexPath animated:YES];
|
2023-03-09 21:44:59 +08:00
|
|
|
|
if (self.dataSource.count > 0) {
|
|
|
|
|
HomeRecommendRoomModel * model = [self.dataSource safeObjectAtIndex1:indexPath.row];
|
2023-03-13 19:50:02 +08:00
|
|
|
|
if (model.roomUid.integerValue > 0) {
|
2023-03-06 18:41:25 +08:00
|
|
|
|
[XPRoomViewController openRoom:model.uid fromNick:model.title fromType:UserEnterRoomFromType_Home_Recommend fromUid:nil viewController:self];
|
|
|
|
|
}
|
2023-03-13 19:50:02 +08:00
|
|
|
|
/// 跳聊天
|
|
|
|
|
// NSString * sessionId = [NSString stringWithFormat:@"%@",model.uid];
|
|
|
|
|
// NIMSession * session = [NIMSession session:sessionId type:NIMSessionTypeP2P];
|
|
|
|
|
// SessionViewController * sessionVC = [[SessionViewController alloc] initWithSession:session];
|
|
|
|
|
// [self.navigationController pushViewController:sessionVC animated:YES];
|
|
|
|
|
|
2023-03-06 18:41:25 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma mark - JXPagingViewListViewDelegate
|
|
|
|
|
- (UIView *)listView {
|
|
|
|
|
return self.view;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (UIScrollView *)listScrollView {
|
|
|
|
|
return self.tableView;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)listViewDidScrollCallback:(void (^)(UIScrollView *))callback {
|
|
|
|
|
self.scrollCallback = callback;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
|
|
|
|
|
self.scrollCallback(scrollView);
|
|
|
|
|
}
|
|
|
|
|
#pragma mark - Getters And Setters
|
|
|
|
|
|
|
|
|
|
- (UITableView *)tableView {
|
|
|
|
|
if (!_tableView) {
|
|
|
|
|
_tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
|
|
|
|
|
_tableView.delegate = self;
|
|
|
|
|
_tableView.dataSource = self;
|
|
|
|
|
_tableView.tableFooterView = [UIView new];
|
|
|
|
|
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
|
|
|
|
|
_tableView.backgroundColor = [UIColor clearColor];
|
|
|
|
|
if (@available(iOS 11.0, *)) {
|
|
|
|
|
_tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
|
|
|
|
|
}
|
|
|
|
|
[_tableView registerClass:[XPFindNewFriendTableViewCell class] forCellReuseIdentifier:NSStringFromClass([XPFindNewFriendTableViewCell class])];
|
|
|
|
|
[_tableView registerClass:[XPHomeListEmptyTableViewCell class] forCellReuseIdentifier:NSStringFromClass([XPHomeListEmptyTableViewCell class])];
|
|
|
|
|
}
|
|
|
|
|
return _tableView;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-09 21:44:59 +08:00
|
|
|
|
- (NSMutableArray *)dataSource {
|
|
|
|
|
if (!_dataSource) {
|
|
|
|
|
_dataSource = [NSMutableArray array];
|
|
|
|
|
}
|
|
|
|
|
return _dataSource;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-06 18:41:25 +08:00
|
|
|
|
|
|
|
|
|
@end
|