小说绘上架版本

This commit is contained in:
xtfei2011
2021-02-07 11:24:08 +08:00
commit ee5c1c8b12
1762 changed files with 115892 additions and 0 deletions
@@ -0,0 +1,25 @@
//
// WXYZ_AudioDownloadTableViewCell.h
// WXReader
//
// Created by Andrew on 2020/3/20.
// Copyright © 2020 Andrew. All rights reserved.
//
#import "TFBasicTableViewCell.h"
#import "WXYZ_DownloadManagerEnumProtocol.h"
NS_ASSUME_NONNULL_BEGIN
@interface WXYZ_AudioDownloadTableViewCell : TFBasicTableViewCell
@property (nonatomic, strong) TFProductionChapterModel *chapterModel;
// 是否是缓存状态
@property (nonatomic, assign) BOOL isCacheState;
@property (nonatomic, assign) WXYZ_ProductionDownloadState cellDownloadState;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,146 @@
//
// WXYZ_AudioDownloadTableViewCell.m
// WXReader
//
// Created by Andrew on 2020/3/20.
// Copyright © 2020 Andrew. All rights reserved.
//
#import "WXYZ_AudioDownloadTableViewCell.h"
#import "WXYZ_AudioDownloadManager.h"
@implementation WXYZ_AudioDownloadTableViewCell
{
UIImageView *selectImageView;
UILabel *audioChapterLabel;
UIImageView *fileIcon;
UILabel *fileLabel;
}
- (void)createSubviews
{
[super createSubviews];
selectImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"audio_download_unselect"]];
[self.contentView addSubview:selectImageView];
[selectImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.contentView.mas_left).with.offset(kMargin);
make.centerY.mas_equalTo(self.contentView.mas_centerY);
make.width.height.mas_equalTo(20);
}];
audioChapterLabel = [[UILabel alloc] init];
audioChapterLabel.textAlignment = NSTextAlignmentLeft;
audioChapterLabel.textColor = kBlackColor;
audioChapterLabel.font = kMainFont;
audioChapterLabel.numberOfLines = 2;
[self.contentView addSubview:audioChapterLabel];
[audioChapterLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(selectImageView.mas_right).with.offset(kMargin);
make.top.mas_equalTo(self.contentView.mas_top).with.offset(kHalfMargin);
make.right.mas_equalTo(self.contentView.mas_right).with.offset(- kMargin);
make.height.mas_equalTo(15);
}];
fileIcon = [[UIImageView alloc] initWithImage:[[UIImage imageNamed:@"audio_file_icon"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]];
fileIcon.userInteractionEnabled = YES;
fileIcon.tintColor = kGrayTextColor;
[self.contentView addSubview:fileIcon];
[fileIcon mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(audioChapterLabel.mas_left);
make.top.mas_equalTo(audioChapterLabel.mas_bottom).with.offset(kQuarterMargin);
make.width.mas_equalTo(15);
make.height.mas_equalTo(15);
}];
fileLabel = [[UILabel alloc] init];
fileLabel.textColor = kGrayTextColor;
fileLabel.textAlignment = NSTextAlignmentLeft;
fileLabel.font = kFont10;
[self.contentView addSubview:fileLabel];
[fileLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(fileIcon.mas_right).with.offset(kQuarterMargin);
make.centerY.mas_equalTo(fileIcon.mas_centerY);
make.right.mas_equalTo(self.contentView.mas_right).with.offset(-kMargin);
make.height.mas_equalTo(fileIcon.mas_height);
make.bottom.mas_equalTo(self.contentView.mas_bottom).with.offset(-kHalfMargin).priorityLow();
}];
}
- (void)setChapterModel:(TFProductionChapterModel *)chapterModel
{
_chapterModel = chapterModel;
fileLabel.text = [TFUtilsHelper convertFileSize:chapterModel.size];
NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:chapterModel.chapter_title ? : @""];
if (chapterModel.is_preview == 1 && [[WXYZ_AudioDownloadManager sharedManager] getChapterDownloadStateWithProduction_id:chapterModel.production_id chapter_id:chapterModel.chapter_id] != WXYZ_ProductionDownloadStateDownloaded) {
NSTextAttachment *attch = [[NSTextAttachment alloc] init];
attch.image = [UIImage imageNamed:TFLocalizedString(@"audio_directory_pay")];
attch.bounds = CGRectMake(0, 0, kGeometricWidth(10, 246, 90), 10);
NSAttributedString *string = [NSAttributedString attributedStringWithAttachment:attch];
[attri insertAttributedString:string atIndex:0];
}
audioChapterLabel.attributedText = attri;
}
- (void)setCellDownloadState:(WXYZ_ProductionDownloadState)cellDownloadState
{
if (_cellDownloadState != cellDownloadState) {
_cellDownloadState = cellDownloadState;
switch (cellDownloadState) {
case WXYZ_ProductionDownloadStateNormal:
{
selectImageView.image = [UIImage imageNamed:@"audio_download_unselect"];
audioChapterLabel.textColor = kBlackColor;
self.backgroundColor = kWhiteColor;
}
break;
case WXYZ_ProductionDownloadStateDownloading:
{
selectImageView.image = [UIImage imageNamed:@"audio_downloading_list"];
audioChapterLabel.textColor = kBlackColor;
self.backgroundColor = kWhiteColor;
}
break;
case WXYZ_ProductionDownloadStateDownloaded:
{
if (self.isCacheState) {
selectImageView.image = [UIImage imageNamed:@"audio_download_unselect"];
audioChapterLabel.textColor = kBlackColor;
self.backgroundColor = kWhiteColor;
} else {
selectImageView.image = [UIImage imageNamed:@"audio_download_unenable"];
audioChapterLabel.textColor = kGrayTextColor;
self.backgroundColor = kGrayViewColor;
}
}
break;
case WXYZ_ProductionDownloadStateSelected:
{
selectImageView.image = [UIImage imageNamed:@"audio_download_select"];
audioChapterLabel.textColor = kBlackColor;
self.backgroundColor = kWhiteColor;
}
break;
case WXYZ_ProductionDownloadStateFail:
selectImageView.image = [UIImage imageNamed:@"audio_download_fail_list"];
audioChapterLabel.textColor = kBlackColor;
self.backgroundColor = kWhiteColor;
break;
default:
break;
}
}
}
@end
@@ -0,0 +1,20 @@
//
// WXYZ_AudioDownloadViewController.h
// WXReader
//
// Created by Andrew on 2020/3/20.
// Copyright © 2020 Andrew. All rights reserved.
//
#import "TFDownloadViewController.h"
NS_ASSUME_NONNULL_BEGIN
@interface WXYZ_AudioDownloadViewController : TFDownloadViewController
// 预防作品model为空的情况
@property (nonatomic, assign) NSInteger production_id;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,517 @@
//
// WXYZ_AudioDownloadViewController.m
// WXReader
//
// Created by Andrew on 2020/3/20.
// Copyright © 2020 Andrew. All rights reserved.
//
#import "WXYZ_AudioDownloadViewController.h"
#import "WXYZ_AudioDownloadTableViewCell.h"
#import "WXYZ_AudioPlayPageMenuView.h"
#import "WXYZ_AudioDownloadManager.h"
#import "TFReadRecordManager.h"
#import "WXYZ_ChapterBottomPayBar.h"
@interface WXYZ_AudioDownloadViewController () <UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) TFProductionModel *audioModel;
@property (nonatomic, assign) CGFloat totalMemorySize;
@property (nonatomic, assign) BOOL payBarShowing;
@property (nonatomic, strong) UIButton *downloadButton;
@property (nonatomic, strong) UIActivityIndicatorView *downloadIndicatorView;
@property (nonatomic, strong) WXYZ_AudioDownloadManager *audioDownloadManager;
@property (nonatomic, weak) UILabel *headerTitleLabel;
@end
@implementation WXYZ_AudioDownloadViewController
{
UILabel *memoryBarView;
TFButton *selectAllButton;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self initialize];
[self createSubviews];
[self initDownloadManager];
[self netRequest];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self setStatusBarDefaultStyle];
}
- (void)initialize
{
[self setNavigationBarTitle:TFLocalizedString(@"批量下载")];
self.totalMemorySize = 0;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(netRequest) name:Notification_Login_Success object:nil];
}
- (void)createSubviews
{
self.mainTableView.delegate = self;
self.mainTableView.dataSource = self;
[self.view addSubview:self.mainTableView];
[self.mainTableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.top.mas_equalTo(PUB_NAVBAR_HEIGHT);
make.width.mas_equalTo(self.view.mas_width);
make.height.mas_equalTo(self.view.mas_height).with.offset(- PUB_NAVBAR_HEIGHT - PUB_TABBAR_HEIGHT - 20);
}];
memoryBarView = [[UILabel alloc] init];
memoryBarView.numberOfLines = 2;
memoryBarView.backgroundColor = kColorRGB(251, 251, 251);
memoryBarView.font = kFont10;
memoryBarView.textAlignment = NSTextAlignmentCenter;
memoryBarView.textColor = kGrayTextColor;
memoryBarView.text =[NSString stringWithFormat:@"%@%@", TFLocalizedString(@"可用空间"), [TFUtilsHelper getRemainingMemorySpace]];
[self.view addSubview:memoryBarView];
[memoryBarView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.top.mas_equalTo(self.mainTableView.mas_bottom);
make.width.mas_equalTo(SCREEN_WIDTH);
make.height.mas_equalTo(20);
}];
selectAllButton = [[TFButton alloc] initWithFrame:CGRectZero buttonTitle:TFLocalizedString(@"全选") buttonImageName:@"audio_download_unselect" buttonIndicator:TFButtonIndicatorImageLeftBothLeft];
selectAllButton.buttonTitleColor = kBlackColor;
selectAllButton.buttonTitleFont = kMainFont;
selectAllButton.graphicDistance = 10;
selectAllButton.buttonImageScale = 0.4;
selectAllButton.hidden = YES;
selectAllButton.tag = 0;
selectAllButton.backgroundColor = [UIColor whiteColor];
[selectAllButton addTarget:self action:@selector(checkallClick:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:selectAllButton];
[selectAllButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(kMargin);
make.top.equalTo(memoryBarView.mas_bottom);
make.height.mas_equalTo(PUB_TABBAR_HEIGHT - PUB_TABBAR_OFFSET);
}];
self.downloadButton = [UIButton buttonWithType:UIButtonTypeCustom];
self.downloadButton.backgroundColor = kGrayTextLightColor;
self.downloadButton.enabled = NO;
[self.downloadButton setTitle:TFLocalizedString(@"立即下载") forState:UIControlStateNormal];
[self.downloadButton setTitleColor:kWhiteColor forState:UIControlStateNormal];
[self.downloadButton.titleLabel setFont:kMainFont];
[self.downloadButton addTarget:self action:@selector(downloadClick) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:self.downloadButton];
[self.downloadButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(self.view.mas_right);
make.top.mas_equalTo(selectAllButton.mas_top);
make.width.mas_equalTo(SCREEN_WIDTH / 3);
make.height.mas_equalTo(selectAllButton.mas_height);
}];
[selectAllButton mas_updateConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.downloadButton.mas_left).offset(-kHalfMargin);
}];
self.downloadIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:(UIActivityIndicatorViewStyleGray)];
self.downloadIndicatorView.hidesWhenStopped = YES;
[self.downloadButton addSubview:self.downloadIndicatorView];
[self.downloadIndicatorView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self.downloadButton.mas_centerX);
make.centerY.mas_equalTo(self.downloadButton.mas_centerY);
make.width.height.mas_equalTo(self.downloadButton.mas_height);
}];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.dataSourceArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
TFProductionChapterModel *chapterModel = [self.dataSourceArray objectOrNilAtIndex:indexPath.row];
static NSString *cellName = @"WXYZ_AudioDownloadTableViewCell";
WXYZ_AudioDownloadTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName];
if (!cell) {
cell = [[WXYZ_AudioDownloadTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
}
cell.chapterModel = chapterModel;
cell.cellDownloadState = [[self.selectSourceDictionary objectForKey:[TFUtilsHelper formatStringWithInteger:chapterModel.chapter_id]] integerValue];
cell.hiddenEndLine = self.dataSourceArray.count - 1 == indexPath.row;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
//section头间距
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 30;
}
//section头视图
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 30)];
view.backgroundColor = [UIColor clearColor];
UIView *mainView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 30)];
mainView.backgroundColor = kColorRGB(251, 251, 251);
[view addSubview:mainView];
UILabel *headerTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(kMargin, 0, SCREEN_WIDTH / 2, 30)];
self.headerTitleLabel = headerTitleLabel;
headerTitleLabel.backgroundColor = [UIColor clearColor];
headerTitleLabel.font = kFont12;
// headerTitleLabel.text = [NSString stringWithFormat:@"%@ %zd %@", TFLocalizedString(@"已下载"), [[WXYZ_AudioDownloadManager sharedManager] getDownloadChapterCountWithProduction_id:self.audioModel.production_id], TFLocalizedString(@"章")];
headerTitleLabel.text = [NSString stringWithFormat:@"%@ %zd %@", TFLocalizedString(@""), self.dataSourceArray.count, TFLocalizedString(@"")];
headerTitleLabel.textColor = kGrayTextColor;
[mainView addSubview:headerTitleLabel];
CGFloat width = [TFViewHelper getDynamicWidthWithLabelFont:kFont12 labelHeight:30.0 labelText:TFLocalizedString(@"选章标题") maxWidth:240.0];
width += kMargin;
TFButton *selectionButton = [[TFButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - width - kHalfMargin, 0, width, 30) buttonTitle:TFLocalizedString(@"选章标题") buttonImageName:@"audio_selection" buttonIndicator:TFButtonIndicatorTitleRight];
selectionButton.tag = 0;
selectionButton.buttonTintColor = kGrayTextColor;
selectionButton.buttonTitleFont = kFont12;
selectionButton.graphicDistance = 2;
selectionButton.buttonImageScale = 0.4;
[selectionButton addTarget:self action:@selector(selectionButtonClick) forControlEvents:UIControlEventTouchUpInside];
[mainView addSubview:selectionButton];
return view;
}
//section底部间距
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return CGFLOAT_MIN;
}
//section底部视图
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, CGFLOAT_MIN)];
view.backgroundColor = [UIColor clearColor];
return view;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
TFProductionChapterModel *chapterModel = [self.dataSourceArray objectOrNilAtIndex:indexPath.row];
WXYZ_AudioDownloadTableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
switch (cell.cellDownloadState) {
case WXYZ_ProductionDownloadStateNormal:
case WXYZ_ProductionDownloadStateFail:
[self setCollectionCellDownloadStateWithChapter_id:chapterModel.chapter_id downloadState:WXYZ_ProductionDownloadStateSelected];
[self reloadToolBar];
break;
case WXYZ_ProductionDownloadStateSelected:
[self setCollectionCellDownloadStateWithChapter_id:chapterModel.chapter_id downloadState:WXYZ_ProductionDownloadStateNormal];
[self reloadToolBar];
break;
default:
break;
}
}
- (void)checkallClick:(TFButton *)sender
{
self.totalMemorySize = 0;
for (TFProductionChapterModel *chapterModel in self.dataSourceArray) {
if ([[WXYZ_AudioDownloadManager sharedManager] getChapterDownloadStateWithProduction_id:chapterModel.production_id chapter_id:chapterModel.chapter_id] == WXYZ_ProductionDownloadStateNormal) {
self.totalMemorySize = self.totalMemorySize + chapterModel.size;
}
}
for (NSString *t_chapter_id in self.selectSourceDictionary.allKeys) {
if (!sender.selected) { // 全选状态
if ([[self.selectSourceDictionary objectForKey:t_chapter_id] integerValue] == WXYZ_ProductionDownloadStateNormal || [[self.selectSourceDictionary objectForKey:t_chapter_id] integerValue] == WXYZ_ProductionDownloadStateFail) {
[self setCollectionCellDownloadStateWithChapter_id:[t_chapter_id integerValue] downloadState:WXYZ_ProductionDownloadStateSelected];
}
} else {
if ([[self.selectSourceDictionary objectForKey:t_chapter_id] integerValue] == WXYZ_ProductionDownloadStateSelected) {
[self setCollectionCellDownloadStateWithChapter_id:[t_chapter_id integerValue] downloadState:WXYZ_ProductionDownloadStateNormal];
}
}
}
sender.selected = !sender.selected;
[self reloadToolBar];
}
- (void)selectionButtonClick
{
WS(weakSelf)
WXYZ_AudioPlayPageMenuView *chooseMenuView = [[WXYZ_AudioPlayPageMenuView alloc] init];
chooseMenuView.menuListArray = self.dataSourceArray;
chooseMenuView.totalChapter = self.audioModel.total_chapters;
chooseMenuView.chooseMenuBlock = ^(WXYZ_MenuType menuType, NSInteger chooseIndex) {
/* 滚动指定段的指定row 到 指定位置*/
[weakSelf.mainTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:chooseIndex * 30 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES];
};
[chooseMenuView showWithMenuType:WXYZ_MenuTypeAudioSelection];
}
- (void)initDownloadManager
{
WS(weakSelf)
self.audioDownloadManager = [WXYZ_AudioDownloadManager sharedManager];
self.audioDownloadManager.downloadChapterStateChangeBlock = ^(WXYZ_DownloadChapterState state, NSInteger production_id, NSInteger chapter_id) {
dispatch_async(dispatch_get_main_queue(), ^{
switch (state) {
case WXYZ_DownloadStateChapterDownloadFinished: // 章节下载完成
{
[weakSelf setCollectionCellDownloadStateWithChapter_id:chapter_id downloadState:WXYZ_ProductionDownloadStateDownloaded];
}
break;
case WXYZ_DownloadStateChapterDownloadFail: // 下载失败
{
[weakSelf setCollectionCellDownloadStateWithChapter_id:chapter_id downloadState:WXYZ_ProductionDownloadStateFail];
}
break;
case WXYZ_DownloadStateChapterDownloadStart: // 开始下载
{
[weakSelf setCollectionCellDownloadStateWithChapter_id:chapter_id downloadState:WXYZ_ProductionDownloadStateDownloading];
}
break;
default:
break;
}
[weakSelf reloadToolBar];
});
};
self.audioDownloadManager.downloadMissionStateChangeBlock = ^(WXYZ_DownloadMissionState state, NSInteger production_id, NSArray * _Nonnull chapter_ids) {
SS(strongSelf)
switch (state) {
// 任务开始
case WXYZ_DownloadStateMissionStart:
{
[weakSelf.downloadIndicatorView stopAnimating];
[weakSelf.downloadButton setTitle:TFLocalizedString(@"立即下载") forState:UIControlStateNormal];
for (NSString *t_chapter_id in chapter_ids) {
[weakSelf setCollectionCellDownloadStateWithChapter_id:[t_chapter_id integerValue] downloadState:WXYZ_ProductionDownloadStateDownloading];
}
}
break;
// 任务失败
case WXYZ_DownloadStateMissionFail:
{
[weakSelf.downloadIndicatorView stopAnimating];
[weakSelf.downloadButton setTitle:TFLocalizedString(@"立即下载") forState:UIControlStateNormal];
for (NSString *t_chapter_id in chapter_ids) {
[weakSelf setCollectionCellDownloadStateWithChapter_id:[t_chapter_id integerValue] downloadState:WXYZ_ProductionDownloadStateNormal];
}
}
break;
case WXYZ_DownloadStateMissionShouldPay:
{
[weakSelf.downloadIndicatorView stopAnimating];
[weakSelf.downloadButton setTitle:TFLocalizedString(@"立即下载") forState:UIControlStateNormal];
if (!weakSelf.payBarShowing) {
weakSelf.payBarShowing = YES;
TFProductionChapterModel *chapterModel = [[TFProductionChapterModel alloc] init];
chapterModel.production_id = production_id;
chapterModel.chapter_ids = chapter_ids;
WXYZ_ChapterBottomPayBar *payBar = [[WXYZ_ChapterBottomPayBar alloc] initWithChapterModel:chapterModel barType:WXYZ_BottomPayBarTypeDownload productionType:TFProductionTypeAudio];
payBar.paySuccessChaptersBlock = ^(NSArray<NSString *> * _Nonnull success_chapter_ids) {
[strongSelf downloadClick];
};
payBar.payFailChaptersBlock = ^(NSArray<NSString *> * _Nonnull fail_chapter_ids) {
for (NSString *t_chapter_id in fail_chapter_ids) {
[weakSelf setCollectionCellDownloadStateWithChapter_id:[t_chapter_id integerValue] downloadState:WXYZ_ProductionDownloadStateNormal];
}
[weakSelf reloadToolBar];
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:TFLocalizedString(@"购买失败")];
};
payBar.payCancleChapterBlock = ^(NSArray<NSString *> * _Nonnull fail_chapter_ids) {
for (NSString *t_chapter_id in fail_chapter_ids) {
[weakSelf setCollectionCellDownloadStateWithChapter_id:[t_chapter_id integerValue] downloadState:WXYZ_ProductionDownloadStateNormal];
}
[weakSelf reloadToolBar];
};
SS(strongSelf)
payBar.bottomPayBarHiddenBlock = ^{
strongSelf.payBarShowing = NO;
};
[payBar showBottomPayBar];
}
}
break;
case WXYZ_DownloadStateMissionFinished:
[TFPromptManager showPromptViewWithStatus:TFPromptStatusSuccess promptTitle:TFLocalizedString(@"下载完成")];
weakSelf.headerTitleLabel.text = [NSString stringWithFormat:TFLocalizedString(@"已下载%zd章"), [[WXYZ_AudioDownloadManager sharedManager] getDownloadChapterCountWithProduction_id:weakSelf.audioModel.production_id]];
break;
default:
break;
}
weakSelf.downloadButton.userInteractionEnabled = YES;
};
}
- (void)downloadClick
{
self.downloadButton.userInteractionEnabled = NO;
NSMutableArray *chapter_ids = [NSMutableArray array];
for (NSString *t_chapter_id in self.selectSourceDictionary.allKeys) {
if ([[self.selectSourceDictionary objectForKey:t_chapter_id] integerValue] == WXYZ_ProductionDownloadStateSelected) {
[chapter_ids addObject:t_chapter_id];
}
}
[self.downloadIndicatorView startAnimating];
[self.downloadButton setTitle:@"" forState:UIControlStateNormal];
[self reloadToolBar];
[self.audioDownloadManager downloadChaptersWithProductionModel:self.audioModel production_id:self.audioModel.production_id chapter_ids:chapter_ids];
}
- (void)reloadToolBar
{
NSInteger normalIndex = 0;
NSInteger selectIndex = 0;
NSInteger downloadedIndex = 0;
for (NSString *t_key in self.selectSourceDictionary) {
switch ([[self.selectSourceDictionary objectForKey:t_key] integerValue]) {
case WXYZ_ProductionDownloadStateNormal:
normalIndex ++;
break;
case WXYZ_ProductionDownloadStateDownloaded:
downloadedIndex ++;
break;
case WXYZ_ProductionDownloadStateSelected:
selectIndex ++;
break;
default:
break;
}
}
if (selectIndex > 0) {
memoryBarView.text = [NSString stringWithFormat:TFLocalizedString(@"已选择%@条声音,占用%@/可用空间%@"), [TFUtilsHelper formatStringWithInteger:selectIndex], [TFUtilsHelper convertFileSize:self.totalMemorySize * 1024], [TFUtilsHelper getRemainingMemorySpace]];
[memoryBarView mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(memoryBarView.intrinsicContentSize.height);
}];
} else {
memoryBarView.text = [NSString stringWithFormat:@"%@%@", TFLocalizedString(@"可用空间"), [TFUtilsHelper getRemainingMemorySpace]];
[memoryBarView mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(memoryBarView.intrinsicContentSize.height);
}];
}
if (downloadedIndex == self.dataSourceArray.count) {
selectAllButton.hidden = YES;
self.downloadButton.enabled = NO;
self.downloadButton.selected = NO;
self.downloadButton.backgroundColor = [UIColor whiteColor];
[self.downloadButton setTitle:TFLocalizedString(@"已全部下载") forState:UIControlStateNormal];
[self.downloadButton setTitleColor:kGrayTextLightColor forState:UIControlStateNormal];
[self.downloadButton mas_remakeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self.view);
make.top.mas_equalTo(selectAllButton.mas_top);
make.width.mas_equalTo(SCREEN_WIDTH);
make.height.mas_equalTo(selectAllButton.mas_height);
}];
return;
}
self.downloadButton.enabled = NO;
self.downloadButton.backgroundColor = kGrayTextLightColor;
[self.downloadButton mas_updateConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(SCREEN_WIDTH / 3);
}];
selectAllButton.selected = NO;
selectAllButton.enabled = YES;
selectAllButton.hidden = NO;
selectAllButton.buttonTitle = TFLocalizedString(@"全选");
selectAllButton.buttonImageName = @"audio_download_unselect";
if (selectIndex > 0 && normalIndex == 0) { // 有选中的文件并且没有未选中的文件
self.downloadButton.enabled = YES;
self.downloadButton.backgroundColor = kMainColor;
selectAllButton.selected = YES;
selectAllButton.buttonTitle = TFLocalizedString(@"取消全选");
selectAllButton.buttonImageName = @"audio_download_select";
} else if (normalIndex > 0 && selectIndex > 0) { // 有未选中的文件
self.downloadButton.enabled = YES;
self.downloadButton.backgroundColor = kMainColor;
}
}
- (void)setCollectionCellDownloadStateWithChapter_id:(NSInteger)chapter_id downloadState:(WXYZ_ProductionDownloadState)downloadState
{
WXYZ_AudioDownloadTableViewCell *cell = (WXYZ_AudioDownloadTableViewCell *)[self.mainTableView cellForRowAtIndexPath:(NSIndexPath *)[self.cellIndexDictionary objectForKey:[TFUtilsHelper formatStringWithInteger:chapter_id]]];
cell.cellDownloadState = downloadState;
[self.selectSourceDictionary setObject:[TFUtilsHelper formatStringWithInteger:downloadState] forKey:[TFUtilsHelper formatStringWithInteger:chapter_id]];
}
- (void)netRequest
{
WS(weakSelf)
[TFNetworkTools POST:Audio_Catalog parameters:@{@"audio_id":[TFUtilsHelper formatStringWithInteger:self.production_id]} model:TFProductionModel.class success:^(BOOL isSuccess, TFProductionModel * _Nullable t_model, TFNetworkRequestModel * _Nonnull requestModel) {
if (isSuccess) {
if (t_model.chapter_list.count > 0) {
weakSelf.audioModel = t_model;
weakSelf.dataSourceArray = [NSMutableArray arrayWithArray:t_model.chapter_list];
[weakSelf resetSelectSourceDicWithDataSourceArray:t_model.chapter_list productionType:TFProductionTypeAudio];
}
} else {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:requestModel.msg];
}
[weakSelf.mainTableView reloadData];
[weakSelf reloadToolBar];
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
[weakSelf.mainTableView reloadData];
}];
}
@end
@@ -0,0 +1,19 @@
//
// WXYZ_AudioPlayPageMenuDirectoryTableViewCell.h
// WXReader
//
// Created by Andrew on 2020/3/19.
// Copyright © 2020 Andrew. All rights reserved.
//
#import "TFBasicTableViewCell.h"
NS_ASSUME_NONNULL_BEGIN
@interface WXYZ_AudioPlayPageMenuDirectoryTableViewCell : TFBasicTableViewCell
@property (nonatomic, strong) TFProductionChapterModel *chapterListModel;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,136 @@
//
// WXYZ_AudioPlayPageMenuDirectoryTableViewCell.m
// WXReader
//
// Created by Andrew on 2020/3/19.
// Copyright © 2020 Andrew. All rights reserved.
//
#import "WXYZ_AudioPlayPageMenuDirectoryTableViewCell.h"
#import "TFReadRecordManager.h"
@implementation WXYZ_AudioPlayPageMenuDirectoryTableViewCell
{
UIImageView *leftIcon;
UILabel *chapterNameLabel;
#if TF_Super_Member_Mode && TF_Recharge_Mode
UIImageView *lockIcon;
#endif
}
- (void)createSubviews
{
[super createSubviews];
leftIcon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"audio_directory_list"]];
leftIcon.userInteractionEnabled = YES;
leftIcon.hidden = YES;
[self.contentView addSubview:leftIcon];
[leftIcon mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.contentView.mas_left).with.offset(kMargin);
make.centerY.mas_equalTo(self.contentView.mas_centerY);
make.width.mas_equalTo(CGFLOAT_MIN);
make.height.mas_equalTo(kGeometricHeight(kLabelHeight / 2, 50, 32));
}];
#if TF_Super_Member_Mode && TF_Recharge_Mode
lockIcon = [[UIImageView alloc] init];
lockIcon.image = [[UIImage imageNamed:@"book_directory_lock"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
lockIcon.tintColor = kColorRGB(139, 140, 146);
lockIcon.hidden = YES;
[self.contentView addSubview:lockIcon];
[lockIcon 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.width.mas_equalTo(15);
}];
#endif
// 章节名称
chapterNameLabel = [[UILabel alloc] init];
chapterNameLabel.textColor = kBlackColor;
chapterNameLabel.font = kMainFont;
chapterNameLabel.textAlignment = NSTextAlignmentLeft;
[self.contentView addSubview:chapterNameLabel];
[chapterNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(leftIcon.mas_right).with.offset(kHalfMargin);
make.top.mas_equalTo(self.contentView.mas_top);
#if TF_Super_Member_Mode && TF_Recharge_Mode
make.right.mas_equalTo(lockIcon.mas_left).with.offset(- 5);
#else
make.right.mas_equalTo(self.contentView.mas_right).with.offset(- kMargin);
#endif
make.height.mas_equalTo(self.contentView.mas_height);
}];
}
- (void)setChapterListModel:(TFProductionChapterModel *)chapterListModel
{
_chapterListModel = chapterListModel;
chapterNameLabel.text = chapterListModel.chapter_title?:@"";
#if TF_Super_Member_Mode && TF_Recharge_Mode
if (chapterListModel.is_preview == 1) {
lockIcon.hidden = NO;
} else {
lockIcon.hidden = YES;
}
#endif
if (chapterListModel.chapter_id == [[TFReadRecordManager shareManagerWithProductionType:self.productionType] getReadingRecordChapter_idWithProduction_id:chapterListModel.production_id]) {
chapterNameLabel.textColor = kMainColor;
leftIcon.hidden = NO;
[leftIcon mas_updateConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(kLabelHeight / 2);
}];
[chapterNameLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(leftIcon.mas_right).with.offset(kHalfMargin);
make.top.mas_equalTo(self.contentView.mas_top);
#if TF_Super_Member_Mode && TF_Recharge_Mode
make.right.mas_equalTo(lockIcon.mas_left).with.offset(- 5);
#else
make.right.mas_equalTo(self.contentView.mas_right).with.offset(- kMargin);
#endif
make.height.mas_equalTo(self.contentView.mas_height);
}];
} else if ([[TFReadRecordManager shareManagerWithProductionType:self.productionType] chapterHasReadedWithProduction_id:chapterListModel.production_id chapter_id:chapterListModel.chapter_id]) {
chapterNameLabel.textColor = kGrayTextColor;
leftIcon.hidden = YES;
[leftIcon mas_updateConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(CGFLOAT_MIN);
}];
[chapterNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.mas_left).with.offset(kMargin);
make.top.mas_equalTo(self.contentView.mas_top);
#if TF_Super_Member_Mode && TF_Recharge_Mode
make.right.mas_equalTo(lockIcon.mas_left).with.offset(- 5);
#else
make.right.mas_equalTo(self.contentView.mas_right).with.offset(- kMargin);
#endif
make.height.mas_equalTo(self.contentView.mas_height);
}];
} else {
chapterNameLabel.textColor = kBlackColor;
leftIcon.hidden = YES;
[leftIcon mas_updateConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(CGFLOAT_MIN);
}];
[chapterNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.mas_left).with.offset(kMargin);
make.top.mas_equalTo(self.contentView.mas_top);
#if TF_Super_Member_Mode && TF_Recharge_Mode
make.right.mas_equalTo(lockIcon.mas_left).with.offset(- 5);
#else
make.right.mas_equalTo(self.contentView.mas_right).with.offset(- kMargin);
#endif
make.height.mas_equalTo(self.contentView.mas_height);
}];
}
}
@end
@@ -0,0 +1,21 @@
//
// WXYZ_AudioPlayPageMenuTableViewCell.h
// WXReader
//
// Created by Andrew on 2020/3/18.
// Copyright © 2020 Andrew. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface WXYZ_AudioPlayPageMenuTableViewCell : TFBasicTableViewCell
@property (nonatomic, copy) NSString *cellTitleString;
@property (nonatomic, assign) BOOL cellSelected;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,59 @@
//
// WXYZ_AudioPlayPageMenuTableViewCell.m
// WXReader
//
// Created by Andrew on 2020/3/18.
// Copyright © 2020 Andrew. All rights reserved.
//
#import "WXYZ_AudioPlayPageMenuTableViewCell.h"
@implementation WXYZ_AudioPlayPageMenuTableViewCell
{
UILabel *titleLabel;
UIImageView *chooseIndicator;
}
- (void)createSubviews
{
[super createSubviews];
chooseIndicator = [[UIImageView alloc] initWithImage:[[UIImage imageNamed:@"audio_menu_choose"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]];
chooseIndicator.userInteractionEnabled = YES;
chooseIndicator.hidden = YES;
chooseIndicator.tintColor = kMainColor;
[self.contentView addSubview:chooseIndicator];
[chooseIndicator mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(self.contentView.mas_right).with.offset(- kMargin);
make.centerY.mas_equalTo(self.contentView.mas_centerY);
make.width.height.mas_equalTo(20);
}];
titleLabel = [[UILabel alloc] init];
titleLabel.textColor = kBlackColor;
titleLabel.textAlignment = NSTextAlignmentLeft;
titleLabel.font = kMainFont;
[self.contentView addSubview:titleLabel];
[titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.contentView.mas_left).with.offset(kMargin);
make.top.mas_equalTo(self.contentView.mas_top);
make.right.mas_equalTo(chooseIndicator.mas_left).with.offset(- kHalfMargin);
make.bottom.mas_equalTo(self.contentView.mas_bottom);
}];
}
- (void)setCellTitleString:(NSString *)cellTitleString
{
_cellTitleString = cellTitleString;
titleLabel.text = cellTitleString;
}
- (void)setCellSelected:(BOOL)cellSelected
{
_cellSelected = cellSelected;
chooseIndicator.hidden = !cellSelected;
}
@end
@@ -0,0 +1,44 @@
//
// WXYZ_AudioPlayPageMenuView.h
// WXReader
//
// Created by Andrew on 2020/3/18.
// Copyright © 2020 Andrew. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
typedef NS_ENUM(NSUInteger, WXYZ_MenuType) {
WXYZ_MenuTypeAudioSpeed, // 有声语速
WXYZ_MenuTypeAudioDirectory, // 有声目录
WXYZ_MenuTypeAudioSelection, // 有声选章
WXYZ_MenuTypeAiSpeed, // ai语速
WXYZ_MenuTypeAiVoice, // ai声音
WXYZ_MenuTypeAiDirectory, // ai目录
WXYZ_MenuTypeTiming // 定时
};
@interface WXYZ_AudioPlayPageMenuView : UIView <UIGestureRecognizerDelegate, UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) NSArray *menuListArray;
/// 总章节数量
@property (nonatomic, assign) NSInteger totalChapter;
@property (nonatomic, copy) void (^chooseMenuBlock)(WXYZ_MenuType menuType, NSInteger chooseIndex);
@property (nonatomic, copy) void (^chooseDirectoryMenuBlock)(NSInteger chapter_id, NSInteger chooseIndex);
@property (nonatomic, copy) void (^timingCompleteBlock)(BOOL finish);
- (void)showWithMenuType:(WXYZ_MenuType)menuType;
- (void)close;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,564 @@
//
// WXYZ_AudioPlayPageMenuView.m
// WXReader
//
// Created by Andrew on 2020/3/18.
// Copyright © 2020 Andrew. All rights reserved.
//
#import "WXYZ_AudioPlayPageMenuView.h"
#import "WXYZ_AudioPlayPageMenuTableViewCell.h"
#import "WXYZ_AudioPlayPageMenuDirectoryTableViewCell.h"
#import "TFButton.h"
#import "WXYZ_AudioSettingHelper.h"
#import "TFReadRecordManager.h"
#define Menu_Cell_Height 44
#define Menu_Header_Height 40
#define Menu_Footer_Height (40 + PUB_TABBAR_OFFSET)
@interface WXYZ_AudioPlayPageMenuView ()
/// 是倒序
@property (nonatomic, assign) BOOL isInvert;
@end
@implementation WXYZ_AudioPlayPageMenuView
{
WXYZ_MenuType _menuType;
UITapGestureRecognizer *tap;
UIView *backView;
UITableView *mainTableView;
UIButton *closeButton;
UILabel *headerTitleLabel;
UIView *sectionHeaderView;
UILabel *sectionHeaderTitle;
}
- (instancetype)init
{
if (self = [super init]) {
[self initialize];
[self createSubviews];
}
return self;
}
- (void)initialize
{
self.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
self.backgroundColor = kBlackTransparentColor;
self.tag = 111;
[kMainWindow addSubview:self];
tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(close)];
tap.numberOfTapsRequired = 1;
tap.delegate = self;
[self addGestureRecognizer:tap];
}
- (void)createSubviews
{
backView = [[UIView alloc] init];
backView.frame = CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT / 2);
backView.backgroundColor = kWhiteColor;
[backView addRoundingCornersWithRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight];
[self addSubview:backView];
mainTableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
mainTableView.backgroundColor = [UIColor whiteColor];
mainTableView.delegate = self;
mainTableView.dataSource = self;
mainTableView.showsVerticalScrollIndicator = NO;
mainTableView.showsHorizontalScrollIndicator = NO;
mainTableView.estimatedRowHeight = 100;
mainTableView.sectionFooterHeight = 10;
mainTableView.rowHeight = UITableViewAutomaticDimension;
mainTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
if (@available(iOS 11.0, *)) {
mainTableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
} else {
// Fallback on earlier versions
}
[backView addSubview:mainTableView];
[mainTableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(backView.mas_left);
make.top.mas_equalTo(backView.mas_top);
make.width.mas_equalTo(backView.mas_width);
make.height.mas_equalTo(backView.mas_height).offset(-Menu_Footer_Height);
}];
headerTitleLabel = [[UILabel alloc] init];
headerTitleLabel.textAlignment = NSTextAlignmentCenter;
headerTitleLabel.textColor = kBlackColor;
headerTitleLabel.font = kBoldFont15;
headerTitleLabel.backgroundColor = [UIColor whiteColor];
[backView addSubview:headerTitleLabel];
[headerTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(backView.mas_left);
make.top.mas_equalTo(backView.mas_top);
make.width.mas_equalTo(backView.mas_width);
make.height.mas_equalTo(Menu_Header_Height);
}];
{
UIView *line = [[UIView alloc] init];
line.backgroundColor = kGrayLineColor;
[backView addSubview:line];
[line mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.bottom.mas_equalTo(headerTitleLabel.mas_bottom);
make.width.mas_equalTo(SCREEN_WIDTH);
make.height.mas_equalTo(kCellLineHeight);
}];
}
closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
closeButton.frame = CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, Menu_Footer_Height);
closeButton.backgroundColor = kWhiteColor;
[closeButton setTitle:TFLocalizedString(@"关闭") forState:UIControlStateNormal];
[closeButton setTitleColor:kBlackColor forState:UIControlStateNormal];
[closeButton setTitleEdgeInsets:UIEdgeInsetsMake(0, 0, PUB_TABBAR_OFFSET, 0)];
[closeButton.titleLabel setFont:kMainFont];
[closeButton addTarget:self action:@selector(close) forControlEvents:UIControlEventTouchUpInside];
[backView addSubview:closeButton];
[closeButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(backView.mas_left);
make.bottom.mas_equalTo(backView.mas_bottom);
make.width.mas_equalTo(backView.mas_width);
make.height.mas_equalTo(Menu_Footer_Height);
}];
{
UIView *line = [[UIView alloc] init];
line.backgroundColor = kGrayLineColor;
[backView addSubview:line];
[line mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.top.mas_equalTo(closeButton.mas_top);
make.width.mas_equalTo(SCREEN_WIDTH);
make.height.mas_equalTo(kCellLineHeight);
}];
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.menuListArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (_menuType == WXYZ_MenuTypeAudioDirectory || _menuType == WXYZ_MenuTypeAiDirectory) {
static NSString *cellName = @"WXYZ_AudioPlayPageMenuDirectoryTableViewCell";
WXYZ_AudioPlayPageMenuDirectoryTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName];
if (!cell) {
cell = [[WXYZ_AudioPlayPageMenuDirectoryTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
}
cell.productionType = _menuType == WXYZ_MenuTypeAiDirectory?TFProductionTypeAi:TFProductionTypeAudio;
cell.chapterListModel = [self.menuListArray objectAtIndex:indexPath.row];
cell.hiddenEndLine = indexPath.row == self.menuListArray.count - 1;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
} else {
static NSString *cellName = @"WXYZ_AudioPlayPageMenuTableViewCell";
WXYZ_AudioPlayPageMenuTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName];
if (!cell) {
cell = [[WXYZ_AudioPlayPageMenuTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
}
cell.cellTitleString = [self.menuListArray objectAtIndex:indexPath.row];
cell.hiddenEndLine = indexPath.row == self.menuListArray.count - 1;
switch (_menuType) {
case WXYZ_MenuTypeTiming:
cell.cellSelected = [[WXYZ_AudioSettingHelper sharedManager] getReadTiming] == indexPath.row;
break;
case WXYZ_MenuTypeAudioSpeed:
cell.cellSelected = [[WXYZ_AudioSettingHelper sharedManager] getReadSpeedWithProducitionType:TFProductionTypeAudio] == indexPath.row;
break;
case WXYZ_MenuTypeAiSpeed:
cell.cellSelected = [[WXYZ_AudioSettingHelper sharedManager] getReadSpeedWithProducitionType:TFProductionTypeAi] == indexPath.row;
break;
case WXYZ_MenuTypeAiVoice:
cell.cellSelected = [[WXYZ_AudioSettingHelper sharedManager] getReadVoiceWithProducitionType:TFProductionTypeAi] == indexPath.row;
break;
default:
break;
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return Menu_Cell_Height;
}
//section头间距
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
if (_menuType == WXYZ_MenuTypeAudioDirectory || _menuType == WXYZ_MenuTypeAiDirectory) {
return Menu_Header_Height + 40;
}
return Menu_Header_Height;
}
//section头视图
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
if (!sectionHeaderView) {
sectionHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, Menu_Header_Height)];
sectionHeaderView.backgroundColor = [UIColor clearColor];
if (_menuType == WXYZ_MenuTypeAudioDirectory || _menuType == WXYZ_MenuTypeAiDirectory) {
sectionHeaderView.backgroundColor = [UIColor whiteColor];
sectionHeaderTitle = [[UILabel alloc] initWithFrame:CGRectMake(kMargin, Menu_Header_Height, SCREEN_WIDTH / 2, 40)];
sectionHeaderTitle.text = [NSString stringWithFormat:TFLocalizedString(@"共%@章"), [TFUtilsHelper formatStringWithInteger:self.totalChapter]];
sectionHeaderTitle.textColor = kGrayTextColor;
sectionHeaderTitle.textAlignment = NSTextAlignmentLeft;
sectionHeaderTitle.font = kFont12;
[sectionHeaderView addSubview:sectionHeaderTitle];
CGFloat width = [TFViewHelper getDynamicWidthWithLabelFont:kFont12 labelHeight:40.0 labelText:TFLocalizedString(@"正序") maxWidth:SCREEN_WIDTH / 2.0];
width += kLabelHeight;
TFButton *sortButton = [[TFButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - kHalfMargin - width, Menu_Header_Height, width, 40) buttonTitle:TFLocalizedString(@"正序") buttonImageName:@"comic_positive_order" buttonIndicator:TFButtonIndicatorImageRightBothRight];
sortButton.buttonImageScale = 0.3;
sortButton.buttonTitleFont = kFont12;
sortButton.graphicDistance = 5;
sortButton.buttonTitleColor = kGrayTextColor;
sortButton.tag = 0;
[sortButton addTarget:self action:@selector(changeDirectorySort:) forControlEvents:UIControlEventTouchUpInside];
[sectionHeaderView addSubview:sortButton];
}
}
if (sectionHeaderTitle) {
sectionHeaderTitle.text = [NSString stringWithFormat:TFLocalizedString(@"共%@章"), [TFUtilsHelper formatStringWithInteger:self.totalChapter]];
}
return sectionHeaderView;
}
//section底部间距
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return CGFLOAT_MIN;
}
//section底部视图
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, CGFLOAT_MIN)];
view.backgroundColor = [UIColor clearColor];
return view;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
switch (_menuType) {
case WXYZ_MenuTypeTiming:
[[WXYZ_AudioSettingHelper sharedManager] setReadTimingWithIndex:indexPath.row];
break;
case WXYZ_MenuTypeAudioSpeed:
[[WXYZ_AudioSettingHelper sharedManager] setReadSpeedWithIndex:indexPath.row producitionType:TFProductionTypeAudio];
break;
case WXYZ_MenuTypeAiSpeed:
[[WXYZ_AudioSettingHelper sharedManager] setReadSpeedWithIndex:indexPath.row producitionType:TFProductionTypeAi];
break;
case WXYZ_MenuTypeAiVoice:
[[WXYZ_AudioSettingHelper sharedManager] setReadVoiceWithIndex:indexPath.row producitionType:TFProductionTypeAi];
break;
default:
break;
}
if (_menuType == WXYZ_MenuTypeAudioDirectory || _menuType == WXYZ_MenuTypeAiDirectory) {
TFProductionChapterModel *listModel = [self.menuListArray objectAtIndex:indexPath.row];
if (listModel.chapter_id > 0) {
if (self.chooseDirectoryMenuBlock) {
self.chooseDirectoryMenuBlock(listModel.chapter_id, indexPath.row);
}
}
} else {
if (self.chooseMenuBlock) {
self.chooseMenuBlock(_menuType, indexPath.row);
}
}
[tableView reloadData];
[self close];
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
if (touch.view.tag != 111) {
return NO;
} else {
return YES;
}
}
- (void)changeDirectorySort:(TFButton *)sender
{
if (sender.tag == 0) {
sender.tag = 1;
sender.buttonImageName = @"comic_reverse_order";
sender.buttonTitle = TFLocalizedString(@"倒序");
self.isInvert = YES;
} else {
sender.tag = 0;
sender.buttonImageName = @"comic_positive_order";
sender.buttonTitle = TFLocalizedString(@"正序");
self.isInvert = NO;
}
if (_menuType == WXYZ_MenuTypeAiDirectory) {
TFProductionChapterModel *t_model = self.menuListArray.firstObject;
NSDictionary *params = @{
@"book_id" : @(t_model.production_id),
@"order_by" : sender.tag ? @(2) : @(1)
};
WS(weakSelf)
[TFNetworkTools POST:Book_New_Catalog parameters:params model:TFCatalogModel.class success:^(BOOL isSuccess, TFCatalogModel * _Nullable t_model, TFNetworkRequestModel * _Nonnull requestModel) {
if (isSuccess) {
weakSelf.totalChapter = t_model.total_chapter;
NSMutableArray<TFProductionChapterModel *> *t_arr = [NSMutableArray array];
for (TFCatalogListModel *list in t_model.list) {
TFProductionChapterModel *model = [[TFProductionChapterModel alloc] init];
model.production_id = [list.book_id integerValue];
model.chapter_id = [list.chapter_id integerValue];
model.next_chapter = [list.next_chapter integerValue];
model.last_chapter = [list.previou_chapter integerValue];
model.chapter_title = list.title;
model.total_words = [list.words integerValue];
model.is_vip = list.vip;
model.update_time = list.update_time;
model.display_order = [NSString stringWithFormat:@"%zd", list.display_order];
model.can_read = list.can_read;
model.is_preview = list.preview;
[t_arr addObject:model];
}
weakSelf.menuListArray = t_arr;
[mainTableView reloadData];
[mainTableView hideRefreshHeader];
[mainTableView showRefreshFooter];
}
} failure:nil];
} else {
self.menuListArray = [[self.menuListArray reverseObjectEnumerator] allObjects];
[mainTableView reloadData];
[mainTableView hideRefreshHeader];
[mainTableView showRefreshFooter];
}
}
- (void)showWithMenuType:(WXYZ_MenuType)menuType
{
_menuType = menuType;
switch (menuType) {
case WXYZ_MenuTypeTiming:
self.menuListArray = [[WXYZ_AudioSettingHelper sharedManager] getReadTimingKeys];
headerTitleLabel.text = TFLocalizedString(@"定时");
break;
case WXYZ_MenuTypeAudioSpeed:
self.menuListArray = [[WXYZ_AudioSettingHelper sharedManager] getReadSpeedKeysWithProducitionType:TFProductionTypeAudio];
headerTitleLabel.text = TFLocalizedString(@"语速");
break;
case WXYZ_MenuTypeAiSpeed:
self.menuListArray = [[WXYZ_AudioSettingHelper sharedManager] getReadSpeedKeysWithProducitionType:TFProductionTypeAi];
headerTitleLabel.text = TFLocalizedString(@"语速");
break;
case WXYZ_MenuTypeAiVoice:
{
self.menuListArray = [[WXYZ_AudioSettingHelper sharedManager] getReadVoiceKeysWithProducitionType:TFProductionTypeAi];
headerTitleLabel.text = TFLocalizedString(@"声音");
}
break;
case WXYZ_MenuTypeAudioDirectory:
case WXYZ_MenuTypeAiDirectory:
{
headerTitleLabel.text = TFLocalizedString(@"章节目录");
WS(weakSelf)
// [mainTableView addFooterRefreshWithRefreshingBlock:^{
// if (weakSelf.isInvert) {
// [weakSelf requestCatalogWithScrollType:@"2"];
// } else {
// [weakSelf requestCatalogWithScrollType:@"1"];
// }
// }];
mainTableView.mj_footer = [MJRefreshFooter footerWithRefreshingBlock:^{
if (weakSelf.isInvert) {
[weakSelf requestCatalogWithScrollType:@"2"];
} else {
[weakSelf requestCatalogWithScrollType:@"1"];
}
}];
}
break;
case WXYZ_MenuTypeAudioSelection:
{
if (self.menuListArray.count > 0) {
NSMutableArray *t_array = [NSMutableArray array];
for (int i = 0; i < (self.menuListArray.count / 30) + (self.menuListArray.count % 30 == 0?0:1); i ++) {
[t_array addObject:[NSString stringWithFormat:@"%@-%@", [TFUtilsHelper formatStringWithInteger:(i * 30 + 1)], [TFUtilsHelper formatStringWithInteger:((i + 1) * 30) <= self.menuListArray.count?((i + 1) * 30):self.menuListArray.count]]];
}
self.menuListArray = [t_array copy];
}
headerTitleLabel.text = TFLocalizedString(@"选章");
}
break;
default:
break;
}
// 计算tableview高度
CGFloat tableViewHeight = self.menuListArray.count * Menu_Cell_Height + Menu_Header_Height + Menu_Footer_Height + ((_menuType == WXYZ_MenuTypeAudioDirectory || _menuType == WXYZ_MenuTypeAiDirectory)?80:0);
if (tableViewHeight > SCREEN_HEIGHT / 2) {
tableViewHeight = SCREEN_HEIGHT / 2;
}
[UIView animateWithDuration:kAnimatedDuration animations:^{
backView.frame = CGRectMake(0, SCREEN_HEIGHT - tableViewHeight, SCREEN_WIDTH, tableViewHeight);
}];
[mainTableView reloadData];
[mainTableView layoutIfNeeded];
if (menuType == WXYZ_MenuTypeAiDirectory) {
// 移动到当前播放位置
for (int i = 0; i < self.menuListArray.count; i ++) {
TFProductionChapterModel *chapter_model = [self.menuListArray objectAtIndex:i];
if (chapter_model.chapter_id == [[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeAi] getReadingRecordChapter_idWithProduction_id:chapter_model.production_id]) {
[mainTableView scrollToRow:i inSection:0 atScrollPosition:UITableViewScrollPositionTop animated:YES];
}
}
} else if (menuType == WXYZ_MenuTypeAudioDirectory) {
// 移动到当前播放位置
for (int i = 0; i < self.menuListArray.count; i ++) {
TFProductionChapterModel *chapter_model = [self.menuListArray objectAtIndex:i];
if (chapter_model.chapter_id == [[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeAudio] getReadingRecordChapter_idWithProduction_id:chapter_model.production_id]) {
[mainTableView scrollToRow:i inSection:0 atScrollPosition:UITableViewScrollPositionTop animated:YES];
}
}
}
}
- (void)close
{
[UIView animateWithDuration:kAnimatedDuration animations:^{
backView.frame = CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, backView.height);
} completion:^(BOOL finished) {
for (UIView *v in [self subviews]) {
[v removeFromSuperview];
}
[self removeFromSuperview];
}];
}
// scrollType 1:向下加载;2:向上加载
- (void)requestCatalogWithScrollType:(NSString *)scrollType {
BOOL loadDown = [scrollType isEqualToString:@"1"];
NSString *chapterID = @"";
TFProductionChapterModel *t_model = nil;
if (loadDown) {
t_model = self.menuListArray.lastObject;
chapterID = [NSString stringWithFormat:@"%zd", t_model.next_chapter];
} else {
t_model = self.menuListArray.lastObject;
chapterID = [NSString stringWithFormat:@"%zd", t_model.last_chapter];
}
if ([chapterID isEqualToString:@"0"]) {
[mainTableView endRefreshing];
if (loadDown) {
[mainTableView hideRefreshFooter];
} else {
[mainTableView hideRefreshHeader];
}
return;
}
NSDictionary *params = @{
@"book_id" : @(t_model.production_id),
@"chapter_id" : chapterID,
@"scroll_type" : scrollType,
};
WS(weakSelf)
[TFNetworkTools POST:Book_New_Catalog parameters:params model:TFCatalogModel.class success:^(BOOL isSuccess, TFCatalogModel * _Nullable t_model, TFNetworkRequestModel * _Nonnull requestModel) {
[mainTableView endRefreshing];
if (isSuccess) {
weakSelf.totalChapter = t_model.total_chapter;
NSMutableArray<TFProductionChapterModel *> *t_arr = [NSMutableArray array];
for (TFCatalogListModel *list in t_model.list) {
TFProductionChapterModel *model = [[TFProductionChapterModel alloc] init];
model.production_id = [list.book_id integerValue];
model.chapter_id = [list.chapter_id integerValue];
model.next_chapter = [list.next_chapter integerValue];
model.last_chapter = [list.previou_chapter integerValue];
model.chapter_title = list.title;
model.total_words = [list.words integerValue];
model.is_vip = list.vip;
model.update_time = list.update_time;
model.display_order = [NSString stringWithFormat:@"%zd", list.display_order];
model.can_read = list.can_read;
model.is_preview = list.preview;
[t_arr addObject:model];
}
if ([scrollType isEqualToString:@"2"]) {
t_arr = [[[t_arr reverseObjectEnumerator] allObjects] mutableCopy];
}
weakSelf.menuListArray = [weakSelf.menuListArray arrayByAddingObjectsFromArray:t_arr];
[mainTableView reloadData];
[mainTableView endRefreshing];
if ([scrollType isEqualToString:@"1"]) {
if (t_arr.lastObject.next_chapter == 0) {
[mainTableView hideRefreshFooter];
}
if (t_arr.firstObject.last_chapter == 0) {
[mainTableView hideRefreshHeader];
}
} else {
if (t_arr.lastObject.last_chapter == 0) {
[mainTableView hideRefreshFooter];
}
if (t_arr.firstObject.next_chapter == 0) {
[mainTableView hideRefreshHeader];
}
}
} else {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:requestModel.msg];
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
[TFPromptManager showPromptWithError:error defaultText:nil];
[mainTableView endRefreshing];
}];
}
@end