小说绘上架版本

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,26 @@
//
// TFAdvertisementManager.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/23.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFAdvertisementBasicView.h"
NS_ASSUME_NONNULL_BEGIN
@interface TFAdvertisementManager : TFAdvertisementBasicView
// 广告关闭时的回调
@property (nonatomic ,copy) void(^closeBlock)(void);
// 广告当前时间戳
@property (nonatomic ,assign ,class) NSInteger adTimestamp;
// 是否需要展示指定广告
+ (BOOL)whetherToLoadAdsWithAdvertisementType:(TFAdvertisementType)type advertisementPosition:(TFAdvertisementPosition)position;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,162 @@
//
// TFAdvertisementManager.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/23.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFAdvertisementManager.h"
#import "TFAdvertisementWebView.h"
#import "AppDelegate.h"
#if TF_Enable_Third_Party_Ad
#import <BUAdSDK/BUBannerAdView.h>
#endif
#import "WXYZ_ADPangolinView.h"
@interface TFAdvertisementManager ()
@property (nonatomic ,weak) TFAdvertisementWebView *webView;
@property (nonatomic ,weak) WXYZ_ADPangolinView *adPangolinView;
@end
@implementation TFAdvertisementManager
+ (BOOL)whetherToLoadAdsWithAdvertisementType:(TFAdvertisementType)type advertisementPosition:(TFAdvertisementPosition)position
{
AppDelegate *appDelegate = (AppDelegate *)kRCodeSync([[UIApplication sharedApplication] delegate]);
switch (position) {
case TFAdvertisementPositionEnd: {
if (type == TFAdvertisementTypeNovel) {
return appDelegate.checkSettingModel.ad_status_setting.chapter_read_end;
} else if (type == TFAdvertisementTypeComic) {
return appDelegate.checkSettingModel.ad_status_setting.comic_read_end;
} else {
return NO;
}
}
break;
case TFAdvertisementPositionBottom: {
if (type == TFAdvertisementTypeNovel) {
return appDelegate.checkSettingModel.ad_status_setting.chapter_read_bottom;
} else {
return NO;
}
}
break;
default:
return YES;
}
}
- (instancetype)initWithFrame:(CGRect)frame advertisementType:(TFAdvertisementType)type advertisementPosition:(TFAdvertisementPosition)position
{
if (![self.class whetherToLoadAdsWithAdvertisementType:type advertisementPosition:position]) return nil;
if (self = [super initWithFrame:frame advertisementType:type advertisementPosition:position]) {
[self initialize];
[self netRequest];
}
return self;
}
- (void)setAdvertModel:(TFAdvertModel *)advertModel
{
[super setAdvertModel:advertModel];
if (advertModel.ad_type == 1) { // 内部广告
self.webView.advertModel = advertModel;
self.webView.hidden = NO;
self.adPangolinView.hidden = YES;
return;
}
if (advertModel.ad_type == 2) { // 穿山甲广告
self.adPangolinView.advertModel = advertModel;
self.adPangolinView.hidden = NO;
self.webView.hidden = YES;
return;
}
}
- (void)setCloseBlock:(void (^)(void))closeBlock
{
_closeBlock = closeBlock;
self.adPangolinView.closeBlock = closeBlock;
}
- (void)initialize
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(saveTimestamp) name:UIApplicationWillResignActiveNotification object:nil];
}
- (void)createSubviews
{
TFAdvertisementWebView *webView = [[TFAdvertisementWebView alloc] initWithFrame:self.bounds advertisementType:self.type advertisementPosition:self.position];
webView.hidden = YES;
self.webView = webView;
[self addSubview:webView];
[webView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self);
}];
WXYZ_ADPangolinView *adPangolinView = [[WXYZ_ADPangolinView alloc] initWithFrame:self.bounds advertisementType:self.type advertisementPosition:self.position];
adPangolinView.hidden = YES;
self.adPangolinView = adPangolinView;
[self addSubview:adPangolinView];
[adPangolinView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self);
}];
}
- (void)netRequest
{
if (self.position == 0 || self.type == 0) return;
WS(weakSelf)
[super requestAdvertisementWithType:self.type advertisementPostion:self.position complete:^(TFAdvertModel * _Nullable adModel, NSString * _Nonnull msg) {
if (adModel) {
_adTimestamp = [adModel.timestamp integerValue];
weakSelf.advertModel = adModel;
} else {
weakSelf.frame = CGRectZero;
}
}];
}
- (void)dealloc
{
[self saveTimestamp];
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
static NSInteger _adTimestamp;
+ (NSInteger)adTimestamp
{
if (!_adTimestamp) {
_adTimestamp = [[NSUserDefaults standardUserDefaults] integerForKey:TF_Reader_Ad_Timestamp];
}
return _adTimestamp;
}
+ (void)setAdTimestamp:(NSInteger)adTimestamp
{
_adTimestamp = adTimestamp;
}
- (void)saveTimestamp
{
[[NSUserDefaults standardUserDefaults] setInteger:_adTimestamp forKey:TF_Reader_Ad_Timestamp];
}
@end
@@ -0,0 +1,18 @@
//
// TFAdvertisementWebView.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/23.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFAdvertisementBasicView.h"
NS_ASSUME_NONNULL_BEGIN
@interface TFAdvertisementWebView : TFAdvertisementBasicView
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,153 @@
//
// TFAdvertisementWebView.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/23.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFAdvertisementWebView.h"
#import "TFWebViewController.h"
#import "TFReaderSettingHelper.h"
#import "AppDelegate.h"
#import "UIView+LayoutCallback.h"
#import "WXYZ_ADPangolinVideo.h"
@interface TFAdvertisementWebView ()
@property (nonatomic ,weak) YYAnimatedImageView *webImageView;
@property (nonatomic ,weak) UILabel *titleLabel;
@property (nonatomic ,weak) UILabel *subtitle;
@end
@implementation TFAdvertisementWebView
- (instancetype)initWithFrame:(CGRect)frame advertisementType:(TFAdvertisementType)type advertisementPosition:(TFAdvertisementPosition)position
{
if (self = [super initWithFrame:frame advertisementType:type advertisementPosition:position]) {
[self createSubViews];
}
return self;
}
- (void)createSubViews
{
self.backgroundColor = [UIColor clearColor];
YYAnimatedImageView *webImageView = [[YYAnimatedImageView alloc] init];
self.webImageView = webImageView;
webImageView.contentMode = UIViewContentModeScaleAspectFill;
webImageView.layer.masksToBounds = YES;
webImageView.userInteractionEnabled = YES;
[webImageView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickAd)]];
[self addSubview:webImageView];
if (self.position == TFAdvertisementPositionEnd && self.type == TFAdvertisementTypeNovel) {
UILabel *subtitle = [[UILabel alloc] init];
self.subtitle = subtitle;
subtitle.backgroundColor = [UIColor clearColor];
UIColor *textColor = [TFReaderSettingHelper sharedManager].getReaderTextColor;
subtitle.textColor = textColor;
subtitle.font = kFont14;
AppDelegate *delegate = (AppDelegate *)kRCodeSync([UIApplication sharedApplication].delegate);
subtitle.text = [NSString stringWithFormat:@"%@%@", delegate.checkSettingModel.ad_status_setting.video_ad_text ?: @"", @">"];
[self addSubview:subtitle];
subtitle.frameBlock = ^(UIView * _Nonnull view) {
[view addBorderLineWithBorderWidth:1.0 borderColor:textColor cornerRadius:0.0 borderType:UIBorderSideTypeBottom];
};
subtitle.userInteractionEnabled = YES;
[subtitle addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(watchVideo)]];
UILabel *titleLabel = [[UILabel alloc] init];
self.titleLabel = titleLabel;
titleLabel.backgroundColor = [UIColor clearColor];
titleLabel.text = TFLocalizedString(@"点击/滑动可继续阅读");
textColor = [textColor colorWithAlphaComponent:0.4];
titleLabel.textColor = textColor;
titleLabel.textAlignment = NSTextAlignmentCenter;
titleLabel.font = kFont17;
[self addSubview:titleLabel];
}
}
- (void)setAdvertModel:(TFAdvertModel *)advertModel
{
[super setAdvertModel:advertModel];
[self.webImageView setImageWithURL:[NSURL URLWithString:advertModel.ad_image ? : @""] placeholder:HoldImage options:YYWebImageOptionSetImageWithFadeAnimation completion:nil];
switch (self.position) {
case TFAdvertisementPositionNone: {
self.webImageView.layer.cornerRadius = 9.5;
[self.webImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self);
}];
}
break;
case TFAdvertisementPositionEnd: {
if (self.type == TFAdvertisementTypeNovel) {
self.titleLabel.hidden = NO;
AppDelegate *delegate = (AppDelegate *)kRCodeSync([UIApplication sharedApplication].delegate);
self.subtitle.hidden = !delegate.checkSettingModel.ad_status_setting.video_ad_switch;
}
self.webImageView.layer.cornerRadius = 12.5;
CGFloat scale = 1.0 / 1.2;
[self.webImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.center.width.equalTo(self);
make.height.equalTo(self.mas_width).multipliedBy(scale);
}];
[self.titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.webImageView.mas_bottom);
make.bottom.equalTo(self.subtitle.mas_top);
make.left.right.equalTo(self);
}];
[self.subtitle mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(self).offset(-kHalfMargin);
make.centerX.equalTo(self);
make.height.mas_equalTo(20);
}];
}
break;
default:
{
[self.webImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self);
}];
}
break;
}
}
- (void)clickAd
{
[super clickAd];
if (kObjectIsEmpty(self.advertModel.ad_skip_url)) {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:TFLocalizedString(@"链接错误,请联系客服")];
return;
}
if (self.advertModel.ad_url_type == 1) {
TFWebViewController *vc = [[TFWebViewController alloc] init];
vc.navTitle = self.advertModel.ad_title;
vc.URLString = self.advertModel.ad_skip_url;
vc.isPresentState = NO;
[[NSNotificationCenter defaultCenter] postNotificationName:NSNotification_Reader_Push object:nil];
[[TFViewHelper getCurrentNavigationController] pushViewController:vc animated:YES];
return;
}
if (self.advertModel.ad_url_type == 2) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:self.advertModel.ad_skip_url] options:@{} completionHandler:nil];
}
}
// 观看激励视频
- (void)watchVideo
{
WXYZ_ADPangolinVideo *video = [[WXYZ_ADPangolinVideo alloc] initWithFrame:CGRectZero advertisementType:self.type advertisementPosition:self.position];
// [video show];
}
@end
@@ -0,0 +1,54 @@
//
// TFAdvertisementBasicView.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/23.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
/*** 广告类型 ***/
typedef NS_ENUM(NSUInteger, TFAdvertisementType) {
TFAdvertisementTypeNone = 0, /*** 列表广告 ***/
TFAdvertisementTypeNovel = 1, /*** 小说广告 ***/
TFAdvertisementTypeComic = 2, /*** 漫画广告 ***/
};
/*** 广告位置 ***/
typedef NS_ENUM(NSUInteger, TFAdvertisementPosition) {
TFAdvertisementPositionNone = 0, /*** 列表广告 ***/
TFAdvertisementPositionEnd = 8, /*** 阅读器章节末尾广告 ***/
TFAdvertisementPositionBottom = 12, /*** 阅读器底部广告 ***/
TFAdvertisementPositionVideo = 13, /*** 激励视频广告 ***/
};
@interface TFAdvertisementBasicView : UIView
@property (nonatomic ,strong) TFAdvertModel *advertModel;
@property (nonatomic ,assign) TFAdvertisementPosition position;
@property (nonatomic ,assign) TFAdvertisementType type;
- (instancetype)initWithFrame:(CGRect)frame advertisementType:(TFAdvertisementType)type advertisementPosition:(TFAdvertisementPosition)position;
+ (instancetype)allocWithZone:(struct _NSZone *)zone UNAVAILABLE_ATTRIBUTE;
+ (instancetype)new UNAVAILABLE_ATTRIBUTE;
- (instancetype)init UNAVAILABLE_ATTRIBUTE;
- (instancetype)initWithFrame:(CGRect)frame UNAVAILABLE_ATTRIBUTE;
- (void)createSubviews;
// 广告点击
- (void)clickAd;
// 请求指定广告信息
- (void)requestAdvertisementWithType:(TFAdvertisementType)type advertisementPostion:(TFAdvertisementPosition)position complete:(void(^)(TFAdvertModel * _Nullable advertModel, NSString *msg))complete;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,52 @@
//
// TFAdvertisementBasicView.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/23.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFAdvertisementBasicView.h"
@implementation TFAdvertisementBasicView
- (instancetype)initWithFrame:(CGRect)frame advertisementType:(TFAdvertisementType)type advertisementPosition:(TFAdvertisementPosition)position
{
if (self = [super initWithFrame:frame]) {
self.type = type;
self.position = position;
[self createSubviews];
}
return self;
}
- (void)createSubviews
{
self.backgroundColor = kGrayViewColor;
}
- (void)clickAd
{
NSMutableDictionary *params = [NSMutableDictionary dictionary];
params[@"advert_id"] = [TFUtilsHelper formatStringWithInteger:self.advertModel.advert_id];
[TFNetworkTools POST:AdVert_Click parameters:params model:nil success:nil failure:nil];
}
- (void)requestAdvertisementWithType:(TFAdvertisementType)type advertisementPostion:(TFAdvertisementPosition)position complete:(void(^)(TFAdvertModel * _Nullable advertModel, NSString *msg))complete
{
NSMutableDictionary *params = [NSMutableDictionary dictionary];
params[@"type"] = @(type);
params[@"position"] = @(position);
[TFNetworkTools POST:Advert_Info parameters:params model:TFAdvertModel.class success:^(BOOL isSuccess, TFAdvertModel * _Nullable t_model, TFNetworkRequestModel * _Nonnull requestModel) {
if (isSuccess) {
!complete ?: complete(t_model, requestModel.msg ?: @"");
} else {
!complete ?: complete(nil, requestModel.msg ?: @"");
}
} failure:nil];
}
@end
@@ -0,0 +1,21 @@
//
// TFDiscoverComicAdvertisementCell.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 TFDiscoverComicAdvertisementCell : TFBasicTableViewCell
- (void)setAdModel:(TFAdvertModel * _Nonnull)adModel refresh:(BOOL)refresh;
@property (nonatomic ,weak) UITableView *mainTableView;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,100 @@
//
// TFDiscoverComicAdvertisementCell.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFDiscoverComicAdvertisementCell.h"
#import "TFAdvertisementManager.h"
@interface TFDiscoverComicAdvertisementCell ()
@property (nonatomic ,strong) TFAdvertModel *advertModel;
@property (nonatomic ,weak) TFAdvertisementManager *adView;
@property (nonatomic ,weak) UILabel *titleLabel;
@end
@implementation TFDiscoverComicAdvertisementCell
- (void)createSubviews
{
[super createSubviews];
TFAdvertisementManager *adView = [[TFAdvertisementManager alloc] initWithFrame:CGRectMake(kHalfMargin, kHalfMargin, SCREEN_WIDTH - kMargin, (SCREEN_WIDTH - 2 * kHalfMargin) / 2) advertisementType:TFAdvertisementTypeNone advertisementPosition:TFAdvertisementPositionNone];
self.adView = adView;
__weak typeof(adView) weakView = adView;
WS(weakSelf)
adView.closeBlock = ^{
[weakView mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(1.0);
make.top.equalTo(self.contentView);
}];
[weakSelf.mainTableView reloadData];
};
adView.userInteractionEnabled = YES;
adView.layer.cornerRadius = 8.0f;
[self.contentView addSubview:adView];
[adView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.contentView.mas_left).with.offset(kHalfMargin);
make.top.mas_equalTo(self.contentView.mas_top).with.offset(kHalfMargin);
make.width.mas_equalTo(SCREEN_WIDTH - kMargin);
make.height.mas_equalTo(kGeometricHeight(SCREEN_WIDTH - kMargin, 7, 4));
}];
UILabel *titleLabel = [[UILabel alloc] init];
self.titleLabel = titleLabel;
titleLabel.textColor = kBlackColor;
titleLabel.textAlignment = NSTextAlignmentLeft;
titleLabel.font = kMainFont;
[self.contentView addSubview:titleLabel];
[titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(kHalfMargin);
make.top.mas_equalTo(adView.mas_bottom).with.offset(kHalfMargin);
make.height.mas_equalTo(kMargin);
make.right.mas_equalTo(self.contentView.mas_right);
}];
UIView *splitLine = [[UIView alloc] init];
splitLine.backgroundColor = [UIColor clearColor];
[self.contentView addSubview:splitLine];
[splitLine mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(titleLabel.mas_bottom).priorityLow();
make.left.right.bottom.equalTo(self.contentView);
make.height.mas_equalTo(0.1);
}];
}
- (void)setAdModel:(TFAdvertModel * _Nonnull)adModel refresh:(BOOL)refresh
{
if (refresh || (adModel.advert_id != _advertModel.advert_id)) {
adModel.ad_width = CGRectGetWidth(self.contentView.bounds);
adModel.ad_height = CGRectGetHeight(self.contentView.bounds);
_advertModel = adModel;
self.adView.advertModel = adModel;
if (adModel.ad_type == 1) {
[self.adView mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo((SCREEN_WIDTH - 2 * kHalfMargin) / 2.0);
}];
} else {
[self.adView mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo((SCREEN_WIDTH - 2 * kHalfMargin) * 1.0 / 3.0);
}];
}
self.titleLabel.text = adModel.ad_title ?: @"";
[self.titleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
if (self.titleLabel.text.length == 0 || adModel.ad_type == 2) {
make.height.mas_equalTo(CGFLOAT_MIN);
} else {
make.height.mas_equalTo(kMargin);
}
}];
}
}
@end
@@ -0,0 +1,21 @@
//
// TFPublicAdvertisementViewCell.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/23.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface TFPublicAdvertisementViewCell : TFBasicTableViewCell
- (void)setAdModel:(TFAdvertModel * _Nonnull)adModel refresh:(BOOL)refresh;
@property (nonatomic ,weak) UITableView *mainTableView;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,63 @@
//
// TFPublicAdvertisementViewCell.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/23.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFPublicAdvertisementViewCell.h"
#import "TFWebViewController.h"
#import "TFAdvertisementManager.h"
@interface TFPublicAdvertisementViewCell ()
@property (nonatomic ,weak) TFAdvertisementManager *adView;
@property (nonatomic ,strong) TFAdvertModel *advertModel;
@end
@implementation TFPublicAdvertisementViewCell
- (void)createSubviews
{
[super createSubviews];
TFAdvertisementManager *adView = [[TFAdvertisementManager alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH - kMargin, kGeometricHeight(SCREEN_WIDTH - kMargin, 3, 1)) advertisementType:TFAdvertisementTypeNone advertisementPosition:TFAdvertisementPositionNone];
__weak typeof(adView) weakView = adView;
WS(weakSelf)
adView.closeBlock = ^{
[weakView mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(1.0);
}];
[weakSelf.mainTableView reloadData];
};
self.adView = adView;
[self.contentView addSubview:adView];
[adView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.contentView.mas_left).with.offset(kHalfMargin);
make.centerY.mas_equalTo(self.contentView.mas_centerY);
make.width.mas_equalTo(SCREEN_WIDTH - kMargin);
make.height.mas_equalTo(kGeometricHeight(SCREEN_WIDTH - kMargin, 3, 1));
make.bottom.mas_equalTo(self.contentView.mas_bottom).priorityLow();
}];
}
- (void)setAdModel:(TFAdvertModel *)adModel refresh:(BOOL)refresh
{
if (refresh || (adModel.advert_id != _advertModel.advert_id)) {
_advertModel = adModel;
self.adView.advertModel = adModel;
if (adModel.ad_width > 0 && adModel.ad_height > 0) {
CGFloat scale = (CGFloat)adModel.ad_height / adModel.ad_width;
[self.adView mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(CGRectGetWidth(self.adView.bounds) * scale);
}];
}
}
}
@end
@@ -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
@@ -0,0 +1,19 @@
//
// TFButton+TFExtension.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/22.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFButton.h"
NS_ASSUME_NONNULL_BEGIN
@interface TFButton (TFExtension)
+ (TFButton *)initWithFrame:(CGRect)frame btnTitle:(NSString *)title btnImageName:(NSString *)imageName backgroundColor:(UIColor *)backgroundColor btnTintColor:(UIColor *)tintColor btnStyle:(TFButtonIndicator)style cornerRadius:(CGFloat)cornerRadius target:(id)target action:(SEL)action;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,24 @@
//
// TFButton+TFExtension.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/22.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFButton+TFExtension.h"
@implementation TFButton (TFExtension)
+ (TFButton *)initWithFrame:(CGRect)frame btnTitle:(NSString *)title btnImageName:(NSString *)imageName backgroundColor:(UIColor *)backgroundColor btnTintColor:(UIColor *)tintColor btnStyle:(TFButtonIndicator)style cornerRadius:(CGFloat)cornerRadius target:(id)target action:(SEL)action
{
TFButton *btn = [[TFButton alloc] initWithFrame:frame buttonTitle:title buttonImageName:imageName buttonIndicator:style];
btn.buttonTintColor = tintColor;
btn.backgroundColor = backgroundColor;
btn.layer.cornerRadius = cornerRadius;
[btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
return btn;
}
@end
@@ -0,0 +1,39 @@
//
// TFCommentsModel.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/13.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@class TFCommentsListModel, TFPagingModel;
@interface TFCommentsModel : TFPagingModel
@property (nonatomic ,strong) NSArray<TFCommentsListModel *> *list;
@end
@interface TFCommentsListModel : NSObject
@property (nonatomic ,copy) NSString *avatar; //评论用户头像
@property (nonatomic ,assign) NSInteger comment_id; //评论id
@property (nonatomic ,assign) NSInteger uid; //评论用户uid
@property (nonatomic ,copy) NSString *time; //评论时间
@property (nonatomic ,copy) NSString *nickname; //评论人昵称
@property (nonatomic ,copy) NSString *content; //评论内容
@property (nonatomic ,assign) NSInteger like_num; //点赞数
@property (nonatomic ,copy) NSString *reply_info; //回复的评论内容
@property (nonatomic ,assign) NSInteger is_vip; //是否为VIP 0否 1是
@property (nonatomic ,assign) NSInteger comment_num; //评论数
@property (nonatomic ,copy) NSString *name_title; // 评论的书籍
@property (nonatomic ,assign) NSInteger reply_num; // 评论回复数
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,24 @@
//
// TFCommentsModel.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/13.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFCommentsModel.h"
@implementation TFCommentsModel
+ (NSDictionary<NSString *,id> *)modelContainerPropertyGenericClass
{
return @{@"list" : [TFCommentsListModel class]};
}
@end
@implementation TFCommentsListModel
@end
@@ -0,0 +1,23 @@
//
// TFCommentsViewCell.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/13.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <YYKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface TFCommentsViewCell : TFBasicTableViewCell
@property (nonatomic, strong) TFCommentsListModel *commentModel;
/// 预览列表分割线和正常列表不一样
- (void)setIsPreview:(BOOL)isPreview lastRow:(BOOL)lastRow;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,184 @@
//
// TFCommentsViewCell.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/13.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFCommentsViewCell.h"
@interface TFCommentsViewCell ()
@property (nonatomic ,strong) UIImageView *avatarView; // 头像
@property (nonatomic ,strong) UILabel *nicknameLabel; // 昵称
@property (nonatomic ,strong) UILabel *commentLabel; // 评论
@property (nonatomic ,strong) YYLabel *replyCommentLabel; // 二级评论
@property (nonatomic ,strong) UILabel *timeLabel; // 发布时间
@property (nonatomic ,strong) UIImageView *vipView;
@end
@implementation TFCommentsViewCell
- (void)createSubviews
{
[super createSubviews];
// 头像
self.avatarView = [[UIImageView alloc] initWithCornerRadiusAdvance:35.0f / 2 rectCornerType:UIRectCornerAllCorners];
[self.contentView addSubview:self.avatarView];
[self.avatarView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.contentView.mas_left).with.offset(kMargin);
make.top.mas_equalTo(self.contentView.mas_top).with.offset(kHalfMargin);
make.width.height.mas_equalTo(35.0f);
}];
// 昵称
self.nicknameLabel = [[UILabel alloc] init];
self.nicknameLabel.textColor = kGrayTextDeepColor;
self.nicknameLabel.font = kFont13;
self.nicknameLabel.textAlignment = NSTextAlignmentLeft;
[self.contentView addSubview:self.nicknameLabel];
[self.nicknameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.avatarView.mas_right).with.offset(kHalfMargin);
make.top.mas_equalTo(self.avatarView.mas_top);
make.width.mas_equalTo(200);
make.height.mas_equalTo(self.avatarView.mas_height).multipliedBy(0.6);
}];
self.timeLabel = [[UILabel alloc] init];
self.timeLabel.textAlignment = NSTextAlignmentLeft;
self.timeLabel.font = kFont10;
self.timeLabel.textColor = kGrayTextColor;
[self.contentView addSubview:self.timeLabel];
[self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.nicknameLabel.mas_left);
make.bottom.mas_equalTo(self.avatarView.mas_bottom);
make.right.mas_equalTo(self.contentView.mas_right);
make.height.mas_equalTo(self.avatarView.mas_height).multipliedBy(0.4);
}];
self.vipView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"public_vip_select"]];
self.vipView.hidden = YES;
[self addSubview:self.vipView];
[self.vipView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.nicknameLabel.mas_right);
make.centerY.mas_equalTo(self.nicknameLabel.mas_centerY);
make.height.mas_equalTo(10);
make.width.mas_equalTo(kGeometricWidth(10, 138, 48));
}];
// 二级评论
self.replyCommentLabel = [[YYLabel alloc] init];
self.replyCommentLabel.textAlignment = NSTextAlignmentLeft;
self.replyCommentLabel.textColor = kGrayTextDeepColor;
self.replyCommentLabel.font = kFont13;
self.replyCommentLabel.backgroundColor = kGrayViewColor;
self.replyCommentLabel.numberOfLines = 0;
self.replyCommentLabel.textContainerInset = UIEdgeInsetsMake(6, 5, 4, 5);
[self.contentView addSubview:self.replyCommentLabel];
[self.replyCommentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.nicknameLabel.mas_left);
make.top.mas_equalTo(self.avatarView.mas_bottom);
make.right.mas_equalTo(self.contentView.mas_right).with.offset(- kMargin);
make.height.mas_equalTo(CGFLOAT_MIN);
}];
// 评论
self.commentLabel = [[UILabel alloc] init];
self.commentLabel.textAlignment = NSTextAlignmentLeft;
self.commentLabel.font = kMainFont;
self.commentLabel.numberOfLines = 0;
self.commentLabel.textColor = kBlackColor;
[self.contentView addSubview:self.commentLabel];
[self.commentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.nicknameLabel.mas_left);
make.right.mas_equalTo(self.contentView.mas_right).with.offset(- kMargin);
make.top.mas_equalTo(self.replyCommentLabel.mas_bottom).with.offset(kHalfMargin);
make.height.mas_equalTo(200);
make.bottom.mas_equalTo(self.contentView.mas_bottom).with.offset(- kHalfMargin).priorityLow();
}];
}
- (void)setIsPreview:(BOOL)isPreview lastRow:(BOOL)lastRow
{
if (isPreview && !lastRow) {
[self.lineView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.commentLabel);
make.height.mas_equalTo(kCellLineHeight);
make.right.equalTo(self.contentView);
make.bottom.mas_equalTo(self.contentView.mas_bottom).with.offset(-kCellLineHeight);
}];
return;
}
if (isPreview && lastRow) {
[self.lineView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.avatarView);
make.height.mas_equalTo(kCellLineHeight);
make.right.equalTo(self.contentView);
make.bottom.mas_equalTo(self.contentView.mas_bottom).with.offset(-kCellLineHeight);
}];
return;
}
}
- (void)setCommentModel:(TFCommentsListModel *)commentModel
{
if (!commentModel) return;
_commentModel = commentModel;
self.timeLabel.text = [NSString stringWithFormat:@"%@",commentModel.time?:@""];
self.commentLabel.text = [NSString stringWithFormat:@"%@",commentModel.content?:@""];
if (commentModel.reply_info.length > 0) {
CGFloat replyHeight = [TFViewHelper getDynamicHeightWithLabelFont:kFont11 labelWidth:(SCREEN_WIDTH - 2 * kMargin - 35.0f - kHalfMargin) labelText:commentModel.reply_info ? : @""];
NSString *replyInfo = [NSString stringWithFormat:@"%@",commentModel.reply_info ? : @""];
NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
style.lineSpacing = 3;
NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:replyInfo];
[attrString addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, replyInfo.length)];
[attrString addAttribute:NSFontAttributeName value:kFont11 range:NSMakeRange(0, replyInfo.length)];
self.replyCommentLabel.attributedText = attrString;
[self.replyCommentLabel mas_updateConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.avatarView.mas_bottom).with.offset(kHalfMargin);
make.height.mas_equalTo(replyHeight);
}];
} else {
self.replyCommentLabel.attributedText = [[NSMutableAttributedString alloc] initWithString:@""];
[self.replyCommentLabel mas_updateConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.avatarView.mas_bottom);
make.height.mas_equalTo(CGFLOAT_MIN);
}];
}
[self.commentLabel mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo([TFViewHelper getDynamicHeightWithLabelFont:self.commentLabel.font labelWidth:(SCREEN_WIDTH - 35.0f - 2 * kMargin) labelText:self.commentLabel.text] - kHalfMargin);
}];
[self.avatarView setImageWithURL:[NSURL URLWithString:commentModel.avatar?:@""] placeholder:HoldUserAvatar options:YYWebImageOptionSetImageWithFadeAnimation completion:nil];
self.nicknameLabel.text = [NSString stringWithFormat:@"%@",commentModel.nickname?:@""];
[self.nicknameLabel mas_updateConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo([TFViewHelper getDynamicWidthWithLabel:self.nicknameLabel maxWidth:SCREEN_WIDTH - 35 - 2 * kMargin]);
}];
if (commentModel.is_vip == 1) {
self.vipView.hidden = NO;
} else {
self.vipView.hidden = YES;
}
}
@end
@@ -0,0 +1,25 @@
//
// TFCommentsViewController.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/13.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@class TFCommentsListModel;
typedef void(^CommentsSuccessBlock)(TFCommentsListModel *commentModel);
@interface TFCommentsViewController : TFBasicViewController
// 作品id
@property (nonatomic ,assign) NSInteger production_id;
@property (nonatomic ,assign) NSInteger chapter_id;
@property (nonatomic ,assign) NSInteger comment_id;
@property (nonatomic ,assign) BOOL pushFromReader;
@property (nonatomic ,copy) CommentsSuccessBlock commentsSuccessBlock;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,429 @@
//
// TFCommentsViewController.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/13.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFCommentsViewController.h"
#import "TFCommentsViewCell.h"
#import "CXTextView.h"
@interface TFCommentsViewController ()<UITableViewDelegate, UITableViewDataSource, UIGestureRecognizerDelegate, UITextViewDelegate>
@property (nonatomic ,strong) CXTextView *commentTextView;
@property (nonatomic ,strong) UIView *commentBottomView;
@property (nonatomic ,strong) TFCommentsModel *commentModel;
@property (nonatomic ,assign) CGFloat keyboardHeight;
@property (nonatomic ,assign) CGFloat commentViewHeight;
@end
@implementation TFCommentsViewController
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self setStatusBarDefaultStyle];
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self initialize];
[self createSubviews];
}
- (void)initialize
{
if (self.chapter_id > 0) {
if (self.productionType == TFProductionTypeComic) {
[self setNavigationBarTitle:TFLocalizedString(@"评论")];
} else {
[self setNavigationBarTitle:[NSString stringWithFormat:@"%@ (0)", TFLocalizedString(@"本章评论")]];
}
} else {
[self setNavigationBarTitle:[NSString stringWithFormat:@"%@ (0)", TFLocalizedString(@"书评")]];
}
self.commentViewHeight = 30;
NSArray *viewControllers = self.navigationController.viewControllers;
if (viewControllers.count <= 1) {
UIButton *closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
closeButton.frame = CGRectMake(kHalfMargin, PUB_NAVBAR_OFFSET + 20, 44, 44);
closeButton.imageEdgeInsets = UIEdgeInsetsMake(12, 12, 12, 12);
[closeButton setImage:[UIImage imageNamed:@"public_close"] forState:UIControlStateNormal];
[closeButton addTarget:self action:@selector(popViewController) forControlEvents:UIControlEventTouchUpInside];
[self setNavigationBarLeftButton:closeButton];
}
if (self.pushFromReader) {
id target = self.navigationController.interactivePopGestureRecognizer.delegate;
UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:target action:NSSelectorFromString(@"handleNavigationTransition:")];
panGesture.delegate = self;
[self.view addGestureRecognizer:panGesture];
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
}
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(netRequest) name:Notification_Reload_BookDetail object:nil];
// 增加监听,当键盘出现或改变时收出消息
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:)name:UIKeyboardWillShowNotification object:nil];
// 增加监听,当键退出时收出消息
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:)name:UIKeyboardWillHideNotification object:nil];
}
- (void)createSubviews
{
self.mainTableView.delegate = self;
self.mainTableView.dataSource = self;
[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 - PUB_TABBAR_HEIGHT);
}];
self.commentBottomView = [[UIView alloc] init];
self.commentBottomView.backgroundColor = kGrayViewColor;
[self.view addSubview:self.commentBottomView];
[self.commentBottomView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.bottom.mas_equalTo(self.view.mas_bottom);
make.width.mas_equalTo(self.view.mas_width);
make.height.mas_equalTo(PUB_TABBAR_HEIGHT);
}];
WS(weakSelf)
self.commentTextView = [[CXTextView alloc] initWithFrame:CGRectMake(kHalfMargin, kQuarterMargin, SCREEN_WIDTH - kMargin, 30)];
self.commentTextView.placeholder = TFLocalizedString(@"说点什么吧");
self.commentTextView.maxLine = 5;
self.commentTextView.maxLength = 200;
self.commentTextView.font = kMainFont;
self.commentTextView.backgroundColor = [UIColor whiteColor];
self.commentTextView.layer.cornerRadius = 15;
self.commentTextView.textHeightChangeBlock = ^(CGFloat height) {
SS(strongSelf)
strongSelf.commentViewHeight = height;
[weakSelf.commentBottomView mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(strongSelf.keyboardHeight + height + kHalfMargin);
}];
};
self.commentTextView.returnHandlerBlock = ^{
[weakSelf sendCommentNetRequest];
[[[UIApplication sharedApplication] keyWindow] endEditing:YES];
};
[self.commentBottomView addSubview:self.commentTextView];
self.mainTableView.mj_header = [TFRefreshHeader headerWithRefreshingBlock:^{
weakSelf.currentPageNumber = 1;
[weakSelf netRequest];
}];
[self.mainTableView.mj_header beginRefreshing];
self.mainTableView.mj_footer = [TFRefreshFooter footerWithRefreshingBlock:^{
weakSelf.currentPageNumber ++;
[weakSelf netRequest];
}];
[self setEmptyOnView:self.mainTableView title:TFLocalizedString(@"暂无评论内容") tapBlock:^{
}];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.dataSourceArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellID = @"TFCommentsViewCell";
TFCommentsViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
if (!cell) {
cell = [[TFCommentsViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
}
cell.commentModel = [self.dataSourceArray objectOrNilAtIndex:indexPath.row];
cell.hiddenEndLine = indexPath.row == self.dataSourceArray.count - 1;
if (self.chapter_id > 0) {
if (self.productionType == TFProductionTypeComic) {
[self setNavigationBarTitle:TFLocalizedString(@"评论")];
} else {
[self setNavigationBarTitle:[NSString stringWithFormat:@"%@ (%@)", TFLocalizedString(@"本章评论"), [TFUtilsHelper formatStringWithInteger:self.commentModel.total_count]]];
}
} else {
[self setNavigationBarTitle:[NSString stringWithFormat:@"%@ (%@)", TFLocalizedString(@"书评"), [TFUtilsHelper formatStringWithInteger:self.commentModel.total_count]]];
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
TFCommentsListModel *t_model = [self.dataSourceArray objectOrNilAtIndex:indexPath.row];
[self.commentTextView textViewBecomeFirstResponder];
self.comment_id = t_model.comment_id;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return CGFLOAT_MIN;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, CGFLOAT_MIN)];
view.backgroundColor = [UIColor clearColor];
return view;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return CGFLOAT_MIN;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, CGFLOAT_MIN)];
view.backgroundColor = [UIColor clearColor];
return view;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if (scrollView == self.mainTableView) {
[[[UIApplication sharedApplication] keyWindow] endEditing:YES];
}
}
- (void)setComment_id:(NSInteger)comment_id
{
_comment_id = comment_id;
[self resetCommentTextViewPlaceHolder];
}
- (void)resetCommentTextViewPlaceHolder
{
if (!self.dataSourceArray || self.dataSourceArray.count == 0) {
return;
}
for (TFCommentsListModel *t_model in self.dataSourceArray) {
if (t_model.comment_id == self.comment_id) {
self.commentTextView.placeholder = [NSString stringWithFormat:@"%@ @%@", TFLocalizedString(@"回复"), [TFUtilsHelper formatStringWithObject:t_model.nickname]];
break;
}
}
}
// 当键盘出现或改变时调用
- (void)keyboardWillShow:(NSNotification *)notification
{
// 获取键盘的高度
self.keyboardHeight = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size.height;
[self.commentBottomView mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(self.keyboardHeight + self.commentViewHeight + kHalfMargin + kQuarterMargin);
}];
[self.commentBottomView.superview layoutIfNeeded];
}
// 当键退出时调用
- (void)keyboardWillHide:(NSNotification *)notification
{
self.keyboardHeight = PUB_TABBAR_OFFSET;
[self.commentBottomView mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(self.commentViewHeight + PUB_TABBAR_OFFSET + (PUB_TABBAR_HEIGHT - PUB_TABBAR_OFFSET - 30));
}];
[self.commentBottomView.superview layoutIfNeeded];
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
if (![self.commentBottomView pointInside:[self.commentBottomView convertPoint:[[touches anyObject] locationInView:self.view] fromView:self.view] withEvent:event]) {
[[[UIApplication sharedApplication] keyWindow] endEditing:YES];
}
}
- (void)netRequest
{
NSString *url = @"";
NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
switch (self.productionType) {
case TFProductionTypeNovel:
url = Book_Comment_List;
parameters[@"book_id"] = [TFUtilsHelper formatStringWithInteger:self.production_id] ? : @"";
parameters[@"page_num"] = [TFUtilsHelper formatStringWithInteger:self.currentPageNumber];
break;
case TFProductionTypeComic:
url = Comic_Comment_List;
parameters[@"comic_id"] = [TFUtilsHelper formatStringWithInteger:self.production_id] ? : @"";
parameters[@"page_num"] = [TFUtilsHelper formatStringWithInteger:self.currentPageNumber];
break;
case TFProductionTypeAudio:
url = Audio_Comment_List;
parameters[@"audio_id"] = [TFUtilsHelper formatStringWithInteger:self.production_id] ? : @"";
parameters[@"page_num"] = [TFUtilsHelper formatStringWithInteger:self.currentPageNumber];
break;
default:
break;
}
if (self.chapter_id > 0) {
[parameters setObject:[TFUtilsHelper formatStringWithInteger:self.chapter_id] ? : @"" forKey:@"chapter_id"];
}
WS(weakSelf)
[TFNetworkTools POST:url parameters:parameters model:TFCommentsModel.class success:^(BOOL isSuccess, TFCommentsModel *_Nullable t_model, TFNetworkRequestModel *requestModel) {
[weakSelf.mainTableView endRefreshing];
if (isSuccess) {
if (weakSelf.currentPageNumber == 1) {
[weakSelf.mainTableView showRefreshFooter];
[weakSelf.dataSourceArray removeAllObjects];
weakSelf.dataSourceArray = [NSMutableArray arrayWithArray:t_model.list];
} else {
[weakSelf.dataSourceArray addObjectsFromArray:t_model.list];
}
if (t_model.total_page <= t_model.current_page) {
[weakSelf.mainTableView hideRefreshFooter];
}
[weakSelf resetCommentTextViewPlaceHolder];
weakSelf.commentModel = t_model;
} else {
[weakSelf.mainTableView hideRefreshFooter];
}
[weakSelf.mainTableView reloadData];
[weakSelf.mainTableView xtfei_endLoading];
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
[weakSelf.mainTableView endRefreshing];
[weakSelf.mainTableView xtfei_endLoading];
[weakSelf.mainTableView hideRefreshFooter];
[TFPromptManager showPromptWithError:error defaultText:nil];
}];
}
- (void)sendCommentNetRequest
{
if (!TFUserInfoManager.isLogin) {
TFAlertView *alert = [[TFAlertView alloc] init];
alert.alertDetailContent = TFLocalizedString(@"登录后才可以进行评论");
alert.confirmTitle = TFLocalizedString(@"去登录");
alert.cancelTitle = TFLocalizedString(@"暂不");
alert.confirmButtonClickBlock = ^{
[TFLoginOptionsViewController presentLoginView:nil];
};
[alert showAlertView];
return;
}
if ([self.commentTextView.text isEqualToString:@""]) {
return;
}
NSString *t_text = self.commentTextView.text;
self.commentTextView.text = @"";
NSString *url = @"";
NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
switch (self.productionType) {
case TFProductionTypeNovel:
url = Book_Comment_Post;
parameters = [NSMutableDictionary dictionaryWithDictionary:@{@"book_id":[TFUtilsHelper formatStringWithInteger:self.production_id] ? : @"", @"content":t_text}];
break;
case TFProductionTypeComic:
url = Comic_Comment_Post;
parameters = [NSMutableDictionary dictionaryWithDictionary:@{@"comic_id":[TFUtilsHelper formatStringWithInteger:self.production_id] ? : @"", @"content":t_text}];
break;
case TFProductionTypeAudio:
url = Audio_Comment_Post;
parameters = [NSMutableDictionary dictionaryWithDictionary:@{@"audio_id":[TFUtilsHelper formatStringWithInteger:self.production_id] ? : @"", @"content":t_text}];
break;
default:
break;
}
if (self.chapter_id > 0) {
[parameters setObject:[TFUtilsHelper formatStringWithInteger:self.chapter_id] forKey:@"chapter_id"];
}
if (self.comment_id && self.comment_id != 0) {
[parameters setObject:[TFUtilsHelper formatStringWithInteger:self.comment_id] forKey:@"comment_id"];
}
WS(weakSelf)
[TFNetworkTools POST:url parameters:parameters model:TFCommentsListModel.class success:^(BOOL isSuccess, TFCommentsListModel *_Nullable t_model, TFNetworkRequestModel *requestModel) {
if (isSuccess) {
weakSelf.comment_id = 0;
weakSelf.commentTextView.placeholder = TFLocalizedString(@"说点什么吧");
[TFPromptManager showPromptViewWithStatus:TFPromptStatusSuccess promptTitle:TFLocalizedString(@"评论成功")];
!weakSelf.commentsSuccessBlock ?: weakSelf.commentsSuccessBlock(t_model);
if (t_model) {
[weakSelf.dataSourceArray insertObject:t_model atIndex:0];
}
weakSelf.commentModel.total_count ++;
[[NSNotificationCenter defaultCenter] postNotificationName:@"changeComment" object:[NSString stringWithFormat:@"%zd", weakSelf.commentModel.total_count]];
[weakSelf.mainTableView reloadData];
[weakSelf.mainTableView xtfei_endLoading];
} else if (Compare_Json_isEqualTo(requestModel.code, 315)) {
weakSelf.comment_id = 0;
weakSelf.commentTextView.placeholder = TFLocalizedString(@"说点什么吧");
[TFPromptManager showPromptViewWithStatus:TFPromptStatusSuccess promptTitle:requestModel.msg];
} else if (Compare_Json_isEqualTo(requestModel.code, 318)) {
weakSelf.commentTextView.text = @"";
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:requestModel.msg];
} else {
weakSelf.commentTextView.text = t_text;
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:requestModel.msg];
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
[TFPromptManager showPromptWithError:error defaultText:TFLocalizedString(@"评论失败")];
}];
}
- (void)popViewController
{
[super popViewController];
[self dismissViewControllerAnimated:YES completion:nil];
}
@end
@@ -0,0 +1,19 @@
//
// TFAudioDetailViewController.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/25.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface TFAudioDetailViewController : TFBasicViewController
@property (nonatomic ,assign) NSInteger audio_id;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,368 @@
//
// TFAudioDetailViewController.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/25.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFAudioDetailViewController.h"
#import "WXYZ_AudioDownloadViewController.h"
#import "TFAudioDetailHeaderView.h"
#import "TFAudioDetailFooterView.h"
#import "WXYZ_CompositeEmbeddedTableView.h"
#import "WXYZ_TouchAssistantView.h"
#import "TFAudioDetailModel.h"
#import "TFShareManager.h"
#import "UIView+BorderLine.h"
@interface TFAudioDetailViewController ()<UITableViewDelegate, UITableViewDataSource, UIScrollViewDelegate>
@property (nonatomic ,strong) UIView *gradientColorView;
@property (nonatomic ,assign) BOOL canScroll;
@property (nonatomic ,assign) CGFloat lastContentOffset; // 滑动距离
@property (nonatomic ,assign) BOOL slidingUp; // 滑动方向
@property (nonatomic ,strong) TFAudioDetailModel *detailModel;
@property (nonatomic ,strong) UIButton *shareButton;
@property (nonatomic ,strong) UIButton *downloadButton;
@property (nonatomic ,strong) WXYZ_CompositeEmbeddedTableView *mallTableView;
@property (nonatomic ,strong) TFAudioDetailHeaderView *headerView;
@property (nonatomic ,strong) TFAudioDetailFooterView *footerView;
@property (nonatomic ,assign) CGFloat headerViewHeight;
@end
@implementation TFAudioDetailViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[self initialize];
[self createSubviews];
[self netRequest];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self setStatusBarLightContentStyle];
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Hidden_Tabbar object:nil];
if (self.headerView) {
[self.headerView reloadCollectionButtonState];
}
}
- (void)initialize
{
[self hiddenSeparator];
self.navigationBar.backgroundColor = [UIColor clearColor];
self.navigationBar.navTitleLabel.alpha = 0;
self.navigationBar.navTitleLabel.textColor = kWhiteColor;
[self.navigationBar setLightLeftButton];
self.canScroll = YES;
self.headerViewHeight = 0;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeScrollStatus:) name:Notification_Audio_Can_Leave_Top object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadAudioDetail:) name:Notification_Audio_Check_Recommend object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(netRequest) name:Notification_Recharge_Success object:nil];
}
- (void)createSubviews
{
self.shareButton = [UIButton buttonWithType:UIButtonTypeCustom];
self.shareButton.adjustsImageWhenHighlighted = NO;
self.shareButton.tintColor = kWhiteColor;
self.shareButton.hidden = YES;
[self.shareButton setImage:[[UIImage imageNamed:@"public_share"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
[self.shareButton setImageEdgeInsets:UIEdgeInsetsMake(6, 12, 6, 0)];
[self.shareButton addTarget:self action:@selector(shareButtonClick) forControlEvents:UIControlEventTouchUpInside];
[self.navigationBar addSubview:self.shareButton];
[self.shareButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(self.navigationBar.mas_right).with.offset(- kMargin);
make.bottom.mas_equalTo(self.navigationBar.mas_bottom).with.offset(- 7);
make.width.height.mas_equalTo(30);
}];
#if TF_Download_Mode
self.downloadButton = [UIButton buttonWithType:UIButtonTypeCustom];
self.downloadButton.hidden = YES;
self.downloadButton.adjustsImageWhenHighlighted = NO;
self.downloadButton.tintColor = kWhiteColor;
[self.downloadButton setImage:[[UIImage imageNamed:@"public_download"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
[self.downloadButton setImageEdgeInsets:UIEdgeInsetsMake(6, 12, 6, 0)];
[self.downloadButton addTarget:self action:@selector(downloadClick) forControlEvents:UIControlEventTouchUpInside];
[self.navigationBar addSubview:self.downloadButton];
[self.downloadButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(self.shareButton.mas_left).with.offset(- kHalfMargin);
make.bottom.mas_equalTo(self.navigationBar.mas_bottom).with.offset(- 7);
make.width.height.mas_equalTo(30);
}];
#endif
self.navigationBar.touchEnabled = YES;
self.gradientColorView = [[UIView alloc] init];
self.gradientColorView.backgroundColor = kGrayViewColor;
[self.view addSubview:self.gradientColorView];
[self.gradientColorView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.view);
}];
self.mallTableView = [[WXYZ_CompositeEmbeddedTableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) style:UITableViewStylePlain];
self.mallTableView.delegate = self;
self.mallTableView.dataSource = self;
self.mallTableView.bounces = NO;
[self.mallTableView addObserver:self forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionNew context:nil];
[self.view addSubview:self.mallTableView];
WS(weakSelf)
self.headerView = [[TFAudioDetailHeaderView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_WIDTH)];
self.headerView.changeIntroductionBlock = ^(CGFloat headerViewHeight, BOOL viewEnable) {
weakSelf.headerViewHeight = headerViewHeight;
weakSelf.mallTableView.scrollEnabled = viewEnable;
// 重置headerView高度
[UIView animateWithDuration:kAnimatedDurationFast animations:^{
UIView *t_headerView = weakSelf.headerView;
t_headerView.height = headerViewHeight;
[weakSelf.mallTableView beginUpdates];
[weakSelf.mallTableView setTableHeaderView:t_headerView];
[weakSelf.mallTableView endUpdates];
}];
};
[self.mallTableView setTableHeaderView:self.headerView];
self.footerView = [[TFAudioDetailFooterView alloc] init];
self.footerView.view.hidden = YES;
self.footerView.view.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
self.footerView.audio_id = self.audio_id;
[self.footerView.view addRoundingCornersWithRoundingCorners:(UIRectCornerTopLeft | UIRectCornerTopRight)];
[self.mallTableView setTableFooterView:self.footerView.view];
[self addChildViewController:self.footerView];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
return [[UITableViewCell alloc] init];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return CGFLOAT_MIN;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return CGFLOAT_MIN;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return CGFLOAT_MIN;
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context
{
if ([keyPath isEqualToString:@"contentOffset"]) {
CGPoint point = [((NSValue *)[self.mallTableView valueForKey:@"contentOffset"]) CGPointValue];
if (self.canScroll) {
self.footerView.contentOffSetY = point.y;
self.headerView.contentOffSetY = point.y;
} else {
self.footerView.contentOffSetY = self.headerViewHeight - PUB_NAVBAR_HEIGHT;
self.headerView.contentOffSetY = self.headerViewHeight - PUB_NAVBAR_HEIGHT;
}
}
}
- (void)changeScrollStatus:(NSNotification *)noti
{
self.canScroll = [noti.object boolValue];
}
- (void)reloadAudioDetail:(NSNotification *)noti
{
self.audio_id = [noti.object integerValue];
self.footerView.audio_id = self.audio_id;
[self netRequest];
}
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
self.lastContentOffset = scrollView.contentOffset.y; //判断上下滑动时
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if (scrollView.contentOffset.y <= self.headerViewHeight - PUB_NAVBAR_HEIGHT) {
if (self.canScroll) {
self.canScroll = YES;
self.footerView.canScroll = NO;
if (scrollView.contentOffset.y <= 0) {
scrollView.contentOffset = CGPointMake(0, 0);
}
} else {
scrollView.contentOffset = CGPointMake(0, self.headerViewHeight - PUB_NAVBAR_HEIGHT);
}
if (scrollView.contentOffset.y < self.lastContentOffset ){
self.slidingUp = NO;
} else if (scrollView.contentOffset.y > self.lastContentOffset ){
self.slidingUp = YES;
}
} else {
self.canScroll = NO;
scrollView.contentOffset = CGPointMake(0, self.headerViewHeight - PUB_NAVBAR_HEIGHT);
self.footerView.canScroll = YES;
}
}
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
if (self.footerView.canScroll || scrollView.contentOffset.y == 0) {
return;
}
if (self.slidingUp) {
if (fabs(scrollView.contentOffset.y - self.lastContentOffset) > self.headerViewHeight * 0.2) {
[scrollView setContentOffset:CGPointMake(0, self.headerViewHeight - PUB_NAVBAR_HEIGHT) animated:YES];
} else {
[scrollView setContentOffset:CGPointMake(0, 0) animated:YES];
}
} else {
if (fabs(scrollView.contentOffset.y - self.lastContentOffset) > self.headerViewHeight * 0.2) {
[scrollView setContentOffset:CGPointMake(0, 0) animated:YES];
} else {
[scrollView setContentOffset:CGPointMake(0, self.headerViewHeight - PUB_NAVBAR_HEIGHT) animated:YES];
}
}
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
if (self.canScroll) {
if (self.slidingUp) {
if (fabs(scrollView.contentOffset.y - self.lastContentOffset) > self.headerViewHeight * 0.2) {
[scrollView setContentOffset:CGPointMake(0, self.headerViewHeight - PUB_NAVBAR_HEIGHT) animated:YES];
} else {
[scrollView setContentOffset:CGPointMake(0, 0) animated:YES];
}
} else {
if (fabs(scrollView.contentOffset.y - self.lastContentOffset) > self.headerViewHeight * 0.2) {
[scrollView setContentOffset:CGPointMake(0, 0) animated:YES];
} else {
[scrollView setContentOffset:CGPointMake(0, self.headerViewHeight - PUB_NAVBAR_HEIGHT) animated:YES];
}
}
}
}
- (void)shareButtonClick
{
[TFShareManager shareWithProduction_id:NSStringFromInteger(self.detailModel.audio.production_id) chapter_id:nil type:TFShareTypeAudio];
}
- (void)downloadClick
{
if (!self.audio_id || self.audio_id == 0) {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:TFLocalizedString(@"书籍获取失败")];
return;
}
if (!self.footerView.directoryModel.chapter_list || self.footerView.directoryModel.chapter_list.count == 0) {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:TFLocalizedString(@"书籍获取失败")];
return;
}
WXYZ_AudioDownloadViewController *vc = [[WXYZ_AudioDownloadViewController alloc] init];
vc.production_id = self.audio_id;
[self.navigationController pushViewController:vc animated:YES];
}
- (void)netRequest
{
if ([TFNetworkManager networkingStatus] == NO) {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:TFLocalizedString(@"当前无网络连接")];
return;
}
WS(weakSelf)
[TFNetworkTools POST:Audio_Info parameters:@{@"audio_id":[TFUtilsHelper formatStringWithInteger:self.audio_id]} model:nil success:^(BOOL isSuccess, id _Nullable t_model, TFNetworkRequestModel * _Nonnull requestModel) {
if (isSuccess) {
NSMutableDictionary *t_dic = [t_model mutableCopy];
NSMutableDictionary *t_data_dic = [[t_dic objectForKey:@"data"] mutableCopy];
NSMutableDictionary *t_production_dic = [NSMutableDictionary dictionaryWithDictionary:[t_data_dic objectForKey:@"audio"]];
NSMutableDictionary *t_ad_dic = [NSMutableDictionary dictionaryWithDictionary:[t_data_dic objectForKey:@"advert"]];
[t_production_dic addEntriesFromDictionary:t_ad_dic];
[t_data_dic setObject:t_production_dic forKey:@"audio"];
TFAudioDetailModel *t_model = [TFAudioDetailModel modelWithDictionary:t_data_dic];
weakSelf.headerView.audioModel = t_model.audio;
weakSelf.detailModel = t_model;
if (t_model.color.count > 1) {
CAGradientLayer *gradientLayer = [CAGradientLayer layer];
gradientLayer.frame = weakSelf.view.frame;
gradientLayer.colors = @[(__bridge id)[UIColor colorWithHexString:[t_model.color firstObject]?:@""].CGColor,(__bridge id)[UIColor colorWithHexString:[t_model.color objectAtIndex:1]?:@""].CGColor];
gradientLayer.startPoint = CGPointMake(0, 0);
gradientLayer.endPoint = CGPointMake(0, 1.0);
[weakSelf.gradientColorView.layer addSublayer:gradientLayer];
}
}
weakSelf.shareButton.hidden = NO;
weakSelf.downloadButton.hidden = NO;
weakSelf.footerView.view.hidden = NO;
} failure:nil];
[TFNetworkTools POST:Audio_Catalog parameters:@{@"audio_id":[TFUtilsHelper formatStringWithInteger:self.audio_id]} model:TFProductionModel.class success:^(BOOL isSuccess, TFProductionModel * _Nullable t_model, TFNetworkRequestModel * _Nonnull requestModel) {
if (isSuccess) {
weakSelf.footerView.directoryModel = t_model;
[weakSelf.mallTableView reloadData];
}
} failure:nil];
}
- (void)dealloc
{
@try {
[self.mallTableView removeObserver:self forKeyPath:@"contentOffset" context:NULL];
} @catch (NSException *exception) {
}
}
@end
@@ -0,0 +1,21 @@
//
// TFAudioDirectoryViewController.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/25.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface TFAudioDirectoryViewController : TFBasicViewController
@property (nonatomic ,assign) NSInteger audio_id;
@property (nonatomic ,assign) BOOL canScroll;
@property (nonatomic ,strong) TFProductionModel *directoryModel;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,416 @@
//
// TFAudioDirectoryViewController.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/25.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFAudioDirectoryViewController.h"
#import "TFAudioPlayViewController.h"
#import "TFTaskViewController.h"
#import "TFAudioDirectoryViewCell.h"
#import "WXYZ_AudioPlayPageMenuView.h"
#import "WXYZ_ChapterBottomPayBar.h"
#import "WXYZ_AudioDownloadManager.h"
#import "TFReadRecordManager.h"
#import "TFCollectionManager.h"
@interface TFAudioDirectoryViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic ,strong) UIView *headerSectionView;
@property (nonatomic ,strong) UILabel *headerSectionLabel;
@property (nonatomic ,assign) BOOL toolSelect; // 工具栏状态选择
@end
@implementation TFAudioDirectoryViewController
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.mainTableView reloadData];
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self initialize];
[self createSubviews];
}
- (void)initialize
{
[self hiddenNavigationBar:YES];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeChapterList:) name:NSNotification_Auto_Buy_Audio_Chapter object:nil];
}
- (void)createSubviews
{
self.mainTableView.delegate = self;
self.mainTableView.dataSource = self;
self.mainTableView.contentInset = UIEdgeInsetsMake(0, 0, PUB_TABBAR_OFFSET, 0);
[self.view addSubview:self.mainTableView];
[self.mainTableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.view);
}];
[self setEmptyOnView:self.mainTableView title:TFLocalizedString(@"暂无目录列表") buttonTitle:@"" tapBlock:^{
}];
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if (self.toolSelect) {
return;
}
if ([scrollView isEqual:self.mainTableView]) {
if (!self.canScroll) {
scrollView.contentOffset = CGPointZero;
}
if (scrollView.contentOffset.y > 0) {
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Audio_Can_Leave_Top object:@NO];
}
}
}
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView
{
self.toolSelect = NO;
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
if (scrollView.contentOffset.y <= 0) {
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Audio_Can_Leave_Top object:@YES];
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.directoryModel.chapter_list.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
WS(weakSelf)
TFProductionChapterModel *t_chapterList = [self.directoryModel.chapter_list objectOrNilAtIndex:indexPath.row];
TFAudioDirectoryViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TFAudioDirectoryViewCell"];
if (!cell) {
cell = [[TFAudioDirectoryViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"TFAudioDirectoryViewCell"];
}
cell.audioDirectoryModel = t_chapterList;
cell.index = indexPath;
cell.cellDownloadState = [[WXYZ_AudioDownloadManager sharedManager] getChapterDownloadStateWithProduction_id:t_chapterList.production_id chapter_id:t_chapterList.chapter_id];
cell.hiddenEndLine = self.directoryModel.chapter_list.count - 1 == indexPath.row;
cell.downloadChapterBlock = ^(NSInteger audio_id, NSInteger chapter_id, NSIndexPath *cellIndexPath) {
[weakSelf requestChapterDownloadDataWithAudio_id:audio_id chapter_ids:@[[TFUtilsHelper formatStringWithInteger:chapter_id]] indexPath:cellIndexPath];
};
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Reset_Player_Inof object:nil];
WS(weakSelf)
TFProductionChapterModel *t_chapterListModel = [self.directoryModel.chapter_list objectOrNilAtIndex:indexPath.row];
TFAudioPlayViewController *vc = [TFAudioPlayViewController sharedManager];
vc.chapter_list = self.directoryModel.chapter_list;
[vc loadDataWithAudio_id:t_chapterListModel.production_id chapter_id:t_chapterListModel.chapter_id];
for (UIViewController *vc in weakSelf.navigationController.viewControllers) {
if ([vc isKindOfClass:[TFAudioPlayViewController class]]) {
[weakSelf popViewController];
return;
}
}
[weakSelf closeContinuePlayButton];
[TFTaskViewController taskReadRequestWithProduction_id:self.audio_id];
TFNavigationController *nav = [[TFNavigationController alloc] initWithRootViewController:vc];
[[TFViewHelper getWindowRootController] presentViewController:nav animated:YES completion:^{
[weakSelf.mainTableView reloadData];
}];
[[TFCollectionManager shareManagerWithProductionType:TFProductionTypeAudio] moveCollectionToTopWithProductionModel:self.directoryModel];
}
//section头间距
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
if (self.directoryModel.chapter_list.count > 0) {
return 60;
}
return CGFLOAT_MIN;
}
//section头视图
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
return self.headerSectionView;
}
//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;
}
- (UIView *)headerSectionView
{
if (!_headerSectionView) {
_headerSectionView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 60)];
_headerSectionView.backgroundColor = kWhiteColor;
[_headerSectionView addSubview:self.headerSectionLabel];
if (![[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeAudio]
isCurrentPlayingProductionWithProduction_id:self.audio_id] // 不是正在播放的作品
&&
([[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeAudio]
getReadingRecordChapter_idWithProduction_id:self.audio_id] > 0) // 记录章节id存在
&&
([[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeAudio]
getReadingRecordChapterTitleWithProduction_id:self.audio_id].length > 0) // 记录的章节名称存在
) {
NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString: [NSString stringWithFormat:@"%@|%@", TFLocalizedString(@"续播"), [[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeAudio] getReadingRecordChapterTitleWithProduction_id:self.audio_id]]];
CGFloat width = [TFViewHelper getDynamicWidthWithLabelFont:kFont10 labelHeight:30.0 labelText:text.string maxWidth:SCREEN_WIDTH / 2.0];
width += kHalfMargin;
UIButton *continuePlay = [UIButton buttonWithType:UIButtonTypeCustom];
continuePlay.frame = CGRectMake(kMargin, kHalfMargin + 5, 20.0 + kQuarterMargin + width, 30);
continuePlay.tag = 1123;
continuePlay.backgroundColor = kWhiteColor;
continuePlay.layer.cornerRadius = 15;
continuePlay.layer.borderColor = kMainColor.CGColor;
continuePlay.layer.borderWidth = 1;
continuePlay.clipsToBounds = YES;
[continuePlay addTarget:self action:@selector(continueButtonClick) forControlEvents:UIControlEventTouchUpInside];
[_headerSectionView addSubview:continuePlay];
UIImageView *icon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"audio_play"]];
icon.frame = CGRectMake(5, 5, continuePlay.height - 10, continuePlay.height - 10);
[continuePlay addSubview:icon];
text.font = kFont10;
text.color = kMainColor;
[text addAttribute:NSFontAttributeName value:kBoldFont10 range:NSMakeRange(0, 2)];
UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(icon.right + 5, 0, width, continuePlay.height)];
title.attributedText = text;
[continuePlay addSubview:title];
UIButton *closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
closeButton.frame = CGRectMake(continuePlay.right - continuePlay.height / 2 + 5, continuePlay.top - 5, continuePlay.height / 2 + 10, continuePlay.height / 2 + 10);
closeButton.layer.cornerRadius = continuePlay.height / 4;
closeButton.clipsToBounds = YES;
closeButton.tag = 1123;
closeButton.contentVerticalAlignment = UIControlContentVerticalAlignmentFill;
closeButton.contentHorizontalAlignment = UIControlContentVerticalAlignmentFill;
[closeButton setImageEdgeInsets:UIEdgeInsetsMake(0, 0, 10, 10)];
[closeButton setImage:[UIImage imageNamed:@"audio_continue_close"] forState:UIControlStateNormal];
[closeButton addTarget:self action:@selector(closeContinuePlayButton) forControlEvents:UIControlEventTouchUpInside];
[_headerSectionView addSubview:closeButton];
}
TFButton *selectionButton = [[TFButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - 40 - kHalfMargin, 10, 40, 40) buttonTitle:TFLocalizedString(@"选章标题") buttonImageName:@"audio_selection" buttonIndicator:TFButtonIndicatorTitleBottom];
selectionButton.tag = 0;
selectionButton.buttonTintColor = kBlackColor;
selectionButton.buttonTitleFont = kFont10;
selectionButton.graphicDistance = 2;
selectionButton.buttonImageScale = 0.4;
[selectionButton addTarget:self action:@selector(toolBarButtonClick:) forControlEvents:UIControlEventTouchUpInside];
[_headerSectionView addSubview:selectionButton];
TFButton *sortButton = [[TFButton alloc] initWithFrame:CGRectMake(selectionButton.left - 40 - kHalfMargin, selectionButton.top, selectionButton.width, selectionButton.height) buttonTitle:TFLocalizedString(@"排序") buttonImageName:@"audio_order_sequence" buttonIndicator:TFButtonIndicatorTitleBottom];
sortButton.selected = NO;
sortButton.tag = 1;
sortButton.buttonTintColor = kBlackColor;
sortButton.buttonTitleFont = kFont10;
sortButton.graphicDistance = 2;
sortButton.buttonImageScale = 0.4;
[sortButton addTarget:self action:@selector(toolBarButtonClick:) forControlEvents:UIControlEventTouchUpInside];
[_headerSectionView addSubview:sortButton];
}
return _headerSectionView;
}
- (UILabel *)headerSectionLabel
{
if (!_headerSectionLabel) {
_headerSectionLabel = [[UILabel alloc] initWithFrame:CGRectMake(kMargin, 0, SCREEN_WIDTH / 2, 60)];
_headerSectionLabel.textColor = kGrayTextDeepColor;
_headerSectionLabel.font = kFont12;
_headerSectionLabel.textAlignment = NSTextAlignmentLeft;
}
return _headerSectionLabel;
}
- (void)setDirectoryModel:(TFProductionModel *)directoryModel
{
_directoryModel = directoryModel;
self.headerSectionLabel.text = [NSString stringWithFormat:TFLocalizedString(@"共%@章"), [TFUtilsHelper formatStringWithInteger:directoryModel.chapter_list.count]];
[self.mainTableView reloadData];
self.emptyView.contentViewY = kHalfMargin;
[self.mainTableView endRefreshing];
[self.mainTableView xtfei_endLoading];
}
- (void)continueButtonClick
{
WS(weakSelf)
TFAudioPlayViewController *vc = [TFAudioPlayViewController sharedManager];
vc.chapter_list = self.directoryModel.chapter_list;
[vc loadDataWithAudio_id:self.audio_id chapter_id:[[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeAudio] getReadingRecordChapter_idWithProduction_id:self.audio_id]];
TFNavigationController *nav = [[TFNavigationController alloc] initWithRootViewController:vc];
[[TFViewHelper getWindowRootController] presentViewController:nav animated:YES completion:^{
[weakSelf closeContinuePlayButton];
[weakSelf.mainTableView reloadData];
}];
}
- (void)closeContinuePlayButton
{
[self.headerSectionView.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if (obj.tag == 1123) {
[obj removeAllSubviews];
[obj removeFromSuperview];
obj = nil;
}
}];
}
- (void)toolBarButtonClick:(TFButton *)sender
{
switch (sender.tag) {
case 0: // 选章
{
WS(weakSelf)
WXYZ_AudioPlayPageMenuView *chooseMenuView = [[WXYZ_AudioPlayPageMenuView alloc] init];
chooseMenuView.menuListArray = self.directoryModel.chapter_list;
chooseMenuView.totalChapter = self.directoryModel.total_chapters;
chooseMenuView.chooseMenuBlock = ^(WXYZ_MenuType menuType, NSInteger chooseIndex) {
/* 滚动指定段的指定row 到 指定位置*/
weakSelf.toolSelect = YES;
[weakSelf.mainTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:chooseIndex * 30 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES];
};
[chooseMenuView showWithMenuType:WXYZ_MenuTypeAudioSelection];
}
break;
case 1: // 排序
{
if (sender.selected) {
sender.selected = NO;
sender.buttonImageName = @"audio_order_sequence";
} else {
sender.selected = YES;
sender.buttonImageName = @"audio_orider_reversed";
}
self.directoryModel.chapter_list = [[self.directoryModel.chapter_list reverseObjectEnumerator] allObjects];
[self.mainTableView reloadData];
}
break;
default:
break;
}
}
- (void)changeChapterList:(NSNotification *)noti
{
// 需要改变状态的chapter的is_preview状态
if ([noti.object isKindOfClass:[NSString class]]) {
NSInteger t_chapter_id = [noti.object integerValue];
for (TFProductionChapterModel *t_chapterModel in self.directoryModel.chapter_list) {
if (t_chapter_id == t_chapterModel.chapter_id) {
t_chapterModel.is_preview = 0;
break;
}
}
}
}
- (void)requestChapterDownloadDataWithAudio_id:(NSInteger)audio_id chapter_ids:(NSArray <NSString *>*)chapter_ids indexPath:(NSIndexPath *)indexPath
{
WS(weakSelf)
WXYZ_AudioDownloadManager *audioDownloadManager = [WXYZ_AudioDownloadManager sharedManager];
[audioDownloadManager downloadChaptersWithProductionModel:self.directoryModel production_id:audio_id chapter_ids:chapter_ids];
audioDownloadManager.downloadChapterStateChangeBlock = ^(WXYZ_DownloadChapterState state, NSInteger production_id, NSInteger chapter_id) {
TFAudioDirectoryViewCell *cell = [self.mainTableView cellForRowAtIndexPath:indexPath];
switch (state) {
case WXYZ_DownloadStateChapterDownloadStart:
cell.cellDownloadState = WXYZ_ProductionDownloadStateDownloading;
break;
case WXYZ_DownloadStateChapterDownloadFinished:
cell.cellDownloadState = WXYZ_ProductionDownloadStateDownloaded;
break;
case WXYZ_DownloadStateChapterDownloadFail:
cell.cellDownloadState = WXYZ_ProductionDownloadStateFail;
break;
default:
break;
}
};
audioDownloadManager.downloadMissionStateChangeBlock = ^(WXYZ_DownloadMissionState state, NSInteger production_id, NSArray * _Nonnull chapter_ids) {
switch (state) {
case WXYZ_DownloadStateMissionShouldPay:
{
TFProductionChapterModel *t_chapterList = [weakSelf.directoryModel.chapter_list objectOrNilAtIndex:indexPath.row];
t_chapterList.chapter_ids = @[[TFUtilsHelper formatStringWithInteger:t_chapterList.chapter_id]];
dispatch_async(dispatch_get_main_queue(), ^{
WXYZ_ChapterBottomPayBar *payBar = [[WXYZ_ChapterBottomPayBar alloc] initWithChapterModel:t_chapterList barType:WXYZ_BottomPayBarTypeDownload productionType:TFProductionTypeAudio];
payBar.paySuccessChaptersBlock = ^(NSArray<NSString *> * _Nonnull success_chapter_ids) {
[weakSelf requestChapterDownloadDataWithAudio_id:audio_id chapter_ids:chapter_ids indexPath:indexPath];
};
payBar.payFailChaptersBlock = ^(NSArray<NSString *> * _Nonnull fail_chapter_ids) {
TFAudioDirectoryViewCell *cell = [self.mainTableView cellForRowAtIndexPath:indexPath];
cell.audioDirectoryModel = cell.audioDirectoryModel;
cell.cellDownloadState = WXYZ_ProductionDownloadStateNormal;
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:TFLocalizedString(@"购买失败")];
};
payBar.payCancleChapterBlock = ^(NSArray<NSString *> * _Nonnull fail_chapter_ids) {
TFAudioDirectoryViewCell *cell = [self.mainTableView cellForRowAtIndexPath:indexPath];
cell.audioDirectoryModel = cell.audioDirectoryModel;
cell.cellDownloadState = WXYZ_ProductionDownloadStateNormal;
};
[payBar showBottomPayBar];
});
}
break;
default:
break;
}
};
}
@end
@@ -0,0 +1,20 @@
//
// TFAudioRecommendedViewController.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/25.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFBasicViewController.h"
NS_ASSUME_NONNULL_BEGIN
@interface TFAudioRecommendedViewController : TFBasicViewController
@property (nonatomic ,assign) BOOL canScroll;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,154 @@
//
// TFAudioRecommendedViewController.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/25.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFAudioRecommendedViewController.h"
#import "TFAudioRecommendedViewCell.h"
#import "TFAudioRecommendedModel.h"
@interface TFAudioRecommendedViewController ()<UITableViewDelegate, UITableViewDataSource>
@end
@implementation TFAudioRecommendedViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[self initialize];
[self createSubviews];
[self netRequest];
}
- (void)initialize
{
[self hiddenNavigationBar:YES];
}
- (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.edges.mas_equalTo(self.view);
}];
[self setEmptyOnView:self.mainTableView title:TFLocalizedString(@"暂无数据") buttonTitle:nil tapBlock:^{
}];
WS(weakSelf)
self.mainTableView.mj_header = [TFRefreshHeader headerWithRefreshingBlock:^{
weakSelf.currentPageNumber = 1;
[weakSelf netRequest];
}];
self.mainTableView.mj_footer = [TFRefreshFooter footerWithRefreshingBlock:^{
weakSelf.currentPageNumber ++;
[weakSelf netRequest];
}];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.dataSourceArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellName = @"TFAudioRecommendedViewCell";
TFAudioRecommendedViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName];
if (!cell) {
cell = [[TFAudioRecommendedViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
}
cell.productionType = self.productionType;
[cell setListModel:[self.dataSourceArray objectOrNilAtIndex:indexPath.row]];
cell.hiddenEndLine = (indexPath.row == self.dataSourceArray.count - 1);
WS(weakSelf)
cell.clickBlock = ^(NSInteger production_id) {
TFAudioDetailViewController *vc = [[TFAudioDetailViewController alloc] init];
vc.audio_id = production_id;
[weakSelf.navigationController pushViewController:vc animated:YES];
};
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return CGFLOAT_MIN;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, PUB_TABBAR_OFFSET == 0 ? 10 : PUB_TABBAR_OFFSET)];
view.backgroundColor = [UIColor clearColor];
return view;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
TFProductionModel *t_model = [self.dataSourceArray objectOrNilAtIndex:indexPath.row];
TFAudioDetailViewController *vc = [[TFAudioDetailViewController alloc] init];
vc.audio_id = t_model.production_id;
[self.navigationController pushViewController:vc animated:YES];
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if ([scrollView isEqual:self.mainTableView]) {
if (!self.canScroll) {
scrollView.contentOffset = CGPointZero;
}
if (scrollView.contentOffset.y > 0) {
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Audio_Can_Leave_Top object:@NO];
}
}
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
if (scrollView.contentOffset.y <= 0) {
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Audio_Can_Leave_Top object:@YES];
}
}
- (void)netRequest
{
WS(weakSelf)
[TFNetworkTools POST:Audio_Info_Recommend parameters:@{@"page_num":[TFUtilsHelper formatStringWithInteger:self.currentPageNumber]} model:TFAudioRecommendedModel.class success:^(BOOL isSuccess, TFAudioRecommendedModel * _Nullable t_model, TFNetworkRequestModel * _Nonnull requestModel) {
[weakSelf.mainTableView endRefreshing];
if (isSuccess) {
if (weakSelf.currentPageNumber == 1) {
[weakSelf.mainTableView showRefreshFooter];
[weakSelf.dataSourceArray removeAllObjects];
weakSelf.dataSourceArray = [NSMutableArray arrayWithArray:t_model.list];
} else {
[weakSelf.dataSourceArray addObjectsFromArray:t_model.list];
}
if (t_model.total_page <= t_model.current_page) {
[weakSelf.mainTableView hideRefreshFooter];
}
}
[weakSelf.mainTableView reloadData];
[weakSelf.mainTableView xtfei_endLoading];
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
[weakSelf.mainTableView endRefreshing];
[weakSelf.mainTableView reloadData];
[weakSelf.mainTableView xtfei_endLoading];
}];
}
@end
@@ -0,0 +1,21 @@
//
// TFAudioDetailModel.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/25.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface TFAudioDetailModel : NSObject
@property (nonatomic ,strong) TFProductionModel *audio;
@property (nonatomic ,strong) NSArray <NSString *> *color;
@property (nonatomic ,assign) NSInteger is_vip;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,28 @@
//
// TFAudioDetailModel.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/25.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFAudioDetailModel.h"
@implementation TFAudioDetailModel
+ (NSDictionary<NSString *,id> *)modelContainerPropertyGenericClass
{
return @{
@"audio" : [TFProductionModel class]
};
}
+ (NSDictionary *)modelCustomPropertyMapper
{
return @{
@"color" :@"audio.color",
@"is_vip" :@"user.is_vip"
};
}
@end
@@ -0,0 +1,30 @@
//
// TFAudioRecommendedModel.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/25.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@class TFAudioContentModel, TFPagingModel;
@interface TFAudioRecommendedModel : TFPagingModel
@property (nonatomic ,strong) NSArray <TFAudioContentModel *>*list;
@end
@interface TFAudioContentModel : TFProductionModel
@property (nonatomic ,assign) BOOL is_vip; // 是否是vip章节
@property (nonatomic ,assign) BOOL is_finish; // 是否已完结
@property (nonatomic ,assign) NSInteger views; // 观看数
@property (nonatomic ,assign) NSInteger total_views;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,23 @@
//
// TFAudioRecommendedModel.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/25.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFAudioRecommendedModel.h"
@implementation TFAudioRecommendedModel
+ (NSDictionary<NSString *,id> *)modelContainerPropertyGenericClass
{
return @{@"list" : [TFAudioContentModel class]};
}
@end
@implementation TFAudioContentModel
@end
@@ -0,0 +1,27 @@
//
// TFAudioDetailFooterView.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/25.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
typedef void(^PushToComicDetailBlock)(NSInteger production_id);
@interface TFAudioDetailFooterView : TFBasicViewController
@property (nonatomic ,assign) BOOL canScroll;
@property (nonatomic ,assign) CGFloat contentOffSetY;
@property (nonatomic ,assign) NSInteger audio_id;
@property (nonatomic ,strong) TFProductionModel *directoryModel;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,87 @@
//
// TFAudioDetailFooterView.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/25.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFAudioDetailFooterView.h"
#import "TFAudioRecommendedViewController.h"
#import "TFAudioDirectoryViewController.h"
@interface TFAudioDetailFooterView ()<SGPageTitleViewDelegate, SGPageContentCollectionViewDelegate>
{
TFAudioRecommendedViewController *rightVC;
TFAudioDirectoryViewController *leftVC;
}
@property (nonatomic ,strong) SGPageTitleView *pageTitleView;
@property (nonatomic ,strong) SGPageContentCollectionView *pageContentCollectionView;
@end
@implementation TFAudioDetailFooterView
- (void)viewDidLoad
{
[super viewDidLoad];
[self hiddenNavigationBar:YES];
[self createSubViews];
}
- (void)createSubViews
{
leftVC = [[TFAudioDirectoryViewController alloc] init];
leftVC.directoryModel = self.directoryModel;
[self addChildViewController:leftVC];
rightVC = [[TFAudioRecommendedViewController alloc] init];
rightVC.productionType = TFProductionTypeAudio;
[self addChildViewController:rightVC];
NSArray *childArr = @[leftVC, rightVC];
NSArray *titleArr = @[TFLocalizedString(@"目录"), TFLocalizedString(@"推荐")];
self.pageContentCollectionView = [[SGPageContentCollectionView alloc] initWithFrame:CGRectMake(0, 44.6, self.view.width, SCREEN_HEIGHT - PUB_NAVBAR_HEIGHT - 44) parentVC:self childVCs:childArr];
self.pageContentCollectionView.delegatePageContentCollectionView = self;
[self.view addSubview:self.pageContentCollectionView];
self.pageConfigure.bottomSeparatorColor = kGrayLineColor;
self.pageConfigure.titleFont = kMainFont;
self.pageConfigure.titleSelectedColor = kBlackColor;
self.pageTitleView = [SGPageTitleView pageTitleViewWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 44) delegate:self titleNames:titleArr configure:self.pageConfigure];
self.pageTitleView.backgroundColor = [UIColor whiteColor];
[self.pageTitleView addRoundingCornersWithRoundingCorners:(UIRectCornerTopLeft | UIRectCornerTopRight)];
[self.view addSubview:self.pageTitleView];
}
- (void)setDirectoryModel:(TFProductionModel *)directoryModel
{
_directoryModel = directoryModel;
leftVC.directoryModel = directoryModel;
}
- (void)setAudio_id:(NSInteger)audio_id
{
_audio_id = audio_id;
leftVC.audio_id = self.audio_id;
}
- (void)setCanScroll:(BOOL)canScroll
{
rightVC.canScroll = canScroll;
leftVC.canScroll = canScroll;
}
- (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];
}
@end
@@ -0,0 +1,24 @@
//
// TFAudioDetailHeaderView.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/25.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface TFAudioDetailHeaderView : UIView
@property (nonatomic ,strong) TFProductionModel *audioModel;
@property (nonatomic ,copy) void (^changeIntroductionBlock)(CGFloat headerViewHeight, BOOL viewEnable);
@property (nonatomic ,assign) CGFloat contentOffSetY;
- (void)reloadCollectionButtonState;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,642 @@
//
// TFAudioDetailHeaderView.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/25.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFAudioDetailHeaderView.h"
#import "TFUpgradeMemberController.h"
#import "TFCollectionManager.h"
#import "TFReadRecordManager.h"
#import "TFAdvertisementManager.h"
#import "UIView+AZGradient.h"
#import "UILabel+LineBreak.h"
#import "UIView+BorderLine.h"
@interface TFAudioDetailHeaderView ()
{
UIView *contentView;
UILabel *navTitleLabel;
UIImageView *coverImageView;
UILabel *audioTitleLabel;
UILabel *hotLabel;
UIImageView *authorIcon;
UILabel *authorLabel;
UILabel *collectNumLabel;
TFButton *collectButton;
UILabel *tagView;
UIView *introductionView;
UILabel *introductionLabel;
TFButton *moreButton;
UIButton *vipButton;
// 展开详情后视图样式
UILabel *introductionBottomLabel;
TFButton *packUpButton;
TFButton *bottomPackUpButton;
TFAdvertisementManager *adView;
}
@property (nonatomic ,strong) YYTextView *introductionTextView;
@end
@implementation TFAudioDetailHeaderView
- (instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
self.backgroundColor = [UIColor clearColor];
self.frame = frame;
[self createSubViews];
}
return self;
}
- (void)createSubViews
{
contentView = [[UIView alloc] init];
contentView.backgroundColor = [UIColor clearColor];
[self addSubview:contentView];
[contentView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.mas_left);
make.top.mas_equalTo(self.mas_top);
make.width.mas_equalTo(self.mas_width);
make.height.mas_equalTo(self.mas_height);
}];
navTitleLabel = [[UILabel alloc] init];
navTitleLabel.alpha = 0;
navTitleLabel.textColor = kWhiteColor;
navTitleLabel.textAlignment = NSTextAlignmentLeft;
navTitleLabel.font = kBoldMainFont;
[contentView addSubview:navTitleLabel];
[navTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(kHalfMargin + 44);
make.top.mas_equalTo(PUB_NAVBAR_HEIGHT - 44);
make.width.mas_equalTo(SCREEN_WIDTH / 2 - 44);
make.height.mas_equalTo(44);
}];
coverImageView = [[UIImageView alloc] initWithCornerRadiusAdvance:4 rectCornerType:UIRectCornerAllCorners];
coverImageView.image = HoldImage;
coverImageView.contentMode = UIViewContentModeScaleAspectFill;
[contentView addSubview:coverImageView];
[coverImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(kMargin);
make.top.mas_equalTo(PUB_NAVBAR_HEIGHT + kHalfMargin);
make.width.mas_equalTo(SCREEN_WIDTH / 4 + kMargin);
make.height.mas_equalTo(kGeometricHeight((SCREEN_WIDTH / 4 + kMargin), 3, 4));
}];
audioTitleLabel = [[UILabel alloc] init];
audioTitleLabel.textColor = kWhiteColor;
audioTitleLabel.textAlignment = NSTextAlignmentLeft;
audioTitleLabel.font = kBoldFont22;
[contentView addSubview:audioTitleLabel];
[audioTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(coverImageView.mas_right).with.offset(kHalfMargin);
make.top.mas_equalTo(coverImageView.mas_top);
make.right.mas_equalTo(contentView.mas_right).with.offset(- kHalfMargin);
make.height.mas_equalTo(30);
}];
tagView = [[UILabel alloc] init];
tagView.backgroundColor = [UIColor clearColor];
tagView.textColor = kColorRGBA(255, 255, 255, 0.9);
tagView.textAlignment = NSTextAlignmentLeft;
tagView.font = kFont12;
[contentView addSubview:tagView];
[tagView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(audioTitleLabel.mas_left);
make.top.mas_equalTo(audioTitleLabel.mas_bottom).with.offset(kQuarterMargin);
make.right.mas_equalTo(audioTitleLabel.mas_right);
make.height.mas_equalTo(25);
}];
hotLabel = [[UILabel alloc] init];
hotLabel.backgroundColor = [UIColor clearColor];
hotLabel.textColor = kColorRGBA(255, 255, 255, 0.9);
hotLabel.textAlignment = NSTextAlignmentLeft;
hotLabel.font = kFont12;
[contentView addSubview:hotLabel];
[hotLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(audioTitleLabel.mas_left);
make.top.mas_equalTo(tagView.mas_bottom);
make.right.mas_equalTo(audioTitleLabel.mas_right);
make.height.mas_equalTo(tagView.mas_height);
}];
collectNumLabel = [[UILabel alloc] init];
collectNumLabel.backgroundColor = [UIColor clearColor];
collectNumLabel.textColor = kColorRGBA(255, 255, 255, 0.9);
collectNumLabel.textAlignment = NSTextAlignmentLeft;
collectNumLabel.font = kFont12;
[contentView addSubview:collectNumLabel];
[collectNumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(audioTitleLabel.mas_left);
make.top.mas_equalTo(hotLabel.mas_bottom);
make.right.mas_equalTo(audioTitleLabel.mas_right);
make.height.mas_equalTo(tagView.mas_height);
}];
collectButton = [[TFButton alloc] initWithFrame:CGRectMake(1, 1, 1, 1) buttonTitle:TFLocalizedString(@"收藏") buttonImageName:@"audio_collection_heart" buttonIndicator:TFButtonIndicatorTitleRight];
collectButton.buttonImageScale = 0.4;
collectButton.buttonTitleFont = kFont12;
collectButton.graphicDistance = 2;
collectButton.buttonTitleColor = kWhiteColor;
collectButton.hidden = YES;
collectButton.layer.cornerRadius = 14;
collectButton.clipsToBounds = YES;
[collectButton addTarget:self action:@selector(collectionButtonClick:) forControlEvents:UIControlEventTouchUpInside];
[contentView addSubview:collectButton];
[collectButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(contentView.mas_right).with.offset(-kMargin);
make.bottom.mas_equalTo(coverImageView.mas_bottom);
make.height.mas_equalTo(28);
make.width.mas_equalTo(80);
}];
authorIcon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"audio_detail_author"]];
authorIcon.hidden = YES;
[contentView addSubview:authorIcon];
[authorIcon mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(collectNumLabel.mas_left);
make.bottom.mas_equalTo(coverImageView.mas_bottom).with.offset(- 2);
make.width.height.mas_equalTo(20);
}];
authorLabel = [[UILabel alloc] init];
authorLabel.backgroundColor = [UIColor clearColor];
authorLabel.textColor = kWhiteColor;
authorLabel.textAlignment = NSTextAlignmentLeft;
authorLabel.font = kMainFont;
[contentView addSubview:authorLabel];
[authorLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(authorIcon.mas_right).with.offset(kHalfMargin);
make.bottom.mas_equalTo(authorIcon.mas_bottom);
make.right.mas_equalTo(collectButton.mas_left).with.offset(- kHalfMargin);
make.height.mas_equalTo(authorIcon.mas_height);
}];
introductionView = [[UIView alloc] init];
introductionView.backgroundColor = kColorRGBA(0, 0, 0, 0.2);
introductionView.layer.cornerRadius = 6;
introductionView.hidden = YES;
introductionView.userInteractionEnabled = YES;
[contentView addSubview:introductionView];
introductionLabel = [[UILabel alloc] init];
introductionLabel.textColor = kColorRGBA(255, 255, 255, 0.9);
introductionLabel.font = kFont12;
introductionLabel.backgroundColor = [UIColor clearColor];
introductionLabel.numberOfLines = 0;
introductionLabel.userInteractionEnabled = YES;
[contentView addSubview:introductionLabel];
[introductionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(kMargin + kHalfMargin);
make.right.mas_equalTo(contentView.mas_right).with.offset(- kMargin - kHalfMargin);
make.top.mas_equalTo(coverImageView.mas_bottom).with.offset(kMargin + kHalfMargin);
make.height.mas_equalTo(80);
}];
[introductionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(introductionLabel.mas_left).with.offset(- kHalfMargin);
make.right.mas_equalTo(introductionLabel.mas_right).with.offset(kHalfMargin);
make.top.mas_equalTo(introductionLabel.mas_top).with.offset(- kQuarterMargin);
make.bottom.mas_equalTo(introductionLabel.mas_bottom).with.offset(kQuarterMargin);
}];
moreButton = [[TFButton alloc] initWithFrame:CGRectZero buttonTitle:TFLocalizedString(@"展开简介") buttonImageName:@"public_down_arrow" buttonIndicator:TFButtonIndicatorTitleLeft];
moreButton.buttonTitleFont = kFont10;
moreButton.buttonImageScale = 0.5;
moreButton.graphicDistance = 3;
moreButton.buttonTintColor = kWhiteColor;
moreButton.backgroundColor = kColorRGBA(255, 255, 255, 0.2);
moreButton.layer.cornerRadius = 10;
[moreButton addTarget:self action:@selector(spreadClick) forControlEvents:UIControlEventTouchUpInside];
[contentView addSubview:moreButton];
[moreButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(introductionLabel.mas_right).with.offset(- kQuarterMargin);
make.bottom.mas_equalTo(introductionLabel.mas_bottom).with.offset(- 2.5);
make.width.mas_equalTo(80);
make.height.mas_equalTo(20);
}];
vipButton = [UIButton buttonWithType:UIButtonTypeCustom];
vipButton.contentVerticalAlignment = UIControlContentVerticalAlignmentFill;
vipButton.contentHorizontalAlignment = UIControlContentVerticalAlignmentFill;
[vipButton setImage:[UIImage imageNamed:TFLocalizedString(@"audio_detail_member")] forState:UIControlStateNormal];
[vipButton addTarget:self action:@selector(vipButtonClick) forControlEvents:UIControlEventTouchUpInside];
[contentView addSubview:vipButton];
[vipButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(kMargin);
make.top.mas_equalTo(introductionView.mas_bottom).with.offset(kMargin);
make.width.mas_equalTo(SCREEN_WIDTH - 2 * kMargin);
make.height.mas_equalTo(CGFLOAT_MIN);
}];
adView = [[TFAdvertisementManager alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH - kMargin * 2, kGeometricHeight(SCREEN_WIDTH - kMargin * 2, 3, 1)) advertisementType:TFAdvertisementTypeNovel advertisementPosition:TFAdvertisementPositionNone];
adView.backgroundColor = [UIColor clearColor];
adView.userInteractionEnabled = YES;
[contentView addSubview:adView];
[adView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(kMargin);
make.width.mas_equalTo(SCREEN_WIDTH - 2 * kMargin);
make.height.mas_equalTo(kGeometricHeight(SCREEN_WIDTH - kMargin, 3, 1));
make.top.mas_equalTo(vipButton.mas_bottom).with.offset(kMargin);
make.bottom.mas_equalTo(contentView.mas_bottom).with.offset(- kMargin).priorityLow();
}];
// 展开详情后视图
introductionBottomLabel = [[UILabel alloc] init];
introductionBottomLabel.text = TFLocalizedString(@"简介");
introductionBottomLabel.textColor = kWhiteColor;
introductionBottomLabel.textAlignment = NSTextAlignmentLeft;
introductionBottomLabel.font = kBoldFont22;
introductionBottomLabel.alpha = 0;
[contentView addSubview:introductionBottomLabel];
[introductionBottomLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(kMargin);
make.top.mas_equalTo(coverImageView.mas_bottom).with.offset(kMargin);
make.width.mas_equalTo(SCREEN_WIDTH / 2);
make.height.mas_equalTo(30);
}];
packUpButton = [[TFButton alloc] initWithFrame:CGRectZero buttonTitle:TFLocalizedString(@"收起简介") buttonImageName:@"public_down_arrow" buttonIndicator:TFButtonIndicatorTitleLeft];
packUpButton.alpha = 0;
packUpButton.transformImageView = YES;
packUpButton.buttonTitleFont = kFont10;
packUpButton.buttonImageScale = 0.5;
packUpButton.graphicDistance = 3;
packUpButton.buttonTintColor = kWhiteColor;
packUpButton.backgroundColor = kColorRGBA(255, 255, 255, 0.2);
packUpButton.layer.cornerRadius = 10;
[packUpButton addTarget:self action:@selector(packUpClick) forControlEvents:UIControlEventTouchUpInside];
[contentView addSubview:packUpButton];
[packUpButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(contentView.mas_right).with.offset(- kMargin);
make.centerY.mas_equalTo(introductionBottomLabel.mas_centerY);
make.width.mas_equalTo(80);
make.height.mas_equalTo(20);
}];
self.introductionTextView = [[YYTextView alloc] init];
self.introductionTextView.editable = NO;
self.introductionTextView.textColor = kWhiteColor;
self.introductionTextView.font = kMainFont;
self.introductionTextView.alpha = 0;
self.introductionTextView.showsVerticalScrollIndicator = NO;
self.introductionTextView.showsHorizontalScrollIndicator = NO;
[contentView addSubview:self.introductionTextView];
[self.introductionTextView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(introductionBottomLabel.mas_left);
make.right.mas_equalTo(packUpButton.mas_right);
make.top.mas_equalTo(introductionBottomLabel.mas_bottom).with.offset(kHalfMargin);
make.bottom.mas_equalTo(contentView.mas_bottom).priorityLow();
}];
bottomPackUpButton = [[TFButton alloc] initWithFrame:CGRectZero buttonTitle:TFLocalizedString(@"点击收起") buttonImageName:@"public_down_arrow" buttonIndicator:TFButtonIndicatorTitleLeft];
bottomPackUpButton.alpha = 0;
bottomPackUpButton.transformImageView = YES;
bottomPackUpButton.buttonTitleFont = kMainFont;
bottomPackUpButton.buttonImageScale = 0.4;
bottomPackUpButton.graphicDistance = 5;
bottomPackUpButton.buttonTintColor = kWhiteColor;
bottomPackUpButton.backgroundColor = kBlackTransparentColor;
bottomPackUpButton.layer.cornerRadius = 20;
[bottomPackUpButton addTarget:self action:@selector(packUpClick) forControlEvents:UIControlEventTouchUpInside];
[contentView addSubview:bottomPackUpButton];
[bottomPackUpButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(contentView.mas_centerX);
make.bottom.mas_equalTo(contentView.mas_bottom).with.offset(- 2 * kMargin);
make.width.mas_equalTo(135);
make.height.mas_equalTo(40);
}];
}
- (void)setAudioModel:(TFProductionModel *)audioModel
{
_audioModel = audioModel;
collectButton.hidden = NO;
[coverImageView setImageWithURL:[NSURL URLWithString:audioModel.cover] placeholder:HoldImage options:YYWebImageOptionSetImageWithFadeAnimation completion:nil];
navTitleLabel.text = audioModel.name?:@"";
audioTitleLabel.text = audioModel.name?:@"";
hotLabel.text = audioModel.hot_num?:@"";
collectNumLabel.text = audioModel.total_favors?:@"";
authorIcon.hidden = NO;
authorLabel.text = audioModel.author.length > 0 ?audioModel.author:@"--";
NSMutableArray *tagArray = [NSMutableArray array];
for (TFTagModel *tagModel in audioModel.tag) {
[tagArray addObject:tagModel.tab];
}
tagView.text = [tagArray componentsJoinedByString:@"|"]?:@"";
[self reloadCollectionButtonState];
[vipButton mas_updateConstraints:^(MASConstraintMaker *make) {
if ([TFUserInfoManager shareInstance].isVip) {
make.top.mas_equalTo(introductionView.mas_bottom).with.offset(CGFLOAT_MIN);
make.height.mas_equalTo(CGFLOAT_MIN);
} else if (!audioModel.is_baoyue) {
make.top.mas_equalTo(introductionView.mas_bottom).with.offset(CGFLOAT_MIN);
make.height.mas_equalTo(CGFLOAT_MIN);
} else {
make.top.mas_equalTo(introductionView.mas_bottom).with.offset(kMargin);
make.height.mas_equalTo(kGeometricHeight(SCREEN_WIDTH - 2 * kMargin, 800, 90));
}
}];
adView.advertModel = audioModel;
[adView mas_updateConstraints:^(MASConstraintMaker *make) {
if (audioModel.ad_type == 0) {
make.top.mas_equalTo(vipButton.mas_bottom).with.offset(CGFLOAT_MIN);
make.height.mas_equalTo(CGFLOAT_MIN);
} else {
make.top.mas_equalTo(vipButton.mas_bottom).with.offset(kMargin);
make.height.mas_equalTo(kGeometricHeight(SCREEN_WIDTH - kMargin, audioModel.ad_width?:3, audioModel.ad_height?:1));
}
}];
[introductionBottomLabel mas_updateConstraints:^(MASConstraintMaker *make) {
if (audioModel.ad_type == 0) {
make.top.mas_equalTo(coverImageView.mas_bottom).with.offset(kMargin);
} else {
make.top.mas_equalTo(coverImageView.mas_bottom).with.offset(kHalfMargin + kMargin + kGeometricHeight(SCREEN_WIDTH - kMargin, audioModel.ad_width?:3, audioModel.ad_height?:1));
}
}];
introductionView.hidden = NO;
{
if (audioModel.production_descirption.length > 0) {
// 截取简介
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:audioModel.production_descirption?:@""];
attributedString.lineSpacing = 6;
attributedString.font = kFont12;
attributedString.color = kWhiteColor;
CGFloat maxWidth = SCREEN_WIDTH - 2 * (kMargin + kHalfMargin) - 120.0;
NSAttributedString *separatedString = [TFViewHelper getSubContentWithOriginalContent:attributedString labelWidth:maxWidth labelMaxLine:3];
introductionLabel.attributedText = separatedString;
[introductionLabel mas_updateConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(coverImageView.mas_bottom).with.offset(kMargin + kHalfMargin);
make.height.mas_equalTo([TFViewHelper boundsWithFont:kFont12 attributedText:separatedString needWidth:(SCREEN_WIDTH - 2 * (kMargin + kHalfMargin)) lineSpacing:6] + kHalfMargin);
}];
[introductionView mas_updateConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(introductionLabel.mas_top).with.offset(- kQuarterMargin);
make.bottom.mas_equalTo(introductionLabel.mas_bottom).with.offset(kQuarterMargin);
}];
moreButton.hidden = NO;
} else {
moreButton.hidden = YES;
[introductionLabel mas_updateConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(coverImageView.mas_bottom).with.offset(CGFLOAT_MIN);
make.height.mas_equalTo(CGFLOAT_MIN);
}];
[introductionView mas_updateConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(introductionLabel.mas_top).with.offset(CGFLOAT_MIN);
make.bottom.mas_equalTo(introductionLabel.mas_bottom).with.offset(CGFLOAT_MIN);
}];
}
}
NSMutableAttributedString __block *attributedString = [[NSMutableAttributedString alloc] initWithString:audioModel.production_descirption?:@""];
attributedString.lineSpacing = 8;
attributedString.font = kMainFont;
attributedString.color = kWhiteColor;
[attributedString appendString:@"\n"];
if (audioModel.horizontal_cover.length > 0) {
WS(weakSelf)
[[YYWebImageManager sharedManager] requestImageWithURL:[NSURL URLWithString:audioModel.horizontal_cover?:@""] options:YYWebImageOptionSetImageWithFadeAnimation progress:nil transform:nil completion:^(UIImage * _Nullable image, NSURL * _Nonnull url, YYWebImageFromType from, YYWebImageStage stage, NSError * _Nullable error) {
dispatch_async(dispatch_get_main_queue(), ^{
YYAnimatedImageView *imageView = nil;
if (image) {
imageView = [[YYAnimatedImageView alloc] initWithImage:image];
imageView.frame = CGRectMake(0, 0, SCREEN_WIDTH - 2 * kMargin, kGeometricHeight(SCREEN_WIDTH - 2 * kMargin, image.size.width, image.size.height));
}
NSMutableAttributedString *attachText = [NSMutableAttributedString attachmentStringWithContent:imageView contentMode:UIViewContentModeScaleAspectFit attachmentSize:imageView.frame.size alignToFont:kMainFont alignment:YYTextVerticalAlignmentCenter];
[attributedString appendAttributedString:attachText];
weakSelf.introductionTextView.attributedText = attributedString;
});
}];
} else {
self.introductionTextView.attributedText = attributedString;
}
[self layoutIfNeeded];
if (self.changeIntroductionBlock) {
if ([[TFUserInfoManager shareInstance] isVip] || !audioModel.is_baoyue) {
self.changeIntroductionBlock(adView.bottom + kHalfMargin, YES);
} else {
self.changeIntroductionBlock(adView.bottom + kHalfMargin, YES);
}
}
}
- (void)setContentOffSetY:(CGFloat)contentOffSetY
{
_contentOffSetY = contentOffSetY;
if (contentOffSetY < self.bottom - PUB_NAVBAR_HEIGHT) {
navTitleLabel.alpha = 0;
[collectButton mas_remakeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(contentView.mas_right).with.offset(- kMargin);
make.bottom.mas_equalTo(coverImageView.mas_bottom);
make.height.mas_equalTo(28);
make.width.mas_equalTo(80);
}];
} else if (contentOffSetY > 0){
navTitleLabel.alpha = 1;
[collectButton mas_remakeConstraints:^(MASConstraintMaker *make) {
//#if TF_Download_Mode && (TF_FB_Share_Mode || TF_Twitter_Share_Mode)
make.right.mas_equalTo(contentView.mas_right).with.offset(-2 *kHalfMargin - kMargin - 60);
//#elif TF_Download_Mode || TF_FB_Share_Mode || TF_Twitter_Share_Mode
// make.right.mas_equalTo(contentView.mas_right).with.offset(- kHalfMargin - kMargin - 30);
//#else
// make.right.mas_equalTo(contentView.mas_right).with.offset(- kMargin);
//#endif
make.centerY.mas_equalTo(navTitleLabel.mas_centerY);
make.height.mas_equalTo(28);
make.width.mas_equalTo(80);
}];
}
if ([[TFCollectionManager shareManagerWithProductionType:TFProductionTypeAudio] isCollectedWithProductionModel:self.audioModel]) {
[collectButton mas_updateConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo([TFViewHelper getDynamicWidthWithLabelFont:kFont12 labelHeight:28 labelText:collectButton.buttonTitle] + 20);
}];
} else {
[collectButton mas_updateConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo([TFViewHelper getDynamicWidthWithLabelFont:kFont12 labelHeight:28 labelText:collectButton.buttonTitle] + 30);
}];
}
[contentView mas_updateConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.mas_top).with.offset(contentOffSetY);
make.height.mas_equalTo(self.mas_height).with.offset(contentOffSetY);
}];
}
// 展开详情
- (void)spreadClick
{
[UIView animateWithDuration:kAnimatedDurationFast animations:^{
moreButton.alpha = 0;
introductionLabel.alpha = 0;
introductionView.alpha = 0;
vipButton.alpha = 0;
packUpButton.alpha = 1;
bottomPackUpButton.alpha = 1;
introductionBottomLabel.alpha = 1;
self.introductionTextView.alpha = 1;
}];
[adView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(kMargin);
make.width.mas_equalTo(SCREEN_WIDTH - 2 * kMargin);
if (self.audioModel.ad_type == 0) {
make.height.mas_equalTo(CGFLOAT_MIN);
} else {
make.height.mas_equalTo(kGeometricHeight(SCREEN_WIDTH - kMargin, self.audioModel.ad_width?:3, self.audioModel.ad_height?:1));
}
make.top.mas_equalTo(coverImageView.mas_bottom).with.offset(kMargin);
make.bottom.mas_equalTo(contentView.mas_bottom).with.offset(- kMargin).priorityLow();
}];
if (self.changeIntroductionBlock) {
self.changeIntroductionBlock(SCREEN_HEIGHT, NO);
}
}
// 收起详情
- (void)packUpClick
{
packUpButton.alpha = 0;
bottomPackUpButton.alpha = 0;
[UIView animateWithDuration:kAnimatedDurationFast animations:^{
moreButton.alpha = 1;
introductionLabel.alpha = 1;
introductionView.alpha = 1;
vipButton.alpha = 1;
introductionBottomLabel.alpha = 0;
self.introductionTextView.alpha = 0;
} completion:^(BOOL finished) {
if (self.changeIntroductionBlock) {
self.changeIntroductionBlock(adView.bottom + kHalfMargin, YES);
}
}];
[adView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(kMargin);
make.width.mas_equalTo(SCREEN_WIDTH - 2 * kMargin);
if (self.audioModel.ad_type == 0) {
make.top.mas_equalTo(vipButton.mas_bottom).with.offset(CGFLOAT_MIN);
make.height.mas_equalTo(CGFLOAT_MIN);
} else {
make.top.mas_equalTo(vipButton.mas_bottom).with.offset(kMargin);
make.height.mas_equalTo(kGeometricHeight(SCREEN_WIDTH - kMargin, self.audioModel.ad_width?:3, self.audioModel.ad_height?:1));
}
make.bottom.mas_equalTo(contentView.mas_bottom).with.offset(- kMargin).priorityLow();
}];
}
- (void)vipButtonClick
{
WS(weakSelf)
TFUpgradeMemberController *vc = [[TFUpgradeMemberController alloc] init];
vc.paySuccessBlock = ^{
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Audio_Check_Recommend object:[TFUtilsHelper formatStringWithInteger:[[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeAudio] getReadingRecordChapter_idWithProduction_id:weakSelf.audioModel.production_id]]];
};
[[TFViewHelper getWindowRootController] presentViewController:vc animated:YES completion:nil];
}
- (void)collectionButtonClick:(TFButton *)sender
{
if (![[TFCollectionManager shareManagerWithProductionType:TFProductionTypeAudio] isCollectedWithProductionModel:self.audioModel]) {
[[TFCollectionManager shareManagerWithProductionType:TFProductionTypeAudio] addCollectionWithProductionModel:self.audioModel];
[TFPromptManager showPromptViewWithStatus:TFPromptStatusSuccess promptTitle:TFLocalizedString(@"已加入书架")];
[self reloadCollectionButtonState];
}
[TFUtilsHelper synchronizationRackProductionWithProduction_id:self.audioModel.production_id productionType:TFProductionTypeAudio complete:nil];
}
- (void)reloadCollectionButtonState
{
if ([[TFCollectionManager shareManagerWithProductionType:TFProductionTypeAudio] isCollectedWithProductionModel:self.audioModel]) {
collectButton.buttonImageScale = 0;
collectButton.buttonTitle = TFLocalizedString(@"已收藏");
collectButton.horizontalMigration = - 3;
[collectButton selectBackgroundColor];
collectButton.tag = 2;
[collectButton mas_updateConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo([TFViewHelper getDynamicWidthWithLabelFont:kFont12 labelHeight:28 labelText:collectButton.buttonTitle] + 20);
}];
} else {
collectButton.buttonImageScale = 0.4;
collectButton.buttonTitle = TFLocalizedString(@"收藏");
collectButton.horizontalMigration = 0;
[collectButton normalBackgroundColor];
collectButton.tag = 1;
[collectButton mas_updateConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo([TFViewHelper getDynamicWidthWithLabelFont:kFont12 labelHeight:28 labelText:collectButton.buttonTitle] + 30);
}];
}
}
@end
@@ -0,0 +1,23 @@
//
// TFAudioDirectoryViewCell.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/25.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "WXYZ_DownloadManagerEnumProtocol.h"
NS_ASSUME_NONNULL_BEGIN
@interface TFAudioDirectoryViewCell : TFBasicTableViewCell
@property (nonatomic ,copy) void (^downloadChapterBlock)(NSInteger audio_id, NSInteger chapter_id, NSIndexPath *cellIndexPath);
@property (nonatomic ,strong) TFProductionChapterModel *audioDirectoryModel;
@property (nonatomic ,assign) WXYZ_ProductionDownloadState cellDownloadState;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,229 @@
//
// TFAudioDirectoryViewCell.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/25.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFAudioDirectoryViewCell.h"
#import "TFReadRecordManager.h"
#import "WXYZ_AudioDownloadManager.h"
@interface TFAudioDirectoryViewCell ()
@property (nonatomic ,strong) UILabel *titleLabel;
@property (nonatomic ,strong) UIImageView *playAmountIconView;
@property (nonatomic ,strong) UILabel *playAmountLabel;
@property (nonatomic ,strong) UIImageView *updateTimeIconView;
@property (nonatomic ,strong) UILabel *updateTimeLabel;
@property (nonatomic ,strong) UIButton *downloadBtn;
@end
@implementation TFAudioDirectoryViewCell
- (void)createSubviews
{
[super createSubviews];
self.titleLabel = [[UILabel alloc] init];
self.titleLabel.textAlignment = NSTextAlignmentLeft;
self.titleLabel.textColor = kBlackColor;
self.titleLabel.font = kMainFont;
[self.contentView addSubview:self.titleLabel];
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.contentView.mas_left).with.offset(kMargin);
make.top.mas_equalTo(self.contentView.mas_top);
make.right.mas_equalTo(self.contentView.mas_right).with.offset(-2 * kHalfMargin - 40);
make.height.mas_equalTo(kLabelHeight);
}];
self.downloadBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[self.downloadBtn setAdjustsImageWhenHighlighted:NO];
[self.downloadBtn setImageEdgeInsets:UIEdgeInsetsMake(10, 10, 10, 10)];
[self.downloadBtn setImage:[UIImage imageNamed:@"audio_download"] forState:UIControlStateNormal];
[self.downloadBtn addTarget:self action:@selector(downloadBtnClick:) forControlEvents:UIControlEventTouchUpInside];
[self.contentView addSubview:self.downloadBtn];
[self.downloadBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(self.contentView.mas_right).with.offset(- kHalfMargin);
make.centerY.mas_equalTo(self.contentView.mas_centerY);
make.height.width.mas_equalTo(40);
}];
self.playAmountIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"audio_directory_readtime"]];
[self.contentView addSubview:self.playAmountIconView];
[self.playAmountIconView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.titleLabel.mas_left);
make.top.mas_equalTo(self.titleLabel.mas_bottom).with.offset(kHalfMargin);
make.height.mas_equalTo(12);
make.width.mas_equalTo(CGFLOAT_MIN);
make.bottom.mas_equalTo(self.contentView.mas_bottom).with.offset(- kMargin).priorityLow();
}];
self.playAmountLabel = [[UILabel alloc] init];
self.playAmountLabel.font = kFont11;
self.playAmountLabel.textColor = kGrayTextColor;
[self.contentView addSubview:self.playAmountLabel];
[self.playAmountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.playAmountIconView.mas_right).with.offset(kQuarterMargin);
make.centerY.mas_equalTo(self.playAmountIconView.mas_centerY);
make.height.mas_equalTo(self.playAmountIconView.mas_height);
make.width.mas_equalTo(CGFLOAT_MIN);
}];
self.updateTimeIconView = [[UIImageView alloc] init];
self.updateTimeIconView.image = [UIImage imageNamed:@"audio_directory_updatetime"];
[self.contentView addSubview:self.updateTimeIconView];
[self.updateTimeIconView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.playAmountLabel.mas_right).with.offset(kHalfMargin);
make.centerY.mas_equalTo(self.playAmountLabel.mas_centerY);
make.height.mas_equalTo(self.playAmountIconView.mas_height);
make.width.mas_equalTo(CGFLOAT_MIN);
}];
self.updateTimeLabel = [[UILabel alloc] init];
self.updateTimeLabel.font = kFont11;
self.updateTimeLabel.textColor = kGrayTextColor;
[self.contentView addSubview:self.updateTimeLabel];
[self.updateTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.updateTimeIconView.mas_right).with.offset(kQuarterMargin);
make.right.mas_equalTo(self.downloadBtn.mas_left);
make.centerY.mas_equalTo(self.updateTimeIconView.mas_centerY);
make.height.mas_equalTo(self.updateTimeIconView.mas_height);
}];
}
- (void)setAudioDirectoryModel:(TFProductionChapterModel *)audioDirectoryModel
{
if (_audioDirectoryModel != audioDirectoryModel) {
_audioDirectoryModel = audioDirectoryModel;
self.titleLabel.text = audioDirectoryModel.chapter_title ? : @"";
if (audioDirectoryModel.play_num > 0) {
self.playAmountIconView.hidden = NO;
[self.playAmountIconView mas_updateConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(12);
}];
self.playAmountLabel.text = audioDirectoryModel.play_num ? : @"";
self.playAmountLabel.hidden = NO;
[self.playAmountLabel mas_updateConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo([TFViewHelper getDynamicWidthWithLabel:self.playAmountLabel]);
}];
} else {
self.playAmountIconView.hidden = YES;
[self.playAmountIconView mas_updateConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.titleLabel.mas_left);
make.width.mas_equalTo(CGFLOAT_MIN);
}];
self.playAmountLabel.hidden = YES;
[self.playAmountLabel mas_updateConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.playAmountIconView.mas_right);
make.width.mas_equalTo(CGFLOAT_MIN);
}];
}
if (audioDirectoryModel.update_time.length > 0) {
self.updateTimeIconView.hidden = NO;
[self.updateTimeIconView mas_updateConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(12);
}];
self.updateTimeLabel.text = audioDirectoryModel.update_time ? : @"";
self.updateTimeLabel.hidden = NO;
} else {
self.updateTimeIconView.hidden = YES;
[self.updateTimeIconView mas_updateConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(CGFLOAT_MIN);
}];
self.updateTimeLabel.hidden = YES;
}
}
if ([[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeAudio] isCurrentPlayingChapterWithProduction_id:audioDirectoryModel.production_id chapter_id:audioDirectoryModel.chapter_id] &&
[[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeAudio] isCurrentPlayingProductionWithProduction_id:audioDirectoryModel.production_id]) {
self.titleLabel.textColor = kMainColor;
} else if ([[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeAudio] chapterHasReadedWithProduction_id:audioDirectoryModel.production_id chapter_id:audioDirectoryModel.chapter_id]) {
self.titleLabel.textColor = kGrayTextColor;
} else {
self.titleLabel.textColor = kBlackColor;
}
[self changeDownloadButtonState];
}
- (void)setCellDownloadState:(WXYZ_ProductionDownloadState)cellDownloadState
{
if (_cellDownloadState != cellDownloadState) {
_cellDownloadState = cellDownloadState;
[self changeDownloadButtonState];
}
}
- (void)changeDownloadButtonState
{
switch (_cellDownloadState) {
case WXYZ_ProductionDownloadStateNormal: {
if (self.audioDirectoryModel.is_preview == 1) {
[self.downloadBtn setImage:[UIImage imageNamed:TFLocalizedString(@"audio_download_vip")] forState:UIControlStateNormal];
} else {
[self.downloadBtn setImage:[UIImage imageNamed:@"audio_download"] forState:UIControlStateNormal];
}
}
break;
case WXYZ_ProductionDownloadStateDownloading: {
[self.downloadBtn setImage:[UIImage imageNamed:@"audio_downloading"] forState:UIControlStateNormal];
}
break;
case WXYZ_ProductionDownloadStateDownloaded: {
[self.downloadBtn setImage:[UIImage imageNamed:@"audio_downloaded"] forState:UIControlStateNormal];
}
break;
case WXYZ_ProductionDownloadStateFail: {
[self.downloadBtn setImage:[UIImage imageNamed:@"audio_download_fail"] forState:UIControlStateNormal];
}
break;
default:
break;
}
}
- (void)downloadBtnClick:(UIButton *)sender
{
if (([[WXYZ_AudioDownloadManager sharedManager] getChapterDownloadStateWithProduction_id:self.audioDirectoryModel.production_id chapter_id:self.audioDirectoryModel.chapter_id] == WXYZ_ProductionDownloadStateDownloading) || ([[WXYZ_AudioDownloadManager sharedManager] getChapterDownloadStateWithProduction_id:self.audioDirectoryModel.production_id chapter_id:self.audioDirectoryModel.chapter_id] == WXYZ_ProductionDownloadStateDownloaded)) {
return;
}
if (self.downloadChapterBlock) {
self.downloadChapterBlock(self.audioDirectoryModel.production_id, self.audioDirectoryModel.chapter_id, self.index);
}
}
@end
@@ -0,0 +1,24 @@
//
// TFAudioRecommendedViewCell.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/25.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFProductionListViewCell.h"
NS_ASSUME_NONNULL_BEGIN
@class TFAudioContentModel;
@interface TFAudioRecommendedViewCell : TFProductionListViewCell
@property (nonatomic ,copy) void(^clickBlock)(NSInteger production_id);
- (void)setListModel:(TFAudioContentModel *)listModel;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,107 @@
//
// TFAudioRecommendedViewCell.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/25.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFAudioRecommendedViewCell.h"
#import "TFCollectionManager.h"
#import "TFAudioRecommendedModel.h"
@interface TFAudioRecommendedViewCell ()
@property (nonatomic ,strong) UILabel *playAmountLabel;
@property (nonatomic ,strong) UIButton *collectionBtn;
@end
@implementation TFAudioRecommendedViewCell
- (void)createSubviews
{
[super createSubviews];
self.tagboardView.hidden = YES;
self.authorLabel.textColor = kMainColor;
UIImageView *playAmountIconView = [[UIImageView alloc] init];
playAmountIconView.image = [UIImage imageNamed:@"audio_directory_readtime"];
[self.contentView addSubview:playAmountIconView];
[playAmountIconView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.authorLabel.mas_right).with.offset(kHalfMargin);
make.centerY.mas_equalTo(self.authorLabel.mas_centerY);
make.height.mas_equalTo(10);
make.width.mas_equalTo(10);
}];
self.playAmountLabel = [[UILabel alloc] init];
self.playAmountLabel.font = kFont12;
self.playAmountLabel.textColor = kGrayTextColor;
[self.contentView addSubview:self.playAmountLabel];
[self.playAmountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(playAmountIconView.mas_right).with.offset(kQuarterMargin);
make.centerY.mas_equalTo(playAmountIconView.mas_centerY);
make.height.mas_equalTo(30);
make.width.mas_equalTo(CGFLOAT_MIN);
}];
self.collectionBtn = [UIButton buttonWithType:UIButtonTypeCustom];
self.collectionBtn.layer.cornerRadius = 10;
self.collectionBtn.layer.borderColor = kMainColor.CGColor;
self.collectionBtn.layer.borderWidth = 0.4;
[self.collectionBtn addTarget:self action:@selector(collectionBtnClick:) forControlEvents:UIControlEventTouchUpInside];
[self.collectionBtn setTitle:TFLocalizedString(@"收藏") forState:UIControlStateNormal];
[self.collectionBtn setTitleColor:kMainColor forState:UIControlStateNormal];
[self.collectionBtn.titleLabel setFont:kFont11];
[self.contentView addSubview:self.collectionBtn];
[self.collectionBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(self.contentView.mas_right).with.offset(- kHalfMargin);
make.centerY.mas_equalTo(playAmountIconView.mas_centerY);
make.width.mas_equalTo(60);
make.height.mas_equalTo(20);
}];
}
- (void)setListModel:(TFAudioContentModel *)listModel
{
[super setProductionModel:listModel];
self.authorLabel.text = listModel.finished ? : @"";
[self.authorLabel mas_updateConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo([TFViewHelper getDynamicWidthWithLabel:self.authorLabel]);
}];
self.playAmountLabel.text = [NSString stringWithFormat:@"%zd", listModel.total_views];
[self.playAmountLabel mas_updateConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo([TFViewHelper getDynamicWidthWithLabel:self.playAmountLabel]);
}];
if ([[TFCollectionManager shareManagerWithProductionType:TFProductionTypeAudio] isCollectedWithProduction_id:self.productionModel.production_id]) {
[self.collectionBtn setTitle:TFLocalizedString(@"已收藏") forState:UIControlStateNormal];
} else {
[self.collectionBtn setTitle:TFLocalizedString(@"收藏") forState:UIControlStateNormal];
}
}
- (void)collectionBtnClick:(UIButton *)sender
{
if ([[TFCollectionManager shareManagerWithProductionType:TFProductionTypeAudio] isCollectedWithProduction_id:self.productionModel.production_id]) {
return;
}
if ([[TFCollectionManager shareManagerWithProductionType:TFProductionTypeAudio] addCollectionWithProductionModel:self.productionModel]) {
[self.collectionBtn setTitle:TFLocalizedString(@"已收藏") forState:UIControlStateNormal];
[TFPromptManager showPromptViewWithStatus:TFPromptStatusSuccess promptTitle:TFLocalizedString(@"已加入书架")];
} else {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:TFLocalizedString(@"加入书架失败")];
}
[TFUtilsHelper synchronizationRackProductionWithProduction_id:self.productionModel.production_id productionType:TFProductionTypeAudio complete:nil];
}
@end
@@ -0,0 +1,24 @@
//
// TFComicDetailLeftViewController.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/19.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFComicDetailModel.h"
NS_ASSUME_NONNULL_BEGIN
typedef void(^PushToComicDetailBlock)(NSInteger production_id);
@interface TFComicDetailLeftViewController : TFBasicViewController
@property (nonatomic ,assign) BOOL canScroll;
@property (nonatomic ,strong) TFComicDetailModel *detailModel;
@property (nonatomic ,copy) PushToComicDetailBlock pushToComicDetailBlock;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,341 @@
//
// TFComicDetailLeftViewController.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/19.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFComicDetailLeftViewController.h"
#import "TFCommentsViewController.h"
#import "TFComicDetailIntroductionCell.h"
#import "TFCommentsViewCell.h"
#import "TFBookStoreComicNormalStyleCell.h"
#import "TFPublicAdvertisementViewCell.h"
@interface TFComicDetailLeftViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic ,strong) UIButton *sectionBottomCommentButton;
@property (nonatomic ,strong) NSArray *sectionTagArray;
@end
@implementation TFComicDetailLeftViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[self initialize];
[self createSubviews];
}
- (void)initialize
{
[self hiddenNavigationBar:YES];
self.view.backgroundColor = [UIColor whiteColor];
}
- (void)createSubviews
{
self.mainTableViewGroup.delegate = self;
self.mainTableViewGroup.dataSource = self;
[self.view addSubview:self.mainTableViewGroup];
[self.mainTableViewGroup mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.view);
}];
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (!self.canScroll) {
scrollView.contentOffset = CGPointZero;
}
if (scrollView.contentOffset.y <= 0) {
self.canScroll = NO;
scrollView.contentOffset = CGPointZero;
//到顶通知父视图改变状态
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Can_Leave_Top object:@YES];
} else {
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Can_Leave_Top object:@NO];
}
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
NSMutableArray *t_sectionTagArray = [NSMutableArray array];
// 简介
if (self.detailModel.productionModel.production_descirption.length > 0) {
[t_sectionTagArray addObject:@"descirption"];
}
// 广告
if (self.detailModel.advert.ad_type != 0) {
[t_sectionTagArray addObject:@"ad"];
}
// 评论
#if TF_Comments_Mode
[t_sectionTagArray addObject:@"comment"];
#endif
// 猜你喜欢
if (self.detailModel.label.count > 0) {
[t_sectionTagArray addObject:@"label"];
}
self.sectionTagArray = [t_sectionTagArray copy];
return t_sectionTagArray.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if ([[self.sectionTagArray objectAtIndex:section] isEqualToString:@"descirption"]) {
return 1;
}
if ([[self.sectionTagArray objectAtIndex:section] isEqualToString:@"ad"]) {
return 1;
}
#if TF_Comments_Mode
if ([[self.sectionTagArray objectAtIndex:section] isEqualToString:@"comment"]) {
return self.detailModel.comment.count;
}
#endif
if ([[self.sectionTagArray objectAtIndex:section] isEqualToString:@"label"]) {
return self.detailModel.label.count;
}
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([[self.sectionTagArray objectAtIndex:indexPath.section] isEqualToString:@"descirption"]) {
return [self createIntroductionStyleCellWithTableView:tableView indexPath:indexPath labelModel:self.detailModel.productionModel];
}
if ([[self.sectionTagArray objectAtIndex:indexPath.section] isEqualToString:@"ad"]) {
return [self createAdCellWithTableView:tableView indexPath:indexPath];
}
#if TF_Comments_Mode
if ([[self.sectionTagArray objectAtIndex:indexPath.section] isEqualToString:@"comment"]) {
TFCommentsListModel *commentModel = [self.detailModel.comment objectOrNilAtIndex:indexPath.row];
return [self createCommentCellWithTableView:tableView indexPath:indexPath labelModel:commentModel];
}
#endif
if ([[self.sectionTagArray objectAtIndex:indexPath.section] isEqualToString:@"label"]) {
TFBookStoreLabelModel *labelModel = [self.detailModel.label objectOrNilAtIndex:indexPath.row];
return [self createNormalStyleComicCellWithTableView:tableView indexPath:indexPath labelModel:labelModel];
}
return [[UITableViewCell alloc] init];
}
- (UITableViewCell *)createIntroductionStyleCellWithTableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath labelModel:(TFProductionModel *)comicModel
{
static NSString *cellName = @"TFComicDetailIntroductionCell";
TFComicDetailIntroductionCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName];
if (!cell) {
cell = [[TFComicDetailIntroductionCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
}
cell.comicModel = comicModel;
return cell;
}
- (UITableViewCell *)createNormalStyleComicCellWithTableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath labelModel:(TFBookStoreLabelModel *)labelModel
{
WS(weakSelf)
static NSString *cellName = @"TFBookStoreComicNormalStyleCell";
TFBookStoreComicNormalStyleCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName];
if (!cell) {
cell = [[TFBookStoreComicNormalStyleCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
}
cell.labelModel = labelModel;
cell.cellDidSelectItemBlock = ^(NSInteger production_id) {
if (weakSelf.pushToComicDetailBlock) {
weakSelf.pushToComicDetailBlock(production_id);
}
};
return cell;
}
- (UITableViewCell *)createCommentCellWithTableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath labelModel:(TFCommentsListModel *)commentModel
{
static NSString *cellName = @"TFCommentsViewCell";
TFCommentsViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName];
if (!cell) {
cell = [[TFCommentsViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
}
cell.commentModel = commentModel;
[cell setIsPreview:YES lastRow:(self.detailModel.comment.count - 1 == indexPath.row)];
cell.hiddenEndLine = NO;
return cell;
}
- (UITableViewCell *)createAdCellWithTableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath
{
static NSString *cellName = @"TFPublicAdvertisementViewCell";
TFPublicAdvertisementViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName];
if (!cell) {
cell = [[TFPublicAdvertisementViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
}
[cell setAdModel:self.detailModel.advert refresh:NO];
cell.mainTableView = tableView;
return cell;
}
//section头部间距
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
#if TF_Comments_Mode
if ([[self.sectionTagArray objectAtIndex:section] isEqualToString:@"comment"]) {
return 54;
}
#endif
return CGFLOAT_MIN;
}
//section头部视图
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, CGFLOAT_MIN)];
view.backgroundColor = kWhiteColor;
if ([[self.sectionTagArray objectAtIndex:section] isEqualToString:@"comment"]) {
view.frame = CGRectMake(0, 0, SCREEN_WIDTH, 54);
if (self.detailModel.advert.ad_type == 0) {
UIView *grayLine = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 10)];
grayLine.backgroundColor = kGrayViewColor;
[view addSubview:grayLine];
}
UIImageView *mainTitleHoldView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"comic_label_hold"]];
mainTitleHoldView.frame = CGRectMake(kHalfMargin, 10 + 22 - kMargin / 2, kMargin, kMargin);
[view addSubview:mainTitleHoldView];
UILabel *t_title = [[UILabel alloc] initWithFrame:CGRectMake(kMargin + kHalfMargin + kQuarterMargin, 10, SCREEN_WIDTH - kMargin, 44)];
t_title.textAlignment = NSTextAlignmentLeft;
t_title.textColor = kBlackColor;
t_title.backgroundColor = [UIColor whiteColor];
t_title.font = kBoldFont16;
t_title.text = TFLocalizedString(@"最新书评");
[t_title addBorderLineWithBorderWidth:0.5 borderColor:kGrayLineColor cornerRadius:0 borderType:UIBorderSideTypeBottom];
[view addSubview:t_title];
UIButton *commentButton = [UIButton buttonWithType:UIButtonTypeCustom];
CGFloat width = [TFViewHelper getDynamicWidthWithLabelFont:kFont12 labelHeight:43.0 labelText:TFLocalizedString(@"写评论") maxWidth:SCREEN_WIDTH / 2.0 - kMargin];
commentButton.frame = CGRectMake(SCREEN_WIDTH - width - kHalfMargin, 10, width, 43);
commentButton.backgroundColor = [UIColor whiteColor];
[commentButton setTitle:TFLocalizedString(@"写评论") forState:UIControlStateNormal];
[commentButton setTitleColor:kMainColor forState:UIControlStateNormal];
[commentButton.titleLabel setFont:kFont12];
[commentButton addTarget:self action:@selector(commentClick) forControlEvents:UIControlEventTouchUpInside];
[view addSubview:commentButton];
}
return view;
}
//section底部间距
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
#if TF_Comments_Mode
if ([[self.sectionTagArray objectAtIndex:section] isEqualToString:@"comment"]) {
return 64;
}
#endif
return CGFLOAT_MIN;
}
//section底部视图
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, CGFLOAT_MIN)];
view.backgroundColor = kWhiteColor;
if ([[self.sectionTagArray objectAtIndex:section] isEqualToString:@"comment"]) {
if (self.detailModel.productionModel.total_comment == 0) {
[self.sectionBottomCommentButton setTitle:TFLocalizedString(@"暂无评论,点击抢沙发") forState:UIControlStateNormal];
} else {
[self.sectionBottomCommentButton setTitle:[NSString stringWithFormat:@"%@(%@%@)", TFLocalizedString(@"查看全部评论"), [TFUtilsHelper formatStringWithInteger:self.detailModel.productionModel.total_comment], TFLocalizedString(@"")] forState:UIControlStateNormal];
}
[view addSubview:self.sectionBottomCommentButton];
UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.sectionBottomCommentButton.frame) + kHalfMargin, SCREEN_WIDTH, 10)];
lineView.backgroundColor = kGrayViewColor;
[view addSubview:lineView];
}
return view;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([[self.sectionTagArray objectAtIndex:indexPath.section] isEqualToString:@"comment"]) {
[self commentWithComment_id:[[self.detailModel.comment objectOrNilAtIndex:indexPath.row] comment_id]];
}
}
- (void)commentClick
{
[self commentWithComment_id:0];
}
- (void)commentWithComment_id:(NSInteger)comment_id
{
WS(weakSelf)
TFCommentsViewController *vc = [[TFCommentsViewController alloc] init];
vc.production_id = self.detailModel.productionModel.production_id;
vc.comment_id = comment_id;
vc.productionType = TFProductionTypeComic;
vc.commentsSuccessBlock = ^(TFCommentsListModel *commentModel) {
NSMutableArray *array = [weakSelf.detailModel.comment mutableCopy];
[array insertObject:commentModel atIndex:0];
weakSelf.detailModel.comment = [array copy];
weakSelf.detailModel.productionModel.total_comment ++;
[weakSelf.mainTableViewGroup reloadData];
};
[self.navigationController pushViewController:vc animated:YES];
}
- (UIButton *)sectionBottomCommentButton
{
if (!_sectionBottomCommentButton) {
_sectionBottomCommentButton = [UIButton buttonWithType:UIButtonTypeCustom];
_sectionBottomCommentButton.frame = CGRectMake(SCREEN_WIDTH / 4, kHalfMargin, SCREEN_WIDTH / 2 + kMargin, 36);
_sectionBottomCommentButton.backgroundColor = [UIColor whiteColor];
_sectionBottomCommentButton.layer.cornerRadius = 18;
_sectionBottomCommentButton.layer.borderColor = kMainColor.CGColor;
_sectionBottomCommentButton.layer.borderWidth = 0.4f;
[_sectionBottomCommentButton setTitleColor:kMainColor forState:UIControlStateNormal];
[_sectionBottomCommentButton.titleLabel setFont:kFont12];
[_sectionBottomCommentButton addTarget:self action:@selector(commentClick) forControlEvents:UIControlEventTouchUpInside];
}
return _sectionBottomCommentButton;
}
- (void)setDetailModel:(TFComicDetailModel *)detailModel
{
_detailModel = detailModel;
[self.mainTableViewGroup reloadData];
}
@end
@@ -0,0 +1,21 @@
//
// TFComicDetailRightViewController.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/19.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface TFComicDetailRightViewController : TFBasicViewController
@property (nonatomic ,assign) BOOL canScroll;
@property (nonatomic ,assign) CGFloat contentOffSetY;
@property (nonatomic ,strong) TFProductionModel *comicModel;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,342 @@
//
// TFComicDetailRightViewController.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/19.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFComicDetailRightViewController.h"
#import "TFComicDetailRightViewCell.h"
#import "TFComicBrowseViewController.h"
#import "TFReadRecordManager.h"
#define MenuButtonHeight 50
@interface TFComicDetailRightViewController ()<UITableViewDelegate, UITableViewDataSource>
{
TFButton *gotoCurrent;
TFButton *gotoEnd;
CGFloat beginOffSetY;
BOOL clickGotoButton;
}
@property (nonatomic, strong) UILabel *headTitleLabel;
@property (nonatomic, strong) TFButton *sortButton;
/// 已阅读章节索引
@property (nonatomic, assign) NSInteger readIndex;
@end
@implementation TFComicDetailRightViewController
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.mainTableView reloadData];
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self initialize];
[self createSubviews];
}
- (void)initialize
{
// 计算已读章节的位置
NSInteger readIndex = [[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeComic] getReadingRecordChapter_idWithProduction_id:self.comicModel.production_id];
NSArray<NSNumber *> *t_arr = [self.comicModel.chapter_list valueForKeyPath:@"chapter_id"];
self.readIndex = [t_arr indexOfObject:@(readIndex)];
if (self.readIndex == NSNotFound) {
self.readIndex = -1;
}
[self hiddenNavigationBar:YES];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadRecordData) name:NSNotification_Updata_Read_Record object:nil];
}
- (void)createSubviews
{
self.mainTableView.delegate = self;
self.mainTableView.dataSource = self;
[self.view addSubview:self.mainTableView];
[self.mainTableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.view);
}];
gotoCurrent = [[TFButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - MenuButtonHeight - kHalfMargin, SCREEN_HEIGHT - Comic_Detail_HeaderView_Height - PUB_TABBAR_HEIGHT - 44 - 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 - Comic_Detail_HeaderView_Height - PUB_TABBAR_HEIGHT - 44 - 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];
[self setEmptyOnView:self.mainTableView title:TFLocalizedString(@"暂无目录列表") buttonTitle:@"" tapBlock:^{}];
if (self.comicModel.chapter_list.count == 0) {
gotoCurrent.hidden = YES;
gotoEnd.hidden = YES;
self.sortButton.hidden = YES;
self.headTitleLabel.hidden = YES;
} else {
gotoCurrent.hidden = NO;
gotoEnd.hidden = NO;
self.sortButton.hidden = NO;
self.headTitleLabel.hidden = NO;
}
dispatch_async(dispatch_get_main_queue(), ^{
[self.mainTableView xtfei_endLoading];
});
}
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
beginOffSetY = scrollView.contentOffset.y;
clickGotoButton = NO;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if (!clickGotoButton) {
if ([scrollView isEqual:self.mainTableView]) {
if (!self.canScroll) {
scrollView.contentOffset = CGPointZero;
}
if (scrollView.contentOffset.y <= 0) {
self.canScroll = NO;
scrollView.contentOffset = CGPointZero;
//到顶通知父视图改变状态
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Can_Leave_Top object:@YES];
} else {
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Can_Leave_Top object:@NO];
}
}
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;
}
}
}
- (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;
}
}
- (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;
}
}
}
- (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;
}
}
- (void)setContentOffSetY:(CGFloat)contentOffSetY
{
gotoCurrent.frame = CGRectMake(SCREEN_WIDTH - MenuButtonHeight - kHalfMargin, SCREEN_HEIGHT - Comic_Detail_HeaderView_Height - PUB_TABBAR_HEIGHT - 44 - 44 - MenuButtonHeight - kMargin - kHalfMargin + contentOffSetY, MenuButtonHeight, MenuButtonHeight);
gotoEnd.frame = CGRectMake(SCREEN_WIDTH - MenuButtonHeight - kHalfMargin, SCREEN_HEIGHT - Comic_Detail_HeaderView_Height - PUB_TABBAR_HEIGHT - 44 - 44 - kMargin + contentOffSetY, MenuButtonHeight, MenuButtonHeight);
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.comicModel.chapter_list.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
TFProductionChapterModel *t_chapterList = [self.comicModel.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 44;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 44)];
view.backgroundColor = [UIColor whiteColor];
[view addSubview:self.headTitleLabel];
[view addSubview:self.sortButton];
return view;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
self.readIndex = indexPath.row;
TFProductionChapterModel *t_chapterModel = [self.comicModel.chapter_list objectOrNilAtIndex:indexPath.row];
[[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeComic] addReadingRecordWithProduction_id:t_chapterModel.production_id chapter_id:t_chapterModel.chapter_id chapterTitle:t_chapterModel.chapter_title];
TFComicBrowseViewController *vc = [[TFComicBrowseViewController alloc] init];
vc.comicProductionModel = self.comicModel;
vc.chapter_id = t_chapterModel.chapter_id;
[self.navigationController pushViewController:vc animated:YES];
}
#pragma mark - 点击事件
- (void)changeDirectorySort:(TFButton *)sender
{
if (self.comicModel.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.comicModel.chapter_list = [[self.comicModel.chapter_list reverseObjectEnumerator] allObjects];
// 计算已读章节的位置
NSInteger readIndex = [[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeComic] getReadingRecordChapter_idWithProduction_id:self.comicModel.production_id];
NSArray<NSNumber *> *t_arr = [self.comicModel.chapter_list valueForKeyPath:@"chapter_id"];
self.readIndex = [t_arr indexOfObject:@(readIndex)];
if (self.readIndex == NSNotFound) {
self.readIndex = -1;
}
[self.mainTableView reloadData];
}
- (void)gotoCurrentClick:(UIButton *)sender
{
if (self.comicModel.chapter_list.count == 0) return;
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Directory_Move object:@"bottom"];
if (self.readIndex != -1) {
[self.mainTableView scrollToRow:self.readIndex inSection:0 atScrollPosition:UITableViewScrollPositionTop animated:YES];
}
}
- (void)gotoEndClick:(UIButton *)sender
{
if (self.comicModel.chapter_list.count == 0) return;
clickGotoButton = YES;
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Can_Leave_Top object:@NO];
if (sender.tag == 0) {
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Directory_Move object:@"bottom"];
[self.mainTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:self.comicModel.chapter_list.count - 1 inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:YES];
gotoEnd.buttonImageName = @"comic_goto_top";
gotoEnd.buttonTitle = TFLocalizedString(@"到顶");
gotoEnd.tag = 1;
} else {
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Directory_Move object:@"top"];
[self.mainTableView setContentOffset:CGPointMake(0,0) animated:YES];
gotoEnd.buttonImageName = @"comic_goto_bottom";
gotoEnd.buttonTitle = TFLocalizedString(@"到底");
gotoEnd.tag = 0;
}
}
#pragma mark - 懒加载
- (UILabel *)headTitleLabel
{
if (!_headTitleLabel) {
_headTitleLabel = [[UILabel alloc] init];
_headTitleLabel.text = self.comicModel.flag?:@"";
_headTitleLabel.frame = CGRectMake(kHalfMargin, 0, SCREEN_WIDTH - kMargin, 44);
_headTitleLabel.font = kFont11;
_headTitleLabel.textColor = kGrayTextColor;
_headTitleLabel.textAlignment = NSTextAlignmentLeft;
}
return _headTitleLabel;
}
- (TFButton *)sortButton
{
if (!_sortButton) {
CGFloat width = [TFViewHelper getDynamicWidthWithLabelFont:kFont11 labelHeight:30.0 labelText:TFLocalizedString(@"正序") maxWidth:SCREEN_WIDTH / 2.0 - kMargin];
width += kLabelHeight;
_sortButton = [[TFButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - kHalfMargin - width, 7, 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)setComicModel:(TFProductionModel *)comicModel
{
_comicModel = comicModel;
if (self.sortButton.tag == 1) {
self.comicModel.chapter_list = [[comicModel.chapter_list reverseObjectEnumerator] allObjects];
}
[self reloadRecordData];
}
- (void)reloadRecordData
{
[self.mainTableView reloadData];
}
@end
@@ -0,0 +1,22 @@
//
// TFComicDetailViewController.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/19.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFBasicViewController.h"
NS_ASSUME_NONNULL_BEGIN
#define Comic_Detail_HeaderView_Height (round(SCREEN_WIDTH * 0.8) - 50.0)
@interface TFComicDetailViewController : TFBasicViewController
@property (nonatomic ,assign) NSInteger comic_id;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,435 @@
//
// TFComicDetailViewController.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/19.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFComicDetailViewController.h"
#import "TFComicBrowseViewController.h"
#import "TFComicDownloadViewController.h"
#import "TFTaskViewController.h"
#import "TFComicDetailHeaderView.h"
#import "TFComicDetailFooterView.h"
#import "WXYZ_CompositeEmbeddedTableView.h"
#import "TFComicDetailModel.h"
#import "TFComicCatalogueModel.h"
#import "TFReadRecordManager.h"
#import "TFShareManager.h"
#import "WXYZ_DownloadHelper.h"
@interface TFComicDetailViewController ()<UITableViewDelegate, UITableViewDataSource>
{
UIButton *menuButton;
UILabel *menuTitle;
}
@property (nonatomic ,assign) BOOL canScroll;
// 是否到顶 到底
@property (nonatomic ,assign) BOOL isAutoScroll;
@property (nonatomic ,strong) UIView *bottomMenuBar;
@property (nonatomic ,strong) UIButton *shareButton;
@property (nonatomic ,strong) UIButton *downloadButton;
@property (nonatomic ,strong) TFComicDetailHeaderView *headerView;
@property (nonatomic ,strong) TFComicDetailFooterView *footerView;
@property (nonatomic ,strong) TFComicDetailModel *comicDetailModel;
@property (nonatomic ,strong) WXYZ_CompositeEmbeddedTableView *mallTableView;
@end
@implementation TFComicDetailViewController
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Hidden_Tabbar object:nil];
[self setStatusBarLightContentStyle];
[self reloadToolBarState];
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Hidden_Tabbar object:nil];
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self initialize];
[self createSubviews];
[self netRequest];
}
- (void)initialize
{
[self hiddenSeparator];
self.navigationBar.backgroundColor = [UIColor clearColor];
self.navigationBar.navTitleLabel.alpha = 0;
self.navigationBar.navTitleLabel.textColor = kWhiteColor;
[self.navigationBar setLightLeftButton];
self.shareButton = [UIButton buttonWithType:UIButtonTypeCustom];
self.shareButton.adjustsImageWhenHighlighted = NO;
self.shareButton.tintColor = kWhiteColor;
self.shareButton.hidden = YES;
[self.shareButton setImage:[[UIImage imageNamed:@"comic_share"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
[self.shareButton setImageEdgeInsets:UIEdgeInsetsMake(4, 4, 3, 3)];
[self.shareButton addTarget:self action:@selector(shareButtonClick:) forControlEvents:UIControlEventTouchUpInside];
[self.navigationBar addSubview:self.shareButton];
[self.shareButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(self.view.mas_right).with.offset(- kMargin);
make.centerY.mas_equalTo(self.navigationBar.navTitleLabel.mas_centerY);
make.width.height.mas_equalTo(30);
}];
#if TF_Download_Mode
self.downloadButton = [UIButton buttonWithType:UIButtonTypeCustom];
self.downloadButton.adjustsImageWhenHighlighted = NO;
self.downloadButton.tintColor = kWhiteColor;
self.downloadButton.hidden = YES;
[self.downloadButton setImage:[[UIImage imageNamed:@"comic_download"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
[self.downloadButton setImageEdgeInsets:UIEdgeInsetsMake(3, 3, 3, 3)];
[self.downloadButton addTarget:self action:@selector(downloadButtonClick) forControlEvents:UIControlEventTouchUpInside];
[self.navigationBar addSubview:self.downloadButton];
[self.downloadButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(self.shareButton.mas_left).with.offset(- kHalfMargin);
make.centerY.mas_equalTo(self.navigationBar.navTitleLabel.mas_centerY);
make.width.height.mas_equalTo(30);
}];
#endif
self.canScroll = YES;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeScrollStatus:) name:Notification_Can_Leave_Top object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(scrollMove:) name:Notification_Directory_Move object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(catalogRequest) name:Notification_Production_Pay_Success object:nil];
}
- (void)createSubviews
{
self.mallTableView = [[WXYZ_CompositeEmbeddedTableView alloc] initWithFrame:CGRectMake(1, 1, 1, 1) style:UITableViewStylePlain];
self.mallTableView.delegate = self;
self.mallTableView.dataSource = self;
[self.mallTableView addObserver:self forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionNew context:nil];
[self.view addSubview:self.mallTableView];
[self.mallTableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.top.mas_equalTo(0);
make.width.mas_equalTo(self.view.mas_width);
make.height.mas_equalTo(self.view.mas_height);
}];
self.headerView = [[TFComicDetailHeaderView alloc] init];
self.headerView.frame = CGRectMake(0, 0, SCREEN_WIDTH, Comic_Detail_HeaderView_Height);
[self.mallTableView setTableHeaderView:self.headerView];
[self.headerView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.top.mas_equalTo(0);
make.width.mas_equalTo(SCREEN_WIDTH);
make.height.mas_equalTo(Comic_Detail_HeaderView_Height);
}];
WS(weakSelf)
self.footerView = [[TFComicDetailFooterView alloc] init];
self.footerView.view.hidden = YES;
self.footerView.view.frame = CGRectMake(0, Comic_Detail_HeaderView_Height, SCREEN_WIDTH, SCREEN_HEIGHT - (Comic_Detail_HeaderView_Height));
self.footerView.pushToComicDetailBlock = ^(NSInteger production_id) {
TFComicDetailViewController *vc = [[TFComicDetailViewController alloc] init];
vc.comic_id = production_id;
[weakSelf.navigationController pushViewController:vc animated:YES];
};
[self.mallTableView setTableFooterView:self.footerView.view];
[self addChildViewController:self.footerView];
self.bottomMenuBar = [[UIView alloc] init];
self.bottomMenuBar.hidden = YES;
self.bottomMenuBar.backgroundColor = kGrayViewColor;
[self.view addSubview:self.bottomMenuBar];
[self.bottomMenuBar mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.bottom.mas_equalTo(self.view.mas_bottom);
make.width.mas_equalTo(self.view.mas_width);
make.height.mas_equalTo(PUB_TABBAR_HEIGHT);
}];
menuButton = [UIButton buttonWithType:UIButtonTypeCustom];
menuButton.backgroundColor = kMainColor;
[menuButton setTitle:TFLocalizedString(@"开始阅读") forState:UIControlStateNormal];
[menuButton setTitleColor:kWhiteColor forState:UIControlStateNormal];
[menuButton.titleLabel setFont:[UIFont boldSystemFontOfSize:kFontSize13]];
[menuButton addTarget:self action:@selector(startReading) forControlEvents:UIControlEventTouchUpInside];
[self.bottomMenuBar addSubview:menuButton];
[menuButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(self.bottomMenuBar.mas_right);
make.top.mas_equalTo(0);
make.height.mas_equalTo(PUB_TABBAR_HEIGHT - PUB_TABBAR_OFFSET);
make.width.mas_equalTo(120);
}];
menuTitle = [[UILabel alloc] init];
menuTitle.textColor = kBlackColor;
menuTitle.textAlignment = NSTextAlignmentLeft;
menuTitle.font = kFont13;
[self.bottomMenuBar addSubview:menuTitle];
[menuTitle mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(kMargin);
make.top.mas_equalTo(0);
make.right.mas_equalTo(menuButton.mas_left);
make.height.mas_equalTo(PUB_TABBAR_HEIGHT - PUB_TABBAR_OFFSET);
}];
}
- (void)scrollMove:(NSNotification *)noti
{
self.isAutoScroll = YES;
if ([noti.object isEqualToString:@"top"]) {
self.footerView.canScroll = NO;
self.canScroll = YES;
self.mallTableView.contentOffset = CGPointMake(0, 0);
} else {
self.footerView.canScroll = YES;
self.canScroll = NO;
self.mallTableView.contentOffset = CGPointMake(0, Comic_Detail_HeaderView_Height - PUB_NAVBAR_HEIGHT);
}
}
- (void)changeScrollStatus:(NSNotification *)noti
{
self.canScroll = [noti.object boolValue];
}
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
self.isAutoScroll = NO;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if (self.isAutoScroll) {
return;
}
if (scrollView.contentOffset.y <= Comic_Detail_HeaderView_Height - PUB_NAVBAR_HEIGHT) {
if (self.canScroll) {
self.canScroll = YES;
self.footerView.canScroll = NO;
if (scrollView.contentOffset.y <= 0) {
scrollView.contentOffset = CGPointMake(0, 0);
}
} else {
scrollView.contentOffset = CGPointMake(0, Comic_Detail_HeaderView_Height - PUB_NAVBAR_HEIGHT);
}
} else {
self.canScroll = NO;
scrollView.contentOffset = CGPointMake(0, Comic_Detail_HeaderView_Height - PUB_NAVBAR_HEIGHT);
self.footerView.canScroll = YES;
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
return [[UITableViewCell alloc] init];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return CGFLOAT_MIN;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return CGFLOAT_MIN;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return CGFLOAT_MIN;
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context
{
if ([keyPath isEqualToString:@"contentOffset"]) {
CGPoint point = [((NSValue *)[self.mallTableView valueForKey:@"contentOffset"]) CGPointValue];
if (self.canScroll) {
self.footerView.contentOffSetY = point.y;
} else {
self.footerView.contentOffSetY = Comic_Detail_HeaderView_Height - PUB_NAVBAR_HEIGHT;
}
[self changeHeaderViewAlpha:point.y];
}
}
- (void)changeHeaderViewAlpha:(CGFloat)contentOffsetY
{
if (contentOffsetY >= 120) {
contentOffsetY = 120;
}
if (contentOffsetY <= 0) {
contentOffsetY = 0;
}
CGFloat viewAlpha = (120 - contentOffsetY) / 120;
self.headerView.headerViewAlpha = viewAlpha;
self.navigationBar.navTitleLabel.alpha = 1 - viewAlpha;
}
#pragma mark - 点击事件
#if TF_Download_Mode
- (void)downloadButtonClick
{
if (self.comicDetailModel.productionModel.chapter_list.count == 0) {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:TFLocalizedString(@"章节正在更新中")];
return;
}
TFComicDownloadViewController *vc = [[TFComicDownloadViewController alloc] init];
vc.comicModel = self.comicDetailModel.productionModel;
[self.navigationController pushViewController:vc animated:YES];
}
#endif
- (void)shareButtonClick:(UIButton *)sender
{
NSInteger chapter_id = [[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeComic] getReadingRecordChapter_idWithProduction_id:self.comic_id];
[TFShareManager shareWithProduction_id:NSStringFromInteger(self.comic_id) chapter_id:NSStringFromInteger(chapter_id) type:TFShareTypeComic];
}
- (void)startReading
{
if (self.comicDetailModel.productionModel.chapter_list.count == 0) {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:TFLocalizedString(@"章节正在更新中")];
return;
}
[TFTaskViewController taskReadRequestWithProduction_id:self.comic_id];
TFComicBrowseViewController *vc = [[TFComicBrowseViewController alloc] init];
vc.comicProductionModel = self.comicDetailModel.productionModel;
vc.chapter_id = [[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeComic] getReadingRecordChapter_idWithProduction_id:self.comic_id];
if (vc.chapter_id == 0) {// 如果没有阅读记录默认阅读第一章
TFProductionChapterModel *t_model = self.comicDetailModel.productionModel.chapter_list.firstObject;
if ([t_model.display_order isEqualToString:@"0"]) {// 判断一下目录的
vc.chapter_id = t_model.chapter_id;
} else {
vc.chapter_id = self.comicDetailModel.productionModel.chapter_list.lastObject.chapter_id;
}
}
[self.navigationController pushViewController:vc animated:YES];
}
- (void)reloadToolBarState
{
if ([[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeComic] productionHasReadedWithProduction_id:self.comicDetailModel.productionModel.production_id]) {
menuTitle.text = [[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeComic] getReadingRecordChapterTitleWithProduction_id:self.comicDetailModel.productionModel.production_id]?:@"";
[menuButton setTitle:TFLocalizedString(@"继续阅读") forState:UIControlStateNormal];
[menuButton mas_updateConstraints:^(MASConstraintMaker *make) {
if (menuButton.intrinsicContentSize.width + kMargin > 120.0) {
make.width.mas_equalTo(menuButton.intrinsicContentSize.width + kMargin);
} else {
make.width.mas_equalTo(120.0);
}
}];
} else {
if (self.comicDetailModel.productionModel.chapter_list.count > 0) {
TFProductionChapterModel *t_chapterList = [self.comicDetailModel.productionModel.chapter_list objectOrNilAtIndex:0];
menuTitle.text = t_chapterList.chapter_title?:@"";
} else {
menuTitle.text = self.comicDetailModel.productionModel.name?:@"";
}
[menuButton setTitle:TFLocalizedString(@"开始阅读") forState:UIControlStateNormal];
[menuButton mas_updateConstraints:^(MASConstraintMaker *make) {
if (menuButton.intrinsicContentSize.width + kMargin > 120.0) {
make.width.mas_equalTo(menuButton.intrinsicContentSize.width + kMargin);
} else {
make.width.mas_equalTo(120.0);
}
}];
}
[self.headerView reloadHeaderView];
}
- (void)netRequest
{
if ([TFNetworkManager networkingStatus] == NO) {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:TFLocalizedString(@"当前无网络连接")];
return;
}
WS(weakSelf)
[TFNetworkTools POST:Comic_Detail parameters:@{@"comic_id":[TFUtilsHelper formatStringWithInteger:self.comic_id]} model:TFComicDetailModel.class success:^(BOOL isSuccess, TFComicDetailModel * _Nullable t_model, TFNetworkRequestModel * _Nonnull requestModel) {
if (isSuccess) {
[weakSelf.navigationBar setNavigationBarTitle:t_model.productionModel.name?:@""];
weakSelf.comicDetailModel = t_model;
}
weakSelf.bottomMenuBar.hidden = NO;
weakSelf.footerView.view.hidden = NO;
weakSelf.downloadButton.hidden = NO;
weakSelf.shareButton.hidden = NO;
[weakSelf catalogRequest];
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
[weakSelf catalogRequest];
}];
}
- (void)catalogRequest
{
WS(weakSelf)
[TFNetworkTools POST:Comic_Catalog parameters:@{@"comic_id":[TFUtilsHelper formatStringWithInteger:self.comic_id]} model:TFComicCatalogueModel.class success:^(BOOL isSuccess, TFComicCatalogueModel *_Nullable t_model, TFNetworkRequestModel * _Nonnull requestModel) {
if (isSuccess) {
weakSelf.comicDetailModel.productionModel.chapter_list = t_model.chapter_list;
weakSelf.headerView.comicProductionModel = weakSelf.comicDetailModel.productionModel;
weakSelf.footerView.detailModel = weakSelf.comicDetailModel;
// 存储作品信息
[[WXYZ_DownloadHelper sharedManager] recordDownloadProductionWithProductionModel:weakSelf.comicDetailModel.productionModel productionType:TFProductionTypeComic];
dispatch_async(dispatch_get_main_queue(), ^{
[weakSelf reloadToolBarState];
});
} else {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:requestModel.msg ?:TFLocalizedString(@"获取失败")];
}
dispatch_async(dispatch_get_main_queue(), ^{
[weakSelf.mallTableView reloadData];
});
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
[TFPromptManager showPromptWithError:error defaultText:TFLocalizedString(@"获取失败")];
}];
}
- (void)dealloc
{
@try {
[self.mallTableView removeObserver:self forKeyPath:@"contentOffset" context:NULL];
} @catch (NSException *exception) {
}
}
@end
@@ -0,0 +1,19 @@
//
// TFComicCatalogueModel.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/19.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface TFComicCatalogueModel : NSObject
@property (nonatomic ,strong) NSArray <TFProductionChapterModel *>*chapter_list;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,25 @@
//
// TFComicCatalogueModel.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/19.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFComicCatalogueModel.h"
@implementation TFComicCatalogueModel
+ (NSDictionary<NSString *,id> *)modelContainerPropertyGenericClass
{
return @{@"chapter_list" : [TFProductionChapterModel class]};
}
+ (NSDictionary *)modelCustomPropertyMapper
{
return @{
@"production_id" : @[@"book_id", @"comic_id", @"audio_id"]
};
}
@end
@@ -0,0 +1,24 @@
//
// TFComicDetailModel.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/19.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@class TFProductionModel, TFBookStoreLabelModel, TFCommentsListModel;
@interface TFComicDetailModel : NSObject
@property (nonatomic ,strong) TFProductionModel *productionModel;
@property (nonatomic ,strong) NSArray <TFCommentsListModel *>*comment;
@property (nonatomic ,strong) NSArray <TFBookStoreLabelModel *>*label;
@property (nonatomic ,strong) TFAdvertModel *advert;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,30 @@
//
// TFComicDetailModel.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/19.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFComicDetailModel.h"
#import "TFBookStoreLabelModel.h"
@implementation TFComicDetailModel
+ (NSDictionary<NSString *,id> *)modelContainerPropertyGenericClass
{
return @{@"comment" : [TFCommentsListModel class],
@"label" : [TFBookStoreLabelModel class],
@"advert" : [TFAdvertModel class],
@"productionModel":[TFProductionModel class]
};
}
+ (NSDictionary *)modelCustomPropertyMapper
{
return @{
@"productionModel" :@"comic"
};
}
@end
@@ -0,0 +1,28 @@
//
// TFComicDetailFooterView.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/19.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFComicDetailModel.h"
NS_ASSUME_NONNULL_BEGIN
typedef void(^PushToComicDetailBlock)(NSInteger production_id);
@interface TFComicDetailFooterView : TFBasicViewController
@property (nonatomic, strong) TFComicDetailModel *detailModel;
@property (nonatomic, assign) BOOL canScroll;
@property (nonatomic, assign) CGFloat contentOffSetY;
@property (nonatomic, copy) PushToComicDetailBlock pushToComicDetailBlock;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,89 @@
//
// TFComicDetailFooterView.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/19.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFComicDetailFooterView.h"
#import "TFComicDetailLeftViewController.h"
#import "TFComicDetailRightViewController.h"
@interface TFComicDetailFooterView () <SGPageTitleViewDelegate, SGPageContentCollectionViewDelegate>
{
TFComicDetailLeftViewController *leftVC;
TFComicDetailRightViewController *rightVC;
}
@property (nonatomic, strong) SGPageTitleView *pageTitleView;
@property (nonatomic, strong) SGPageContentCollectionView *pageContentCollectionView;
@end
@implementation TFComicDetailFooterView
- (void)viewDidLoad
{
[super viewDidLoad];
[self hiddenNavigationBar:YES];
[self createSubViews];
}
- (void)createSubViews
{
WS(weakSelf)
leftVC = [[TFComicDetailLeftViewController alloc] init];
leftVC.pushToComicDetailBlock = ^(NSInteger production_id) {
if (weakSelf.pushToComicDetailBlock) {
weakSelf.pushToComicDetailBlock(production_id);
}
};
rightVC = [[TFComicDetailRightViewController alloc] init];
NSArray *childArr = @[leftVC, rightVC];
NSArray *titleArr = @[TFLocalizedString(@"详情"), TFLocalizedString(@"目录")];
self.pageContentCollectionView = [[SGPageContentCollectionView alloc] initWithFrame:CGRectMake(0, 44.6, self.view.width, SCREEN_HEIGHT - PUB_NAVBAR_HEIGHT - PUB_TABBAR_OFFSET - 44 - 44.6 - kQuarterMargin) parentVC:self childVCs:childArr];
self.pageContentCollectionView.delegatePageContentCollectionView = self;
[self.view addSubview:self.pageContentCollectionView];
self.pageConfigure.bottomSeparatorColor = kGrayLineColor;
self.pageConfigure.titleFont = kMainFont;
self.pageTitleView = [SGPageTitleView pageTitleViewWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 44) delegate:self titleNames:titleArr configure:self.pageConfigure];
self.pageTitleView.backgroundColor = [UIColor whiteColor];
[self.view addSubview:self.pageTitleView];
}
- (void)setDetailModel:(TFComicDetailModel *)detailModel
{
_detailModel = detailModel;
leftVC.detailModel = self.detailModel;
rightVC.comicModel = self.detailModel.productionModel;
}
- (void)setCanScroll:(BOOL)canScroll
{
leftVC.canScroll = canScroll;
rightVC.canScroll = canScroll;
}
- (void)setContentOffSetY:(CGFloat)contentOffSetY
{
rightVC.contentOffSetY = contentOffSetY;
}
- (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];
}
@end
@@ -0,0 +1,24 @@
//
// TFComicDetailHeaderView.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/19.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFComicDetailModel.h"
NS_ASSUME_NONNULL_BEGIN
@interface TFComicDetailHeaderView : UIView
@property (nonatomic ,strong) TFProductionModel *comicProductionModel;
@property (nonatomic ,assign) CGFloat headerViewAlpha;
- (void)reloadHeaderView;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,290 @@
//
// TFComicDetailHeaderView.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/19.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFComicDetailHeaderView.h"
#import "TFTagboardView.h"
#import "TFCollectionManager.h"
#import "UIView+AZGradient.h"
#import "UIImage+Blur.h"
@interface TFComicDetailHeaderView ()
{
UIView *backFrostedGlassView;
UIView *tagBottomView;
UIImageView *comicCoverImageView;
UILabel *comicTitleLabel;
UIButton *collectButton;
UILabel *hotLabel;
UILabel *authorLabel;
UILabel *collectNumLabel;
TFTagboardView *tagView;
UIVisualEffectView *effectView;
}
@property (nonatomic ,weak) UIImageView *backHoldImageView;
@end
@implementation TFComicDetailHeaderView
- (instancetype)init
{
if (self = [super init]) {
[self createSubViews];
}
return self;
}
- (void)createSubViews
{
UIImageView *backHoldImageView = [[UIImageView alloc] init];
self.backHoldImageView = backHoldImageView;
backHoldImageView.image = HoldImage;
backHoldImageView.contentMode = UIViewContentModeScaleAspectFill;
backHoldImageView.clipsToBounds = YES;
[self addSubview:backHoldImageView];
[backHoldImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.top.mas_equalTo(0);
make.width.mas_equalTo(SCREEN_WIDTH);
make.height.mas_equalTo(Comic_Detail_HeaderView_Height);
}];
backFrostedGlassView = [[UIView alloc] init];
[self addSubview:backFrostedGlassView];
[backFrostedGlassView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(backHoldImageView);
}];
effectView = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleDark]];
effectView.alpha = 0;
[self addSubview:effectView];
[effectView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(backHoldImageView);
}];
tagBottomView = [[UIView alloc] init];
tagBottomView.backgroundColor = kWhiteColor;
tagBottomView.layer.cornerRadius = 20;
[self addSubview:tagBottomView];
[tagBottomView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.bottom.mas_equalTo(self.mas_bottom).with.offset(kMargin);
make.width.mas_equalTo(self.mas_width);
make.height.mas_equalTo(80 + kMargin);
}];
comicCoverImageView = [[UIImageView alloc] initWithCornerRadiusAdvance:8 rectCornerType:UIRectCornerAllCorners];
comicCoverImageView.image = HoldImage;
comicCoverImageView.contentMode = UIViewContentModeScaleAspectFill;
[comicCoverImageView zy_attachBorderWidth:2 color:kWhiteColor];
[self addSubview:comicCoverImageView];
[comicCoverImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.mas_left).with.offset(kMargin);
make.bottom.mas_equalTo(self.mas_bottom).with.offset(- kQuarterMargin);
make.width.mas_equalTo((255) / 2);
make.height.mas_equalTo(kGeometricHeight((255) / 2, 3, 4));
}];
comicTitleLabel = [[UILabel alloc] init];
comicTitleLabel.textColor = kWhiteColor;
comicTitleLabel.textAlignment = NSTextAlignmentLeft;
comicTitleLabel.font = kBoldFont22;
[self addSubview:comicTitleLabel];
[comicTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(comicCoverImageView.mas_right).with.offset(kHalfMargin);
make.top.mas_equalTo(comicCoverImageView.mas_top);
make.right.mas_equalTo(self.mas_right).with.offset(- kHalfMargin);
make.height.mas_equalTo(30);
}];
collectButton = [UIButton buttonWithType:UIButtonTypeCustom];
collectButton.backgroundColor = kMainColor;
collectButton.layer.cornerRadius = 12;
collectButton.hidden = YES;
[collectButton setTitle:TFLocalizedString(@"+收藏") forState:UIControlStateNormal];
[collectButton setTitleColor:kWhiteColor forState:UIControlStateNormal];
[collectButton.titleLabel setFont:kFont12];
[collectButton addTarget:self action:@selector(collectionClick:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:collectButton];
[collectButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(self.mas_right).with.offset(- kMargin);
make.bottom.mas_equalTo(tagBottomView.mas_top).with.offset(- kHalfMargin);
make.height.mas_equalTo(24);
make.width.mas_equalTo(70.0);
}];
collectNumLabel = [[UILabel alloc] init];
collectNumLabel.backgroundColor = [UIColor clearColor];
collectNumLabel.textColor = kWhiteColor;
collectNumLabel.textAlignment = NSTextAlignmentLeft;
collectNumLabel.font = kMainFont;
[self addSubview:collectNumLabel];
[collectNumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(comicCoverImageView.mas_right).with.offset(kHalfMargin);
make.bottom.mas_equalTo(collectButton.mas_bottom);
make.right.mas_equalTo(collectButton.mas_left).with.offset(-kQuarterMargin);
make.height.mas_equalTo(20);
}];
hotLabel = [[UILabel alloc] init];
hotLabel.backgroundColor = [UIColor clearColor];
hotLabel.textColor = kWhiteColor;
hotLabel.textAlignment = NSTextAlignmentLeft;
hotLabel.font = kMainFont;
[self addSubview:hotLabel];
[hotLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(comicCoverImageView.mas_right).with.offset(kHalfMargin);
make.bottom.mas_equalTo(collectNumLabel.mas_top).with.offset(- kQuarterMargin);
make.right.mas_equalTo(self.mas_right).with.offset(- kHalfMargin);
make.height.mas_equalTo(collectNumLabel.mas_height);
}];
authorLabel = [[UILabel alloc] init];
authorLabel.backgroundColor = [UIColor clearColor];
authorLabel.textColor = kWhiteColor;
authorLabel.textAlignment = NSTextAlignmentLeft;
authorLabel.font = kMainFont;
[self addSubview:authorLabel];
[authorLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(comicCoverImageView.mas_right).with.offset(kHalfMargin);
make.bottom.mas_equalTo(hotLabel.mas_top).with.offset(- kQuarterMargin);
make.right.mas_equalTo(self.mas_right).with.offset(- kHalfMargin);
make.height.mas_equalTo(collectNumLabel.mas_height);
}];
tagView = [[TFTagboardView alloc] init];
tagView.textAlignment = TFTagboardTextAlignmentLeft;
tagView.borderStyle = TFTagboardBorderStyleFill;
tagView.layoutStyle = TFTagboardLayoutStyleScroll;
tagView.spacing = 15;
tagView.cornerRadius = 8.5;
[self addSubview:tagView];
[tagView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(comicCoverImageView.mas_right).with.offset(kHalfMargin);
make.top.mas_equalTo(tagBottomView.mas_top).with.offset(kHalfMargin);
make.right.mas_equalTo(self.mas_right).with.offset(- kMargin);
make.height.mas_equalTo(20);
}];
}
- (void)setComicProductionModel:(TFProductionModel *)comicProductionModel
{
if (_comicProductionModel != comicProductionModel) {
_comicProductionModel = comicProductionModel;
collectButton.hidden = NO;
WS(weakSelf)
[[YYWebImageManager sharedManager] requestImageWithURL:[NSURL URLWithString:comicProductionModel.horizontal_cover.length > 0 ?comicProductionModel.horizontal_cover:comicProductionModel.vertical_cover] options:YYWebImageOptionSetImageWithFadeAnimation progress:nil transform:nil completion:^(UIImage * _Nullable image, NSURL * _Nonnull url, YYWebImageFromType from, YYWebImageStage stage, NSError * _Nullable error) {
dispatch_async(dispatch_get_main_queue(), ^{
SS(strongSelf)
weakSelf.backHoldImageView.image = [image imgWithLightAlpha:0.4 radius:3 colorSaturationFactor:1.8];
strongSelf->backFrostedGlassView.backgroundColor = kColorRGBA(0, 0, 0, 0.4);
});
}];
[comicCoverImageView setImageWithURL:[NSURL URLWithString:comicProductionModel.vertical_cover] placeholder:HoldImage options:YYWebImageOptionSetImageWithFadeAnimation completion:nil];
comicTitleLabel.attributedText = [self formatAttributedText:comicProductionModel.name];
hotLabel.attributedText = [self formatAttributedText:comicProductionModel.hot_num];
collectNumLabel.attributedText = [self formatAttributedText:comicProductionModel.total_favors];
authorLabel.attributedText = [self formatAttributedText:comicProductionModel.author];
tagView.tagboardArray = comicProductionModel.tag;
if ([[TFCollectionManager shareManagerWithProductionType:TFProductionTypeComic] isCollectedWithProductionModel:comicProductionModel]) {
collectButton.tag = 1;
collectButton.backgroundColor = [kMainColor colorWithAlphaComponent:0.75];
[collectButton setTitle:TFLocalizedString(@"已收藏") forState:UIControlStateNormal];
} else {
collectButton.tag = 0;
collectButton.backgroundColor = kMainColor;
[collectButton setTitle:TFLocalizedString(@"+收藏") forState:UIControlStateNormal];
}
}
}
- (NSAttributedString *)formatAttributedText:(NSString *)normalText
{
// NSShadow *shadow = [[NSShadow alloc] init];
// shadow.shadowBlurRadius = 6.0;
// shadow.shadowOffset = CGSizeMake(0, 0);
// shadow.shadowColor = [UIColor blackColor];
NSMutableAttributedString *authorAttString = [[NSMutableAttributedString alloc] initWithString:normalText?:@""];
// [authorAttString addAttribute:NSShadowAttributeName value:shadow range:NSMakeRange(0, authorAttString.length)];
return authorAttString;
}
- (void)setHeaderViewAlpha:(CGFloat)headerViewAlpha
{
_headerViewAlpha = headerViewAlpha;
[tagBottomView mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(80 * headerViewAlpha);
}];
comicCoverImageView.alpha = headerViewAlpha;
comicTitleLabel.alpha = headerViewAlpha;
collectButton.alpha = headerViewAlpha;
hotLabel.alpha = headerViewAlpha;
collectNumLabel.alpha = headerViewAlpha;
authorLabel.alpha = headerViewAlpha;
tagView.alpha = headerViewAlpha;
backFrostedGlassView.alpha = headerViewAlpha;
effectView.alpha = 1 - headerViewAlpha;
}
- (void)reloadHeaderView
{
if (![[TFCollectionManager shareManagerWithProductionType:TFProductionTypeComic] isCollectedWithProductionModel:self.comicProductionModel]) {
collectButton.backgroundColor = kMainColor;
[collectButton setTitle:TFLocalizedString(@"+收藏") forState:UIControlStateNormal];
} else {
collectButton.backgroundColor = [kMainColor colorWithAlphaComponent:0.75];
[collectButton setTitle:TFLocalizedString(@"已收藏") forState:UIControlStateNormal];
}
}
- (void)collectionClick:(UIButton *)sender
{
if (![[TFCollectionManager shareManagerWithProductionType:TFProductionTypeComic] isCollectedWithProductionModel:self.comicProductionModel]) {
[TFUtilsHelper synchronizationRackProductionWithProduction_id:self.comicProductionModel.production_id productionType:TFProductionTypeComic complete:nil];
if ([[TFCollectionManager shareManagerWithProductionType:TFProductionTypeComic] addCollectionWithProductionModel:self.comicProductionModel]) {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusSuccess promptTitle:TFLocalizedString(@"已加入书架")];
}
[self reloadHeaderView];
}
}
@end
@@ -0,0 +1,20 @@
//
// TFComicDetailIntroductionCell.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/19.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFComicDetailModel.h"
NS_ASSUME_NONNULL_BEGIN
@interface TFComicDetailIntroductionCell : TFBasicTableViewCell
@property (nonatomic ,strong) TFProductionModel *comicModel;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,95 @@
//
// TFComicDetailIntroductionCell.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/19.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFComicDetailIntroductionCell.h"
@interface TFComicDetailIntroductionCell ()
{
UILabel *introductionLabel;
UILabel *introductionContent;
}
@end
@implementation TFComicDetailIntroductionCell
- (void)createSubviews
{
[super createSubviews];
introductionLabel = [[UILabel alloc] init];
introductionLabel.text = TFLocalizedString(@"作品简介");
introductionLabel.textColor = kGrayTextDeepColor;
introductionLabel.textAlignment = NSTextAlignmentLeft;
introductionLabel.font = kMainFont;
[self.contentView addSubview:introductionLabel];
[introductionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.contentView.mas_left).with.offset(kMargin);
make.top.mas_equalTo(self.contentView.mas_top).with.offset(kMargin);
make.right.mas_equalTo(self.contentView.mas_right).with.offset(- kMargin);
make.height.mas_equalTo(0.0);
}];
introductionContent = [[UILabel alloc] init];
introductionContent.textColor = kGrayTextColor;
introductionContent.textAlignment = NSTextAlignmentLeft;
introductionContent.font = kFont12;
introductionContent.numberOfLines = 0;
[self.contentView addSubview:introductionContent];
[introductionContent mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(introductionLabel.mas_left);
make.top.mas_equalTo(self.contentView.mas_top).offset(kHalfMargin);
make.right.mas_equalTo(introductionLabel.mas_right);
}];
UIView *splitLine = [[UIView alloc] init];
splitLine.backgroundColor = [UIColor clearColor];
[self.contentView addSubview:splitLine];
[splitLine mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(0.1);
make.right.bottom.left.equalTo(self.contentView);
make.top.equalTo(introductionContent.mas_bottom).offset(kHalfMargin).priorityLow();
}];
}
- (void)setComicModel:(TFProductionModel *)comicModel
{
if (_comicModel != comicModel) {
_comicModel = comicModel;
if (comicModel.production_descirption.length > 0) {
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:comicModel.production_descirption?:@""];
attributedString.lineSpacing = 6;
attributedString.font = kFont12;
attributedString.color = kGrayTextColor;
YYTextLayout *layout = [YYTextLayout layoutWithContainerSize:CGSizeMake(SCREEN_WIDTH - 2 * kMargin, MAXFLOAT) text:attributedString];
if (layout.rowCount < 5) {
introductionContent.attributedText = attributedString;
} else {
// 截取前5行的内容
YYTextLine *lastLine = layout.lines[4];
NSMutableAttributedString *t_atr = [[attributedString attributedSubstringFromRange:NSMakeRange(0, lastLine.range.location + lastLine.range.length)] mutableCopy];
// 截取第5行一半的内容
CGFloat maxWidth = (SCREEN_WIDTH - 2 * kMargin) / 2.0;
if (lastLine.lineWidth > maxWidth) {
// 获取多出来的距离
CGFloat spacing = lastLine.lineWidth - maxWidth;
// 获取多余的文字个数(多余的间距 / 单个字的宽度)
NSInteger number = spacing / (lastLine.lineWidth / lastLine.range.length);
t_atr = [[t_atr attributedSubstringFromRange:NSMakeRange(0, t_atr.length - number - 1)] mutableCopy];
[t_atr appendString:@" ..."];
}
introductionContent.attributedText = t_atr;
}
}
}
}
@end
@@ -0,0 +1,20 @@
//
// TFComicDetailRightViewCell.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/19.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFReadRecordManager.h"
NS_ASSUME_NONNULL_BEGIN
@interface TFComicDetailRightViewCell : TFBasicTableViewCell
@property (nonatomic ,strong) TFProductionChapterModel *chapterModel;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,116 @@
//
// TFComicDetailRightViewCell.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/19.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFComicDetailRightViewCell.h"
#import "TFProductionCoverView.h"
@interface TFComicDetailRightViewCell ()
{
TFProductionCoverView *comicCoverImageView;
UILabel *comicTitleLabel;
UILabel *comicSubTitleLabel;
UIView *grayMask;
UIImageView *currentReadImageView;
}
@end
@implementation TFComicDetailRightViewCell
- (void)createSubviews
{
[super createSubviews];
self.selectionStyle = UITableViewCellSelectionStyleNone;
comicCoverImageView = [[TFProductionCoverView alloc] initWithProductionType:TFProductionTypeComic coverDirection:TFProductionCoverDirectionHorizontal];
[self.contentView addSubview:comicCoverImageView];
[comicCoverImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.contentView.mas_left).with.offset(kHalfMargin);
make.top.mas_equalTo(self.contentView.mas_top).with.offset(kHalfMargin * 0.8);
make.width.mas_equalTo(self.contentView.mas_width).multipliedBy(0.4).with.offset(- kMargin - kHalfMargin);
make.height.mas_equalTo(kGeometricHeight(((SCREEN_WIDTH * 0.4) - kMargin - kHalfMargin), 5, 3));
make.bottom.mas_equalTo(self.contentView.mas_bottom).with.offset(- kHalfMargin * 0.8).priorityLow();
}];
comicTitleLabel = [[UILabel alloc] init];
comicTitleLabel.textColor = kBlackColor;
comicTitleLabel.textAlignment = NSTextAlignmentLeft;
comicTitleLabel.font = kMainFont;
[self.contentView addSubview:comicTitleLabel];
[comicTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(comicCoverImageView.mas_right).with.offset(kHalfMargin);
make.top.mas_equalTo(comicCoverImageView.mas_top);
make.right.mas_equalTo(self.contentView.mas_right).with.offset(- kHalfMargin);
make.height.mas_equalTo(30);
}];
comicSubTitleLabel = [[UILabel alloc] init];
comicSubTitleLabel.textColor = kGrayTextColor;
comicSubTitleLabel.textAlignment = NSTextAlignmentLeft;
comicSubTitleLabel.font = kFont12;
[self.contentView addSubview:comicSubTitleLabel];
[comicSubTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(comicTitleLabel.mas_left);
make.bottom.mas_equalTo(comicCoverImageView.mas_bottom);
make.right.mas_equalTo(comicTitleLabel.mas_right);
make.height.mas_equalTo(20);
}];
grayMask = [[UIView alloc] init];
grayMask.backgroundColor = kWhiteColor;
grayMask.alpha = 0;
grayMask.userInteractionEnabled = YES;
[self.contentView addSubview:grayMask];
[grayMask mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.contentView);
}];
currentReadImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"comic_current_read"]];
currentReadImageView.hidden = YES;
[self.contentView addSubview:currentReadImageView];
[currentReadImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.contentView.mas_top).with.offset(kHalfMargin);
make.right.mas_equalTo(self.contentView.mas_right);
make.width.height.mas_equalTo(20);
}];
}
- (void)setChapterModel:(TFProductionChapterModel *)chapterModel
{
_chapterModel = chapterModel;
comicCoverImageView.coverImageUrl = chapterModel.cover;
comicCoverImageView.is_locked = chapterModel.is_preview;
comicTitleLabel.text = chapterModel.chapter_title?:@"";
comicSubTitleLabel.text = chapterModel.subtitle?:@"";
if ([[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeComic] getReadingRecordChapter_idWithProduction_id:chapterModel.production_id] == chapterModel.chapter_id) {
self.contentView.backgroundColor = kGrayLineColor;
grayMask.alpha = 0.7;
currentReadImageView.hidden = NO;
} else if ([[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeComic] chapterHasReadedWithProduction_id:chapterModel.production_id chapter_id:chapterModel.chapter_id]) {
self.contentView.backgroundColor = kGrayLineColor;
grayMask.alpha = 0.7;
currentReadImageView.hidden = YES;
} else {
self.contentView.backgroundColor = kWhiteColor;
grayMask.alpha = 0;
currentReadImageView.hidden = YES;
}
}
@end
@@ -0,0 +1,22 @@
//
// TFNovelDetailViewController.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/19.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFBasicViewController.h"
NS_ASSUME_NONNULL_BEGIN
@interface TFNovelDetailViewController : TFBasicViewController
@property (nonatomic ,assign) NSInteger book_id; //书籍id
/// 是不是从阅读器进入
@property (nonatomic ,assign) BOOL isReader;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,905 @@
//
// TFNovelDetailViewController.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/19.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFNovelDetailViewController.h"
#import "TFCommentsViewController.h"
#import "TFTaskViewController.h"
#import "TFNovelCatalogueBookmarkController.h"
#import "TFNovelDetailHeaderView.h"
#import "TFBookStoreNovelStyleOneCell.h"
#import "TFBookStoreNovelStyleTwoCell.h"
#import "TFBookStoreNovelStyleThreeCell.h"
#import "TFBookStoreNovelStyleFourCell.h"
#import "TFCommentsViewCell.h"
#import "TFPublicAdvertisementViewCell.h"
#import "TFReadNovelViewController.h"
#import "TFCollectionManager.h"
#import "TFReadRecordManager.h"
#import "WXYZ_BookDownloadManager.h"
#import "TFReaderBookManager.h"
#import "TFNovelDetailModel.h"
#import "TFReaderSettingHelper.h"
#import "TFCatalogModel.h"
#import "TFShareManager.h"
#import "AppDelegate.h"
#import "TFNovelDownloadMenuView.h"
#import "TFDownloadCacheViewController.h"
#import "WXYZ_BookAiPlayPageViewController.h"
@interface TFNovelDetailViewController ()<UITableViewDelegate, UITableViewDataSource
#if TF_Enable_Third_Party_Ad
,BUBannerAdViewDelegate>
#else
>
#endif
@property (nonatomic ,strong) TFNovelDetailModel *bookDetailModel;
@property (nonatomic ,strong) UIView *commentSectionView;
@property (nonatomic ,strong) UIButton *sectionBottomCommentButton;
@property (nonatomic ,weak) UIButton *shareButton;
@property (nonatomic ,strong) UIButton *readBookButton;
@property (nonatomic ,weak) UIButton *addBookRack;
@property (nonatomic ,weak) UIButton *downloadButton;
@property (nonatomic ,strong) NSArray *sectionTagArray;
@property (nonatomic ,assign) BOOL needRefresh;
@end
@implementation TFNovelDetailViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[self initialize];
[self createSubviews];
[self netRequest];
}
- (void)initialize
{
self.needRefresh = YES;
[self hiddenSeparator];
[self setStatusBarLightContentStyle];
self.navigationBar.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:0];
self.navigationBar.navTitleLabel.textColor = kBlackColor;
self.navigationBar.navTitleLabel.alpha = 0.0;
[self.navigationBar setLightLeftButton];
#if TF_Enable_Ai
[WXYZ_BookAiPlayPageViewController sharedManager];
#endif
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self changeNavBarColorState:self.mainTableViewGroup.contentOffset.y withAnimate:NO];
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Hidden_Tabbar object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pushToDownload) name:Notification_Push_To_Download object:nil];
if (self.addBookRack) {
if ([[TFCollectionManager shareManagerWithProductionType:TFProductionTypeNovel] isCollectedWithProductionModel:self.bookDetailModel.bookModel]) {
self.addBookRack.enabled = NO;
[self.addBookRack setTitle:TFLocalizedString(@"已加入书架") forState:UIControlStateNormal];
[self.addBookRack setTitleColor:kMainColorAlpha(0.5) forState:UIControlStateNormal];
self.addBookRack.userInteractionEnabled = NO;
} else {
self.addBookRack.enabled = YES;
[self.addBookRack setTitle:TFLocalizedString(@"加入书架") forState:UIControlStateNormal];
[self.addBookRack setTitleColor:kMainColor forState:UIControlStateNormal];
[self.addBookRack addTarget:self action:@selector(addBookRackClick:) forControlEvents:UIControlEventTouchUpInside];
self.addBookRack.userInteractionEnabled = YES;
}
if ([[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeNovel] productionHasReadedWithProduction_id:self.bookDetailModel.bookModel.production_id]) {
[self.readBookButton setTitle:TFLocalizedString(@"继续阅读") forState:UIControlStateNormal];
} else {
[self.readBookButton setTitle:TFLocalizedString(@"开始阅读") forState:UIControlStateNormal];
}
}
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
[[NSNotificationCenter defaultCenter] removeObserver:self name:Notification_Reload_BookDetail object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:Notification_Push_To_Download object:nil];
}
- (void)createSubviews
{
UIButton *shareButton = [UIButton buttonWithType:UIButtonTypeCustom];
self.shareButton = shareButton;
shareButton.hidden = YES;
shareButton.adjustsImageWhenHighlighted = NO;
shareButton.tintColor = kWhiteColor;
[shareButton setImage:[[UIImage imageNamed:@"public_share"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
[shareButton setImageEdgeInsets:UIEdgeInsetsMake(6, 6, 6, 6)];
[shareButton addTarget:self action:@selector(UMShareClick) forControlEvents:UIControlEventTouchUpInside];
[self.navigationBar addSubview:shareButton];
[shareButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(self.navigationBar.mas_right).with.offset(- kHalfMargin);
make.bottom.mas_equalTo(self.navigationBar.mas_bottom).with.offset(- 7);
make.width.height.mas_equalTo(30);
}];
#if TF_Download_Mode
if ([TFUtilsHelper getAiReadSwitchState]) {
UIButton *downloadButton = [UIButton buttonWithType:UIButtonTypeCustom];
self.downloadButton = downloadButton;
downloadButton.hidden = YES;
downloadButton.adjustsImageWhenHighlighted = NO;
downloadButton.tintColor = kWhiteColor;
[downloadButton setImage:[[UIImage imageNamed:@"public_download"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
[downloadButton setImageEdgeInsets:UIEdgeInsetsMake(6, 6, 5.5, 5.5)];
[downloadButton addTarget:self action:@selector(downloadClick) forControlEvents:UIControlEventTouchUpInside];
[self.navigationBar addSubview:downloadButton];
[downloadButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(shareButton.mas_left).with.offset(- kHalfMargin);
make.bottom.mas_equalTo(self.navigationBar.mas_bottom).with.offset(- 7);
make.width.height.mas_equalTo(30);
}];
}
#endif
self.mainTableViewGroup.delegate = self;
self.mainTableViewGroup.dataSource = self;
[self.view addSubview:self.mainTableViewGroup];
[self.mainTableViewGroup mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.top.mas_equalTo(0);
make.width.mas_equalTo(self.view.mas_width);
make.height.mas_equalTo(self.view.mas_height);
}];
WS(weakSelf)
self.mainTableViewGroup.mj_header = [TFRefreshHeader headerWithRefreshingBlock:^{
[weakSelf netRequest];
}];
}
- (void)createToolBar
{
[self.mainTableViewGroup mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(self.view.mas_height).with.offset(- PUB_TABBAR_HEIGHT);
}];
UIView *toolBarView = [[UIView alloc] init];
toolBarView.backgroundColor = kGrayViewColor;
[self.view addSubview:toolBarView];
[toolBarView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.bottom.mas_equalTo(self.view.mas_bottom);
make.width.mas_equalTo(self.view.mas_width);
make.height.mas_equalTo(PUB_TABBAR_HEIGHT);
}];
// 加入书架
UIButton *addBookRack = [UIButton buttonWithType:UIButtonTypeCustom];
self.addBookRack = addBookRack;
if ([[TFCollectionManager shareManagerWithProductionType:TFProductionTypeNovel] isCollectedWithProductionModel:self.bookDetailModel.bookModel]) {
self.addBookRack.enabled = NO;
[addBookRack setTitle:TFLocalizedString(@"已加入书架") forState:UIControlStateNormal];
[addBookRack setTitleColor:kMainColorAlpha(0.5) forState:UIControlStateNormal];
} else {
self.addBookRack.enabled = YES;
[addBookRack setTitle:TFLocalizedString(@"加入书架") forState:UIControlStateNormal];
[addBookRack setTitleColor:kMainColor forState:UIControlStateNormal];
[addBookRack addTarget:self action:@selector(addBookRackClick:) forControlEvents:UIControlEventTouchUpInside];
}
addBookRack.backgroundColor = kGrayViewColor;
[addBookRack.titleLabel setFont:kMainFont];
[addBookRack addBorderLineWithBorderWidth:0.5 borderColor:kGrayViewColor cornerRadius:0 borderType:UIBorderSideTypeRight];
[toolBarView addSubview:addBookRack];
// 开始阅读
self.readBookButton = [UIButton buttonWithType:UIButtonTypeCustom];
if ([[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeNovel] productionHasReadedWithProduction_id:self.bookDetailModel.bookModel.production_id]) {
[self.readBookButton setTitle:TFLocalizedString(@"继续阅读") forState:UIControlStateNormal];
} else {
[self.readBookButton setTitle:TFLocalizedString(@"开始阅读") forState:UIControlStateNormal];
}
self.readBookButton.backgroundColor = kMainColor;
[self.readBookButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[self.readBookButton.titleLabel setFont:[UIFont boldSystemFontOfSize:kFontSize13]];
[self.readBookButton addTarget:self action:@selector(readBookClick) forControlEvents:UIControlEventTouchUpInside];
[toolBarView addSubview:self.readBookButton];
// 听书
UIButton *audioButton = [UIButton buttonWithType:UIButtonTypeCustom];
audioButton.backgroundColor = kGrayViewColor;
[audioButton setTitleColor:kMainColor forState:UIControlStateNormal];
[audioButton.titleLabel setFont:kMainFont];
[audioButton addTarget:self action:@selector(audioButtonClick:) forControlEvents:UIControlEventTouchUpInside];
#if TF_Enable_Ai
if ([TFUtilsHelper getAiReadSwitchState]) {
[audioButton setTitle:TFLocalizedString(@"听书详情") forState:UIControlStateNormal];
} else {
[audioButton setTitle:TFLocalizedString(@"下载书籍") forState:UIControlStateNormal];
}
#else
[audioButton setTitle:TFLocalizedString(@"下载书籍") forState:UIControlStateNormal];
#endif
[toolBarView addSubview:audioButton];
NSArray *viewArray = @[audioButton, self.readBookButton, addBookRack];
[viewArray mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing:0 leadSpacing:0 tailSpacing:0];
[viewArray mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(0);
make.height.mas_equalTo(toolBarView.mas_height).with.offset(- PUB_TABBAR_OFFSET);
}];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
NSMutableArray *t_sectionTagArray = [NSMutableArray array];
// 简介
// if (self.bookDetailModel.bookModel.production_descirption.length > 0) {
[t_sectionTagArray addObject:@"descirption"];
// }
// 广告
if (self.bookDetailModel.advert.ad_type != 0) {
[t_sectionTagArray addObject:@"ad"];
}
// 评论
#if TF_Comments_Mode
[t_sectionTagArray addObject:@"comment"];
#endif
// 猜你喜欢
if (self.bookDetailModel.label.firstObject.list.count > 0) {
[t_sectionTagArray addObject:@"label"];
}
if (t_sectionTagArray.count == 0 || t_sectionTagArray.count == 1) {
[t_sectionTagArray addObject:@"descirption"];
}
self.sectionTagArray = [t_sectionTagArray copy];
return t_sectionTagArray.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if ([[self.sectionTagArray objectAtIndex:section] isEqualToString:@"descirption"]) {
return 1;
}
if ([[self.sectionTagArray objectAtIndex:section] isEqualToString:@"ad"]) {
return 1;
}
#if TF_Comments_Mode
if ([[self.sectionTagArray objectAtIndex:section] isEqualToString:@"comment"]) {
return self.bookDetailModel.comment.count;
}
#endif
if ([[self.sectionTagArray objectAtIndex:section] isEqualToString:@"label"]) {
return self.bookDetailModel.label.count;
}
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([[self.sectionTagArray objectAtIndex:indexPath.section] isEqualToString:@"descirption"]) {
return [self createHeaderViewCellWithTableView:tableView indexPath:indexPath];
}
if ([[self.sectionTagArray objectAtIndex:indexPath.section] isEqualToString:@"ad"]) {
return [self createAdCellWithTableView:tableView indexPath:indexPath];
}
#if TF_Comments_Mode
if ([[self.sectionTagArray objectAtIndex:indexPath.section] isEqualToString:@"comment"]) {
return [self createCommentCellWithTableView:tableView indexPath:indexPath];
}
#endif
if ([[self.sectionTagArray objectAtIndex:indexPath.section] isEqualToString:@"label"]) {
return [self createCellWithTabelView:tableView indexPath:indexPath];
}
return [[UITableViewCell alloc] init];
}
- (UITableViewCell *)createHeaderViewCellWithTableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath
{
WS(weakSelf)
static NSString *cellName = @"TFNovelDetailHeaderView";
TFNovelDetailHeaderView *cell = [tableView dequeueReusableCellWithIdentifier:cellName];
if (!cell) {
cell = [[TFNovelDetailHeaderView alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
}
cell.bookModel = self.bookDetailModel.bookModel;
cell.catalogueButtonClickBlock = ^{
if (!weakSelf.bookDetailModel.bookModel) return;
TFNovelCatalogueBookmarkController *vc = [[TFNovelCatalogueBookmarkController alloc] init];
vc.isReader = weakSelf.isReader;
vc.bookModel = weakSelf.bookDetailModel.bookModel;
vc.isBookDetailPush = YES;
[weakSelf.navigationController pushViewController:vc animated:YES];
};
return cell;
}
- (UITableViewCell *)createCellWithTabelView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath
{
TFBookStoreLabelModel *labelModel = [self.bookDetailModel.label objectOrNilAtIndex:indexPath.row];
Class cellClass = TFBookStoreNovelStyleOneCell.class;
switch (labelModel.style) {
case 1:
cellClass = TFBookStoreNovelStyleOneCell.class;
break;
case 2:
cellClass = TFBookStoreNovelStyleTwoCell.class;
break;
case 3:
cellClass = TFBookStoreNovelStyleThreeCell.class;
break;
case 4:
cellClass = TFBookStoreNovelStyleFourCell.class;
break;
default:
cellClass = TFBookStoreNovelStyleOneCell.class;
break;
}
WS(weakSelf)
TFBookStoreNovelBasicViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(cellClass)];
if (!cell) {
cell = [[cellClass alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass(cellClass)];
}
cell.labelModel = labelModel;
cell.cellDidSelectItemBlock = ^(NSInteger production_id) {
TFNovelDetailViewController *vc = [[TFNovelDetailViewController alloc] init];
vc.book_id = production_id;
[weakSelf.navigationController pushViewController:vc animated:YES];
};
return cell;
}
- (UITableViewCell *)createCommentCellWithTableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath
{
static NSString *cellName = @"TFCommentsViewCell";
TFCommentsViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName];
if (!cell) {
cell = [[TFCommentsViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
}
cell.commentModel = [self.bookDetailModel.comment objectOrNilAtIndex:indexPath.row];
cell.hiddenEndLine = NO;
[cell setIsPreview:YES lastRow:(self.bookDetailModel.comment.count - 1 == indexPath.row)];
return cell;
}
- (UITableViewCell *)createAdCellWithTableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath
{
static NSString *cellName = @"TFPublicAdvertisementViewCell";
TFPublicAdvertisementViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName];
if (!cell) {
cell = [[TFPublicAdvertisementViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
}
[cell setAdModel:self.bookDetailModel.advert refresh:self.needRefresh];
cell.mainTableView = tableView;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
#if TF_Comments_Mode
if ([[self.sectionTagArray objectAtIndex:indexPath.section] isEqualToString:@"comment"]) {
TFCommentsListModel *t_model = [self.bookDetailModel.comment objectOrNilAtIndex:indexPath.row];
[self commentWithComment_id:t_model.comment_id];
}
#endif
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
#if TF_Comments_Mode
if (!self.bookDetailModel) {
return CGFLOAT_MIN;
}
if ([[self.sectionTagArray objectAtIndex:section] isEqualToString:@"comment"]) {
return 54;
}
#endif
return CGFLOAT_MIN;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
#if TF_Comments_Mode
if ([[self.sectionTagArray objectAtIndex:section] isEqualToString:@"comment"]) {
return self.commentSectionView;
}
#endif
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 10)];
view.backgroundColor = [UIColor clearColor];
return view;
}
- (UIView *)commentSectionView
{
if (!_commentSectionView) {
_commentSectionView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 54)];
_commentSectionView.backgroundColor = [UIColor whiteColor];
if (self.bookDetailModel.advert.ad_type == 0) {
UIView *grayLine = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 10)];
grayLine.backgroundColor = kGrayViewColor;
[_commentSectionView addSubview:grayLine];
}
UIImageView *mainTitleHoldView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"book_label_hold"]];
[_commentSectionView addSubview:mainTitleHoldView];
[mainTitleHoldView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(kHalfMargin);
make.centerY.mas_equalTo(_commentSectionView.mas_centerY).with.offset(5);
make.width.height.mas_equalTo(kHalfMargin + kQuarterMargin);
}];
UILabel *t_title = [[UILabel alloc] init];
t_title.textAlignment = NSTextAlignmentLeft;
t_title.textColor = kBlackColor;
t_title.backgroundColor = [UIColor whiteColor];
t_title.font = kBoldFont16;
t_title.text = TFLocalizedString(@"最新书评");
[t_title addBorderLineWithBorderWidth:0.5 borderColor:kGrayLineColor cornerRadius:0 borderType:UIBorderSideTypeBottom];
[_commentSectionView addSubview:t_title];
[t_title mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(_commentSectionView).offset(kMargin + kHalfMargin);
make.top.equalTo(_commentSectionView).offset(kHalfMargin);
make.height.mas_equalTo(44.0);
}];
UIButton *commentButton = [UIButton buttonWithType:UIButtonTypeCustom];
commentButton.backgroundColor = [UIColor whiteColor];
[commentButton setTitle:TFLocalizedString(@"写评论") forState:UIControlStateNormal];
[commentButton setTitleColor:kMainColor forState:UIControlStateNormal];
[commentButton.titleLabel setFont:kFont12];
[commentButton addTarget:self action:@selector(commentClick) forControlEvents:UIControlEventTouchUpInside];
[_commentSectionView addSubview:commentButton];
[commentButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(t_title.mas_right).offset(kHalfMargin);
make.right.equalTo(_commentSectionView).offset(-kHalfMargin);
make.centerY.equalTo(t_title);
make.height.mas_equalTo(40.0);
}];
}
return _commentSectionView;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
#if TF_Comments_Mode
if (!self.bookDetailModel) {
return CGFLOAT_MIN;
}
if ([[self.sectionTagArray objectAtIndex:section] isEqualToString:@"comment"]) {
return 50;
}
#endif
return CGFLOAT_MIN;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 50)];
view.backgroundColor = kWhiteColor;
#if TF_Comments_Mode
if ([[self.sectionTagArray objectAtIndex:section] isEqualToString:@"comment"]) {
if (self.bookDetailModel) {
if (self.bookDetailModel.bookModel.total_comment == 0) {
[self.sectionBottomCommentButton setTitle:TFLocalizedString(@"暂无评论,点击抢沙发") forState:UIControlStateNormal];
} else {
[self.sectionBottomCommentButton setTitle:[NSString stringWithFormat:@"%@(%@%@)", TFLocalizedString(@"查看全部评论"), [TFUtilsHelper formatStringWithInteger:self.bookDetailModel.bookModel.total_comment], TFLocalizedString(@"")] forState:UIControlStateNormal];
}
[view addSubview:self.sectionBottomCommentButton];
}
}
#endif
return view;
}
- (UIButton *)sectionBottomCommentButton
{
if (!_sectionBottomCommentButton) {
_sectionBottomCommentButton = [UIButton buttonWithType:UIButtonTypeCustom];
_sectionBottomCommentButton.frame = CGRectMake(SCREEN_WIDTH / 4, kHalfMargin, SCREEN_WIDTH / 2 + kMargin, 36);
_sectionBottomCommentButton.backgroundColor = [UIColor whiteColor];
_sectionBottomCommentButton.layer.cornerRadius = 18;
_sectionBottomCommentButton.layer.borderColor = kMainColor.CGColor;
_sectionBottomCommentButton.layer.borderWidth = 0.4f;
[_sectionBottomCommentButton setTitleColor:kMainColor forState:UIControlStateNormal];
[_sectionBottomCommentButton.titleLabel setFont:kFont12];
[_sectionBottomCommentButton addTarget:self action:@selector(commentClick) forControlEvents:UIControlEventTouchUpInside];
}
return _sectionBottomCommentButton;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat pointY = scrollView.contentOffset.y;
[self changeNavBarColorState:pointY withAnimate:YES];
}
- (void)pushToDownload
{
#if TF_Download_Mode
TFDownloadCacheViewController *vc = [[TFDownloadCacheViewController alloc] init];
vc.onlyBookMode = YES;
[self.navigationController pushViewController:vc animated:YES];
#endif
}
- (void)commentClick
{
[self commentWithComment_id:0];
}
- (void)commentWithComment_id:(NSInteger)comment_id
{
WS(weakSelf)
TFCommentsViewController *vc = [[TFCommentsViewController alloc] init];
vc.production_id = self.book_id;
vc.comment_id = comment_id;
vc.productionType = TFProductionTypeNovel;
vc.commentsSuccessBlock = ^(TFCommentsListModel *commentModel) {
TFNovelDetailModel *t_model = weakSelf.bookDetailModel;
// 评论数++
t_model.bookModel.total_comment ++;
// 评论数组model添加
NSMutableArray *t_array = [NSMutableArray arrayWithArray:t_model.comment];
[t_array insertObject:commentModel atIndex:0];
t_model.comment = [t_array copy];
weakSelf.bookDetailModel = t_model;
[weakSelf.mainTableViewGroup reloadData];
};
[self.navigationController pushViewController:vc animated:YES];
}
- (void)audioButtonClick:(UIButton *)sender
{
if ([TFNetworkManager networkingStatus] == NO) {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusSuccess promptTitle:TFLocalizedString(@"听书功能仅支持在线使用")];
return;
}
if (self.bookDetailModel.bookModel.chapter_list.count == 0) {
sender.enabled = NO;
[sender setTitleColor:kGrayViewColor forState:UIControlStateNormal];
UIActivityIndicatorView *indicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
indicatorView.frame = CGRectMake(0, 0, 30, 30);
indicatorView.center = sender.center;
[indicatorView startAnimating];
[sender addSubview:indicatorView];
WS(weakSelf)
[TFNetworkTools POST:Book_Catalog parameters:@{@"book_id" : [TFUtilsHelper formatStringWithInteger:self.book_id]} model:TFProductionModel.class success:^(BOOL isSuccess, TFProductionModel * _Nullable t_model, TFNetworkRequestModel * _Nonnull requestModel) {
sender.enabled = YES;
[indicatorView removeFromSuperview];
[sender setTitleColor:kMainColor forState:UIControlStateNormal];
if (isSuccess) {
weakSelf.bookDetailModel.bookModel.chapter_list = t_model.chapter_list;
[weakSelf saveCatalog:requestModel.data];
if (t_model.chapter_list.count > 0) {
[weakSelf audioButtonClick:sender];
} else {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:TFLocalizedString(@"书籍获取失败")];
}
} else {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:requestModel.msg ?: TFLocalizedString(@"书籍获取失败")];
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
sender.enabled = YES;
[indicatorView removeFromSuperview];
[sender setTitleColor:kMainColor forState:UIControlStateNormal];
[TFPromptManager showPromptWithError:error defaultText:TFLocalizedString(@"书籍获取失败")];
}];
return;
}
#if TF_Enable_Ai
if ([TFUtilsHelper getAiReadSwitchState]) {
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Reset_Player_Inof object:nil];
WXYZ_BookAiPlayPageViewController *vc = [WXYZ_BookAiPlayPageViewController sharedManager];
[vc loadDataWithBookModel:self.bookDetailModel.bookModel chapterModel:nil];
for (UIViewController *vc in self.navigationController.viewControllers) {
if ([vc isKindOfClass:[WXYZ_BookAiPlayPageViewController class]]) {
[self popViewController];
return;
}
}
TFNavigationController *nav = [[TFNavigationController alloc] initWithRootViewController:vc];
[[TFViewHelper getWindowRootController] presentViewController:nav animated:YES completion:nil];
}
#endif
#if TF_Download_Mode
if (![TFUtilsHelper getAiReadSwitchState]) {
[self downloadClick];
}
#endif
}
- (void)downloadClick
{
if (!self.book_id) {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:TFLocalizedString(@"书籍获取失败")];
return;
}
if (self.bookDetailModel.bookModel.list.count == 0) {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:TFLocalizedString(@"书籍获取失败")];
return;
}
self.downloadButton.enabled = NO;
TFNovelDownloadMenuView *downloadBar = [[TFNovelDownloadMenuView alloc] init];
downloadBar.book_id = [TFUtilsHelper formatStringWithInteger:self.book_id];
downloadBar.chapter_id = [TFUtilsHelper formatStringWithInteger:[[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeNovel] getReadingRecordChapter_idWithProduction_id:self.book_id]];
WS(weakSelf)
downloadBar.menuBarDidHiddenBlock = ^{
weakSelf.downloadButton.enabled = YES;
};
[kMainWindow addSubview:downloadBar];
[downloadBar showDownloadPayView];
}
- (void)UMShareClick
{
[TFShareManager shareWithProduction_id:NSStringFromInteger(self.bookDetailModel.bookModel.production_id) chapter_id:nil type:TFShareTypeBook];
}
- (void)addBookRackClick:(UIButton *)sender
{
[TFUtilsHelper synchronizationRackProductionWithProduction_id:self.book_id productionType:TFProductionTypeNovel complete:nil];
if ([[TFCollectionManager shareManagerWithProductionType:TFProductionTypeNovel] addCollectionWithProductionModel:self.bookDetailModel.bookModel atIndex:0]) {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusSuccess promptTitle:TFLocalizedString(@"已加入书架")];
[sender setTitle:TFLocalizedString(@"已加入书架") forState:UIControlStateNormal];
[sender setTitleColor:kMainColorAlpha(0.5) forState:UIControlStateNormal];
sender.enabled = NO;
} else {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:TFLocalizedString(@"添加失败")];
}
}
- (void)readBookClick
{
if (self.isReader) {
[self.navigationController popViewControllerAnimated:YES];
return;
}
if (!self.bookDetailModel.bookModel) {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:TFLocalizedString(@"书籍获取失败")];
return;
}
[TFTaskViewController taskReadRequestWithProduction_id:self.book_id];
// 删除多余的阅读器和书籍详情页
NSArray<UIViewController *> *t_arr = self.navigationController.viewControllers;
NSMutableArray<UIViewController *> *tt_arr = [t_arr mutableCopy];
for (UIViewController *obj in t_arr) {
if ([obj isKindOfClass:TFReadNovelViewController.class] ||
([obj isKindOfClass:TFNovelDetailViewController.class] && obj != self)) {
[tt_arr removeObject:obj];
}
}
if (tt_arr.count != self.navigationController.viewControllers.count) {
self.navigationController.viewControllers = tt_arr;
}
TFReadNovelViewController *vc = [[TFReadNovelViewController alloc] init];
vc.book_id = self.book_id;
// vc.bookModel = self.bookDetailModel.bookModel;
[self.navigationController pushViewController:vc animated:YES];
[[TFCollectionManager shareManagerWithProductionType:TFProductionTypeNovel] moveCollectionToTopWithProductionModel:self.bookDetailModel.bookModel];
}
- (void)jumpToReader:(NSNotification *)noti
{
if ([noti.object isEqualToString:@"TFNovelDetailViewController"]) {
TFProductionModel *t_model = [noti.userInfo objectForKey:@"bookModel"];
TFReadNovelViewController *vc = [[TFReadNovelViewController alloc] init];
vc.book_id = t_model.production_id;
vc.bookModel = t_model;
[self.navigationController pushViewController:vc animated:YES];
}
}
- (void)netRequest
{
if ([TFNetworkManager networkingStatus] == NO) {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:TFLocalizedString(@"当前无网络连接")];
return;
}
WS(weakSelf)
[TFNetworkTools POST:Book_Mall_Detail parameters:@{@"book_id":[TFUtilsHelper formatStringWithInteger:self.book_id]} model:TFNovelDetailModel.class success:^(BOOL isSuccess, TFNovelDetailModel * _Nullable t_model, TFNetworkRequestModel * _Nonnull requestModel) {
if (isSuccess) {
weakSelf.bookDetailModel = t_model;
[weakSelf createToolBar];
[weakSelf requestCatalog];
} else {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:requestModel.msg ?: TFLocalizedString(@"书籍获取失败")];
}
weakSelf.shareButton.hidden = NO;
#if TF_Download_Mode
weakSelf.downloadButton.hidden = NO;
#endif
[weakSelf.mainTableViewGroup endRefreshing];
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
[TFPromptManager showPromptWithError:error defaultText:TFLocalizedString(@"书籍获取失败")];
[weakSelf.mainTableViewGroup endRefreshing];
}];
}
// 获取目录信息
- (void)requestCatalog {
NSInteger chapter_id = [[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeNovel] getReadingRecordChapter_idWithProduction_id:self.book_id];
NSDictionary *params = @{
@"book_id" : [TFUtilsHelper formatStringWithInteger:self.book_id],
@"chapter_id" : @(chapter_id),
@"scroll_type": @(1), // 1:向下加载;2:向上加载
};
TFCatalogModel * __block catalogModel = nil;
NSDictionary * __block catalogDict = nil;
WS(weakSelf)
[TFNetworkTools POST:Book_New_Catalog parameters:params model:TFCatalogModel.class success:^(BOOL isSuccess, TFCatalogModel * _Nullable t_model, TFNetworkRequestModel * _Nonnull requestModel) {
if (isSuccess) {
catalogModel = t_model;
weakSelf.bookDetailModel.bookModel.list = t_model.list;
weakSelf.bookDetailModel.bookModel.author_name = t_model.author.author_name;
weakSelf.bookDetailModel.bookModel.author_id = t_model.author.author_id;
weakSelf.bookDetailModel.bookModel.author_note = t_model.author.author_note;
weakSelf.bookDetailModel.bookModel.author_avatar = t_model.author.author_avatar;
// 预下载第一章
if (t_model.list.count > 0) {
[[TFReaderBookManager sharedManager] downloadPrestrainChapterWithProductionModel:weakSelf.bookDetailModel.bookModel production_id:weakSelf.book_id chapter_id:[[t_model.list firstObject].chapter_id integerValue] completionHandler:nil];
}
if (catalogDict) {
NSString *str = [t_model.author modelToJSONString];
NSDictionary *t_dict = [TFUtilsHelper dictionaryWithJsonString:str];
NSMutableDictionary *tt_dict = [NSMutableDictionary dictionaryWithDictionary:catalogDict];
[tt_dict setObject:t_dict forKey:@"author"];
[weakSelf saveCatalog:tt_dict];
}
} else {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:requestModel.msg ?: TFLocalizedString(@"书籍获取失败")];
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
[TFPromptManager showPromptWithError:error defaultText:TFLocalizedString(@"书籍获取失败")];
}];
[TFNetworkTools POST:Book_Catalog parameters:@{@"book_id" : [TFUtilsHelper formatStringWithInteger:self.book_id]} model:TFProductionModel.class success:^(BOOL isSuccess, TFProductionModel * _Nullable t_model, TFNetworkRequestModel * _Nonnull requestModel) {
if (isSuccess) {
weakSelf.bookDetailModel.bookModel.chapter_list = t_model.chapter_list;
if (catalogModel) {
NSString *str = [catalogModel.author modelToJSONString];
NSDictionary *t_dict = [TFUtilsHelper dictionaryWithJsonString:str];
NSMutableDictionary *tt_dict = [NSMutableDictionary dictionaryWithDictionary:requestModel.data];
[tt_dict setObject:t_dict forKey:@"author"];
[weakSelf saveCatalog:tt_dict];
} else {
catalogDict = requestModel.data;
}
}
} failure:nil];
}
- (void)setBookDetailModel:(TFNovelDetailModel *)bookDetailModel
{
_bookDetailModel = bookDetailModel;
[self.navigationBar setNavigationBarTitle:bookDetailModel.bookModel.name?:@""];
self.needRefresh = YES;
[self.mainTableViewGroup reloadData];
dispatch_async(dispatch_get_main_queue(), ^{
self.needRefresh = NO;
});
}
- (void)changeNavBarColorState:(CGFloat)contentOffsetY withAnimate:(BOOL)animate
{
CGFloat alpha = [TFColorHelper getAlphaWithContentOffsetY:contentOffsetY];
CGFloat rbgColor = [TFColorHelper getColorWithContentOffsetY:contentOffsetY];
self.navigationBar.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:alpha];
self.navigationBar.navTitleLabel.backgroundColor = [UIColor clearColor];
self.navigationBar.navTitleLabel.alpha = alpha;
self.navigationBar.navTitleLabel.textColor = kColorRGBA(rbgColor, rbgColor, rbgColor, 1);
[self.navigationBar setLeftButtonTintColor:kColorRGBA(rbgColor, rbgColor, rbgColor, 1)];
self.shareButton.tintColor = kColorRGBA(rbgColor, rbgColor, rbgColor, 1);
#if TF_Download_Mode
self.downloadButton.tintColor = kColorRGBA(rbgColor, rbgColor, rbgColor, 1);
#endif
if (contentOffsetY > 60) {
[self setStatusBarDefaultStyle];
} else {
[self setStatusBarLightContentStyle];
}
}
/// 保存目录列表到本地
- (void)saveCatalog:(NSDictionary *)catalog {
NSString *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject;
path = [path stringByAppendingPathComponent:[TFUtilsHelper stringToMD5:@"book_catalog"]];
if (![[NSFileManager defaultManager] fileExistsAtPath:path]) {
[[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:@{} error:nil];
}
NSString *catalogName = [NSString stringWithFormat:@"%zd_%@", self.book_id, @"catalog"];
NSString *fullPath = [path stringByAppendingFormat:@"/%@.plist", [TFUtilsHelper stringToMD5:catalogName]];
[catalog writeToFile:fullPath atomically:YES];
}
@end
@@ -0,0 +1,23 @@
//
// TFNovelDetailModel.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/19.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@class TFCommentsListModel, TFTagModel, TFProductionModel, TFProductionModel, TFBookStoreLabelModel;
@interface TFNovelDetailModel : NSObject
@property (nonatomic ,strong) NSArray <TFCommentsListModel *> *comment; // 作品评论列表
@property (nonatomic ,strong) NSArray <TFBookStoreLabelModel *> *label; // 推荐作品label
@property (nonatomic ,strong) TFProductionModel *bookModel; // 作品基本信息
@property (nonatomic ,strong) TFAdvertModel *advert; // 广告
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,29 @@
//
// TFNovelDetailModel.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/19.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFNovelDetailModel.h"
#import "TFBookStoreLabelModel.h"
@implementation TFNovelDetailModel
+ (NSDictionary<NSString *,id> *)modelContainerPropertyGenericClass
{
return @{
@"label" : [TFBookStoreLabelModel class],
@"comment" : [TFCommentsListModel class],
@"advert" : [TFAdvertModel class]
};
}
+ (NSDictionary *)modelCustomPropertyMapper
{
return @{
@"bookModel" : @"book"
};
}
@end
@@ -0,0 +1,22 @@
//
// TFNovelDetailHeaderView.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/19.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
typedef void(^CatalogueButtonClickBlock)(void);
@interface TFNovelDetailHeaderView : TFBasicTableViewCell
@property (nonatomic ,strong) TFProductionModel *bookModel;
@property (nonatomic ,copy) CatalogueButtonClickBlock catalogueButtonClickBlock;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,338 @@
//
// TFNovelDetailHeaderView.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/19.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFNovelDetailHeaderView.h"
#import "TFTagboardView.h"
#import "UIImage+Blur.h"
@interface TFNovelDetailHeaderView ()
{
TFProductionCoverView *bookImageView;
UILabel *bookNameLabel;
UILabel *authorLabel;
UILabel *introductionLabel;
UILabel *commontNumLabel;
UILabel *collecitonNumLabel;
UILabel *bookDescriptionLabel;
UILabel *timeLabel;
UIButton *catalogueButton;
UILabel *catalogueDetailLabel;
TFTagboardView *tagView;
}
@property (nonatomic, strong) UIImageView __block *headBackImageView;
@end
@implementation TFNovelDetailHeaderView
- (void)createSubviews
{
[super createSubviews];
// 背景图
_headBackImageView = [[UIImageView alloc] init];
_headBackImageView.backgroundColor = [UIColor whiteColor];
_headBackImageView.contentMode = UIViewContentModeScaleAspectFill;
_headBackImageView.clipsToBounds = YES;
_headBackImageView.image = HoldImage;
[self.contentView addSubview:_headBackImageView];
[_headBackImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.contentView.mas_left);
make.top.mas_equalTo(self.contentView.mas_top);
make.width.mas_equalTo(SCREEN_WIDTH);
make.height.mas_equalTo(SCREEN_WIDTH / 2 + PUB_NAVBAR_OFFSET + kMargin);
}];
// 书籍图片
bookImageView = [[TFProductionCoverView alloc] initWithProductionType:TFProductionTypeNovel coverDirection:TFProductionCoverDirectionVertical];
bookImageView.userInteractionEnabled = YES;
[self.contentView addSubview:bookImageView];
[bookImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(kMargin);
make.bottom.mas_equalTo(_headBackImageView.mas_bottom).with.offset(kMargin);
make.width.mas_equalTo(BOOK_WIDTH);
make.height.mas_equalTo(BOOK_HEIGHT);
}];
// 书名
bookNameLabel = [[UILabel alloc] init];
bookNameLabel.textAlignment = NSTextAlignmentLeft;
bookNameLabel.textColor = [UIColor whiteColor];
bookNameLabel.backgroundColor = [UIColor clearColor];
bookNameLabel.font = kBoldFont16;
[self.contentView addSubview:bookNameLabel];
[bookNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(bookImageView.mas_right).with.offset(kMargin);
make.top.mas_equalTo(bookImageView.mas_top);
make.right.mas_equalTo(self.contentView.mas_right).with.offset(- kMargin);
make.height.mas_equalTo(kLabelHeight);
}];
// 作者
authorLabel = [[UILabel alloc] init];
authorLabel.backgroundColor = [UIColor clearColor];
authorLabel.textColor = [UIColor whiteColor];
authorLabel.textAlignment = NSTextAlignmentLeft;
authorLabel.font = kFont12;
[self.contentView addSubview:authorLabel];
[authorLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(bookNameLabel.mas_left);
make.top.mas_equalTo(bookNameLabel.mas_bottom).with.offset(5);
make.width.mas_equalTo(bookNameLabel.mas_width).multipliedBy(0.5);
make.height.mas_equalTo(17);
}];
// 书籍标签
introductionLabel = [[UILabel alloc] init];
introductionLabel.backgroundColor = [UIColor clearColor];
introductionLabel.textColor = [UIColor whiteColor];
introductionLabel.textAlignment = NSTextAlignmentLeft;
introductionLabel.font = kFont12;
[self.contentView addSubview:introductionLabel];
[introductionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(bookNameLabel.mas_left);
make.top.mas_equalTo(authorLabel.mas_bottom).with.offset(5);
make.width.mas_equalTo(bookNameLabel.mas_width).multipliedBy(0.5);
make.height.mas_equalTo(authorLabel.mas_height);
}];
// 评价数
commontNumLabel = [[UILabel alloc] init];
commontNumLabel.backgroundColor = [UIColor clearColor];
commontNumLabel.textColor = [UIColor whiteColor];
commontNumLabel.textAlignment = NSTextAlignmentLeft;
commontNumLabel.font = kFont12;
[self.contentView addSubview:commontNumLabel];
[commontNumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(bookNameLabel.mas_left);
make.top.mas_equalTo(introductionLabel.mas_bottom).with.offset(kQuarterMargin);
make.width.mas_equalTo(bookNameLabel.mas_width).multipliedBy(0.5);
make.height.mas_equalTo(authorLabel.mas_height);
}];
collecitonNumLabel = [[UILabel alloc] init];
collecitonNumLabel.backgroundColor = [UIColor clearColor];
collecitonNumLabel.textColor = [UIColor whiteColor];
collecitonNumLabel.textAlignment = NSTextAlignmentLeft;
collecitonNumLabel.font = kFont12;
[self.contentView addSubview:collecitonNumLabel];
[collecitonNumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(bookNameLabel.mas_left);
make.top.mas_equalTo(commontNumLabel.mas_bottom).with.offset(kQuarterMargin);
make.width.mas_equalTo(bookNameLabel.mas_width).multipliedBy(0.5);
make.height.mas_equalTo(authorLabel.mas_height);
}];
// 简介
bookDescriptionLabel = [[UILabel alloc] init];
bookDescriptionLabel.backgroundColor = [UIColor whiteColor];
bookDescriptionLabel.textColor = kBlackColor;
bookDescriptionLabel.textAlignment = NSTextAlignmentLeft;
bookDescriptionLabel.font = kMainFont;
bookDescriptionLabel.numberOfLines = 0;
[self.contentView addSubview:bookDescriptionLabel];
[bookDescriptionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(kMargin);
make.top.mas_equalTo(bookImageView.mas_bottom).with.offset(kHalfMargin);
make.width.mas_equalTo(self.mas_width).with.offset(- 2 * kMargin);
make.height.mas_equalTo(50);
}];
// 目录列
catalogueButton = [UIButton buttonWithType:UIButtonTypeCustom];
catalogueButton.backgroundColor = [UIColor clearColor];
catalogueButton.hidden = YES;
[catalogueButton addTarget:self action:@selector(catalogueClick) forControlEvents:UIControlEventTouchUpInside];
[self.contentView addSubview:catalogueButton];
[catalogueButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.top.mas_equalTo(bookDescriptionLabel.mas_bottom).with.offset(kHalfMargin);
make.width.mas_equalTo(self.contentView.mas_width);
make.height.mas_equalTo(kLabelHeight + kHalfMargin);
}];
UIImageView *catalogueIcon = [[UIImageView alloc] init];
catalogueIcon.image = [UIImage imageNamed:@"book_directory"];
catalogueIcon.userInteractionEnabled = YES;
[catalogueButton addSubview:catalogueIcon];
[catalogueIcon mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(kMargin);
make.centerY.mas_equalTo(catalogueButton.mas_centerY);
make.height.mas_equalTo(kMargin);
make.width.mas_equalTo(kMargin);
}];
UILabel *catalogueTitle = [[UILabel alloc] init];
catalogueTitle.text = TFLocalizedString(@"目录");
catalogueTitle.font = kMainFont;
catalogueTitle.textColor = kBlackColor;
catalogueTitle.textAlignment = NSTextAlignmentLeft;
[catalogueButton addSubview:catalogueTitle];
[catalogueTitle mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(catalogueIcon.mas_right).with.offset(5);
make.centerY.mas_equalTo(catalogueIcon.mas_centerY);
make.width.mas_equalTo(catalogueTitle.intrinsicContentSize.width);
make.height.mas_equalTo(catalogueIcon.mas_height);
}];
// 横线
for (int i = 0; i < 2; i ++) {
UIView *cellLine = [[UIView alloc] init];
cellLine.hidden = NO;
cellLine.backgroundColor = kGrayLineColor;
[catalogueButton addSubview:cellLine];
[cellLine mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(kMargin);
if (i == 0) {
make.top.mas_equalTo(kCellLineHeight);
} else {
make.bottom.mas_equalTo(catalogueButton.mas_bottom).with.offset(- kCellLineHeight);
}
make.width.mas_equalTo(self.mas_width).with.offset( - kMargin);
make.height.mas_equalTo(kCellLineHeight);
}];
}
UIImageView *connerImageView = [[UIImageView alloc] init];
connerImageView.image = [[UIImage imageNamed:@"public_more"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
connerImageView.userInteractionEnabled = YES;
connerImageView.tintColor = kGrayTextColor;
[catalogueButton addSubview:connerImageView];
[connerImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(catalogueButton.mas_right).with.offset(- kMargin);
make.centerY.mas_equalTo(catalogueButton.mas_centerY);
make.width.height.mas_equalTo(10);
}];
timeLabel = [[UILabel alloc] init];
timeLabel.textAlignment = NSTextAlignmentRight;
timeLabel.font = kFont10;
timeLabel.textColor = kGrayTextColor;
[catalogueButton addSubview:timeLabel];
[timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(connerImageView.mas_left).with.offset(- kQuarterMargin);
make.top.mas_equalTo(0);
make.width.mas_equalTo(CGFLOAT_MIN);
make.height.mas_equalTo(catalogueButton.mas_height);
}];
catalogueDetailLabel = [[UILabel alloc] init];
catalogueDetailLabel.backgroundColor = [UIColor clearColor];
catalogueDetailLabel.textAlignment = NSTextAlignmentLeft;
catalogueDetailLabel.font = kFont12;
catalogueDetailLabel.textColor = kGrayTextColor;
[catalogueButton addSubview:catalogueDetailLabel];
[catalogueDetailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(catalogueTitle.mas_right).offset(kQuarterMargin);
make.top.mas_equalTo(0);
make.right.mas_equalTo(timeLabel.mas_left).with.offset(- kQuarterMargin);
make.height.mas_equalTo(catalogueButton.mas_height);
}];
// 标签
tagView = [[TFTagboardView alloc] init];
tagView.textAlignment = TFTagboardTextAlignmentLeft;
tagView.borderStyle = TFTagboardBorderStyleFill;
tagView.layoutStyle = TFTagboardLayoutStyleScroll;
[self.contentView addSubview:tagView];
[tagView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(kMargin);
make.top.mas_equalTo(catalogueButton.mas_bottom).with.offset(kHalfMargin);
make.width.mas_equalTo(self.contentView.mas_width).with.offset(- 2 * kMargin);
make.height.mas_equalTo(20);
make.bottom.mas_equalTo(self.contentView.mas_bottom).with.offset(- kHalfMargin).priorityLow();
}];
}
- (void)catalogueClick
{
if (self.catalogueButtonClickBlock) {
self.catalogueButtonClickBlock();
}
}
- (void)setBookModel:(TFProductionModel *)bookModel
{
if (bookModel && (_bookModel != bookModel)) {
_bookModel = bookModel;
WS(weakSelf)
[[YYWebImageManager sharedManager] requestImageWithURL:[NSURL URLWithString:bookModel.cover?:@""] options:YYWebImageOptionSetImageWithFadeAnimation progress:nil transform:nil completion:^(UIImage * _Nullable image, NSURL * _Nonnull url, YYWebImageFromType from, YYWebImageStage stage, NSError * _Nullable error) {
dispatch_async(dispatch_get_main_queue(), ^{
weakSelf.headBackImageView.image = [image imgWithLightAlpha:0.4 radius:3 colorSaturationFactor:1.8];
});
}];
bookImageView.coverImageUrl = bookModel.cover;
bookNameLabel.text = [TFUtilsHelper formatStringWithObject:bookModel.name?:@""];
authorLabel.text = [TFUtilsHelper formatStringWithObject:bookModel.author?:@""];
[introductionLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(bookNameLabel.mas_left);
make.top.mas_equalTo(authorLabel.mas_bottom).with.offset(5);
make.width.mas_equalTo(bookNameLabel.mas_width);
make.height.mas_equalTo(authorLabel.mas_height);
}];
commontNumLabel.text = [TFUtilsHelper formatStringWithObject:bookModel.hot_num?:@""];
collecitonNumLabel.text = [TFUtilsHelper formatStringWithObject:bookModel.total_favors?:@""];
// 截取简介
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:bookModel.production_descirption?:@""];
attributedString.lineSpacing = 5;
attributedString.font = kFont(13);
attributedString.color = kBlackColor;
NSAttributedString *separatedString = [TFViewHelper getSubContentWithOriginalContent:attributedString labelWidth:(SCREEN_WIDTH - 2 * (kMargin + kHalfMargin)) labelMaxLine:4];
bookDescriptionLabel.attributedText = separatedString;
if (separatedString.length == 0) {
[bookDescriptionLabel mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(0.0);
}];
} else {
[bookDescriptionLabel mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo([TFViewHelper boundsWithFont:kFont(13) attributedText:separatedString needWidth:(SCREEN_WIDTH - 2 * (kMargin + kHalfMargin)) lineSpacing:6] + kHalfMargin);
}];
}
tagView.tagboardArray = bookModel.tag;
timeLabel.text = bookModel.last_chapter_time?:@"";
[timeLabel mas_updateConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo([TFViewHelper getDynamicWidthWithLabel:timeLabel]);
}];
catalogueDetailLabel.text = bookModel.last_chapter?:@"";
catalogueButton.hidden = NO;
}
}
@end
@@ -0,0 +1,20 @@
//
// TFComicDownloadContentChoiceController.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFDownloadViewController.h"
NS_ASSUME_NONNULL_BEGIN
@interface TFComicDownloadContentChoiceController : TFDownloadViewController
@property (nonatomic ,strong) TFProductionModel *comicModel;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,327 @@
//
// TFComicDownloadContentChoiceController.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFComicDownloadContentChoiceController.h"
#import "TFComicDownloadViewCell.h"
#import "WXYZ_ChapterBottomPayBar.h"
#import "TFComicDownloadModel.h"
#import "WXYZ_ComicDownloadManager.h"
@interface TFComicDownloadContentChoiceController ()<UICollectionViewDelegate, UICollectionViewDataSource>
{
UIView *toolBarView;
YYLabel *toolBarLeftLabel;
UILabel *toolBarRightLabel;
UIButton *deleteButton;
UIButton *selectAllButton;
}
@end
@implementation TFComicDownloadContentChoiceController
- (void)viewDidLoad
{
[super viewDidLoad];
[self initialize];
[self createSubviews];
[self netRequest];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self setStatusBarDefaultStyle];
}
- (void)initialize
{
[self setNavigationBarTitle:self.navTitle?:TFLocalizedString(@"选择章节")];
self.view.backgroundColor = kGrayViewColor;
}
- (void)createSubviews
{
TFButton *sortButton = [[TFButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - kHalfMargin - 60, PUB_NAVBAR_HEIGHT - 30 - kQuarterMargin, 60, 30) buttonTitle:TFLocalizedString(@"正序") buttonImageName:@"comic_positive_order" buttonIndicator:TFButtonIndicatorImageRightBothRight];
sortButton.selected = NO;
sortButton.buttonImageScale = 0.4;
sortButton.buttonTitleFont = kFont11;
sortButton.graphicDistance = 5;
sortButton.buttonTitleColor = kGrayTextColor;
[sortButton addTarget:self action:@selector(sortClick:) forControlEvents:UIControlEventTouchUpInside];
[self.navigationBar addSubview:sortButton];
self.mainCollectionViewFlowLayout.minimumLineSpacing = kHalfMargin;
self.mainCollectionViewFlowLayout.minimumInteritemSpacing = kHalfMargin;
self.mainCollectionViewFlowLayout.itemSize = CGSizeMake((SCREEN_WIDTH - 5 * kHalfMargin) / 4, 40);
self.mainCollectionViewFlowLayout.sectionInset = UIEdgeInsetsMake(kHalfMargin, kHalfMargin, kHalfMargin, kHalfMargin);
self.mainCollectionView.delegate = self;
self.mainCollectionView.dataSource = self;
self.mainCollectionView.alwaysBounceVertical = YES;
[self.mainCollectionView registerClass:[TFComicDownloadViewCell class] forCellWithReuseIdentifier:@"TFComicDownloadViewCell"];
[self.view addSubview:self.mainCollectionView];
[self.mainCollectionView 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 - PUB_TABBAR_HEIGHT - 20);
}];
toolBarView = [[UIView alloc] init];
toolBarView.backgroundColor = kWhiteColor;
[self.view addSubview:toolBarView];
[toolBarView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.bottom.mas_equalTo(self.view.mas_bottom);
make.width.mas_equalTo(self.view.mas_width);
make.height.mas_equalTo(PUB_TABBAR_HEIGHT + 20);
}];
toolBarLeftLabel = [[YYLabel alloc] init];
toolBarLeftLabel.textColor = kGrayTextColor;
toolBarLeftLabel.textContainerInset = UIEdgeInsetsMake(3, kHalfMargin, 0, 0);
toolBarLeftLabel.textAlignment = NSTextAlignmentLeft;
toolBarLeftLabel.font = kFont10;
toolBarLeftLabel.backgroundColor = kGrayDeepViewColor;
[toolBarView addSubview:toolBarLeftLabel];
[toolBarLeftLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.top.mas_equalTo(0);
make.width.mas_equalTo(toolBarView.mas_width);
make.height.mas_equalTo(20);
}];
toolBarRightLabel = [[UILabel alloc] init];
toolBarRightLabel.text = TFLocalizedString(@"已选0话");
toolBarRightLabel.textColor = kGrayTextColor;
toolBarRightLabel.textAlignment = NSTextAlignmentRight;
toolBarRightLabel.font = kFont10;
toolBarRightLabel.backgroundColor = [UIColor clearColor];
[toolBarView addSubview:toolBarRightLabel];
[toolBarRightLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(toolBarView.mas_right).with.offset(- kHalfMargin);
make.top.mas_equalTo(0);
make.width.mas_equalTo(toolBarView.mas_width).with.multipliedBy(0.5);
make.height.mas_equalTo(20);
}];
selectAllButton = [UIButton buttonWithType:UIButtonTypeCustom];
[selectAllButton setTitle:TFLocalizedString(@"全选") forState:UIControlStateNormal];
[selectAllButton setTitleColor:kBlackColor forState:UIControlStateNormal];
[selectAllButton.titleLabel setFont:kMainFont];
[selectAllButton addTarget:self action:@selector(checkallClick:) forControlEvents:UIControlEventTouchUpInside];
[toolBarView addSubview:selectAllButton];
[selectAllButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(toolBarView.mas_left);
make.top.mas_equalTo(toolBarRightLabel.mas_bottom);
make.width.mas_equalTo(SCREEN_WIDTH / 2);
make.height.mas_equalTo(PUB_TABBAR_HEIGHT - PUB_TABBAR_OFFSET);
}];
deleteButton = [UIButton buttonWithType:UIButtonTypeCustom];
deleteButton.enabled = NO;
[deleteButton setTitle:TFLocalizedString(@"删除") forState:UIControlStateNormal];
[deleteButton setTitleColor:kGrayTextLightColor forState:UIControlStateNormal];
[deleteButton.titleLabel setFont:kMainFont];
[deleteButton addTarget:self action:@selector(deleteClick:) forControlEvents:UIControlEventTouchUpInside];
[toolBarView addSubview:deleteButton];
[deleteButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(selectAllButton.mas_right);
make.top.mas_equalTo(toolBarRightLabel.mas_bottom);
make.right.mas_equalTo(toolBarView.mas_right);
make.height.mas_equalTo(PUB_TABBAR_HEIGHT - PUB_TABBAR_OFFSET);
}];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return self.dataSourceArray.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"TFComicDownloadViewCell";
TFProductionChapterModel *listModel = [self.dataSourceArray objectOrNilAtIndex:indexPath.row];
listModel.can_read = YES;
TFComicDownloadViewCell __weak *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
cell.chapterModel = listModel;
cell.cellDownloadState = [[self.selectSourceDictionary objectForKey:[TFUtilsHelper formatStringWithInteger:listModel.chapter_id]] integerValue];
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
TFProductionChapterModel *listModel = [self.dataSourceArray objectOrNilAtIndex:indexPath.row];
TFComicDownloadViewCell *cell = (TFComicDownloadViewCell *)[collectionView cellForItemAtIndexPath:indexPath];
switch (cell.cellDownloadState) {
case WXYZ_ProductionDownloadStateDownloaded:
[self setCollectionCellDownloadStateWithChapter_id:listModel.chapter_id downloadState:WXYZ_ProductionDownloadStateSelected];
[self reloadToolBar];
break;
case WXYZ_ProductionDownloadStateSelected:
[self setCollectionCellDownloadStateWithChapter_id:listModel.chapter_id downloadState:WXYZ_ProductionDownloadStateDownloaded];
[self reloadToolBar];
break;
default:
break;
}
}
#pragma mark - 点击事件
- (void)sortClick:(TFButton *)sender
{
if (sender.selected) {
sender.buttonImageName = @"comic_positive_order";
sender.buttonTitle = TFLocalizedString(@"正序");
} else {
sender.buttonImageName = @"comic_reverse_order";
sender.buttonTitle = TFLocalizedString(@"倒序");
}
sender.selected = !sender.selected;
self.dataSourceArray = [[[self.dataSourceArray reverseObjectEnumerator] allObjects] mutableCopy];
[self.mainCollectionView reloadData];
}
- (void)checkallClick:(UIButton *)sender
{
for (NSString *t_chapter_id in self.selectSourceDictionary.allKeys) {
if (!sender.selected) { // 全选状态
if ([[self.selectSourceDictionary objectForKey:t_chapter_id] integerValue] == WXYZ_ProductionDownloadStateDownloaded) {
[self setCollectionCellDownloadStateWithChapter_id:[t_chapter_id integerValue] downloadState:WXYZ_ProductionDownloadStateSelected];
}
} else {
if ([[self.selectSourceDictionary objectForKey:t_chapter_id] integerValue] == WXYZ_ProductionDownloadStateSelected) {
[self setCollectionCellDownloadStateWithChapter_id:[t_chapter_id integerValue] downloadState:WXYZ_ProductionDownloadStateDownloaded];
}
}
}
sender.selected = !sender.selected;
[self reloadToolBar];
}
- (void)deleteClick:(UIButton *)sender
{
NSMutableArray *t_deleteArr = [NSMutableArray array];
for (NSString *t_chapter_id in self.selectSourceDictionary.allKeys) {
if ([[self.selectSourceDictionary objectForKey:t_chapter_id] integerValue] == WXYZ_ProductionDownloadStateSelected) {
[t_deleteArr addObject:t_chapter_id];
}
}
WS(weakSelf)
[[WXYZ_ComicDownloadManager sharedManager] removeDownloadChaptersWithProduction_id:self.comicModel.production_id chapter_ids:t_deleteArr];
[WXYZ_ComicDownloadManager sharedManager].downloadDeleteFinishBlock = ^(NSArray * _Nonnull success_chapter_ids, NSArray * _Nonnull fail_chapter) {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusSuccess promptTitle:TFLocalizedString(@"删除成功")];
[weakSelf netRequest];
};
}
- (void)reloadToolBar
{
NSInteger selectIndex = 0;
NSInteger downloadedIndex = 0;
for (NSString *t_key in self.selectSourceDictionary) {
switch ([[self.selectSourceDictionary objectForKey:t_key] integerValue]) {
case WXYZ_ProductionDownloadStateDownloaded:
downloadedIndex ++;
break;
case WXYZ_ProductionDownloadStateSelected:
selectIndex ++;
break;
default:
break;
}
}
toolBarLeftLabel.text = [NSString stringWithFormat:TFLocalizedString(@"已下载%@话"), [TFUtilsHelper formatStringWithInteger:self.dataSourceArray.count]];
toolBarRightLabel.text = [NSString stringWithFormat:TFLocalizedString(@"已选%@话"), [TFUtilsHelper formatStringWithInteger:selectIndex]];
deleteButton.enabled = NO;
[deleteButton setTitleColor:kGrayTextLightColor forState:UIControlStateNormal];
selectAllButton.enabled = YES;
selectAllButton.selected = NO;
[selectAllButton setTitle:TFLocalizedString(@"全选") forState:UIControlStateNormal];
[selectAllButton mas_updateConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(SCREEN_WIDTH / 2);
}];
if (selectIndex > 0 && downloadedIndex == 0) { // 有选中的文件并且没有未选中的文件
deleteButton.enabled = YES;
[deleteButton setTitleColor:kBlackColor forState:UIControlStateNormal];
selectAllButton.selected = YES;
[selectAllButton setTitle:TFLocalizedString(@"取消全选") forState:UIControlStateNormal];
[selectAllButton setTitleColor:kBlackColor forState:UIControlStateNormal];
} else if (downloadedIndex > 0 && selectIndex > 0) { // 有未选中的文件
deleteButton.enabled = YES;
[deleteButton setTitleColor:kBlackColor forState:UIControlStateNormal];
}
}
- (void)setCollectionCellDownloadStateWithChapter_id:(NSInteger)chapter_id downloadState:(WXYZ_ProductionDownloadState)downloadState
{
TFComicDownloadViewCell *cell = (TFComicDownloadViewCell *)[self.mainCollectionView cellForItemAtIndexPath:(NSIndexPath *)[self.cellIndexDictionary objectForKey:[TFUtilsHelper formatStringWithInteger:chapter_id]]];
cell.cellDownloadState = downloadState;
[self.selectSourceDictionary setObject:[TFUtilsHelper formatStringWithInteger:downloadState] forKey:[TFUtilsHelper formatStringWithInteger:chapter_id]];
}
- (void)netRequest
{
self.dataSourceArray = [[[WXYZ_ComicDownloadManager sharedManager] getDownloadChapterModelArrayWithProduction_id:self.comicModel.production_id] mutableCopy];
// 章节名称序号排序
NSString *tmp = @"";
NSInteger m = self.dataSourceArray.count;
for (NSInteger i = 0; i < m - 1; i++) {
for (NSInteger j = 0; j < m- i - 1; j++) {
if ([[self.dataSourceArray[j] display_label] integerValue] > [[self.dataSourceArray[j + 1] display_label] integerValue]) {
tmp = self.dataSourceArray[j + 1];
self.dataSourceArray[j+1] = self.dataSourceArray[j];
self.dataSourceArray[j] = tmp;
}
}
}
if (self.dataSourceArray.count == 0) {
[self.navigationController popViewControllerAnimated:NO];
return;
}
[self resetSelectSourceDicWithDataSourceArray:[self.dataSourceArray copy] productionType:TFProductionTypeComic];
[self reloadToolBar];
[self.mainCollectionView reloadData];
}
@end
@@ -0,0 +1,24 @@
//
// TFComicDownloadManagerController.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 TFComicDownloadManagerController : TFBasicViewController
/// 切换编辑状态
@property (nonatomic ,copy ,readonly) BOOL (^editStateBlock)(void);
@property (nonatomic ,copy) void(^changeEditStateBlock)(BOOL status);
@property (nonatomic ,assign) BOOL isEditting;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,422 @@
//
// TFComicDownloadManagerController.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFComicDownloadManagerController.h"
#import "TFComicBrowseViewController.h"
#import "TFComicDownloadContentChoiceController.h"
#import "TFComicDownloadManagerCell.h"
#import "WXYZ_ComicDownloadManager.h"
#import "TFReadRecordManager.h"
#import "UIView+LayoutCallback.h"
#import "TFCollectionManager.h"
@interface TFComicDownloadManagerController ()<UITableViewDelegate, UITableViewDataSource>
/// 编辑页面
@property (nonatomic, weak) UIView *edittingView;
@property (nonatomic, weak) UIButton *edittingAll;
@property (nonatomic, weak) UIButton *edittingDelete;
@property (nonatomic, strong) NSMutableArray<NSNumber *> *selectedArray;
@property (nonatomic, weak) CALayer *topLayer;
@property (nonatomic, weak) CALayer *middleLayer;
@end
@implementation TFComicDownloadManagerController
- (void)viewDidLoad
{
[super viewDidLoad];
[self initialize];
[self createSubviews];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self setStatusBarDefaultStyle];
NSArray *t_sourceArray = [[[[WXYZ_DownloadHelper sharedManager] getDownloadProductionArrayWithProductionType:TFProductionTypeComic] reverseObjectEnumerator] allObjects];
self.dataSourceArray = [NSMutableArray array];
for (TFProductionModel *t_model in t_sourceArray) {
if ([[WXYZ_ComicDownloadManager sharedManager] getDownloadChapterCountWithProduction_id:t_model.production_id] > 0) {
[self.dataSourceArray addObject:t_model];
}
}
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.05 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
if (self.dataSourceArray.count == 0) {
[self.mainTableView xtfei_showEmptyView];
} else {
[self.mainTableView xtfei_hideEmptyView];
}
});
[self.mainTableView reloadData];
}
- (void)initialize
{
self.selectedArray = [NSMutableArray array];
// 设置编辑状态
WS(weakSelf)
_editStateBlock = ^() {
BOOL isEditting = NO;
if (weakSelf.mainTableView.visibleCells.count == 0) return NO;
for (UITableViewCell *cell in weakSelf.mainTableView.visibleCells) {
if ([cell isMemberOfClass:TFComicDownloadManagerCell.class]) {
TFComicDownloadManagerCell *celll = (TFComicDownloadManagerCell *)cell;
isEditting = !celll.isEditting;
weakSelf.isEditting = isEditting;
// 隐藏/显示底部编辑区域
if (isEditting) {
[UIView animateWithDuration:kAnimatedDuration animations:^{
[weakSelf.edittingView mas_updateConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(weakSelf.view);
}];
[weakSelf.edittingView.superview layoutIfNeeded];
}];
} else {
[UIView animateWithDuration:kAnimatedDuration animations:^{
[weakSelf.edittingView mas_updateConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(weakSelf.view).offset(CGRectGetHeight(weakSelf.edittingView .bounds));
}];
[weakSelf.edittingView.superview layoutIfNeeded];
}];
}
[celll setEditing:!celll.isEditting];
continue;
}
}
return isEditting;
};
[self hiddenNavigationBar:YES];
}
- (void)createSubviews
{
UIView *edittingView = [[UIView alloc] init];
self.edittingView = edittingView;
edittingView .backgroundColor = self.view.backgroundColor;
WS(weakSelf)
edittingView.frameBlock = ^(UIView * _Nonnull view) {
if (weakSelf.topLayer) return;
CALayer *layer = [CALayer layer];
layer.backgroundColor = kColorRGB(238, 238, 238).CGColor;
layer.frame = CGRectMake(0, 0, CGRectGetWidth(view.bounds), 0.5);
[view.layer addSublayer:layer];
weakSelf.topLayer = layer;
};
[self.view addSubview:edittingView ];
[edittingView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.width.bottom.equalTo(self.view);
}];
// 编辑状态下全选按钮
UIButton *edittingAll = [UIButton buttonWithType:UIButtonTypeCustom];
self.edittingAll = edittingAll;
[edittingAll setTitle:TFLocalizedString(@"全选") forState:UIControlStateNormal];
[edittingAll addTarget:self action:@selector(selectedAllEvent) forControlEvents:UIControlEventTouchUpInside];
edittingAll.frameBlock = ^(UIButton * _Nonnull button) {
if (weakSelf.middleLayer) return;
CALayer *layer = [CALayer layer];
layer.backgroundColor = kColorRGB(238, 238, 238).CGColor;
layer.frame = CGRectMake(CGRectGetMaxX(button.frame), 16.0f, 0.5, CGRectGetHeight(button.bounds) - 2 * 16.0f);
[button.layer addSublayer:layer];
weakSelf.middleLayer = layer;
};
[edittingAll setTitleColor:kBlackColor forState:UIControlStateNormal];
edittingAll.titleLabel.font = kFont14;
[edittingView addSubview:edittingAll];
[edittingAll mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(edittingView ).offset(1.0f);
make.left.equalTo(edittingView );
make.width.equalTo(edittingView ).multipliedBy(0.5f);
make.height.equalTo(edittingAll.mas_width).multipliedBy(60.0f / 187.5f);
make.bottom.equalTo(edittingView ).offset(-PUB_TABBAR_OFFSET).priorityLow();
}];
// 编辑状态下删除按钮
UIButton *edittingDelete = [UIButton buttonWithType:UIButtonTypeCustom];
self.edittingDelete = edittingDelete;
[edittingDelete setTitle:TFLocalizedString(@"删除") forState:UIControlStateNormal];
[edittingDelete addTarget:self action:@selector(deleteEvent) forControlEvents:UIControlEventTouchUpInside];
[edittingDelete setTitleColor:kGrayTextColor forState:UIControlStateNormal];
edittingDelete.titleLabel.font = kFont14;
[edittingView addSubview:edittingDelete];
[edittingDelete mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.top.equalTo(edittingAll);
make.left.equalTo(edittingAll.mas_right);
}];
[edittingView setNeedsLayout];
[edittingView layoutIfNeeded];
// 设置编辑区域默认高度
[edittingView mas_updateConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(self.view).offset(CGRectGetHeight(edittingView .bounds));
}];
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.top.left.right.equalTo(self.view);
make.bottom.equalTo(edittingView .mas_top);
}];
[self setEmptyOnView:self.mainTableView title:TFLocalizedString(@"还没有下载记录") tapBlock:nil];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.05 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
if (self.dataSourceArray.count == 0) {
[self.mainTableView xtfei_showEmptyView];
} else {
[self.mainTableView xtfei_hideEmptyView];
}
});
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.dataSourceArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
WS(weakSelf)
TFComicDownloadManagerCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TFComicDownloadManagerCell"];
if (!cell) {
cell = [[TFComicDownloadManagerCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"TFComicDownloadManagerCell"];
}
TFProductionModel *t_model = [self.dataSourceArray objectOrNilAtIndex:indexPath.row];
cell.comicModel = t_model;
[cell set_Editting:self.isEditting];
cell.cellSelectBlock = ^(TFProductionModel *comicModel, NSString *comic_name) {
TFComicDownloadContentChoiceController *vc = [[TFComicDownloadContentChoiceController alloc] init];
vc.comicModel = comicModel;
vc.navTitle = comic_name;
[weakSelf.navigationController pushViewController:vc animated:YES];
};
cell.imageViewSelectBlock = ^(NSInteger comic_id) {
TFComicDetailViewController *vc = [[TFComicDetailViewController alloc] init];
vc.comic_id = comic_id;
[weakSelf.navigationController pushViewController:vc animated:YES];
};
cell.buttonSelectBlock = ^(TFProductionModel *comicModel) {
[[TFCollectionManager shareManagerWithProductionType:TFProductionTypeComic] moveCollectionToTopWithProductionModel:t_model];
TFComicBrowseViewController *vc = [[TFComicBrowseViewController alloc] init];
vc.comicProductionModel = comicModel;
vc.chapter_id = [[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeComic] getReadingRecordChapter_idWithProduction_id:comicModel.production_id];
[weakSelf.navigationController pushViewController:vc animated:YES];
};
if ([self.selectedArray containsObject:@(t_model.production_id)]) {
[cell switchSelectedState:YES];
} else {
[cell switchSelectedState:NO];
}
cell.selecteEdittingCellBlock = ^(TFProductionModel * _Nonnull productionModel, BOOL isSelected) {
if (isSelected) {
[weakSelf.selectedArray addObject:@(productionModel.production_id)];
} else {
[weakSelf.selectedArray removeObject:@(productionModel.production_id)];
}
[weakSelf updateEdittingView];
};
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
{
TFProductionModel *t_model = [self.dataSourceArray objectOrNilAtIndex:indexPath.row];
[[WXYZ_ComicDownloadManager sharedManager] removeDownloadProductionWithProduction_id:t_model.production_id];
[self.dataSourceArray removeObject:t_model];
[self.mainTableView reloadData];
if (self.dataSourceArray.count > 0) {
[self.mainTableView xtfei_hideEmptyView];
} else {
[self.mainTableView xtfei_showEmptyView];
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return kHalfMargin;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, kHalfMargin)];
view.backgroundColor = [UIColor clearColor];
return view;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return CGFLOAT_MIN;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, PUB_TABBAR_OFFSET == 0 ? 10 : PUB_TABBAR_OFFSET)];
view.backgroundColor = [UIColor clearColor];
return view;
}
- (void)selectedAllEvent
{
if ([self.edittingAll.titleLabel.text isEqualToString:TFLocalizedString(@"全选")]) {
for (UITableViewCell *cell in self.mainTableView.visibleCells) {
if ([cell isMemberOfClass:TFComicDownloadManagerCell.class]) {
TFComicDownloadManagerCell *tempCell = (TFComicDownloadManagerCell *)cell;
[tempCell switchSelectedState:YES];
}
}
for (TFProductionModel *t_model in self.dataSourceArray) {
if (![self.selectedArray containsObject:@(t_model.production_id)]) {
[self.selectedArray addObject:@(t_model.production_id)];
}
}
} else {
for (UITableViewCell *cell in self.mainTableView.visibleCells) {
if ([cell isMemberOfClass:TFComicDownloadManagerCell.class]) {
TFComicDownloadManagerCell *tempCell = (TFComicDownloadManagerCell *)cell;
[tempCell switchSelectedState:NO];
}
}
[self.selectedArray removeAllObjects];
}
[self updateEdittingView];
}
// 删除按钮点击事件
- (void)deleteEvent {
if (self.selectedArray.count == 0) return;
NSMutableArray *arr = [self.dataSourceArray mutableCopy];
NSMutableArray<NSIndexPath *> *pathArr = [NSMutableArray array];
[arr enumerateObjectsUsingBlock:^(TFProductionModel * _Nonnull productionModel, NSUInteger idx, BOOL * _Nonnull stop) {
if ([self.selectedArray containsObject:@(productionModel.production_id)]) {
[[WXYZ_ComicDownloadManager sharedManager] removeDownloadProductionWithProduction_id:productionModel.production_id];
[self.dataSourceArray removeObject:productionModel];
[self.selectedArray removeObject:@(productionModel.production_id)];
[pathArr addObject:[NSIndexPath indexPathForRow:idx inSection:0]];
}
}];
WS(weakSelf)
if (@available(iOS 11.0, *)) {
[self.mainTableView performBatchUpdates:^{
[self.mainTableView deleteRowsAtIndexPaths:pathArr withRowAnimation:UITableViewRowAnimationLeft];
} completion:^(BOOL finished) {
if (!finished) return;
SS(strongSelf)
BOOL a = !strongSelf->_editStateBlock ?: strongSelf->_editStateBlock();
NSLog(@"%@", a?@"":@"");
[UIView animateWithDuration:kAnimatedDuration animations:^{
[self.edittingView mas_updateConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(self.view).offset(CGRectGetHeight(self.edittingView .bounds));
}];
[self.edittingView.superview layoutIfNeeded];
}];
!self.changeEditStateBlock ?: self.changeEditStateBlock(YES);
}];
} else {
[self.mainTableView beginUpdates];
[self.mainTableView deleteRowsAtIndexPaths:pathArr withRowAnimation:UITableViewRowAnimationLeft];
[self.mainTableView endUpdates];
dispatch_async(dispatch_get_main_queue(), ^{
SS(strongSelf)
BOOL a = !strongSelf->_editStateBlock ?: strongSelf->_editStateBlock();
NSLog(@"%@", a?@"":@"");
[UIView animateWithDuration:kAnimatedDuration animations:^{
[self.edittingView mas_updateConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(self.view).offset(CGRectGetHeight(self.edittingView .bounds));
}];
[self.edittingView.superview layoutIfNeeded];
}];
!self.changeEditStateBlock ?: self.changeEditStateBlock(YES);
});
}
if (self.dataSourceArray.count > 0) {
[self.mainTableView xtfei_hideEmptyView];
} else {
[self.mainTableView xtfei_showEmptyView];
}
self.isEditting = NO;
[self updateEdittingView];
}
// 更新底部编辑区域
- (void)updateEdittingView {
if (self.dataSourceArray.count > 0 && self.mainTableView.visibleCells.count == 0) return;
BOOL allSelected = YES;
for (TFProductionModel *t_model in self.dataSourceArray) {
if (![self.selectedArray containsObject:@(t_model.production_id)]) {
allSelected = NO;
break;
}
}
if (allSelected) {
[self.edittingAll setTitle:TFLocalizedString(@"取消全选") forState:UIControlStateNormal];
} else {
[self.edittingAll setTitle:TFLocalizedString(@"全选") forState:UIControlStateNormal];
}
if (self.selectedArray.count == 0) {
[self.edittingDelete setTitle:TFLocalizedString(@"删除") forState:UIControlStateNormal];
[self.edittingDelete setTitleColor:kGrayTextColor forState:UIControlStateNormal];
} else {
[self.edittingDelete setTitle:[NSString stringWithFormat:@"%@(%zd)", TFLocalizedString(@"删除"), self.selectedArray.count] forState:UIControlStateNormal];
[self.edittingDelete setTitleColor:kRedColor forState:UIControlStateNormal];
}
}
@end
@@ -0,0 +1,20 @@
//
// TFComicDownloadViewController.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/15.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFDownloadViewController.h"
NS_ASSUME_NONNULL_BEGIN
@interface TFComicDownloadViewController : TFDownloadViewController
@property (nonatomic ,strong) TFProductionModel *comicModel;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,483 @@
//
// TFComicDownloadViewController.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/15.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFComicDownloadViewController.h"
#import "TFComicDownloadViewCell.h"
#import "WXYZ_ChapterBottomPayBar.h"
#import "TFComicDownloadModel.h"
#import "WXYZ_ComicDownloadManager.h"
#import "TFReadRecordManager.h"
@interface TFComicDownloadViewController ()<UICollectionViewDelegate, UICollectionViewDataSource>
{
UIView *toolBarView;
YYLabel *toolBarLeftLabel;
UILabel *toolBarRightLabel;
UIButton *selectAllButton;
}
@property (nonatomic, strong) WXYZ_ComicDownloadManager *comicDownloadManager;
@property (nonatomic, strong) UIButton *downloadButton;
@property (nonatomic, strong) UIActivityIndicatorView *downloadIndicatorView;
@property (nonatomic, assign) BOOL payBarShowing;
@end
@implementation TFComicDownloadViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[self initialize];
[self createSubviews];
[self initDownloadManager];
[self netRequest];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self setStatusBarDefaultStyle];
}
- (void)initialize
{
[self setNavigationBarTitle:TFLocalizedString(@"选择章节")];
self.view.backgroundColor = kGrayViewColor;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(netRequest) name:Notification_Login_Success object:nil];
}
- (void)createSubviews
{
CGFloat width = [TFViewHelper getDynamicWidthWithLabelFont:kFont11 labelHeight:30.0 labelText:TFLocalizedString(@"正序") maxWidth:240];
width += kLabelHeight;
TFButton *sortButton = [[TFButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - kHalfMargin - width, PUB_NAVBAR_HEIGHT - 30 - kQuarterMargin, width, 30) buttonTitle:TFLocalizedString(@"正序") buttonImageName:@"comic_positive_order" buttonIndicator:TFButtonIndicatorImageRightBothRight];
sortButton.selected = NO;
sortButton.buttonImageScale = 0.4;
sortButton.buttonTitleFont = kFont11;
sortButton.graphicDistance = 5;
sortButton.buttonTitleColor = kGrayTextColor;
[sortButton addTarget:self action:@selector(sortClick:) forControlEvents:UIControlEventTouchUpInside];
[self.navigationBar addSubview:sortButton];
self.mainCollectionViewFlowLayout.minimumLineSpacing = kHalfMargin;
self.mainCollectionViewFlowLayout.minimumInteritemSpacing = kHalfMargin;
self.mainCollectionViewFlowLayout.itemSize = CGSizeMake((SCREEN_WIDTH - 5 * kHalfMargin) / 4, 40);
self.mainCollectionViewFlowLayout.sectionInset = UIEdgeInsetsMake(kHalfMargin, kHalfMargin, kHalfMargin, kHalfMargin);
self.mainCollectionView.delegate = self;
self.mainCollectionView.dataSource = self;
self.mainCollectionView.alwaysBounceVertical = YES;
[self.mainCollectionView registerClass:[TFComicDownloadViewCell class] forCellWithReuseIdentifier:@"TFComicDownloadViewCell"];
[self.view addSubview:self.mainCollectionView];
[self.mainCollectionView 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 - PUB_TABBAR_HEIGHT - 20);
}];
toolBarView = [[UIView alloc] init];
toolBarView.backgroundColor = kWhiteColor;
[self.view addSubview:toolBarView];
[toolBarView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.bottom.mas_equalTo(self.view.mas_bottom);
make.width.mas_equalTo(self.view.mas_width);
make.height.mas_equalTo(PUB_TABBAR_HEIGHT + 20);
}];
toolBarLeftLabel = [[YYLabel alloc] init];
toolBarLeftLabel.textColor = kGrayTextColor;
toolBarLeftLabel.textContainerInset = UIEdgeInsetsMake(3, kHalfMargin, 0, 0);
toolBarLeftLabel.textAlignment = NSTextAlignmentLeft;
toolBarLeftLabel.font = kFont10;
toolBarLeftLabel.backgroundColor = kGrayDeepViewColor;
[toolBarView addSubview:toolBarLeftLabel];
[toolBarLeftLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.top.mas_equalTo(0);
make.width.mas_equalTo(toolBarView.mas_width);
make.height.mas_equalTo(20);
}];
toolBarRightLabel = [[UILabel alloc] init];
toolBarRightLabel.text = TFLocalizedString(@"已选0话");
toolBarRightLabel.textColor = kGrayTextColor;
toolBarRightLabel.textAlignment = NSTextAlignmentRight;
toolBarRightLabel.font = kFont10;
toolBarRightLabel.backgroundColor = [UIColor clearColor];
toolBarRightLabel.hidden = YES;
[toolBarView addSubview:toolBarRightLabel];
[toolBarRightLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(toolBarView.mas_right).with.offset(- kHalfMargin);
make.top.mas_equalTo(0);
make.width.mas_equalTo(toolBarView.mas_width).with.multipliedBy(0.5);
make.height.mas_equalTo(20);
}];
selectAllButton = [UIButton buttonWithType:UIButtonTypeCustom];
[selectAllButton setTitle:TFLocalizedString(@"全选") forState:UIControlStateNormal];
[selectAllButton setTitleColor:kBlackColor forState:UIControlStateNormal];
[selectAllButton.titleLabel setFont:kMainFont];
[selectAllButton addTarget:self action:@selector(checkallClick:) forControlEvents:UIControlEventTouchUpInside];
[toolBarView addSubview:selectAllButton];
[selectAllButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(toolBarView.mas_left);
make.top.mas_equalTo(toolBarRightLabel.mas_bottom);
make.width.mas_equalTo(SCREEN_WIDTH / 2);
make.height.mas_equalTo(PUB_TABBAR_HEIGHT - PUB_TABBAR_OFFSET);
}];
self.downloadButton = [UIButton buttonWithType:UIButtonTypeCustom];
self.downloadButton.enabled = NO;
[self.downloadButton setTitle:TFLocalizedString(@"下载") forState:UIControlStateNormal];
[self.downloadButton setTitleColor:kGrayTextLightColor forState:UIControlStateNormal];
[self.downloadButton.titleLabel setFont:kMainFont];
[self.downloadButton addTarget:self action:@selector(downloadClick) forControlEvents:UIControlEventTouchUpInside];
[toolBarView addSubview:self.downloadButton];
[self.downloadButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(selectAllButton.mas_right);
make.top.mas_equalTo(toolBarRightLabel.mas_bottom);
make.right.mas_equalTo(toolBarView.mas_right);
make.height.mas_equalTo(PUB_TABBAR_HEIGHT - PUB_TABBAR_OFFSET);
}];
self.downloadIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:(UIActivityIndicatorViewStyleGray)];
self.downloadIndicatorView.hidesWhenStopped = YES;
[toolBarView addSubview:self.downloadIndicatorView];
[self.downloadIndicatorView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self.downloadButton.mas_centerX);
make.centerY.mas_equalTo(self.downloadButton.mas_centerY);
make.width.height.mas_equalTo(self.downloadButton.mas_height);
}];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return self.dataSourceArray.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
TFProductionChapterModel *chapterModel = [self.dataSourceArray objectOrNilAtIndex:indexPath.row];
static NSString *cellIdentifier = @"TFComicDownloadViewCell";
TFComicDownloadViewCell __weak *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
cell.chapterModel = chapterModel;
cell.cellDownloadState = [[self.selectSourceDictionary objectForKey:[TFUtilsHelper formatStringWithInteger:chapterModel.chapter_id]] integerValue];
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
TFProductionChapterModel *chapterModel = [self.dataSourceArray objectOrNilAtIndex:indexPath.row];
TFComicDownloadViewCell *cell = (TFComicDownloadViewCell *)[collectionView cellForItemAtIndexPath:indexPath];
switch (cell.cellDownloadState) {
case WXYZ_ProductionDownloadStateNormal:
case WXYZ_ProductionDownloadStateFail:
[self setCollectionCellDownloadStateWithChapter_id:chapterModel.chapter_id downloadState:WXYZ_ProductionDownloadStateSelected];
[self reloadToolBar];
break;
case WXYZ_ProductionDownloadStateSelected:
[self setCollectionCellDownloadStateWithChapter_id:chapterModel.chapter_id downloadState:WXYZ_ProductionDownloadStateNormal];
[self reloadToolBar];
break;
default:
break;
}
}
#pragma mark - 点击事件
- (void)sortClick:(TFButton *)sender
{
if (sender.selected) {
sender.buttonImageName = @"comic_positive_order";
sender.buttonTitle = TFLocalizedString(@"正序");
} else {
sender.buttonImageName = @"comic_reverse_order";
sender.buttonTitle = TFLocalizedString(@"倒序");
}
sender.selected = !sender.selected;
self.dataSourceArray = [[[self.dataSourceArray reverseObjectEnumerator] allObjects] mutableCopy];
[self.mainCollectionView reloadData];
}
- (void)checkallClick:(UIButton *)sender
{
for (NSString *t_chapter_id in self.selectSourceDictionary.allKeys) {
if (!sender.selected) { // 全选状态
if ([[self.selectSourceDictionary objectForKey:t_chapter_id] integerValue] == WXYZ_ProductionDownloadStateNormal || [[self.selectSourceDictionary objectForKey:t_chapter_id] integerValue] == WXYZ_ProductionDownloadStateFail) {
[self setCollectionCellDownloadStateWithChapter_id:[t_chapter_id integerValue] downloadState:WXYZ_ProductionDownloadStateSelected];
}
} else {
if ([[self.selectSourceDictionary objectForKey:t_chapter_id] integerValue] == WXYZ_ProductionDownloadStateSelected) {
[self setCollectionCellDownloadStateWithChapter_id:[t_chapter_id integerValue] downloadState:WXYZ_ProductionDownloadStateNormal];
}
}
}
sender.selected = !sender.selected;
[self reloadToolBar];
}
- (void)initDownloadManager
{
WS(weakSelf)
self.comicDownloadManager = [WXYZ_ComicDownloadManager sharedManager];
self.comicDownloadManager.downloadChapterStateChangeBlock = ^(WXYZ_DownloadChapterState state, NSInteger production_id, NSInteger chapter_id) {
dispatch_async(dispatch_get_main_queue(), ^{
switch (state) {
case WXYZ_DownloadStateChapterDownloadFinished: // 章节下载完成
{
[weakSelf setCollectionCellDownloadStateWithChapter_id:chapter_id downloadState:WXYZ_ProductionDownloadStateDownloaded];
}
break;
case WXYZ_DownloadStateChapterDownloadFail: // 下载失败
{
[weakSelf setCollectionCellDownloadStateWithChapter_id:chapter_id downloadState:WXYZ_ProductionDownloadStateFail];
}
break;
case WXYZ_DownloadStateChapterDownloadStart: // 开始下载
{
[weakSelf setCollectionCellDownloadStateWithChapter_id:chapter_id downloadState:WXYZ_ProductionDownloadStateDownloading];
}
break;
default:
break;
}
[weakSelf reloadToolBar];
});
};
self.comicDownloadManager.downloadMissionStateChangeBlock = ^(WXYZ_DownloadMissionState state, NSInteger production_id, NSArray * _Nonnull chapter_ids) {
switch (state) {
// 任务开始
case WXYZ_DownloadStateMissionStart:
{
[weakSelf.downloadIndicatorView stopAnimating];
weakSelf.downloadButton.hidden = NO;
for (NSString *t_chapter_id in chapter_ids) {
[weakSelf setCollectionCellDownloadStateWithChapter_id:[t_chapter_id integerValue] downloadState:WXYZ_ProductionDownloadStateDownloading];
}
}
break;
// 任务失败
case WXYZ_DownloadStateMissionFail:
{
[weakSelf.downloadIndicatorView stopAnimating];
weakSelf.downloadButton.hidden = NO;
for (NSString *t_chapter_id in chapter_ids) {
[weakSelf setCollectionCellDownloadStateWithChapter_id:[t_chapter_id integerValue] downloadState:WXYZ_ProductionDownloadStateFail];
}
}
break;
// 需要支付
case WXYZ_DownloadStateMissionShouldPay:
{
[weakSelf.downloadIndicatorView stopAnimating];
weakSelf.downloadButton.hidden = NO;
if (!weakSelf.payBarShowing) {
weakSelf.payBarShowing = YES;
TFProductionChapterModel *chapterModel = [[TFProductionChapterModel alloc] init];
chapterModel.production_id = production_id;
chapterModel.chapter_ids = chapter_ids;
WXYZ_ChapterBottomPayBar *payBar = [[WXYZ_ChapterBottomPayBar alloc] initWithChapterModel:chapterModel barType:WXYZ_BottomPayBarTypeDownload productionType:TFProductionTypeComic];
payBar.paySuccessChaptersBlock = ^(NSArray<NSString *> * _Nonnull success_chapter_ids) {
[weakSelf downloadClick];
};
payBar.payFailChaptersBlock = ^(NSArray<NSString *> * _Nonnull fail_chapter_ids) {
for (NSString *t_chapter_id in fail_chapter_ids) {
[weakSelf setCollectionCellDownloadStateWithChapter_id:[t_chapter_id integerValue] downloadState:WXYZ_ProductionDownloadStateNormal];
}
[weakSelf reloadToolBar];
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:TFLocalizedString(@"购买失败")];
};
payBar.payCancleChapterBlock = ^(NSArray<NSString *> * _Nonnull fail_chapter_ids) {
for (NSString *t_chapter_id in fail_chapter_ids) {
[weakSelf setCollectionCellDownloadStateWithChapter_id:[t_chapter_id integerValue] downloadState:WXYZ_ProductionDownloadStateNormal];
}
[weakSelf reloadToolBar];
};
SS(strongSelf)
payBar.bottomPayBarHiddenBlock = ^{
strongSelf.payBarShowing = NO;
};
[payBar showBottomPayBar];
}
}
break;
case WXYZ_DownloadStateMissionFinished:
[TFPromptManager showPromptViewWithStatus:TFPromptStatusSuccess promptTitle:TFLocalizedString(@"下载完成")];
break;
default:
break;
}
weakSelf.downloadButton.userInteractionEnabled = YES;
};
}
- (void)downloadClick
{
self.downloadButton.userInteractionEnabled = NO;
NSMutableArray *chapter_ids = [NSMutableArray array];
for (NSString *t_chapter_id in self.selectSourceDictionary.allKeys) {
if ([[self.selectSourceDictionary objectForKey:t_chapter_id] integerValue] == WXYZ_ProductionDownloadStateSelected) {
[chapter_ids addObject:t_chapter_id];
}
}
[self.downloadIndicatorView startAnimating];
self.downloadButton.hidden = YES;
[self reloadToolBar];
[self.comicDownloadManager downloadChaptersWithProductionModel:self.comicModel production_id:self.comicModel.production_id chapter_ids:chapter_ids];
}
- (void)reloadToolBar
{
NSInteger normalIndex = 0;
NSInteger selectIndex = 0;
NSInteger downloadedIndex = 0;
for (NSString *t_key in self.selectSourceDictionary) {
switch ([[self.selectSourceDictionary objectForKey:t_key] integerValue]) {
case WXYZ_ProductionDownloadStateNormal:
normalIndex ++;
break;
case WXYZ_ProductionDownloadStateDownloaded:
downloadedIndex ++;
break;
case WXYZ_ProductionDownloadStateSelected:
selectIndex ++;
break;
default:
break;
}
}
toolBarRightLabel.text = [NSString stringWithFormat:TFLocalizedString(@"已选%@话"), [TFUtilsHelper formatStringWithInteger:selectIndex]];
toolBarRightLabel.hidden = (selectIndex == 0);
if (downloadedIndex == self.dataSourceArray.count) {
toolBarRightLabel.text = @"";
selectAllButton.enabled = NO;
selectAllButton.selected = NO;
[selectAllButton setTitle:TFLocalizedString(@"已全部下载") forState:UIControlStateNormal];
[selectAllButton setTitleColor:kGrayTextLightColor forState:UIControlStateNormal];
[selectAllButton mas_updateConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(SCREEN_WIDTH);
}];
return;
}
self.downloadButton.enabled = NO;
[self.downloadButton setTitleColor:kGrayTextLightColor forState:UIControlStateNormal];
selectAllButton.enabled = YES;
selectAllButton.selected = NO;
[selectAllButton setTitle:TFLocalizedString(@"全选") forState:UIControlStateNormal];
[selectAllButton mas_updateConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(SCREEN_WIDTH / 2);
}];
if (selectIndex > 0 && normalIndex == 0) { // 有选中的文件并且没有未选中的文件
self.downloadButton.enabled = YES;
[self.downloadButton setTitleColor:kBlackColor forState:UIControlStateNormal];
selectAllButton.selected = YES;
[selectAllButton setTitle:TFLocalizedString(@"取消全选") forState:UIControlStateNormal];
[selectAllButton setTitleColor:kBlackColor forState:UIControlStateNormal];
} else if (normalIndex > 0 && selectIndex > 0) { // 有未选中的文件
self.downloadButton.enabled = YES;
[self.downloadButton setTitleColor:kBlackColor forState:UIControlStateNormal];
}
}
- (void)setCollectionCellDownloadStateWithChapter_id:(NSInteger)chapter_id downloadState:(WXYZ_ProductionDownloadState)downloadState
{
TFComicDownloadViewCell *cell = (TFComicDownloadViewCell *)[self.mainCollectionView cellForItemAtIndexPath:(NSIndexPath *)[self.cellIndexDictionary objectForKey:[TFUtilsHelper formatStringWithInteger:chapter_id]]];
cell.cellDownloadState = downloadState;
[self.selectSourceDictionary setObject:[TFUtilsHelper formatStringWithInteger:downloadState] forKey:[TFUtilsHelper formatStringWithInteger:chapter_id]];
}
- (void)netRequest
{
WS(weakSelf)
[TFNetworkTools POSTQuick:Comic_DownloadOption parameters:@{@"comic_id":[TFUtilsHelper formatStringWithInteger:self.comicModel.production_id]} model:TFComicDownloadModel.class success:^(BOOL isSuccess, TFComicDownloadModel *_Nullable t_model, BOOL isCache, TFNetworkRequestModel *requestModel) {
if (isSuccess) {
toolBarLeftLabel.text = t_model.display_label?:@"";
if (t_model.down_list.count > 0) {
weakSelf.dataSourceArray = [NSMutableArray arrayWithArray:t_model.down_list];
[weakSelf resetSelectSourceDicWithDataSourceArray:t_model.down_list productionType:TFProductionTypeComic];
}
} else {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:requestModel.msg];
}
[weakSelf.mainCollectionView reloadData];
[weakSelf reloadToolBar];
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
[weakSelf.mainCollectionView reloadData];
}];
}
@end
@@ -0,0 +1,24 @@
//
// TFComicDownloadModel.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/15.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface TFComicDownloadModel : NSObject
@property (nonatomic ,assign) NSInteger total_chapters;
@property (nonatomic ,copy) NSString *display_label;
@property (nonatomic ,strong) NSArray <TFProductionChapterModel *>*down_list;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,26 @@
//
// TFComicDownloadModel.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/15.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFComicDownloadModel.h"
@implementation TFComicDownloadModel
+ (NSDictionary *)modelCustomPropertyMapper
{
return @{
@"total_chapters" : @"base_info.total_chapters",
@"display_label" : @"base_info.display_label"
};
}
+ (NSDictionary<NSString *,id> *)modelContainerPropertyGenericClass
{
return @{@"down_list" : [TFProductionChapterModel class]};
}
@end
@@ -0,0 +1,45 @@
//
// TFComicDownloadManagerCell.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
typedef void(^CellSelectBlock)(TFProductionModel *comicModel, NSString *comic_name);
typedef void(^ImageViewSelectBlock)(NSInteger comic_id);
typedef void(^ButtonSelectBlock)(TFProductionModel *comicModel);
@interface TFComicDownloadManagerCell : TFBasicTableViewCell
@property (nonatomic, strong) TFProductionModel *comicModel;
@property (nonatomic, copy) CellSelectBlock cellSelectBlock;
@property (nonatomic, copy) ImageViewSelectBlock imageViewSelectBlock;
@property (nonatomic, copy) ButtonSelectBlock buttonSelectBlock;
@property (nonatomic, assign, readonly) BOOL isEditting;
@property (nonatomic, assign, readonly) BOOL isSelected;
/// 选择编辑单元
@property (nonatomic, copy) void(^selecteEdittingCellBlock)(TFProductionModel *productionModel, BOOL isSelected);
- (void)setEditing:(BOOL)editing;
// 强行设置编辑状态
- (void)set_Editting:(BOOL)editting;
// 切换选中状态
- (void)switchSelectedState:(BOOL)state;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,236 @@
//
// TFComicDownloadManagerCell.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/16.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFComicDownloadManagerCell.h"
#import "WXYZ_ComicDownloadManager.h"
#import "TFReadRecordManager.h"
@interface TFComicDownloadManagerCell ()
@property (nonatomic ,weak) UIView *mainView;
@property (nonatomic ,weak) TFProductionCoverView *coverImageView;
@property (nonatomic ,weak) UILabel *titleNameLabel;
@property (nonatomic ,weak) UILabel *subTitleLabel;
@property (nonatomic ,weak) UIButton *readButton;
@property (nonatomic ,weak) UIImageView *selectedView;
@end
@implementation TFComicDownloadManagerCell
- (void)createSubviews
{
[super createSubviews];
[self addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(cellTapClick:)]];
UIView *mainView = [[UIView alloc] init];
self.mainView = mainView;
mainView.backgroundColor = [UIColor clearColor];
[self.contentView addSubview:mainView];
[mainView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.contentView);
make.left.equalTo(self.contentView).offset(-16.0f);
make.width.equalTo(self.contentView).offset(16.0f);
make.height.equalTo(self.contentView);
}];
UIImageView *selectedView = [[UIImageView alloc] init];
self.selectedView = selectedView;
selectedView.image = [UIImage imageNamed:@"audio_download_unselect"];
[mainView addSubview:selectedView];
[selectedView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.height.mas_equalTo(16.0f);
make.left.equalTo(mainView);
make.centerY.equalTo(mainView);
}];
TFProductionCoverView *coverImageView = [[TFProductionCoverView alloc] initWithProductionType:TFProductionTypeComic coverDirection:TFProductionCoverDirectionVertical];
self.coverImageView = coverImageView;
coverImageView.tag = 200;
[coverImageView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(cellTapClick:)]];
[mainView addSubview:coverImageView];
[coverImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(selectedView.mas_right).with.offset(kHalfMargin);
make.top.mas_equalTo(mainView.mas_top).with.offset(kQuarterMargin);
make.width.mas_equalTo(BOOK_WIDTH_SMALL - kMargin);
make.height.mas_equalTo(kGeometricHeight(BOOK_WIDTH_SMALL - kMargin, 3, 4));
make.bottom.mas_equalTo(mainView.mas_bottom).with.offset(- kQuarterMargin).priorityLow();
}];
UILabel *titleNameLabel = [[UILabel alloc] init];
self.titleNameLabel = titleNameLabel;
titleNameLabel.textColor = kBlackColor;
titleNameLabel.textAlignment = NSTextAlignmentLeft;
titleNameLabel.font = kBoldFont14;
titleNameLabel.numberOfLines = 0;
[mainView addSubview:titleNameLabel];
[titleNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(coverImageView.mas_right).with.offset(kHalfMargin);
make.top.mas_equalTo(coverImageView.mas_top);
make.right.mas_equalTo(mainView.mas_right).offset(-kQuarterMargin);
}];
UILabel *subTitleLabel = [[UILabel alloc] init];
self.subTitleLabel = subTitleLabel;
subTitleLabel.textColor = kGrayTextColor;
subTitleLabel.textAlignment = NSTextAlignmentLeft;
subTitleLabel.font = kFont12;
subTitleLabel.numberOfLines = 1;
[mainView addSubview:subTitleLabel];
[subTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.mas_equalTo(titleNameLabel);
make.bottom.mas_equalTo(coverImageView.mas_bottom);
}];
UIButton *readButton = [UIButton buttonWithType:UIButtonTypeCustom];
self.readButton = readButton;
readButton.backgroundColor = kMainColor;
readButton.layer.cornerRadius = 12;
[readButton setTitle:TFLocalizedString(@"开始阅读") forState:UIControlStateNormal];
[readButton setTitleColor:kWhiteColor forState:UIControlStateNormal];
[readButton.titleLabel setFont:kFont12];
[readButton addTarget:self action:@selector(readButtonClick) forControlEvents:UIControlEventTouchUpInside];
[mainView addSubview:readButton];
[readButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(mainView.mas_right).with.offset(- kHalfMargin);
make.centerY.mas_equalTo(mainView.mas_centerY);
make.width.mas_equalTo(70);
make.height.mas_equalTo(24);
}];
[titleNameLabel mas_updateConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(self.readButton.mas_top).offset(-kQuarterMargin);
}];
[subTitleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.readButton.mas_bottom).offset(kQuarterMargin);
}];
}
- (void)setComicModel:(TFProductionModel *)comicModel
{
_comicModel = comicModel;
if (comicModel.vertical_cover.length > 0) {
self.coverImageView.coverImageUrl = comicModel.vertical_cover;
} else if (comicModel.horizontal_cover.length > 0) {
self.coverImageView.coverImageUrl = comicModel.horizontal_cover;
} else {
self.coverImageView.coverImageUrl = comicModel.cover;
}
self.titleNameLabel.text = comicModel.name?:@"";
self.subTitleLabel.text = [NSString stringWithFormat:TFLocalizedString(@"%@话/%@话"), [TFUtilsHelper formatStringWithInteger:[[WXYZ_ComicDownloadManager sharedManager] getDownloadChapterCountWithProduction_id:comicModel.production_id]], [TFUtilsHelper formatStringWithInteger:comicModel.total_chapters]];
if ([[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeComic] getReadingRecordChapterTitleWithProduction_id:comicModel.production_id].length > 0) {
[self.readButton setTitle:TFLocalizedString(@"继续阅读") forState:UIControlStateNormal];
} else {
[self.readButton setTitle:TFLocalizedString(@"开始阅读") forState:UIControlStateNormal];
}
}
- (void)cellTapClick:(UITapGestureRecognizer *)tap
{
if (_isEditting) {
[self switchSelectedState:!_isSelected];
return;
}
if (tap.view.tag == 200) {
if (self.imageViewSelectBlock) {
self.imageViewSelectBlock(_comicModel.production_id);
}
} else {
if (self.cellSelectBlock) {
self.cellSelectBlock(_comicModel, _comicModel.name);
}
}
}
- (void)readButtonClick
{
if (self.buttonSelectBlock) {
self.buttonSelectBlock(_comicModel);
}
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
return YES;
}
- (void)switchSelectedState:(BOOL)state {
UIImage *image = nil;
if (state) {
image = [UIImage imageNamed:@"audio_download_select"];
} else {
image = [UIImage imageNamed:@"audio_download_unselect"];
}
_isSelected = state;
self.selectedView.image = image;
!self.selecteEdittingCellBlock ?: self.selecteEdittingCellBlock(self.comicModel, state);
}
- (void)setEditing:(BOOL)editing {
if (editing && _isEditting == NO) {
self.readButton.hidden = editing;
[UIView animateWithDuration:0.2 animations:^{
[self.mainView mas_updateConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentView).offset(17.0f);
}];
[self.mainView.superview layoutIfNeeded];
} completion:^(BOOL finished) {
if (finished) {
self->_isEditting = YES;
}
}];
return;
}
if (!editing && _isEditting == YES) {
self.readButton.hidden = editing;
[UIView animateWithDuration:0.2 animations:^{
[self.mainView mas_updateConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentView).offset(-16.0f);
}];
[self.mainView.superview layoutIfNeeded];
} completion:^(BOOL finished) {
if (finished) {
self->_isEditting = NO;
}
}];
return;
}
}
- (void)set_Editting:(BOOL)editting {
if (editting) {
[self.mainView mas_updateConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentView).offset(17.0f);
}];
} else {
[self.mainView mas_updateConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentView).offset(-16.0f);
}];
}
[self.mainView.superview layoutIfNeeded];
_isEditting = editting;
}
@end
@@ -0,0 +1,22 @@
//
// TFComicDownloadViewCell.h
// TFReader
//
// Created by 谢腾飞 on 2020/12/15.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "WXYZ_DownloadManagerEnumProtocol.h"
NS_ASSUME_NONNULL_BEGIN
@interface TFComicDownloadViewCell : UICollectionViewCell
@property (nonatomic ,strong) TFProductionChapterModel *chapterModel;
@property (nonatomic ,assign) WXYZ_ProductionDownloadState cellDownloadState;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,170 @@
//
// TFComicDownloadViewCell.m
// TFReader
//
// Created by 谢腾飞 on 2020/12/15.
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
//
#import "TFComicDownloadViewCell.h"
#import "WXYZ_ComicDownloadManager.h"
@interface TFComicDownloadViewCell ()
{
UILabel *chapterNumLabel;
UIImageView *lockImageView;
UILabel *cellStateLabel;
}
@end
@implementation TFComicDownloadViewCell
- (instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
self.backgroundColor = [UIColor clearColor];
[self createSubViews];
}
return self;
}
- (void)createSubViews
{
chapterNumLabel = [[UILabel alloc] init];
chapterNumLabel.backgroundColor = kWhiteColor;
chapterNumLabel.textColor = kBlackColor;
chapterNumLabel.textAlignment = NSTextAlignmentCenter;
chapterNumLabel.font = kMainFont;
chapterNumLabel.layer.cornerRadius = 8;
chapterNumLabel.clipsToBounds = YES;
[self addSubview:chapterNumLabel];
[chapterNumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self);
}];
lockImageView = [[UIImageView alloc] init];
lockImageView.image = [[UIImage imageNamed:@"comic_lock"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
lockImageView.tintColor = kMainColor;
lockImageView.hidden = YES;
[chapterNumLabel addSubview:lockImageView];
[lockImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(kQuarterMargin);
make.top.mas_equalTo(kQuarterMargin);
make.width.height.mas_equalTo(self.mas_height).with.multipliedBy(0.3);
}];
cellStateLabel = [[UILabel alloc] init];
cellStateLabel.backgroundColor = [UIColor clearColor];
cellStateLabel.textColor = kWhiteColor;
cellStateLabel.textAlignment = NSTextAlignmentCenter;
cellStateLabel.font = kFont6;
cellStateLabel.layer.cornerRadius = (self.height * 0.2) / 2;
cellStateLabel.clipsToBounds = YES;
[chapterNumLabel addSubview:cellStateLabel];
[cellStateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(chapterNumLabel.mas_right).with.offset(- 2);
make.bottom.mas_equalTo(chapterNumLabel.mas_bottom).with.offset(- 2);
make.width.mas_equalTo(20);
make.height.mas_equalTo(self.mas_height).with.multipliedBy(0.2);
}];
}
- (void)setChapterModel:(TFProductionChapterModel *)chapterModel
{
_chapterModel = chapterModel;
chapterNumLabel.text = chapterModel.display_label?:@"";
if (chapterModel.can_read) {
lockImageView.hidden = YES;
} else {
lockImageView.hidden = NO;
}
chapterNumLabel.text = chapterModel.display_label?:@"";
}
- (void)setCellDownloadState:(WXYZ_ProductionDownloadState)cellDownloadState
{
_cellDownloadState = cellDownloadState;
lockImageView.hidden = self.chapterModel.can_read;
switch (cellDownloadState) {
case WXYZ_ProductionDownloadStateNormal:
{
cellStateLabel.backgroundColor = [UIColor clearColor];
cellStateLabel.hidden = YES;
cellStateLabel.text = @"";
lockImageView.tintColor = kMainColor;
chapterNumLabel.backgroundColor = kWhiteColor;
chapterNumLabel.textColor = kBlackColor;
}
break;
case WXYZ_ProductionDownloadStateDownloading:
{
cellStateLabel.backgroundColor = kColorRGBA(28, 220, 142, 1);
cellStateLabel.hidden = NO;
cellStateLabel.text = TFLocalizedString(@"下载中");
lockImageView.tintColor = kMainColor;
lockImageView.hidden = YES;
chapterNumLabel.backgroundColor = kGrayDeepViewColor;
chapterNumLabel.textColor = kGrayTextColor;
}
break;
case WXYZ_ProductionDownloadStateDownloaded:
{
cellStateLabel.backgroundColor = kColorRGBA(28, 220, 142, 0.5);
cellStateLabel.hidden = NO;
cellStateLabel.text = TFLocalizedString(@"本地");
lockImageView.tintColor = kMainColor;
lockImageView.hidden = YES;
chapterNumLabel.backgroundColor = kGrayDeepViewColor;
chapterNumLabel.textColor = kGrayTextColor;
}
break;
case WXYZ_ProductionDownloadStateFail:
{
cellStateLabel.backgroundColor = kRedColor;
cellStateLabel.hidden = NO;
cellStateLabel.text = TFLocalizedString(@"失败");
lockImageView.tintColor = kMainColor;
chapterNumLabel.backgroundColor = kWhiteColor;
chapterNumLabel.textColor = kBlackColor;
}
break;
case WXYZ_ProductionDownloadStateSelected:
{
cellStateLabel.backgroundColor = [UIColor clearColor];
cellStateLabel.hidden = YES;
cellStateLabel.text = @"";
lockImageView.tintColor = kWhiteColor;
chapterNumLabel.backgroundColor = kMainColor;
chapterNumLabel.textColor = kWhiteColor;
}
break;
default:
break;
}
[cellStateLabel mas_updateConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo([TFViewHelper getDynamicWidthWithLabelFont:kFont6 labelHeight:(self.height * 0.2) labelText:cellStateLabel.text]);
}];
}
@end

Some files were not shown because too many files have changed in this diff Show More