Files
peko-ios/YuMi/Modules/YMNewHome/View/XPHomePagingViewController.m

333 lines
13 KiB
Mathematica
Raw Normal View History

2024-06-17 17:20:08 +08:00
//
// XPHomePagingViewController.m
// YuMi
//
// Created by P on 2024/6/16.
//
#import "XPHomePagingViewController.h"
#import "XPNewHomeViewController.h"
#import "XPHomeMineViewController.h"
#import "XPRoomSearchContainerViewController.h"
#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"
#import "FirstRechargeManager.h"
#import "FirstRechargeModel.h"
#import "YUMIHtmlUrl.h"
#import "YUMIMacroUitls.h"
2024-08-08 19:46:25 +08:00
@interface XPHomePagingViewController () <UIPageViewControllerDelegate, UIPageViewControllerDataSource, FirstRechargeManagerDelegate>
@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
//
@property (nonatomic, strong) XPWebViewController *firstChargeWebVC;
//
@property (nonatomic, strong) UIView *firstChargeBackgroundView;
2024-06-17 17:20:08 +08:00
@end
@implementation XPHomePagingViewController
- (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];
[self setup];
//
[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];
});
}
- (void)setup {
self.view.backgroundColor = [[ClientConfig shareConfig] bgColor];
[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];
[self didTapRecommendButton];
[self addChildViewController:_pageContainer];
[self.view addSubview:_pageContainer.view];
[self.pageContainer.view mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.bottom.trailing.mas_equalTo(self.view);
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
}
- (void)setupTopTheme {
__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;
[self.view addSubview:theme];
[[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;
}
}];
}
- (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];
[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);
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
}];
_mineButton = [UIButton buttonWithType:UIButtonTypeCustom];
2024-06-21 01:37:38 +08:00
[_mineButton setTitle:YMLocalizedString(@"TabbarViewController5") forState:UIControlStateNormal];
[_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);
make.width.mas_greaterThanOrEqualTo(40);
make.leading.mas_equalTo(_recommendButton.mas_trailing).offset(32);
}];
2024-06-17 17:20:08 +08:00
UIButton *searchButton = [UIButton buttonWithType:UIButtonTypeCustom];
[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];
[searchButton addTarget:self
action:@selector(didTapSearchButton)
forControlEvents:UIControlEventTouchUpInside];
[_topControlView addSubview:searchButton];
[searchButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(self.mineButton);
make.trailing.mas_equalTo(self.topControlView).offset(-16);
make.width.height.mas_equalTo(28);
}];
2024-07-08 17:06:10 +08:00
}
- (void)displayMineTab {
[_mineButton.titleLabel setFont:kFontBold(20)];
[_recommendButton.titleLabel setFont:kFontRegular(16)];
[_mineButton setTitleColor:UIColorRGBAlpha(0x313131, 1) forState:UIControlStateNormal];
[_recommendButton setTitleColor:UIColorRGBAlpha(0x313131, 1) forState:UIControlStateNormal];
}
- (void)displayRecommendTab {
[_mineButton.titleLabel setFont:kFontRegular(16)];
[_recommendButton.titleLabel setFont:kFontBold(20)];
[_recommendButton setTitleColor:UIColorRGBAlpha(0x313131, 1) forState:UIControlStateNormal];
[_mineButton setTitleColor:UIColorRGBAlpha(0x313131, 1) forState:UIControlStateNormal];
}
#pragma mark -
- (void)didTapMineButton {
2024-06-21 01:37:38 +08:00
[self.pageContainer setViewControllers:@[self.viewControllers[1]]
direction:UIPageViewControllerNavigationDirectionReverse
animated:NO
completion:nil];
[self displayMineTab];
}
- (void)didTapRecommendButton {
2024-06-21 01:37:38 +08:00
[self.pageContainer setViewControllers:@[self.viewControllers[0]]
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];
}
}
- (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;
} completion:^(BOOL finished) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self removeFirstChargePopup];
});
}];
}];
[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