Files
yinmeng-ios/xplan-ios/Main/Mine/View/Friend/XPMineFansViewController.m
2022-09-14 19:14:09 +08:00

236 lines
7.9 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
#import "ThemeColor.h"
#import "XPMacro.h"
///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"
@interface XPMineFansViewController ()<UITableViewDelegate,UITableViewDataSource, XPMineFansProtocol, XPMineFansTableViewCellDelegate>
///列表
@property (nonatomic,strong) UITableView *tableView;
///数据源
@property (nonatomic,strong) NSMutableArray *datasource;
///当前页数
@property (nonatomic,assign) int page;
///更多数据
@property (nonatomic,assign) BOOL hasNoMoreData;
@end
@implementation XPMineFansViewController
- (BOOL)isHiddenNavBar {
return self.type == ContactUseingType_In_Room ? 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 = [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 getUserFansList:self.page pageSize:20 state:0];
}
- (void)footerRefresh {
if (self.hasNoMoreData) {
[self showErrorToast:@"没有更多房间了"];
return;
}
self.page++;
[self.presenter getUserFansList:self.page pageSize:20 state:1];
}
#pragma mark - Private Method
- (void)initSubViews {
self.title = @"我的粉丝";
[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:@"关注成功"];
[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 ? 65 : 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 objectAtIndex: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 = @"您还没有任何粉丝";
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if (self.datasource.count > 0) {
FansInfoModel * fansInfoModel = [self.datasource objectAtIndex: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;
}
#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];
_tableView.rowHeight = 65;
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