Files
peko-ios/YuMi/Modules/YMRoom/View/SendRedPacket/PIRoomSendRedPacketVC.m
2023-11-01 20:42:47 +08:00

376 lines
14 KiB
Objective-C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// PIRoomSendRedPacketVC.m
// YuMi
//
// Created by duoban on 2023/10/18.
//
#import "PIRoomSendRedPacketVC.h"
#import <JXPagingView/JXPagerView.h>
#import <JXPagingView/JXPagerListRefreshView.h>
#import <JXCategoryView/JXCategoryView.h>
#import "PIRoomSendRedPacketItemVC.h"
#import "XPRoomRedPacketPresenter.h"
#import "WalletInfoModel.h"
#import "RoomInfoModel.h"
#import "XPIAPRechargeViewController.h"
#import "XCCurrentVCStackManager.h"
#import "XPRoomHalfWebView.h"
#import "XPWebViewController.h"
@interface PIRoomSendRedPacketVC ()<JXPagerViewDelegate,JXPagerMainTableViewGestureDelegate,JXCategoryViewDelegate,JXPagerMainTableViewGestureDelegate>
///host代理
@property (nonatomic,weak) id<RoomHostDelegate>hostDelegate;
///分页标题
@property (nonatomic, strong) NSArray<NSString *> *titles;
///分页控件
@property (nonatomic, strong) JXCategoryTitleView *titleView;
///分页lineView
@property (nonatomic, strong) JXPagerView *contentView;
///返回
@property(nonatomic,strong) UIButton *pi_backBtn;
///背景
@property(nonatomic,strong) UIView *bgView;
///隐藏键盘
@property(nonatomic,strong) UIButton *hiddenViewBnt;
///背景图片
@property(nonatomic,strong) UIImageView *topImageView;
///红包提示
@property(nonatomic,strong) UIButton *tipsBtn;
///钻石背景
@property(nonatomic,strong) UIImageView *pi_diamondNumView;
///钻石数量
@property(nonatomic,strong) UILabel *diamondNumTextView;
///钻石icom
@property(nonatomic,strong) UIImageView *diamondIconView;
//加号
@property(nonatomic,strong) UIImageView *addIconView;
///大厅红包
@property(nonatomic,strong) PIRoomSendRedPacketItemVC *roomRedVC;
///全服红包
@property(nonatomic,strong) PIRoomSendRedPacketItemVC *entireServerVC;
@end
@implementation PIRoomSendRedPacketVC
- (XPRoomRedPacketPresenter *)createPresenter {
return [[XPRoomRedPacketPresenter alloc] init];
}
- (instancetype)initWithDelegate:(id<RoomHostDelegate>)delegate {
if (self = [super init]) {
self.hostDelegate = delegate;
}
return self;
}
- (BOOL)isHiddenNavBar {
return YES;
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.presenter getUserWalletInfo];
}
///获取用户钱包信息成功
- (void)getUserWalletInfo:(WalletInfoModel *)balanceInfo {
self.diamondNumTextView.text = balanceInfo.diamonds;
self.roomRedVC.walletModel = balanceInfo;
self.entireServerVC.walletModel = balanceInfo;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor clearColor];
self.navigationController.view.backgroundColor = [UIColor clearColor];
[self.navigationController setNavigationBarHidden:YES];
RoomInfoModel *roomInfo = self.hostDelegate.getRoomInfo;
if(roomInfo.redEnvelopeType == 1){
self.titles = @[YMLocalizedString(@"PIRoomSendRedPacketVC0")];
}else if(roomInfo.redEnvelopeType == 2){
self.titles = @[YMLocalizedString(@"PIRoomSendRedPacketVC1")];
}else{
self.titles = @[YMLocalizedString(@"PIRoomSendRedPacketVC0"),YMLocalizedString(@"PIRoomSendRedPacketVC1")];
}
[self installUI];
[self installConstraints];
}
-(void)installUI{
[self.view addSubview:self.pi_backBtn];
[self.view addSubview:self.bgView];
[self.view addSubview:self.topImageView];
[self.view addSubview:self.hiddenViewBnt];
[self.view addSubview:self.tipsBtn];
[self.view addSubview:self.pi_diamondNumView];
[self.pi_diamondNumView addSubview:self.diamondIconView];
[self.pi_diamondNumView addSubview:self.diamondNumTextView];
[self.pi_diamondNumView addSubview:self.addIconView];
[self.view addSubview:self.contentView];
}
-(void)installConstraints{
[self.pi_backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.view);
}];
[self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.trailing.bottom.equalTo(self.view);
make.height.mas_equalTo(kGetScaleWidth(543));
}];
[self.topImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.bgView.mas_top).mas_offset(-kGetScaleWidth(120));
make.leading.trailing.equalTo(self.view);
make.height.mas_equalTo(kGetScaleWidth(243));
}];
[self.hiddenViewBnt mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.trailing.bottom.equalTo(self.view);
make.top.equalTo(self.topImageView.mas_top).mas_offset(kGetScaleWidth(50));
}];
[self.tipsBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.height.mas_equalTo(kGetScaleWidth(24));
make.trailing.mas_equalTo(-kGetScaleWidth(12));
make.top.equalTo(self.topImageView.mas_top).mas_offset(kGetScaleWidth(71));
}];
[self.pi_diamondNumView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.bgView.mas_top).mas_offset(kGetScaleWidth(13));
make.trailing.mas_equalTo(-kGetScaleWidth(0));
make.width.mas_greaterThanOrEqualTo(kGetScaleWidth(10));
make.height.mas_equalTo(kGetScaleWidth(30));
}];
[self.diamondIconView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.height.mas_equalTo(kGetScaleWidth(20));
make.centerY.equalTo(self.pi_diamondNumView);
make.leading.mas_equalTo(kGetScaleWidth(6));
}];
[self.addIconView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(self.pi_diamondNumView);
make.width.height.mas_equalTo(kGetScaleWidth(16));
make.trailing.mas_equalTo(-kGetScaleWidth(6));
}];
[self.diamondNumTextView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(self.pi_diamondNumView);
make.leading.mas_equalTo(kGetScaleWidth(25));
make.trailing.mas_equalTo(-kGetScaleWidth(23));
}];
[self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.bgView.mas_top).mas_offset(kGetScaleWidth(52));
make.left.right.bottom.mas_equalTo(self.view);
}];
}
-(void)hiddenViewBntAction{
[self.view endEditing:YES];
}
#pragma mark - JXCategoryViewDelegate
- (NSUInteger)tableHeaderViewHeightInPagerView:(JXPagerView *)pagerView {
return 0;
}
- (UIView *)tableHeaderViewInPagerView:(JXPagerView *)pagerView {
return [UIView new];
}
- (NSUInteger)heightForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
return kGetScaleWidth(44);
}
- (UIView *)viewForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
return self.titleView;
}
- (NSInteger)numberOfListsInPagerView:(JXPagerView *)pagerView {
return self.titles.count;
}
- (id<JXPagerViewListViewDelegate>)pagerView:(JXPagerView *)pagerView initListAtIndex:(NSInteger)index {
RoomInfoModel *roomInfo = self.hostDelegate.getRoomInfo;
if(roomInfo.redEnvelopeType == 1){
return self.roomRedVC;
}else if(roomInfo.redEnvelopeType == 2){
return self.entireServerVC;
}else{
return index == 0 ? self.roomRedVC : self.entireServerVC;
}
}
#pragma mark - JXPagerMainTableViewGestureDelegate
- (BOOL)mainTableViewGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
//禁止categoryView左右滑动的时候上下和左右都可以滚动
if (otherGestureRecognizer.view == self.contentView.listContainerView) {
return NO;
}
if(otherGestureRecognizer.view.tag == 3000000001){
return YES;
}
return [gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]] && [otherGestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]];
}
-(void)tipsAction{
XPRoomHalfWebView * webView = [[XPRoomHalfWebView alloc] init];
webView.url = URLWithType(kRedPacketRuleURL);
TTPopupService * config = [[TTPopupService alloc] init];
config.contentView = webView;
[TTPopup popupWithConfig:config];
}
-(void)hiddenViewAction{
[self dismissViewControllerAnimated:YES completion:nil];
}
-(void)getDiamondAction{
XPWebViewController * rechargeVC =[[XPWebViewController alloc] initWithCustomizeNav:NO];
NSString *url = [NSString stringWithFormat:URLWithType(kThirdPartyPay),@"4",[YYUtility deviceID]];
rechargeVC.url = url;
[[XCCurrentVCStackManager shareManager].getCurrentVC.navigationController pushViewController:rechargeVC animated:YES];
}
-(NSTextAttachment *)getDiamondNumAtt:(NSString *)image{
NSTextAttachment * diamondAttachment = [[NSTextAttachment alloc] init];
UIImage *diamondIconImage = [UIImage imageNamed:image];;
diamondAttachment.bounds = CGRectMake(0, roundf(kFontMedium(13).capHeight - diamondIconImage.size.height)/2.f, diamondIconImage.size.width, diamondIconImage.size.height);
diamondAttachment.image = diamondIconImage;
return diamondAttachment;
}
- (UIImage*)resizableImage:(UIImage *)image {
//图片拉伸区域
CGFloat top = (image.size.height - 1) / 2;
CGFloat left = (image.size.width - 1) / 2;
CGFloat right = (image.size.width - 1) / 2;
CGFloat bottom = (image.size.height - 1) / 2;
return [image resizableImageWithCapInsets:UIEdgeInsetsMake(top, left, bottom, right) resizingMode:UIImageResizingModeStretch];
}
#pragma mark - 懒加载
- (UIView *)bgView{
if(!_bgView){
_bgView = [UIView new];
_bgView.backgroundColor = [UIColor whiteColor];
}
return _bgView;
}
- (UIButton *)pi_backBtn{
if(!_pi_backBtn){
_pi_backBtn = [UIButton new];
[_pi_backBtn addTarget:self action:@selector(hiddenViewAction) forControlEvents:UIControlEventTouchUpInside];
}
return _pi_backBtn;
}
- (UIImageView *)topImageView{
if(!_topImageView){
_topImageView = [UIImageView new];
_topImageView.image = kImage(@"pi_red_packet_top_icon_logo");
}
return _topImageView;
}
- (UIButton *)tipsBtn{
if(!_tipsBtn){
_tipsBtn = [UIButton new];
[_tipsBtn setEnlargeEdgeWithTop:10 right:10 bottom:10 left:10];
[_tipsBtn addTarget:self action:@selector(tipsAction) forControlEvents:UIControlEventTouchUpInside];
[_tipsBtn setBackgroundImage:kImage(@"pi_red_packet_top_tip_logo") forState:UIControlStateNormal];
}
return _tipsBtn;
}
- (UIImageView *)pi_diamondNumView{
if(!_pi_diamondNumView){
_pi_diamondNumView = [UIImageView new];
_pi_diamondNumView.image = [self resizableImage:kImage(@"pi_red_packet_top_diamond_bg")];
_pi_diamondNumView.userInteractionEnabled = YES;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(getDiamondAction)];
[_pi_diamondNumView addGestureRecognizer:tap];
}
return _pi_diamondNumView;
}
- (UILabel *)diamondNumTextView{
if(!_diamondNumTextView){
_diamondNumTextView = [UILabel labelInitWithText:@"0" font:kFontMedium(13) textColor:[UIColor whiteColor]];
_diamondNumTextView.textAlignment = NSTextAlignmentCenter;
}
return _diamondNumTextView;
}
- (UIImageView *)diamondIconView{
if(!_diamondIconView){
_diamondIconView = [UIImageView new];
_diamondIconView.image = kImage(@"pi_red_packet_top_diamond_icon");
}
return _diamondIconView;
}
-(UIImageView *)addIconView{
if(!_addIconView){
_addIconView = [UIImageView new];
_addIconView.image = kImage(@"pi_red_packet_top_diamond_add");
}
return _addIconView;
}
- (JXCategoryTitleView *)titleView {
if (!_titleView) {
_titleView = [[JXCategoryTitleView alloc] init];
_titleView.delegate = self;
_titleView.titles = self.titles;
_titleView.backgroundColor = [UIColor clearColor];
_titleView.titleColor = UIColorFromRGB(0x767585);
_titleView.titleSelectedColor = UIColorFromRGB(0xFF285C);
_titleView.titleFont =kFontMedium(18);
_titleView.titleSelectedFont = kFontSemibold(18);
_titleView.titleLabelAnchorPointStyle = JXCategoryTitleLabelAnchorPointStyleCenter;
_titleView.contentScrollViewClickTransitionAnimationEnabled = NO;
_titleView.averageCellSpacingEnabled = NO;
if(self.titles.count == 2){
_titleView.contentEdgeInsetLeft = kGetScaleWidth(78);
_titleView.contentEdgeInsetRight = kGetScaleWidth(78);
_titleView.cellWidth = kGetScaleWidth(72);
_titleView.cellSpacing = kGetScaleWidth(75);
}else{
_titleView.cellWidth = KScreenWidth;
}
_titleView.defaultSelectedIndex = 0;
_titleView.listContainer = (id<JXCategoryViewListContainer>)self.contentView.listContainerView;
JXCategoryIndicatorImageView *lineView = [[JXCategoryIndicatorImageView alloc] init];
lineView.indicatorImageViewSize = CGSizeMake(kGetScaleWidth(12), kGetScaleWidth(4));
lineView.verticalMargin = kGetScaleWidth(5);
lineView.backgroundColor = UIColorFromRGB(0xFF285C);
lineView.layer.cornerRadius = kGetScaleWidth(4)/2;
lineView.layer.masksToBounds = YES;
_titleView.indicators = @[lineView];
}
return _titleView;
}
- (JXPagerView *)contentView {
if (!_contentView) {
_contentView = [[JXPagerView alloc] initWithDelegate:self listContainerType:0];
_contentView.mainTableView.gestureDelegate = self;
_contentView.backgroundColor = [UIColor clearColor];
_contentView.listContainerView.backgroundColor = [UIColor clearColor];
_contentView.listContainerView.listCellBackgroundColor = [UIColor clearColor];
_contentView.mainTableView.backgroundColor = [UIColor clearColor];
}
return _contentView;
}
- (UIButton *)hiddenViewBnt{
if(!_hiddenViewBnt){
_hiddenViewBnt = [UIButton new];
[_hiddenViewBnt addTarget:self action:@selector(hiddenViewBntAction) forControlEvents:UIControlEventTouchUpInside];
}
return _hiddenViewBnt;
}
- (PIRoomSendRedPacketItemVC *)roomRedVC{
if(!_roomRedVC){
_roomRedVC = [[PIRoomSendRedPacketItemVC alloc]initWithDelegate:self.hostDelegate type:0];
}
return _roomRedVC;
}
- (PIRoomSendRedPacketItemVC *)entireServerVC{
if(!_entireServerVC){
_entireServerVC = [[PIRoomSendRedPacketItemVC alloc]initWithDelegate:self.hostDelegate type:1];
}
return _entireServerVC;
}
@end