Files
peko-ios/YuMi/Modules/YMMine/View/XPMineVisitorViewController.m

300 lines
11 KiB
Objective-C

//
// YMMineVisitorViewController.m
// YUMI
//
// Created by YUMI on 2022/1/26.
//
#import "XPMineVisitorViewController.h"
///Third
#import <Masonry/Masonry.h>
#import <MJRefresh/MJRefresh.h>
///Tool
#import "DJDKMIMOMColor.h"
#import "NSArray+Safe.h"
#import "ClientConfig.h"
///Model
#import "XPMineVisitorItemModel.h"
///View
#import "XPMineVisitorTableViewCell.h"
#import "XPMineVisitorEmptyTableViewCell.h"
///P
#import "XPMineVisitorPresenter.h"
#import "XPMineVisitorProtocol.h"
///VC
#import "XPMineUserInfoViewController.h"
#import "SessionViewController.h"
#import "VIPCenterViewController.h"
#import "XCCurrentVCStackManager.h"
#import "XPWebViewController.h"
@interface XPMineVisitorViewController ()<UITableViewDelegate,UITableViewDataSource, XPMineVisitorProtocol, XPMineVisitorTableViewCellDelegate>
///列表
@property (nonatomic,strong) UITableView *tableView;
///数据源
@property (nonatomic,strong) NSMutableArray *datasource;
///当前页数
@property (nonatomic,assign) int page;
///更多数据
@property (nonatomic,assign) BOOL hasNoMoreData;
@property(nonatomic, strong) UIVisualEffectView *blurEffectView;
@property(nonatomic, assign) BOOL vipVisible;
@property(nonatomic, assign) NSInteger vipLimit;
@end
@implementation XPMineVisitorViewController
- (instancetype)initWithVIPVisible:(BOOL)visit vipLimit:(NSInteger)visitListVipLimit {
if (self = [super init]) {
self.vipVisible = visit;
self.vipLimit = visitListVipLimit;
}
return self;
}
- (XPMineVisitorPresenter *)createPresenter {
return [[XPMineVisitorPresenter alloc] init];
}
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
[self initHeaderAndFooterRrfresh];
[self initSubViews];
[self initSubViewConstraints];
[self addBlurEffect];
}
- (void)addBlurEffect {
if (self.vipVisible) {
return;
}
UIVisualEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
self.blurEffectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
self.blurEffectView.backgroundColor = [UIColor clearColor];
[self.view addSubview:self.blurEffectView];
[self.blurEffectView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.view);
}];
UIView *container = [[UIView alloc] init];
[self.view addSubview:container];
[container mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.view);
}];
UIImageView *lock = [self lockImageView];
[container addSubview:lock];
UILabel *tipsLabel = [self lockTipsLabel];
[container addSubview:tipsLabel];
UIButton *lockButton = [self lockToVipButton];
[container addSubview:lockButton];
[tipsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.center.mas_equalTo(self.view);
}];
[lock mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.mas_equalTo(tipsLabel.mas_top).offset(-6);
make.centerX.mas_equalTo(self.view);
make.size.mas_equalTo(CGSizeMake(36, 36));
}];
[lockButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(tipsLabel.mas_bottom).offset(16);
make.centerX.mas_equalTo(self.view);
make.size.mas_equalTo(CGSizeMake(150, 38));
}];
}
#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 getVisitorList:self.page pageSize:20 state:0];
}
- (void)footerRefresh {
if (self.hasNoMoreData) {
[self showErrorToast:YMLocalizedString(@"XPMineVisitorViewController0")];
return;
}
self.page++;
[self.presenter getVisitorList:self.page pageSize:20 state:1];
}
#pragma mark - Private Method
- (void)initSubViews {
self.title = YMLocalizedString(@"XPMineVisitorViewController1");
[self.view addSubview:self.tableView];
}
- (void)initSubViewConstraints {
[self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.view);
}];
}
#pragma mark - XPMineVisitorProtocol
- (void)onGetVisitorListSuccess:(NSArray *)array state:(int)state {
if (state == 0) {
[self.datasource removeAllObjects];
[self.tableView.mj_header endRefreshing];
}
[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)getVisitorListFail:(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;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (self.datasource.count > 0) {
XPMineVisitorTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPMineVisitorTableViewCell class])];
if (cell == nil) {
cell = [[XPMineVisitorTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([XPMineVisitorTableViewCell class])];
}
cell.isFirstItem = indexPath.row == 0;
cell.isLastItem = indexPath.row == self.datasource.count - 1;
cell.delegate = self;
cell.item = [self.datasource xpSafeObjectAtIndex:indexPath.row];
return cell;
}
XPMineVisitorEmptyTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPMineVisitorEmptyTableViewCell class])];
if (cell == nil) {
cell = [[XPMineVisitorEmptyTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([XPMineVisitorEmptyTableViewCell class])];
}
cell.emptyTitle = YMLocalizedString(@"XPMineVisitorViewController2");
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 85;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
XPMineVisitorItemModel *item = [self.datasource xpSafeObjectAtIndex:indexPath.row];
XPMineUserInfoViewController * userInfoVC = [[XPMineUserInfoViewController alloc] init];
userInfoVC.uid = item.uid;
[self.navigationController pushViewController:userInfoVC animated:YES];
}
#pragma mark - TTVisitorRecordCellDelegate
- (void)onAvatarClick:(XPMineVisitorTableViewCell *)cell {
NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
XPMineVisitorItemModel *item = [self.datasource xpSafeObjectAtIndex:indexPath.row];
XPMineUserInfoViewController * userInfoVC = [[XPMineUserInfoViewController alloc] init];
userInfoVC.uid = item.uid;
[self.navigationController pushViewController:userInfoVC animated:YES];
}
- (void)onChatClick:(XPMineVisitorTableViewCell *)cell {
NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
XPMineVisitorItemModel *item = [self.datasource xpSafeObjectAtIndex:indexPath.row];
NSString * sessionId = [NSString stringWithFormat:@"%lld",item.uid];
NIMSession * session = [NIMSession session:sessionId type:NIMSessionTypeP2P];
SessionViewController * sessionVC = [[SessionViewController alloc] initWithSession:session];
[self.navigationController pushViewController:sessionVC animated:YES];
}
- (void)didTapVIPButton {
[self.navigationController popViewControllerAnimated:NO];
// VIPCenterViewController *vc = [[VIPCenterViewController alloc] initWithRoomUid:-1];
// [[XCCurrentVCStackManager shareManager].currentNavigationController pushViewController:vc animated:NO];
// [vc jumpToTargetVIP:self.vipLimit];
XPWebViewController * webVC =[[XPWebViewController alloc] initWithRoomUID:nil];
webVC.url = URLWithType(kVIP);
[self.navigationController pushViewController:webVC animated:YES];
}
#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:[XPMineVisitorEmptyTableViewCell class] forCellReuseIdentifier:NSStringFromClass([XPMineVisitorEmptyTableViewCell class])];
[_tableView registerClass:[XPMineVisitorTableViewCell class] forCellReuseIdentifier:NSStringFromClass([XPMineVisitorTableViewCell class])];
}
return _tableView;
}
- (NSMutableArray *)datasource {
if (!_datasource) {
_datasource = [NSMutableArray array];
}
return _datasource;
}
- (UIImageView *)lockImageView {
return [[UIImageView alloc] initWithImage:kImage(@"visitor_lock")];
}
- (UILabel *)lockTipsLabel {
return [UILabel labelInitWithText:[NSString stringWithFormat:YMLocalizedString(@"20.20.51_text_25"),
@(self.vipLimit)]
font:kFontMedium(14)
textColor:UIColorFromRGB(0x313131)];
}
- (UIButton *)lockToVipButton {
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button.titleLabel setFont:kFontMedium(16)];
[button setTitle:[NSString stringWithFormat:YMLocalizedString(@"20.20.51_text_26"),
@(self.vipLimit)]
forState:UIControlStateNormal];
[button setBackgroundImage:[UIImage gradientColorImageFromColors:@[
UIColorFromRGB(0xe28939), UIColorFromRGB(0xfcc074)
] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(150, 40)] forState:UIControlStateNormal];
[button addTarget:self action:@selector(didTapVIPButton) forControlEvents:UIControlEventTouchUpInside];
[button setCornerRadius:20];
return button;
}
@end