123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249 |
- //
- // YMGuestViewController.m
- // MSYOUPAI
- //
- // Created by YoMi on 2024/2/17.
- // Copyright © 2024 MS. All rights reserved.
- //
- #import "YMGuestViewController.h"
- #import "YMGuestViewModel.h"
- #import "YMGuestCell.h"
- #import "YMGuestUnlockPopupView.h"
- @interface YMGuestViewController()<UITableViewDataSource, UITableViewDelegate>
- /// 粉丝VM
- @property (nonatomic, strong) YMGuestViewModel *viewModel;
- /// 内容列表
- @property (nonatomic, strong) UITableView *contentTableView;
- /// 遮罩基础视图
- @property (nonatomic, strong) UIView *maskView;
- /// 模糊遮罩视图
- @property (nonatomic, strong) YMCustomEffectView *blurMaskView;
- /// 解锁全部访客按钮
- @property (nonatomic, strong) UIButton *unlockGuestBtn;
- @end
- @implementation YMGuestViewController
- @dynamic viewModel;
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- }
- - (void)viewWillAppear:(BOOL)animated{
- [super viewWillAppear:animated];
- self.maskView.hidden = [self.viewModel isHideMaskView];
- }
- - (void)ym_setupViews{
- [self.view addSubview:self.contentTableView];
- [self.view addSubview:self.maskView];
- [self.maskView addSubview:self.blurMaskView];
- [self.maskView addSubview:self.unlockGuestBtn];
- [self.view setNeedsUpdateConstraints];
- [self.view updateConstraintsIfNeeded];
- }
- - (void)updateViewConstraints{
- [self.contentTableView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.view).offset(kYMNavHeight);
- make.left.equalTo(self.view);
- make.right.equalTo(self.view);
- make.bottom.equalTo(self.view);
- }];
-
- [self.maskView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.view).offset(kYMNavHeight);
- make.left.equalTo(self.view);
- make.right.equalTo(self.view);
- make.bottom.equalTo(self.view);
- }];
-
- [self.blurMaskView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.maskView);
- make.left.equalTo(self.maskView);
- make.right.equalTo(self.maskView);
- make.bottom.equalTo(self.maskView);
- }];
-
- [self.unlockGuestBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.maskView).offset(adapt(24));
- make.right.equalTo(self.maskView).offset(adapt(-24));
- make.bottom.equalTo(self.maskView).offset(Is_iPhoneX ? adapt(-32) : adapt(-12));
- make.height.mas_equalTo(adapt(45));
- }];
-
- [super updateViewConstraints];
- }
- - (void)ym_bindViewModel{
- [self headerRefreshing];
-
- @weakify(self)
- [[self.viewModel.refreshUISubject takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id result) {
- @strongify(self)
- [self.contentTableView reloadData];
- switch ([result intValue]) {
- case YMHeaderRefresh_HasMoreData:
- case YMHeaderRefresh_HasNoMoreData:
- {
- [self.contentTableView.mj_header endRefreshing];
- [self.contentTableView.mj_footer endRefreshing];
- }
- break;
- case YMFooterRefresh_HasMoreData:
- {
- [self.contentTableView.mj_header endRefreshing];
- [self.contentTableView.mj_footer endRefreshing];
- if (self.contentTableView.mj_footer == self.noLoadMoreFooter) {
- self.contentTableView.mj_footer = self.loadMoreFooter;
- }
- }
- break;
- case YMFooterRefresh_HasNoMoreData:
- {
- [self.contentTableView.mj_header endRefreshing];
- [self.contentTableView.mj_footer endRefreshing];
- if (self.contentTableView.mj_footer == self.loadMoreFooter) {
- self.contentTableView.mj_footer = self.noLoadMoreFooter;
- }
- }
- break;
- case YMRefreshError: {
- [self.contentTableView.mj_header endRefreshing];
- [self.contentTableView.mj_footer endRefreshing];
- }
- break;
- default:
- break;
- }
- [self.contentTableView ym_endLoading];
- }];
- }
- - (void)headerRefreshing{
- [self.contentTableView ym_startLoading];
- self.viewModel.currentPage = 1;
- [self.viewModel getGuestListData];
- }
- - (void)footerRefreshing{
- [self.contentTableView ym_startLoading];
- self.viewModel.currentPage++;
- [self.viewModel getGuestListData];
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return self.viewModel.listDataArray.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
-
- YMGuestCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([YMGuestCell class])];
- if (!cell) {
- cell = [[YMGuestCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:NSStringFromClass([YMGuestCell class])];
- }
- cell.selectionStyle = UITableViewCellSelectionStyleNone;
- [cell ym_bindViewModel:self.viewModel.listDataArray[indexPath.item]];
- return cell;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
- return adapt(85);
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- if (self.viewModel.listDataArray[indexPath.item].userId != 0) {
- [self.viewModel.gotoPersonalPageSubject sendNext:@(self.viewModel.listDataArray[indexPath.item].userId)];
- }
-
- }
- - (UITableView *)contentTableView{
- if (!_contentTableView) {
- _contentTableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
- _contentTableView.delegate = self;
- _contentTableView.dataSource = self;
- _contentTableView.estimatedRowHeight = 0;
- _contentTableView.estimatedSectionHeaderHeight = 0;
- _contentTableView.estimatedSectionFooterHeight = 0;
- _contentTableView.showsVerticalScrollIndicator = NO;
- _contentTableView.showsHorizontalScrollIndicator = NO;
- _contentTableView.separatorColor = UIColor.clearColor;
- _contentTableView.backgroundColor = UIColor.whiteColor;
- [_contentTableView registerClass:[YMGuestCell class] forCellReuseIdentifier:NSStringFromClass([YMGuestCell class])];
- _contentTableView.mj_header = self.refreshHeader;
- _contentTableView.mj_footer = self.noLoadMoreFooter;
- YMEmptyView *empty = [YMEmptyView emptyViewWithImageStr:@"ym_common_no_data_icon" titleStr:@"暂无数据" detailStr:@""];
- empty.imageSize = kEmptyViewSize;
- _contentTableView.ym_emptyView = empty;
- _contentTableView.ym_emptyView.autoShowEmptyView = NO;
- }
- return _contentTableView;
- }
- - (UIView *)maskView{
- if (!_maskView) {
- _maskView = [[UIView alloc]init];
- _maskView.hidden = YES;
- }
- return _maskView;
- }
- - (YMCustomEffectView *)blurMaskView{
- if (!_blurMaskView) {
- UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle: UIBlurEffectStyleLight];
- _blurMaskView = [[YMCustomEffectView alloc]initWithEffect:blurEffect intensity:0.15];
- _blurMaskView.userInteractionEnabled = YES;
- WS(weakSelf)
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init];
- [_blurMaskView addGestureRecognizer:tap];
- [[[tap rac_gestureSignal] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) {
- weakSelf.unlockGuestBtn.hidden = YES;
- YMGuestUnlockPopupView *customView = [[YMGuestUnlockPopupView alloc]init];
- YMPopupView *popupView = [YMPopupView initWithCustomView:customView parentView:weakSelf.maskView popStyle:YMPopupStyleFade dismissStyle:YMDismissStyleFade];
- popupView.priority = 999;
- popupView.cornerRadius = adapt(10);
- popupView.rectCorners = UIRectCornerAllCorners;
- popupView.positionStyle = YMPositionStyleCenter;
- popupView.isHideBg = NO;
- popupView.bgAlpha = 0.5;
- @weakify(popupView)
- customView.buttonBlock = ^(BOOL isConfirm) {
- @strongify(popupView)
- if (isConfirm) {
- if ([weakSelf.viewModel isNeedPurchaseMember]) {
- return;
- }
- }
- weakSelf.unlockGuestBtn.hidden = NO;
- [popupView dismissWithStyle:YMDismissStyleFade duration:2.0];
- };
- [popupView pop];
- }];
- }
- return _blurMaskView;
- }
- - (UIButton *)unlockGuestBtn{
- if (!_unlockGuestBtn) {
- _unlockGuestBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- _unlockGuestBtn.titleLabel.font = LCFont(15);
- [_unlockGuestBtn setTitle:@"解锁全部访客" forState:UIControlStateNormal];
- [_unlockGuestBtn setTitleColor:HexColorFromRGB(0xFFFFFF) forState:UIControlStateNormal];
- _unlockGuestBtn.layer.cornerRadius = adapt(10);
- [_unlockGuestBtn ym_setGradientBackgroundWithColors:kMainGradColors locations:kMainGradLocation startPoint:kMainGradStartP endPoint:kMainGradEndP];
- WS(weakSelf)
- [[[_unlockGuestBtn rac_signalForControlEvents:UIControlEventTouchUpInside] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id x) {
- if ([weakSelf.viewModel isNeedPurchaseMember]) {
- return;
- }
- }];
- }
- return _unlockGuestBtn;
- }
- @end
|