Files
peko-ios/YuMi/Modules/YMRoom/View/Custom Background/CustomRoomBGContentViewController.m
eggmanQQQ efefa94d3c temp save
2024-11-07 16:16:09 +08:00

892 lines
32 KiB
Objective-C

//
// CustomRoomBGContentViewController.m
// YuMi
//
// Created by P on 2024/10/29.
//
#import "CustomRoomBGContentViewController.h"
#import "SVGA.h"
#import "CustomRoomBGCell.h"
#import "CustomRoomBGPresenter.h"
#import "XPRoomSettingPresenter.h"
@interface CustomRoomBGContentViewController () <UICollectionViewDelegateFlowLayout, UICollectionViewDataSource, UIImagePickerControllerDelegate, UINavigationControllerDelegate>
@property (nonatomic, strong) UIView *bottomAreaBackGround;
@property (nonatomic, strong) UIView *emptyStateView;
@property (nonatomic, strong) UIButton *freeButton;
@property (nonatomic, strong) UIButton *payButton;
@property (nonatomic, strong) UIButton *customButton;
@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, strong) UIView *previewMask;
@property (nonatomic, strong) UIImageView *previewFrontImageView;
@property (nonatomic, strong) NetImageView *previewBackImageView;
@property (nonatomic, strong) SVGAImageView *previewBackSvgaView;
@property (nonatomic, strong) UIView *previewBottomBackground;
@property (nonatomic, strong) UILabel *previewTipsContentLabel;
@property (nonatomic, strong) UIButton *previewActionButton;
@property (nonatomic, strong) UIButton *cancelPreviewButton;
@property (nonatomic, strong) UIButton *createCustomButton;
@property (nonatomic, strong) UIButton *helpButton;
@property (nonatomic, strong) NSMutableArray *payBackgrounds;
@property (nonatomic, strong) NSMutableArray *freeBackgrounds;
@property (nonatomic, strong) NSMutableArray *customBackgrounds;
@property (nonatomic, assign) NSInteger currentSelectedTabIndex;
@property (nonatomic, assign) NSInteger currentSelectedItemIndex;
@property (nonatomic, strong) CustomRoomBGItemModel *currentSelectedModel;
@property (nonatomic, strong) UIView *previewArea;
@property (nonatomic, strong) UIButton *dismissPreviewButton;
@property (nonatomic, strong) UIImageView *previewGold;
@property (nonatomic, strong) UILabel *previewPricePerDay;
@property (nonatomic, strong) UIImage *customSelectedImage;
@property (nonatomic, assign) NSInteger customBGUsageHours;
@property (nonatomic, assign) NSInteger customBGUsageGolds;
@end
@implementation CustomRoomBGContentViewController
- (CustomRoomBGPresenter *)createPresenter {
return [[CustomRoomBGPresenter alloc] init];
}
- (void)viewDidLoad {
[super viewDidLoad];
self.currentSelectedTabIndex = 0;
self.currentSelectedItemIndex = 0;
[self setupUI];
[self setupData];
}
- (void)setupData {
self.payBackgrounds = @[].mutableCopy;
self.freeBackgrounds = @[].mutableCopy;
self.customBackgrounds = @[].mutableCopy;
__block CustomRoomBGItemModel *currentModel = nil;
@kWeakify(self);
[self.presenter loadListOfRoomBG:self.roomUID
complete:^(CustomRoomBGModel *roomBGModel) {
@kStrongify(self);
self.customBGUsageHours = roomBGModel.customHour;
self.customBGUsageGolds = roomBGModel.customGoldPrice;
for (CustomRoomBGItemModel *model in roomBGModel.itemList) {
if (model.isCur) {
currentModel = model;
}
switch (model.type) {
case RoomBGType_Free:
[self.freeBackgrounds addObject:model];
break;
case RoomBGType_Pay:
[self.payBackgrounds addObject:model];
break;
case RoomBGType_Custom:
[self.customBackgrounds addObject:model];
break;
default:
break;
}
}
if (currentModel) {
[self updateTabButtonStatus:currentModel];
} else {
[self didSelectedButton:self.freeButton];
}
[self.collectionView reloadData];
} failure:^{
@kStrongify(self);
[self didTapEmptySpace];
}];
}
- (void)updateTabButtonStatus:(CustomRoomBGItemModel *)model {
self.currentSelectedTabIndex = model.type;
switch (model.type) {
case RoomBGType_Pay:
[self didSelectedButton:self.payButton];
break;
case RoomBGType_Free:
[self didSelectedButton:self.freeButton];
break;
case RoomBGType_Custom:
[self didSelectedButton:self.customButton];
break;
default:
break;
}
}
- (void)setupUI {
self.view.backgroundColor = [UIColor colorWithWhite:0 alpha:0.3];
[self setupBackgroundContent];
[self setupTopButtons];
[self.view addSubview:self.collectionView];
[self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.bottomAreaBackGround).offset(50);
make.leading.trailing.mas_equalTo(self.view);
make.height.mas_equalTo(kGetScaleWidth(180 + 32 + 32));
}];
}
- (void)setupBackgroundContent {
[self.view addSubview:[self bottomAreaBackGround]];
UIButton *b = [self dismissButton];
[self.view addSubview:b];
[b mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.leading.trailing.mas_equalTo(self.view);
make.bottom.mas_equalTo(self.bottomAreaBackGround.mas_top).offset(-16);
}];
[self.view addSubview:self.emptyStateView];
[self.emptyStateView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.bottomAreaBackGround).offset(72);
make.leading.trailing.mas_equalTo(self.view);
make.height.mas_equalTo(26 + 110);
}];
}
- (void)setupTopButtons {
self.freeButton = [self bgCategoryButton:100];
self.payButton = [self bgCategoryButton:101];
self.customButton = [self bgCategoryButton:102];
[self.view addSubview:self.freeButton];
[self.freeButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.bottomAreaBackGround).offset(10);
make.leading.mas_equalTo(15);
make.height.mas_equalTo(22);
make.width.mas_greaterThanOrEqualTo(20);
}];
[self.view addSubview:self.payButton];
[self.payButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.freeButton);
make.leading.mas_equalTo(self.freeButton.mas_trailing).offset(25);
make.height.mas_equalTo(22);
make.width.mas_greaterThanOrEqualTo(20);
}];
[self.view addSubview:self.customButton];
[self.customButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.freeButton);
make.leading.mas_equalTo(self.payButton.mas_trailing).offset(25);
make.height.mas_equalTo(22);
make.width.mas_greaterThanOrEqualTo(20);
}];
[self.view addSubview:self.helpButton];
[self.helpButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(self.freeButton);
make.trailing.mas_equalTo(self.view).offset(-15);
make.size.mas_equalTo(CGSizeMake(22, 22));
}];
[self.view addSubview:self.createCustomButton];
[self.createCustomButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(self.freeButton);
make.trailing.mas_equalTo(self.helpButton.mas_leading).offset(-5);
make.size.mas_equalTo(CGSizeMake(82, 22));
}];
}
#pragma mark -
- (void)updateDataSource:(NSInteger)tag {
self.currentSelectedTabIndex = tag - 100;
self.currentSelectedItemIndex = 0;
[self.collectionView reloadData];
self.helpButton.hidden = YES;
self.createCustomButton.hidden = YES;
switch (tag) {
case 100:
self.emptyStateView.hidden = YES;
break;
case 101:
self.emptyStateView.hidden = self.payBackgrounds.count != 0;
break;
case 102:
self.helpButton.hidden = NO;
self.createCustomButton.hidden = NO;
self.emptyStateView.hidden = self.customBackgrounds.count != 0;
break;
default:
self.emptyStateView.hidden = YES;
break;
}
}
- (void)displayPreviewArea {
UIView *view = [self previewMask];
[self.view addSubview:view];
self.previewArea = view;
[view addSubview:self.dismissPreviewButton];
[self.dismissPreviewButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(view);
}];
[view addSubview:self.previewBottomBackground];
[self.previewBottomBackground addSubview:self.previewTipsContentLabel];
[self.previewTipsContentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.previewBottomBackground).offset(47);
make.leading.trailing.mas_equalTo(self.previewBottomBackground).inset(15);
}];
[self.previewBottomBackground addSubview:self.previewGold];
[self.previewGold mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.previewBottomBackground).offset(103);
make.leading.mas_equalTo(self.previewBottomBackground).offset(15);
make.size.mas_equalTo(CGSizeMake(26, 26));
}];
[self.previewBottomBackground addSubview:self.previewPricePerDay];
[self.previewPricePerDay mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(self.previewGold);
make.leading.mas_equalTo(self.previewGold.mas_trailing).offset(4);
}];
[self.previewBottomBackground addSubview:self.previewActionButton];
[self.previewActionButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.previewBottomBackground).offset(103);
make.trailing.mas_equalTo(self.previewBottomBackground).offset(-15);
make.size.mas_equalTo(CGSizeMake(120, 38));
}];
[view addSubview:self.previewFrontImageView];
[self.previewFrontImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.mas_equalTo(self.previewBottomBackground.mas_top).offset(-16);
make.top.mas_equalTo(100);
make.leading.trailing.mas_equalTo(view).inset(64);
}];
[view insertSubview:self.previewBackImageView belowSubview:self.previewFrontImageView];
[self.previewBackImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.previewFrontImageView);
}];
[view insertSubview:self.previewBackSvgaView belowSubview:self.previewFrontImageView];
[self.previewBackSvgaView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.previewFrontImageView);
}];
}
- (void)updatePreviewArea:(CustomRoomBGItemModel *)model {
self.currentSelectedModel = model;
BOOL isSvga = [model.url hasSuffix:@"svga"];
self.previewBackImageView.hidden = isSvga;
self.previewBackSvgaView.hidden = !isSvga;
switch (model.type) {
case RoomBGType_Free:
// [self.previewPricePerDay removeFromSuperview];
// [self.previewGold removeFromSuperview];
// [self.previewActionButton setTitle:YMLocalizedString(@"1.0.18_15") forState:UIControlStateNormal];
break;
case RoomBGType_Pay:
self.previewPricePerDay.text = [model pricePerDays];
self.previewTipsContentLabel.text = YMLocalizedString(@"1.0.18_13");
[self.previewActionButton setTitle:YMLocalizedString(@"1.0.18_16") forState:UIControlStateNormal];
break;
case RoomBGType_Custom:
self.previewPricePerDay.text = [model pricePerDays];
self.previewTipsContentLabel.text = YMLocalizedString(@"1.0.18_12");
[self.previewActionButton setTitle:YMLocalizedString(@"1.0.18_15") forState:UIControlStateNormal];
break;
default:
break;
}
if (isSvga) {
SVGAParser *_parser = [SVGAParser new];
@kWeakify(self);
[_parser parseWithURL:[NSURL URLWithString:[model.url stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]]]
completionBlock:^(SVGAVideoEntity * _Nullable videoItem) {
@kStrongify(self);
self.previewBackSvgaView.loops = 0;
self.previewBackSvgaView.videoItem = videoItem;
[self.previewBackSvgaView startAnimation];
} failureBlock:^(NSError * _Nullable error) {
NSLog(@"%@", error);
}];
} else {
self.previewBackImageView.imageUrl = model.url;
}
}
- (void)updatePreviewWith:(UIImage *)image {
self.previewBackImageView.image = image;
[self.previewActionButton setTitle:YMLocalizedString(@"1.0.18_16") forState:UIControlStateNormal];
}
#pragma mark -
- (void)didTapEmptySpace {
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)didSelectedButton:(UIButton *)button {
self.freeButton.selected = NO;
self.payButton.selected = NO;
self.customButton.selected = NO;
button.selected = YES;
[self updateDataSource:button.tag];
}
- (void)didTapCreate {
@kWeakify(self);
[YYUtility checkAssetsLibrayAvailable:^{
@kStrongify(self);
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.modalPresentationCapturesStatusBarAppearance = YES;
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.allowsEditing = NO;
[self presentViewController:imagePicker animated:YES completion:NULL];
} denied:^{
@kStrongify(self);
[self showNotPhoto:YMLocalizedString(@"SessionViewController21") content:YMLocalizedString(@"XPMineUserInfoAlbumViewController8")];
} restriction:^{
@kStrongify(self);
[self showNotPhoto:YMLocalizedString(@"SessionViewController21") content:YMLocalizedString(@"XPMineUserInfoAlbumViewController10")];
}];
}
- (void)didTapHelp {
TTAlertConfig *config = [[TTAlertConfig alloc]init];
config.title = YMLocalizedString(@"UserDetail_CP_Toast_0");
config.message = YMLocalizedString(@"1.0.18_6");
config.actionStyle = TTAlertActionConfirmStyle;
[TTPopup alertWithConfig:config
showBorder:NO
confirmHandler:^{}
cancelHandler:^{}];
}
- (void)didTapActionButton {
[self updateRoomBG];
}
- (void)didTapCancelPreview {
[self.previewArea removeFromSuperview];
}
- (void)updateRoomBG {
if (!self.currentSelectedModel) {
[self uploadBG];
return;
}
switch (self.currentSelectedModel.type) {
case 0:
[self applyBG];
break;
case 1:
if (self.currentSelectedModel.status == 1 && [self.currentSelectedModel isAlreadyPay]) {
[self applyBG];
} else {
[self buyBG];
}
break;
case 2:
[self uploadBG];
break;
default:
break;
}
}
- (void)buyBG {
@kWeakify(self);
[self.presenter buyRoomBG:self.roomUID
itemID:@(self.currentSelectedModel.id).stringValue
complete:^{
@kStrongify(self);
[self applyBG];
}
failure:^{}];
}
- (void)uploadBG {
@kWeakify(self);
[self.presenter uploadRoomBG:self.roomUID photo:self.customSelectedImage complete:^{
@kStrongify(self);
// TODO: 跳转到 custom tab
[self setupData];
} failure:^{
[self hideHUD];
}];
}
- (void)applyBG {
@kWeakify(self);
[self.presenter useRoomBG:self.roomUID
itemID:@(self.currentSelectedModel.id).stringValue
complete:^{
@kStrongify(self);
[self didTapEmptySpace];
}
failure:^{}];
}
#pragma mark - UIImagePickerControllerDelegate
- (void)showNotPhoto:(NSString *)title content:(NSString *)content{
TTAlertConfig *config = [[TTAlertConfig alloc] init];
config.title = title;
config.message = content;
[TTPopup alertWithConfig:config confirmHandler:^{
NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
if ([[UIApplication sharedApplication] canOpenURL:url]) {
[[UIApplication sharedApplication] openURL:url];
}
} cancelHandler:^{
}];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
@kWeakify(self);
[picker dismissViewControllerAnimated:YES completion:^{
@kStrongify(self);
UIImage *selectedPhoto = [info objectForKey:UIImagePickerControllerOriginalImage];
if (selectedPhoto) {
self.customSelectedImage = selectedPhoto;
[self displayPreviewArea];
[self updatePreviewWith:selectedPhoto];
}
}];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissViewControllerAnimated:YES completion:^{
}];
}
#pragma mark -
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
switch (self.currentSelectedTabIndex) {
case 0:
return self.freeBackgrounds.count;
break;
case 1:
return self.payBackgrounds.count;
break;
case 2:
return self.customBackgrounds.count;
break;
default:
return 0;
break;
}
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
CustomRoomBGItemModel *model;
switch (self.currentSelectedTabIndex) {
case 0:
model = [self.freeBackgrounds xpSafeObjectAtIndex:indexPath.row];
break;
case 1:
model = [self.payBackgrounds xpSafeObjectAtIndex:indexPath.row];
break;
case 2:
model = [self.customBackgrounds xpSafeObjectAtIndex:indexPath.row];
break;
default:
break;
}
if (model) {
CustomRoomBGCell *cell = [CustomRoomBGCell reuseFrom:collectionView
model:model
atIndexPath:indexPath];
@kWeakify(self);
[cell setHandleTapPlayButton:^(id _Nonnull obj) {
@kStrongify(self);
[self displayPreviewArea];
}];
return cell;
}
return nil;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
CustomRoomBGItemModel *model;
switch (self.currentSelectedTabIndex) {
case 0:
model = [self.freeBackgrounds xpSafeObjectAtIndex:indexPath.row];
break;
case 1:
model = [self.payBackgrounds xpSafeObjectAtIndex:indexPath.row];
break;
case 2:
model = [self.customBackgrounds xpSafeObjectAtIndex:indexPath.row];
break;
default:
break;
}
if (model) {
self.currentSelectedModel = model;
if (model.isCur) {
[collectionView reloadData];
return;
}
// TODO: 处理 buy 类型的拉起 preview不正确
if (model.status == RoomBGStatus_Pass) {
if ([model isAlreadyPay]) {
[self applyBG];
} else {
self.currentSelectedItemIndex = indexPath.row;
[self displayPreviewArea];
[self updatePreviewArea:model];
// [collectionView reloadData];
}
} else {
self.currentSelectedItemIndex = indexPath.row;
[self displayPreviewArea];
[self updatePreviewArea:model];
// [collectionView reloadData];
}
}
}
- (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath {
CustomRoomBGCell *bgCell = (CustomRoomBGCell *)cell;
[bgCell playSVGA];
}
- (void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath {
CustomRoomBGCell *bgCell = (CustomRoomBGCell *)cell;
[bgCell pauseSVGA];
}
#pragma mark -
- (UIButton *)dismissButton {
UIButton *b = [UIButton buttonWithType:UIButtonTypeCustom];
[b setBackgroundColor:[UIColor clearColor]];
[b addTarget:self action:@selector(didTapEmptySpace) forControlEvents:UIControlEventTouchUpInside];
return b;
}
- (UIView *)bottomAreaBackGround {
if (!_bottomAreaBackGround) {
CGFloat height = kGetScaleWidth(323) + kSafeAreaBottomHeight;
UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, KScreenHeight - height, KScreenWidth, height)];
v.userInteractionEnabled = YES;
v.backgroundColor = [UIColor blackColor];
v.layer.cornerRadius = 16;
v.layer.maskedCorners = kCALayerMinXMinYCorner | kCALayerMaxXMinYCorner;
v.layer.masksToBounds = YES;
_bottomAreaBackGround = v;
}
return _bottomAreaBackGround;
}
- (UIButton *)bgCategoryButton:(NSInteger)tag {
UIButton *b = [UIButton buttonWithType:UIButtonTypeCustom];
b.tag = tag;
// 设置普通状态字体
UIFont *normalFont = kFontRegular(15);
NSDictionary *normalAttributes = @{NSFontAttributeName: normalFont,
NSForegroundColorAttributeName: [UIColor colorWithWhite:1 alpha:0.6]};
NSAttributedString *normalTitle = [[NSAttributedString alloc] initWithString:[self titleForTag:tag]
attributes:normalAttributes];
[b setAttributedTitle:normalTitle forState:UIControlStateNormal];
// 设置选中状态字体
UIFont *selectedFont = kFontMedium(15);
NSDictionary *selectedAttributes = @{NSFontAttributeName: selectedFont,
NSForegroundColorAttributeName: [UIColor whiteColor]};
NSAttributedString *selectedTitle = [[NSAttributedString alloc] initWithString:[self titleForTag:tag]
attributes:selectedAttributes];
[b setAttributedTitle:selectedTitle forState:UIControlStateSelected];
[b addTarget:self
action:@selector(didSelectedButton:)
forControlEvents:UIControlEventTouchUpInside];
[b setContentHuggingPriority:UILayoutPriorityRequired
forAxis:UILayoutConstraintAxisHorizontal];
[b setContentCompressionResistancePriority:UILayoutPriorityRequired
forAxis:UILayoutConstraintAxisHorizontal];
return b;
}
- (UIButton *)createCustomButton {
if (!_createCustomButton) {
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.hidden = YES;
button.frame = CGRectMake(0, 0, 82, 22);
[button setTitle:YMLocalizedString(@"1.0.18_4") forState:UIControlStateNormal];
[button.titleLabel setFont:kFontRegular(12)];
button.layer.cornerRadius = 11; // 设置圆角
button.clipsToBounds = YES; // 使圆角生效
// 创建渐变图层
CAGradientLayer *gradientLayer = [CAGradientLayer layer];
gradientLayer.colors = @[(__bridge id)UIColorFromRGB(0xE29030).CGColor,
(__bridge id)UIColorFromRGB(0xFCC074).CGColor];
gradientLayer.startPoint = CGPointMake(0.0, 0.0); // 顶部中央
gradientLayer.endPoint = CGPointMake(0.0, 1.0); // 底部中央
gradientLayer.frame = button.bounds; // 设置渐变图层大小
// 将渐变图层添加到按钮图层
[button.layer insertSublayer:gradientLayer atIndex:0];
[button addTarget:self
action:@selector(didTapCreate)
forControlEvents:UIControlEventTouchUpInside];
_createCustomButton = button;
}
return _createCustomButton;
}
- (UIButton *)helpButton {
if (!_helpButton) {
UIButton *b = [UIButton buttonWithType:UIButtonTypeCustom];
b.hidden = YES;
[b setImage:kImage(@"custom_bg_help") forState:UIControlStateNormal];
[b addTarget:self
action:@selector(didTapHelp)
forControlEvents:UIControlEventTouchUpInside];
_helpButton = b;
}
return _helpButton;
}
- (UIView *)emptyStateView {
if (!_emptyStateView) {
UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 26 + 110)];
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImageConstant defaultEmptyPlaceholder_UFO]];
[v addSubview:imageView];
[imageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.centerX.mas_equalTo(v);
make.size.mas_equalTo(CGSizeMake(kGetScaleWidth(110), kGetScaleWidth(110)));
}];
UILabel *messageLabel = [UILabel labelInitWithText:YMLocalizedString(@"1.0.18_5")
font:kFontRegular(14)
textColor:[UIColor colorWithWhite:1 alpha:0.4]];
messageLabel.textAlignment = NSTextAlignmentCenter;
[v addSubview:messageLabel];
[messageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.trailing.mas_equalTo(v).inset(52);
make.top.mas_equalTo(imageView.mas_bottom).offset(6);
make.height.mas_equalTo(22);
}];
v.hidden = YES;
_emptyStateView = v;
}
return _emptyStateView;
}
- (UICollectionView *)collectionView {
if (!_collectionView) {
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.itemSize = CGSizeMake(kGetScaleWidth(135), kGetScaleWidth(180 + 32 + 32));
layout.minimumLineSpacing = 10;
layout.minimumInteritemSpacing = 10;
layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
layout.sectionInset = UIEdgeInsetsMake(0, 15, 0, 15);
_collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
_collectionView.backgroundColor = [UIColor clearColor];
_collectionView.delegate = self;
_collectionView.dataSource = self;
_collectionView.clipsToBounds = NO;
_collectionView.showsHorizontalScrollIndicator = NO;
[CustomRoomBGCell registerTo:_collectionView];
}
return _collectionView;
}
- (UIView *)previewMask {
UIView *v = [[UIView alloc] initWithFrame:self.view.bounds];
v.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
return v;
}
- (UIView *)previewBottomBackground {
if (!_previewBottomBackground) {
CGFloat height = kGetScaleWidth(174) + kSafeAreaBottomHeight;
UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, KScreenHeight - height, KScreenWidth, height)];
v.userInteractionEnabled = YES;
v.backgroundColor = [UIColor blackColor];
v.layer.cornerRadius = 16;
v.layer.maskedCorners = kCALayerMinXMinYCorner | kCALayerMaxXMinYCorner;
v.layer.masksToBounds = YES;
UILabel *tipsTitleLabel = [UILabel labelInitWithText:YMLocalizedString(@"1.0.18_11")
font:kFontMedium(15)
textColor:[UIColor whiteColor]];
tipsTitleLabel.textAlignment = NSTextAlignmentCenter;
[v addSubview:tipsTitleLabel];
[tipsTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(v).offset(13);
make.centerX.mas_equalTo(v);
}];
UIButton *b = [self cancelPreviewButton];
[v addSubview:b];
[b mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.top.mas_equalTo(15);
make.size.mas_equalTo(22);
}];
_previewBottomBackground = v;
}
return _previewBottomBackground;
}
- (NetImageView *)previewBackImageView {
if (!_previewBackImageView) {
_previewBackImageView = [[NetImageView alloc] init];
_previewBackImageView.layer.cornerRadius = 14;
_previewBackImageView.layer.masksToBounds = YES;
_previewBackImageView.contentMode = UIViewContentModeScaleAspectFill;
}
return _previewBackImageView;
}
- (SVGAImageView *)previewBackSvgaView {
if (!_previewBackSvgaView) {
_previewBackSvgaView = [[SVGAImageView alloc] init];
_previewBackSvgaView.layer.cornerRadius = 14;
_previewBackSvgaView.layer.masksToBounds = YES;
_previewBackSvgaView.autoPlay = YES;
}
return _previewBackSvgaView;
}
- (UIImageView *)previewFrontImageView {
if (!_previewFrontImageView) {
_previewFrontImageView = [[UIImageView alloc] initWithImage:kImage(@"custom_bg_preview")];
_previewFrontImageView.layer.cornerRadius = 14;
_previewFrontImageView.layer.masksToBounds = YES;
_previewFrontImageView.contentMode = UIViewContentModeScaleAspectFit;
}
return _previewFrontImageView;
}
- (UILabel *)previewTipsContentLabel {
if (!_previewTipsContentLabel) {
_previewTipsContentLabel = [UILabel labelInitWithText:YMLocalizedString(@"1.0.18_12")
font:kFontMedium(15)
textColor:[UIColor colorWithWhite:1 alpha:0.6]];
_previewTipsContentLabel.numberOfLines = 0;
_previewTipsContentLabel.textAlignment = NSTextAlignmentCenter;
}
return _previewTipsContentLabel;
}
- (UIImageView *)previewGold {
if (!_previewGold) {
_previewGold = [[UIImageView alloc] initWithImage:kImage(@"moli_money_icon")];
}
return _previewGold;
}
- (UILabel *)previewPricePerDay {
if (!_previewPricePerDay) {
_previewPricePerDay = [UILabel labelInitWithText:YMLocalizedString(@"1.0.18_14")
font:kFontMedium(16)
textColor:UIColorFromRGB(0xFF8C03)];
}
return _previewPricePerDay;
}
- (UIButton *)previewActionButton {
if (!_previewActionButton) {
_previewActionButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_previewActionButton setTitle:YMLocalizedString(@"1.0.18_15")
forState:UIControlStateNormal];
_previewActionButton.layer.cornerRadius = 11;
_previewActionButton.layer.masksToBounds = YES;
[_previewActionButton addTarget:self
action:@selector(didTapActionButton)
forControlEvents:UIControlEventTouchUpInside];
// 创建渐变图层
CAGradientLayer *gradientLayer = [CAGradientLayer layer];
gradientLayer.colors = @[(__bridge id)UIColorFromRGB(0xE29030).CGColor,
(__bridge id)UIColorFromRGB(0xFCC074).CGColor];
gradientLayer.startPoint = CGPointMake(0.0, 0.0); // 顶部中央
gradientLayer.endPoint = CGPointMake(0.0, 1.0); // 底部中央
gradientLayer.frame = CGRectMake(0, 0, 120, 38); // 设置渐变图层大小
// 将渐变图层添加到按钮图层
[_previewActionButton.layer insertSublayer:gradientLayer atIndex:0];
}
return _previewActionButton;
}
- (UIButton *)cancelPreviewButton {
UIButton *b = [UIButton buttonWithType:UIButtonTypeCustom];
[b setImage:kImage(@"common_nav_back_white") forState:UIControlStateNormal];
[b addTarget:self action:@selector(didTapCancelPreview) forControlEvents:UIControlEventTouchUpInside];
return b;
}
- (UIButton *)dismissPreviewButton {
if (!_dismissPreviewButton) {
_dismissPreviewButton = [UIButton buttonWithType:UIButtonTypeCustom];
_dismissPreviewButton.backgroundColor = [UIColor clearColor];
[_dismissPreviewButton addTarget:self
action:@selector(didTapCancelPreview)
forControlEvents:UIControlEventTouchUpInside];
}
return _dismissPreviewButton;
}
#pragma mark -
- (NSString *)titleForTag:(NSInteger)tag {
NSString *title = @"";
switch (tag) {
case 100:
title = YMLocalizedString(@"1.0.18_1");
break;
case 101:
title = YMLocalizedString(@"1.0.18_2");
break;
case 102:
title = YMLocalizedString(@"1.0.18_3");
break;
default:
break;
}
return title;
}
@end