小说绘上架版本
This commit is contained in:
+19
@@ -0,0 +1,19 @@
|
||||
//
|
||||
// TFReadNovelBackgroundController.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 TFReadNovelBackgroundController : UIViewController
|
||||
|
||||
- (void)updateWithViewController:(UIViewController *)viewController;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
//
|
||||
// TFReadNovelBackgroundController.m
|
||||
// TFReader
|
||||
//
|
||||
// Created by 谢腾飞 on 2020/12/15.
|
||||
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TFReadNovelBackgroundController.h"
|
||||
#import "TFReaderSettingHelper.h"
|
||||
#import "TFAdvertisementManager.h"
|
||||
|
||||
@interface TFReadNovelBackgroundController ()
|
||||
|
||||
@property (nonatomic ,weak) UIImageView *backgroundImageView;
|
||||
|
||||
@end
|
||||
|
||||
@implementation TFReadNovelBackgroundController
|
||||
|
||||
- (instancetype)init
|
||||
{
|
||||
if (self = [super init]) {
|
||||
[self createSubviews];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)createSubviews
|
||||
{
|
||||
self.view.backgroundColor = [[TFReaderSettingHelper sharedManager] getReaderBackgroundColor];
|
||||
|
||||
UIImageView *backgroundImageView = [[UIImageView alloc] initWithFrame:CGRectZero];
|
||||
backgroundImageView.backgroundColor = self.view.backgroundColor;
|
||||
self.backgroundImageView = backgroundImageView;
|
||||
[self.view addSubview:backgroundImageView];
|
||||
}
|
||||
|
||||
- (void)updateWithViewController:(UIViewController *)viewController
|
||||
{
|
||||
self.backgroundImageView.frame = viewController.view.bounds;
|
||||
self.backgroundImageView.image = [self captureView:viewController.view];
|
||||
self.backgroundImageView.alpha = 0.6;
|
||||
}
|
||||
|
||||
- (UIImage *)captureView:(UIView *)view
|
||||
{
|
||||
UIImage * __block image = nil;
|
||||
kCodeSync({
|
||||
CGRect rect = view.bounds;
|
||||
UIGraphicsBeginImageContextWithOptions(rect.size, YES, 0.0f);
|
||||
CGContextRef context = UIGraphicsGetCurrentContext();
|
||||
|
||||
CGAffineTransform transform = CGAffineTransformMake(-1.0, 0.0, 0.0, 1.0, rect.size.width, 0.0);
|
||||
CGContextConcatCTM(context,transform);
|
||||
[view.layer renderInContext:context];
|
||||
image = UIGraphicsGetImageFromCurrentImageContext();
|
||||
UIGraphicsEndImageContext();
|
||||
});
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
@end
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
//
|
||||
// TFReadNovelTextController.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 TFReadNovelTextController : UIViewController
|
||||
|
||||
@property (nonatomic ,copy) NSAttributedString *contentString;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
+269
@@ -0,0 +1,269 @@
|
||||
//
|
||||
// TFReadNovelTextController.m
|
||||
// TFReader
|
||||
//
|
||||
// Created by 谢腾飞 on 2020/12/15.
|
||||
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TFReadNovelTextController.h"
|
||||
#import "TYAttributedLabel.h"
|
||||
#import "TFReaderBookManager.h"
|
||||
#import "TFReaderSettingHelper.h"
|
||||
#import "WXYZ_BatteryView.h"
|
||||
#import "TFEmptyViewHeader.h"
|
||||
#import "WXYZ_BookReaderMenuPayView.h"
|
||||
#import "NSAttributedString+TReaderPage.h"
|
||||
#import "TFNetworkManager.h"
|
||||
|
||||
#import "TFReaderBookManager.h"
|
||||
|
||||
@interface TFReadNovelTextController ()
|
||||
{
|
||||
UILabel *emptyTitleLabel;
|
||||
UIButton *emptyButton;
|
||||
}
|
||||
|
||||
@property (nonatomic ,strong) UILabel *chapterTitleLabel;
|
||||
|
||||
@property (nonatomic ,strong) UILabel *bookNameLabel;
|
||||
|
||||
@property (nonatomic ,strong) UILabel *pageNumberLabel;
|
||||
|
||||
@property (nonatomic ,strong) TYAttributedLabel *chapterContentLabel;
|
||||
|
||||
@property (nonatomic ,strong) WXYZ_BatteryView *battery;
|
||||
|
||||
@property (nonatomic ,strong) WXYZ_BookReaderMenuPayView *payView;
|
||||
|
||||
@end
|
||||
|
||||
@implementation TFReadNovelTextController
|
||||
|
||||
- (void)viewDidLoad
|
||||
{
|
||||
[super viewDidLoad];
|
||||
|
||||
self.view.backgroundColor = [[TFReaderSettingHelper sharedManager] getReaderBackgroundColor];
|
||||
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadFrame) name:Notification_Check_Setting_Update object:nil];
|
||||
|
||||
WS(weakSelf)
|
||||
[TFReaderSettingHelper sharedManager].readerBackgroundViewChanged = ^() {
|
||||
[weakSelf reloadSubviews];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:NSNotification_Retry_Chapter object:nil];
|
||||
};
|
||||
}
|
||||
|
||||
- (void)setContentString:(NSAttributedString *)contentString
|
||||
{
|
||||
if ([contentString.string isEqualToString:k_Chapter_RequstFail] || !contentString) {
|
||||
[self createEmptyView];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:NSNotification_EmptyView_Changed object:@1];
|
||||
return;
|
||||
}
|
||||
[self reloadSubviews];
|
||||
|
||||
if ([[TFReaderBookManager sharedManager] isPreviewChapter] && contentString.length > 1) {
|
||||
CGSize size = CGSizeMake(CGRectGetWidth(self.chapterContentLabel.bounds), CGRectGetHeight(self.chapterContentLabel.bounds) / 2.0);
|
||||
NSArray<NSValue *> *t_arr = [contentString pageRangeArrayWithConstrainedToSize:size];
|
||||
if (t_arr.count > 0) {
|
||||
NSRange range = [t_arr.firstObject rangeValue];
|
||||
contentString = [contentString attributedSubstringFromRange:range];
|
||||
}
|
||||
|
||||
[self payView];
|
||||
} else {
|
||||
TFReaderBookManager *manager = [TFReaderBookManager sharedManager];
|
||||
NSString *chapter_id = [NSString stringWithFormat:@"%zd", manager.chapter_id];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Production_Pay_Success object:@[chapter_id]];
|
||||
_payView.hidden = YES;
|
||||
}
|
||||
|
||||
_contentString = contentString;
|
||||
self.chapterContentLabel.attributedText = contentString;
|
||||
|
||||
// 总章节页数
|
||||
NSUInteger totalChapterPagerCount = [[TFReaderBookManager sharedManager] totalChapterPagerCount];
|
||||
NSUInteger readedPagerCount = ([[TFReaderBookManager sharedManager] currentPagerIndex] + 1) + (([[TFReaderBookManager sharedManager] currentChapterPagerCount]) * ([[TFReaderBookManager sharedManager] currentChapterIndex]));
|
||||
|
||||
float progressValue = [[NSNumber numberWithUnsignedInteger:readedPagerCount] floatValue] / [[NSNumber numberWithUnsignedInteger:totalChapterPagerCount] floatValue] * 100;
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
self.pageNumberLabel.text = [NSString stringWithFormat:@"%.1lf%@", progressValue < 0.1?0.1f:progressValue, @"%"];
|
||||
});
|
||||
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:NSNotification_EmptyView_Changed object:@0];
|
||||
}
|
||||
|
||||
- (void)reloadSubviews
|
||||
{
|
||||
kCodeSync({
|
||||
self.view.backgroundColor = [[TFReaderSettingHelper sharedManager] getReaderBackgroundColor];
|
||||
|
||||
UIColor *textColor = [[TFReaderSettingHelper sharedManager] getReaderTextColor];
|
||||
UIColor *titleTextColor = [[TFReaderSettingHelper sharedManager] getReaderTitleTextColor];
|
||||
|
||||
self.chapterContentLabel.font = [UIFont systemFontOfSize:[[TFReaderSettingHelper sharedManager] getReaderFontSize]];
|
||||
self.chapterContentLabel.linesSpacing = [[TFReaderSettingHelper sharedManager] getReaderLinesSpacing];
|
||||
|
||||
self.bookNameLabel.text = [[TFReaderBookManager sharedManager] getBookName];
|
||||
self.bookNameLabel.textColor = titleTextColor;
|
||||
|
||||
self.chapterTitleLabel.text = [[TFReaderBookManager sharedManager] getChapterTitle];
|
||||
self.chapterTitleLabel.textColor = titleTextColor;
|
||||
|
||||
self.chapterContentLabel.textColor = textColor;
|
||||
|
||||
self.battery.batteryTintColor = titleTextColor;
|
||||
|
||||
self.pageNumberLabel.textColor = [[TFReaderSettingHelper sharedManager] getReaderTitleTextColor];
|
||||
self.pageNumberLabel.hidden = NO;
|
||||
|
||||
emptyButton.hidden = YES;
|
||||
emptyTitleLabel.hidden = YES;
|
||||
|
||||
if ([TFReaderBookManager sharedManager].currentChapterIndex == 0 && [TFReaderBookManager sharedManager].currentPagerIndex == 0) {
|
||||
self.chapterTitleLabel.hidden = YES;
|
||||
self.battery.hidden = YES;
|
||||
self.pageNumberLabel.hidden = YES;
|
||||
self.bookNameLabel.hidden = YES;
|
||||
} else {
|
||||
self.chapterTitleLabel.hidden = NO;
|
||||
self.battery.hidden = NO;
|
||||
self.pageNumberLabel.hidden = NO;
|
||||
self.bookNameLabel.hidden = NO;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
- (void)reloadFrame
|
||||
{
|
||||
[self reloadSubviews];
|
||||
_pageNumberLabel.frame = CGRectMake(SCREEN_WIDTH / 2, [[TFReaderSettingHelper sharedManager] getReaderViewBottom] + kHalfMargin, (SCREEN_WIDTH - 2 * kMargin) / 2, kMargin);
|
||||
_battery.frame = CGRectMake(kMargin, [[TFReaderSettingHelper sharedManager] getReaderViewBottom] + kHalfMargin, SCREEN_WIDTH / 2, kMargin);
|
||||
_bookNameLabel.frame = CGRectMake(SCREEN_WIDTH / 3, [[TFReaderSettingHelper sharedManager] getReaderViewBottom] + kHalfMargin, SCREEN_WIDTH / 3, kMargin);
|
||||
_chapterContentLabel.frame = [[TFReaderSettingHelper sharedManager] getReaderViewFrame];
|
||||
}
|
||||
|
||||
- (UILabel *)pageNumberLabel
|
||||
{
|
||||
if (!_pageNumberLabel) {
|
||||
_pageNumberLabel = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH / 2, [[TFReaderSettingHelper sharedManager] getReaderViewBottom] + kHalfMargin, (SCREEN_WIDTH - 2 * kMargin) / 2, kMargin)];
|
||||
_pageNumberLabel.text = @"0.1%";
|
||||
_pageNumberLabel.font = kFont12;
|
||||
_pageNumberLabel.hidden = YES;
|
||||
_pageNumberLabel.textAlignment = NSTextAlignmentRight;
|
||||
[self.view addSubview:_pageNumberLabel];
|
||||
}
|
||||
return _pageNumberLabel;
|
||||
}
|
||||
|
||||
- (WXYZ_BatteryView *)battery
|
||||
{
|
||||
if (!_battery) {
|
||||
_battery = [[WXYZ_BatteryView alloc] initWithFrame:CGRectMake(kMargin, [[TFReaderSettingHelper sharedManager] getReaderViewBottom] + kHalfMargin, SCREEN_WIDTH / 2, kMargin)];
|
||||
[self.view addSubview:_battery];
|
||||
}
|
||||
return _battery;
|
||||
}
|
||||
|
||||
- (UILabel *)bookNameLabel
|
||||
{
|
||||
if (!_bookNameLabel) {
|
||||
_bookNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH / 3, [[TFReaderSettingHelper sharedManager] getReaderViewBottom] + kHalfMargin, SCREEN_WIDTH / 3, kMargin)];
|
||||
_bookNameLabel.font = kFont12;
|
||||
_bookNameLabel.textAlignment = NSTextAlignmentCenter;
|
||||
[self.view addSubview:_bookNameLabel];
|
||||
}
|
||||
return _bookNameLabel;
|
||||
}
|
||||
|
||||
- (UILabel *)chapterTitleLabel
|
||||
{
|
||||
if (!_chapterTitleLabel) {
|
||||
_chapterTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(kMargin, kMargin + PUB_NAVBAR_OFFSET, (SCREEN_WIDTH - 2 * kMargin) / 2, kMargin)];
|
||||
_chapterTitleLabel.font = kFont12;
|
||||
_chapterTitleLabel.textAlignment = NSTextAlignmentLeft;
|
||||
[self.view addSubview:_chapterTitleLabel];
|
||||
}
|
||||
return _chapterTitleLabel;
|
||||
}
|
||||
|
||||
- (TYAttributedLabel *)chapterContentLabel
|
||||
{
|
||||
if (!_chapterContentLabel) {
|
||||
_chapterContentLabel = nil;
|
||||
kCodeSync({
|
||||
_chapterContentLabel = [[TYAttributedLabel alloc] init];
|
||||
_chapterContentLabel.frame = [[TFReaderSettingHelper sharedManager] getReaderViewFrame];
|
||||
_chapterContentLabel.font = [UIFont systemFontOfSize:[[TFReaderSettingHelper sharedManager] getReaderFontSize]];
|
||||
_chapterContentLabel.backgroundColor = [UIColor clearColor];
|
||||
_chapterContentLabel.linesSpacing = [[TFReaderSettingHelper sharedManager] getReaderLinesSpacing];
|
||||
_chapterContentLabel.lineBreakMode = NSLineBreakByWordWrapping;
|
||||
[self.view addSubview:_chapterContentLabel];
|
||||
});
|
||||
}
|
||||
return _chapterContentLabel;
|
||||
}
|
||||
|
||||
- (WXYZ_BookReaderMenuPayView *)payView
|
||||
{
|
||||
if (!_payView) {
|
||||
_payView = [[WXYZ_BookReaderMenuPayView alloc] init];
|
||||
[self.view addSubview:_payView];
|
||||
}
|
||||
_payView.hidden = NO;
|
||||
return _payView;
|
||||
}
|
||||
|
||||
- (void)createEmptyView
|
||||
{
|
||||
if (!emptyTitleLabel) {
|
||||
emptyTitleLabel = [[UILabel alloc] init];
|
||||
emptyTitleLabel.textColor = [TFReaderSettingHelper sharedManager].getReaderTextColor;
|
||||
emptyTitleLabel.font = kFont16;
|
||||
emptyTitleLabel.text = TFLocalizedString(@"内容加载失败");
|
||||
emptyTitleLabel.textAlignment = NSTextAlignmentCenter;
|
||||
[self.view addSubview:emptyTitleLabel];
|
||||
|
||||
[emptyTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.bottom.mas_equalTo(self.view.mas_centerY).with.offset(- kHalfMargin);
|
||||
make.left.mas_equalTo(0);
|
||||
make.width.mas_equalTo(SCREEN_WIDTH);
|
||||
make.height.mas_equalTo(kLabelHeight);
|
||||
}];
|
||||
}
|
||||
|
||||
if (!emptyButton) {
|
||||
emptyButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
emptyButton.backgroundColor = [UIColor clearColor];
|
||||
emptyButton.layer.cornerRadius = 15;
|
||||
emptyButton.layer.borderColor = [TFReaderSettingHelper sharedManager].getReaderTextColor.CGColor;
|
||||
emptyButton.layer.borderWidth = 1.0;
|
||||
[emptyButton setTitle:TFLocalizedString(@"重试") forState:UIControlStateNormal];
|
||||
[emptyButton setTitleColor:[TFReaderSettingHelper sharedManager].getReaderTextColor forState:UIControlStateNormal];
|
||||
[emptyButton.titleLabel setFont:kFont12];
|
||||
[emptyButton addTarget:self action:@selector(retryClick:) forControlEvents:UIControlEventTouchUpInside];
|
||||
[self.view addSubview:emptyButton];
|
||||
|
||||
[emptyButton mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.centerX.mas_equalTo(self.view.mas_centerX);
|
||||
make.top.mas_equalTo(emptyTitleLabel.mas_bottom);
|
||||
make.width.mas_equalTo(80);
|
||||
make.height.mas_equalTo(kLabelHeight);
|
||||
}];
|
||||
}
|
||||
|
||||
emptyButton.hidden = NO;
|
||||
emptyTitleLabel.hidden = NO;
|
||||
}
|
||||
|
||||
- (void)retryClick:(UIButton *)sender
|
||||
{
|
||||
if (![TFNetworkManager networkingStatus] || [TFNetworkManager currentNetworkStatus] == kCTCellularDataRestrictedStateUnknown) {
|
||||
return;
|
||||
}
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:NSNotification_Retry_Chapter object:@"1"];
|
||||
}
|
||||
|
||||
@end
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
//
|
||||
// TFReadNovelViewController.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
|
||||
@class TFProductionModel;
|
||||
@interface TFReadNovelViewController : TFBasicViewController
|
||||
|
||||
- (instancetype)initWithSpecificIndex:(NSInteger)specificIndex chapterSort:(NSInteger)chapterSort;
|
||||
|
||||
- (instancetype)initWithChapterIndex:(NSInteger)specifiedChapter;
|
||||
|
||||
@property (nonatomic ,assign) NSInteger book_id;
|
||||
|
||||
@property (nonatomic ,strong) TFProductionModel *bookModel;
|
||||
|
||||
/// 跳转到指定章节
|
||||
@property (nonatomic ,assign) NSInteger specifiedChapter;
|
||||
|
||||
/// 跳转到指定页码
|
||||
@property (nonatomic ,assign) NSInteger specifiedPage;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
+1228
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user