小说绘上架版本

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,21 @@
//
// TFHistoricalRecordCommController.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/21.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFBasicViewController.h"
NS_ASSUME_NONNULL_BEGIN
@interface TFHistoricalRecordCommController : TFBasicViewController
// 一键清空历史记录
- (void)stepClear;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,469 @@
//
// TFHistoricalRecordCommController.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/21.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFHistoricalRecordCommController.h"
#if TF_Enable_Book
#import "TFReadNovelViewController.h"
#endif
#if TF_Enable_Comic
#import "TFComicBrowseViewController.h"
#endif
#if TF_Enable_Audio
#import "TFAudioPlayViewController.h"
#import "WXYZ_Player.h"
#endif
#import "TFHistoricalRecordCommCell.h"
#import "TFPublicAdvertisementViewCell.h"
#import "TFReadRecordManager.h"
#import "TFCollectionManager.h"
@interface TFHistoricalRecordCommController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic ,assign) BOOL needRefresh;
@end
@implementation TFHistoricalRecordCommController
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self setStatusBarDefaultStyle];
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self initialize];
[self createSubviews];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
NSString *url = @"";
switch (self.productionType) {
case TFProductionTypeNovel:
url = Book_Readlog_Delete;
break;
case TFProductionTypeComic:
url = Comic_Readlog_Delete;
break;
case TFProductionTypeAudio:
url = Audio_Readlog_Delete;
break;
default:
break;
}
WS(weakSelf)
for (NSString *log_id in [self log_idArr]) {
[TFNetworkTools POST:url parameters:@{@"log_id":log_id} model:nil success:^(BOOL isSuccess, id _Nullable t_model, TFNetworkRequestModel *requestModel) {
if (!isSuccess) {
// 删除失败,保存删除的log_id下次删除
[weakSelf addLog_id:log_id];
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
[weakSelf addLog_id:log_id];
}];
}
}
- (void)initialize
{
self.needRefresh = YES;
[self hiddenNavigationBar:YES];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(netRequest) name:Notification_Login_Success object:nil];
}
- (void)createSubviews
{
self.mainTableView.delegate = self;
self.mainTableView.dataSource = self;
self.mainTableView.contentInset = UIEdgeInsetsMake(0, 0, PUB_TABBAR_OFFSET, 0);
[self.view addSubview:self.mainTableView];
[self.mainTableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.top.mas_equalTo(self.view.mas_top);
make.height.mas_equalTo(SCREEN_HEIGHT - PUB_NAVBAR_HEIGHT - self.pageViewHeight);
make.width.mas_equalTo(self.view.mas_width);
}];
[self createEmptyView];
WS(weakSelf)
self.mainTableView.mj_header = [TFRefreshHeader headerWithRefreshingBlock:^{
weakSelf.currentPageNumber = 1;
[weakSelf netRequest];
}];
[self.mainTableView.mj_header beginRefreshing];
self.mainTableView.mj_footer = [TFRefreshFooter footerWithRefreshingBlock:^{
weakSelf.currentPageNumber ++;
[weakSelf netRequest];
}];
}
- (void)createEmptyView
{
WS(weakSelf)
if (!TFUserInfoManager.isLogin) {
[self setEmptyOnView:self.mainTableView title:TFLocalizedString(@"登录后可同步历史记录") buttonTitle:TFLocalizedString(@"立即登录") tapBlock:^{
[TFLoginOptionsViewController presentLoginView:^(TFUserInfoManager * _Nonnull userDataModel) {
weakSelf.emptyView = nil;
[weakSelf createEmptyView];
}];
}];
} else {
[self setEmptyOnView:self.mainTableView title:TFLocalizedString(@"暂无历史记录") buttonTitle:nil tapBlock:^{
}];
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.dataSourceArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
TFProductionModel *productionModel = [self.dataSourceArray objectOrNilAtIndex:indexPath.row];
if (productionModel.ad_type == 0) {
WS(weakSelf)
TFHistoricalRecordCommCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TFHistoricalRecordCommCell"];
if (!cell) {
cell = [[TFHistoricalRecordCommCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"TFHistoricalRecordCommCell"];
}
cell.productionType = self.productionType;
cell.productionModel = productionModel;
cell.hiddenEndLine = self.dataSourceArray.count - 1 == indexPath.row;
cell.continueReadBlock = ^(NSInteger book_id) {
switch (self.productionType) {
#if TF_Enable_Book
case TFProductionTypeNovel: {
TFReadNovelViewController *vc = [[TFReadNovelViewController alloc] init];
[[TFCollectionManager shareManagerWithProductionType:TFProductionTypeNovel] moveCollectionToTopWithProductionModel:productionModel];
vc.book_id = book_id;
[weakSelf.navigationController pushViewController:vc animated:NO];
}
break;
#endif
#if TF_Enable_Comic
case TFProductionTypeComic: {
TFComicBrowseViewController *vc = [[TFComicBrowseViewController alloc] init];
[[TFCollectionManager shareManagerWithProductionType:TFProductionTypeComic] moveCollectionToTopWithProductionModel:productionModel];
vc.comicProductionModel = productionModel;
vc.chapter_id = [[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeComic] getReadingRecordChapter_idWithProduction_id:productionModel.production_id];
[self.navigationController pushViewController:vc animated:YES];
}
break;
#endif
#if TF_Enable_Audio
case TFProductionTypeAudio: {
if ([WXYZ_Player sharedPlayer].state != TFBasicVoicePlayerStatePlaying) {
[[WXYZ_Player sharedPlayer] play];
}
TFAudioPlayViewController *vc = [[TFAudioPlayViewController alloc] init];
[[TFCollectionManager shareManagerWithProductionType:TFProductionTypeAudio] moveCollectionToTopWithProductionModel:productionModel];
[vc loadDataWithAudio_id:productionModel.production_id chapter_id:0];
TFNavigationController *nav = [[TFNavigationController alloc] initWithRootViewController:vc];
[[TFViewHelper getWindowRootController] presentViewController:nav animated:YES completion:nil];
}
break;
#endif
default:
break;
}
};
cell.hiddenEndLine = (self.dataSourceArray.count - 1 == indexPath.row);
if (indexPath.row + 1 < self.dataSourceArray.count) {
TFProductionModel *t_model = [self.dataSourceArray objectOrNilAtIndex:indexPath.row + 1];
cell.hiddenEndLine = t_model.advert_id != 0;
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
} else {
TFPublicAdvertisementViewCell *cell = [self.advertDict objectForKey:[TFUtilsHelper formatStringWithInteger:indexPath.row]];
if (!cell) {
static NSString *cellName = @"TFPublicAdvertisementViewCell";
cell = [[TFPublicAdvertisementViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
[cell setAdModel:productionModel refresh:self.needRefresh];
cell.mainTableView = tableView;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
[self.advertDict setObject:cell forKey:[TFUtilsHelper formatStringWithInteger:indexPath.row]];
}
return cell;
}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
TFProductionModel *t_model = [self.dataSourceArray objectOrNilAtIndex:indexPath.row];
switch (self.productionType) {
#if TF_Enable_Book
case TFProductionTypeNovel: {
TFNovelDetailViewController *vc = [[TFNovelDetailViewController alloc] init];
vc.book_id = t_model.production_id;
[self.navigationController pushViewController:vc animated:YES];
}
break;
#endif
#if TF_Enable_Comic
case TFProductionTypeComic: {
TFComicDetailViewController *vc = [[TFComicDetailViewController alloc] init];
vc.comic_id = t_model.production_id;
[self.navigationController pushViewController:vc animated:YES];
}
break;
#endif
#if TF_Enable_Audio
case TFProductionTypeAudio: {
TFAudioDetailViewController *vc = [[TFAudioDetailViewController alloc] init];
vc.audio_id = t_model.production_id;
[self.navigationController pushViewController:vc animated:YES];
}
break;
#endif
default:
break;
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return CGFLOAT_MIN;
}
- (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;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return CGFLOAT_MIN;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, PUB_TABBAR_OFFSET == 0 ? 10 : PUB_TABBAR_OFFSET)];
view.backgroundColor = [UIColor clearColor];
return view;
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
TFProductionModel *productionModel = [self.dataSourceArray objectOrNilAtIndex:indexPath.row];
if (productionModel.ad_type > 0) {
return NO;
}
return YES;
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewCellEditingStyleDelete;
}
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
{
return TFLocalizedString(@"删除");
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
[self deleteReadlogWithIndexPath:indexPath];
}
- (void)netRequest
{
if ([TFNetworkManager networkingStatus] == NO) {
[self.mainTableView xtfei_showEmptyView];
return;
}
NSString *url = @"";
switch (self.productionType) {
case TFProductionTypeNovel:
url = Book_Read_Log_List;
break;
case TFProductionTypeComic:
url = Comic_Read_Log_List;
break;
case TFProductionTypeAudio:
url = Audio_Read_Log_List;
break;
default:
break;
}
WS(weakSelf)
NSMutableDictionary *params = [NSMutableDictionary dictionary];
params[@"page_num"] = [TFUtilsHelper formatStringWithInteger:self.currentPageNumber];
[TFNetworkTools POST:url parameters:params model:TFProductionListModel.class success:^(BOOL isSuccess, TFProductionListModel *_Nullable t_model, TFNetworkRequestModel *requestModel) {
[weakSelf.mainTableView endRefreshing];
if (isSuccess) {
if (weakSelf.currentPageNumber == 1) {
[weakSelf.mainTableView showRefreshFooter];
weakSelf.dataSourceArray = [NSMutableArray arrayWithArray:t_model.list];
} else {
[weakSelf.dataSourceArray addObjectsFromArray:t_model.list];
}
if (t_model.total_page <= t_model.current_page) {
[weakSelf.mainTableView hideRefreshFooter];
}
}
weakSelf.needRefresh = YES;
[weakSelf.mainTableView reloadData];
dispatch_async(dispatch_get_main_queue(), ^{
weakSelf.needRefresh = NO;
});
[weakSelf.mainTableView xtfei_endLoading];
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
[weakSelf.mainTableView endRefreshing];
[weakSelf.mainTableView xtfei_endLoading];
}];
}
- (void)deleteReadlogWithIndexPath:(NSIndexPath *)indexPath
{
// 获取被删除的cell
NSString *log_id;
NSMutableArray<NSIndexPath *> *pathArr = [NSMutableArray array];
if (indexPath) {
[pathArr addObject:indexPath];
TFProductionModel *productionModel = [self.dataSourceArray objectOrNilAtIndex:indexPath.row];
log_id = [TFUtilsHelper formatStringWithInteger:productionModel.log_id];
[self.dataSourceArray removeObjectAtIndex:indexPath.row];
} else {
for (NSInteger i = 0; i < self.dataSourceArray.count; i++) {
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:0];
[pathArr addObject:indexPath];
}
[self.dataSourceArray removeAllObjects];
log_id = @"all";
}
// 删除并更新页面
if (@available(iOS 11.0, *)) {
[self.mainTableView performBatchUpdates:^{
[self.mainTableView deleteRowsAtIndexPaths:pathArr withRowAnimation:UITableViewRowAnimationLeft];
} completion:^(BOOL finished) {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusSuccess promptTitle:finished ? TFLocalizedString(@"清除成功") : TFLocalizedString(@"删除失败")];
[self.mainTableView xtfei_endLoading];
}];
} else {
[CATransaction begin];
[CATransaction setCompletionBlock:^{
[TFPromptManager showPromptViewWithStatus:TFPromptStatusSuccess promptTitle:TFLocalizedString(@"清除成功")];
[self.mainTableView xtfei_endLoading];
}];
[self.mainTableView beginUpdates];
[self.mainTableView deleteRowsAtIndexPaths:pathArr withRowAnimation:UITableViewRowAnimationLeft];
[self.mainTableView endUpdates];
[CATransaction commit];
}
NSString *url = @"";
switch (self.productionType) {
case TFProductionTypeNovel:
url = Book_Readlog_Delete;
break;
case TFProductionTypeComic:
url = Comic_Readlog_Delete;
break;
case TFProductionTypeAudio:
url = Audio_Readlog_Delete;
break;
default:
break;
}
WS(weakSelf)
[TFNetworkTools POST:url parameters:@{@"log_id":log_id} model:nil success:^(BOOL isSuccess, id _Nullable t_model, TFNetworkRequestModel *requestModel) {
if (!isSuccess) {
// 删除失败,保存删除的log_id下次删除
[weakSelf addLog_id:log_id];
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
[weakSelf addLog_id:log_id];
}];
}
- (void)stepClear
{
if (self.dataSourceArray.count == 0) return;
TFAlertView *alert = [[TFAlertView alloc] init];
alert.alertDetailContent = TFLocalizedString(@"是否清除历史记录");
alert.confirmButtonClickBlock = ^{
[self deleteReadlogWithIndexPath:nil];
};
[alert showAlertView];
}
- (void)addLog_id:(NSString *)log_id
{
NSString *filePath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject;
NSString *fullPath = [filePath stringByAppendingPathComponent:@"listory.plist"];
if (![[NSFileManager defaultManager] fileExistsAtPath:fullPath]) {
[[NSFileManager defaultManager] createFileAtPath:fullPath contents:nil attributes:nil];
}
NSArray<NSString *> *arr = [NSArray arrayWithContentsOfFile:fullPath];
if (!arr) arr = [NSArray array];
NSMutableSet<NSString *> *logSet = [NSMutableSet setWithArray:arr];
if ([log_id isEqualToString:@"all"]) {
for (TFProductionModel *t_model in self.dataSourceArray) {
[logSet addObject:[NSString stringWithFormat:@"%zd", t_model.log_id]];
}
} else {
[logSet addObject:log_id];
}
arr = logSet.allObjects;
[arr writeToFile:fullPath atomically:YES];
}
- (NSArray<NSString *> *)log_idArr
{
NSString *filePath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject;
NSString *fullPath = [filePath stringByAppendingPathComponent:@"listory.plist"];
return [NSArray arrayWithContentsOfFile:fullPath];
}
@end
@@ -0,0 +1,18 @@
//
// TFHistoricalRecordController.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/21.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFBasicViewController.h"
NS_ASSUME_NONNULL_BEGIN
@interface TFHistoricalRecordController : TFBasicViewController
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,168 @@
//
// TFHistoricalRecordController.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/21.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFHistoricalRecordController.h"
#import "TFHistoricalRecordCommController.h"
@interface TFHistoricalRecordController ()<SGPageTitleViewDelegate, SGPageContentCollectionViewDelegate>
@property (nonatomic ,strong) SGPageTitleView *pageTitleView;
@property (nonatomic ,strong) SGPageContentCollectionView *pageContentCollectionView;
@property (nonatomic ,weak) TFHistoricalRecordCommController *bookVC;
@property (nonatomic ,weak) TFHistoricalRecordCommController *comicVC;
@property (nonatomic ,weak) TFHistoricalRecordCommController *audioVC;
@end
@implementation TFHistoricalRecordController
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self setStatusBarDefaultStyle];
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Hidden_Tabbar object:@"1"];
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self initialize];
[self createSubViews];
}
- (void)initialize
{
[self setNavigationBarTitle:TFLocalizedString(@"历史记录")];
[self hiddenSeparator];
UIButton *rightButton;
[self setNavigationBarRightButton:({
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
rightButton = button;
[button setTitle:TFLocalizedString(@"清空") forState:UIControlStateNormal];
[button setTitleColor:kGrayTextColor forState:UIControlStateNormal];
button.titleLabel.font = kFont14;
button.backgroundColor = [UIColor clearColor];
[button addTarget:self action:@selector(stepClear) forControlEvents:UIControlEventTouchUpInside];
button;
})];
[rightButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.view).offset(-kMargin);
make.centerY.equalTo(self.navigationBar.navTitleLabel);
}];
}
- (void)createSubViews
{
#if TF_Enable_Book
TFHistoricalRecordCommController *bookVC = [[TFHistoricalRecordCommController alloc] init];
self.bookVC = bookVC;
bookVC.productionType = TFProductionTypeNovel;
[self addChildViewController:bookVC];
#endif
#if TF_Enable_Comic
TFHistoricalRecordCommController *comicVC = [[TFHistoricalRecordCommController alloc] init];
self.comicVC = comicVC;
comicVC.productionType = TFProductionTypeComic;
[self addChildViewController:comicVC];
#endif
#if TF_Enable_Audio
TFHistoricalRecordCommController *audioVC = [[TFHistoricalRecordCommController alloc] init];
self.audioVC = audioVC;
audioVC.productionType = TFProductionTypeAudio;
[self addChildViewController:audioVC];
#endif
NSMutableArray *titleArr = [NSMutableArray array];
NSMutableArray *childArr = [NSMutableArray array];
for (NSNumber *siteNumber in [TFUtilsHelper getSiteState]) {
#if TF_Enable_Book
if ([siteNumber integerValue] == 1) {
[titleArr addObject:TFLocalizedString(@"小说")];
[childArr addObject:bookVC];
}
#endif
#if TF_Enable_Comic
if ([siteNumber integerValue] == 2) {
[titleArr addObject:TFLocalizedString(@"漫画")];
[childArr addObject:comicVC];
}
#endif
#if TF_Enable_Audio
if ([siteNumber integerValue] == 3) {
[titleArr addObject:TFLocalizedString(@"听书")];
[childArr addObject:audioVC];
}
#endif
}
if ([TFUtilsHelper getSiteState].count <= 1) {
[titleArr removeAllObjects];
[titleArr addObject:TFLocalizedString(@"历史记录")];
}
self.pageContentCollectionView = [[SGPageContentCollectionView alloc] initWithFrame:CGRectMake(0, PUB_NAVBAR_HEIGHT + self.pageViewHeight, SCREEN_WIDTH, SCREEN_HEIGHT - PUB_NAVBAR_HEIGHT - self.pageViewHeight) parentVC:self childVCs:childArr];
self.pageContentCollectionView.delegatePageContentCollectionView = self;
[self.view addSubview:self.pageContentCollectionView];
self.pageTitleView = [SGPageTitleView pageTitleViewWithFrame:CGRectMake(0, PUB_NAVBAR_HEIGHT, SCREEN_WIDTH, self.pageViewHeight) delegate:self titleNames:titleArr configure:self.pageConfigure];
self.pageTitleView.backgroundColor = kWhiteColor;
[self.view addSubview:self.pageTitleView];
}
- (void)pageTitleView:(SGPageTitleView *)pageTitleView selectedIndex:(NSInteger)selectedIndex
{
[self.pageContentCollectionView setPageContentCollectionViewCurrentIndex:selectedIndex];
}
- (void)pageContentCollectionView:(SGPageContentCollectionView *)pageContentCollectionView index:(NSInteger)index
{
TFBasicViewController *vc = [pageContentCollectionView.childViewControllers objectAtIndex:index];
[vc cancleTableViewCellEditingState];
}
- (void)pageContentCollectionView:(SGPageContentCollectionView *)pageContentCollectionView progress:(CGFloat)progress originalIndex:(NSInteger)originalIndex targetIndex:(NSInteger)targetIndex
{
[self.pageTitleView setPageTitleViewWithProgress:progress originalIndex:originalIndex targetIndex:targetIndex];
}
// 一键清空历史记录
- (void)stepClear
{
NSInteger index = self.pageTitleView.signBtnIndex;
switch (index) {
case 0: {
[self.bookVC stepClear];
}
break;
case 1: {
[self.comicVC stepClear];
}
break;
case 2: {
[self.audioVC stepClear];
}
break;
default:
break;
}
}
@end