// // YMDressUpShopViewController.m // YUMI // // Created by YUMI on 2022/7/28. // #import "XPDressUpShopViewController.h" ///Third #import #import #import #import ///Tool #import "DJDKMIMOMColor.h" #import "Api+DressUp.h" #import "YUMIMacroUitls.h" #import "UIImage+Utils.h" #import "AccountInfoStorage.h" #import "NSArray+Safe.h" ///Model #import "ActivityInfoModel.h" #import "WalletInfoModel.h" ///View #import "XPDressUpShopListViewController.h" #import "XPRoomViewController.h" #import "XPWebViewController.h" #import "XPMineDressUpViewController.h" #import "XPDressUpShopCardViewController.h" #import "XPMineRechargeViewController.h" @interface XPDressUpShopViewController () ///分页标题 @property (nonatomic, strong) NSArray *titles; ///分页控件 @property (nonatomic, strong) JXCategoryTitleView *titleView; ///分页lineView @property (nonatomic, strong) JXCategoryListContainerView *contentView; ///头饰 @property (nonatomic,strong) XPDressUpShopListViewController *headwearView; ///座驾 @property (nonatomic,strong) XPDressUpShopListViewController *carView; ///铭牌 @property (nonatomic,strong) XPDressUpShopListViewController *nameplateView; ///贵族资料卡 @property (nonatomic, strong) XPDressUpShopCardViewController *nobleView; ///公屏气泡 @property (nonatomic, strong) XPDressUpShopListViewController *bubbleView; ///轮播图 @property (nonatomic,strong) SDCycleScrollView *pi_BannerView; ///房间活动的列表 @property (nonatomic,copy) NSArray *activityList; ///容器view @property (nonatomic, strong) UIView *mainView; ///名字 @property (nonatomic, strong) UILabel *titleLabel; ///钻石图标 @property (nonatomic, strong) UIImageView *diamondImageView; ///钻石金额 @property (nonatomic, strong) UILabel *diamondLabel; ///赠送 @property (nonatomic, strong) UIButton *sendButton; @end @implementation XPDressUpShopViewController - (void)viewDidLoad { [super viewDidLoad]; [self requestActivityList]; [self initSubViews]; [self initSubViewConstraints]; [self addNavigationItemWithTitles:@[YMLocalizedString(@"XPDressUpShopViewController0")] titleColor:[DJDKMIMOMColor textThirdColor] isLeft:NO target:self action:@selector(rightButtonAction:) tags:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(buyDressSuccess) name:@"buyDressSuccessNoti" object:nil]; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self requestWallet]; } #pragma mark - Private Method - (void)initSubViews { self.title = YMLocalizedString(@"XPDressUpShopViewController1"); [self.view addSubview:self.pi_BannerView]; [self.view addSubview:self.titleView]; [self.view addSubview:self.contentView]; [self.view addSubview:self.mainView]; [self.mainView addSubview:self.titleLabel]; [self.mainView addSubview:self.diamondImageView]; [self.mainView addSubview:self.diamondLabel]; [self.mainView addSubview:self.sendButton]; } - (void)initSubViewConstraints { [self.pi_BannerView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.mas_equalTo(self.view); make.left.mas_equalTo(15); make.right.mas_equalTo(-15); make.height.mas_equalTo(100); }]; [self.titleView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.mas_equalTo(self.view); make.height.mas_equalTo(50); make.top.mas_equalTo(self.pi_BannerView.mas_bottom); }]; [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.mas_equalTo(self.view); make.bottom.mas_equalTo(self.mainView.mas_top); make.top.mas_equalTo(self.titleView.mas_bottom); }]; [self.mainView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.bottom.mas_equalTo(self.view); make.height.mas_equalTo(iPhoneXSeries ? 48+34 : 48); }]; [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(self.diamondImageView.mas_right).mas_offset(4); make.centerY.mas_equalTo(self.diamondImageView); make.height.mas_equalTo(17); }]; [self.diamondImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(15); make.size.mas_equalTo(CGSizeMake(15, 15)); make.top.mas_equalTo(18); }]; [self.diamondLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.mas_equalTo(self.titleLabel); make.left.mas_equalTo(self.titleLabel.mas_right).mas_offset(4); make.height.mas_equalTo(22); }]; [self.sendButton mas_makeConstraints:^(MASConstraintMaker *make) { make.size.mas_equalTo(CGSizeMake(72, 24)); make.right.mas_equalTo(-15); make.centerY.mas_equalTo(self.titleLabel); }]; } #pragma mark - notification - (void)buyDressSuccess { [self requestWallet]; } - (void)requestWallet { NSString * uid = [AccountInfoStorage instance].getUid; NSString * ticket = [AccountInfoStorage instance].getTicket; [Api getUserWalletInfo:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) { if (code == 200) { WalletInfoModel * model = [WalletInfoModel modelWithDictionary:data.data]; self.diamondLabel.text = model.diamonds; } } uid:uid ticket:ticket]; } - (void)requestActivityList { [Api dressupBannerList:^(BaseModel * _Nullable data, NSInteger code, NSString * _Nullable msg) { if (code == 200) { NSArray * array = [ActivityInfoModel modelsWithArray:data.data]; if (array.count <= 0) { [self.pi_BannerView mas_updateConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(0); }]; return; } self.activityList = array; NSMutableArray * picList = [NSMutableArray array]; [array enumerateObjectsUsingBlock:^(ActivityInfoModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { if (obj.bannerPic.length > 0) { [picList addObject:obj.bannerPic]; } }]; self.pi_BannerView.imageURLStringsGroup = picList; if (array.count > 1) { [self.pi_BannerView setAutoScroll:YES]; self.pi_BannerView.autoScrollTimeInterval = 3; } else { [self.pi_BannerView setAutoScroll:NO]; } } else { [self.pi_BannerView mas_updateConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(0); }]; } } type:@"3"]; } - (void)rightButtonAction:(UIButton *)sender { XPMineDressUpViewController *vc = [[XPMineDressUpViewController alloc] init]; [self.navigationController pushViewController:vc animated:YES]; } #pragma mark - JXCategoryViewDelegate - (NSInteger)numberOfListsInlistContainerView:(JXCategoryListContainerView *)listContainerView { return self.titles.count; } - (id)listContainerView:(JXCategoryListContainerView *)listContainerView initListForIndex:(NSInteger)index { if (index == 0) { return self.headwearView; } else if(index == 1) { return self.carView; } else if (index == 2) { return self.nameplateView; } else if (index == 3) { return self.nobleView; } return self.bubbleView; } // 点击选中或者滚动选中都会调用该方法。适用于只关心选中事件,不关心具体是点击还是滚动选中的。 - (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index { // 侧滑手势处理 self.navigationController.interactivePopGestureRecognizer.enabled = (index == 0); } #pragma mark - SDCycleScrollViewDelegate - (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index { if (self.activityList.count > index) { ActivityInfoModel * info = [self.activityList safeObjectAtIndex1:index]; if (info.skipType == ActivitySkipType_Room) { [XPRoomViewController openRoom:info.skipUri viewController:self.navigationController]; } else if(info.skipType == ActivitySkipType_Web) { XPWebViewController * webVC = [[XPWebViewController alloc] init]; webVC.url = info.skipUri; [self.navigationController pushViewController:webVC animated:YES]; } } } - (void)rechargeButtonAction:(UIButton *)sender { XPWebViewController * webVC =[[XPWebViewController alloc] init]; webVC.url = [NSString stringWithFormat:URLWithType(kThirdPartyPay),@"4",[YYUtility deviceID]]; webVC.isPush = YES; [self.navigationController pushViewController:webVC animated:YES]; } #pragma mark - Getters And Setters - (void)setCurrentIndex:(NSInteger)currentIndex { if (currentIndex < self.titles.count) { [self.titleView setDefaultSelectedIndex:currentIndex]; } } - (JXCategoryTitleView *)titleView { if (!_titleView) { _titleView = [[JXCategoryTitleView alloc] init]; _titleView.delegate = self; _titleView.titles = self.titles; _titleView.titleColor = [DJDKMIMOMColor secondTextColor]; _titleView.titleSelectedColor = [DJDKMIMOMColor mainTextColor]; _titleView.titleFont = [UIFont fontWithName:@"PingFang-SC-Medium" size:16]; _titleView.titleSelectedFont = [UIFont fontWithName:@"PingFang-SC-Medium" size:16]; _titleView.titleLabelAnchorPointStyle = JXCategoryTitleLabelAnchorPointStyleCenter; _titleView.contentScrollViewClickTransitionAnimationEnabled = NO; _titleView.defaultSelectedIndex = 0; _titleView.listContainer = self.contentView; JXCategoryIndicatorLineView *lineView = [[JXCategoryIndicatorLineView alloc] init]; lineView.indicatorColor = [DJDKMIMOMColor appMainColor]; lineView.indicatorWidth = 8.f; lineView.indicatorHeight = 4.f; lineView.indicatorCornerRadius = 2.f; _titleView.indicators = @[lineView]; } return _titleView; } - (JXCategoryListContainerView *)contentView { if (!_contentView) { _contentView = [[JXCategoryListContainerView alloc] initWithType:JXCategoryListContainerType_ScrollView delegate:self]; _contentView.scrollView.backgroundColor = [UIColor clearColor]; _contentView.defaultSelectedIndex = 0; } return _contentView; } - (NSArray *)titles { return @[YMLocalizedString(@"XPMineDressUpViewController1"), YMLocalizedString(@"XPMineDressUpViewController2"), YMLocalizedString(@"XPMineDressUpViewController3"), YMLocalizedString(@"XPMineDressUpViewController4"), YMLocalizedString(@"XPDressUpShopViewController6")]; } - (XPDressUpShopListViewController *)headwearView { if (!_headwearView) { _headwearView = [[XPDressUpShopListViewController alloc] init]; _headwearView.type = DressUpShopListType_HeadWear; } return _headwearView; } - (XPDressUpShopListViewController *)carView { if (!_carView) { _carView = [[XPDressUpShopListViewController alloc] init]; _carView.type = DressUpShopListType_Car; } return _carView; } - (XPDressUpShopListViewController *)nameplateView { if (!_nameplateView) { _nameplateView = [[XPDressUpShopListViewController alloc] init]; _nameplateView.type = DressUpShopListType_Nameplate; } return _nameplateView; } - (XPDressUpShopCardViewController *)nobleView { if (!_nobleView) { _nobleView = [[XPDressUpShopCardViewController alloc] init]; _nobleView.type = DressUpShopListType_Noble; } return _nobleView; } - (XPDressUpShopListViewController *)bubbleView { if (!_bubbleView) { _bubbleView = [[XPDressUpShopListViewController alloc] init]; _bubbleView.type = DressUpShopListType_Bubble; } return _bubbleView; } - (SDCycleScrollView *)pi_BannerView { if (!_pi_BannerView) { _pi_BannerView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectZero delegate:self placeholderImage:nil]; _pi_BannerView.pageControlAliment = SDCycleScrollViewPageContolAlimentCenter; _pi_BannerView.currentPageDotColor = [UIColor whiteColor]; _pi_BannerView.pageDotColor = [UIColor colorWithWhite:1 alpha:0.15]; _pi_BannerView.backgroundColor = [UIColor colorWithWhite:1 alpha:0.00]; _pi_BannerView.bannerImageViewContentMode = UIViewContentModeScaleAspectFill; _pi_BannerView.layer.masksToBounds = YES; _pi_BannerView.layer.cornerRadius = 12; } return _pi_BannerView; } - (UIView *)mainView { if (!_mainView) { _mainView = [[UIView alloc] init]; _mainView.backgroundColor = [UIColor whiteColor]; } return _mainView; } - (UILabel *)titleLabel { if (!_titleLabel) { _titleLabel = [[UILabel alloc] init]; _titleLabel.font = [UIFont systemFontOfSize:12 weight:UIFontWeightBold]; _titleLabel.textColor = [DJDKMIMOMColor textThirdColor]; _titleLabel.text = YMLocalizedString(@"XPDressUpShopViewController7"); } return _titleLabel; } - (UIImageView *)diamondImageView { if (!_diamondImageView) { _diamondImageView = [[UIImageView alloc] init]; _diamondImageView.image = [UIImage imageNamed:@"common_diamond"]; } return _diamondImageView; } - (UILabel *)diamondLabel { if (!_diamondLabel) { _diamondLabel = [[UILabel alloc] init]; _diamondLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightBold]; _diamondLabel.textColor = UIColorFromRGB(0xFFBC51); } return _diamondLabel; } - (UIButton *)sendButton { if (!_sendButton) { _sendButton = [UIButton buttonWithType:UIButtonTypeCustom]; [_sendButton setTitle:YMLocalizedString(@"XPDressUpShopViewController8") forState:UIControlStateNormal]; [_sendButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; [_sendButton addTarget:self action:@selector(rechargeButtonAction:) forControlEvents:UIControlEventTouchUpInside]; _sendButton.layer.masksToBounds = YES; _sendButton.layer.cornerRadius = 24/2; _sendButton.titleLabel.font = [UIFont systemFontOfSize:12]; [_sendButton setBackgroundImage:[UIImage gradientColorImageFromColors:@[[DJDKMIMOMColor confirmButtonGradientStartColor], [DJDKMIMOMColor confirmButtonGradientEndColor]] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(10, 10)] forState:UIControlStateNormal]; } return _sendButton; } @end