小说绘上架版本
This commit is contained in:
+22
@@ -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
|
||||
+808
@@ -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
|
||||
+20
@@ -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
|
||||
+344
@@ -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
|
||||
Reference in New Issue
Block a user