小说绘上架版本
This commit is contained in:
+21
@@ -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
|
||||
+469
@@ -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
|
||||
+18
@@ -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
|
||||
+168
@@ -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
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
//
|
||||
// TFHistoricalRecordCommCell.h
|
||||
// TFReader
|
||||
//
|
||||
// Created by 谢腾飞 on 2020/12/21.
|
||||
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "TFBasicTableViewCell.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
typedef void(^ContinueReadBlock)(NSInteger book_id);
|
||||
@interface TFHistoricalRecordCommCell : TFBasicTableViewCell
|
||||
|
||||
@property (nonatomic ,strong) TFProductionModel *productionModel;
|
||||
@property (nonatomic ,copy) ContinueReadBlock continueReadBlock;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
+184
@@ -0,0 +1,184 @@
|
||||
//
|
||||
// TFHistoricalRecordCommCell.m
|
||||
// TFReader
|
||||
//
|
||||
// Created by 谢腾飞 on 2020/12/21.
|
||||
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TFHistoricalRecordCommCell.h"
|
||||
|
||||
@interface TFHistoricalRecordCommCell ()
|
||||
|
||||
@property (nonatomic ,strong) UIView *advertView;
|
||||
@property (nonatomic ,strong) TFProductionCoverView *coverView;
|
||||
@property (nonatomic ,strong) UIButton *continueBtn;
|
||||
@property (nonatomic ,strong) UILabel *titleLabel;
|
||||
@property (nonatomic ,strong) UILabel *recordLabel;
|
||||
@property (nonatomic ,strong) UILabel *timeLabel;
|
||||
@property (nonatomic ,strong) UIView *posterView;
|
||||
|
||||
@end
|
||||
|
||||
@implementation TFHistoricalRecordCommCell
|
||||
|
||||
- (void)createSubviews
|
||||
{
|
||||
[super createSubviews];
|
||||
|
||||
// 图片
|
||||
self.coverView = [[TFProductionCoverView alloc] initWithProductionType:TFProductionTypeNovel coverDirection:TFProductionCoverDirectionVertical];
|
||||
self.coverView.userInteractionEnabled = YES;
|
||||
self.coverView.hidden = YES;
|
||||
[self.contentView addSubview:self.coverView];
|
||||
|
||||
[self.coverView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(self.contentView.mas_left).with.offset(kHalfMargin);
|
||||
make.top.mas_equalTo(self.contentView.mas_top).with.offset(kHalfMargin);
|
||||
make.width.mas_equalTo(BOOK_WIDTH_SMALL - kMargin);
|
||||
make.height.mas_equalTo(kGeometricHeight(BOOK_WIDTH_SMALL - kMargin, 3, 4));
|
||||
make.bottom.mas_equalTo(self.contentView.mas_bottom).with.offset(- kHalfMargin).priorityLow();
|
||||
}];
|
||||
|
||||
self.continueBtn = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
[self.continueBtn setHidden:YES];
|
||||
[self.continueBtn.layer setCornerRadius:12];
|
||||
[self.continueBtn setBackgroundColor:kMainColor];
|
||||
[self.continueBtn setTitle:TFLocalizedString(@"历史记录继续阅读") forState:UIControlStateNormal];
|
||||
[self.continueBtn setTitleColor:kWhiteColor forState:UIControlStateNormal];
|
||||
[self.continueBtn.titleLabel setFont:kFont11];
|
||||
[self.continueBtn addTarget:self action:@selector(continueReadClick) forControlEvents:UIControlEventTouchUpInside];
|
||||
[self.contentView addSubview:self.continueBtn];
|
||||
|
||||
[self.continueBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.right.mas_equalTo(self.contentView.mas_right).with.offset(- kHalfMargin);
|
||||
make.centerY.mas_equalTo(self.coverView.mas_centerY);
|
||||
make.width.mas_equalTo(70);
|
||||
make.height.mas_equalTo(24);
|
||||
}];
|
||||
|
||||
// 书名
|
||||
self.titleLabel = [[UILabel alloc] init];
|
||||
self.titleLabel.numberOfLines = 1;
|
||||
self.titleLabel.hidden = YES;
|
||||
self.titleLabel.backgroundColor = kWhiteColor;
|
||||
self.titleLabel.font = kMainFont;
|
||||
self.titleLabel.textAlignment = NSTextAlignmentLeft;
|
||||
[self.contentView addSubview:self.titleLabel];
|
||||
|
||||
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(self.coverView.mas_right).with.offset(kHalfMargin);
|
||||
make.right.mas_equalTo(self.continueBtn.mas_left).with.offset(- kHalfMargin);
|
||||
make.top.mas_equalTo(self.coverView.mas_top).mas_offset(10);
|
||||
}];
|
||||
|
||||
// 阅读记录
|
||||
self.recordLabel = [[UILabel alloc] init];
|
||||
self.recordLabel.hidden = YES;
|
||||
self.recordLabel.textColor = kGrayTextColor;
|
||||
self.recordLabel.font = kFont11;
|
||||
self.recordLabel.textAlignment = NSTextAlignmentLeft;
|
||||
[self.contentView addSubview:self.recordLabel];
|
||||
|
||||
[self.recordLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(self.titleLabel.mas_left);
|
||||
make.centerY.mas_equalTo(self.coverView.centerY).mas_offset(10);
|
||||
make.width.mas_equalTo(self.titleLabel.mas_width);
|
||||
make.height.mas_equalTo(20);
|
||||
}];
|
||||
|
||||
// 更新记录
|
||||
self.timeLabel = [[UILabel alloc] init];
|
||||
self.timeLabel.hidden = YES;
|
||||
self.timeLabel.textColor = kGrayTextColor;
|
||||
self.timeLabel.font = kFont10;
|
||||
self.timeLabel.textAlignment = NSTextAlignmentLeft;
|
||||
[self.contentView addSubview:self.timeLabel];
|
||||
|
||||
[self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(self.titleLabel.mas_left);
|
||||
make.top.mas_equalTo(self.recordLabel.mas_bottom);
|
||||
make.width.mas_equalTo(self.titleLabel.mas_width);
|
||||
make.height.mas_equalTo(self.recordLabel.mas_height);
|
||||
}];
|
||||
|
||||
|
||||
self.posterView = [[UIView alloc] init];
|
||||
self.posterView.backgroundColor = [UIColor whiteColor];
|
||||
self.posterView.hidden = YES;
|
||||
[self.contentView addSubview:self.posterView];
|
||||
|
||||
[self.posterView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.edges.mas_equalTo(self.contentView);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)setAdvertView:(UIView *)advertView
|
||||
{
|
||||
_advertView = advertView;
|
||||
|
||||
[self.posterView addSubview:advertView];
|
||||
}
|
||||
|
||||
- (void)setProductionModel:(TFProductionModel *)productionModel
|
||||
{
|
||||
_productionModel = productionModel;
|
||||
|
||||
if (productionModel.ad_type != 0) {
|
||||
self.coverView.hidden = YES;
|
||||
self.continueBtn.hidden = YES;
|
||||
self.titleLabel.hidden = YES;
|
||||
self.recordLabel.hidden = YES;
|
||||
self.timeLabel.hidden = YES;
|
||||
self.posterView.hidden = NO;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
self.coverView.hidden = NO;
|
||||
self.continueBtn.hidden = NO;
|
||||
self.titleLabel.hidden = NO;
|
||||
self.recordLabel.hidden = NO;
|
||||
self.timeLabel.hidden = NO;
|
||||
self.posterView.hidden = YES;
|
||||
|
||||
self.titleLabel.text = productionModel.name ? : @"";
|
||||
|
||||
if (productionModel.vertical_cover.length > 0) {
|
||||
self.coverView.coverImageUrl = productionModel.vertical_cover;
|
||||
} else if (productionModel.horizontal_cover.length > 0) {
|
||||
self.coverView.coverImageUrl = productionModel.horizontal_cover;
|
||||
} else {
|
||||
self.coverView.coverImageUrl = productionModel.cover;
|
||||
}
|
||||
|
||||
if (self.productionType == TFProductionTypeAudio) {
|
||||
self.recordLabel.text = [NSString stringWithFormat:@"%@%@", TFLocalizedString(@"上次收听到:"), productionModel.record_title ?: @""];
|
||||
} else {
|
||||
self.recordLabel.text = [NSString stringWithFormat:@"%@%@", TFLocalizedString(@"上次阅读到:"), productionModel.record_title ?: @""];
|
||||
}
|
||||
|
||||
self.timeLabel.text = [NSString stringWithFormat:TFLocalizedString(@"%@ 更新至第%@章"), productionModel.last_chapter_time ? : @"", [TFUtilsHelper formatStringWithInteger:productionModel.total_chapters] ?: @""];
|
||||
}
|
||||
|
||||
- (void)continueReadClick
|
||||
{
|
||||
if (self.continueReadBlock) {
|
||||
self.continueReadBlock(_productionModel.production_id);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setProductionType:(TFProductionType)productionType
|
||||
{
|
||||
[super setProductionType:productionType];
|
||||
|
||||
self.coverView.productionType = productionType;
|
||||
|
||||
if (productionType == TFProductionTypeAudio) {
|
||||
[self.continueBtn setTitle:TFLocalizedString(@"历史记录继续收听") forState:UIControlStateNormal];
|
||||
} else {
|
||||
[self.continueBtn setTitle:TFLocalizedString(@"历史记录继续阅读") forState:UIControlStateNormal];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user