159 lines
5.8 KiB
Objective-C
159 lines
5.8 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
|
|
#import "ThemeColor.h"
|
|
#import "XPMacro.h"
|
|
#import "NSArray+Safe.h"
|
|
///Model
|
|
#import "UserInfoModel.h"
|
|
///View
|
|
#import "XPMineFriendEmptyTableViewCell.h"
|
|
#import "XPMineFriendTableViewCell.h"
|
|
#import "SessionViewController.h"
|
|
///P
|
|
#import "XPMineFriendPresenter.h"
|
|
#import "XPMineFriendProtocol.h"
|
|
|
|
@interface XPMineFriendViewController ()<UITableViewDelegate,UITableViewDataSource, XPMineFriendProtocol>
|
|
///列表
|
|
@property (nonatomic,strong) UITableView *tableView;
|
|
///数据源
|
|
@property (nonatomic,strong) NSArray *datasource;
|
|
///当前页数
|
|
@property (nonatomic,assign) int page;
|
|
///更多数据
|
|
@property (nonatomic,assign) BOOL hasNoMoreData;
|
|
@end
|
|
|
|
@implementation XPMineFriendViewController
|
|
|
|
- (__kindof id)createPresenter {
|
|
return [[XPMineFriendPresenter alloc] init];
|
|
}
|
|
|
|
- (BOOL)isHiddenNavBar {
|
|
return (self.type == ContactUseingType_In_Room || self.type == ContactUseingType_Normal) ? YES : NO;
|
|
}
|
|
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
NSArray * array = [[NIMSDK sharedSDK].userManager myFriends];
|
|
if (array.count > 0) {
|
|
NSMutableArray * uids = [NSMutableArray array];
|
|
for (int i = 0; i< array.count; i++) {
|
|
NIMUser * user = [array safeObjectAtIndex1:i];
|
|
[uids addObject:user.userId];
|
|
}
|
|
[self.presenter getUserListInfo:uids];
|
|
}
|
|
[self initSubViews];
|
|
[self initSubViewConstraints];
|
|
}
|
|
#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 - 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 ? 65 : 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 safeObjectAtIndex1: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 = @"您还没有任何好友";
|
|
return cell;
|
|
}
|
|
|
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
[tableView deselectRowAtIndexPath:indexPath animated:YES];
|
|
if (self.datasource.count > 0) {
|
|
UserInfoModel * userInfo = [self.datasource safeObjectAtIndex1:indexPath.row];
|
|
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]];
|
|
sessionVC.openType = SessionListOpenTypeRoom;
|
|
[self.navigationController pushViewController:sessionVC animated:YES];
|
|
}
|
|
}
|
|
}
|
|
|
|
#pragma mark - XPMineFriendProtocol
|
|
- (void)getUserListInfoSuccess:(NSArray *)list {
|
|
self.datasource = list;
|
|
[self.tableView reloadData];
|
|
}
|
|
|
|
#pragma mark - JXCategoryListContentViewDelegate
|
|
- (UIView *)listView {
|
|
return self.view;
|
|
}
|
|
|
|
#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
|