小说绘上架版本
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
//
|
||||
// WXYZ_ChapterBottomPayBar.h
|
||||
// WXReader
|
||||
//
|
||||
// Created by Andrew on 2020/7/27.
|
||||
// Copyright © 2020 Andrew. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
typedef NS_ENUM(NSUInteger, WXYZ_BottomPayBarType) {
|
||||
WXYZ_BottomPayBarTypeDownload,
|
||||
WXYZ_BottomPayBarTypeBuyChapter
|
||||
};
|
||||
|
||||
typedef void(^PaySuccessChaptersBlock)(NSArray <NSString *>*success_chapter_ids);
|
||||
|
||||
typedef void(^PayCancleChapterBlock)(NSArray <NSString *>*fail_chapter_ids);
|
||||
|
||||
typedef void(^PayFailChaptersBlock)(NSArray <NSString *>*fail_chapter_ids);
|
||||
|
||||
typedef void(^BottomPayBarHiddenBlock)(void);
|
||||
|
||||
@interface WXYZ_ChapterBottomPayBar : UIView
|
||||
|
||||
@property (nonatomic, copy) PaySuccessChaptersBlock paySuccessChaptersBlock;
|
||||
|
||||
@property (nonatomic, copy) PayCancleChapterBlock payCancleChapterBlock;
|
||||
|
||||
@property (nonatomic, copy) PayFailChaptersBlock payFailChaptersBlock;
|
||||
|
||||
@property (nonatomic, copy) BottomPayBarHiddenBlock bottomPayBarHiddenBlock;
|
||||
|
||||
@property (nonatomic, assign) BOOL canTouchHiddenView;
|
||||
|
||||
- (instancetype)initWithChapterModel:(TFProductionChapterModel *)chapterModel barType:(WXYZ_BottomPayBarType)barType productionType:(TFProductionType)productionType;
|
||||
|
||||
- (instancetype)initWithChapterModel:(TFProductionChapterModel *)chapterModel barType:(WXYZ_BottomPayBarType)barType productionType:(TFProductionType)productionType buyChapterNum:(NSInteger)buyChapterNum;
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame chapterModel:(TFProductionChapterModel *)chapterModel barType:(WXYZ_BottomPayBarType)barType productionType:(TFProductionType)productionType;
|
||||
|
||||
- (void)showBottomPayBar;
|
||||
|
||||
- (void)hiddenBottomPayBar;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -0,0 +1,470 @@
|
||||
//
|
||||
// WXYZ_ChapterBottomPayBar.m
|
||||
// WXReader
|
||||
//
|
||||
// Created by Andrew on 2020/7/27.
|
||||
// Copyright © 2020 Andrew. All rights reserved.
|
||||
//
|
||||
|
||||
#import "WXYZ_ChapterBottomPayBar.h"
|
||||
|
||||
#import "TFRechargeViewController.h"
|
||||
|
||||
#import "WXYZ_ChapterBottomPayBarTitleTableViewCell.h"
|
||||
#import "WXYZ_ChapterBottomPayBarOptionTableViewCell.h"
|
||||
#import "WXYZ_ChapterBottomPayBarBalanceTableViewCell.h"
|
||||
#import "WXYZ_ChapterBottomPayBarAutoBuyTableViewCell.h"
|
||||
#import "WXYZ_ChapterBottomPayBarCostTableViewCell.h"
|
||||
|
||||
#import "TFReaderBookManager.h"
|
||||
|
||||
@interface WXYZ_ChapterBottomPayBar () <UITableViewDelegate, UITableViewDataSource>
|
||||
|
||||
@property (nonatomic, strong) UITableView *mainTableView;
|
||||
|
||||
@end
|
||||
|
||||
@implementation WXYZ_ChapterBottomPayBar
|
||||
{
|
||||
// 选项卡选择下标
|
||||
NSInteger _optionSelectIndex;
|
||||
|
||||
NSInteger _buyChapterNum;
|
||||
|
||||
WXYZ_BottomPayBarType _barType;
|
||||
TFProductionType _productionType;
|
||||
|
||||
TFProductionChapterModel *_chapterModel;
|
||||
WXYZ_ChapterPayBarModel *_payBarModel;
|
||||
}
|
||||
|
||||
- (instancetype)initWithChapterModel:(TFProductionChapterModel *)chapterModel barType:(WXYZ_BottomPayBarType)barType productionType:(TFProductionType)productionType
|
||||
{
|
||||
if (self = [self initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) chapterModel:chapterModel barType:barType productionType:productionType buyChapterNum:1]) {
|
||||
[[TFViewHelper getWindowRootController].view addSubview:self];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithChapterModel:(TFProductionChapterModel *)chapterModel barType:(WXYZ_BottomPayBarType)barType productionType:(TFProductionType)productionType buyChapterNum:(NSInteger)buyChapterNum
|
||||
{
|
||||
if (self = [self initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) chapterModel:chapterModel barType:barType productionType:productionType buyChapterNum:buyChapterNum]) {
|
||||
[[TFViewHelper getWindowRootController].view addSubview:self];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame chapterModel:(TFProductionChapterModel *)chapterModel barType:(WXYZ_BottomPayBarType)barType productionType:(TFProductionType)productionType
|
||||
{
|
||||
if (self = [self initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) chapterModel:chapterModel barType:barType productionType:productionType buyChapterNum:1]) {
|
||||
[[TFViewHelper getWindowRootController].view addSubview:self];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame chapterModel:(TFProductionChapterModel *)chapterModel barType:(WXYZ_BottomPayBarType)barType productionType:(TFProductionType)productionType buyChapterNum:(NSInteger)buyChapterNum
|
||||
{
|
||||
if (self = [super initWithFrame:frame]) {
|
||||
_barType = barType;
|
||||
_productionType = productionType;
|
||||
|
||||
_chapterModel = chapterModel;
|
||||
|
||||
_optionSelectIndex = 0;
|
||||
_buyChapterNum = buyChapterNum;
|
||||
|
||||
_canTouchHiddenView = YES;
|
||||
|
||||
self.backgroundColor = kBlackTransparentColor;
|
||||
[self initialize];
|
||||
[self createSubViews];
|
||||
[self netRequest];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)initialize
|
||||
{
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(netRequest) name:Notification_Login_Success object:nil];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(netRequest) name:Notification_Recharge_Success object:nil];
|
||||
}
|
||||
|
||||
- (void)createSubViews
|
||||
{
|
||||
self.mainTableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
|
||||
self.mainTableView.frame = CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, CGFLOAT_MIN);
|
||||
self.mainTableView.backgroundColor = [UIColor clearColor];
|
||||
self.mainTableView.showsVerticalScrollIndicator = NO;
|
||||
self.mainTableView.showsHorizontalScrollIndicator = NO;
|
||||
self.mainTableView.estimatedRowHeight = 100;
|
||||
self.mainTableView.sectionFooterHeight = 10;
|
||||
self.mainTableView.rowHeight = UITableViewAutomaticDimension;
|
||||
self.mainTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
|
||||
self.mainTableView.delegate = self;
|
||||
self.mainTableView.dataSource = self;
|
||||
self.mainTableView.scrollEnabled = NO;
|
||||
if (@available(iOS 11.0, *)) {
|
||||
self.mainTableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
|
||||
} else {
|
||||
// Fallback on earlier versions
|
||||
}
|
||||
[self addSubview:self.mainTableView];
|
||||
}
|
||||
|
||||
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
|
||||
{
|
||||
if (_barType == WXYZ_BottomPayBarTypeDownload) {
|
||||
return 3;
|
||||
}
|
||||
return 5;
|
||||
}
|
||||
|
||||
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
switch (indexPath.row) {
|
||||
case 0:
|
||||
{
|
||||
return [self createPayBarTitleTabelViewCellWithTabelView:tableView];
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
{
|
||||
if (_barType == WXYZ_BottomPayBarTypeDownload) {
|
||||
return [self createPayBarBalanceTabelViewCellWithTabelView:tableView];
|
||||
} else {
|
||||
WS(weakSelf)
|
||||
static NSString *cellName = @"WXYZ_ChapterBottomPayBarOptionTableViewCell";
|
||||
WXYZ_ChapterBottomPayBarOptionTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName];
|
||||
if (!cell) {
|
||||
cell = [[WXYZ_ChapterBottomPayBarOptionTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
|
||||
}
|
||||
cell.hiddenEndLine = NO;
|
||||
cell.pay_options = _payBarModel.pay_options;
|
||||
cell.payOptionClickBlock = ^(WXYZ_ChapterPayBarOptionModel * _Nonnull chapterOptionModel, NSInteger selectIndex) {
|
||||
_optionSelectIndex = selectIndex;
|
||||
_buyChapterNum = chapterOptionModel.buy_num;
|
||||
[weakSelf.mainTableView reloadData];
|
||||
};
|
||||
|
||||
return cell;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
{
|
||||
if (_barType == WXYZ_BottomPayBarTypeDownload) {
|
||||
return [self createPayBarCostTableViewCellWithTableView:tableView];
|
||||
} else {
|
||||
return [self createPayBarBalanceTabelViewCellWithTabelView:tableView];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
{
|
||||
static NSString *cellName = @"WXYZ_ChapterBottomPayBarAutoBuyTableViewCell";
|
||||
WXYZ_ChapterBottomPayBarAutoBuyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName];
|
||||
if (!cell) {
|
||||
cell = [[WXYZ_ChapterBottomPayBarAutoBuyTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
|
||||
}
|
||||
cell.hiddenEndLine = NO;
|
||||
|
||||
return cell;
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
{
|
||||
return [self createPayBarCostTableViewCellWithTableView:tableView];
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return [[UITableViewCell alloc] init];
|
||||
}
|
||||
|
||||
- (UITableViewCell *)createPayBarTitleTabelViewCellWithTabelView:(UITableView *)tableView
|
||||
{
|
||||
static NSString *cellName = @"WXYZ_ChapterBottomPayBarTitleTableViewCell";
|
||||
WXYZ_ChapterBottomPayBarTitleTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName];
|
||||
if (!cell) {
|
||||
cell = [[WXYZ_ChapterBottomPayBarTitleTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
|
||||
}
|
||||
cell.hiddenEndLine = NO;
|
||||
cell.buyOptionModel = [_payBarModel.pay_options objectOrNilAtIndex:_optionSelectIndex];
|
||||
|
||||
return cell;
|
||||
}
|
||||
|
||||
- (UITableViewCell *)createPayBarBalanceTabelViewCellWithTabelView:(UITableView *)tableView
|
||||
{
|
||||
static NSString *cellName = @"WXYZ_ChapterBottomPayBarBalanceTableViewCell";
|
||||
WXYZ_ChapterBottomPayBarBalanceTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName];
|
||||
if (!cell) {
|
||||
cell = [[WXYZ_ChapterBottomPayBarBalanceTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
|
||||
}
|
||||
cell.hiddenEndLine = NO;
|
||||
cell.base_info = _payBarModel.base_info;
|
||||
|
||||
return cell;
|
||||
}
|
||||
|
||||
- (UITableViewCell *)createPayBarCostTableViewCellWithTableView:(UITableView *)tableView
|
||||
{
|
||||
// WS(weakSelf)
|
||||
static NSString *cellName = @"WXYZ_ChapterBottomPayBarCostTableViewCell";
|
||||
WXYZ_ChapterBottomPayBarCostTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName];
|
||||
if (!cell) {
|
||||
cell = [[WXYZ_ChapterBottomPayBarCostTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
|
||||
}
|
||||
cell.base_info = _payBarModel.base_info;
|
||||
cell.buyOptionModel = [_payBarModel.pay_options objectOrNilAtIndex:_optionSelectIndex];
|
||||
cell.buyChapterClickBlock = ^(BOOL needRecharge) {
|
||||
if (!TFUserInfoManager.isLogin) {
|
||||
[TFLoginOptionsViewController presentLoginView:nil];
|
||||
// [kMainWindow sendSubviewToBack:weakSelf];
|
||||
} else {
|
||||
if (needRecharge) {
|
||||
|
||||
TFRechargeViewController *vc = [[TFRechargeViewController alloc] init];
|
||||
vc.production_id = _chapterModel.production_id;
|
||||
vc.productionType = _productionType;
|
||||
TFNavigationController *t_nav = [[TFNavigationController alloc] initWithRootViewController:vc];
|
||||
[[TFViewHelper getWindowRootController] presentViewController:t_nav animated:YES completion:nil];
|
||||
// [kMainWindow sendSubviewToBack:weakSelf];
|
||||
} else {
|
||||
WS(weakSelf)
|
||||
[weakSelf hiddenBottomPayBar];
|
||||
[weakSelf chapterPayRequest];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return cell;
|
||||
}
|
||||
|
||||
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
if ((_barType == WXYZ_BottomPayBarTypeDownload && indexPath.row == 2) || indexPath.row == 4) {
|
||||
return 60;
|
||||
}
|
||||
return 50;
|
||||
}
|
||||
|
||||
//section头间距
|
||||
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
|
||||
{
|
||||
return CGFLOAT_MIN;
|
||||
}
|
||||
//section头视图
|
||||
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
|
||||
{
|
||||
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, CGFLOAT_MIN)];
|
||||
view.backgroundColor = [UIColor clearColor];
|
||||
return view;
|
||||
}
|
||||
|
||||
//section底部间距
|
||||
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
|
||||
{
|
||||
return PUB_TABBAR_OFFSET;
|
||||
}
|
||||
//section底部视图
|
||||
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
|
||||
{
|
||||
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, PUB_TABBAR_OFFSET)];
|
||||
view.backgroundColor = kColorRGBA(247, 248, 250, 1);
|
||||
return view;
|
||||
}
|
||||
|
||||
- (void)showBottomPayBar
|
||||
{
|
||||
[UIView animateWithDuration:kAnimatedDurationFast animations:^{
|
||||
self.mainTableView.frame = CGRectMake(0, SCREEN_HEIGHT - (_barType == WXYZ_BottomPayBarTypeDownload?(2 * 50 + 60):(4 * 50 + 60)) - PUB_TABBAR_OFFSET, SCREEN_WIDTH, (_barType == WXYZ_BottomPayBarTypeDownload?(2 * 50 + 60):(4 * 50 + 60)) + PUB_TABBAR_OFFSET);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)hiddenBottomPayBar
|
||||
{
|
||||
if (!self.hidden) {
|
||||
|
||||
[UIView animateWithDuration:kAnimatedDurationFast animations:^{
|
||||
self.mainTableView.frame = CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, (_barType == WXYZ_BottomPayBarTypeDownload?(2 * 50 + 60):(4 * 50 + 60)) + PUB_TABBAR_OFFSET);
|
||||
} completion:^(BOOL finished) {
|
||||
[self removeAllSubviews];
|
||||
[self removeFromSuperview];
|
||||
self.hidden = YES;
|
||||
if (self.bottomPayBarHiddenBlock) {
|
||||
self.bottomPayBarHiddenBlock();
|
||||
}
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - 系统方法
|
||||
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
|
||||
{
|
||||
if (self.canTouchHiddenView) {
|
||||
UIView *touchView = [[touches anyObject] view];
|
||||
if (![touchView isDescendantOfView:self.mainTableView]) {
|
||||
[self hiddenBottomPayBar];
|
||||
|
||||
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:TFLocalizedString(@"您已取消购买")];
|
||||
|
||||
if (self.payCancleChapterBlock) {
|
||||
self.payCancleChapterBlock(_chapterModel.chapter_ids);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
|
||||
{
|
||||
if (CGRectContainsPoint(CGRectMake(0, 0, SCREEN_WIDTH, PUB_NAVBAR_HEIGHT), point) && !self.canTouchHiddenView) {
|
||||
return nil;
|
||||
}
|
||||
return [super hitTest:point withEvent:event];
|
||||
}
|
||||
|
||||
- (void)netRequest
|
||||
{
|
||||
NSString *url = @"";
|
||||
NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
|
||||
|
||||
switch (_productionType) {
|
||||
case TFProductionTypeNovel:
|
||||
case TFProductionTypeAi:
|
||||
{
|
||||
url = Book_Buy_Index;
|
||||
[parameters setObject:[TFUtilsHelper formatStringWithInteger:_chapterModel.production_id] forKey:@"book_id"];
|
||||
[parameters setObject:[TFUtilsHelper formatStringWithInteger:_chapterModel.chapter_id] forKey:@"chapter_id"];
|
||||
|
||||
if (_barType == WXYZ_BottomPayBarTypeDownload) {
|
||||
[parameters setObject:@"down" forKey:@"page_from"];
|
||||
[parameters setObject:[TFUtilsHelper formatStringWithInteger:_buyChapterNum] forKey:@"num"];
|
||||
} else {
|
||||
[parameters setObject:@"read" forKey:@"page_from"];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case TFProductionTypeComic:
|
||||
{
|
||||
url = Comic_Buy_Index;
|
||||
|
||||
[parameters setObject:[TFUtilsHelper formatStringWithInteger:_chapterModel.production_id] forKey:@"comic_id"];
|
||||
if (_barType == WXYZ_BottomPayBarTypeDownload) {
|
||||
[parameters setObject:[_chapterModel.chapter_ids componentsJoinedByString:@","] forKey:@"chapter_id"];
|
||||
[parameters setObject:@"down" forKey:@"page_from"];
|
||||
} else {
|
||||
[parameters setObject:[TFUtilsHelper formatStringWithInteger:_chapterModel.chapter_id] forKey:@"chapter_id"];
|
||||
[parameters setObject:@"read" forKey:@"page_from"];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case TFProductionTypeAudio:
|
||||
{
|
||||
url = Audio_Buy_Index;
|
||||
|
||||
[parameters setObject:[TFUtilsHelper formatStringWithInteger:_chapterModel.production_id] forKey:@"audio_id"];
|
||||
if (_barType == WXYZ_BottomPayBarTypeDownload) {
|
||||
[parameters setObject:[_chapterModel.chapter_ids componentsJoinedByString:@","] forKey:@"chapter_id"];
|
||||
[parameters setObject:@"down" forKey:@"page_from"];
|
||||
} else {
|
||||
[parameters setObject:[TFUtilsHelper formatStringWithInteger:_chapterModel.chapter_id] forKey:@"chapter_id"];
|
||||
[parameters setObject:@"read" forKey:@"page_from"];
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
WS(weakSelf)
|
||||
[TFNetworkTools POST:url parameters:[parameters copy] model:nil success:^(BOOL isSuccess, NSDictionary * _Nullable t_model, TFNetworkRequestModel * _Nonnull requestModel) {
|
||||
if (isSuccess) {
|
||||
SS(strongSelf)
|
||||
[TFUserInfoManager shareInstance].totalRemain = [[[t_model objectForKey:@"data"] objectForKey:@"remain"] integerValue];
|
||||
if (strongSelf) {
|
||||
strongSelf->_payBarModel = [WXYZ_ChapterPayBarModel modelWithDictionary:[t_model objectForKey:@"data"]];
|
||||
}
|
||||
[weakSelf.mainTableView reloadData];
|
||||
}
|
||||
} failure:nil];
|
||||
}
|
||||
|
||||
- (void)chapterPayRequest
|
||||
{
|
||||
NSString *url = @"";
|
||||
NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
|
||||
|
||||
switch (_productionType) {
|
||||
case TFProductionTypeNovel:
|
||||
case TFProductionTypeAi:
|
||||
{
|
||||
url = Book_Buy_Chapter;
|
||||
[parameters setObject:[TFUtilsHelper formatStringWithInteger:_chapterModel.production_id] forKey:@"book_id"];
|
||||
[parameters setObject:[TFUtilsHelper formatStringWithInteger:_chapterModel.chapter_id] forKey:@"chapter_id"];
|
||||
[parameters setObject:[TFUtilsHelper formatStringWithInteger:_buyChapterNum] forKey:@"num"];
|
||||
}
|
||||
break;
|
||||
case TFProductionTypeComic:
|
||||
{
|
||||
url = Comic_Buy_Chapter;
|
||||
[parameters setObject:[TFUtilsHelper formatStringWithInteger:_chapterModel.production_id] forKey:@"comic_id"];
|
||||
|
||||
if (_barType == WXYZ_BottomPayBarTypeDownload) {
|
||||
[parameters setObject:[_chapterModel.chapter_ids componentsJoinedByString:@","] forKey:@"chapter_id"];
|
||||
|
||||
} else {
|
||||
[parameters setObject:[TFUtilsHelper formatStringWithInteger:_chapterModel.chapter_id] forKey:@"chapter_id"];
|
||||
[parameters setObject:[TFUtilsHelper formatStringWithInteger:_buyChapterNum] forKey:@"num"];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case TFProductionTypeAudio:
|
||||
{
|
||||
url = Audio_Buy_Chapter;
|
||||
[parameters setObject:[TFUtilsHelper formatStringWithInteger:_chapterModel.production_id] forKey:@"audio_id"];
|
||||
[parameters setObject:[TFUtilsHelper formatStringWithInteger:_buyChapterNum] forKey:@"num"];
|
||||
|
||||
if (_barType == WXYZ_BottomPayBarTypeDownload) {
|
||||
[parameters setObject:[_chapterModel.chapter_ids componentsJoinedByString:@","] forKey:@"chapter_id"];
|
||||
} else {
|
||||
[parameters setObject:[TFUtilsHelper formatStringWithInteger:_chapterModel.chapter_id] forKey:@"chapter_id"];
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
[TFNetworkTools POST:url parameters:parameters model:nil success:^(BOOL isSuccess, id _Nullable t_model, TFNetworkRequestModel * _Nonnull requestModel) {
|
||||
if (isSuccess) {
|
||||
|
||||
NSArray<NSString *> *t_arr = [requestModel.data objectForKey:@"chapter_ids"];
|
||||
if (self.paySuccessChaptersBlock) {
|
||||
self.paySuccessChaptersBlock(t_arr);
|
||||
}
|
||||
|
||||
[TFPromptManager showPromptViewWithStatus:TFPromptStatusSuccess promptTitle:TFLocalizedString(@"购买成功")];
|
||||
NSInteger index = [TFReaderBookManager sharedManager].currentChapterIndex;
|
||||
for (NSInteger i = index; i < index + t_arr.count; i++) {
|
||||
[TFReaderBookManager sharedManager].bookModel.chapter_list[index].is_preview = NO;
|
||||
}
|
||||
if (_productionType == TFProductionTypeNovel || _productionType == TFProductionTypeAi) {
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:NSNotification_Retry_Chapter object:nil];
|
||||
}
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Production_Pay_Success object:t_arr];
|
||||
|
||||
} else {
|
||||
!self.payFailChaptersBlock ?: self.payFailChaptersBlock(_chapterModel.chapter_ids);
|
||||
}
|
||||
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
|
||||
[TFPromptManager showPromptWithError:error defaultText:nil];
|
||||
}];
|
||||
}
|
||||
|
||||
@end
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
//
|
||||
// WXYZ_ChapterBottomPayBarAutoBuyTableViewCell.h
|
||||
// WXReader
|
||||
//
|
||||
// Created by Andrew on 2020/7/27.
|
||||
// Copyright © 2020 Andrew. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TFBasicTableViewCell.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface WXYZ_ChapterBottomPayBarAutoBuyTableViewCell : TFBasicTableViewCell
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
//
|
||||
// WXYZ_ChapterBottomPayBarAutoBuyTableViewCell.m
|
||||
// WXReader
|
||||
//
|
||||
// Created by Andrew on 2020/7/27.
|
||||
// Copyright © 2020 Andrew. All rights reserved.
|
||||
//
|
||||
|
||||
#import "WXYZ_ChapterBottomPayBarAutoBuyTableViewCell.h"
|
||||
#import <AudioToolbox/AudioToolbox.h>
|
||||
#import "KLSwitch.h"
|
||||
|
||||
@implementation WXYZ_ChapterBottomPayBarAutoBuyTableViewCell
|
||||
|
||||
- (void)createSubviews
|
||||
{
|
||||
[super createSubviews];
|
||||
|
||||
WS(weakSelf)
|
||||
KLSwitch *autoBuySwitch = [[KLSwitch alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - 51 - kMargin, 10, 51, 31) didChangeHandler:^(BOOL isOn) {
|
||||
[weakSelf autoBuyNetRequest];
|
||||
}];
|
||||
autoBuySwitch.transform = CGAffineTransformMakeScale(0.7, 0.7);//缩放
|
||||
autoBuySwitch.onTintColor = kMainColor;
|
||||
[autoBuySwitch setDefaultOnState:[TFUserInfoManager shareInstance].auto_sub];
|
||||
[self.contentView addSubview:autoBuySwitch];
|
||||
|
||||
[autoBuySwitch mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.centerY.mas_equalTo(self.contentView.mas_centerY);
|
||||
make.right.mas_equalTo(self.contentView.mas_right).with.offset(- kMargin);
|
||||
make.width.mas_equalTo(51);
|
||||
make.height.mas_offset(31);
|
||||
}];
|
||||
|
||||
|
||||
UILabel *autoBuyTitleLabel = [[UILabel alloc] init];
|
||||
autoBuyTitleLabel.text = TFLocalizedString(@"自动购买下一章");
|
||||
autoBuyTitleLabel.textColor = kBlackColor;
|
||||
autoBuyTitleLabel.font = kMainFont;
|
||||
autoBuyTitleLabel.textAlignment = NSTextAlignmentLeft;
|
||||
[self.contentView addSubview:autoBuyTitleLabel];
|
||||
|
||||
[autoBuyTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(self.contentView.mas_left).with.offset(kMargin);
|
||||
make.right.mas_equalTo(autoBuySwitch.mas_left).with.offset(- kHalfMargin);
|
||||
make.top.mas_equalTo(self.contentView.mas_top);
|
||||
make.bottom.mas_equalTo(self.contentView.mas_bottom);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)autoBuyNetRequest
|
||||
{
|
||||
[TFNetworkTools POST:Auto_Sub_Chapter parameters:nil model:nil success:^(BOOL isSuccess, NSDictionary * _Nullable t_model, TFNetworkRequestModel * _Nonnull requestModel) {
|
||||
if (isSuccess) {
|
||||
NSString *auto_sub_state = [NSString stringWithFormat:@"%@", [[t_model objectForKey:@"data"] objectForKey:@"auto_sub"]];
|
||||
if (auto_sub_state && auto_sub_state.length > 0) {
|
||||
AudioServicesPlaySystemSound(1519);
|
||||
[TFUserInfoManager shareInstance].auto_sub = [auto_sub_state isEqualToString:@"1"];
|
||||
}
|
||||
}
|
||||
} failure:nil];
|
||||
}
|
||||
|
||||
@end
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
//
|
||||
// WXYZ_ChapterBottomPayBarBalanceTableViewCell.h
|
||||
// WXReader
|
||||
//
|
||||
// Created by Andrew on 2020/7/27.
|
||||
// Copyright © 2020 Andrew. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TFBasicTableViewCell.h"
|
||||
#import "WXYZ_ChapterPayBarModel.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface WXYZ_ChapterBottomPayBarBalanceTableViewCell : TFBasicTableViewCell
|
||||
|
||||
@property (nonatomic, strong) WXYZ_ChapterPayBarInfoModel *base_info;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
//
|
||||
// WXYZ_ChapterBottomPayBarBalanceTableViewCell.m
|
||||
// WXReader
|
||||
//
|
||||
// Created by Andrew on 2020/7/27.
|
||||
// Copyright © 2020 Andrew. All rights reserved.
|
||||
//
|
||||
|
||||
#import "WXYZ_ChapterBottomPayBarBalanceTableViewCell.h"
|
||||
|
||||
@implementation WXYZ_ChapterBottomPayBarBalanceTableViewCell
|
||||
{
|
||||
UILabel *balanceDetailTitleLabel;
|
||||
}
|
||||
|
||||
- (void)createSubviews
|
||||
{
|
||||
[super createSubviews];
|
||||
|
||||
UILabel *balanceTitleLabel = [[UILabel alloc] init];
|
||||
balanceTitleLabel.text = TFLocalizedString(@"账户余额");
|
||||
balanceTitleLabel.textColor = kBlackColor;
|
||||
balanceTitleLabel.font = kMainFont;
|
||||
balanceTitleLabel.textAlignment = NSTextAlignmentLeft;
|
||||
[self.contentView addSubview:balanceTitleLabel];
|
||||
|
||||
[balanceTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(self.contentView.mas_left).with.offset(kMargin);
|
||||
make.width.mas_equalTo(150);
|
||||
make.top.mas_equalTo(self.contentView.mas_top);
|
||||
make.bottom.mas_equalTo(self.contentView.mas_bottom);
|
||||
}];
|
||||
|
||||
balanceDetailTitleLabel = [[UILabel alloc] init];
|
||||
balanceDetailTitleLabel.text = [NSString stringWithFormat:@"0%@", Main_Unit_Name];
|
||||
balanceDetailTitleLabel.textColor = kGrayTextColor;
|
||||
balanceDetailTitleLabel.font = kFont12;
|
||||
balanceDetailTitleLabel.textAlignment = NSTextAlignmentRight;
|
||||
[self.contentView addSubview:balanceDetailTitleLabel];
|
||||
|
||||
[balanceDetailTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(balanceTitleLabel.mas_right);
|
||||
make.right.mas_equalTo(self.contentView.mas_right).with.offset(- kMargin);
|
||||
make.top.mas_equalTo(balanceTitleLabel.mas_top);
|
||||
make.height.mas_equalTo(balanceTitleLabel.mas_height);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)setBase_info:(WXYZ_ChapterPayBarInfoModel *)base_info
|
||||
{
|
||||
if (_base_info != base_info) {
|
||||
_base_info = base_info;
|
||||
|
||||
if (TFUserInfoManager.isLogin) {
|
||||
NSString *constString = @"";
|
||||
if (base_info.gold_remain == 0 && base_info.silver_remain > 0) {
|
||||
constString = [constString stringByAppendingString:[NSString stringWithFormat:@"%@%@", [TFUtilsHelper formatStringWithInteger:base_info.silver_remain], base_info.subUnit?:@""]];
|
||||
} else if (base_info.gold_remain > 0 && base_info.silver_remain == 0) {
|
||||
constString = [constString stringByAppendingString:[NSString stringWithFormat:@"%@%@", [TFUtilsHelper formatStringWithInteger:base_info.gold_remain], base_info.unit?:@""]];
|
||||
} else {
|
||||
constString = [constString stringByAppendingString:[NSString stringWithFormat:@"%@%@ + %@%@", [TFUtilsHelper formatStringWithInteger:base_info.gold_remain], base_info.unit?:@"", [TFUtilsHelper formatStringWithInteger:base_info.silver_remain], base_info.subUnit?:@""]];
|
||||
}
|
||||
balanceDetailTitleLabel.text = constString;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
//
|
||||
// WXYZ_ChapterBottomPayBarCostTableViewCell.h
|
||||
// WXReader
|
||||
//
|
||||
// Created by Andrew on 2020/7/27.
|
||||
// Copyright © 2020 Andrew. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TFBasicTableViewCell.h"
|
||||
#import "WXYZ_ChapterPayBarModel.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface WXYZ_ChapterBottomPayBarCostTableViewCell : TFBasicTableViewCell
|
||||
|
||||
@property (nonatomic, copy) void (^buyChapterClickBlock)(BOOL needRecharge);
|
||||
|
||||
@property (nonatomic, strong) WXYZ_ChapterPayBarInfoModel *base_info;
|
||||
|
||||
@property (nonatomic, strong) WXYZ_ChapterPayBarOptionModel *buyOptionModel;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
+162
@@ -0,0 +1,162 @@
|
||||
//
|
||||
// WXYZ_ChapterBottomPayBarCostTableViewCell.m
|
||||
// WXReader
|
||||
//
|
||||
// Created by Andrew on 2020/7/27.
|
||||
// Copyright © 2020 Andrew. All rights reserved.
|
||||
//
|
||||
|
||||
#import "WXYZ_ChapterBottomPayBarCostTableViewCell.h"
|
||||
|
||||
@implementation WXYZ_ChapterBottomPayBarCostTableViewCell
|
||||
{
|
||||
UIButton *buyChapterButton;
|
||||
UILabel *buyPriceLabel;
|
||||
UILabel *buyOriginalPriceLabel;
|
||||
}
|
||||
|
||||
- (void)createSubviews
|
||||
{
|
||||
[super createSubviews];
|
||||
|
||||
self.contentView.backgroundColor = kColorRGBA(247, 248, 250, 1);
|
||||
|
||||
buyChapterButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
buyChapterButton.layer.cornerRadius = 4;
|
||||
buyChapterButton.clipsToBounds = YES;
|
||||
buyChapterButton.backgroundColor = kMainColor;
|
||||
[buyChapterButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
|
||||
[buyChapterButton.titleLabel setFont:kMainFont];
|
||||
[buyChapterButton addTarget:self action:@selector(buyChapterButtonClick) forControlEvents:UIControlEventTouchUpInside];
|
||||
[self.contentView addSubview:buyChapterButton];
|
||||
|
||||
[buyChapterButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.right.mas_equalTo(self.contentView.mas_right).with.offset(- kMargin);
|
||||
make.centerY.mas_equalTo(self.contentView.mas_centerY);
|
||||
make.height.mas_equalTo(35);
|
||||
make.width.mas_equalTo(100);
|
||||
}];
|
||||
|
||||
buyOriginalPriceLabel = [[UILabel alloc] init];
|
||||
buyOriginalPriceLabel.backgroundColor = [UIColor clearColor];
|
||||
buyOriginalPriceLabel.font = kFont12;
|
||||
buyOriginalPriceLabel.textAlignment = NSTextAlignmentLeft;
|
||||
buyOriginalPriceLabel.numberOfLines = 1;
|
||||
buyOriginalPriceLabel.textColor = kBlackColor;
|
||||
[self.contentView addSubview:buyOriginalPriceLabel];
|
||||
|
||||
[buyOriginalPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(self.contentView.mas_left).with.offset(kMargin);
|
||||
make.right.mas_equalTo(buyChapterButton.mas_left).with.offset(- kHalfMargin);
|
||||
make.bottom.mas_equalTo(self.contentView.mas_bottom).with.offset(- kHalfMargin);
|
||||
make.height.mas_equalTo(20);
|
||||
}];
|
||||
|
||||
buyPriceLabel = [[UILabel alloc] init];
|
||||
buyPriceLabel.backgroundColor = [UIColor clearColor];
|
||||
buyPriceLabel.font = kMainFont;
|
||||
buyPriceLabel.textAlignment = NSTextAlignmentLeft;
|
||||
buyPriceLabel.numberOfLines = 1;
|
||||
[self.contentView addSubview:buyPriceLabel];
|
||||
|
||||
[buyPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(buyOriginalPriceLabel.mas_left);
|
||||
make.right.mas_equalTo(buyOriginalPriceLabel.mas_right);
|
||||
make.top.mas_equalTo(self.contentView.mas_top).with.offset(kHalfMargin);
|
||||
make.bottom.mas_equalTo(buyOriginalPriceLabel.mas_top);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)setBuyOptionModel:(WXYZ_ChapterPayBarOptionModel *)buyOptionModel
|
||||
{
|
||||
_buyOptionModel = buyOptionModel;
|
||||
|
||||
if (TFUserInfoManager.isLogin) {
|
||||
if (self.base_info.remain - buyOptionModel.total_price >= 0) {
|
||||
[buyChapterButton setTitle:TFLocalizedString(@"确认购买") forState:UIControlStateNormal];
|
||||
} else {
|
||||
[buyChapterButton setTitle:TFLocalizedString(@"充值并购买") forState:UIControlStateNormal];
|
||||
}
|
||||
} else {
|
||||
[buyChapterButton setTitle:TFLocalizedString(@"登录后购买") forState:UIControlStateNormal];
|
||||
}
|
||||
|
||||
// 实付
|
||||
buyPriceLabel.attributedText = [self getPriceString];
|
||||
|
||||
// 原价
|
||||
buyOriginalPriceLabel.attributedText = [self getOriginalPriceString];
|
||||
|
||||
if (buyOptionModel.discount.length > 0) {
|
||||
[buyOriginalPriceLabel mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.height.mas_equalTo(20);
|
||||
}];
|
||||
} else {
|
||||
[buyOriginalPriceLabel mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.height.mas_equalTo(CGFLOAT_MIN);
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setBase_info:(WXYZ_ChapterPayBarInfoModel *)base_info
|
||||
{
|
||||
_base_info = base_info;
|
||||
}
|
||||
|
||||
- (void)buyChapterButtonClick
|
||||
{
|
||||
if (self.buyChapterClickBlock) {
|
||||
self.buyChapterClickBlock((self.base_info.remain - self.buyOptionModel.total_price <= 0));
|
||||
}
|
||||
}
|
||||
|
||||
- (NSMutableAttributedString *)getPriceString
|
||||
{
|
||||
NSMutableAttributedString *attributedStr = [[NSMutableAttributedString alloc] init];
|
||||
|
||||
NSString *suffix = nil;
|
||||
|
||||
if (self.buyOptionModel.actual_cost.gold_cost == 0 && self.buyOptionModel.actual_cost.silver_cost > 0) {
|
||||
[attributedStr appendString:[NSString stringWithFormat:@"%@%@%@", TFLocalizedString(@"实付:"), [TFUtilsHelper formatStringWithInteger:self.buyOptionModel.actual_cost.gold_cost], self.base_info.subUnit?:@""]];
|
||||
suffix = [NSString stringWithFormat:@"%@%@", [TFUtilsHelper formatStringWithInteger:self.buyOptionModel.actual_cost.gold_cost], self.base_info.subUnit?:@""];
|
||||
|
||||
} else if (self.buyOptionModel.actual_cost.gold_cost > 0 && self.buyOptionModel.actual_cost.silver_cost == 0) {
|
||||
[attributedStr appendString:[NSString stringWithFormat:@"%@%@%@", TFLocalizedString(@"实付:"), [TFUtilsHelper formatStringWithInteger:self.buyOptionModel.actual_cost.gold_cost], self.base_info.unit?:@""]];
|
||||
suffix = [NSString stringWithFormat:@"%@%@", [TFUtilsHelper formatStringWithInteger:self.buyOptionModel.actual_cost.gold_cost], self.base_info.unit?:@""];
|
||||
|
||||
} else {
|
||||
[attributedStr appendString:[NSString stringWithFormat:@"%@%@%@ + %@%@", TFLocalizedString(@"实付:"), [TFUtilsHelper formatStringWithInteger:self.buyOptionModel.actual_cost.gold_cost], self.base_info.unit?:@"", [TFUtilsHelper formatStringWithInteger:self.buyOptionModel.actual_cost.silver_cost], self.base_info.subUnit?:@""]];
|
||||
suffix = [NSString stringWithFormat:@"%@%@ + %@%@", [TFUtilsHelper formatStringWithInteger:self.buyOptionModel.actual_cost.gold_cost], self.base_info.unit?:@"", [TFUtilsHelper formatStringWithInteger:self.buyOptionModel.actual_cost.silver_cost], self.base_info.subUnit?:@""];
|
||||
}
|
||||
|
||||
|
||||
[attributedStr addAttribute:NSForegroundColorAttributeName value:kMainColor range:NSMakeRange(attributedStr.length - suffix.length, suffix.length)];
|
||||
return attributedStr;
|
||||
}
|
||||
|
||||
- (NSMutableAttributedString *)getOriginalPriceString
|
||||
{
|
||||
NSMutableAttributedString *attributedStr = [[NSMutableAttributedString alloc] init];
|
||||
|
||||
NSString *suffix = nil;
|
||||
|
||||
if (self.buyOptionModel.original_cost.gold_cost == 0 && self.buyOptionModel.original_cost.silver_cost > 0) {
|
||||
[attributedStr appendString:[NSString stringWithFormat:@"%@%@%@", TFLocalizedString(@"原价:"), [TFUtilsHelper formatStringWithInteger:self.buyOptionModel.original_cost.gold_cost], self.base_info.subUnit?:@""]];
|
||||
suffix = [NSString stringWithFormat:@"%@%@", [TFUtilsHelper formatStringWithInteger:self.buyOptionModel.original_cost.gold_cost], self.base_info.subUnit?:@""];
|
||||
|
||||
} else if (self.buyOptionModel.original_cost.gold_cost > 0 && self.buyOptionModel.original_cost.silver_cost == 0) {
|
||||
[attributedStr appendString:[NSString stringWithFormat:@"%@%@%@", TFLocalizedString(@"原价:"), [TFUtilsHelper formatStringWithInteger:self.buyOptionModel.original_cost.gold_cost], self.base_info.unit?:@""]];
|
||||
suffix = [NSString stringWithFormat:@"%@%@", [TFUtilsHelper formatStringWithInteger:self.buyOptionModel.original_cost.gold_cost], self.base_info.unit?:@""];
|
||||
|
||||
} else {
|
||||
[attributedStr appendString:[NSString stringWithFormat:@"%@%@%@ + %@%@", TFLocalizedString(@"原价:"), [TFUtilsHelper formatStringWithInteger:self.buyOptionModel.original_cost.gold_cost], self.base_info.unit?:@"", [TFUtilsHelper formatStringWithInteger:self.buyOptionModel.original_cost.silver_cost], self.base_info.subUnit?:@""]];
|
||||
suffix = [NSString stringWithFormat:@"%@%@ + %@%@", [TFUtilsHelper formatStringWithInteger:self.buyOptionModel.original_cost.gold_cost], self.base_info.unit?:@"", [TFUtilsHelper formatStringWithInteger:self.buyOptionModel.original_cost.silver_cost], self.base_info.subUnit?:@""];
|
||||
|
||||
}
|
||||
|
||||
[attributedStr addAttribute:NSForegroundColorAttributeName value:kGrayTextColor range:NSMakeRange(0, attributedStr.length)];
|
||||
[attributedStr addAttributes:@{NSStrikethroughStyleAttributeName : @(NSUnderlinePatternSolid | NSUnderlineStyleSingle), NSBaselineOffsetAttributeName : @(0)} range:NSMakeRange(attributedStr.length - suffix.length, suffix.length)];
|
||||
return attributedStr;
|
||||
}
|
||||
|
||||
@end
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
//
|
||||
// WXYZ_ChapterBottomPayBarOptionTableViewCell.h
|
||||
// WXReader
|
||||
//
|
||||
// Created by Andrew on 2020/7/27.
|
||||
// Copyright © 2020 Andrew. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TFBasicTableViewCell.h"
|
||||
#import "WXYZ_ChapterPayBarModel.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface WXYZ_ChapterBottomPayBarOptionTableViewCell : TFBasicTableViewCell
|
||||
|
||||
@property (nonatomic, copy) void (^payOptionClickBlock)(WXYZ_ChapterPayBarOptionModel *chapterOptionModel, NSInteger selectIndex);
|
||||
|
||||
@property (nonatomic, strong) NSArray <WXYZ_ChapterPayBarOptionModel *> *pay_options;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
+94
@@ -0,0 +1,94 @@
|
||||
//
|
||||
// WXYZ_ChapterBottomPayBarOptionTableViewCell.m
|
||||
// WXReader
|
||||
//
|
||||
// Created by Andrew on 2020/7/27.
|
||||
// Copyright © 2020 Andrew. All rights reserved.
|
||||
//
|
||||
|
||||
#import "WXYZ_ChapterBottomPayBarOptionTableViewCell.h"
|
||||
|
||||
@implementation WXYZ_ChapterBottomPayBarOptionTableViewCell
|
||||
{
|
||||
UIScrollView *optionScorllView;
|
||||
}
|
||||
|
||||
- (void)createSubviews
|
||||
{
|
||||
[super createSubviews];
|
||||
|
||||
optionScorllView = [[UIScrollView alloc] init];
|
||||
optionScorllView.showsVerticalScrollIndicator = NO;
|
||||
optionScorllView.showsHorizontalScrollIndicator = NO;
|
||||
optionScorllView.backgroundColor = [UIColor whiteColor];
|
||||
[self.contentView addSubview:optionScorllView];
|
||||
|
||||
[optionScorllView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(self.contentView.mas_left);
|
||||
make.top.mas_equalTo(self.contentView.mas_top);
|
||||
make.width.mas_equalTo(self.contentView.mas_width);
|
||||
make.height.mas_equalTo(self.contentView.mas_height);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)setPay_options:(NSArray<WXYZ_ChapterPayBarOptionModel *> *)pay_options
|
||||
{
|
||||
if (_pay_options != pay_options) {
|
||||
_pay_options = pay_options;
|
||||
|
||||
[optionScorllView removeAllSubviews];
|
||||
|
||||
NSInteger buttonNum = pay_options.count;
|
||||
CGFloat button_H = 30;//按钮高
|
||||
CGFloat margin_X = kMargin;//第一个按钮的X坐标
|
||||
CGFloat margin_Y = 10;//第一个按钮的Y坐标
|
||||
CGFloat space_X = kHalfMargin;//按钮间距
|
||||
CGFloat button_X = margin_X;
|
||||
CGFloat button_W = - 10;
|
||||
for (NSInteger i = 0; i < buttonNum; i++) {
|
||||
WXYZ_ChapterPayBarOptionModel *option = [pay_options objectOrNilAtIndex:i];
|
||||
button_X = button_X + button_W + space_X;
|
||||
button_W = [TFViewHelper getDynamicWidthWithLabelFont:kMainFont labelHeight:30 labelText:option.label] + 10;//按钮宽
|
||||
|
||||
UIButton *optionButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
optionButton.frame = CGRectMake(button_X, margin_Y, button_W, button_H);
|
||||
optionButton.layer.cornerRadius = 4;
|
||||
optionButton.backgroundColor = [UIColor whiteColor];
|
||||
optionButton.tag = i;
|
||||
[optionButton.titleLabel setFont:kMainFont];
|
||||
[optionButton setTitle:option.label?:@"" forState:UIControlStateNormal];
|
||||
[optionButton setTitleColor:kGrayTextColor forState:UIControlStateNormal];
|
||||
[optionButton addTarget:self action:@selector(optionButtonClick:) forControlEvents:UIControlEventTouchUpInside];
|
||||
[optionScorllView addSubview:optionButton];
|
||||
|
||||
if (i == buttonNum - 1) {
|
||||
[optionScorllView setContentSize:CGSizeMake(optionButton.right, 0)];
|
||||
}
|
||||
|
||||
if (buttonNum > 0 && i == 0) {
|
||||
optionButton.backgroundColor = kMainColor;
|
||||
[optionButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)optionButtonClick:(UIButton *)sender
|
||||
{
|
||||
[optionScorllView.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
||||
if ([obj isKindOfClass:[UIButton class]]) {
|
||||
UIButton *button = (UIButton *)obj;
|
||||
button.backgroundColor = [UIColor whiteColor];
|
||||
[button setTitleColor:kGrayTextColor forState:UIControlStateNormal];
|
||||
}
|
||||
}];
|
||||
|
||||
sender.backgroundColor = kMainColor;
|
||||
[sender setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
|
||||
|
||||
if (self.payOptionClickBlock) {
|
||||
self.payOptionClickBlock([self.pay_options objectOrNilAtIndex:sender.tag], sender.tag);
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
//
|
||||
// WXYZ_ChapterBottomPayBarTitleTableViewCell.h
|
||||
// WXReader
|
||||
//
|
||||
// Created by Andrew on 2020/7/27.
|
||||
// Copyright © 2020 Andrew. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TFBasicTableViewCell.h"
|
||||
#import "WXYZ_ChapterPayBarModel.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface WXYZ_ChapterBottomPayBarTitleTableViewCell : TFBasicTableViewCell
|
||||
|
||||
@property (nonatomic, strong) WXYZ_ChapterPayBarOptionModel *buyOptionModel;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
//
|
||||
// WXYZ_ChapterBottomPayBarTitleTableViewCell.m
|
||||
// WXReader
|
||||
//
|
||||
// Created by Andrew on 2020/7/27.
|
||||
// Copyright © 2020 Andrew. All rights reserved.
|
||||
//
|
||||
|
||||
#import "WXYZ_ChapterBottomPayBarTitleTableViewCell.h"
|
||||
|
||||
@implementation WXYZ_ChapterBottomPayBarTitleTableViewCell
|
||||
{
|
||||
UILabel *payBarTitleLabel;
|
||||
|
||||
// 打折信息
|
||||
UILabel *discountTitleLabel;
|
||||
}
|
||||
|
||||
- (void)createSubviews
|
||||
{
|
||||
[super createSubviews];
|
||||
|
||||
payBarTitleLabel = [[UILabel alloc] init];
|
||||
payBarTitleLabel.text = TFLocalizedString(@"从本章开始购买");
|
||||
payBarTitleLabel.textColor = kBlackColor;
|
||||
payBarTitleLabel.font = kMainFont;
|
||||
payBarTitleLabel.textAlignment = NSTextAlignmentCenter;
|
||||
[self.contentView addSubview:payBarTitleLabel];
|
||||
|
||||
[payBarTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.mas_equalTo(self.contentView.mas_top);
|
||||
make.centerX.mas_equalTo(self.contentView.mas_centerX).with.offset(CGFLOAT_MIN);
|
||||
make.width.mas_equalTo(SCREEN_WIDTH);
|
||||
make.bottom.mas_equalTo(self.contentView.mas_bottom);
|
||||
}];
|
||||
|
||||
discountTitleLabel = [[UILabel alloc] init];
|
||||
discountTitleLabel.textColor = kWhiteColor;
|
||||
discountTitleLabel.textAlignment = NSTextAlignmentCenter;
|
||||
discountTitleLabel.font = kFont10;
|
||||
discountTitleLabel.backgroundColor = kRedColor;
|
||||
discountTitleLabel.layer.cornerRadius = 2;
|
||||
discountTitleLabel.clipsToBounds = YES;
|
||||
[self.contentView addSubview:discountTitleLabel];
|
||||
|
||||
[discountTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(payBarTitleLabel.mas_right).with.offset(kQuarterMargin);
|
||||
make.centerY.mas_equalTo(payBarTitleLabel.mas_centerY);
|
||||
make.width.mas_equalTo(CGFLOAT_MIN);
|
||||
make.height.mas_equalTo(16);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)setBuyOptionModel:(WXYZ_ChapterPayBarOptionModel *)buyOptionModel
|
||||
{
|
||||
_buyOptionModel = buyOptionModel;
|
||||
|
||||
payBarTitleLabel.text = buyOptionModel.label?:TFLocalizedString(@"从本章开始购买");
|
||||
|
||||
if (buyOptionModel.discount.length > 0 && buyOptionModel.discount) {
|
||||
discountTitleLabel.text = buyOptionModel.discount?:@"";
|
||||
|
||||
CGFloat t_width = [TFViewHelper getDynamicWidthWithLabel:discountTitleLabel] + kQuarterMargin;
|
||||
[discountTitleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.width.mas_equalTo(t_width);
|
||||
}];
|
||||
|
||||
[payBarTitleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.centerX.mas_equalTo(self.contentView.mas_centerX).with.offset(- t_width / 2);
|
||||
make.width.mas_equalTo([TFViewHelper getDynamicWidthWithLabel:payBarTitleLabel]);
|
||||
}];
|
||||
} else {
|
||||
[discountTitleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.width.mas_equalTo(CGFLOAT_MIN);
|
||||
}];
|
||||
|
||||
[payBarTitleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.centerX.mas_equalTo(self.contentView.mas_centerX).with.offset(CGFLOAT_MIN);
|
||||
make.width.mas_equalTo(SCREEN_WIDTH);
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,71 @@
|
||||
//
|
||||
// WXYZ_ChapterPayBarModel.h
|
||||
// WXReader
|
||||
//
|
||||
// Created by Andrew on 2018/7/15.
|
||||
// Copyright © 2018年 Andrew. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@class WXYZ_ChapterPayBarInfoModel, WXYZ_ChapterPayBarOptionModel, Actual_Cost, Original_Cost;
|
||||
@interface WXYZ_ChapterPayBarModel : NSObject
|
||||
|
||||
@property (nonatomic, strong) WXYZ_ChapterPayBarInfoModel *base_info;
|
||||
|
||||
@property (nonatomic, strong) NSArray <WXYZ_ChapterPayBarOptionModel *> *pay_options;
|
||||
|
||||
@end
|
||||
|
||||
@interface WXYZ_ChapterPayBarInfoModel : NSObject
|
||||
|
||||
@property (nonatomic, assign) NSInteger remain;
|
||||
|
||||
@property (nonatomic, assign) NSInteger gold_remain;
|
||||
|
||||
@property (nonatomic, assign) NSInteger silver_remain;
|
||||
|
||||
@property (nonatomic, copy) NSString *unit;
|
||||
|
||||
@property (nonatomic, copy) NSString *subUnit;
|
||||
|
||||
@property (nonatomic, assign) NSInteger chapter_id;
|
||||
|
||||
@property (nonatomic, assign) NSInteger auto_sub;
|
||||
|
||||
@end
|
||||
|
||||
@interface WXYZ_ChapterPayBarOptionModel : NSObject
|
||||
|
||||
@property (nonatomic, strong) Original_Cost *original_cost; // 原价
|
||||
|
||||
@property (nonatomic, assign) NSInteger buy_num;
|
||||
|
||||
@property (nonatomic, assign) NSInteger original_price;
|
||||
|
||||
@property (nonatomic, strong) Actual_Cost *actual_cost; // 实际需要消费的金额
|
||||
|
||||
@property (nonatomic, copy) NSString *discount;
|
||||
|
||||
@property (nonatomic, copy) NSString *label;
|
||||
|
||||
@property (nonatomic, assign) NSInteger total_price;
|
||||
|
||||
@end
|
||||
|
||||
@interface Actual_Cost : NSObject
|
||||
|
||||
@property (nonatomic, assign) NSInteger gold_cost;
|
||||
|
||||
@property (nonatomic, assign) NSInteger silver_cost;
|
||||
|
||||
@end
|
||||
|
||||
@interface Original_Cost : NSObject
|
||||
|
||||
@property (nonatomic, assign) NSInteger gold_cost;
|
||||
|
||||
@property (nonatomic, assign) NSInteger silver_cost;
|
||||
|
||||
@end
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
//
|
||||
// WXYZ_ChapterPayBarModel.m
|
||||
// WXReader
|
||||
//
|
||||
// Created by Andrew on 2018/7/15.
|
||||
// Copyright © 2018年 Andrew. All rights reserved.
|
||||
//
|
||||
|
||||
#import "WXYZ_ChapterPayBarModel.h"
|
||||
|
||||
@implementation WXYZ_ChapterPayBarModel
|
||||
|
||||
+ (NSDictionary<NSString *,id> *)modelContainerPropertyGenericClass{
|
||||
return @{@"pay_options" : [WXYZ_ChapterPayBarOptionModel class]};
|
||||
}
|
||||
|
||||
+ (NSDictionary *)modelCustomPropertyMapper {
|
||||
return @{
|
||||
@"pay_options" :@"buy_option"
|
||||
};
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation WXYZ_ChapterPayBarInfoModel
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation WXYZ_ChapterPayBarOptionModel
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation Actual_Cost
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation Original_Cost
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user