Files
peko-ios/YuMi/Modules/YMMine/View/Friend/XPMineFansViewController.m
2025-03-14 19:43:04 +08:00

252 lines
9.2 KiB
Objective-C

//
// XPMineFansViewController.m
// xplan-ios
//
// Created by 冯硕 on 2021/12/21.
//
#import "XPMineFansViewController.h"
///Third
#import <Masonry/Masonry.h>
#import <MJRefresh/MJRefresh.h>
///Tool"
///Model
#import "FansInfoModel.h"
///View
#import "XPMineFriendEmptyTableViewCell.h"
#import "XPMineFansTableViewCell.h"
///P
#import "XPMineFansPresenter.h"
#import "XPMineFansProtocol.h"
///VC
#import "XPMineUserInfoViewController.h"
#import "SessionViewController.h"
#import <JXPagingView/JXPagerView.h>
@interface XPMineFansViewController ()<UITableViewDelegate,UITableViewDataSource, XPMineFansProtocol, XPMineFansTableViewCellDelegate,JXPagerViewListViewDelegate>
///列表
@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 XPMineFansViewController
- (BOOL)isHiddenNavBar {
return self.type == ContactUseingType_In_Room || self.type == ContactUseingType_In_Session ? YES : NO;
}
- (XPMineFansPresenter *)createPresenter {
return [[XPMineFansPresenter alloc] init];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.tableView reloadData];
}
- (void)viewDidLoad {
[super viewDidLoad];
[self initHeaderAndFooterRrfresh];
[self initSubViews];
[self initSubViewConstraints];
}
#pragma mark - 下拉刷新
- (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 = [DJDKMIMOMColor secondTextColor];
header.lastUpdatedTimeLabel.textColor = [DJDKMIMOMColor secondTextColor];
self.tableView.mj_header = header;
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;
[self headerRefresh];
}
#pragma mark - 刷新的fangfa
- (void)headerRefresh {
self.page = 1;
[self.presenter getUserFansList:self.page pageSize:20 state:0];
}
- (void)footerRefresh {
if (self.hasNoMoreData) {
[self showErrorToast:YMLocalizedString(@"XPMineFansViewController0")];
return;
}
self.page++;
[self.presenter getUserFansList:self.page pageSize:20 state:1];
}
#pragma mark - Private Method
- (void)initSubViews {
// self.view.backgroundColor = [UIColor whiteColor];
self.title = YMLocalizedString(@"XPMineFansViewController1");
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);
}];
}
#pragma mark - XPMineFansProtocol
- (void)getUserFansListSuccess:(NSArray *)array state:(int)state {
if (state == 0) {
[self.datasource removeAllObjects];
[self.tableView.mj_header endRefreshing];
} else {
[self.tableView.mj_footer endRefreshing];
}
if (array.count > 0) {
self.hasNoMoreData = NO;
[self.datasource addObjectsFromArray:array];
} else {
self.hasNoMoreData = YES;
[self.tableView.mj_footer endRefreshingWithNoMoreData];
}
[self.tableView reloadData];
}
- (void)getUserFansListFail:(int)state {
if (state == 0) {
[self.tableView.mj_header endRefreshing];
} else {
[self.tableView.mj_footer endRefreshing];
}
}
- (void)attentionFansSuccess {
/// 因为不知道是不是接口请求的问题 需要等一会才能 和云信的好友关系同步 所以加个延迟吧
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self showSuccessToast:YMLocalizedString(@"XPMineFansViewController2")];
[self.tableView reloadData];
});
}
#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) {
XPMineFansTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPMineFansTableViewCell class])];
if (cell == nil) {
cell = [[XPMineFansTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([XPMineFansTableViewCell class])];
}
cell.delegate = self;
FansInfoModel * fansInfo = [self.datasource xpSafeObjectAtIndex:indexPath.row];
fansInfo.useingType = self.type;
cell.fansInfo = fansInfo;
return cell;
}
XPMineFriendEmptyTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPMineFriendEmptyTableViewCell class])];
if (cell == nil) {
cell = [[XPMineFriendEmptyTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([XPMineFriendEmptyTableViewCell class])];
}
cell.emptyTitle = YMLocalizedString(@"XPMineFansViewController3");
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if (self.datasource.count > 0) {
FansInfoModel * fansInfoModel = [self.datasource xpSafeObjectAtIndex:indexPath.row];
if (self.type == ContactUseingType_In_Room) {
SessionViewController * sessionVC = [[SessionViewController alloc] initWithSession:[NIMSession session:fansInfoModel.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 if(self.type == ContactUseingType_Share) {
if (self.delegate && [self.delegate respondsToSelector:@selector(xPMineFansViewController:didSelectItem:)]) {
[self.delegate xPMineFansViewController:self didSelectItem:fansInfoModel];
}
} else {
XPMineUserInfoViewController * userInfoVC = [[XPMineUserInfoViewController alloc] init];
userInfoVC.uid = fansInfoModel.uid.integerValue;
[self.navigationController pushViewController:userInfoVC 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 - mark
- (void)xPMineFansTableViewCell:(XPMineFansTableViewCell *)view didClickAttention:(NSString *)uid {
if (uid.length > 0) {
[self.presenter attentionFans:uid];
}
}
#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:[XPMineFriendEmptyTableViewCell class] forCellReuseIdentifier:NSStringFromClass([XPMineFriendEmptyTableViewCell class])];
[_tableView registerClass:[XPMineFansTableViewCell class] forCellReuseIdentifier:NSStringFromClass([XPMineFansTableViewCell class])];
}
return _tableView;
}
- (NSMutableArray *)datasource {
if (!_datasource) {
_datasource = [NSMutableArray array];
}
return _datasource;
}
@end