194 lines
6.0 KiB
Objective-C
194 lines
6.0 KiB
Objective-C
//
|
|
// XPFindNewFriendViewController.m
|
|
// xplan-ios
|
|
//
|
|
// Created by XY on 2023/3/6.
|
|
//
|
|
|
|
#import "XPFindNewFriendViewController.h"
|
|
///Third
|
|
#import <Masonry/Masonry.h>
|
|
#import <MJRefresh.h>
|
|
///Tool
|
|
#import "NSArray+Safe.h"
|
|
#import "ThemeColor.h"
|
|
///View
|
|
#import "XPFindNewFriendTableViewCell.h"
|
|
#import "XPHomeListEmptyTableViewCell.h"
|
|
#import "XPHomeBannerTableViewCell.h"
|
|
///VC
|
|
#import "XPWebViewController.h"
|
|
#import "XPRoomViewController.h"
|
|
#import "SessionViewController.h"
|
|
///Model
|
|
#import "UserInfoModel.h"
|
|
///P
|
|
#import "XPHomePresenter.h"
|
|
#import "XPHomeProtocol.h"
|
|
|
|
@interface XPFindNewFriendViewController ()<UITableViewDelegate, UITableViewDataSource, XPHomeBannerTableViewCellDelegate, XPHomeProtocol, XPFindNewFriendTableViewCellDelegate>
|
|
///列表
|
|
@property (nonatomic,strong) UITableView *tableView;
|
|
@property (nonatomic, copy) void(^scrollCallback)(UIScrollView *scrollView);
|
|
|
|
/// 数据源
|
|
@property (nonatomic, strong) NSMutableArray *dataSource;
|
|
|
|
///当前的页数
|
|
@property (nonatomic,assign) int page;
|
|
/// 没有新的数据了
|
|
@property (nonatomic,assign) BOOL hasNoMoreData;
|
|
|
|
@end
|
|
|
|
@implementation XPFindNewFriendViewController
|
|
|
|
- (XPHomePresenter *)createPresenter {
|
|
return [[XPHomePresenter alloc] init];
|
|
}
|
|
|
|
- (BOOL)isHiddenNavBar {
|
|
return YES;
|
|
}
|
|
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
[self initSubViews];
|
|
[self initSubViewConstraints];
|
|
[self requestData:nil];
|
|
}
|
|
|
|
#pragma mark - InitHttp
|
|
|
|
- (void)requestData:(nullable NSString *)gender {
|
|
[self.presenter getNewFriendListWithGender:gender];
|
|
}
|
|
|
|
/// 刷新数据,可见时才调用
|
|
- (void)refreshData:(nullable NSString *)gender {
|
|
if (self.isViewLoaded && self.view.window) {
|
|
[self requestData:gender];
|
|
}
|
|
}
|
|
|
|
#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);
|
|
}];
|
|
}
|
|
|
|
#pragma mark - XPFindNewFriendTableViewCellDelegate
|
|
|
|
|
|
|
|
#pragma mark - XPHomeProtocol
|
|
|
|
- (void)getNewFriendListSuccess:(NSArray *)list {
|
|
[self.dataSource removeAllObjects];
|
|
[self.dataSource addObjectsFromArray:list];
|
|
[self.tableView reloadData];
|
|
}
|
|
|
|
- (void)getNewFriendListFail {
|
|
|
|
}
|
|
|
|
#pragma mark - UITableViewDelegate And UITableViewDataSource
|
|
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
|
return self.dataSource.count > 0 ? self.dataSource.count : 1;
|
|
}
|
|
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
if (self.dataSource.count > 0) {
|
|
return 105;
|
|
}
|
|
return 300;
|
|
}
|
|
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
if (self.dataSource.count > 0) {
|
|
UserInfoModel * model = [self.dataSource safeObjectAtIndex1:indexPath.row];
|
|
XPFindNewFriendTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPFindNewFriendTableViewCell class])];
|
|
cell.roomInfo = model;
|
|
cell.delegate = self;
|
|
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];
|
|
if (self.dataSource.count > 0) {
|
|
UserInfoModel *model = [self.dataSource safeObjectAtIndex1:indexPath.row];
|
|
if (model.inRoomUid.length > 0) {
|
|
if (model.inMic) {
|
|
[XPRoomViewController openRoom:model.inRoomUid fromNick:model.nick fromType:UserEnterRoomFromType_Follow_User fromUid:[NSString stringWithFormat:@"%ld",model.uid] viewController:self];
|
|
}else{
|
|
[XPRoomViewController openRoom:model.inRoomUid fromNick:nil fromType:UserEnterRoomFromType_Home_Recommend fromUid:nil viewController:self];
|
|
}
|
|
}else{
|
|
/// 跳聊天
|
|
NSString * sessionId = [NSString stringWithFormat:@"%ld",model.uid];
|
|
NIMSession * session = [NIMSession session:sessionId type:NIMSessionTypeP2P];
|
|
SessionViewController * sessionVC = [[SessionViewController alloc] initWithSession:session];
|
|
[self.navigationController pushViewController:sessionVC animated:YES];
|
|
}
|
|
}
|
|
}
|
|
|
|
#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;
|
|
}
|
|
|
|
- (NSMutableArray *)dataSource {
|
|
if (!_dataSource) {
|
|
_dataSource = [NSMutableArray array];
|
|
}
|
|
return _dataSource;
|
|
}
|
|
|
|
|
|
@end
|