2024-06-17 17:20:08 +08:00
|
|
|
|
//
|
|
|
|
|
// XPHomePagingViewController.m
|
|
|
|
|
// YuMi
|
|
|
|
|
//
|
|
|
|
|
// Created by P on 2024/6/16.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#import "XPHomePagingViewController.h"
|
|
|
|
|
|
2024-06-18 17:38:13 +08:00
|
|
|
|
#import "XPNewHomeViewController.h"
|
|
|
|
|
#import "XPHomeMineViewController.h"
|
|
|
|
|
#import "XPRoomSearchContainerViewController.h"
|
2025-07-02 15:52:48 +08:00
|
|
|
|
#import "XPWebViewController.h"
|
2024-06-17 17:20:08 +08:00
|
|
|
|
|
2024-08-08 19:46:25 +08:00
|
|
|
|
#import "Api+Gift.h"
|
|
|
|
|
#import "XPGiftStorage.h"
|
2025-07-02 15:52:48 +08:00
|
|
|
|
#import "FirstRechargeManager.h"
|
|
|
|
|
#import "FirstRechargeModel.h"
|
|
|
|
|
#import "YUMIHtmlUrl.h"
|
|
|
|
|
#import "YUMIMacroUitls.h"
|
2024-08-08 19:46:25 +08:00
|
|
|
|
|
2025-07-02 15:52:48 +08:00
|
|
|
|
@interface XPHomePagingViewController () <UIPageViewControllerDelegate, UIPageViewControllerDataSource, FirstRechargeManagerDelegate>
|
2024-06-18 17:38:13 +08:00
|
|
|
|
|
|
|
|
|
@property (nonatomic, strong) UIView *topControlView;
|
|
|
|
|
@property (nonatomic, strong) UIButton *mineButton;
|
|
|
|
|
@property (nonatomic, strong) UIButton *recommendButton;
|
|
|
|
|
|
|
|
|
|
@property (nonatomic, strong) UIPageViewController *pageContainer;
|
|
|
|
|
@property (nonatomic, strong) NSArray *viewControllers; // 存储子视图控制器的数组
|
|
|
|
|
@property (nonatomic, assign) NSUInteger currentIndex; // 当前显示的页面索引
|
|
|
|
|
|
|
|
|
|
@property (nonatomic, strong) XPNewHomeViewController *recommendVC;
|
|
|
|
|
@property (nonatomic, strong) XPHomeMineViewController *mineVC;
|
2024-06-17 17:20:08 +08:00
|
|
|
|
|
2025-07-02 15:52:48 +08:00
|
|
|
|
// 首充弹窗引用
|
|
|
|
|
@property (nonatomic, strong) XPWebViewController *firstChargeWebVC;
|
|
|
|
|
// 首充弹窗背景视图
|
|
|
|
|
@property (nonatomic, strong) UIView *firstChargeBackgroundView;
|
|
|
|
|
|
2024-06-17 17:20:08 +08:00
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@implementation XPHomePagingViewController
|
|
|
|
|
|
2025-07-02 15:52:48 +08:00
|
|
|
|
- (void)dealloc {
|
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
|
|
|
|
[FirstRechargeManager sharedManager].delegate = nil;
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-21 01:37:38 +08:00
|
|
|
|
- (BOOL)isHiddenNavBar {
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-17 17:20:08 +08:00
|
|
|
|
- (void)viewDidLoad {
|
|
|
|
|
[super viewDidLoad];
|
2024-06-18 17:38:13 +08:00
|
|
|
|
[self setup];
|
2025-07-02 15:52:48 +08:00
|
|
|
|
|
|
|
|
|
// 注册首充管理器监听
|
|
|
|
|
[FirstRechargeManager sharedManager].delegate = self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)viewDidAppear:(BOOL)animated {
|
|
|
|
|
[super viewDidAppear:animated];
|
|
|
|
|
|
|
|
|
|
// 启动首充监控
|
|
|
|
|
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
|
|
|
[[FirstRechargeManager sharedManager] startMonitoring];
|
|
|
|
|
});
|
2024-06-18 17:38:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)setup {
|
|
|
|
|
|
2024-11-05 17:09:22 +08:00
|
|
|
|
self.view.backgroundColor = [[ClientConfig shareConfig] bgColor];
|
2024-06-18 17:38:13 +08:00
|
|
|
|
|
|
|
|
|
[self setupTopTheme];
|
|
|
|
|
[self setupTopControl];
|
|
|
|
|
|
|
|
|
|
_pageContainer = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll
|
|
|
|
|
navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal
|
|
|
|
|
options:nil];
|
|
|
|
|
_pageContainer.delegate = self;
|
|
|
|
|
_pageContainer.dataSource = self;
|
|
|
|
|
_recommendVC = [[XPNewHomeViewController alloc] init];
|
|
|
|
|
_mineVC = [[XPHomeMineViewController alloc] init];
|
2024-06-21 01:37:38 +08:00
|
|
|
|
_viewControllers = @[_recommendVC, _mineVC];
|
2024-06-18 17:38:13 +08:00
|
|
|
|
[self didTapRecommendButton];
|
|
|
|
|
|
|
|
|
|
[self addChildViewController:_pageContainer];
|
|
|
|
|
[self.view addSubview:_pageContainer.view];
|
|
|
|
|
|
|
|
|
|
[self.pageContainer.view mas_makeConstraints:^(MASConstraintMaker *make) {
|
2024-07-30 20:16:21 +08:00
|
|
|
|
make.leading.bottom.trailing.mas_equalTo(self.view);
|
2024-06-18 17:38:13 +08:00
|
|
|
|
make.top.mas_equalTo(self.topControlView.mas_bottom);
|
|
|
|
|
}];
|
|
|
|
|
[self.pageContainer didMoveToParentViewController:self];
|
2024-06-21 01:37:38 +08:00
|
|
|
|
|
|
|
|
|
for (UIView *view in self.pageContainer.view.subviews) {
|
|
|
|
|
if ([view isKindOfClass:[UIScrollView class]]) {
|
|
|
|
|
UIScrollView *scrollView = (UIScrollView *)view;
|
|
|
|
|
scrollView.scrollEnabled = NO; // 禁用滚动
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-06-17 17:20:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-06-18 17:38:13 +08:00
|
|
|
|
- (void)setupTopTheme {
|
2024-11-05 17:09:22 +08:00
|
|
|
|
__block UIImageView *theme = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, kGetScaleWidth(140))];
|
2024-11-06 17:57:32 +08:00
|
|
|
|
theme.image = [[ClientConfig shareConfig] navigationAreaBG];
|
|
|
|
|
theme.contentMode = UIViewContentModeScaleAspectFill;
|
2024-06-18 17:38:13 +08:00
|
|
|
|
[self.view addSubview:theme];
|
2024-11-05 17:09:22 +08:00
|
|
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserverForName:[ClientConfig shareConfig].reloadNavigationAreaImageKey
|
|
|
|
|
object:nil
|
|
|
|
|
queue:[NSOperationQueue mainQueue]
|
|
|
|
|
usingBlock:^(NSNotification * _Nonnull notification) {
|
|
|
|
|
if ([notification.object isKindOfClass:[UIImage class]]) {
|
|
|
|
|
theme.image = (UIImage *)notification.object;
|
|
|
|
|
}
|
|
|
|
|
}];
|
2024-06-18 17:38:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)setupTopControl {
|
2024-06-21 01:37:38 +08:00
|
|
|
|
_topControlView = [[UIView alloc] initWithFrame:CGRectMake(0, 0,
|
|
|
|
|
KScreenWidth,
|
|
|
|
|
44+[UIApplication sharedApplication].keyWindow.safeAreaInsets.top)];
|
|
|
|
|
_topControlView.backgroundColor = [UIColor clearColor];
|
2024-06-18 17:38:13 +08:00
|
|
|
|
[self.view addSubview:_topControlView];
|
|
|
|
|
|
2024-06-21 01:37:38 +08:00
|
|
|
|
_recommendButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
|
|
|
[_recommendButton setTitle:YMLocalizedString(@"XPMonentsViewController2") forState:UIControlStateNormal];
|
|
|
|
|
[_recommendButton addTarget:self
|
|
|
|
|
action:@selector(didTapRecommendButton)
|
|
|
|
|
forControlEvents:UIControlEventTouchUpInside];
|
|
|
|
|
[_topControlView addSubview:_recommendButton];
|
|
|
|
|
[_recommendButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
2025-04-02 11:04:07 +08:00
|
|
|
|
make.bottom.mas_equalTo(self.topControlView).offset(-6);
|
2024-06-21 16:14:36 +08:00
|
|
|
|
make.width.mas_greaterThanOrEqualTo(40);
|
2025-04-02 11:04:07 +08:00
|
|
|
|
make.leading.mas_equalTo(self.topControlView).offset(12);
|
2024-06-21 01:37:38 +08:00
|
|
|
|
}];
|
|
|
|
|
|
2024-06-18 17:38:13 +08:00
|
|
|
|
_mineButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
2024-06-21 01:37:38 +08:00
|
|
|
|
[_mineButton setTitle:YMLocalizedString(@"TabbarViewController5") forState:UIControlStateNormal];
|
2024-06-18 17:38:13 +08:00
|
|
|
|
[_mineButton addTarget:self
|
|
|
|
|
action:@selector(didTapMineButton)
|
|
|
|
|
forControlEvents:UIControlEventTouchUpInside];
|
|
|
|
|
[_topControlView addSubview:_mineButton];
|
|
|
|
|
[_mineButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
2025-04-02 11:04:07 +08:00
|
|
|
|
make.bottom.mas_equalTo(self.topControlView).offset(-6);
|
2024-06-21 16:14:36 +08:00
|
|
|
|
make.width.mas_greaterThanOrEqualTo(40);
|
2024-07-30 20:16:21 +08:00
|
|
|
|
make.leading.mas_equalTo(_recommendButton.mas_trailing).offset(32);
|
2024-06-18 17:38:13 +08:00
|
|
|
|
}];
|
2024-06-17 17:20:08 +08:00
|
|
|
|
|
2024-06-18 17:38:13 +08:00
|
|
|
|
UIButton *searchButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
2024-06-27 21:31:00 +08:00
|
|
|
|
[searchButton setEnlargeEdgeWithTop:10 right:10 bottom:10 left:10];
|
2024-06-21 01:37:38 +08:00
|
|
|
|
[searchButton setBackgroundImage:[UIImage imageNamed:@"home_nav_search"] forState:UIControlStateNormal];
|
2024-06-18 17:38:13 +08:00
|
|
|
|
[searchButton addTarget:self
|
|
|
|
|
action:@selector(didTapSearchButton)
|
|
|
|
|
forControlEvents:UIControlEventTouchUpInside];
|
|
|
|
|
[_topControlView addSubview:searchButton];
|
|
|
|
|
[searchButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
2024-06-21 16:14:36 +08:00
|
|
|
|
make.centerY.mas_equalTo(self.mineButton);
|
2024-07-30 20:16:21 +08:00
|
|
|
|
make.trailing.mas_equalTo(self.topControlView).offset(-16);
|
2024-09-03 20:22:54 +08:00
|
|
|
|
make.width.height.mas_equalTo(28);
|
2024-06-21 16:14:36 +08:00
|
|
|
|
}];
|
2024-07-08 17:06:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-06-18 17:38:13 +08:00
|
|
|
|
- (void)displayMineTab {
|
2024-09-03 20:22:54 +08:00
|
|
|
|
[_mineButton.titleLabel setFont:kFontBold(20)];
|
|
|
|
|
[_recommendButton.titleLabel setFont:kFontRegular(16)];
|
|
|
|
|
[_mineButton setTitleColor:UIColorRGBAlpha(0x313131, 1) forState:UIControlStateNormal];
|
|
|
|
|
[_recommendButton setTitleColor:UIColorRGBAlpha(0x313131, 1) forState:UIControlStateNormal];
|
2024-06-18 17:38:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)displayRecommendTab {
|
2024-09-03 20:22:54 +08:00
|
|
|
|
[_mineButton.titleLabel setFont:kFontRegular(16)];
|
|
|
|
|
[_recommendButton.titleLabel setFont:kFontBold(20)];
|
|
|
|
|
[_recommendButton setTitleColor:UIColorRGBAlpha(0x313131, 1) forState:UIControlStateNormal];
|
|
|
|
|
[_mineButton setTitleColor:UIColorRGBAlpha(0x313131, 1) forState:UIControlStateNormal];
|
2024-06-18 17:38:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
- (void)didTapMineButton {
|
2024-06-21 01:37:38 +08:00
|
|
|
|
[self.pageContainer setViewControllers:@[self.viewControllers[1]]
|
2024-06-18 17:38:13 +08:00
|
|
|
|
direction:UIPageViewControllerNavigationDirectionReverse
|
|
|
|
|
animated:NO
|
|
|
|
|
completion:nil];
|
|
|
|
|
[self displayMineTab];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)didTapRecommendButton {
|
2024-06-21 01:37:38 +08:00
|
|
|
|
[self.pageContainer setViewControllers:@[self.viewControllers[0]]
|
2024-06-18 17:38:13 +08:00
|
|
|
|
direction:UIPageViewControllerNavigationDirectionForward
|
|
|
|
|
animated:NO
|
|
|
|
|
completion:nil];
|
|
|
|
|
[self displayRecommendTab];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)didTapSearchButton {
|
|
|
|
|
XPRoomSearchContainerViewController * searchVC = [[XPRoomSearchContainerViewController alloc] init];
|
|
|
|
|
searchVC.modalPresentationStyle = UIModalPresentationFullScreen;
|
|
|
|
|
[self.navigationController presentViewController:searchVC
|
|
|
|
|
animated:YES
|
|
|
|
|
completion:nil];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma mark - UIPageViewController Delegate & DataSource
|
|
|
|
|
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController {
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController {
|
|
|
|
|
return nil;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma mark - UIPageViewControllerDelegate
|
|
|
|
|
- (void)pageViewController:(UIPageViewController *)pageViewController willTransitionToViewControllers:(NSArray<UIViewController *> *)pendingViewControllers {
|
|
|
|
|
// 更新当前索引
|
|
|
|
|
self.currentIndex = [self.viewControllers indexOfObject:pendingViewControllers.firstObject];
|
|
|
|
|
if (self.currentIndex == 0) {
|
|
|
|
|
[self displayMineTab];
|
|
|
|
|
} else {
|
|
|
|
|
[self displayRecommendTab];
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-07-02 15:52:48 +08:00
|
|
|
|
|
|
|
|
|
- (void)tokenInvalid {
|
|
|
|
|
// 停止首充监控
|
|
|
|
|
[[FirstRechargeManager sharedManager] stopMonitoring];
|
|
|
|
|
|
|
|
|
|
// [super tokenInvalid];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#pragma mark - FirstRechargeManagerDelegate
|
|
|
|
|
|
|
|
|
|
- (void)firstRechargeManager:(FirstRechargeManager *)manager didCheckFirstRecharge:(FirstRechargeModel *)model shouldShow:(BOOL)shouldShow {
|
|
|
|
|
if (shouldShow && model.chargeStatus == NO) {
|
|
|
|
|
// 展示首充弹窗
|
|
|
|
|
[self showFirstRechargePopup:model];
|
|
|
|
|
|
|
|
|
|
// 标记今天已展示过(在展示后标记)
|
|
|
|
|
[[FirstRechargeManager sharedManager] markTodayShown];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)showFirstRechargePopup:(FirstRechargeModel *)model {
|
|
|
|
|
if (model.chargeStatus) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 如果已经有弹窗在显示,先移除它
|
|
|
|
|
[self removeFirstChargePopup];
|
|
|
|
|
|
|
|
|
|
// 创建背景视图
|
|
|
|
|
self.firstChargeBackgroundView = [[UIView alloc] initWithFrame:self.view.bounds];
|
|
|
|
|
self.firstChargeBackgroundView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
|
|
|
|
|
self.firstChargeBackgroundView.alpha = 0;
|
|
|
|
|
|
|
|
|
|
// 添加点击手势
|
|
|
|
|
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleBackgroundTap:)];
|
|
|
|
|
[self.firstChargeBackgroundView addGestureRecognizer:tapGesture];
|
|
|
|
|
|
|
|
|
|
// 添加到当前视图
|
|
|
|
|
[self.view addSubview:self.firstChargeBackgroundView];
|
|
|
|
|
|
|
|
|
|
// 创建并配置 web 视图
|
|
|
|
|
self.firstChargeWebVC = [[XPWebViewController alloc] initWithRoomUID:@""];
|
|
|
|
|
self.firstChargeWebVC.isPush = NO;
|
|
|
|
|
self.firstChargeWebVC.url = URLWithType(kFirstChargeHomeIndex);
|
|
|
|
|
|
|
|
|
|
[self addChildViewController:self.firstChargeWebVC];
|
|
|
|
|
[self.firstChargeBackgroundView addSubview:self.firstChargeWebVC.view];
|
|
|
|
|
[self.firstChargeWebVC didMoveToParentViewController:self];
|
|
|
|
|
|
|
|
|
|
self.firstChargeWebVC.view.backgroundColor = [UIColor clearColor];
|
|
|
|
|
self.firstChargeWebVC.webview.backgroundColor = [UIColor clearColor];
|
|
|
|
|
self.firstChargeWebVC.webview.opaque = NO;
|
|
|
|
|
self.firstChargeWebVC.webview.scrollView.backgroundColor = [UIColor clearColor];
|
|
|
|
|
self.firstChargeWebVC.view.frame = CGRectMake(0,
|
|
|
|
|
0,
|
|
|
|
|
kGetScaleWidth(305),
|
|
|
|
|
kGetScaleWidth(403));
|
|
|
|
|
self.firstChargeWebVC.view.center = self.firstChargeBackgroundView.center;
|
|
|
|
|
|
|
|
|
|
@kWeakify(self);
|
|
|
|
|
[self.firstChargeWebVC setUrlLoadCompleted:^(BOOL result, NSError * _Nullable error) {
|
|
|
|
|
@kStrongify(self);
|
|
|
|
|
[UIView animateWithDuration:0.5 animations:^{
|
|
|
|
|
self.firstChargeBackgroundView.alpha = 1;
|
2025-07-14 17:37:10 +08:00
|
|
|
|
} completion:^(BOOL finished) {
|
|
|
|
|
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
|
|
|
[self removeFirstChargePopup];
|
|
|
|
|
});
|
2025-07-02 15:52:48 +08:00
|
|
|
|
}];
|
|
|
|
|
}];
|
|
|
|
|
[self.firstChargeWebVC setDidTapCharge:^{
|
|
|
|
|
@kStrongify(self);
|
|
|
|
|
[self removeFirstChargePopup];
|
|
|
|
|
}];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 处理背景点击事件
|
|
|
|
|
- (void)handleBackgroundTap:(UITapGestureRecognizer *)gesture {
|
|
|
|
|
// 获取点击位置
|
|
|
|
|
CGPoint location = [gesture locationInView:self.firstChargeBackgroundView];
|
|
|
|
|
|
|
|
|
|
// 检查是否点击在 webView 区域外
|
|
|
|
|
if (self.firstChargeWebVC && self.firstChargeWebVC.view) {
|
|
|
|
|
CGRect webViewFrame = self.firstChargeWebVC.view.frame;
|
|
|
|
|
if (!CGRectContainsPoint(webViewFrame, location)) {
|
|
|
|
|
// 点击在 webView 外部,移除弹窗
|
|
|
|
|
[self removeFirstChargePopup];
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// 如果 webView 不存在,直接移除弹窗
|
|
|
|
|
[self removeFirstChargePopup];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 移除弹窗
|
|
|
|
|
- (void)removeFirstChargePopup {
|
|
|
|
|
if (self.firstChargeWebVC) {
|
|
|
|
|
[self.firstChargeWebVC willMoveToParentViewController:nil];
|
|
|
|
|
[self.firstChargeWebVC.view removeFromSuperview];
|
|
|
|
|
[self.firstChargeWebVC removeFromParentViewController];
|
|
|
|
|
self.firstChargeWebVC = nil;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (self.firstChargeBackgroundView) {
|
|
|
|
|
[self.firstChargeBackgroundView removeFromSuperview];
|
|
|
|
|
self.firstChargeBackgroundView = nil;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-17 17:20:08 +08:00
|
|
|
|
@end
|