2021-12-21 18:10:33 +08:00
|
|
|
//
|
|
|
|
// XPMineAttentionViewController.m
|
|
|
|
// xplan-ios
|
|
|
|
//
|
|
|
|
// Created by 冯硕 on 2021/12/21.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "XPMineAttentionViewController.h"
|
|
|
|
///Third
|
|
|
|
#import <Masonry/Masonry.h>
|
|
|
|
#import <MJRefresh/MJRefresh.h>
|
|
|
|
///Tool
|
|
|
|
#import "ThemeColor.h"
|
2022-05-29 19:07:08 +08:00
|
|
|
#import "XPMacro.h"
|
2021-12-22 14:25:44 +08:00
|
|
|
///Model
|
|
|
|
#import "FansInfoModel.h"
|
2021-12-21 18:10:33 +08:00
|
|
|
///View
|
|
|
|
#import "XPMineAttentionTableViewCell.h"
|
|
|
|
#import "XPMineFriendEmptyTableViewCell.h"
|
|
|
|
///View
|
|
|
|
#import "XPMineFriendEmptyTableViewCell.h"
|
|
|
|
#import "XPMineAttentionTableViewCell.h"
|
|
|
|
///P
|
|
|
|
#import "XPMineAttentionPresenter.h"
|
|
|
|
#import "XPMineAttentionProtocol.h"
|
2021-12-22 14:25:44 +08:00
|
|
|
#import "RoomHostDelegate.h"
|
|
|
|
///VC
|
|
|
|
#import "XPMineUserInfoViewController.h"
|
|
|
|
#import "XPRoomViewController.h"
|
2022-05-29 19:07:08 +08:00
|
|
|
#import "SessionViewController.h"
|
2021-12-21 18:10:33 +08:00
|
|
|
|
2021-12-22 14:25:44 +08:00
|
|
|
@interface XPMineAttentionViewController ()<UITableViewDelegate,UITableViewDataSource, XPMineAttentionProtocol, XPMineAttentionTableViewCellDelegate>
|
2021-12-21 18:10:33 +08:00
|
|
|
///列表
|
|
|
|
@property (nonatomic,strong) UITableView *tableView;
|
|
|
|
///数据源
|
|
|
|
@property (nonatomic,strong) NSMutableArray *datasource;
|
|
|
|
///当前页数
|
|
|
|
@property (nonatomic,assign) int page;
|
|
|
|
///更多数据
|
|
|
|
@property (nonatomic,assign) BOOL hasNoMoreData;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation XPMineAttentionViewController
|
|
|
|
|
2022-05-29 19:07:08 +08:00
|
|
|
- (BOOL)isHiddenNavBar {
|
2022-06-27 20:04:54 +08:00
|
|
|
return self.type == ContactUseingType_In_Room ? YES : NO;
|
2022-05-29 19:07:08 +08:00
|
|
|
}
|
|
|
|
|
2021-12-21 18:10:33 +08:00
|
|
|
- (XPMineAttentionPresenter *)createPresenter {
|
|
|
|
return [[XPMineAttentionPresenter alloc] init];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (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 getUserAttentionList:self.page pageSize:20 state:0];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)footerRefresh {
|
|
|
|
if (self.hasNoMoreData) {
|
|
|
|
[self showErrorToast:@"没有更多数据了"];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
self.page++;
|
|
|
|
[self.presenter getUserAttentionList: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 - XPMineAttentionProtocol
|
|
|
|
- (void)getUserAttentionListSuccess:(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)getUserAttentionListFail:(int)state {
|
|
|
|
if (state == 0) {
|
|
|
|
[self.tableView.mj_header endRefreshing];
|
|
|
|
} else {
|
|
|
|
[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;
|
|
|
|
}
|
|
|
|
|
2022-05-29 19:07:08 +08:00
|
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
|
2022-06-27 20:04:54 +08:00
|
|
|
return self.datasource.count > 0 ? 65 : self.type == ContactUseingType_In_Room ? (KScreenHeight - kNavigationHeight) : (KScreenHeight - 200 - kNavigationHeight);
|
2022-05-29 19:07:08 +08:00
|
|
|
}
|
|
|
|
|
2021-12-21 18:10:33 +08:00
|
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
|
if (self.datasource.count > 0) {
|
|
|
|
XPMineAttentionTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPMineAttentionTableViewCell class])];
|
|
|
|
if (cell == nil) {
|
|
|
|
cell = [[XPMineAttentionTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([XPMineAttentionTableViewCell class])];
|
|
|
|
}
|
2021-12-22 14:25:44 +08:00
|
|
|
cell.delegate = self;
|
2022-05-29 19:07:08 +08:00
|
|
|
FansInfoModel * fansInfo = [self.datasource objectAtIndex:indexPath.row];
|
2022-06-27 20:04:54 +08:00
|
|
|
fansInfo.useingType = self.type;
|
2022-05-29 19:07:08 +08:00
|
|
|
cell.fansInfo = fansInfo;
|
2021-12-21 18:10:33 +08:00
|
|
|
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];
|
2021-12-22 14:25:44 +08:00
|
|
|
if (self.datasource.count > 0) {
|
2022-06-27 20:04:54 +08:00
|
|
|
FansInfoModel * fansInfoModel = [self.datasource objectAtIndex:indexPath.row];
|
|
|
|
if (self.type == ContactUseingType_In_Room) {
|
2022-05-29 19:07:08 +08:00
|
|
|
SessionViewController * sessionVC = [[SessionViewController alloc] initWithSession:[NIMSession session:fansInfoModel.uid type:NIMSessionTypeP2P]];
|
|
|
|
sessionVC.openType = SessionListOpenTypeRoom;
|
2022-09-14 19:14:09 +08:00
|
|
|
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];
|
2022-06-27 20:04:54 +08:00
|
|
|
} else if(self.type == ContactUseingType_Share){
|
|
|
|
if (self.delegate && [self.delegate respondsToSelector:@selector(xPMineAttentionViewController:didSelectItem:)]) {
|
|
|
|
[self.delegate xPMineAttentionViewController:self didSelectItem:fansInfoModel];
|
|
|
|
}
|
2022-05-29 19:07:08 +08:00
|
|
|
} else {
|
|
|
|
XPMineUserInfoViewController * userInfoVC = [[XPMineUserInfoViewController alloc] init];
|
|
|
|
userInfoVC.uid = fansInfoModel.uid.integerValue;
|
|
|
|
[self.navigationController pushViewController:userInfoVC animated:YES];
|
|
|
|
}
|
2021-12-22 14:25:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - XPMineAttentionTableViewCellDelegate
|
|
|
|
- (void)xPMineAttentionTableViewCell:(XPMineAttentionTableViewCell *)view findUser:(NSString *)uid {
|
|
|
|
//TODO:退出原来的房间 如果有的话 TODO 总感觉这种处理不太优雅 进房入口多了 怎么办 进房需要整合
|
|
|
|
[self.navigationController.viewControllers enumerateObjectsUsingBlock:^(__kindof UIViewController * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
|
|
|
if ([obj isKindOfClass:[XPRoomViewController class]]) {
|
|
|
|
[self.navigationController popToRootViewControllerAnimated:NO];
|
|
|
|
XPRoomViewController<RoomHostDelegate> * rooomVC = obj;
|
|
|
|
[rooomVC exitRoom];
|
|
|
|
*stop = YES;
|
|
|
|
}
|
|
|
|
}];
|
|
|
|
[XPRoomViewController openRoom:uid viewController:self];
|
2021-12-21 18:10:33 +08:00
|
|
|
}
|
|
|
|
|
2022-05-29 19:07:08 +08:00
|
|
|
#pragma mark - JXCategoryListContentViewDelegate
|
|
|
|
- (UIView *)listView {
|
|
|
|
return self.view;
|
|
|
|
}
|
|
|
|
|
2021-12-21 18:10:33 +08:00
|
|
|
#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:[XPMineAttentionTableViewCell class] forCellReuseIdentifier:NSStringFromClass([XPMineAttentionTableViewCell class])];
|
|
|
|
}
|
|
|
|
return _tableView;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSMutableArray *)datasource {
|
|
|
|
if (!_datasource) {
|
|
|
|
_datasource = [NSMutableArray array];
|
|
|
|
}
|
|
|
|
return _datasource;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|