小说绘上架版本

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,48 @@
//
// WXYZ_BookAuthorNoteView.h
// WXReader
//
// Created by LL on 2020/6/2.
// Copyright © 2020 Andrew. All rights reserved.
//
#import <UIKit/UIKit.h>
@class WXYZ_BookAuthorNoteModel;
NS_ASSUME_NONNULL_BEGIN
@interface WXYZ_BookAuthorNoteView : UIView
- (instancetype)initWithFrame:(CGRect)frame notoModel:(WXYZ_BookAuthorNoteModel *)noteModel;
@property (nonatomic, assign) CGFloat noteHeight;
@property (nonatomic, assign) CGFloat spacing;
@end
@interface WXYZ_BookAuthorNoteModel : NSObject
/// 作者寄语
@property (nonatomic, copy) NSString *author_note;
/// 评论数
@property (nonatomic, copy) NSString *comment_num;
/// 月票数
@property (nonatomic, copy) NSString *ticket_num;
/// 打赏数
@property (nonatomic, copy) NSString *reward_num;
@property (nonatomic, assign) NSInteger author_id;
@property (nonatomic, copy) NSString *author_name;
@property (nonatomic, copy) NSString *author_avatar;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,306 @@
//
// WXYZ_BookAuthorNoteView.m
// WXReader
//
// Created by LL on 2020/6/2.
// Copyright © 2020 Andrew. All rights reserved.
//
#import "WXYZ_BookAuthorNoteView.h"
#import "TFReaderSettingHelper.h"
#import "TFReaderBookManager.h"
#import "WXYZ_GiftView.h"
#import "AppDelegate.h"
#import "TFCommentsViewController.h"
@interface WXYZ_BookAuthorNoteView ()
@property (nonatomic, strong) WXYZ_BookAuthorNoteModel *noteModel;
@property (nonatomic, weak) UIButton *firstBtn;
@property (nonatomic, strong) NSArray<UIButton *> *btnArr;
@property (nonatomic, weak) UIView *mainView;
@property (nonatomic, weak) UIButton *commentBtn;
@property (nonatomic, weak) UIButton *rewardBtn;
@property (nonatomic, weak) UIButton *ticketBtn;
@end
@implementation WXYZ_BookAuthorNoteView
- (instancetype)initWithFrame:(CGRect)frame notoModel:(WXYZ_BookAuthorNoteModel *)noteModel {
if (self = [super initWithFrame:frame]) {
self.noteModel = noteModel;
[self netRequest];
[self initialize];
[self createSubviews];
}
return self;
}
- (void)initialize {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeComment:) name:@"changeComment" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(rewardEvent:) name:@"changeReward" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(ticketEvent:) name:@"changeTicket" object:nil];
}
- (void)netRequest {
NSDictionary *params = @{
@"book_id" : @([TFReaderBookManager sharedManager].book_id),
@"chapter_id" : @([TFReaderBookManager sharedManager].chapter_id),
@"scroll_type" : @"1",
};
WS(weakSelf)
[TFNetworkTools POST:Book_New_Catalog parameters:params model:TFCatalogModel.class success:^(BOOL isSuccess, TFCatalogModel * _Nullable t_model, TFNetworkRequestModel * _Nonnull requestModel) {
weakSelf.noteModel.reward_num = [NSString stringWithFormat:@"%zd", t_model.list.firstObject.reward_num];
weakSelf.noteModel.ticket_num = [NSString stringWithFormat:@"%zd", t_model.list.firstObject.ticket_num];
weakSelf.noteModel.comment_num = [NSString stringWithFormat:@"%zd", t_model.list.firstObject.comment_num];
[weakSelf.rewardBtn setAttributedTitle:[self atrbuteStringWithDict:@{TFLocalizedString(@"打赏") : @"reward_num"}] forState:UIControlStateNormal];
[weakSelf.ticketBtn setAttributedTitle:[self atrbuteStringWithDict:@{TFLocalizedString(@"月票") : @"ticket_num"}] forState:UIControlStateNormal];
[weakSelf.commentBtn setAttributedTitle:[self atrbuteStringWithDict:@{TFLocalizedString(@"评论") : @"comment_num"}] forState:UIControlStateNormal];
} failure:nil];
}
- (void)createSubviews {
self.backgroundColor = [UIColor clearColor];
UIView *mainView = nil;
if (self.noteModel.author_note.length > 0) {
mainView = [[UIView alloc] init];
self.mainView = mainView;
mainView.backgroundColor = [[[TFReaderSettingHelper sharedManager] getReaderTextColor] colorWithAlphaComponent:0.2];
mainView.layer.cornerRadius = 5.0f;
mainView.layer.masksToBounds = YES;
[self addSubview:mainView];
[mainView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self);
make.right.equalTo(self);
make.top.equalTo(self);
}];
UIView *backView = [[UIView alloc] init];
backView.backgroundColor = kColorRGB(83, 59, 37);
[mainView addSubview:backView];
[backView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(mainView);
make.top.equalTo(mainView).offset(11);
make.size.mas_equalTo(CGSizeMake(3.0, 19.0));
}];
UILabel *titleLabel = [[UILabel alloc] init];
titleLabel.textColor = [[TFReaderSettingHelper sharedManager] getReaderTextColor];
titleLabel.font = kFont14;
titleLabel.text = TFLocalizedString(@"作家的话");
[mainView addSubview:titleLabel];
[titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(backView);
make.left.equalTo(backView.mas_right).offset(kHalfMargin);
make.right.equalTo(mainView);
}];
UIImageView *coverImageView = [[UIImageView alloc] init];
[coverImageView setImageWithURL:[NSURL URLWithString:self.noteModel.author_avatar] placeholder:HoldImage];
coverImageView.contentMode = UIViewContentModeScaleAspectFill;
coverImageView.clipsToBounds = YES;
coverImageView.layer.cornerRadius = 12.0;
coverImageView.layer.masksToBounds = YES;
[mainView addSubview:coverImageView];
[coverImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(titleLabel);
make.top.equalTo(titleLabel.mas_bottom).offset(14.0);
make.size.mas_equalTo(CGSizeMake(24.0, 24.0));
}];
UILabel *authorLabel = [[UILabel alloc] init];
authorLabel.textColor = [[TFReaderSettingHelper sharedManager] getReaderTextColor];
authorLabel.font = kFont14;
authorLabel.text = self.noteModel.author_name;
[mainView addSubview:authorLabel];
[authorLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(coverImageView);
make.left.equalTo(coverImageView.mas_right).offset(kHalfMargin);
make.right.equalTo(mainView);
}];
UILabel *descLabel = [[UILabel alloc] init];
descLabel.textColor = [[TFReaderSettingHelper sharedManager] getReaderTextColor];
descLabel.font = kFont10;
descLabel.numberOfLines = 0;
descLabel.text = self.noteModel.author_note;
[mainView addSubview:descLabel];
[descLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(coverImageView.mas_bottom).offset(11.0);
make.left.equalTo(coverImageView);
make.right.equalTo(mainView).offset(-kHalfMargin);
make.bottom.equalTo(mainView).offset(-kMoreHalfMargin);
}];
}
NSMutableArray<NSDictionary *> *textArr = [NSMutableArray array];
AppDelegate *delegate = (AppDelegate *)kRCodeSync([UIApplication sharedApplication].delegate);
if (self.noteModel.reward_num.length > 0 && delegate.checkSettingModel.system_setting.novel_reward_switch == 1) {
[textArr addObject:@{TFLocalizedString(@"打赏") : @"reward_num"}];
}
if (self.noteModel.ticket_num.length > 0 && delegate.checkSettingModel.system_setting.monthly_ticket_switch == 1) {
[textArr addObject:@{TFLocalizedString(@"月票") : @"ticket_num"}];
}
if (self.noteModel.comment_num.length > 0) {
[textArr addObject:@{TFLocalizedString(@"评论") : @"comment_num"}];
}
if (textArr.count == 0) return;
WS(weakSelf)
NSMutableArray<UIButton *> *btnArr = [NSMutableArray array];
[textArr enumerateObjectsUsingBlock:^(NSDictionary * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setAttributedTitle:[self atrbuteStringWithDict:obj] forState:UIControlStateNormal];
button.titleLabel.numberOfLines = 0;
if ([obj.allKeys.firstObject isEqualToString:TFLocalizedString(@"评论")]) {
weakSelf.commentBtn = button;
}
if ([obj.allKeys.firstObject isEqualToString:TFLocalizedString(@"打赏")]) {
weakSelf.rewardBtn = button;
}
if ([obj.allKeys.firstObject isEqualToString:TFLocalizedString(@"月票")]) {
weakSelf.ticketBtn = button;
}
button.titleLabel.textAlignment = NSTextAlignmentCenter;
[button addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithActionBlock:^(id _Nonnull sender) {
if ([obj.allValues.firstObject isEqualToString:@"reward_num"]) {
WXYZ_GiftView *mainView = [[WXYZ_GiftView alloc] initWithFrame:CGRectZero bookModel:[TFReaderBookManager sharedManager].bookModel];
mainView.giftNumBlock = ^(NSInteger giftNumber) {
weakSelf.noteModel.reward_num = [TFUtilsHelper formatStringWithInteger:giftNumber];
[button setAttributedTitle:[weakSelf atrbuteStringWithDict:obj] forState:UIControlStateNormal];
};
[mainView show];
} else if ([obj.allValues.firstObject isEqualToString:@"ticket_num"]) {
WXYZ_GiftView *mainView = [[WXYZ_GiftView alloc] initWithFrame:CGRectZero bookModel:[TFReaderBookManager sharedManager].bookModel];
mainView.ticketNumBlock = ^(NSInteger ticketNumber) {
weakSelf.noteModel.ticket_num = [TFUtilsHelper formatStringWithInteger:ticketNumber];
[button setAttributedTitle:[weakSelf atrbuteStringWithDict:obj] forState:UIControlStateNormal];
};
mainView.isTicket = YES;
[mainView show];
} else if ([obj.allValues.firstObject isEqualToString:@"comment_num"]) {
[[NSNotificationCenter defaultCenter] postNotificationName:NSNotification_Reader_Push object:@"TFCommentsViewController"];
}
}]];
[self addSubview:button];
[btnArr addObject:button];
}];
self.btnArr = btnArr;
if (btnArr.count == 1 || btnArr.count == 0) {
if (btnArr.count == 1) {
[btnArr.firstObject mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(self);
make.centerX.equalTo(self);
}];
}
} else {
[btnArr mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing:0 leadSpacing:0 tailSpacing:0];
[btnArr mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(self);
}];
[btnArr enumerateObjectsUsingBlock:^(UIButton * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if (btnArr.count == idx + 1) {
*stop = YES;
}
UIView *splitLine = [[UIView alloc] init];
splitLine.backgroundColor = kColorRGBA(83, 59, 37, 0.8);
splitLine.hidden = btnArr.count == idx + 1;
[obj addSubview:splitLine];
[splitLine mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(22.0f);
make.width.mas_equalTo(0.5f);
make.right.equalTo(obj);
make.centerY.equalTo(obj);
}];
}];
}
[self setNeedsLayout];
[self layoutIfNeeded];
self.firstBtn = btnArr.firstObject;
}
- (void)changeComment:(NSNotification *)noti {
self.noteModel.comment_num = noti.object;
[self.commentBtn setAttributedTitle:[self atrbuteStringWithDict:@{TFLocalizedString(@"评论") : @"comment_num"}] forState:UIControlStateNormal];
}
- (void)rewardEvent:(NSNotification *)noti {
self.noteModel.reward_num = noti.object;
[self.rewardBtn setAttributedTitle:[self atrbuteStringWithDict:@{TFLocalizedString(@"打赏") : @"reward_num"}] forState:UIControlStateNormal];
}
- (void)ticketEvent:(NSNotification *)noti {
self.noteModel.ticket_num = noti.object;
[self.ticketBtn setAttributedTitle:[self atrbuteStringWithDict:@{TFLocalizedString(@"月票") : @"ticket_num"}] forState:UIControlStateNormal];
}
- (NSAttributedString *)atrbuteStringWithDict:(NSDictionary *)dict {
NSString *text = dict.allKeys.firstObject;
NSString *num = [self.noteModel performSelectorWithArgs:NSSelectorFromString(dict.allValues.firstObject)];
NSMutableAttributedString *atr = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@\n%@", text, num] attributes:@{NSFontAttributeName : kFont10, NSForegroundColorAttributeName : [[TFReaderSettingHelper sharedManager] getReaderTextColor]}];
[atr addAttribute:NSFontAttributeName value:kFont14 range:NSMakeRange(0, text.length)];
return atr;
}
- (void)setSpacing:(CGFloat)spacing {
_spacing = spacing;
if (spacing == -1) {
CGFloat t_spacing = CGRectGetHeight(self.bounds);
t_spacing = t_spacing - self.noteHeight + kHalfMargin;
[self.btnArr mas_updateConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.mainView.mas_bottom).offset(t_spacing);
}];
}
}
- (CGFloat)noteHeight {
CGFloat __block height = 0;
if ([NSThread isMainThread]) {
if (self.mainView) {
height = CGRectGetHeight(self.mainView.bounds) + CGRectGetHeight(self.firstBtn.bounds) + kHalfMargin;
} else {
height = CGRectGetHeight(self.firstBtn.bounds);
}
} else {
dispatch_semaphore_t signal = dispatch_semaphore_create(0);
dispatch_async(dispatch_get_main_queue(), ^{
if (self.mainView) {
height = CGRectGetHeight(self.mainView.bounds) + CGRectGetHeight(self.firstBtn.bounds) + kHalfMargin;
} else {
height = CGRectGetHeight(self.firstBtn.bounds);
}
dispatch_semaphore_signal(signal);
});
dispatch_semaphore_wait(signal, DISPATCH_TIME_FOREVER);
}
return height;
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
@end
@implementation WXYZ_BookAuthorNoteModel
@end
@@ -0,0 +1,24 @@
//
// WXYZ_BookBackSideHeaderView.h
// WXReader
//
// Created by Andrew on 2020/5/27.
// Copyright © 2020 Andrew. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "WXYZ_BookBackSideModel.h"
NS_ASSUME_NONNULL_BEGIN
@interface WXYZ_BookBackSideHeaderView : UIView
@property (nonatomic, copy) void (^commentClickBlock)(void);
@property (nonatomic, strong) WXYZ_BookBackSideModel *headerModel;
@property (nonatomic, strong) TFProductionModel *bookModel;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,220 @@
//
// WXYZ_BookBackSideHeaderView.m
// WXReader
//
// Created by Andrew on 2020/5/27.
// Copyright © 2020 Andrew. All rights reserved.
//
#import "WXYZ_BookBackSideHeaderView.h"
#import "TFShareManager.h"
#import "WXYZ_GiftView.h"
#import "AppDelegate.h"
@implementation WXYZ_BookBackSideHeaderView
{
UILabel *headerTitleLabel;
UILabel *headerDescLabel;
TFButton *commentButton;
}
- (instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
[self createSubviews];
}
return self;
}
- (void)createSubviews
{
headerTitleLabel = [[UILabel alloc] init];
headerTitleLabel.font = kBoldFont22;
headerTitleLabel.numberOfLines = 0;
headerTitleLabel.textAlignment = NSTextAlignmentLeft;
headerTitleLabel.textColor = kBlackColor;
[self addSubview:headerTitleLabel];
[headerTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.mas_left).with.offset(kMargin);
make.width.mas_equalTo(SCREEN_WIDTH - 2 * kMargin);
make.top.mas_equalTo(self.mas_top).with.offset(kMargin);
make.height.mas_equalTo(CGFLOAT_MIN);
}];
headerDescLabel = [[UILabel alloc] init];
headerDescLabel.font = kMainFont;
headerDescLabel.numberOfLines = 0;
headerDescLabel.textAlignment = NSTextAlignmentLeft;
headerDescLabel.textColor = kGrayTextLightColor;
[self addSubview:headerDescLabel];
[headerDescLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(headerTitleLabel.mas_left);
make.right.mas_equalTo(headerTitleLabel.mas_right);
make.top.mas_equalTo(headerTitleLabel.mas_bottom);
make.height.mas_equalTo(CGFLOAT_MIN);
}];
CGFloat buttonWidth = (SCREEN_WIDTH - kMargin) / 3;
AppDelegate *app = (AppDelegate *)kRCodeSync([UIApplication sharedApplication].delegate);
if (app.checkSettingModel.system_setting.novel_reward_switch == 0 && app.checkSettingModel.system_setting.monthly_ticket_switch == 0) {
buttonWidth = (SCREEN_WIDTH - kMargin) / 2;
}
commentButton = [[TFButton alloc] initWithFrame:CGRectZero buttonTitle:TFLocalizedString(@"评论") buttonImageName:@"book_back_side_comment" buttonIndicator:TFButtonIndicatorTitleBottom];
commentButton.tag = 0;
commentButton.buttonTitleColor = kGrayTextLightColor;
commentButton.graphicDistance = 8;
commentButton.buttonImageScale = 0.4;
[commentButton addTarget:self action:@selector(toolBarButtonClick:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:commentButton];
[commentButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(kHalfMargin);
make.top.mas_equalTo(headerDescLabel.mas_bottom).with.offset(kMargin);
make.width.mas_equalTo(buttonWidth);
make.height.mas_equalTo(50);
}];
{
UIView *line = [[UIView alloc] init];
line.backgroundColor = kColorRGB(204, 204, 204);
[self addSubview:line];
[line mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(commentButton.mas_right);
make.centerY.mas_equalTo(commentButton.mas_centerY);
make.width.mas_equalTo(0.8);
make.height.mas_equalTo(commentButton.mas_height).multipliedBy(0.7);
}];
}
TFButton *exceptionalButton = [[TFButton alloc] initWithFrame:CGRectZero buttonTitle:TFLocalizedString(@"打赏") buttonImageName:@"book_back_side_exceptional" buttonIndicator:TFButtonIndicatorTitleBottom];
exceptionalButton.tag = 1;
exceptionalButton.buttonTitleColor = kGrayTextLightColor;
exceptionalButton.graphicDistance = 8;
exceptionalButton.buttonImageScale = 0.4;
[exceptionalButton addTarget:self action:@selector(toolBarButtonClick:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:exceptionalButton];
[exceptionalButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(commentButton.mas_right);
make.top.mas_equalTo(commentButton.mas_top);
make.width.mas_equalTo(CGFLOAT_MIN);
make.height.mas_equalTo(commentButton.mas_height);
}];
if (app.checkSettingModel.system_setting.novel_reward_switch == 1 || app.checkSettingModel.system_setting.monthly_ticket_switch == 1) {
[exceptionalButton mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(commentButton.mas_right);
make.top.mas_equalTo(commentButton.mas_top);
make.width.mas_equalTo(buttonWidth);
make.height.mas_equalTo(commentButton.mas_height);
}];
if (app.checkSettingModel.system_setting.novel_reward_switch == 0 && app.checkSettingModel.system_setting.monthly_ticket_switch == 1) {
exceptionalButton.buttonTitle = TFLocalizedString(@"月票");
}
{
UIView *line = [[UIView alloc] init];
line.backgroundColor = kColorRGB(204, 204, 204);
[self addSubview:line];
[line mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(exceptionalButton.mas_right);
make.centerY.mas_equalTo(exceptionalButton.mas_centerY);
make.width.mas_equalTo(0.8);
make.height.mas_equalTo(exceptionalButton.mas_height).multipliedBy(0.7);
}];
}
}
TFButton *shareButton = [[TFButton alloc] initWithFrame:CGRectZero buttonTitle:TFLocalizedString(@"分享") buttonImageName:@"public_share" buttonIndicator:TFButtonIndicatorTitleBottom];
shareButton.tag = 2;
shareButton.buttonTitleColor = kGrayTextLightColor;
shareButton.graphicDistance = 8;
shareButton.buttonImageScale = 0.35;
[shareButton addTarget:self action:@selector(toolBarButtonClick:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:shareButton];
[shareButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(exceptionalButton.mas_right);
make.top.mas_equalTo(commentButton.mas_top);
make.width.mas_equalTo(buttonWidth);
make.height.mas_equalTo(commentButton.mas_height);
}];
}
- (void)layoutSubviews
{
[super layoutSubviews];
self.frame = CGRectMake(0, 0, SCREEN_WIDTH, (headerDescLabel.bottom + kHalfMargin + 50 + kMargin));
}
- (void)setHeaderModel:(WXYZ_BookBackSideModel *)headerModel
{
_headerModel = headerModel;
headerTitleLabel.text = headerModel.title?:@"";
[headerTitleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo([TFViewHelper getDynamicHeightWithLabel:headerTitleLabel]);
}];
headerDescLabel.text = headerModel.desc?:@"";
[headerDescLabel mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo([TFViewHelper getDynamicHeightWithLabel:headerDescLabel]);
}];
if (headerModel.comment_num > 0) {
commentButton.cornerTitle = [TFUtilsHelper formatStringWithInteger:headerModel.comment_num];
if (headerModel.comment_num > 99) {
commentButton.cornerTitle = @"99+";
}
} else {
commentButton.cornerTitle = @"";
}
[self layoutIfNeeded];
}
- (void)setBookModel:(TFProductionModel *)bookModel
{
_bookModel = bookModel;
}
- (void)toolBarButtonClick:(TFButton *)sender
{
switch (sender.tag) {
case 0:
{
if (self.commentClickBlock) {
self.commentClickBlock();
}
}
break;
case 1:
{
WXYZ_GiftView *mainView = [[WXYZ_GiftView alloc] initWithFrame:CGRectZero bookModel:self.bookModel];
[mainView show];
}
break;
case 2:
{
#if TF_FB_Share_Mode
[TFShareManager shareWithProduction_id:[NSString stringWithFormat:@"%zd", self.bookModel.production_id] chapter_id:nil type:TFShareTypeBook];
#endif
}
break;
default:
break;
}
}
@end
@@ -0,0 +1,27 @@
//
// WXYZ_BookBackSideModel.h
// WXReader
//
// Created by Andrew on 2020/5/27.
// Copyright © 2020 Andrew. All rights reserved.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@class TFBookStoreLabelModel;
@interface WXYZ_BookBackSideModel : NSObject
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *desc;
@property (nonatomic, assign) NSInteger comment_num;
@property (nonatomic, strong) TFBookStoreLabelModel *guess_like;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,18 @@
//
// WXYZ_BookBackSideModel.m
// WXReader
//
// Created by Andrew on 2020/5/27.
// Copyright © 2020 Andrew. All rights reserved.
//
#import "WXYZ_BookBackSideModel.h"
#import "TFBookStoreLabelModel.h"
@implementation WXYZ_BookBackSideModel
+ (NSDictionary<NSString *,id> *)modelContainerPropertyGenericClass{
return @{@"guess_like" : [TFBookStoreLabelModel class]};
}
@end
@@ -0,0 +1,19 @@
//
// WXYZ_BookBackSideViewController.h
// WXReader
//
// Created by LL on 2020/5/27.
// Copyright © 2020 Andrew. All rights reserved.
//
NS_ASSUME_NONNULL_BEGIN
/// 书籍末尾推荐书籍
@interface WXYZ_BookBackSideViewController : TFBasicViewController
@property (nonatomic, strong) TFProductionModel *bookModel;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,209 @@
//
// WXYZ_BookBackSideViewController.m
// WXReader
//
// Created by LL on 2020/5/27.
// Copyright © 2020 Andrew. All rights reserved.
//
#import "WXYZ_BookBackSideViewController.h"
#import "TFCommentsViewController.h"
#import "WXYZ_BookBackSideHeaderView.h"
#import "TFBookStoreNovelStyleOneCell.h"
#import "TFBookStoreNovelStyleTwoCell.h"
#import "TFBookStoreNovelStyleThreeCell.h"
#import "TFBookStoreNovelStyleFourCell.h"
#import "TFPublicAdvertisementViewCell.h"
#import "WXYZ_BookBackSideModel.h"
#import "TFBookStoreLabelModel.h"
@interface WXYZ_BookBackSideViewController () <UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) WXYZ_BookBackSideModel *backSideModel;
@property (nonatomic, strong) WXYZ_BookBackSideHeaderView *headerView;
@property (nonatomic, assign) BOOL needRefresh;
@end
@implementation WXYZ_BookBackSideViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self initialize];
[self createSubviews];
[self netRequest];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Hidden_Tabbar object:@"1"];
[self setStatusBarDefaultStyle];
}
- (void)initialize
{
self.needRefresh = YES;
[self setNavigationBarTitle:self.bookModel.name ?: @""];
self.view.backgroundColor = [UIColor whiteColor];
UIButton *_rightBtn;
[self setNavigationBarRightButton:({
UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
_rightBtn = rightBtn;
[rightBtn setImage:[UIImage imageNamed:@"public_home"] forState:UIControlStateNormal];
[rightBtn addTarget:self action:@selector(goHome) forControlEvents:UIControlEventTouchUpInside];
rightBtn;
})];
[_rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.view).offset(-kMargin);
make.centerY.equalTo(self.navigationBar.navTitleLabel);
}];
}
- (void)createSubviews
{
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(PUB_NAVBAR_HEIGHT);
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];
}];
self.headerView = [[WXYZ_BookBackSideHeaderView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 200)];
self.headerView.commentClickBlock = ^{
TFCommentsViewController *vc = [[TFCommentsViewController alloc] init];
vc.production_id = weakSelf.bookModel.production_id;
vc.commentsSuccessBlock = ^(TFCommentsListModel *commentModel) {
weakSelf.backSideModel.comment_num ++;
weakSelf.headerView.headerModel = weakSelf.backSideModel;
};
[weakSelf.navigationController pushViewController:vc animated:YES];
};
[self.mainTableViewGroup setTableHeaderView:self.headerView];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
TFBookStoreLabelModel *labelModel = self.backSideModel.guess_like;
if (labelModel.ad_type == 0) {
switch (labelModel.style) {
case 1:
return [self createCellWithTabelView:tableView cellClass:TFBookStoreNovelStyleOneCell.class indexPath:indexPath labelModel:labelModel];
break;
case 2:
return [self createCellWithTabelView:tableView cellClass:TFBookStoreNovelStyleTwoCell.class indexPath:indexPath labelModel:labelModel];
break;
case 3:
return [self createCellWithTabelView:tableView cellClass:TFBookStoreNovelStyleThreeCell.class indexPath:indexPath labelModel:labelModel];
break;
case 4:
return [self createCellWithTabelView:tableView cellClass:TFBookStoreNovelStyleFourCell.class indexPath:indexPath labelModel:labelModel];
break;
default:
return [self createCellWithTabelView:tableView cellClass:TFBookStoreNovelStyleOneCell.class indexPath:indexPath labelModel:labelModel];
break;
}
} else {
return [self createAdStyleCellWithTableView:tableView indexPath:indexPath adModel:labelModel];
}
}
- (UITableViewCell *)createCellWithTabelView:(UITableView *)tableView cellClass:(Class)cellClass indexPath:(NSIndexPath *)indexPath labelModel:(TFBookStoreLabelModel *)labelModel
{
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];
};
cell.index = indexPath;
cell.cellSelectRefreshBlock = ^(TFBookStoreLabelModel *labelModel, NSIndexPath *indexPath) {
[weakSelf refreshRequestWithLabelModel:labelModel indexPath:indexPath];
};
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
- (UITableViewCell *)createAdStyleCellWithTableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath adModel:(TFBookStoreLabelModel *)labelModel
{
static NSString *cellName = @"TFPublicAdvertisementViewCell";
TFPublicAdvertisementViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName];
if (!cell) {
cell = [[TFPublicAdvertisementViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
}
[cell setAdModel:labelModel refresh:self.needRefresh];
cell.mainTableView = tableView;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
- (void)netRequest
{
WS(weakSelf)
[TFNetworkTools POST:Book_Endof_Recommend parameters:@{@"book_id":[TFUtilsHelper formatStringWithInteger:self.bookModel.production_id]} model:WXYZ_BookBackSideModel.class success:^(BOOL isSuccess, WXYZ_BookBackSideModel * _Nullable t_model, TFNetworkRequestModel * _Nonnull requestModel) {
if (isSuccess) {
weakSelf.backSideModel = t_model;
weakSelf.headerView.headerModel = t_model;
weakSelf.needRefresh = YES;
[weakSelf.mainTableViewGroup reloadData];
dispatch_async(dispatch_get_main_queue(), ^{
weakSelf.needRefresh = NO;
});
}
[weakSelf.mainTableViewGroup endRefreshing];
} failure:nil];
}
- (void)refreshRequestWithLabelModel:(TFBookStoreLabelModel *)labelModel indexPath:(NSIndexPath *)indexPath
{
WS(weakSelf)
[TFNetworkTools POST:Book_Guess_Like parameters:@{@"book_id":[TFUtilsHelper formatStringWithInteger:self.bookModel.production_id]} model:TFBookStoreLabelModel.class success:^(BOOL isSuccess, TFBookStoreLabelModel * _Nullable t_model, TFNetworkRequestModel * _Nonnull requestModel) {
if (isSuccess) {
weakSelf.backSideModel.guess_like.list = t_model.list;
TFBookStoreNovelBasicViewCell *cell = [weakSelf.mainTableViewGroup cellForRowAtIndexPath:indexPath];
cell.labelModel = t_model;
[cell stopRefreshing];
}
} failure:nil];
}
- (void)goHome
{
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Change_Tabbar_Index object:@"1"];
[self.navigationController popToRootViewControllerAnimated:YES];
}
@end
@@ -0,0 +1,24 @@
//
// WXYZ_BookFrontCoverView.h
// WXReader
//
// Created by LL on 2020/5/23.
// Copyright © 2020 Andrew. All rights reserved.
//
#import <UIKit/UIKit.h>
@class TFReaderSettingHelper;
NS_ASSUME_NONNULL_BEGIN
/// 书籍第一章第一页的封面
@interface WXYZ_BookFrontCoverView : UIView
- (instancetype)initWithFrame:(CGRect)frame
bookModel:(TFProductionModel *)bookModel
readerSetting:(TFReaderSettingHelper *)readerSetting;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,133 @@
//
// WXYZ_BookFrontCoverView.m
// WXReader
//
// Created by LL on 2020/5/23.
// Copyright © 2020 Andrew. All rights reserved.
//
#import "WXYZ_BookFrontCoverView.h"
#import "TFReaderSettingHelper.h"
#import "TFReaderBookManager.h"
@interface WXYZ_BookFrontCoverView ()
@property (nonatomic, strong) TFProductionModel *bookModel;
@property (nonatomic, strong) TFReaderSettingHelper *readerSetting;
@end
@implementation WXYZ_BookFrontCoverView
- (instancetype)initWithFrame:(CGRect)frame
bookModel:(TFProductionModel *)bookModel
readerSetting:(TFReaderSettingHelper *)readerSetting {
if (self = [super initWithFrame:frame]) {
self.bookModel = bookModel;
self.readerSetting = readerSetting;
if ([TFNetworkManager networkingStatus]) {
[self netRquest];
} else {
NSString *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject;
path = [path stringByAppendingPathComponent:[TFUtilsHelper stringToMD5:@"book_catalog"]];
NSString *catalogName = [NSString stringWithFormat:@"%zd_%@", bookModel.production_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];
if (catalog.author) {
self.bookModel.author = self.bookModel.author ? self.bookModel.author : catalog.author.author_name;
self.bookModel.author_name = self.bookModel.author_name ? self.bookModel.author_name : catalog.author.author_name;
self.bookModel.author_id = self.bookModel.author_id ? self.bookModel.author_id : catalog.author.author_id;
self.bookModel.author_note = self.bookModel.author_note ? self.bookModel.author_note : catalog.author.author_note;
self.bookModel.author_avatar = self.bookModel.author_avatar ? self.bookModel.author_avatar : catalog.author.author_avatar;
} else {
TFProductionModel *t_catalog = [TFProductionModel modelWithDictionary:dict];
self.bookModel.author = self.bookModel.author ? self.bookModel.author : t_catalog.name;
self.bookModel.author_name = self.bookModel.author_name ? self.bookModel.author_name : t_catalog.name;
}
}
[self createSubviews];
}
}
return self;
}
- (void)netRquest {
WS(weakSelf)
[TFNetworkTools POST:Book_New_Catalog parameters:@{@"book_id" : @([TFReaderBookManager sharedManager].book_id)} model:TFCatalogModel.class success:^(BOOL isSuccess, TFCatalogModel * _Nullable t_model, TFNetworkRequestModel * _Nonnull requestModel) {
weakSelf.bookModel.author_note = t_model.author.author_note;
weakSelf.bookModel.author = t_model.author.author_name;
weakSelf.bookModel.author_name = t_model.author.author_name;
[weakSelf createSubviews];
} failure:nil];
}
- (void)createSubviews {
UIImageView *coverImageView = [[UIImageView alloc] init];
coverImageView.backgroundColor = [UIColor clearColor];
coverImageView.image = [UIImage imageNamed:@"book_reader_cover"];
[self addSubview:coverImageView];
[coverImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self);
}];
UILabel *nameLabel = [[UILabel alloc] init];
nameLabel.text = self.bookModel.name ? : @"";
nameLabel.font = kBoldFont18;
nameLabel.textColor = [self.readerSetting getReaderTitleTextColor];
[coverImageView addSubview:nameLabel];
[nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(coverImageView);
make.bottom.equalTo(coverImageView.mas_centerY);
}];
TFProductionCoverView *bookCoverView = [[TFProductionCoverView alloc] initWithProductionType:TFProductionTypeNovel coverDirection:TFProductionCoverDirectionVertical];
bookCoverView.coverImageUrl = self.bookModel.cover;
[coverImageView addSubview:bookCoverView];
[bookCoverView mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(nameLabel.mas_top).offset(-kMargin -kQuarterMargin);
make.centerX.equalTo(nameLabel);
make.height.equalTo(coverImageView.mas_height).multipliedBy(1.0 / 3.0);
make.width.equalTo(bookCoverView.mas_height).multipliedBy(150.0 / 200.0);
}];
self.bookModel.author_note = [self.bookModel.author_note stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
if (self.bookModel.author_note.length == 0) {
UILabel *authorLabel = [[UILabel alloc] init];
authorLabel.text = [NSString stringWithFormat:@"%@/%@", self.bookModel.author ?: @"", TFLocalizedString(@"作品")];
authorLabel.font = kFont14;
authorLabel.textColor = [self.readerSetting getReaderTextColor];
[coverImageView addSubview:authorLabel];
[authorLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(nameLabel.mas_bottom).offset(12.0f);
make.centerX.equalTo(bookCoverView);
}];
} else {
UILabel *descLabel = [[UILabel alloc] init];
descLabel.numberOfLines = 5;
descLabel.font = kFont14;
descLabel.textColor = [self.readerSetting getReaderTextColor];
descLabel.text = self.bookModel.author_note;
[coverImageView addSubview:descLabel];
[descLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(nameLabel.mas_bottom).offset(SCREEN_HEIGHT * 65.0 / 896.0);
make.left.equalTo(coverImageView).offset(63.0);
make.right.equalTo(coverImageView).offset(-63.0);
}];
UILabel *authorLabel = [[UILabel alloc] init];
authorLabel.font = kFont14;
authorLabel.textColor = [self.readerSetting getReaderTextColor];
authorLabel.text = [NSString stringWithFormat:@"%@%@", @"—— ", self.bookModel.author_name ?: @""];
[coverImageView addSubview:authorLabel];
[authorLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(descLabel.mas_bottom).offset(kMoreHalfMargin);
make.right.equalTo(descLabel);
}];
}
}
@end