You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
809 lines
34 KiB
809 lines
34 KiB
4 years ago
|
//
|
||
|
// 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
|