Files
peko-ios/YuMi/Modules/YMMine/View/Friend/XPMineFriendViewController.m
2025-03-21 16:19:07 +08:00

231 lines
8.7 KiB
Objective-C

//
// XPMineFriendViewController.m
// xplan-ios
//
// Created by 冯硕 on 2021/12/21.
//
#import "XPMineFriendViewController.h"
///Third
#import <Masonry/Masonry.h>
#import <MJRefresh/MJRefresh.h>
#import <NIMSDK/NIMSDK.h>
///Tool
///Model
#import "UserInfoModel.h"
///View
#import "XPMineFriendEmptyTableViewCell.h"
#import "XPMineFriendTableViewCell.h"
#import "SessionViewController.h"
#import "XPMineUserInfoViewController.h"
///P
#import "XPMineFriendPresenter.h"
#import "XPMineFriendProtocol.h"
@interface XPMineFriendViewController ()<UITableViewDelegate,UITableViewDataSource, XPMineFriendProtocol>
///列表
@property (nonatomic,strong) UITableView *tableView;
///数据源
@property (nonatomic,strong) NSMutableArray *datasource;
///当前页数
@property (nonatomic,assign) int page;
///更多数据
@property (nonatomic,assign) BOOL hasNoMoreData;
@property (nonatomic, copy) void(^scrollCallback)(UIScrollView *scrollView);
@end
@implementation XPMineFriendViewController
- (__kindof id)createPresenter {
return [[XPMineFriendPresenter alloc] init];
}
- (BOOL)isHiddenNavBar {
return self.type == ContactUseingType_In_Room || self.type == ContactUseingType_In_Session ? YES : NO;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.title = YMLocalizedString(@"XPTreasureFairyFriendView0");
self.datasource = @[].mutableCopy;
[self initSubViews];
[self initSubViewConstraints];
[self addRefreshControl];
[self addLoadControl];
self.page = 1;
if (self.isHiddenNavBar) {
[self loadData];
}else {
[self.tableView.mj_header beginRefreshing];
}
}
#pragma mark - Private Method
- (void)initSubViews {
if (self.isClearColor){
self.view.backgroundColor = [UIColor clearColor];
}else{
self.view.backgroundColor = [UIColor whiteColor];
}
[self.view addSubview:self.tableView];
}
- (void)initSubViewConstraints {
[self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.view);
}];
}
- (void)addRefreshControl {
MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(handlePullToRefresh)];
header.stateLabel.font = [UIFont systemFontOfSize:10.0];
header.lastUpdatedTimeLabel.font = [UIFont systemFontOfSize:10.0];
header.stateLabel.textColor = [DJDKMIMOMColor secondTextColor];
header.lastUpdatedTimeLabel.textColor = [DJDKMIMOMColor secondTextColor];
self.tableView.mj_header = header;
}
- (void)addLoadControl {
MJRefreshBackNormalFooter *footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(footerRefresh)];
footer.stateLabel.textColor = [DJDKMIMOMColor secondTextColor];
footer.stateLabel.font = [UIFont systemFontOfSize:10.0];
self.tableView.mj_footer = footer;
}
- (void)handlePullToRefresh {
self.page = 1;
[self loadData];
[self.tableView.mj_footer resetNoMoreData];
}
- (void)footerRefresh {
self.page += 1;
[self loadData];
}
- (void)loadData {
[self.presenter getFriends:self.page];
}
- (void)getFriendsList:(NSArray *)list {
if (self.page == 1) {
self.datasource = list.mutableCopy;
} else {
[self.datasource addObjectsFromArray:list];
}
[self.tableView reloadData];
[self.tableView.mj_header endRefreshing];
[self.tableView.mj_footer endRefreshing];
}
- (void)getFriendsFailure {
[self.tableView.mj_header endRefreshing];
[self.tableView.mj_footer endRefreshing];
}
#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 {
return self.datasource.count > 0 ? 92 : self.type == ContactUseingType_In_Room ? (KScreenHeight - kNavigationHeight) : (KScreenHeight - 200 - kNavigationHeight);
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (self.datasource.count > 0) {
XPMineFriendTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPMineFriendTableViewCell class])];
if (cell == nil) {
cell = [[XPMineFriendTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([XPMineFriendTableViewCell class])];
}
cell.userInfo = [self.datasource xpSafeObjectAtIndex:indexPath.row];
return cell;
}
XPMineFriendEmptyTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPMineFriendEmptyTableViewCell class])];
if (cell == nil) {
cell = [[XPMineFriendEmptyTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([XPMineFriendEmptyTableViewCell class])];
}
cell.emptyTitle = YMLocalizedString(@"XPMineFriendViewController0");
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if (self.datasource.count > 0) {
UserInfoModel * userInfo = [self.datasource xpSafeObjectAtIndex:indexPath.row];
if (self.isFromMineTab) {
XPMineUserInfoViewController * userInfoVC = [[XPMineUserInfoViewController alloc] init];
userInfoVC.uid = userInfo.uid;
[self.navigationController pushViewController:userInfoVC animated:YES];
}else {
if (self.type == ContactUseingType_Share) {
if (self.delegate && [self.delegate respondsToSelector:@selector(xPMineFriendViewController:didSelectItem:)]) {
[self.delegate xPMineFriendViewController:self didSelectItem:userInfo];
}
} else if(self.type == ContactUseingType_In_Room) {
SessionViewController * sessionVC = [[SessionViewController alloc] initWithSession:[NIMSession session:[NSString stringWithFormat:@"%ld", userInfo.uid] type:NIMSessionTypeP2P]];
sessionVC.openType = SessionListOpenTypeRoom;
CATransition *transition = [CATransition animation];
transition.duration = 0.3f;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromRight;
[self.mainController.view.layer addAnimation:transition forKey:nil];
[self.mainController addChildViewController:sessionVC];
[self.mainController.view addSubview:sessionVC.view];
} else {
SessionViewController * sessionVC = [[SessionViewController alloc] initWithSession:[NIMSession session:[NSString stringWithFormat:@"%ld", userInfo.uid] type:NIMSessionTypeP2P]];
if (self.type == ContactUseingType_Normal) {
sessionVC.openType = SessionListOpenTypeRoom;
} else {
sessionVC.openType = self.type == ContactUseingType_In_Session ? SessionListOpenTypeDefault : SessionListOpenTypeRoom;
}
[self.navigationController pushViewController:sessionVC animated:YES];
}
}
}
}
#pragma mark - JXCategoryListContentViewDelegate
- (UIView *)listView {
return self.view;
}
- (UIScrollView *)listScrollView {
return self.tableView;
}
- (void)listViewDidScrollCallback:(void (^)(UIScrollView *))callback {
self.scrollCallback = callback;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if(self.scrollCallback){
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];
_tableView.rowHeight = 65;
if (@available(iOS 11.0, *)) {
_tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}
[_tableView registerClass:[XPMineFriendEmptyTableViewCell class] forCellReuseIdentifier:NSStringFromClass([XPMineFriendEmptyTableViewCell class])];
[_tableView registerClass:[XPMineFriendTableViewCell class] forCellReuseIdentifier:NSStringFromClass([XPMineFriendTableViewCell class])];
}
return _tableView;
}
@end