小说绘上架版本

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,22 @@
//
// TFComicBrowseViewController.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/15.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFBasicViewController.h"
NS_ASSUME_NONNULL_BEGIN
@interface TFComicBrowseViewController : TFBasicViewController
@property (nonatomic ,strong) TFProductionModel *comicProductionModel;
@property (nonatomic ,assign) NSInteger chapter_id;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,808 @@
//
// TFComicBrowseViewController.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/15.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFComicBrowseViewController.h"
#import "TFCommentsViewController.h"
#import "TFComicCatalogueViewController.h"
#import "TFComicDownloadViewController.h"
#import "TFComicBrowseViewCell.h"
#import "TFComicBrowseBottomCell.h"
#import "TFPublicAdvertisementViewCell.h"
#import "TFComicBrowseMenuView.h"
#import "WXYZ_ChapterBottomPayBar.h"
#import "TFAdvertisementManager.h"
#import "WXYZ_ComicDownloadManager.h"
#import "TFReadRecordManager.h"
#import "TFNightModeView.h"
#import "TFComicBarrageModel.h"
#import "OCBarrage.h"
#import "TFCollectionManager.h"
#define MinScale 1.0f
#define MaxScale 2.0f
@interface TFComicBrowseViewController ()<UITableViewDelegate, UITableViewDataSource, UIScrollViewDelegate>
{
BOOL isEnableTurnPage;
BOOL isEnableBarrage;
}
@property (nonatomic ,strong) UIScrollView *mainBottomScrollView;
@property (nonatomic ,strong) TFProductionChapterModel *comicChapterModel;
@property (nonatomic ,strong) TFAdvertModel *adModel;
@property (nonatomic ,strong) UIView *welcomePageView;
@property (nonatomic ,strong) WXYZ_ChapterBottomPayBar *payBar;
@property (nonatomic ,strong) OCBarrageManager *barrageManager;
@property (nonatomic ,strong) NSMutableArray<TFComicBarrageList *> *barrageList;
/// 弹幕所有的数据
@property (nonatomic ,copy) NSArray<TFComicBarrageList *> *totalBarrageArray;
/// YES:弹幕数据已完
@property (nonatomic ,assign) BOOL barrageComplete;
@property (nonatomic ,assign) BOOL needRefresh;
/// 上次请求的章节ID
@property (nonatomic ,assign) NSInteger oldChapterID;
@end
@implementation TFComicBrowseViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[self initialize];
[self createSubviews];
[self netRequest];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self setStatusBarDefaultStyle];
if (self.comicProductionModel.is_recommend) {
self.comicProductionModel.is_recommend = NO;
[[TFCollectionManager shareManagerWithProductionType:TFProductionTypeComic] modificationCollectionWithProductionModel:self.comicProductionModel];
}
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[UIApplication sharedApplication].statusBarHidden = NO;
if (self.mainTableViewGroup.contentOffset.y > 0) {
[[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeComic] setComicReadingRecord:self.comicChapterModel.production_id chapter_id:self.chapter_id offsetY:self.mainTableViewGroup.contentOffset.y];
}
}
- (void)initialize
{
self.oldChapterID = -1;
self.needRefresh = YES;
self.barrageList = [NSMutableArray array];
self.totalBarrageArray = [NSArray array];
[self setNavigationBarTitle:[[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeComic] getReadingRecordChapterTitleWithProduction_id : self.comicProductionModel.production_id] ? : @""];
if ([[[NSUserDefaults standardUserDefaults] objectForKey:Enable_Click_Page] isEqualToString:@"0"]) {
isEnableTurnPage = NO;
} else {
isEnableTurnPage = YES;
}
NSString *enableBarrage = [[NSUserDefaults standardUserDefaults] objectForKey:Enable_Barrage];
if ([enableBarrage isEqualToString:@"0"] || !enableBarrage) {
isEnableBarrage = NO;
} else {
isEnableBarrage = YES;
}
[[TFCollectionManager shareManagerWithProductionType:TFProductionTypeComic] moveCollectionToTopWithProductionModel:self.comicProductionModel];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeChapter:) name:Notification_Switch_Chapter object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(popViewController) name:Notification_Pop_Comic_Reader object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pushToComments) name:Notification_Push_To_Comments object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pushToDirectory) name:Notification_Push_To_Directory object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(enableTapClick:) name:Enable_Click_Page object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(barrageSwitchClick:) name:Notification_Switch_Barrage object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(tableViewScorllToTop) name:Notification_Reader_Scroll_To_Top object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pushToDownloadView) name:Notification_Push_To_Comic_Download object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeBarrage:) name:Notification_Change_Barrage object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(nightModeChange:) name:Enable_Click_Night object:nil];
}
- (void)createSubviews
{
self.mainBottomScrollView = [[UIScrollView alloc] init];
self.mainBottomScrollView.minimumZoomScale = MinScale;
self.mainBottomScrollView.maximumZoomScale = MaxScale;
self.mainBottomScrollView.bounces = NO;
self.mainBottomScrollView.delegate = self;
self.mainBottomScrollView.showsVerticalScrollIndicator = NO;
self.mainBottomScrollView.showsHorizontalScrollIndicator = NO;
[self.view addSubview:self.mainBottomScrollView];
[self.mainBottomScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.top.mas_equalTo(0);
make.width.mas_equalTo(SCREEN_WIDTH);
make.height.mas_equalTo(SCREEN_HEIGHT);
}];
if (@available(iOS 11.0, *)) {
self.mainBottomScrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}
self.mainTableViewGroup.delegate = self;
self.mainTableViewGroup.dataSource = self;
[self.mainBottomScrollView addSubview:self.mainTableViewGroup];
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_HEIGHT, PUB_NAVBAR_HEIGHT)];
headerView.backgroundColor = kWhiteColor;
[self.mainTableViewGroup setTableHeaderView:headerView];
[self.mainTableViewGroup mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.top.mas_equalTo(0);
make.width.mas_equalTo(self.mainBottomScrollView.mas_width);
make.height.mas_equalTo(self.mainBottomScrollView.mas_height);
}];
WS(weakSelf)
CGFloat y = (SCREEN_HEIGHT - 290) / 2.0 - 50;
[self setEmptyOnView:self.mainTableViewGroup imageName:@"" title:TFLocalizedString(@"内容获取失败") detailTitle:nil buttonTitle:TFLocalizedString(@"重试") centerY:y tapBlock:^{
[weakSelf netRequest];
}];
// [self.mainTableViewGroup addToastFooterRefreshWithRefreshingBlock:^{
// [[NSNotificationCenter defaultCenter] postNotificationName:Notification_Switch_Chapter object:[TFUtilsHelper formatStringWithInteger:weakSelf.comicChapterModel.next_chapter]];
// }];
self.mainTableViewGroup.mj_footer = [MJRefreshFooter footerWithRefreshingBlock:^{
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Switch_Chapter object:[TFUtilsHelper formatStringWithInteger:weakSelf.comicChapterModel.next_chapter]];
}];
UITapGestureRecognizer *singleTapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTap:)];
singleTapRecognizer.numberOfTouchesRequired = 1;
[self.mainTableViewGroup addGestureRecognizer:singleTapRecognizer];
UITapGestureRecognizer *doubleTapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleTap:)];
doubleTapRecognizer.numberOfTapsRequired = 2;
[self.mainTableViewGroup addGestureRecognizer:doubleTapRecognizer];
[singleTapRecognizer requireGestureRecognizerToFail:doubleTapRecognizer];
[self.view addSubview:self.welcomePageView];
[self.view addSubview:[TFComicBrowseMenuView sharedManager]];
if ([[[NSUserDefaults standardUserDefaults] objectForKey:Enable_Click_Night] isEqualToString:@"1"]) {
[self.view addSubview:[TFNightModeView sharedManager]];
}
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return self.mainTableViewGroup;
}
- (void)tableViewScorllToTop
{
[self.mainTableViewGroup scrollToTop];
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if (self.comicChapterModel.is_preview) {
[[TFComicBrowseMenuView sharedManager] showMenuView];
[self.barrageManager pause];
return;
}
if (scrollView == self.mainTableViewGroup) {
if (scrollView.contentOffset.y <= PUB_NAVBAR_HEIGHT) {
[[TFComicBrowseMenuView sharedManager] showMenuView];
[self.barrageManager pause];
} else if (scrollView.contentOffset.y > scrollView.contentSize.height - SCREEN_HEIGHT - PUB_NAVBAR_HEIGHT) {
[[TFComicBrowseMenuView sharedManager] showMenuView];
[self.barrageManager pause];
} else {
[[TFComicBrowseMenuView sharedManager] hiddenMenuView];
if (isEnableBarrage) {
[self.barrageManager resume];
}
}
}
[[[UIApplication sharedApplication] keyWindow] endEditing:YES];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
if (self.comicChapterModel.image_list.count > 0) {
if ([TFAdvertisementManager whetherToLoadAdsWithAdvertisementType:TFAdvertisementTypeComic advertisementPosition:TFAdvertisementPositionEnd]) {
return 3;
}
return 2;
}
return 0;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (section == 0) {
return self.comicChapterModel.image_list.count;
}
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (self.comicChapterModel.image_list.count > 0) {
if (indexPath.section == 0) {
TFComicBrowseViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TFComicBrowseViewCell"];
if (!cell) {
cell = [[TFComicBrowseViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"TFComicBrowseViewCell"];
}
cell.comic_id = self.comicChapterModel.production_id;
cell.chapter_id = self.comicChapterModel.chapter_id;
cell.chapter_update_time = [self.comicChapterModel.update_time integerValue];
cell.imageModel = [self.comicChapterModel.image_list objectOrNilAtIndex:indexPath.row];
return cell;
}
if ([TFAdvertisementManager whetherToLoadAdsWithAdvertisementType:TFAdvertisementTypeComic advertisementPosition:TFAdvertisementPositionEnd]) {
if (indexPath.section == 1) {
static NSString *cellName = @"TFPublicAdvertisementViewCell";
TFPublicAdvertisementViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName];
if (!cell) {
cell = [[TFPublicAdvertisementViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
}
[cell setAdModel:self.adModel refresh:self.needRefresh];
cell.mainTableView = tableView;
return cell;
}
}
TFComicBrowseBottomCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TFComicBrowseBottomCell"];
if (!cell) {
cell = [[TFComicBrowseBottomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"TFComicBrowseBottomCell"];
}
cell.comicChapterModel = self.comicChapterModel;
return cell;
}
return [[UITableViewCell alloc] init];
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
if ([TFAdvertisementManager whetherToLoadAdsWithAdvertisementType:TFAdvertisementTypeComic advertisementPosition:TFAdvertisementPositionEnd] && section == 1) {
return kHalfMargin;
}
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, CGFLOAT_MIN)];
view.backgroundColor = [UIColor clearColor];
return view;
}
#pragma mark - 点击事件
- (void)singleTap:(UITapGestureRecognizer *)tapGes
{
CGPoint touchPoint = [tapGes locationInView:self.view];
CGFloat contentOffSetY = self.mainTableViewGroup.contentOffset.y;
CGFloat contentSizeH = self.mainTableViewGroup.contentSize.height;
CGFloat scrollOffSet = SCREEN_HEIGHT * self.mainBottomScrollView.zoomScale * 3 / 4;
if ([TFComicBrowseMenuView sharedManager].isShowing) {
if (touchPoint.y < PUB_NAVBAR_HEIGHT || touchPoint.y > SCREEN_HEIGHT - 80) {
return;
}
}
if (touchPoint.y <= SCREEN_HEIGHT / 3 && isEnableTurnPage) { // 向上滚动
[self.mainTableViewGroup setContentOffset:CGPointMake(0, (contentOffSetY - SCREEN_HEIGHT / 4 * 3) <= 0?0:(contentOffSetY - SCREEN_HEIGHT / 4 * 3 + SCREEN_HEIGHT * (self.mainBottomScrollView.zoomScale - MinScale))) animated:YES];
} else if (touchPoint.y >= SCREEN_HEIGHT / 3 * 2 && isEnableTurnPage) { // 向下滚动
if (contentOffSetY + SCREEN_HEIGHT + scrollOffSet >= contentSizeH) {
contentOffSetY = contentSizeH - SCREEN_HEIGHT + (SCREEN_HEIGHT / 4) * (self.mainBottomScrollView.zoomScale - MinScale);
} else {
contentOffSetY = contentOffSetY + scrollOffSet;
}
[self.mainTableViewGroup setContentOffset:CGPointMake(0, contentOffSetY) animated:YES];
} else { // 菜单栏
if (contentOffSetY > PUB_NAVBAR_HEIGHT && !(contentOffSetY > contentSizeH - SCREEN_HEIGHT - PUB_NAVBAR_HEIGHT)) {
[[TFComicBrowseMenuView sharedManager] autoShowOrHiddenMenuView];
if ([TFComicBrowseMenuView sharedManager].isShowing) {
[self.barrageManager pause];
} else {
if (isEnableBarrage) {
[self.barrageManager resume];
}
}
}
}
}
- (void)doubleTap:(UITapGestureRecognizer *)tapGes
{
if (self.comicChapterModel.image_list.count == 0) return;
CGFloat currScale = self.mainBottomScrollView.zoomScale;
CGFloat goalScale;
if ([TFComicBrowseMenuView sharedManager].isShowing) {
if ([tapGes locationInView:self.view].y < PUB_NAVBAR_HEIGHT || [tapGes locationInView:self.view].y > SCREEN_HEIGHT - 80) {
return;
}
}
if (currScale == MinScale) {
goalScale = MaxScale;
} else {
goalScale = MinScale;
}
if (currScale == goalScale) {
return;
}
CGPoint touchPoint = [tapGes locationInView:[self viewForZoomingInScrollView:self.mainBottomScrollView]];
CGFloat xsize = self.mainBottomScrollView.frame.size.width / goalScale;
CGFloat ysize = self.mainBottomScrollView.frame.size.height / goalScale;
CGFloat x = touchPoint.x - xsize / 2;
CGFloat y = touchPoint.y - ysize / 2;
[self.mainBottomScrollView zoomToRect:CGRectMake(x, y, xsize, ysize) animated:YES];
}
- (void)enableTapClick:(NSNotification *)noti
{
if ([noti.object isEqualToString:@"1"]) {
isEnableTurnPage = YES;
}
if ([noti.object isEqualToString:@"0"]) {
isEnableTurnPage = NO;
}
}
- (void)barrageSwitchClick:(NSNotification *)noti
{
if ([noti.object isEqualToString:@"1"]) {
isEnableBarrage = YES;
// [self.barrageManager resume];
[self addNormalBarrage];
self.barrageManager.renderView.hidden = NO;
}
if ([noti.object isEqualToString:@"0"]) {
isEnableBarrage = NO;
// [self.barrageManager pause];
self.barrageManager.renderView.hidden = YES;
}
}
- (void)nightModeChange:(NSNotification *)noti
{
if ([noti.object isEqualToString:@"1"]) {
[self.view addSubview:[TFNightModeView sharedManager]];
} else {
[[TFNightModeView sharedManager] removeFromSuperview];
}
}
- (void)pushToComments
{
TFCommentsViewController *vc = [[TFCommentsViewController alloc] init];
vc.production_id = self.comicProductionModel.production_id;
vc.chapter_id = self.chapter_id;
vc.productionType = TFProductionTypeComic;
vc.commentsSuccessBlock = ^(TFCommentsListModel *commentModel) {
TFProductionChapterModel *chapterModel = [TFComicBrowseMenuView sharedManager].comicChapterModel;
chapterModel.total_comment = commentModel.comment_num;
[TFComicBrowseMenuView sharedManager].comicChapterModel = chapterModel;
};
TFNavigationController *nav = [[TFNavigationController alloc] initWithRootViewController:vc];
[self.navigationController presentViewController:nav animated:YES completion:nil];
}
- (void)pushToDirectory
{
TFComicCatalogueViewController *vc = [[TFComicCatalogueViewController alloc] init];
vc.comic_id = self.comicProductionModel.production_id;
[self.navigationController pushViewController:vc animated:YES];
}
- (void)pushToDownloadView
{
TFComicDownloadViewController *vc = [[TFComicDownloadViewController alloc] init];
vc.comicModel = self.comicProductionModel;
[self.navigationController pushViewController:vc animated:YES];
}
- (void)changeChapter:(NSNotification *)noti
{
self.chapter_id = [noti.object integerValue];
[[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeComic] addReadingRecordWithProduction_id:self.comicChapterModel.production_id chapter_id:self.chapter_id chapterTitle:self.comicChapterModel.chapter_title];
[self.mainTableViewGroup setContentOffset:CGPointZero];
[self netRequest];
}
- (void)reloadDataSource
{
[self hiddenNavigationBar:YES];
[self hiddenNavigationBarLeftButton];
self.mainBottomScrollView.userInteractionEnabled = YES;
[[TFComicBrowseMenuView sharedManager] showMenuView];
self.needRefresh = YES;
[self.mainTableViewGroup reloadData];
dispatch_async(dispatch_get_main_queue(), ^{
self.needRefresh = NO;
});
NSDictionary<NSString *, NSString *> *dict = [[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeComic] getComicReadingRecord:self.comicChapterModel.production_id];
if ([dict objectForKey:[NSString stringWithFormat:@"%zd", self.chapter_id]]) {
CGFloat offsetY = [[dict objectForKey:[NSString stringWithFormat:@"%zd", self.chapter_id]] floatValue];
if (offsetY > self.mainTableViewGroup.contentSize.height) {
offsetY = self.mainTableViewGroup.contentSize.height;
}
dispatch_async(dispatch_get_main_queue(), ^{
[self.mainTableViewGroup setContentOffset:CGPointMake(0, offsetY)];
});
}
if (!self.comicChapterModel) {
[[NSNotificationCenter defaultCenter] postNotificationName:Enable_Click_Page object:@"0"];
}
[self.mainTableViewGroup xtfei_endLoading];
if (self.welcomePageView.alpha > 0) {
[UIView animateWithDuration:kAnimatedDuration animations:^{
self.welcomePageView.alpha = 0;
} completion:^(BOOL finished) {
[self.welcomePageView removeAllSubviews];
[self.welcomePageView removeFromSuperview];
}];
}
}
- (UIView *)welcomePageView
{
if (!_welcomePageView) {
_welcomePageView = [[UIView alloc] init];
_welcomePageView.backgroundColor = kWhiteColor;
_welcomePageView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
_welcomePageView.userInteractionEnabled = NO;
NSMutableArray *imagesArray = [NSMutableArray array];
for (int i = 1; i < 27; i++) {
[imagesArray addObject:[YYImage imageNamed:[NSString stringWithFormat:@"comic_loading%d.png", i]]];
}
YYAnimatedImageView *imageView = [[YYAnimatedImageView alloc] init];
imageView.animationDuration = 2;
imageView.animationImages = imagesArray;
imageView.animationRepeatCount = 999;
[_welcomePageView addSubview:imageView];
[imageView startAnimating];
[imageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(_welcomePageView.mas_centerX).with.offset(- kMargin);
make.centerY.mas_equalTo(_welcomePageView.mas_centerY);
make.width.height.mas_equalTo(_welcomePageView.mas_width).with.multipliedBy(0.5);
}];
UIView *progress = [[UIView alloc] init];
progress.backgroundColor = kGrayViewColor;
progress.layer.cornerRadius = 1.5;
[_welcomePageView addSubview:progress];
[progress mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(_welcomePageView.mas_centerX);
make.top.mas_equalTo(imageView.mas_bottom);
make.width.mas_equalTo(imageView.mas_width);
make.height.mas_equalTo(3);
}];
UIBezierPath *bezPath = [UIBezierPath bezierPath];
[bezPath moveToPoint:CGPointMake(0, 1)];
[bezPath addLineToPoint:CGPointMake(SCREEN_WIDTH / 2, 1)];
CAShapeLayer *layer = [CAShapeLayer layer];
layer.lineWidth = 3;
layer.path = bezPath.CGPath;
layer.strokeColor = kMainColor.CGColor;
layer.fillColor = kGrayViewColor.CGColor;
layer.lineCap = @"round";
[progress.layer addSublayer:layer];
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
animation.duration = 30;
animation.fromValue = @0;
animation.toValue = @1;
animation.repeatCount = 999;
[layer addAnimation:animation forKey:nil];
}
return _welcomePageView;
}
- (void)netRequest
{
if ([TFNetworkManager networkingStatus] == NO) {
[self.emptyView setTitle:TFLocalizedString(@"当前为离线状态,只可查看缓存内容哦")];
// 获取本地缓存信息
self.comicChapterModel = [[WXYZ_ComicDownloadManager sharedManager] getDownloadChapterModelWithProduction_id:self.comicProductionModel.production_id chapter_id:[[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeComic] getReadingRecordChapter_idWithProduction_id:self.comicProductionModel.production_id]];
// 不存在就只展示缓存内容
if (!self.comicChapterModel) {
TFProductionModel *productionModel = [[WXYZ_DownloadHelper sharedManager] getDownloadProductionModelWithProduction_id:self.comicProductionModel.production_id productionType:TFProductionTypeComic];
// 没有阅读记录
if (self.chapter_id == 0) {
self.comicChapterModel = [productionModel.chapter_list firstObject];
self.chapter_id = self.comicChapterModel.chapter_id;
} else {
for (TFProductionChapterModel *chapterModel in productionModel.chapter_list) {
if (self.chapter_id == chapterModel.chapter_id) {
self.comicChapterModel = chapterModel;
}
}
}
}
// 设置记录信息
[[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeComic] addReadingRecordWithProduction_id:self.comicChapterModel.production_id chapter_id:self.chapter_id chapterTitle:self.comicChapterModel.chapter_title];
[[TFComicBrowseMenuView sharedManager] stopLoadingData];
[TFComicBrowseMenuView sharedManager].comicChapterModel = self.comicChapterModel;
[TFComicBrowseMenuView sharedManager].productionModel = self.comicProductionModel;
if (self.comicChapterModel.next_chapter > 0) {
[self.mainTableViewGroup showRefreshFooter];
} else {
[self.mainTableViewGroup hideRefreshFooter];
}
[self reloadDataSource];
[self.mainTableViewGroup endRefreshing];
[self.mainTableViewGroup xtfei_endLoading];
return;
}
WS(weakSelf)
[self.emptyView setTitle:TFLocalizedString(@"内容获取失败")];
[self.emptyView setBtnTitle:TFLocalizedString(@"重试")];
[[TFComicBrowseMenuView sharedManager] startLoadingData];
self.mainBottomScrollView.userInteractionEnabled = NO;
if (self.chapter_id == self.oldChapterID) return;
[TFNetworkTools POST:Comic_Chapter parameters:@{@"comic_id":[TFUtilsHelper formatStringWithInteger:self.comicProductionModel.production_id], @"chapter_id":[TFUtilsHelper formatStringWithInteger:self.chapter_id]} model:TFProductionChapterModel.class success:^(BOOL isSuccess, TFProductionChapterModel * _Nullable t_model, TFNetworkRequestModel * _Nonnull requestModel) {
[[TFComicBrowseMenuView sharedManager] stopLoadingData];
weakSelf.oldChapterID = -1;
if (isSuccess) {
weakSelf.comicChapterModel = t_model;
weakSelf.chapter_id = t_model.chapter_id;
[weakSelf requestBarrage];
[[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeComic] addReadingRecordWithProduction_id:t_model.production_id chapter_id:t_model.chapter_id chapterTitle:t_model.chapter_title];
[TFComicBrowseMenuView sharedManager].comicChapterModel = t_model;
[TFComicBrowseMenuView sharedManager].productionModel = weakSelf.comicProductionModel;
if (t_model.is_preview) {
if (!weakSelf.payBar && weakSelf) {
TFProductionChapterModel *tt_model = [[TFProductionChapterModel alloc] init];
tt_model.production_id = t_model.production_id;
tt_model.chapter_id = t_model.chapter_id;
WXYZ_ChapterBottomPayBar *payBar = [[WXYZ_ChapterBottomPayBar alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) chapterModel:tt_model barType:WXYZ_BottomPayBarTypeBuyChapter productionType:TFProductionTypeComic];
weakSelf.payBar = payBar;
payBar.paySuccessChaptersBlock = ^(NSArray<NSString *> * _Nonnull success_chapter_ids) {
[weakSelf netRequest];
};
payBar.canTouchHiddenView = NO;
[weakSelf.view addSubview:payBar];
[payBar showBottomPayBar];
}
} else {
[weakSelf.payBar hiddenBottomPayBar];
[weakSelf.payBar removeFromSuperview];
weakSelf.payBar = nil;
}
if (t_model.next_chapter > 0) {
[weakSelf.mainTableViewGroup showRefreshFooter];
} else {
[weakSelf.mainTableViewGroup hideRefreshFooter];
}
}
[weakSelf reloadDataSource];
[weakSelf.mainTableViewGroup endRefreshing];
[weakSelf.mainTableViewGroup xtfei_endLoading];
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
weakSelf.oldChapterID = -1;
[[TFComicBrowseMenuView sharedManager] stopLoadingData];
[weakSelf.mainTableViewGroup endRefreshing];
[weakSelf.mainTableViewGroup xtfei_endLoading];
}];
[TFNetworkTools POST:Advert_Info parameters:@{@"type" : @"2", @"position" : @"8"} model:TFAdvertModel.class success:^(BOOL isSuccess, TFAdvertModel * _Nullable t_model, TFNetworkRequestModel * _Nonnull requestModel) {
weakSelf.adModel = t_model;
} failure:nil];
[TFNetworkTools POST:Comic_Add_Read_Log parameters:@{@"comic_id":[TFUtilsHelper formatStringWithInteger:self.comicProductionModel.production_id], @"chapter_id":[TFUtilsHelper formatStringWithInteger:self.chapter_id]} model:nil success:nil failure:nil];
}
// 请求弹幕数据
- (void)requestBarrage {
// 移除当前所有弹幕
[self.barrageList removeAllObjects];
self.totalBarrageArray = @[];
self.currentPageNumber = 1;
self.barrageComplete = NO;
[self.barrageManager.renderView removeAllSubviews];
[self.barrageManager.renderView.animatingCells removeAllObjects];
[self.barrageManager.renderView.idleCells removeAllObjects];
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(addNormalBarrage) object:nil];
[self request_Barrage];
}
- (void)request_Barrage {
WS(weakSelf)
if (self.barrageComplete) {
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(addNormalBarrage) object:nil];
[self.barrageList removeAllObjects];
self.barrageList = [NSMutableArray arrayWithArray:self.totalBarrageArray];
if (self.barrageList.count > 0) {
if (_barrageManager.renderView.animatingCells.count == 0 && weakSelf.barrageComplete) {
self.barrageManager.renderView.animationStopBlock = ^{
if (weakSelf.barrageManager.renderView.animatingCells.count <= 1) {
[weakSelf addNormalBarrage];
}
};
[weakSelf addNormalBarrage];
} else {
self.barrageManager.renderView.animationStopBlock = ^{
if (weakSelf.barrageManager.renderView.animatingCells.count <= 1 && weakSelf.barrageComplete) {
[weakSelf addNormalBarrage];
}
};
}
}
return;
}
NSDictionary *params = @{
@"comic_id" : @(self.comicProductionModel.production_id),
@"chapter_id" : @(self.chapter_id),
@"page_num" : @(self.currentPageNumber),
};
[TFNetworkTools POST:Comic_Barrage parameters:params model:TFComicBarrageModel.class success:^(BOOL isSuccess, TFComicBarrageModel *_Nullable t_model, TFNetworkRequestModel *requestModel) {
if (isSuccess) {
weakSelf.barrageComplete = t_model.current_page >= t_model.total_page;
[weakSelf.barrageList addObjectsFromArray:t_model.list];
weakSelf.totalBarrageArray = [weakSelf.totalBarrageArray arrayByAddingObjectsFromArray:t_model.list];
[weakSelf addNormalBarrage];
} else {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:requestModel.msg ?: TFLocalizedString(@"弹幕获取失败")];
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
[TFPromptManager showPromptWithError:error defaultText:TFLocalizedString(@"请求失败")];
}];
}
- (void)addNormalBarrage {
if (isEnableBarrage == NO) {
return;
}
if ([TFComicBrowseMenuView sharedManager].isShowing) {
[self.barrageManager pause];
}
TFComicBarrageList *t_model = [self barrageModel];
if (!t_model) {
self.currentPageNumber++;
[self request_Barrage];
return;
}
OCBarrageTextDescriptor *textDescriptor = [[OCBarrageTextDescriptor alloc] init];
textDescriptor.text = t_model.content ?: @"";
textDescriptor.textColor = [UIColor colorWithHexString:t_model.color ?: @""];
textDescriptor.positionPriority = OCBarragePositionVeryHigh;
textDescriptor.textFont = [UIFont systemFontOfSize:17.0];
textDescriptor.strokeColor = [[UIColor blackColor] colorWithAlphaComponent:1.0];
textDescriptor.strokeWidth = -1;
textDescriptor.fixedSpeed = 15;
textDescriptor.barrageCellClass = [OCBarrageTextCell class];
if (![TFComicBrowseMenuView sharedManager].isShowing) {
[self.barrageManager renderBarrageDescriptor:textDescriptor];
}
[self performSelector:@selector(addNormalBarrage) afterDelay:0.5];
}
// 获取弹幕内容
- (TFComicBarrageList *)barrageModel {
TFComicBarrageList *t_model = [self.barrageList objectOrNilAtIndex:0];
if (t_model && ![TFComicBrowseMenuView sharedManager].isShowing) {
[self.barrageList removeObject:t_model];
}
return t_model;
}
// 更新弹幕
- (void)changeBarrage:(NSNotification *)noti {
NSString *text = noti.object ?: @"";
TFComicBarrageList *t_model = [[TFComicBarrageList alloc] init];
t_model.content = text;
t_model.color = @"#fdf03e";
[self.barrageList insertObject:t_model atIndex:0];
self.totalBarrageArray = [self.totalBarrageArray arrayByAddingObjectsFromArray:@[t_model]];
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(addNormalBarrage) object:nil];
[self addNormalBarrage];
}
- (OCBarrageManager *)barrageManager {
if (!_barrageManager) {
_barrageManager = [[OCBarrageManager alloc] init];
_barrageManager.renderView.backgroundColor = [UIColor clearColor];
_barrageManager.renderView.userInteractionEnabled = NO;
[_barrageManager start];
[self.view insertSubview:_barrageManager.renderView belowSubview:[TFComicBrowseMenuView sharedManager]];
[_barrageManager.renderView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.width.equalTo(self.view);
make.top.equalTo(self.view).offset(kStatusBarHeight);
make.height.equalTo(self.view).multipliedBy(1.0 / 3.0);
}];
}
return _barrageManager;
}
@end
@@ -0,0 +1,20 @@
//
// TFComicCatalogueViewController.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/15.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFBasicViewController.h"
NS_ASSUME_NONNULL_BEGIN
@interface TFComicCatalogueViewController : TFBasicViewController
@property (nonatomic ,assign) NSInteger comic_id;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,344 @@
//
// TFComicCatalogueViewController.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/15.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFComicCatalogueViewController.h"
#import "TFComicDetailRightViewCell.h"
#import "TFComicCatalogueModel.h"
#import "TFReadRecordManager.h"
#import "WXYZ_ComicDownloadManager.h"
#define MenuButtonHeight 50
@interface TFComicCatalogueViewController ()<UITableViewDelegate, UITableViewDataSource>
{
TFButton *gotoCurrent;
TFButton *gotoEnd;
CGFloat beginOffSetY;
}
@property (nonatomic ,strong) TFButton *sortButton;
@property (nonatomic ,strong) TFComicCatalogueModel *directoryListModel;
// 已阅读章节索引
@property (nonatomic ,assign) NSInteger readIndex;
// 按钮触发的滚动事件
@property (nonatomic ,assign) BOOL btnTrigger;
@end
@implementation TFComicCatalogueViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[self initialize];
[self createSubviews];
[self networkRequest];
}
- (void)initialize
{
self.readIndex = -1;
[self setNavigationBarTitle:TFLocalizedString(@"目录")];
[self.navigationBar addSubview:self.sortButton];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(networkRequest) name:Notification_Production_Pay_Success object:nil];
[self setEmptyOnView:self.mainTableView title:TFLocalizedString(@"暂无目录列表") buttonTitle:@"" tapBlock:^{
}];
}
- (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(PUB_NAVBAR_HEIGHT);
make.width.mas_equalTo(self.view.mas_width);
make.height.mas_equalTo(self.view.mas_height).with.offset(- PUB_NAVBAR_HEIGHT);
}];
gotoCurrent = [[TFButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - MenuButtonHeight - kHalfMargin, SCREEN_HEIGHT - PUB_TABBAR_HEIGHT - 44 - MenuButtonHeight - kMargin - kHalfMargin, MenuButtonHeight, MenuButtonHeight) buttonTitle:TFLocalizedString(@"当前") buttonImageName:@"comic_goto_current" buttonIndicator:TFButtonIndicatorTitleBottom];
gotoCurrent.layer.cornerRadius = 25;
gotoCurrent.layer.borderWidth = 1;
gotoCurrent.layer.borderColor = kGrayViewColor.CGColor;
gotoCurrent.clipsToBounds = YES;
gotoCurrent.backgroundColor = kWhiteColor;
gotoCurrent.buttonMargin = 8;
gotoCurrent.buttonTitleFont = kFont10;
gotoCurrent.graphicDistance = 0;
gotoCurrent.buttonImageScale = 0.4;
[gotoCurrent addTarget:self action:@selector(gotoCurrentClick:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:gotoCurrent];
gotoEnd = [[TFButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - MenuButtonHeight - kHalfMargin, SCREEN_HEIGHT - PUB_TABBAR_HEIGHT - 44 - kMargin, MenuButtonHeight, MenuButtonHeight) buttonTitle:TFLocalizedString(@"到底") buttonImageName:@"comic_goto_bottom" buttonIndicator:TFButtonIndicatorTitleBottom];
gotoEnd.layer.cornerRadius = 25;
gotoEnd.layer.borderWidth = 1;
gotoEnd.layer.borderColor = kGrayViewColor.CGColor;
gotoEnd.clipsToBounds = YES;
gotoEnd.tag = 0;
gotoEnd.backgroundColor = kWhiteColor;
gotoEnd.buttonMargin = 8;
gotoEnd.buttonTitleFont = kFont10;
gotoEnd.graphicDistance = 0;
gotoEnd.buttonImageScale = 0.4;
[gotoEnd addTarget:self action:@selector(gotoEndClick:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:gotoEnd];
}
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
beginOffSetY = scrollView.contentOffset.y;
}
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView {
if (scrollView.contentSize.height - scrollView.contentOffset.y <= CGRectGetHeight(scrollView.bounds)) {// 滑到了底部
gotoEnd.buttonImageName = @"comic_goto_top";
gotoEnd.buttonTitle = TFLocalizedString(@"到顶");
gotoEnd.tag = 1;
} else if (scrollView.contentOffset.y == 0) {// 滑到了顶部
gotoEnd.buttonImageName = @"comic_goto_bottom";
gotoEnd.buttonTitle = TFLocalizedString(@"到底");
gotoEnd.tag = 0;
}
self.btnTrigger = NO;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (!self.btnTrigger) {
if (scrollView.contentOffset.y > beginOffSetY) {
gotoEnd.buttonImageName = @"comic_goto_bottom";
gotoEnd.buttonTitle = TFLocalizedString(@"到底");
gotoEnd.tag = 0;
} else if (scrollView.contentOffset.y < beginOffSetY) {
gotoEnd.buttonImageName = @"comic_goto_top";
gotoEnd.buttonTitle = TFLocalizedString(@"到顶");
gotoEnd.tag = 1;
}
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.directoryListModel.chapter_list.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
TFProductionChapterModel *t_chapterList = [self.directoryListModel.chapter_list objectOrNilAtIndex:indexPath.row];
TFComicDetailRightViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TFComicDetailRightViewCell"];
if (!cell) {
cell = [[TFComicDetailRightViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"TFComicDetailRightViewCell"];
}
cell.chapterModel = t_chapterList;
return cell;
}
- (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 whiteColor];
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, PUB_TABBAR_OFFSET == 0?10:PUB_TABBAR_OFFSET)];
view.backgroundColor = [UIColor clearColor];
return view;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
TFProductionChapterModel *t_chapterModel = [self.directoryListModel.chapter_list objectOrNilAtIndex:indexPath.row];
[[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeComic] addReadingRecordWithProduction_id:self.comic_id chapter_id:t_chapterModel.chapter_id chapterTitle:t_chapterModel.chapter_title];
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Switch_Chapter object:[TFUtilsHelper formatStringWithInteger:t_chapterModel.chapter_id]];
[self.navigationController popViewControllerAnimated:YES];
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
if (scrollView.contentSize.height - scrollView.contentOffset.y <= CGRectGetHeight(scrollView.bounds)) {// 滑到了底部
gotoEnd.buttonImageName = @"comic_goto_top";
gotoEnd.buttonTitle = TFLocalizedString(@"到顶");
gotoEnd.tag = 1;
} else if (scrollView.contentOffset.y == 0) {// 滑到了顶部
gotoEnd.buttonImageName = @"comic_goto_bottom";
gotoEnd.buttonTitle = TFLocalizedString(@"到底");
gotoEnd.tag = 0;
}
self.btnTrigger = NO;
}
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
if (!decelerate) {
if (scrollView.contentSize.height - scrollView.contentOffset.y <= CGRectGetHeight(scrollView.bounds)) {// 滑到了底部
gotoEnd.buttonImageName = @"comic_goto_top";
gotoEnd.buttonTitle = TFLocalizedString(@"到顶");
gotoEnd.tag = 1;
} else if (scrollView.contentOffset.y == 0) {// 滑到了顶部
gotoEnd.buttonImageName = @"comic_goto_bottom";
gotoEnd.buttonTitle = TFLocalizedString(@"到底");
gotoEnd.tag = 0;
}
}
self.btnTrigger = NO;
}
#pragma mark - 点击事件
- (void)changeDirectorySort:(TFButton *)sender
{
if (self.directoryListModel.chapter_list.count == 0) return;
if (sender.tag == 0) {
sender.tag = 1;
sender.buttonImageName = @"comic_reverse_order";
sender.buttonTitle = TFLocalizedString(@"倒序");
} else {
sender.tag = 0;
sender.buttonImageName = @"comic_positive_order";
sender.buttonTitle = TFLocalizedString(@"正序");
}
self.directoryListModel.chapter_list = [[self.directoryListModel.chapter_list reverseObjectEnumerator] allObjects];
self.directoryListModel = self.directoryListModel;// 更新阅读章节下标索引
[self.mainTableView reloadData];
}
- (void)gotoCurrentClick:(UIButton *)sender
{
if (self.directoryListModel.chapter_list.count == 0) return;
if (self.readIndex) {
[self.mainTableView scrollToRow:self.readIndex inSection:0 atScrollPosition:UITableViewScrollPositionTop animated:NO];
} else {
[self.mainTableView setContentOffset:CGPointMake(0,0) animated:NO];
}
}
- (void)gotoEndClick:(UIButton *)sender
{
if (self.mainTableView.intrinsicContentSize.height <= CGRectGetHeight(self.mainTableView.bounds)) return;
self.btnTrigger = YES;
if (self.directoryListModel.chapter_list.count == 0) return;
if (sender.tag == 0) {
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Directory_Move object:@"bottom"];
[self.mainTableView scrollToBottomAnimated:YES];
gotoEnd.buttonImageName = @"comic_goto_top";
gotoEnd.buttonTitle = TFLocalizedString(@"到顶");
gotoEnd.tag = 1;
} else {
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Directory_Move object:@"top"];
[self.mainTableView scrollToTopAnimated:YES];
gotoEnd.buttonImageName = @"comic_goto_bottom";
gotoEnd.buttonTitle = TFLocalizedString(@"到底");
gotoEnd.tag = 0;
}
}
#pragma mark - 懒加载
- (TFButton *)sortButton
{
if (!_sortButton) {
CGFloat width = [TFViewHelper getDynamicWidthWithLabelFont:kFont11 labelHeight:30.0 labelText:TFLocalizedString(@"正序") maxWidth:240.0];
width += kLabelHeight;
_sortButton = [[TFButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - kHalfMargin - width, PUB_NAVBAR_HEIGHT - 30 - kQuarterMargin, width, 30) buttonTitle:TFLocalizedString(@"正序") buttonSubTitle:@"" buttonImageName:@"comic_positive_order" buttonIndicator:TFButtonIndicatorImageRightBothRight showMaskView:NO];
_sortButton.buttonImageScale = 0.4;
_sortButton.buttonTitleFont = kFont11;
_sortButton.graphicDistance = 5;
_sortButton.buttonTitleColor = kGrayTextColor;
_sortButton.tag = 0;
[_sortButton addTarget:self action:@selector(changeDirectorySort:) forControlEvents:UIControlEventTouchUpInside];
}
return _sortButton;
}
- (void)setDirectoryListModel:(TFComicCatalogueModel *)directoryListModel {
_directoryListModel = directoryListModel;
// 计算已读章节的位置
NSInteger readIndex = [[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeComic] getReadingRecordChapter_idWithProduction_id:self.comic_id];
NSArray<NSNumber *> *t_arr = [self.directoryListModel.chapter_list valueForKeyPath:@"chapter_id"];
self.readIndex = [t_arr indexOfObject:@(readIndex)];
if (self.readIndex == NSNotFound) {
self.readIndex = -1;
}
}
- (void)networkRequest
{
if ([TFNetworkManager networkingStatus] == NO) {
TFProductionModel *comicModel = [[WXYZ_DownloadHelper sharedManager] getDownloadProductionModelWithProduction_id:self.comic_id productionType:TFProductionTypeComic];
self.directoryListModel = [[TFComicCatalogueModel alloc] init];
self.directoryListModel.chapter_list = comicModel.chapter_list;
[self.mainTableView reloadData];
dispatch_async(dispatch_get_main_queue(), ^{
[gotoCurrent sendActionsForControlEvents:UIControlEventTouchUpInside];
});
if (self.directoryListModel.chapter_list.count == 0) {
self.mainTableView.scrollEnabled = NO;
} else {
self.mainTableView.scrollEnabled = YES;
}
[self.mainTableView xtfei_endLoading];
return;
}
WS(weakSelf)
[TFNetworkTools POSTQuick:Comic_Catalog parameters:@{@"comic_id":[TFUtilsHelper formatStringWithInteger:self.comic_id]} model:TFComicCatalogueModel.class success:^(BOOL isSuccess, TFComicCatalogueModel *_Nullable t_model, BOOL isCache, TFNetworkRequestModel *requestModel) {
if (isSuccess) {
weakSelf.directoryListModel = t_model;
[weakSelf.mainTableView reloadData];
dispatch_async(dispatch_get_main_queue(), ^{
[gotoCurrent sendActionsForControlEvents:UIControlEventTouchUpInside];
});
} else {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:requestModel.msg ?: TFLocalizedString(@"请求失败")];
}
if (weakSelf.directoryListModel.chapter_list.count == 0) {
weakSelf.mainTableView.scrollEnabled = NO;
} else {
weakSelf.mainTableView.scrollEnabled = YES;
}
[weakSelf.mainTableView xtfei_endLoading];
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
if (weakSelf.directoryListModel.chapter_list.count == 0) {
weakSelf.mainTableView.scrollEnabled = NO;
} else {
weakSelf.mainTableView.scrollEnabled = YES;
}
[weakSelf.mainTableView xtfei_endLoading];
[TFPromptManager showPromptWithError:error defaultText:TFLocalizedString(@"请求失败")];
}];
}
@end
@@ -0,0 +1,33 @@
//
// TFComicBarrageModel.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/15.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@class TFComicBarrageList, TFPagingModel;
@interface TFComicBarrageModel : TFPagingModel
@property (nonatomic ,copy) NSArray<TFComicBarrageList *> *list;
@end
@interface TFComicBarrageList : NSObject
/// 弹幕内容
@property (nonatomic ,copy) NSString *content;
// 弹幕颜色,16进制
@property (nonatomic ,copy) NSString *color;
@property (nonatomic ,assign) NSInteger uid;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,26 @@
//
// TFComicBarrageModel.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/15.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFComicBarrageModel.h"
@implementation TFComicBarrageModel
+ (NSDictionary<NSString *,id> *)modelContainerPropertyGenericClass
{
return @{
@"list" : TFComicBarrageList.class
};
}
@end
@implementation TFComicBarrageList
@end
@@ -0,0 +1,35 @@
//
// TFComicBrowseBottomBar.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#define Comic_Menu_Bottom_Bar_Top_Height 40
#define Comic_Menu_Bottom_Bar_Height (PUB_TABBAR_HEIGHT + Comic_Menu_Bottom_Bar_Top_Height)
NS_ASSUME_NONNULL_BEGIN
@interface TFComicBrowseBottomBar : UIView <YYTextViewDelegate>
@property (nonatomic ,strong) TFProductionChapterModel *comicChapterModel;
@property (nonatomic ,strong) TFProductionModel *productionModel;
- (void)showMenuBottomBar;
- (void)hiddenMenuBottomBar;
- (void)startLoadingData;
- (void)stopLoadingData;
- (void)reloadCollectionState;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,694 @@
//
// TFComicBrowseBottomBar.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFComicBrowseBottomBar.h"
#import "TFComicBrowseSetBar.h"
#import "TFShareManager.h"
#import "WXYZ_ComicDownloadManager.h"
#import "TFCollectionManager.h"
#import "WXYZ_BadgeView.h"
#import "UIControl+EventInterval.h"
#define MenuButtonHeight 50
@interface TFComicBrowseBottomBar ()
{
#if TF_Comments_Mode
UIButton *commentsButton;
#endif
#if TF_Comments_Mode
YYTextView *commentsTextView;
UIButton *sendComments;
#endif
UILabel *currentPageLabel;
UIButton *previousButton;
UIButton *nextButton;
UIActivityIndicatorView *indicatorView;
TFButton *barrageSwitch;
TFComicBrowseSetBar *settingBar;
UIButton *scrollToTop;
UIButton *collectionButton;
CGFloat keyboardHeight; //键盘高度
BOOL isCommentState; // 是否是评论状态
__weak UIButton *_leftImageButton;
WXYZ_BadgeView *badgeView;
}
@end
@implementation TFComicBrowseBottomBar
- (instancetype)init
{
if (self = [super init]) {
#if TF_Comments_Mode
self.frame = CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, PUB_TABBAR_HEIGHT + Comic_Menu_Bottom_Bar_Top_Height);
#else
self.frame = CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, Comic_Menu_Bottom_Bar_Height - Comic_Menu_Bottom_Bar_Top_Height);
#endif
self.backgroundColor = kGrayViewColor;
//增加监听,当键盘出现或改变时收出消息
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:)name:UIKeyboardWillShowNotification object:nil];
//增加监听,当键退出时收出消息
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:)name:UIKeyboardWillHideNotification object:nil];
[self createSubViews];
}
return self;
}
- (void)createSubViews
{
#if TF_Comments_Mode
sendComments = [UIButton buttonWithType:UIButtonTypeCustom];
if ([[[NSUserDefaults standardUserDefaults] objectForKey:Enable_Barrage] isEqualToString:@"1"]) {
[sendComments setTitle:TFLocalizedString(@"发射") forState:UIControlStateNormal];
isCommentState = NO;
} else {
[sendComments setTitle:TFLocalizedString(@"发送") forState:UIControlStateNormal];
isCommentState = YES;
}
sendComments.backgroundColor = [UIColor clearColor];
[sendComments setTitleColor:kBlackColor forState:UIControlStateNormal];
[sendComments.titleLabel setFont:kMainFont];
[sendComments addTarget:self action:@selector(sendCommentsClick) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:sendComments];
[sendComments mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(self.mas_right);
make.top.mas_equalTo(kQuarterMargin);
make.width.mas_equalTo(70);
make.height.mas_equalTo(Comic_Menu_Bottom_Bar_Top_Height - kHalfMargin);
}];
commentsTextView = [[YYTextView alloc] init];
commentsTextView.backgroundColor = kWhiteColor;
commentsTextView.contentInset = UIEdgeInsetsMake(2, 30, 0, 0);
commentsTextView.textVerticalAlignment = YYTextVerticalAlignmentCenter;
if ([[[NSUserDefaults standardUserDefaults] objectForKey:Enable_Barrage] isEqualToString:@"1"]) {
commentsTextView.placeholderText = TFLocalizedString(@"发一条弹幕吧");
} else {
commentsTextView.placeholderText = TFLocalizedString(@"发一条评论吧");
}
commentsTextView.placeholderFont = kFont12;
commentsTextView.placeholderTextColor = kGrayTextColor;
commentsTextView.font = kFont12;
commentsTextView.returnKeyType = UIReturnKeySend;
commentsTextView.layer.cornerRadius = (Comic_Menu_Bottom_Bar_Top_Height - kHalfMargin) / 2;
commentsTextView.layer.borderColor = kGrayViewColor.CGColor;
commentsTextView.layer.borderWidth = 0.8;
commentsTextView.delegate = self;
[self addSubview:commentsTextView];
[commentsTextView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(kMargin);
make.top.mas_equalTo(kQuarterMargin);
make.right.mas_equalTo(sendComments.mas_left).with.offset(kHalfMargin);
make.height.mas_equalTo(sendComments.mas_height);
}];
UIButton *leftImageButton = [[UIButton alloc] init];
_leftImageButton = leftImageButton;
if ([[[NSUserDefaults standardUserDefaults] objectForKey:Enable_Barrage] isEqualToString:@"1"]) {
leftImageButton.tag = 0;
[leftImageButton setImage:[UIImage imageNamed:TFLocalizedString(@"comic_barrage")] forState:UIControlStateNormal];
} else {
leftImageButton.tag = 1;
[leftImageButton setImage:[UIImage imageNamed:TFLocalizedString(@"comic_comments_icon")] forState:UIControlStateNormal];
}
leftImageButton.adjustsImageWhenHighlighted = NO;
[leftImageButton addTarget:self action:@selector(changeCommentsState:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:leftImageButton];
[leftImageButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(commentsTextView.mas_left).with.offset(kQuarterMargin);
make.centerY.mas_equalTo(sendComments.mas_centerY);
make.width.height.mas_equalTo(30 - kHalfMargin);
}];
#endif
// 上一话
previousButton = [UIButton buttonWithType:UIButtonTypeCustom];
previousButton.backgroundColor = [UIColor clearColor];
previousButton.adjustsImageWhenHighlighted = NO;
previousButton.enabled = NO;
[previousButton.titleLabel setFont:kMainFont];
[previousButton setImage:[[UIImage imageNamed:@"public_back"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
[previousButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
[previousButton setTintColor:kGrayTextLightColor];
[previousButton setImageEdgeInsets:UIEdgeInsetsMake(14, 20, 14, 8)];
[previousButton addTarget:self action:@selector(previousButtonClick) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:previousButton];
[previousButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.mas_left);
make.bottom.mas_equalTo(self.mas_bottom).with.offset(- PUB_TABBAR_OFFSET);
make.width.mas_equalTo(PUB_TABBAR_HEIGHT - PUB_TABBAR_OFFSET);
make.height.mas_equalTo(PUB_TABBAR_HEIGHT - PUB_TABBAR_OFFSET);
}];
currentPageLabel = [[UILabel alloc] init];
currentPageLabel.text = TFLocalizedString(@"当前话");
currentPageLabel.textAlignment = NSTextAlignmentCenter;
currentPageLabel.textColor = kBlackColor;
currentPageLabel.font = kMainFont;
[self addSubview:currentPageLabel];
[currentPageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(previousButton.mas_right);
make.centerY.mas_equalTo(previousButton.mas_centerY);
make.width.mas_equalTo(70);
make.height.mas_equalTo(previousButton.mas_height);
}];
indicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:(UIActivityIndicatorViewStyleGray)];
indicatorView.color = kBlackColor;
indicatorView.hidesWhenStopped = YES;
[currentPageLabel addSubview:indicatorView];
[indicatorView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(currentPageLabel.mas_centerX);
make.centerY.mas_equalTo(currentPageLabel.mas_centerY);
make.width.height.mas_equalTo(previousButton.mas_height);
}];
// 下一话
nextButton = [UIButton buttonWithType:UIButtonTypeCustom];
nextButton.backgroundColor = [UIColor clearColor];
nextButton.adjustsImageWhenHighlighted = NO;
nextButton.transform = CGAffineTransformMakeRotation(M_PI);
nextButton.enabled = NO;
[nextButton.titleLabel setFont:kMainFont];
[nextButton setImage:[[UIImage imageNamed:@"public_back"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
[nextButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
[nextButton setTintColor:kGrayTextLightColor];
[nextButton setImageEdgeInsets:UIEdgeInsetsMake(14, 20, 14, 8)];
[nextButton addTarget:self action:@selector(nextButtonClick) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:nextButton];
[nextButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(currentPageLabel.mas_right);
make.centerY.mas_equalTo(previousButton.mas_centerY);
make.width.mas_equalTo(previousButton.mas_width);
make.height.mas_equalTo(previousButton.mas_height);
}];
UIView *buttonMenuBar = [[UIView alloc] init];
buttonMenuBar.backgroundColor = [UIColor clearColor];
[self addSubview:buttonMenuBar];
[buttonMenuBar mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(nextButton.mas_right).with.offset(kMargin);
make.centerY.mas_equalTo(previousButton.mas_centerY);
make.right.mas_equalTo(self.mas_right).with.offset(- kMargin);
make.height.mas_equalTo(30);
}];
UIButton *settingButton = [UIButton buttonWithType:UIButtonTypeCustom];
settingButton.adjustsImageWhenHighlighted = NO;
settingButton.tintColor = kColorRGB(111, 111, 111);
settingButton.touchEventInterval = 0.5;
[settingButton setImage:[[UIImage imageNamed:@"comic_setting"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
[settingButton setImageEdgeInsets:UIEdgeInsetsMake(3, 3, 3, 3)];
[settingButton addTarget:self action:@selector(settingButtonClick) forControlEvents:UIControlEventTouchUpInside];
[buttonMenuBar addSubview:settingButton];
#if TF_Download_Mode
UIButton *downloadButton = [UIButton buttonWithType:UIButtonTypeCustom];
downloadButton.adjustsImageWhenHighlighted = NO;
downloadButton.tintColor = kColorRGB(111, 111, 111);
downloadButton.touchEventInterval = 0.5;
[downloadButton setImage:[[UIImage imageNamed:@"comic_download"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
[downloadButton setImageEdgeInsets:UIEdgeInsetsMake(3, 3, 4, 4)];
[downloadButton addTarget:self action:@selector(downloadButtonClick) forControlEvents:UIControlEventTouchUpInside];
[buttonMenuBar addSubview:downloadButton];
#endif
UIButton *shareButton = [UIButton buttonWithType:UIButtonTypeCustom];
shareButton.adjustsImageWhenHighlighted = NO;
shareButton.tintColor = kColorRGB(111, 111, 111);
shareButton.touchEventInterval = 0.5;
[shareButton setImage:[[UIImage imageNamed:@"comic_share"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
[shareButton setImageEdgeInsets:UIEdgeInsetsMake(4, 4, 4, 4)];
[shareButton addTarget:self action:@selector(shareButtonClick:) forControlEvents:UIControlEventTouchUpInside];
[buttonMenuBar addSubview:shareButton];
#if TF_Comments_Mode
commentsButton = [UIButton buttonWithType:UIButtonTypeCustom];
commentsButton.adjustsImageWhenHighlighted = NO;
commentsButton.tintColor = kColorRGB(111, 111, 111);
commentsButton.touchEventInterval = 0.5;
[commentsButton setImage:[[UIImage imageNamed:@"comic_comments"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
[commentsButton setImageEdgeInsets:UIEdgeInsetsMake(5, 5, 5, 5)];
[commentsButton addTarget:self action:@selector(checkCommentsClick) forControlEvents:UIControlEventTouchUpInside];
[buttonMenuBar addSubview:commentsButton];
badgeView = [[WXYZ_BadgeView alloc] initWithView:commentsButton];
[badgeView setCircleAtFrame:CGRectMake(0, 0, 17, 17)];
[badgeView moveCircleByX:18 Y:- 2];
badgeView.maxCount = 99;
[badgeView setCircleColor:kRedColor labelColor:kWhiteColor];
[badgeView setCountLabelFont:kFont9];
#endif
NSArray *buttonMenuArr = [NSArray arrayWithObjects:
#if TF_Comments_Mode
commentsButton,
#endif
shareButton,
#if TF_Download_Mode
downloadButton,
#endif
settingButton, nil];
[buttonMenuArr mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedItemLength:30 leadSpacing:0 tailSpacing:0];
[buttonMenuArr mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(0);
make.height.mas_equalTo(30);
}];
#if TF_Comments_Mode
NSString *imageName = nil;
if ([[[NSUserDefaults standardUserDefaults] objectForKey:Enable_Barrage] isEqualToString:@"1"]) {
imageName = @"comic_danmu_select";
} else {
imageName = @"comic_danmu";
}
barrageSwitch = [[TFButton alloc] initWithFrame:CGRectZero buttonTitle:TFLocalizedString(@"弹幕") buttonSubTitle:@"" buttonImageName:imageName buttonIndicator:TFButtonIndicatorTitleRight showMaskView:NO];
barrageSwitch.buttonTitleFont = kFont10;
barrageSwitch.buttonTitleColor = kWhiteColor;
barrageSwitch.graphicDistance = 2;
barrageSwitch.buttonImageScale = 0.5;
barrageSwitch.tag = 1;
barrageSwitch.backgroundColor = kBlackTransparentColor;
barrageSwitch.layer.cornerRadius = 10;
[barrageSwitch addTarget:self action:@selector(barrageSwitchClick:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:barrageSwitch];
CGFloat width = [TFViewHelper getDynamicWidthWithLabelFont:kFont10 labelHeight:22.0 labelText:TFLocalizedString(@"弹幕") maxWidth:SCREEN_WIDTH / 2.0];
[barrageSwitch mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(kHalfMargin);
make.top.mas_equalTo(self.mas_top).with.offset(PUB_TABBAR_HEIGHT + Comic_Menu_Bottom_Bar_Top_Height);
make.width.mas_equalTo(width + kLabelHeight);
make.height.mas_equalTo(22);
}];
#endif
settingBar = [[TFComicBrowseSetBar alloc] init];
scrollToTop = [UIButton buttonWithType:UIButtonTypeCustom];
scrollToTop.adjustsImageWhenHighlighted = NO;
[scrollToTop setImage:[UIImage imageNamed:TFLocalizedString(@"comic_top")] forState:UIControlStateNormal];
[scrollToTop addTarget:self action:@selector(scrollToTopClick) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:scrollToTop];
[scrollToTop mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(self.mas_right).with.offset(- kHalfMargin);
make.bottom.mas_equalTo(self.mas_top).with.offset(6 * MenuButtonHeight);
make.width.height.mas_equalTo(MenuButtonHeight);
}];
if (![[TFCollectionManager shareManagerWithProductionType:TFProductionTypeComic] isCollectedWithProduction_id:self.comicChapterModel.production_id]) {
collectionButton = [UIButton buttonWithType:UIButtonTypeCustom];
collectionButton.adjustsImageWhenHighlighted = NO;
[collectionButton setImage:[UIImage imageNamed:TFLocalizedString(@"comic_collection")] forState:UIControlStateNormal];
[collectionButton addTarget:self action:@selector(collectionButtonClick:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:collectionButton];
[collectionButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(self.mas_right).with.offset(- kHalfMargin);
make.bottom.mas_equalTo(scrollToTop.mas_top).with.offset(- kHalfMargin);
make.width.height.mas_equalTo(MenuButtonHeight);
}];
}
}
- (void)showMenuBottomBar
{
[UIView animateWithDuration:kAnimatedDurationFast animations:^{
#if TF_Comments_Mode
self.frame = CGRectMake(0, SCREEN_HEIGHT - (PUB_TABBAR_HEIGHT + Comic_Menu_Bottom_Bar_Top_Height), SCREEN_WIDTH, PUB_TABBAR_HEIGHT + Comic_Menu_Bottom_Bar_Top_Height);
#else
self.frame = CGRectMake(0, SCREEN_HEIGHT - (Comic_Menu_Bottom_Bar_Height - Comic_Menu_Bottom_Bar_Top_Height), SCREEN_WIDTH, Comic_Menu_Bottom_Bar_Height - Comic_Menu_Bottom_Bar_Top_Height);
#endif
}];
[barrageSwitch mas_updateConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.mas_top).with.offset(- kHalfMargin - 20);
}];
[scrollToTop mas_updateConstraints:^(MASConstraintMaker *make) {
make.bottom.mas_equalTo(self.mas_top).with.offset(- kHalfMargin);
}];
}
- (void)reloadCollectionState
{
if (![[TFCollectionManager shareManagerWithProductionType:TFProductionTypeComic] isCollectedWithProduction_id:self.comicChapterModel.production_id]) {
collectionButton.hidden = NO;
} else {
collectionButton.hidden = YES;
}
}
- (void)hiddenMenuBottomBar
{
[[[UIApplication sharedApplication] keyWindow] endEditing:YES];
[UIView animateWithDuration:kAnimatedDurationFast animations:^{
#if TF_Comments_Mode
self.frame = CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, PUB_TABBAR_HEIGHT + Comic_Menu_Bottom_Bar_Top_Height);
#else
self.frame = CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, Comic_Menu_Bottom_Bar_Height - Comic_Menu_Bottom_Bar_Top_Height);
#endif
}];
[barrageSwitch mas_updateConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.mas_top).with.offset(PUB_TABBAR_HEIGHT + Comic_Menu_Bottom_Bar_Top_Height);
}];
[scrollToTop mas_updateConstraints:^(MASConstraintMaker *make) {
make.bottom.mas_equalTo(self.mas_top).with.offset(6 * MenuButtonHeight);
}];
}
- (void)startLoadingData
{
currentPageLabel.text = @"";
[indicatorView startAnimating];
previousButton.enabled = NO;
[previousButton setTintColor:kGrayTextLightColor];
nextButton.enabled = NO;
[nextButton setTintColor:kGrayTextLightColor];
}
- (void)stopLoadingData
{
currentPageLabel.text = TFLocalizedString(@"当前话");
[indicatorView stopAnimating];
previousButton.enabled = YES;
[previousButton setTintColor:kBlackColor];
nextButton.enabled = YES;
[nextButton setTintColor:kBlackColor];
}
#pragma mark - 点击事件
- (void)changeCommentsState:(UIButton *)sender
{
if (sender.tag == 0) { // 评论
[self changeComentInput:YES];
} else { // 吐槽
[self changeComentInput:NO];
}
}
// 改变评论输入框状态
- (void)changeComentInput:(BOOL)isComment {
#if TF_Comments_Mode
if (isComment) {
commentsTextView.placeholderText = TFLocalizedString(@"发一条评论吧");
[sendComments setTitle:TFLocalizedString(@"发送") forState:UIControlStateNormal];
isCommentState = YES;
_leftImageButton.tag = 1;
[_leftImageButton setImage:[UIImage imageNamed:TFLocalizedString(@"comic_comments_icon")] forState:UIControlStateNormal];
return;
}
if (!isComment) {
commentsTextView.placeholderText = TFLocalizedString(@"发一条弹幕吧");
[sendComments setTitle:TFLocalizedString(@"发射") forState:UIControlStateNormal];
isCommentState = NO;
_leftImageButton.tag = 0;
[_leftImageButton setImage:[UIImage imageNamed:TFLocalizedString(@"comic_barrage")] forState:UIControlStateNormal];
return;
}
#endif
}
- (void)previousButtonClick
{
if (self.comicChapterModel.last_chapter && self.comicChapterModel.last_chapter > 0) {
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Switch_Chapter object:[TFUtilsHelper formatStringWithInteger:self.comicChapterModel.last_chapter]];
}
}
- (void)nextButtonClick
{
if (self.comicChapterModel.next_chapter && self.comicChapterModel.next_chapter > 0) {
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Switch_Chapter object:[TFUtilsHelper formatStringWithInteger:self.comicChapterModel.next_chapter]];
}
}
- (void)settingButtonClick
{
[settingBar showSettingBar];
}
- (void)barrageSwitchClick:(UIButton *)sender
{
if (sender.tag == 0) {
sender.tag = 1;
barrageSwitch.buttonImageName = @"comic_danmu_select";
[[NSUserDefaults standardUserDefaults] setObject:@"1" forKey:Enable_Barrage];
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Switch_Barrage object:@"1"];
[self changeComentInput:NO];
} else {
sender.tag = 0;
barrageSwitch.buttonImageName = @"comic_danmu";
[[NSUserDefaults standardUserDefaults] setObject:@"0" forKey:Enable_Barrage];
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Switch_Barrage object:@"0"];
[self changeComentInput:YES];
}
[[NSUserDefaults standardUserDefaults] synchronize];
}
- (void)shareButtonClick:(UIButton *)sender
{
[TFShareManager shareWithProduction_id:NSStringFromInteger(self.comicChapterModel.production_id) chapter_id:NSStringFromInteger(self.comicChapterModel.chapter_id) type:TFShareTypeComic];
}
- (void)checkCommentsClick
{
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Push_To_Comments object:nil];
}
- (void)scrollToTopClick
{
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Reader_Scroll_To_Top object:nil];
}
- (void)downloadButtonClick
{
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Push_To_Comic_Download object:nil];
}
- (void)collectionButtonClick:(UIButton *)sender
{
if ([[TFCollectionManager shareManagerWithProductionType:TFProductionTypeComic] isCollectedWithProduction_id:self.comicChapterModel.production_id]) {
return;
}
WS(weakSelf)
[TFUtilsHelper synchronizationRackProductionWithProduction_id:self.comicChapterModel.production_id productionType:TFProductionTypeComic complete:nil];
if ([[TFCollectionManager shareManagerWithProductionType:TFProductionTypeComic] addCollectionWithProductionModel:weakSelf.productionModel]) {
sender.hidden = YES;
[TFPromptManager showPromptViewWithStatus:TFPromptStatusSuccess promptTitle:TFLocalizedString(@"已加入书架")];
} else {
sender.hidden = NO;
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:TFLocalizedString(@"加入书架失败")];
}
}
- (void)sendCommentsClick
{
#if TF_Comments_Mode
if (!TFUserInfoManager.isLogin) {
[TFLoginOptionsViewController presentLoginView:nil];
return;
}
if (commentsTextView.text.length < 1) {
return;
}
NSString *t_text = commentsTextView.text;
commentsTextView.text = @"";
[[[UIApplication sharedApplication] keyWindow] endEditing:YES];
WS(weakSelf)
if (!isCommentState) {
[TFNetworkTools POST:Comic_Send_Barrage parameters:@{@"comic_id":[TFUtilsHelper formatStringWithInteger:self.comicChapterModel.production_id], @"chapter_id":[TFUtilsHelper formatStringWithInteger:self.comicChapterModel.chapter_id], @"content":t_text} model:nil success:^(BOOL isSuccess, NSDictionary * _Nullable t_model, TFNetworkRequestModel * _Nonnull requestModel) {
SS(strongSelf)
if (isSuccess) {
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Change_Barrage object:t_text];
strongSelf->commentsTextView.text = @"";
strongSelf.frame = CGRectMake(0, SCREEN_HEIGHT - (PUB_TABBAR_HEIGHT + Comic_Menu_Bottom_Bar_Top_Height), SCREEN_WIDTH, PUB_TABBAR_HEIGHT + Comic_Menu_Bottom_Bar_Top_Height);
[TFPromptManager showPromptViewWithStatus:TFPromptStatusSuccess promptTitle:TFLocalizedString(@"发射成功")];
} else if (Compare_Json_isEqualTo(requestModel.code, 315)) {
strongSelf->commentsTextView.text = @"";
[TFPromptManager showPromptViewWithStatus:TFPromptStatusSuccess promptTitle:requestModel.msg];
} else if (requestModel.code == 319) {// 发送成功,但需要审核
strongSelf->commentsTextView.text = @"";
[TFPromptManager showPromptViewWithStatus:TFPromptStatusSuccess promptTitle:requestModel.msg];
} else {
strongSelf->commentsTextView.text = t_text;
[strongSelf->commentsTextView becomeFirstResponder];
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:requestModel.msg];
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
SS(strongSelf)
strongSelf->commentsTextView.text = t_text;
}];
} else {
[TFNetworkTools POST:Comic_Comment_Post parameters:@{@"comic_id":[TFUtilsHelper formatStringWithInteger:self.comicChapterModel.production_id], @"content":t_text} model:nil success:^(BOOL isSuccess, NSDictionary * _Nullable t_model, TFNetworkRequestModel * _Nonnull requestModel) {
SS(strongSelf)
if (isSuccess) {
strongSelf->commentsTextView.text = @"";
[TFPromptManager showPromptViewWithStatus:TFPromptStatusSuccess promptTitle:TFLocalizedString(@"评论成功")];
[badgeView increment];
} else if (Compare_Json_isEqualTo(requestModel.code, 315)) {
strongSelf->commentsTextView.text = @"";
[TFPromptManager showPromptViewWithStatus:TFPromptStatusSuccess promptTitle:requestModel.msg];
} else if (requestModel.code == 318) {// 发送成功,但需要审核
strongSelf->commentsTextView.text = @"";
[TFPromptManager showPromptViewWithStatus:TFPromptStatusSuccess promptTitle:requestModel.msg];
} else {
strongSelf->commentsTextView.text = t_text;
[strongSelf->commentsTextView becomeFirstResponder];
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:requestModel.msg];
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
SS(strongSelf)
strongSelf->commentsTextView.text = t_text;
}];
}
#endif
}
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
UIView *view = [super hitTest:point withEvent:event];
if ([barrageSwitch pointInside:[barrageSwitch convertPoint:point fromView:self] withEvent:event]) {
return barrageSwitch;
}
if ([collectionButton pointInside:[collectionButton convertPoint:point fromView:self] withEvent:event]) {
return collectionButton;
}
if ([scrollToTop pointInside:[scrollToTop convertPoint:point fromView:self] withEvent:event]) {
return scrollToTop;
}
if ([view isKindOfClass:[self class]]) {
return nil;
}
return view;
}
//当键盘出现或改变时调用
- (void)keyboardWillShow:(NSNotification *)aNotification
{
//获取键盘的高度
NSDictionary *userInfo = [aNotification userInfo];
keyboardHeight = [[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size.height;
self.frame = CGRectMake(0, SCREEN_HEIGHT - (PUB_TABBAR_HEIGHT + Comic_Menu_Bottom_Bar_Top_Height) - keyboardHeight + PUB_NAVBAR_OFFSET, SCREEN_WIDTH, PUB_TABBAR_HEIGHT + Comic_Menu_Bottom_Bar_Top_Height);
}
//当键退出时调用
- (void)keyboardWillHide:(NSNotification *)aNotification
{
keyboardHeight = PUB_TABBAR_HEIGHT + Comic_Menu_Bottom_Bar_Top_Height;
self.frame = CGRectMake(0, SCREEN_HEIGHT - (PUB_TABBAR_HEIGHT + Comic_Menu_Bottom_Bar_Top_Height), SCREEN_WIDTH, PUB_TABBAR_HEIGHT + Comic_Menu_Bottom_Bar_Top_Height);
}
- (void)textViewDidChange:(YYTextView *)textView
{
CGFloat textViewHeight = [TFViewHelper getDynamicHeightWithLabelFont:textView.font labelWidth:textView.width labelText:textView.text maxHeight:70] - kMargin;
if (textViewHeight < 30) {
textViewHeight = 30;
}
#if TF_Comments_Mode
[sendComments mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(textViewHeight);
}];
#endif
if (is_iPhone6) {
self.frame = CGRectMake(0, SCREEN_HEIGHT - keyboardHeight - PUB_TABBAR_HEIGHT + PUB_TABBAR_OFFSET - textViewHeight, SCREEN_WIDTH, PUB_TABBAR_HEIGHT + Comic_Menu_Bottom_Bar_Top_Height);
} else {
if (![textView.text isEqualToString:@""]) {
self.frame = CGRectMake(0, SCREEN_HEIGHT - keyboardHeight - PUB_TABBAR_HEIGHT + PUB_TABBAR_OFFSET - textViewHeight - kMargin, SCREEN_WIDTH, PUB_TABBAR_HEIGHT + Comic_Menu_Bottom_Bar_Top_Height);
}
}
}
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
if ([text isEqualToString:@"\n"]) {
[self sendCommentsClick];
return NO;
}
return YES;
}
- (void)setComicChapterModel:(TFProductionChapterModel *)comicChapterModel
{
_comicChapterModel = comicChapterModel;
#if TF_Comments_Mode
[badgeView setCount:(int)comicChapterModel.total_comment];
[badgeView showCount];
#endif
if (comicChapterModel.next_chapter == 0) {
[nextButton setTintColor:kGrayTextLightColor];
nextButton.enabled = NO;
} else {
[nextButton setTintColor:kBlackColor];
nextButton.enabled = YES;
}
if (comicChapterModel.last_chapter == 0) {
[previousButton setTintColor:kGrayTextLightColor];
previousButton.enabled = NO;
} else {
[previousButton setTintColor:kBlackColor];
previousButton.enabled = YES;
}
}
@end
@@ -0,0 +1,19 @@
//
// TFComicBrowseBottomCell.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/15.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface TFComicBrowseBottomCell : TFBasicTableViewCell
@property (nonatomic ,strong) TFProductionChapterModel *comicChapterModel;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,100 @@
//
// TFComicBrowseBottomCell.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/15.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFComicBrowseBottomCell.h"
#import "TFComicBrowseBottomBar.h"
@interface TFComicBrowseBottomCell ()
{
TFButton *previousButton;
TFButton *nextButton;
}
@end
@implementation TFComicBrowseBottomCell
- (void)createSubviews
{
[super createSubviews];
previousButton = [[TFButton alloc] initWithFrame:CGRectZero buttonTitle:TFLocalizedString(@"上一篇") buttonImageName:@"public_back" buttonIndicator:TFButtonIndicatorTitleRight];
previousButton.tag = 0;
previousButton.buttonImageScale = 0.2;
[previousButton addTarget:self action:@selector(changeChapter:) forControlEvents:UIControlEventTouchUpInside];
[self.contentView addSubview:previousButton];
[previousButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.contentView.mas_left).with.offset(kMargin);
make.top.mas_equalTo(self.contentView.mas_top);
make.width.mas_equalTo(self.contentView.mas_width).multipliedBy(0.5).with.offset(- kMargin);
make.height.mas_equalTo(60);
make.bottom.mas_equalTo(self.contentView.mas_bottom).with.offset(- (PUB_TABBAR_HEIGHT + Comic_Menu_Bottom_Bar_Top_Height)).priorityLow();
}];
UIView *line = [[UIView alloc] init];
line.backgroundColor = kGrayLineColor;
[self.contentView addSubview:line];
[line mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(previousButton.mas_right);
make.height.mas_equalTo(previousButton.mas_height).with.multipliedBy(0.8);
make.width.mas_equalTo(kCellLineHeight);
make.centerY.mas_equalTo(previousButton.mas_centerY);
}];
nextButton = [[TFButton alloc] initWithFrame:CGRectZero buttonTitle:TFLocalizedString(@"下一篇") buttonImageName:@"public_back" buttonIndicator:TFButtonIndicatorTitleLeft];
nextButton.transformImageView = YES;
nextButton.tag = 1;
nextButton.buttonImageScale = 0.2;
[nextButton addTarget:self action:@selector(changeChapter:) forControlEvents:UIControlEventTouchUpInside];
[self.contentView addSubview:nextButton];
[nextButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(self.contentView.mas_right).with.offset(- kMargin);
make.top.mas_equalTo(self.contentView.mas_top);
make.width.mas_equalTo(previousButton.mas_width);
make.height.mas_equalTo(previousButton.mas_height);
}];
}
- (void)setComicChapterModel:(TFProductionChapterModel *)comicChapterModel
{
_comicChapterModel = comicChapterModel;
if (comicChapterModel.last_chapter > 0) {
previousButton.buttonTintColor = kBlackColor;
} else {
previousButton.buttonTintColor = kGrayTextLightColor;
}
if (comicChapterModel.next_chapter > 0) {
nextButton.buttonTintColor = kBlackColor;
} else {
nextButton.buttonTintColor = kGrayTextLightColor;
}
}
- (void)changeChapter:(UIButton *)sender
{
if (sender.tag == 0) { // 上一篇
if (self.comicChapterModel.last_chapter > 0) {
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Switch_Chapter object:[TFUtilsHelper formatStringWithInteger:self.comicChapterModel.last_chapter]];
} else {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:TFLocalizedString(@"已是第一篇")];
}
} else { // 下一篇
if (self.comicChapterModel.next_chapter > 0) {
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Switch_Chapter object:[TFUtilsHelper formatStringWithInteger:self.comicChapterModel.next_chapter]];
} else {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:TFLocalizedString(@"已是最后一篇")];
}
}
}
@end
@@ -0,0 +1,35 @@
//
// TFComicBrowseMenuView.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface TFComicBrowseMenuView : UIView
@property (nonatomic ,strong) TFProductionModel *productionModel;
@property (nonatomic ,strong) TFProductionChapterModel *comicChapterModel;
@property (nonatomic ,assign) BOOL isShowing;
interface_singleton
- (void)autoShowOrHiddenMenuView;
- (void)showMenuView;
- (void)hiddenMenuView;
- (void)startLoadingData;
- (void)stopLoadingData;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,140 @@
//
// TFComicBrowseMenuView.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFComicBrowseMenuView.h"
#import "TFComicBrowseTopBar.h"
#import "TFComicBrowseBottomBar.h"
@interface TFComicBrowseMenuView ()
{
TFComicBrowseTopBar *topBar;
TFComicBrowseBottomBar *bottomBar;
}
@end
@implementation TFComicBrowseMenuView
implementation_singleton(TFComicBrowseMenuView)
- (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 = [UIColor clearColor];
self.userInteractionEnabled = YES;
self.isShowing = NO;
}
- (void)createSubViews
{
topBar = [[TFComicBrowseTopBar alloc] init];
[self addSubview:topBar];
bottomBar = [[TFComicBrowseBottomBar alloc] init];
[self addSubview:bottomBar];
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
[self hiddenMenuView];
}
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
UIView *touchView = [super hitTest:point withEvent:event];
if (CGRectContainsPoint(topBar.bounds, point)) {
if ([touchView isKindOfClass:[UIButton class]]) {
return touchView;
}
return nil;
}
if ([touchView isDescendantOfView:bottomBar]) {
return touchView;
}
return nil;
}
- (void)autoShowOrHiddenMenuView
{
if (!self.isShowing) {
[self showMenuView];
} else {
[self hiddenMenuView];
}
}
- (void)showMenuView
{
[bottomBar reloadCollectionState];
if (self.isShowing) {
return;
}
self.isShowing = YES;
[topBar showMenuTopBar];
[bottomBar showMenuBottomBar];
[TFViewHelper setStateBarDefaultStyle];
[UIApplication sharedApplication].statusBarHidden = NO;
}
- (void)hiddenMenuView
{
if (!self.isShowing) {
return;
}
self.isShowing = NO;
[topBar hiddenMenuTopBar];
[bottomBar hiddenMenuBottomBar];
[UIApplication sharedApplication].statusBarHidden = YES;
}
- (void)startLoadingData
{
[bottomBar startLoadingData];
}
- (void)stopLoadingData
{
[bottomBar stopLoadingData];
}
- (void)setComicChapterModel:(TFProductionChapterModel *)comicChapterModel
{
_comicChapterModel = comicChapterModel;
if (comicChapterModel) {
[topBar setNavTitle:comicChapterModel.chapter_title?:self.productionModel.name];
bottomBar.comicChapterModel = comicChapterModel;
} else {
[topBar setNavTitle:@""];
bottomBar.comicChapterModel = comicChapterModel;
}
}
- (void)setProductionModel:(TFProductionModel *)productionModel
{
if (_productionModel != productionModel) {
_productionModel = productionModel;
bottomBar.productionModel = productionModel;
}
}
@end
@@ -0,0 +1,19 @@
//
// TFComicBrowseSetBar.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface TFComicBrowseSetBar : UIView
- (void)showSettingBar;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,276 @@
//
// TFComicBrowseSetBar.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFComicBrowseSetBar.h"
#import "KLSwitch.h"
#import "TFNightModeView.h"
#import <AudioToolbox/AudioToolbox.h>
#define Menu_Setting_Cell_Height 70
#define Menu_Setting_Bar_Height (2 * Menu_Setting_Cell_Height + PUB_NAVBAR_OFFSET)
@interface TFComicBrowseSetBar ()
@property (nonatomic ,strong) UIView *bottomView;
@property (nonatomic ,strong) KLSwitch *clickPageSwitch;
@property (nonatomic ,strong) KLSwitch *nightSwitch;
@end
@implementation TFComicBrowseSetBar
- (instancetype)init
{
if (self = [super init]) {
self.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
self.backgroundColor = kBlackTransparentColor;
self.hidden = YES;
[kMainWindow addSubview:self];
NSUserDefaults *defualt = [NSUserDefaults standardUserDefaults];
// 默认开启
if (![defualt objectForKey:Enable_Click_Page]) {
[defualt setObject:@"1" forKey:Enable_Click_Page];
[defualt synchronize];
}
// 默认关闭
if (![defualt objectForKey:Enable_Click_Night]) {
[defualt setObject:@"0" forKey:Enable_Click_Night];
[defualt synchronize];
}
// 默认开启
if (![defualt objectForKey:Enable_Barrage]) {
[defualt setObject:@"1" forKey:Enable_Barrage];
[defualt synchronize];
}
[self createSubViews];
}
return self;
}
- (void)createSubViews
{
self.bottomView = [[UIView alloc] init];
self.bottomView.backgroundColor = [UIColor whiteColor];
[self addSubview:self.bottomView];
[self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.top.mas_equalTo(self.mas_bottom);
make.width.mas_equalTo(self.mas_width);
make.height.mas_equalTo(Menu_Setting_Bar_Height);
}];
NSInteger cellIndex = 0;
{
UIView *cell = [[UIView alloc] init];
cell.backgroundColor = [UIColor whiteColor];
[self.bottomView addSubview:cell];
[cell mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.top.mas_equalTo(cellIndex * Menu_Setting_Cell_Height);
make.width.mas_equalTo(self.bottomView.mas_width);
make.height.mas_equalTo(Menu_Setting_Cell_Height);
}];
self.clickPageSwitch = [[KLSwitch alloc] initWithFrame:CGRectMake(1, 1, 51, 31) didChangeHandler:^(BOOL isOn) {
AudioServicesPlaySystemSound(1519);
if (isOn) {
[[NSUserDefaults standardUserDefaults] setObject:@"1" forKey:Enable_Click_Page];
[[NSNotificationCenter defaultCenter] postNotificationName:Enable_Click_Page object:@"1"];
} else {
[[NSUserDefaults standardUserDefaults] setObject:@"0" forKey:Enable_Click_Page];
[[NSNotificationCenter defaultCenter] postNotificationName:Enable_Click_Page object:@"0"];
}
[[NSUserDefaults standardUserDefaults] synchronize];
}];
self.clickPageSwitch.onTintColor = kMainColor;
self.clickPageSwitch.transform = CGAffineTransformMakeScale(0.7, 0.7);//缩放
[cell addSubview:self.clickPageSwitch];
if ([[[NSUserDefaults standardUserDefaults] objectForKey:Enable_Click_Page] isEqualToString:@"1"]) {
[self.clickPageSwitch setDefaultOnState:YES];
} else {
[self.clickPageSwitch setDefaultOnState:NO];
}
[self.clickPageSwitch mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(cell.mas_centerY);
make.right.mas_equalTo(cell.mas_right).with.offset(- kHalfMargin);
make.width.mas_equalTo(51);
make.height.mas_equalTo(31);
}];
UILabel *titleLabel = [[UILabel alloc] init];
titleLabel.text = TFLocalizedString(@"点击翻页");
titleLabel.textAlignment = NSTextAlignmentLeft;
titleLabel.textColor = kBlackColor;
titleLabel.font = kMainFont;
[cell addSubview:titleLabel];
[titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.mas_equalTo(cell.mas_centerY);
make.left.mas_equalTo(kHalfMargin);
make.width.mas_equalTo(SCREEN_WIDTH / 2);
make.height.mas_equalTo(20);
}];
UILabel *subTitleLabel = [[UILabel alloc] init];
subTitleLabel.numberOfLines = 2;
subTitleLabel.preferredMaxLayoutWidth = SCREEN_WIDTH - kMargin - 51.0 - kQuarterMargin;
subTitleLabel.text = TFLocalizedString(@"打开后可点击屏幕上下方翻页");
subTitleLabel.textAlignment = NSTextAlignmentLeft;
subTitleLabel.textColor = kGrayTextColor;
subTitleLabel.font = kFont12;
[cell addSubview:subTitleLabel];
[subTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(titleLabel.mas_left);
make.top.mas_equalTo(titleLabel.mas_bottom);
make.right.equalTo(self.clickPageSwitch.mas_left).offset(-kQuarterMargin);
make.height.mas_equalTo(subTitleLabel.intrinsicContentSize.height);
}];
UIView *line = [[UIView alloc] init];
line.backgroundColor = kGrayLineColor;
[cell addSubview:line];
[line mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(kMargin);
make.height.mas_equalTo(kCellLineHeight);
make.width.mas_equalTo(SCREEN_WIDTH);
make.bottom.mas_equalTo(cell.mas_bottom);
}];
cellIndex ++;
}
{
UIView *cell = [[UIView alloc] init];
cell.backgroundColor = [UIColor whiteColor];
[self.bottomView addSubview:cell];
[cell mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.top.mas_equalTo(cellIndex * Menu_Setting_Cell_Height);
make.width.mas_equalTo(self.bottomView.mas_width);
make.height.mas_equalTo(Menu_Setting_Cell_Height);
}];
self.nightSwitch = [[KLSwitch alloc] initWithFrame:CGRectMake(1, 1, 51, 31) didChangeHandler:^(BOOL isOn) {
AudioServicesPlaySystemSound(1519);
if (isOn) {
[[NSUserDefaults standardUserDefaults] setObject:@"1" forKey:Enable_Click_Night];
[[NSUserDefaults standardUserDefaults] synchronize];
[[NSNotificationCenter defaultCenter] postNotificationName:Enable_Click_Night object:@"1"];
} else {
[[NSUserDefaults standardUserDefaults] setObject:@"0" forKey:Enable_Click_Night];
[[NSUserDefaults standardUserDefaults] synchronize];
[[NSNotificationCenter defaultCenter] postNotificationName:Enable_Click_Night object:@"0"];
}
[[NSUserDefaults standardUserDefaults] synchronize];
}];
self.nightSwitch.onTintColor = kMainColor;
self.nightSwitch.transform = CGAffineTransformMakeScale(0.7, 0.7); // 缩放
[cell addSubview:self.nightSwitch];
if ([[[NSUserDefaults standardUserDefaults] objectForKey:Enable_Click_Night] isEqualToString:@"1"]) {
[self.nightSwitch setDefaultOnState:YES];
} else {
[self.nightSwitch setDefaultOnState:NO];
}
[self.nightSwitch mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(cell.mas_centerY);
make.right.mas_equalTo(cell.mas_right).with.offset(- kHalfMargin);
make.width.mas_equalTo(51);
make.height.mas_equalTo(31);
}];
UILabel *titleLabel = [[UILabel alloc] init];
titleLabel.text = TFLocalizedString(@"夜间模式");
titleLabel.textAlignment = NSTextAlignmentLeft;
titleLabel.textColor = kBlackColor;
titleLabel.font = kMainFont;
[cell addSubview:titleLabel];
[titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(cell.mas_centerY);
make.left.mas_equalTo(kHalfMargin);
make.width.mas_equalTo(SCREEN_WIDTH / 2);
make.height.mas_equalTo(30);
}];
cellIndex ++;
}
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
UIView *touchView = [[touches anyObject] view];
if (![touchView isEqual:self.bottomView]) {
[self hiddenSettingBar];
}
}
- (void)showSettingBar
{
self.hidden = NO;
[UIView animateWithDuration:kAnimatedDuration animations:^{
[self.bottomView mas_updateConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.mas_bottom).with.offset(- Menu_Setting_Bar_Height);
}];
}];
[UIView animateWithDuration:kAnimatedDuration animations:^{
[self.bottomView.superview layoutIfNeeded];
}];
}
- (void)hiddenSettingBar
{
[self.bottomView.superview setNeedsUpdateConstraints];
[UIView animateWithDuration:kAnimatedDuration animations:^{
[self.bottomView mas_updateConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.mas_bottom);
}];
}];
[UIView animateWithDuration:kAnimatedDuration animations:^{
[self.bottomView.superview layoutIfNeeded];
} completion:^(BOOL finished) {
self.hidden = YES;
}];
}
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
UIView *view = [super hitTest:point withEvent:event];
if ([self.clickPageSwitch pointInside:[self.clickPageSwitch convertPoint:point fromView:self] withEvent:event]) {
return self.clickPageSwitch;
}
if ([self.nightSwitch pointInside:[self.nightSwitch convertPoint:point fromView:self] withEvent:event]) {
return self.nightSwitch;
}
if ([self.bottomView pointInside:[self.bottomView convertPoint:point fromView:self] withEvent:event]) {
return self.bottomView;
}
return view;
}
@end
@@ -0,0 +1,23 @@
//
// TFComicBrowseTopBar.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface TFComicBrowseTopBar : UIView
- (void)showMenuTopBar;
- (void)hiddenMenuTopBar;
- (void)setNavTitle:(NSString *)titleString;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,128 @@
//
// TFComicBrowseTopBar.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFComicBrowseTopBar.h"
@interface TFComicBrowseTopBar ()
{
UILabel *navTitleLabel;
}
@end
@implementation TFComicBrowseTopBar
- (instancetype)init
{
if (self = [super init]) {
self.frame = CGRectMake(0, - PUB_NAVBAR_HEIGHT, SCREEN_WIDTH, PUB_NAVBAR_HEIGHT);
[self createSubViews];
}
return self;
}
- (void)createSubViews
{
self.backgroundColor = kWhiteColor;
// 默认左侧显示返回按钮
UIButton *leftBackButton = [UIButton buttonWithType:UIButtonTypeCustom];
leftBackButton.backgroundColor = [UIColor clearColor];
[leftBackButton.titleLabel setFont:kMainFont];
leftBackButton.adjustsImageWhenHighlighted = NO;
[leftBackButton setImage:[[UIImage imageNamed:@"public_back"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
[leftBackButton setImageEdgeInsets:UIEdgeInsetsMake(12, 6, 12, 18)];
[leftBackButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
[leftBackButton setTintColor:kBlackColor];
[leftBackButton addTarget:self action:@selector(leftBack) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:leftBackButton];
[leftBackButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(kHalfMargin);
make.bottom.mas_equalTo(self.bottom);
make.width.mas_equalTo(44);
make.height.mas_equalTo(44);
}];
navTitleLabel = [[UILabel alloc] init];
navTitleLabel.backgroundColor = [UIColor clearColor];
navTitleLabel.textColor = [UIColor blackColor];
navTitleLabel.numberOfLines = 1;
navTitleLabel.font = kFont16;
navTitleLabel.textAlignment = NSTextAlignmentCenter;
[self addSubview:navTitleLabel];
[navTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(leftBackButton.mas_centerY);
make.height.mas_equalTo(20);
make.left.equalTo(leftBackButton.mas_right).offset(kHalfMargin);
}];
UIButton *completeButton = [UIButton buttonWithType:UIButtonTypeCustom];
completeButton.backgroundColor = [UIColor clearColor];
completeButton.adjustsImageWhenHighlighted = NO;
[completeButton setTitleColor:kMainColor forState:UIControlStateNormal];
[completeButton setTitle:TFLocalizedString(@"全集") forState:UIControlStateNormal];
[completeButton.titleLabel setFont:kMainFont];
[completeButton addTarget:self action:@selector(completeButtonClick) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:completeButton];
[navTitleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(completeButton.mas_left).offset(-kHalfMargin);
}];
[completeButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(self.mas_right).with.offset(- kHalfMargin);
make.bottom.mas_equalTo(self.bottom);
make.width.mas_equalTo(completeButton.intrinsicContentSize.width);
make.height.mas_equalTo(44);
}];
UIImageView *navBottomLine = [[UIImageView alloc] init];
navBottomLine.userInteractionEnabled = YES;
navBottomLine.image = [UIImage imageNamed:@"navbar_bottom_line"];
[self addSubview:navBottomLine];
[navBottomLine mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.top.mas_equalTo(self.mas_bottom);
make.width.mas_equalTo(self.mas_width);
make.height.mas_equalTo(1);
}];
}
- (void)showMenuTopBar
{
[UIView animateWithDuration:kAnimatedDurationFast animations:^{
self.frame = CGRectMake(0, 0, SCREEN_WIDTH, PUB_NAVBAR_HEIGHT);
}];
}
- (void)hiddenMenuTopBar
{
[UIView animateWithDuration:kAnimatedDurationFast animations:^{
self.frame = CGRectMake(0, - PUB_NAVBAR_HEIGHT, SCREEN_WIDTH, PUB_NAVBAR_HEIGHT);
}];
}
- (void)setNavTitle:(NSString *)titleString
{
navTitleLabel.text = titleString?:@"";
}
- (void)leftBack
{
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Pop_Comic_Reader object:nil];
}
- (void)completeButtonClick
{
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Push_To_Directory object:nil];
}
@end
@@ -0,0 +1,25 @@
//
// TFComicBrowseViewCell.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/15.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface TFComicBrowseViewCell : TFBasicTableViewCell
@property (nonatomic ,strong) TFImageListModel *imageModel;
@property (nonatomic ,assign) NSInteger comic_id;
@property (nonatomic ,assign) NSInteger chapter_id;
@property (nonatomic ,assign) NSInteger chapter_update_time;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,71 @@
//
// TFComicBrowseViewCell.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/15.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFComicBrowseViewCell.h"
#import "WXYZ_ComicDownloadManager.h"
@interface TFComicBrowseViewCell ()
{
UIImageView *chapterImageView;
}
@end
@implementation TFComicBrowseViewCell
- (void)createSubviews
{
[super createSubviews];
chapterImageView = [[UIImageView alloc] init];
chapterImageView.contentMode = UIViewContentModeScaleAspectFill;
[self.contentView addSubview:chapterImageView];
[chapterImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.contentView.mas_left);
make.top.mas_equalTo(self.contentView.mas_top);
make.width.mas_equalTo(self.contentView.mas_width);
make.height.mas_equalTo(SCREEN_HEIGHT);
make.bottom.mas_equalTo(self.contentView.mas_bottom).priorityLow();
}];
}
- (void)setImageModel:(TFImageListModel *)imageModel
{
_imageModel = imageModel;
[chapterImageView mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(kGeometricHeight(SCREEN_WIDTH, imageModel.width <= 0?SCREEN_WIDTH:imageModel.width, imageModel.height <= 0?SCREEN_HEIGHT:imageModel.height));
}];
// 查找内存中的图片缓存
UIImage *cacheImage = [[YYImageCache sharedCache] getImageForKey:imageModel.image withType:YYImageCacheTypeMemory];
// 如果有则使用缓存加载图片
if (cacheImage) {
chapterImageView.image = cacheImage;
} else { // 缓存中不存在,则从本地查找图片,获取本地图片后,也放置内存中,提高运行速度
// 查找沙盒中的文件
UIImage *localImage = [[WXYZ_ComicDownloadManager sharedManager] getDownloadLocalImageWithProduction_id:self.comic_id chapter_id:self.chapter_id image_id:imageModel.image_id image_update_time:imageModel.image_update_time];
if (localImage) {
chapterImageView.image = localImage;
// 将沙盒中的文件存储到内存中
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[[YYImageCache sharedCache] setImage:localImage imageData:nil forKey:imageModel.image withType:YYImageCacheTypeMemory];
});
} else { // 沙盒中没有缓存图片
// 加载网络图片
[chapterImageView setImageWithURL:[NSURL URLWithString:imageModel.image] placeholder:HoldImage options:YYWebImageOptionSetImageWithFadeAnimation completion:nil];
}
}
}
@end
@@ -0,0 +1,22 @@
//
// TFNovelBookMarkViewController.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/15.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFBasicViewController.h"
NS_ASSUME_NONNULL_BEGIN
@interface TFNovelBookMarkViewController : TFBasicViewController
@property (nonatomic ,strong) TFProductionModel *bookModel;
@property (nonatomic ,assign) BOOL isReader;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,146 @@
//
// TFNovelBookMarkViewController.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/15.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFNovelBookMarkViewController.h"
#import "TFBookMarkModel.h"
#import "NSObject+Observer.h"
#import "TFReadRecordManager.h"
#import "TFReaderBookManager.h"
#import "TFReaderSettingHelper.h"
#import "NSString+TFExtension.h"
#import "TYTextContainer.h"
#import "NSAttributedString+TReaderPage.h"
#import "TFReadNovelViewController.h"
#import "TFNovelBookMarkViewCell.h"
@interface TFNovelBookMarkViewController ()<UITableViewDataSource, UITableViewDelegate>
@end
@implementation TFNovelBookMarkViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[self createSubviews];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
NSMutableArray<TFBookMarkModel *> *t_arr = [[TFReadRecordManager bookMark:[TFUtilsHelper formatStringWithInteger:self.bookModel.production_id]] mutableCopy];
t_arr = [[t_arr sortedArrayUsingComparator:^NSComparisonResult(TFBookMarkModel * _Nonnull obj1, TFBookMarkModel * _Nonnull obj2) {
if ([obj1.timestamp integerValue] < [obj2.timestamp integerValue]) {
return NSOrderedDescending;
}
return NSOrderedAscending;
}] mutableCopy];
NSSortDescriptor *sort1 = [NSSortDescriptor sortDescriptorWithKey:KEY_PATH(t_arr.firstObject, chapterSort) ascending:YES];
t_arr = [[t_arr sortedArrayUsingDescriptors:@[sort1]] mutableCopy];
self.dataSourceArray = t_arr;
[self.mainTableView reloadData];
[self.mainTableView xtfei_endLoading];
}
- (void)createSubviews {
[self setBasicLayout];
[self.view addSubview:self.mainTableView];
self.mainTableView.delegate = self;
self.mainTableView.dataSource = self;
self.mainTableView.contentInset = UIEdgeInsetsMake(0, 0, PUB_TABBAR_OFFSET, 0);
[self.mainTableView registerClass:[TFNovelBookMarkViewCell class] forCellReuseIdentifier:@"Identifier"];
[self.mainTableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.view);
}];
[self setEmptyOnView:self.mainTableView title:TFLocalizedString(@"暂无书签记录") buttonTitle:@"" tapBlock:^{}];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.dataSourceArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
TFNovelBookMarkViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Identifier" forIndexPath:indexPath];
[cell setBookMarkModel:self.dataSourceArray[indexPath.row]];
return cell;
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
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 {
TFBookMarkModel *t_model = self.dataSourceArray[indexPath.row];
[self.dataSourceArray removeObjectAtIndex:indexPath.row];
if (@available(iOS 11.0, *)) {
[tableView performBatchUpdates:^{
[tableView deleteRowAtIndexPath:indexPath withRowAnimation:UITableViewRowAnimationLeft];
} completion:^(BOOL finished) {
[TFReadRecordManager removeBookMark:t_model];
[tableView xtfei_endLoading];
}];
} else {
[CATransaction begin];
[CATransaction setCompletionBlock:^{
[TFReadRecordManager removeBookMark:t_model];
[tableView xtfei_endLoading];
}];
[tableView beginUpdates];
[tableView deleteRowAtIndexPath:indexPath withRowAnimation:UITableViewRowAnimationLeft];
[tableView endUpdates];
[CATransaction commit];
}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
TFBookMarkModel *t_model = self.dataSourceArray[indexPath.row];
if (self.isReader) {
[[NSNotificationCenter defaultCenter] postNotificationName:NSNOtification_Book_Mark object:@{[NSString stringWithFormat:@"%zd", t_model.chapterSort] : [NSString stringWithFormat:@"%zd", t_model.specificIndex]}];
[self.navigationController popViewControllerAnimated:YES];
} else {
TFReadNovelViewController *vc = [[TFReadNovelViewController alloc] initWithSpecificIndex:t_model.specificIndex chapterSort:t_model.chapterSort];
vc.bookModel = self.bookModel;
vc.book_id = self.bookModel.production_id;
[self.navigationController pushViewController:vc animated:YES];
}
}
//section头部间距
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return kHalfMargin;
}
//section头部视图
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, kHalfMargin)];
view.backgroundColor = [UIColor clearColor];
return view;
}
- (void)setBasicLayout {
[self hiddenNavigationBar:YES];
}
@end
@@ -0,0 +1,28 @@
//
// TFNovelCatalogueBookmarkController.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/15.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@class TFProductionModel;
@interface TFNovelCatalogueBookmarkController : TFBasicViewController
@property (nonatomic ,strong) TFProductionModel *bookModel;
@property (nonatomic ,assign) BOOL isReader;
@property (nonatomic ,copy) NSString *book_id;
@property (nonatomic ,assign) NSUInteger currentIndex;
@property (nonatomic ,assign) BOOL isBookDetailPush;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,124 @@
//
// TFNovelCatalogueBookmarkController.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/15.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFNovelCatalogueBookmarkController.h"
#import "TFNovelCatalogueViewController.h"
#import "TFNovelBookMarkViewController.h"
@interface TFNovelCatalogueBookmarkController ()<SGPageContentCollectionViewDelegate, SGPageTitleViewDelegate>
@property (nonatomic ,strong) SGPageTitleView *pageTitleView;
@property (nonatomic ,strong) SGPageContentCollectionView *pageContentCollectionView;
@property (nonatomic ,weak) TFNovelCatalogueViewController *bookDir;
@property (nonatomic ,weak) UIButton *rightButton;
@end
@implementation TFNovelCatalogueBookmarkController
- (void)viewDidLoad
{
[super viewDidLoad];
[self initialize];
[self createSubviews];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self setStatusBarDefaultStyle];
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Hidden_Tabbar object:nil];
}
- (void)initialize
{
[self setNavigationBarTitle:@""];
[self hiddenSeparator];
[self setNavigationBarRightButton:({
UIButton *rightBtn = [[UIButton alloc] init];
self.rightButton = rightBtn;
rightBtn.backgroundColor = [UIColor clearColor];
rightBtn.adjustsImageWhenHighlighted = NO;
[rightBtn setImage:[UIImage imageNamed:@"book_directory_order"] forState:UIControlStateNormal];
[rightBtn setImageEdgeInsets:UIEdgeInsetsMake(2, 2, 2, 2)];
[rightBtn addTarget:self action:@selector(orderChapter:) forControlEvents:UIControlEventTouchUpInside];
rightBtn;
})];
[self.rightButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(self.navigationBar.navTitleLabel);
make.right.equalTo(self.view).offset(-kMargin);
make.size.mas_equalTo(CGSizeMake(25, 25));
}];
}
- (void)createSubviews
{
TFNovelCatalogueViewController *bookDir = [[TFNovelCatalogueViewController alloc] init];
bookDir.isReader = self.isReader;
self.bookDir = bookDir;
if (self.bookModel) {
bookDir.bookModel = self.bookModel;
} else {
bookDir.book_id = self.book_id;
}
bookDir.isBookDetailPush = self.isBookDetailPush;
[self addChildViewController:bookDir];
TFNovelBookMarkViewController *bookMark = [[TFNovelBookMarkViewController alloc] init];
bookMark.isReader = self.isReader;
bookMark.bookModel = self.bookModel;
[self addChildViewController:bookMark];
self.pageConfigure.indicatorColor = kMainColor;
self.pageConfigure.indicatorStyle = SGIndicatorStyleDynamic;
self.pageConfigure.indicatorHeight = 3;
self.pageConfigure.bounces = NO;
self.pageConfigure.indicatorFixedWidth = 10;
self.pageConfigure.indicatorDynamicWidth = 14;
self.pageConfigure.indicatorToBottomDistance = 3;
self.pageConfigure.titleSelectedColor = kBlackColor;
self.pageConfigure.titleSelectedFont = kFont18;
self.pageConfigure.titleFont = kFont16;
self.pageConfigure.titleColor = kBlackColor;
self.pageContentCollectionView = [[SGPageContentCollectionView alloc] initWithFrame:CGRectMake(0, PUB_NAVBAR_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT - PUB_NAVBAR_HEIGHT) parentVC:self childVCs:@[bookDir, bookMark]];
_pageContentCollectionView.delegatePageContentCollectionView = self;
[self.view addSubview:self.pageContentCollectionView];
CGFloat width1 = [TFViewHelper getDynamicWidthWithLabelFont:kFont14 labelHeight:self.pageViewHeight labelText:TFLocalizedString(@"目录") maxWidth:120];
CGFloat width2 = [TFViewHelper getDynamicWidthWithLabelFont:kFont15 labelHeight:self.pageViewHeight labelText:TFLocalizedString(@"书签") maxWidth:120];
CGFloat width = width1 + width2 + kLabelHeight + kMargin;
self.pageTitleView = [SGPageTitleView pageTitleViewWithFrame:CGRectMake((SCREEN_WIDTH - width) / 2.0f, PUB_NAVBAR_OFFSET + kMargin, width, self.pageViewHeight) delegate:self titleNames:@[TFLocalizedString(@"目录"), TFLocalizedString(@"书签")] configure:self.pageConfigure];
self.pageTitleView.backgroundColor = kWhiteColor;
[self.navigationBar addSubview:self.pageTitleView];
}
- (void)pageTitleView:(SGPageTitleView *)pageTitleView selectedIndex:(NSInteger)selectedIndex
{
[self.pageContentCollectionView setPageContentCollectionViewCurrentIndex:selectedIndex];
}
- (void)pageContentCollectionView:(SGPageContentCollectionView *)pageContentCollectionView progress:(CGFloat)progress originalIndex:(NSInteger)originalIndex targetIndex:(NSInteger)targetIndex
{
[self.pageTitleView setPageTitleViewWithProgress:progress originalIndex:originalIndex targetIndex:targetIndex];
}
- (void)pageContentCollectionView:(SGPageContentCollectionView *)pageContentCollectionView index:(NSInteger)index {
self.rightButton.hidden = index != 0;
}
- (void)orderChapter:(UIButton *)sender {
[self.bookDir orderChapter:sender];
}
@end
@@ -0,0 +1,29 @@
//
// TFNovelCatalogueViewController.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/15.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFBasicViewController.h"
NS_ASSUME_NONNULL_BEGIN
@interface TFNovelCatalogueViewController : TFBasicViewController
@property (nonatomic ,strong) TFProductionModel *bookModel;
@property (nonatomic ,copy) NSString *book_id;
@property (nonatomic ,assign) BOOL isBookDetailPush;
/// 是不是从阅读器进入
@property (nonatomic ,assign) BOOL isReader;
- (void)orderChapter:(UIButton *)sender;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,512 @@
//
// TFNovelCatalogueViewController.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/15.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFNovelCatalogueViewController.h"
#import "TFReadNovelViewController.h"
#import "TFNovelCatalogueViewCell.h"
#import "TFReaderSettingHelper.h"
#import "TFReaderBookManager.h"
#import "TFReadRecordManager.h"
#import "TFCatalogModel.h"
@interface TFNovelCatalogueViewController ()<UITableViewDelegate, UITableViewDataSource, UIGestureRecognizerDelegate>
{
BOOL isScroll;//进入目录滚动到指定位置,只进行一次
BOOL first;// 第一次进入目录
}
@property (nonatomic, strong) NSIndexPath *selectedIndexPath;
@property (nonatomic, assign) BOOL firstRequest;
/// 目录是不是逆序
@property (nonatomic, assign) BOOL isReverseOrder;
/// 已购买章节
@property (nonatomic, strong) NSMutableArray<NSString *> *purchasedChapters;
@property (nonatomic, strong) NSMutableArray<TFCatalogListModel *> *dataSourceArray;
@end
@implementation TFNovelCatalogueViewController
@synthesize dataSourceArray = _dataSourceArray;
- (void)viewDidLoad
{
[super viewDidLoad];
[self initialize];
[self createSubviews];
if (self.dataSourceArray.count == 0) {
[self requestCatalogWithDown:YES];
}
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
NSInteger index = 0;
if (self.dataSourceArray.count > 0) {
NSInteger chapter_id = [[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeNovel] getReadingRecordChapter_idWithProduction_id:[self.book_id integerValue]];
for (TFCatalogListModel *t_model in self.dataSourceArray) {
if ([t_model.chapter_id integerValue] == chapter_id) {
break;
}
index++;
}
if (index == self.dataSourceArray.count) {// 如果没有阅读记录
index = 0;
}
}
[self.mainTableView reloadData];
dispatch_async(dispatch_get_main_queue(), ^{
if (self.dataSourceArray.count > 0) {
[self.mainTableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:index inSection:0] animated:NO scrollPosition:UITableViewScrollPositionTop];
}
});
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
first = NO;
}
- (void)initialize
{
self.dataSourceArray = [NSMutableArray array];
self.purchasedChapters = [NSMutableArray array];
first = YES;
[self hiddenNavigationBar:YES];
if (self.bookModel) {
self.book_id = [TFUtilsHelper formatStringWithInteger:self.bookModel.production_id];
}
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(paySuccess:) name:Notification_Production_Pay_Success object:nil];
// 获取本地目录列表
if (![TFNetworkManager networkingStatus]) {
NSString *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject;
path = [path stringByAppendingPathComponent:[TFUtilsHelper stringToMD5:@"book_catalog"]];
NSString *catalogName = [NSString stringWithFormat:@"%@_%@", self.book_id, @"catalog"];
NSString *fullPath = [path stringByAppendingFormat:@"/%@.plist", [TFUtilsHelper stringToMD5:catalogName]];
if ([[NSFileManager defaultManager] fileExistsAtPath:fullPath]) {
NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:fullPath];
TFCatalogModel *catalog = [TFCatalogModel modelWithDictionary:dict];
self.dataSourceArray = [catalog.list mutableCopy];
} else {
self.dataSourceArray = [self.bookModel.list mutableCopy];
}
} else {
if (self.bookModel.list.count != 0) {
self.dataSourceArray = [self.bookModel.list mutableCopy];
}
}
[self setEmptyOnView:self.mainTableView title:TFLocalizedString(@"暂无目录列表") buttonTitle:@"" tapBlock:^{
}];
}
- (void)paySuccess:(NSNotification *)noti {
NSArray<NSString *> *t_arr = noti.object;
[self.purchasedChapters addObjectsFromArray:t_arr];
}
- (void)createSubviews {
self.mainTableView.delegate = self;
self.mainTableView.dataSource = self;
self.mainTableView.showsVerticalScrollIndicator = YES;
self.mainTableView.showsHorizontalScrollIndicator = NO;
[self.mainTableView registerClass:TFNovelCatalogueViewCell.class forCellReuseIdentifier:@"WXBookDirectoryTableViewCell"];
[self.view addSubview:self.mainTableView];
self.mainTableView.contentInset = UIEdgeInsetsMake(0, 0, PUB_TABBAR_OFFSET, 0);
[self.mainTableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.view);
}];
WS(weakSelf)
self.mainTableView.mj_header = [TFRefreshHeader headerWithRefreshingBlock:^{
[weakSelf requestCatalogWithDown:NO];
}];
self.mainTableView.mj_footer = [TFRefreshFooter footerWithRefreshingBlock:^{
[weakSelf requestCatalogWithDown:YES];
}];
TFCatalogListModel *list = self.dataSourceArray.firstObject;
if ([list.previou_chapter isEqualToString:@"0"]) {
[self.mainTableView hideRefreshHeader];
}
list = self.dataSourceArray.lastObject;
if ([list.next_chapter isEqualToString:@"0"]) {
[self.mainTableView hideRefreshFooter];
}
if (self.dataSourceArray.count > 0) {
[self.mainTableView xtfei_hideEmptyView];
} else {
[self.mainTableView xtfei_showEmptyView];
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.dataSourceArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
TFNovelCatalogueViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"WXBookDirectoryTableViewCell" forIndexPath:indexPath];
TFCatalogListModel *t_model = [self.dataSourceArray objectOrNilAtIndex:indexPath.row];
cell.hiddenEndLine = (indexPath.row == self.dataSourceArray.count - 1);
if ([self.purchasedChapters containsObject:t_model.chapter_id]) {
t_model.preview = NO;
[self.purchasedChapters removeObject:t_model.chapter_id];
}
cell.chapterModel = t_model;
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 44;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
WS(weakSelf)
self.selectedIndexPath = indexPath;
NSInteger chapterIndex = indexPath.row;
// if (self.isReverseOrder) {
// chapterIndex = self.dataSourceArray.count - 1 - chapterIndex;
// }
TFCatalogListModel *t_model = self.dataSourceArray[chapterIndex];
[[TFReaderSettingHelper sharedManager] setLocationMemoryOfChapterIndex:t_model.display_order pagerIndex:0 book_id:[self.book_id integerValue]];
[TFReaderBookManager sharedManager].currentChapterIndex = t_model.display_order;
[TFReaderBookManager sharedManager].currentPagerIndex = 0;
if (self.isReader) {
UIViewController *vc = nil;
for (UIViewController *obj in self.navigationController.viewControllers) {
if ([obj isKindOfClass:TFReadNovelViewController.class]) {
vc = obj;
break;
}
}
if (vc) {
[[NSNotificationCenter defaultCenter] postNotificationName:NSNotification_Retry_Chapter object:nil];
[self.navigationController popToViewController:vc animated:YES];
} else {
[self.navigationController popViewControllerAnimated:YES];
}
} else {
if (self.isBookDetailPush) {
TFReadNovelViewController *vc = [[TFReadNovelViewController alloc] init];
vc.book_id = [self.book_id integerValue];
vc.bookModel = self.bookModel;
[self.navigationController pushViewController:vc animated:YES];
} else {
[[NSNotificationCenter defaultCenter] postNotificationName:NSNotification_Retry_Chapter object:nil];
[weakSelf.navigationController popViewControllerAnimated:YES];
}
}
dispatch_async(dispatch_get_main_queue(), ^{
[tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:NO];
});
}
//section头部间距
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return kHalfMargin;
}
//section头部视图
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView *view = [[UIView alloc] init];
view.backgroundColor = [UIColor clearColor];
return view;
}
- (void)orderChapter:(UIButton *)sender {
if (!self.isReverseOrder) {
[sender setImage:[UIImage imageNamed:@"book_directory_reverse"] forState:UIControlStateNormal];
self.isReverseOrder = YES;
} else {
[sender setImage:[UIImage imageNamed:@"book_directory_order"] forState:UIControlStateNormal];
self.isReverseOrder = NO;
}
if (![TFNetworkManager networkingStatus]) {
self.dataSourceArray = [[[self.dataSourceArray reverseObjectEnumerator] allObjects] mutableCopy];
[self.mainTableView reloadData];
return;
}
NSDictionary *params = @{
@"book_id" : self.book_id,
@"order_by" : self.isReverseOrder ? @(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.dataSourceArray removeAllObjects];
[weakSelf.dataSourceArray addObjectsFromArray:t_model.list];
[weakSelf.mainTableView reloadData];
if (@available(iOS 11.0, *)) {
[weakSelf.mainTableView performBatchUpdates:nil completion:^(BOOL finished) {
[weakSelf.mainTableView scrollToTopAnimated:NO];
}];
} else {
dispatch_async(dispatch_get_main_queue(), ^{
[weakSelf.mainTableView scrollToTopAnimated:NO];
});
}
[weakSelf.mainTableView xtfei_endLoading];
[weakSelf.mainTableView hideRefreshHeader];
[weakSelf.mainTableView showRefreshFooter];
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
[weakSelf.mainTableView xtfei_endLoading];
}];
}
// isDownYES 往下翻页,NO 往上翻页
- (void)requestCatalogWithDown:(BOOL)isDown
{
if (![TFNetworkManager networkingStatus]) {
[self.mainTableView endRefreshing];
return;
}
// 判断目录是不是倒序展示
if (self.isReverseOrder) {
isDown = !isDown;
}
// 章节id
NSString *chapter_id;
// 翻页方式
NSString *scrollType = isDown ? @"1" : @"2";
if (first) {// 判断是不是首次进入目录页面
if (self.dataSourceArray.count > 0) {
NSArray<TFCatalogListModel *> *list = self.dataSourceArray;
chapter_id = list.lastObject.next_chapter;
if ([chapter_id isEqualToString:@"0"]) {
[self.mainTableView endRefreshing];
[self.mainTableView hideRefreshFooter];
return;
}
} else {
chapter_id = [NSString stringWithFormat:@"%zd", [[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeNovel] getReadingRecordChapter_idWithProduction_id:[self.book_id integerValue]]];
}
[self requestCatalogWithScrollType:scrollType chapter_id:chapter_id];
return;
}
// 获取正确的章节id
NSArray<TFCatalogListModel *> *list = self.dataSourceArray;
if (isDown && self.isReverseOrder) {// 往下翻页,倒序
chapter_id = list.firstObject.next_chapter;
}
if (isDown && !self.isReverseOrder) {// 往下翻页,正序
chapter_id = list.lastObject.next_chapter;
}
if (!isDown && self.isReverseOrder) {// 往上翻页,倒序
chapter_id = list.lastObject.previou_chapter;
}
if (!isDown && !self.isReverseOrder) {// 往上翻页,正序
chapter_id = list.firstObject.previou_chapter;
}
if ([chapter_id isEqualToString:@"0"]) {
[self.mainTableView endRefreshing];
if (isDown) {
[self.mainTableView hideRefreshFooter];
} else {
[self.mainTableView hideRefreshHeader];
}
return;
}
[self requestCatalogWithScrollType:scrollType chapter_id:chapter_id];
}
// scrollType 1:向下加载;2:向上加载
- (void)requestCatalogWithScrollType:(NSString *)scrollType chapter_id:(NSString *)chapter_id {
if (!self.book_id || !chapter_id) {
if (self.dataSourceArray.count > 0) {
[self.mainTableView xtfei_hideEmptyView];
} else {
[self.mainTableView xtfei_showEmptyView];
}
[self.mainTableView endRefreshing];
return;
}
NSDictionary *params = @{
@"book_id" : self.book_id,
@"chapter_id" : chapter_id,
@"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) {
[weakSelf.mainTableView endRefreshing];
if (isSuccess) {
BOOL isDown = [scrollType isEqualToString:@"1"];
if (isDown && t_model.list.count == 1 && weakSelf.dataSourceArray.count == 0) {
[weakSelf requestCatalogWithScrollType:@"2" chapter_id:chapter_id];
return;
}
[weakSelf updateTableViewWithList:t_model.list isDown:isDown firstRequest:weakSelf.firstRequest];
weakSelf.firstRequest = YES;
// 隐藏上拉/下拉刷新控件
if (isDown && self.isReverseOrder) {// 往下翻页,倒序
if ([t_model.list.lastObject.next_chapter isEqualToString:@"0"]) {
[weakSelf.mainTableView hideRefreshHeader];
}
}
if (isDown && !self.isReverseOrder) {// 往下翻页,正序
if ([t_model.list.lastObject.next_chapter isEqualToString:@"0"]) {
[weakSelf.mainTableView hideRefreshFooter];
}
}
if (!isDown && self.isReverseOrder) {// 往上翻页,倒序
if ([t_model.list.firstObject.previou_chapter isEqualToString:@"0"]) {
[weakSelf.mainTableView hideRefreshFooter];
}
}
if (!isDown && !self.isReverseOrder) {// 往上翻页,正序
if ([t_model.list.firstObject.previou_chapter isEqualToString:@"0"]) {
[weakSelf.mainTableView hideRefreshHeader];
}
}
} else {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:requestModel.msg];
}
if (weakSelf.dataSourceArray.count > 0) {
[weakSelf.mainTableView xtfei_hideEmptyView];
} else {
[weakSelf.mainTableView xtfei_showEmptyView];
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
[TFPromptManager showPromptWithError:error defaultText:nil];
[weakSelf.mainTableView endRefreshing];
if (weakSelf.dataSourceArray.count > 0) {
[weakSelf.mainTableView xtfei_hideEmptyView];
} else {
[weakSelf.mainTableView xtfei_showEmptyView];
}
}];
}
// 更新tableView
- (void)updateTableViewWithList:(NSArray<TFCatalogListModel *> *)list isDown:(BOOL)isDown firstRequest:(BOOL)firstRequest {
NSMutableArray<NSIndexPath *> *pathArr = [NSMutableArray array];
// 刷新前的数据个数
NSUInteger oldCount = self.dataSourceArray.count;
// 填充数据
if (isDown && self.isReverseOrder) {// 往下翻页,倒序
list = list.reverseObjectEnumerator.allObjects;
[self.dataSourceArray insertObjects:list atIndex:0];
for (NSUInteger i = 0; i < list.count; i++) {
[pathArr addObject:[NSIndexPath indexPathForRow:i inSection:0]];
}
}
if (isDown && !self.isReverseOrder) {// 往下翻页,正序
[self.dataSourceArray addObjectsFromArray:list];
for (NSUInteger i = oldCount; i < self.dataSourceArray.count; i++) {
[pathArr addObject:[NSIndexPath indexPathForRow:i inSection:0]];
}
}
if (!isDown && self.isReverseOrder) {// 往上翻页,倒序
list = list.reverseObjectEnumerator.allObjects;
[self.dataSourceArray addObjectsFromArray:list];
for (NSUInteger i = oldCount; i < self.dataSourceArray.count; i++) {
[pathArr addObject:[NSIndexPath indexPathForRow:i inSection:0]];
}
}
if (!isDown && !self.isReverseOrder) {// 往上翻页,正序
[self.dataSourceArray insertObjects:list atIndex:0];
for (NSUInteger i = 0; i < list.count; i++) {
[pathArr addObject:[NSIndexPath indexPathForRow:i inSection:0]];
}
}
self.bookModel.list = self.dataSourceArray;
// 判断是不是第一次刷新
if (self.mainTableView.visibleCells.count == 0) {
[self.mainTableView reloadData];
NSInteger chapter_id = [[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeNovel] getReadingRecordChapter_idWithProduction_id:[self.book_id integerValue]];
NSInteger __block index = -1;
[self.dataSourceArray enumerateObjectsUsingBlock:^(TFCatalogListModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if ([obj.chapter_id integerValue] == chapter_id) {
index = idx;
*stop = YES;
}
}];
dispatch_async(dispatch_get_main_queue(), ^{
if (index != -1) {
[self.mainTableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:index inSection:0] animated:NO scrollPosition:UITableViewScrollPositionTop];
}
});
if (isDown == NO) {
dispatch_async(dispatch_get_main_queue(), ^{
if ((NSInteger)self.dataSourceArray.count - 2 >= 0) {
[self.mainTableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:self.dataSourceArray.count - 2 inSection:0] animated:NO scrollPosition:UITableViewScrollPositionBottom];
}
});
}
return;
}
[UIView performWithoutAnimation:^{
[self.mainTableView insertRowsAtIndexPaths:pathArr withRowAnimation:UITableViewRowAnimationNone];
}];
if (isDown && self.isReverseOrder) {// 往下翻页,倒序
[self.mainTableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:list.count inSection:0] animated:NO scrollPosition:UITableViewScrollPositionTop];
}
if (isDown && !self.isReverseOrder) {// 往下翻页,正序
[self.mainTableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:oldCount inSection:0] animated:NO scrollPosition:UITableViewScrollPositionBottom];
}
if (!isDown && self.isReverseOrder) {// 往上翻页,倒序
[self.mainTableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:oldCount inSection:0] animated:NO scrollPosition:UITableViewScrollPositionBottom];
}
if (!isDown && !self.isReverseOrder) {// 往上翻页,正序
[self.mainTableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:list.count inSection:0] animated:NO scrollPosition:UITableViewScrollPositionTop];
}
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
@end
@@ -0,0 +1,21 @@
//
// TFNovelBookMarkViewCell.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/15.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@class TFBookMarkModel;
@interface TFNovelBookMarkViewCell : UITableViewCell
@property (nonatomic ,strong) TFBookMarkModel *bookMarkModel;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,83 @@
//
// TFNovelBookMarkViewCell.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/15.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFNovelBookMarkViewCell.h"
#import "NSObject+Observer.h"
#import "TFBookMarkModel.h"
@interface TFNovelBookMarkViewCell ()
@end
@implementation TFNovelBookMarkViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
self.selectionStyle = UITableViewCellSelectionStyleNone;
[self createSubviews];
}
return self;
}
- (void)createSubviews
{
UILabel *titleLabel = [[UILabel alloc] init];
titleLabel.font = kFont14;
titleLabel.textColor = kBlackColor;
[self.contentView addSubview:titleLabel];
[titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.contentView).offset(kMargin);
make.left.equalTo(self.contentView).offset(kMoreHalfMargin);
}];
UILabel *timeLabel = [[UILabel alloc] init];
timeLabel.font = kFont11;
timeLabel.textColor = kGrayTextColor;
timeLabel.textAlignment = NSTextAlignmentRight;
[self.contentView addSubview:timeLabel];
[timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(titleLabel);
make.right.equalTo(self.contentView).offset(-kMoreHalfMargin);
}];
[titleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(timeLabel.mas_left).offset(-kMargin);
}];
UILabel *descLabel = [[UILabel alloc] init];
descLabel.numberOfLines = 2;
descLabel.font = kFont12;
descLabel.textColor = kGrayTextColor;
[self.contentView addSubview:descLabel];
[descLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(titleLabel.mas_bottom).offset(13);
make.left.equalTo(titleLabel);
make.right.equalTo(self.contentView).offset(-25.0);
}];
UIView *splitLine = [[UIView alloc] init];
splitLine.backgroundColor = kGrayLineColor;
[self.contentView addSubview:splitLine];
[splitLine mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(kCellLineHeight);
make.left.right.bottom.equalTo(self.contentView);
make.top.equalTo(descLabel.mas_bottom).offset(kMoreHalfMargin).priorityLow();
}];
[self addObserver:KEY_PATH(self, bookMarkModel) complete:^(TFNovelBookMarkViewCell * _Nonnull obj, TFBookMarkModel * _Nullable oldVal, TFBookMarkModel * _Nullable newVal) {
titleLabel.text = newVal.chapterTitle ?: @"";
timeLabel.text = [TFUtilsHelper dateStringWithTimestamp:newVal.timestamp] ?: @"";
if ([[newVal.pageContent stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] isEqualToString:@"\U0000fffc"]) {
descLabel.text = TFLocalizedString(@"广告页");
} else {
descLabel.text = newVal.pageContent ?: @"";
}
}];
}
@end
@@ -0,0 +1,19 @@
//
// TFNovelCatalogueViewCell.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/15.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@class TFCatalogListModel;
@interface TFNovelCatalogueViewCell : TFBasicTableViewCell
@property (nonatomic ,strong) TFCatalogListModel *chapterModel;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,95 @@
//
// TFNovelCatalogueViewCell.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/15.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFNovelCatalogueViewCell.h"
#import "TFCatalogModel.h"
#import "TFReadRecordManager.h"
@interface TFNovelCatalogueViewCell ()
{
UILabel *chapterNameLabel;
#if TF_Super_Member_Mode && TF_Recharge_Mode
UIImageView *lockIcon;
#endif
}
@end
@implementation TFNovelCatalogueViewCell
- (void)createSubviews
{
[super createSubviews];
self.selectionStyle = UITableViewCellSelectionStyleNone;
#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(self.contentView.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);
}];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeLock:) name:Notification_ChangeLock object:nil];
}
- (void)changeLock:(NSNotification *)noti
{
if ([noti.object isEqualToString:self.chapterModel.chapter_id]) {
self.chapterModel.preview = NO;
#if TF_Super_Member_Mode && TF_Recharge_Mode
lockIcon.hidden = YES;
#endif
}
}
- (void)setChapterModel:(TFCatalogListModel *)chapterModel
{
_chapterModel = chapterModel;
chapterNameLabel.text = chapterModel.title?:@"";
#if TF_Super_Member_Mode && TF_Recharge_Mode
if (chapterModel.isPreview == 1) {
lockIcon.hidden = NO;
} else {
lockIcon.hidden = YES;
}
#endif
if ([[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeNovel] getReadingRecordChapter_idWithProduction_id:[chapterModel.book_id integerValue]] == [chapterModel.chapter_id integerValue]) {
chapterNameLabel.textColor = kMainColor;
} else if ([[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeNovel] chapterHasReadedWithProduction_id:[chapterModel.book_id integerValue] chapter_id:[chapterModel.chapter_id integerValue]]) {
chapterNameLabel.textColor = kGrayTextColor;
} else {
chapterNameLabel.textColor = kBlackColor;
}
}
@end