小说绘上架版本

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,18 @@
//
// WXYZ_BookAiPlayPageHeaderView.h
// WXReader
//
// Created by Andrew on 2020/3/11.
// Copyright © 2020 Andrew. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "TFBasicVoiceHeaderView.h"
NS_ASSUME_NONNULL_BEGIN
@interface WXYZ_BookAiPlayPageHeaderView : TFBasicVoiceHeaderView
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,316 @@
//
// WXYZ_BookAiPlayPageHeaderView.m
// WXReader
//
// Created by Andrew on 2020/3/11.
// Copyright © 2020 Andrew. All rights reserved.
//
#import "WXYZ_BookAiPlayPageHeaderView.h"
#import "TFAudioPlayViewController.h"
#import "TFReaderBookManager.h"
#import "TFReadRecordManager.h"
#import "WXYZ_AudioSettingHelper.h"
#import "WXYZ_PlayingInfoCenter.h"
#import "WXYZ_TouchAssistantView.h"
#import "WXYZ_Player.h"
#if __has_include(<iflyMSC/IFlyMSC.h>)
#import "iflyMSC/IFlyMSC.h"
#endif
@interface WXYZ_BookAiPlayPageHeaderView () <WXYZ_PlayingInfoCenterDelegate
#if __has_include(<iflyMSC/IFlyMSC.h>)
, IFlySpeechSynthesizerDelegate
#endif
>
// 分割字符,讯飞只能解析8000字符,把小说章节内容拆分为数组解析
@property (nonatomic, strong) NSMutableArray __block *segmentCharacterArray;
#if __has_include(<iflyMSC/IFlyMSC.h>)
@property (nonatomic, strong) IFlySpeechSynthesizer *iFlySpeechSynthesizer;
#endif
@end
@implementation WXYZ_BookAiPlayPageHeaderView
#if __has_include(<iflyMSC/IFlyMSC.h>)
- (void)createSubviews
{
[super createSubviews];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(relationViewTitleChange) name:Notification_Change_Audio_Chapter object:nil];
[WXYZ_PlayingInfoCenter sharedManager].delegate = self;
WS(weakSelf)
self.resetPlayerBlock = ^(BOOL immediateReset) {
if (immediateReset) {
[weakSelf initIFlySpeech];
} else if (weakSelf.segmentCharacterArray.count == 0) {
[weakSelf initIFlySpeech];
}
};
}
- (void)setProductionChapterModel:(TFProductionChapterModel *)productionChapterModel
{
[super setProductionChapterModel:productionChapterModel];
WS(weakSelf)
[[WXYZ_AudioSettingHelper sharedManager] getCurrentTimingBlock:^(NSUInteger currentTime) {
dispatch_async(dispatch_get_main_queue(), ^{
weakSelf.timingButton.buttonTitle = [NSString stringWithFormat:@"%02zd:%02zd", (NSInteger)(currentTime / 60), (NSInteger)(currentTime % 60)];
});
} finishBlock:^{
dispatch_async(dispatch_get_main_queue(), ^{
if ([[WXYZ_AudioSettingHelper sharedManager] getReadTiming] == 1) {
weakSelf.timingButton.buttonTitle = TFLocalizedString(@"听完本章节");
} else if ([[WXYZ_AudioSettingHelper sharedManager] getReadTiming] == 0) {
weakSelf.timingButton.buttonTitle = TFLocalizedString(@"定时");
} else {
weakSelf.timingButton.buttonTitle = TFLocalizedString(@"定时");
#if __has_include(<iflyMSC/IFlyMSC.h>)
if (weakSelf.playerState == TFBasicVoicePlayerStatePlaying) {
[[IFlySpeechSynthesizer sharedInstance] pauseSpeaking];
}
#endif
}
});
}];
if (productionChapterModel.chapter_id == 0) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:TFLocalizedString(@"章节正在更新中")];
});
self.playerState = TFBasicVoicePlayerStateStoped;
return;
}
if (self.temp_chapterModel.chapter_id == productionChapterModel.chapter_id && self.temp_chapterModel.is_preview == productionChapterModel.is_preview && ![TFUserInfoManager shareInstance].auto_sub) {
if ([WXYZ_Player sharedPlayer].state == TFBasicVoicePlayerStatePlaying && ![[WXYZ_AudioSettingHelper sharedManager] isPlayPageShowingWithProductionType:TFProductionTypeAudio]) {
[[IFlySpeechSynthesizer sharedInstance] resumeSpeaking];
[[WXYZ_Player sharedPlayer] pause];
}
return;
}
if ([[WXYZ_AudioSettingHelper sharedManager] isPlayPageShowingWithProductionType:TFProductionTypeAudio]) {
[[WXYZ_AudioSettingHelper sharedManager] playPageViewShow:NO productionType:TFProductionTypeAudio];
if ([TFAudioPlayViewController sharedManager].speaking) {
self.playerState = TFBasicVoicePlayerStateStoped;
}
return;
}
self.temp_chapterModel = [productionChapterModel modelCopy];
if (productionChapterModel.is_preview && ![TFUserInfoManager shareInstance].auto_sub) {
self.playerState = TFBasicVoicePlayerStateStoped;
[self.iFlySpeechSynthesizer stopSpeaking];
[self showPayView];
return;
}
[self initIFlySpeech];
}
- (void)initIFlySpeech
{
//设置在线工作方式
[self.iFlySpeechSynthesizer setParameter:[IFlySpeechConstant TYPE_CLOUD]
forKey:[IFlySpeechConstant ENGINE_TYPE]];
[self.iFlySpeechSynthesizer setParameter:@"wxyz.pcm"
forKey: [IFlySpeechConstant TTS_AUDIO_PATH]];
// 语速
WXYZ_AudioSettingHelper *audioTool = [WXYZ_AudioSettingHelper sharedManager];
[self.iFlySpeechSynthesizer setParameter:[TFUtilsHelper formatStringWithInteger:[[[audioTool getReadSpeedValuesWithProducitionType:self.productionType] objectAtIndex:[audioTool getReadSpeedWithProducitionType:self.productionType]] floatValue] * 50] forKey:[IFlySpeechConstant SPEED]];
//设置音量,取值范围 0~100
[self.iFlySpeechSynthesizer setParameter:@"1" forKey:[IFlySpeechConstant MPPLAYINGINFOCENTER]];
// 音量
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[self.iFlySpeechSynthesizer setParameter:[TFUtilsHelper formatStringWithInteger:audioSession.outputVolume * 100] forKey: [IFlySpeechConstant VOLUME]];
// 发音人
[self.iFlySpeechSynthesizer setParameter:[[audioTool getReadVoiceValuesWithProducitionType:self.productionType] objectAtIndex:[audioTool getReadVoiceWithProducitionType:self.productionType]] forKey:[IFlySpeechConstant VOICE_NAME]];
WS(weakSelf)
[[TFReaderBookManager sharedManager] getChapterTextWithBook_id:self.productionChapterModel.production_id chapter_index:[self.productionChapterModel.display_order integerValue] completionHandler:^(NSString *content) {
[weakSelf.segmentCharacterArray removeAllObjects];
content = [content stringByReplacingOccurrencesOfString:@"W$$X" withString:@""];
content = [content stringByReplacingOccurrencesOfString:k_Chapter_RequstFail withString:@""];
// 分割长度
NSInteger segmentLength = 3500;
// 分割数量
NSInteger segmentCount = content.length / segmentLength + (content.length % segmentLength > 0 ? 1 : 0);
// 整数量分割
if (segmentCount == 1) {
[weakSelf.segmentCharacterArray addObject:content];
} else {
for (int i = 0; i < segmentCount; i ++) {
if (segmentCount - 1 == i) {
[weakSelf.segmentCharacterArray addObject:[content substringWithRange:NSMakeRange(i * segmentLength, content.length % segmentLength)]];
} else {
[weakSelf.segmentCharacterArray addObject:[content substringWithRange:NSMakeRange(i * segmentLength, segmentLength)]];
}
}
}
if (weakSelf.segmentCharacterArray.count > 0) {
[weakSelf.iFlySpeechSynthesizer startSpeaking:[weakSelf.segmentCharacterArray firstObject]];
}
[[WXYZ_PlayingInfoCenter sharedManager] showPlayingInfoCenterWithProductionChapterModel:weakSelf.productionChapterModel];
}];
}
#pragma mark - WXYZ_PlayingInfoCenterDelegate
- (void)playRemoteCommand
{
if ([WXYZ_TouchAssistantView sharedManager].productionType == TFProductionTypeNovel) {
if (self.playerState == TFBasicVoicePlayerStatePause) {
[self.iFlySpeechSynthesizer resumeSpeaking];
}
}
}
- (void)pauseRemoteCommand
{
if ([WXYZ_TouchAssistantView sharedManager].productionType == TFProductionTypeNovel) {
if (self.playerState == TFBasicVoicePlayerStatePlaying) {
[self.iFlySpeechSynthesizer pauseSpeaking];
}
}
}
- (void)lastRemoteCommand
{
if ([WXYZ_TouchAssistantView sharedManager].productionType == TFProductionTypeNovel) {
[self skipToLastChapter];
}
}
- (void)nextRemoteCommand
{
if ([WXYZ_TouchAssistantView sharedManager].productionType == TFProductionTypeNovel) {
[self skipToNextChapter];
}
}
#pragma mark - IFlySpeechDelegate
- (void)onCompleted:(IFlySpeechError *)error
{
if (error) {
if ([TFNetworkManager networkingStatus] == NO) {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:TFLocalizedString(@"当前为离线状态,只可查看缓存内容哦")];
} else {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:TFLocalizedString(@"播放出错")];
}
self.playerState = TFBasicVoicePlayerStateStoped;
}
}
// 合成开始
- (void)onSpeakBegin
{
self.playerState = TFBasicVoicePlayerStatePlaying;
if ([[WXYZ_AudioSettingHelper sharedManager] isPlayPageShowingWithProductionType:TFProductionTypeAudio] && [[WXYZ_AudioSettingHelper sharedManager] isPlayPageShowingWithProductionType:TFProductionTypeNovel] && [WXYZ_Player sharedPlayer].state == TFBasicVoicePlayerStatePlaying) {
[self.iFlySpeechSynthesizer pauseSpeaking];
} else {
if ([WXYZ_Player sharedPlayer].state == TFBasicVoicePlayerStatePlaying) {
[[WXYZ_Player sharedPlayer] pause];
}
}
[[WXYZ_PlayingInfoCenter sharedManager] showPlayingInfoCenterWithProductionChapterModel:self.productionChapterModel];
}
// 合成播放进度
- (void)onSpeakProgress:(int)progress beginPos:(int)beginPos endPos:(int)endPos
{
if (progress == 100) { // 片段播放结束
[self.segmentCharacterArray removeFirstObject];
if (self.segmentCharacterArray.count == 0) {
if ([[WXYZ_AudioSettingHelper sharedManager] getReadTiming] == 1) {
[[WXYZ_AudioSettingHelper sharedManager] setReadTimingWithIndex:0];
self.timingButton.buttonTitle = TFLocalizedString(@"定时");
[self.iFlySpeechSynthesizer pauseSpeaking];
self.playerState = TFBasicVoicePlayerStatePause;
} else {
if (self.productionChapterModel.next_chapter > 0 && self.productionChapterModel.next_chapter) {
[self skipToNextChapter];
}
}
} else {
[self.iFlySpeechSynthesizer startSpeaking:[self.segmentCharacterArray firstObject]];
}
}
}
// 暂停播放回调
- (void)onSpeakPaused
{
self.playerState = TFBasicVoicePlayerStatePause;
[[WXYZ_PlayingInfoCenter sharedManager] hiddenPlayingInfoCenter];
}
// 恢复播放回调
- (void)onSpeakResumed
{
self.playerState = TFBasicVoicePlayerStatePlaying;
[[WXYZ_PlayingInfoCenter sharedManager] showPlayingInfoCenterWithProductionChapterModel:self.productionChapterModel];
}
// 取消播放
- (void)onSpeakCancel
{
self.playerState = TFBasicVoicePlayerStateStoped;
[[WXYZ_PlayingInfoCenter sharedManager] hiddenPlayingInfoCenter];
}
- (void)relationViewTitleChange
{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self setRelationViewTitle:[[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeAudio] getReadingRecordChapterTitleWithProduction_id:self.relationModel.production_id]?:self.relationModel.chapter_title?:@""];
});
}
#pragma mark - lazy
- (IFlySpeechSynthesizer *)iFlySpeechSynthesizer
{
if (!_iFlySpeechSynthesizer) {
_iFlySpeechSynthesizer = [IFlySpeechSynthesizer sharedInstance];
//设置协议委托对象
_iFlySpeechSynthesizer.delegate = self;
}
return _iFlySpeechSynthesizer;
}
- (NSMutableArray *)segmentCharacterArray
{
if (!_segmentCharacterArray) {
_segmentCharacterArray = [NSMutableArray array];
}
return _segmentCharacterArray;
}
#endif
@end
@@ -0,0 +1,28 @@
//
// WXYZ_BookAiPlayPageViewController.h
// WXReader
//
// Created by Andrew on 2020/3/8.
// Copyright © 2020 Andrew. All rights reserved.
//
NS_ASSUME_NONNULL_BEGIN
@interface WXYZ_BookAiPlayPageViewController : TFBasicViewController
@property (nonatomic, assign, readonly) BOOL speaking;
@property (nonatomic, assign, readonly) BOOL stoped; // 暂停不可播放状态
@property (nonatomic, strong) TFProductionModel *bookModel;
interface_singleton
- (instancetype)init NS_UNAVAILABLE;
- (void)loadDataWithBookModel:(TFProductionModel * __nullable)bookModel chapterModel:(TFProductionChapterModel * __nullable)chapterModel;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,850 @@
//
// WXYZ_BookAiPlayPageViewController.m
// WXReader
//
// Created by Andrew on 2020/3/8.
// Copyright © 2020 Andrew. All rights reserved.
//
#import "WXYZ_BookAiPlayPageViewController.h"
#import "TFCommentsViewController.h"
#import "TFReadNovelViewController.h"
#import "TFAudioPlayViewController.h"
#import "WXYZ_BookAiPlayPageHeaderView.h"
#import "TFBookStoreNovelStyleOneCell.h"
#import "TFCommentsViewCell.h"
#import "TFPublicAdvertisementViewCell.h"
#import "CXTextView.h"
#import "CXCustomTextView.h"
#import "WXYZ_TouchAssistantView.h"
#import "WXYZ_PlayPageModel.h"
#import "WXYZ_Player.h"
#import "WXYZ_AudioSettingHelper.h"
#import "TFShareManager.h"
#import "TFKeyboardManager.h"
#import "TFCollectionManager.h"
#import "TFReadRecordManager.h"
@interface WXYZ_BookAiPlayPageViewController () <UITableViewDelegate, UITableViewDataSource>
{
CXTextView *commentTextView;
TFKeyboardManager *keyboardManager;
}
@property (nonatomic, strong) TFProductionChapterModel *chapterModel;
@property (nonatomic, strong) WXYZ_PlayPageModel *audioPlayPageModel;
@property (nonatomic, strong) WXYZ_BookAiPlayPageHeaderView *headerView;
@property (nonatomic, strong) UIButton *addBookRack;
@property (nonatomic, strong) UIView *bottomMenu;
@property (nonatomic, strong) UIView *sectionHeaderView;
@property (nonatomic, strong) UILabel *sectionTitleLabel;
@property (nonatomic, strong) UIButton *sectionBottomCommentButton;
@property (nonatomic, strong) UILabel *commentConnerLabel;
@property (nonatomic, assign) BOOL needRefresh;
@end
@implementation WXYZ_BookAiPlayPageViewController
implementation_singleton(WXYZ_BookAiPlayPageViewController)
- (instancetype)init
{
if (self = [super init]) {
[self initialize];
[self createSubviews];
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self hiddenNavigationBar:YES];
}
- (void)loadDataWithBookModel:(TFProductionModel *)bookModel chapterModel:(TFProductionChapterModel *)chapterModel
{
[[TFCollectionManager shareManagerWithProductionType:TFProductionTypeAudio] moveCollectionToTopWithProductionModel:bookModel];
if (self.bookModel.production_id == bookModel.production_id && self.chapterModel.chapter_id == chapterModel.chapter_id) {
chapterModel.production_id = self.bookModel.production_id;
chapterModel.name = self.bookModel.name;
chapterModel.cover = self.bookModel.cover;
return;
}
if (bookModel) {
self.bookModel = bookModel;
}
if (!chapterModel) {
NSInteger recordChapter_id = [[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeAi] getReadingRecordChapter_idWithProduction_id:self.bookModel.production_id];
if (recordChapter_id == 0) {
if (self.bookModel.chapter_list.count > 0) {
chapterModel = [self.bookModel.chapter_list firstObject];
} else {
chapterModel = [[TFProductionChapterModel alloc] init];
}
} else {
for (TFProductionChapterModel *t_model in self.bookModel.chapter_list) {
if (t_model.chapter_id == recordChapter_id) {
chapterModel = t_model;
break;
}
}
}
}
chapterModel.production_id = self.bookModel.production_id;
chapterModel.name = self.bookModel.name;
chapterModel.cover = self.bookModel.cover;
self.chapterModel = chapterModel;
[[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeAi] addReadingRecordWithProduction_id:chapterModel.production_id chapter_id:chapterModel.chapter_id chapterTitle:chapterModel.chapter_title];
self.headerView.productionChapterModel = chapterModel;
self.headerView.chapter_list = self.bookModel.chapter_list;
[self.mainTableViewGroup setTableHeaderView:self.headerView];
if ([[TFCollectionManager shareManagerWithProductionType:TFProductionTypeNovel] isCollectedWithProductionModel:self.bookModel]) {
[self.addBookRack setTitle:TFLocalizedString(@"已加入书架") forState:UIControlStateNormal];
[self.addBookRack mas_updateConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(self.addBookRack.intrinsicContentSize.width);
}];
[self.addBookRack setTitleColor:kGrayTextColor forState:UIControlStateNormal];
self.addBookRack.enabled = NO;
} else {
[self.addBookRack setTitle:TFLocalizedString(@"加入书架") forState:UIControlStateNormal];
[self.addBookRack mas_updateConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(self.addBookRack.intrinsicContentSize.width);
}];
[self.addBookRack setTitleColor:kBlackColor forState:UIControlStateNormal];
self.addBookRack.enabled = YES;
}
[self netRequest];
}
- (void)initialize
{
self.needRefresh = YES;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeAiChapter:) name:Notification_Change_AiBook_Chapter object:nil];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self setStatusBarDefaultStyle];
[[WXYZ_AudioSettingHelper sharedManager] playPageViewShow:YES productionType:TFProductionTypeAi];
[[WXYZ_TouchAssistantView sharedManager] hiddenAssistiveTouchView];
[[WXYZ_TouchAssistantView sharedManager] setPlayerProductionType:TFProductionTypeNovel];
if ([[TFCollectionManager shareManagerWithProductionType:TFProductionTypeNovel] isCollectedWithProductionModel:self.bookModel]) {
[self.addBookRack setTitle:TFLocalizedString(@"已加入书架") forState:UIControlStateNormal];
[self.addBookRack mas_updateConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(self.addBookRack.intrinsicContentSize.width);
}];
[self.addBookRack setTitleColor:kGrayTextColor forState:UIControlStateNormal];
self.addBookRack.enabled = NO;
} else {
[self.addBookRack setTitle:TFLocalizedString(@"加入书架") forState:UIControlStateNormal];
[self.addBookRack mas_updateConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(self.addBookRack.intrinsicContentSize.width);
}];
[self.addBookRack setTitleColor:kBlackColor forState:UIControlStateNormal];
self.addBookRack.enabled = YES;
}
}
- (void)viewWillDisappear:(BOOL)animated
{
if (!([WXYZ_Player sharedPlayer].state == TFBasicVoicePlayerStatePlaying)) {
[[WXYZ_TouchAssistantView sharedManager] showAssistiveTouchViewWithImageCover:self.bookModel.cover productionType:TFProductionTypeNovel];
} else {
[[WXYZ_TouchAssistantView sharedManager] showAssistiveTouchView];
}
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[[WXYZ_TouchAssistantView sharedManager] hiddenAssistiveTouchView];
}
- (void)createSubviews
{
WS(weakSelf)
UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
backButton.frame = CGRectMake(10, PUB_NAVBAR_OFFSET + 20, 44, 44);
backButton.backgroundColor = [UIColor clearColor];
backButton.adjustsImageWhenHighlighted = NO;
[backButton.titleLabel setFont:kMainFont];
[backButton setTitleColor:kBlackColor forState:UIControlStateNormal];
[backButton setImage:[[UIImage imageNamed:@"public_down_arrow"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
[backButton setImageEdgeInsets:UIEdgeInsetsMake(12, 12, 12, 12)];
[backButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
[backButton setTintColor:kBlackColor];
[backButton addTarget:self action:@selector(popViewController) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:backButton];
self.addBookRack = [UIButton buttonWithType:UIButtonTypeCustom];
if ([[TFCollectionManager shareManagerWithProductionType:TFProductionTypeNovel] isCollectedWithProductionModel:self.bookModel]) {
[self.addBookRack setTitle:TFLocalizedString(@"已加入书架") forState:UIControlStateNormal];
[self.addBookRack setTitleColor:kGrayTextColor forState:UIControlStateNormal];
self.addBookRack.enabled = NO;
} else {
[self.addBookRack setTitle:TFLocalizedString(@"加入书架") forState:UIControlStateNormal];
[self.addBookRack setTitleColor:kBlackColor forState:UIControlStateNormal];
self.addBookRack.enabled = YES;
}
self.addBookRack.backgroundColor = kWhiteColor;
[self.addBookRack setTitleColor:kBlackColor forState:UIControlStateNormal];
[self.addBookRack.titleLabel setFont:kMainFont];
[self.addBookRack setContentHorizontalAlignment:UIControlContentHorizontalAlignmentRight];
[self.addBookRack addTarget:self action:@selector(addBookRackClick) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:self.addBookRack];
[self.addBookRack mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(self.view.mas_right).with.offset(- kMargin);
make.centerY.mas_equalTo(backButton.mas_centerY);
make.width.mas_equalTo(self.addBookRack.intrinsicContentSize.width);
make.height.mas_equalTo(44);
}];
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).with.offset(- PUB_TABBAR_HEIGHT- PUB_NAVBAR_HEIGHT);
}];
[self.mainTableViewGroup setTableHeaderView:self.headerView];
self.bottomMenu = [[UIView alloc] init];
self.bottomMenu.backgroundColor = [UIColor whiteColor];
self.bottomMenu.layer.shadowColor = kBlackColor.CGColor;
self.bottomMenu.layer.shadowOpacity = 0.1;
self.bottomMenu.layer.shadowRadius = 1;
self.bottomMenu.layer.shadowOffset = CGSizeMake(0, - 1);
[self.view addSubview:self.bottomMenu];
[self.bottomMenu mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.view.mas_left);
make.bottom.mas_equalTo(self.view.mas_bottom).with.offset(- PUB_TABBAR_OFFSET);
make.width.mas_equalTo(SCREEN_WIDTH);
make.height.mas_equalTo(PUB_TABBAR_HEIGHT - PUB_TABBAR_OFFSET);
}];
TFButton *shareButton = [[TFButton alloc] initWithFrame:CGRectZero buttonTitle:TFLocalizedString(@"分享") buttonImageName:@"public_share" buttonIndicator:TFButtonIndicatorTitleBottom];
shareButton.tag = 0;
shareButton.graphicDistance = 5;
shareButton.buttonImageScale = 0.4;
shareButton.buttonTintColor = kBlackColor;
shareButton.buttonTitleColor = kGrayTextLightColor;
[shareButton addTarget:self action:@selector(toolBarButtonClick:) forControlEvents:UIControlEventTouchUpInside];
[self.bottomMenu addSubview:shareButton];
[shareButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(self.bottomMenu.mas_right).with.offset(- kHalfMargin);
make.top.mas_equalTo(self.bottomMenu.mas_top).with.offset(5);
make.width.height.mas_equalTo(40);
}];
TFButton *commentButton = [[TFButton alloc] initWithFrame:CGRectZero buttonTitle:TFLocalizedString(@"听书评论") buttonImageName:@"audio_comment" buttonIndicator:TFButtonIndicatorTitleBottom];
commentButton.tag = 1;
commentButton.graphicDistance = 5;
commentButton.buttonImageScale = 0.45;
commentButton.buttonTitleColor = kGrayTextLightColor;
[commentButton addTarget:self action:@selector(toolBarButtonClick:) forControlEvents:UIControlEventTouchUpInside];
[self.bottomMenu addSubview:commentButton];
[commentButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(shareButton.mas_left).with.offset(- kHalfMargin);
make.centerY.mas_equalTo(shareButton.mas_centerY);
make.width.height.mas_equalTo(shareButton);
}];
self.commentConnerLabel = [[UILabel alloc] init];
self.commentConnerLabel.text = @"0";
self.commentConnerLabel.textAlignment = NSTextAlignmentCenter;
self.commentConnerLabel.textColor = kMainColor;
self.commentConnerLabel.backgroundColor = [UIColor whiteColor];
self.commentConnerLabel.font = [UIFont systemFontOfSize:6];
[commentButton addSubview:self.commentConnerLabel];
[self.commentConnerLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(commentButton.mas_centerX).with.offset(1);
make.right.mas_equalTo(commentButton.mas_right).with.offset(- 5);
make.top.mas_equalTo(commentButton.mas_top).with.offset(- 1);
make.height.mas_equalTo(6);
}];
UIView *commentBottomView = [[UIView alloc] init];
commentBottomView.backgroundColor = kGrayViewColor;
commentBottomView.layer.cornerRadius = 20;
[self.bottomMenu addSubview:commentBottomView];
[commentBottomView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.bottomMenu.mas_left).with.offset(kHalfMargin);
make.top.mas_equalTo(self.bottomMenu.mas_top).with.offset(5);
make.right.mas_equalTo(commentButton.mas_left).with.offset(- kHalfMargin);
make.height.mas_equalTo(40);
}];
UIImageView *leftView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"audio_pencil"]];
[commentBottomView addSubview:leftView];
[leftView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(kMoreHalfMargin);
make.top.mas_equalTo(commentBottomView.mas_top).with.offset(10);
make.height.width.mas_equalTo(16);
}];
commentTextView = [[CXTextView alloc] initWithFrame:CGRectMake(kMoreHalfMargin + 16 + kHalfMargin, 0, SCREEN_WIDTH - (kMoreHalfMargin + 16 + kHalfMargin + kHalfMargin + 3 * 40 + 5 * kHalfMargin), 40)];
commentTextView.placeholder = TFLocalizedString(@"我来说两句...");
commentTextView.maxLine = 5;
commentTextView.maxLength = 200;
commentTextView.v_margin = 10;
commentTextView.font = kMainFont;
commentTextView.backgroundColor = [UIColor clearColor];
commentTextView.layer.cornerRadius = 15;
commentTextView.textView.backgroundColor = [UIColor clearColor];
commentTextView.textHeightChangeBlock = ^(CGFloat height) {
[commentBottomView mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(height);
}];
[weakSelf.bottomMenu mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(10 + height);
}];
[weakSelf.mainTableViewGroup mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(weakSelf.view.mas_height).with.offset(- PUB_TABBAR_OFFSET - PUB_NAVBAR_HEIGHT - height - 10);
}];
};
commentTextView.returnHandlerBlock = ^{
[[[UIApplication sharedApplication] keyWindow] endEditing:YES];
[weakSelf sendCommentNetRequest];
};
[commentBottomView addSubview:commentTextView];
keyboardManager = [[TFKeyboardManager alloc] initObserverWithAdaptiveMovementView:commentBottomView];
keyboardManager.keyboardHeightChanged = ^(CGFloat keyboardHeight, CGFloat shouldMoveDistance, CGRect shouldMoveFrame) {
[weakSelf.bottomMenu mas_updateConstraints:^(MASConstraintMaker *make) {
make.bottom.mas_equalTo(weakSelf.view.mas_bottom).with.offset(keyboardHeight == 0 ? - PUB_TABBAR_OFFSET:- keyboardHeight);
}];
};
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
[TFKeyboardManager hideKeyboard];
}
#pragma mark - UITableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 3;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
switch (section) {
case 0:
if (self.audioPlayPageModel.advert.ad_type != 0) {
return 1;
}
break;
case 1:
if (self.audioPlayPageModel.list.count > 0) {
return 1;
}
break;
case 2:
return self.audioPlayPageModel.comment.list.count;
break;
default:
break;
}
return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
switch (indexPath.section) {
case 0:
return [self createAdCellWithTableView:tableView indexPath:indexPath];
break;
case 1:
return [self createSingleStyleCellWithTableView:tableView indexPath:indexPath listArray:self.audioPlayPageModel.list];
break;
case 2:
return [self createCommentCellWithTableView:tableView indexPath:indexPath labelModel:[self.audioPlayPageModel.comment.list objectOrNilAtIndex:indexPath.row]];
break;
default:
break;
}
return [[UITableViewCell alloc] init];
}
- (UITableViewCell *)createSingleStyleCellWithTableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath listArray:(NSArray *)listArray
{
WS(weakSelf)
static NSString *cellName = @"TFBookStoreNovelStyleOneCell";
TFBookStoreLabelModel *labelModel = [[TFBookStoreLabelModel alloc] init];
labelModel.list = listArray;
labelModel.label = TFLocalizedString(@"猜你喜欢");
TFBookStoreNovelStyleOneCell *cell = [tableView dequeueReusableCellWithIdentifier:cellName];
if (!cell) {
cell = [[TFBookStoreNovelStyleOneCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellName];
}
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.selectionStyle = UITableViewCellSelectionStyleNone;
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.audioPlayPageModel.comment.list.count - 1 == indexPath.row)];
cell.hiddenEndLine = NO;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
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.audioPlayPageModel.advert refresh:self.needRefresh];
cell.mainTableView = tableView;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
//section头部间距
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
#if TF_Comments_Mode
if (!self.bookModel) {
return CGFLOAT_MIN;
}
if (section == 2) {// 评论头部高度
return 54;
}
#endif
return kQuarterMargin;
}
//section头部视图
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
if (section == 2) {
UIView *sectionView = self.sectionHeaderView;
self.sectionTitleLabel.text = [NSString stringWithFormat:@"%@ (%@)", TFLocalizedString(@"本章评论"),[TFUtilsHelper formatStringWithInteger:self.audioPlayPageModel.comment_total_count]];
return sectionView;
}
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, kHalfMargin)];
view.backgroundColor = kGrayViewColor;
return view;
}
- (UIView *)sectionHeaderView
{
if (!_sectionHeaderView) {
_sectionHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 54)];
_sectionHeaderView.backgroundColor = [UIColor whiteColor];
UIView *grayLine = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 10)];
grayLine.backgroundColor = kGrayViewColor;
[_sectionHeaderView addSubview:grayLine];
UIImageView *mainTitleHoldView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"book_label_hold"]];
[_sectionHeaderView addSubview:mainTitleHoldView];
[mainTitleHoldView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(kHalfMargin);
make.centerY.mas_equalTo(_sectionHeaderView.mas_centerY).with.offset(5);
make.width.height.mas_equalTo(kHalfMargin + kQuarterMargin);
}];
[_sectionHeaderView addSubview:self.sectionTitleLabel];
}
return _sectionHeaderView;
}
- (UILabel *)sectionTitleLabel
{
if (!_sectionTitleLabel) {
_sectionTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(kMargin + kHalfMargin, 10, SCREEN_WIDTH - kMargin, 44)];
_sectionTitleLabel.textAlignment = NSTextAlignmentLeft;
_sectionTitleLabel.textColor = kBlackColor;
_sectionTitleLabel.backgroundColor = [UIColor whiteColor];
_sectionTitleLabel.font = kBoldFont16;
}
return _sectionTitleLabel;
}
//section底部间距
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
#if TF_Comments_Mode
if (!self.bookModel) {
return CGFLOAT_MIN;
}
if (section == 2) {
return 56;
}
#endif
return CGFLOAT_MIN;
}
//section底部视图
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 50)];
view.backgroundColor = kWhiteColor;
if (section == 2) {
if (self.audioPlayPageModel) {
if (self.audioPlayPageModel.comment.list.count == 0) {
[self.sectionBottomCommentButton setTitle:TFLocalizedString(@"暂无评论,点击抢沙发") forState:UIControlStateNormal];
} else {
[self.sectionBottomCommentButton setTitle:[NSString stringWithFormat:@"%@(%@%@)", TFLocalizedString(@"查看全部评论"), [TFUtilsHelper formatStringWithInteger:self.audioPlayPageModel.comment_total_count], TFLocalizedString(@"")] forState:UIControlStateNormal];
}
[view addSubview:self.sectionBottomCommentButton];
}
}
return view;
}
- (void)changeAiChapter:(NSNotification *)noti
{
NSInteger chapter_id = [[TFUtilsHelper formatStringWithObject:noti.object] integerValue];
// 支付成功的章节更新预览内容
NSArray *success_chapter_ids = [noti.userInfo objectForKey:@"success_chapter_ids"];
if (success_chapter_ids.count > 0) {
for (NSString *chapter_id in success_chapter_ids) {
for (TFProductionChapterModel *t_model in self.bookModel.chapter_list) {
if (t_model.chapter_id == [chapter_id integerValue]) {
t_model.is_preview = 0;
break;
}
}
}
}
for (TFProductionChapterModel *t_model in self.bookModel.chapter_list) {
if (t_model.chapter_id == chapter_id) {
t_model.name = self.chapterModel.name;
t_model.cover = self.chapterModel.cover;
t_model.production_id = self.chapterModel.production_id;
self.headerView.productionChapterModel = t_model;
[[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeAi] addReadingRecordWithProduction_id:self.bookModel.production_id chapter_id:chapter_id chapterTitle:t_model.chapter_title];
break;
}
}
if ([[TFCollectionManager shareManagerWithProductionType:TFProductionTypeNovel] isCollectedWithProductionModel:self.bookModel]) {
[self.addBookRack setTitle:TFLocalizedString(@"已加入书架") forState:UIControlStateNormal];
[self.addBookRack mas_updateConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(self.addBookRack.intrinsicContentSize.width);
}];
[self.addBookRack setTitleColor:kGrayTextColor forState:UIControlStateNormal];
self.addBookRack.enabled = NO;
} else {
[self.addBookRack setTitle:TFLocalizedString(@"加入书架") forState:UIControlStateNormal];
[self.addBookRack mas_updateConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(self.addBookRack.intrinsicContentSize.width);
}];
[self.addBookRack setTitleColor:kBlackColor forState:UIControlStateNormal];
self.addBookRack.enabled = YES;
}
[self requestChapterCommentWithChapter_id:chapter_id];
}
- (BOOL)speaking
{
if (self.headerView.playerState == TFBasicVoicePlayerStatePlaying) {
return YES;
}
return NO;
}
- (BOOL)stoped
{
if (self.headerView.playerState == TFBasicVoicePlayerStateStoped) {
return YES;
}
return NO;
}
- (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;
}
- (WXYZ_BookAiPlayPageHeaderView *)headerView
{
if (!_headerView) {
WS(weakSelf)
_headerView = [[WXYZ_BookAiPlayPageHeaderView alloc] initWithProductionType:TFProductionTypeAi];
_headerView.checkOriginalBlock = ^(TFProductionChapterModel * _Nonnull chapterModel) {
if (weakSelf.navigationController.view.tag == 2345) {
[weakSelf popViewController];
return;
}
TFReadNovelViewController *vc = [[TFReadNovelViewController alloc] init];
vc.book_id = weakSelf.bookModel.production_id;
vc.bookModel = weakSelf.bookModel;
[weakSelf.navigationController pushViewController:vc animated:YES];
};
_headerView.checkRelationProductionBlock = ^(WXYZ_RelationModel * _Nonnull relationModel) {
dispatch_async(dispatch_get_main_queue(), ^{
[[TFCollectionManager shareManagerWithProductionType:TFProductionTypeAudio] moveCollectionToTopWithProductionModel:weakSelf.bookModel];
TFAudioPlayViewController *vc = [TFAudioPlayViewController sharedManager];
[vc loadDataWithAudio_id:relationModel.production_id chapter_id:relationModel.chapter_id];
if (!vc.presentedViewController) {
TFNavigationController *nav = [[TFNavigationController alloc] initWithRootViewController:vc];
[[TFViewHelper getWindowRootController] presentViewController:nav animated:YES completion:nil];
} else {
[weakSelf popViewController];
if ([weakSelf.navigationController.viewControllers.lastObject isKindOfClass:WXYZ_BookAiPlayPageViewController.class]) {
[kNotification postNotificationName:NSNotification_Reader_Back object:@"1"];
}
}
});
};
}
return _headerView;
}
#pragma mark - 点击事件
- (void)addBookRackClick
{
[[TFCollectionManager shareManagerWithProductionType:TFProductionTypeNovel] addCollectionWithProductionModel:self.bookModel];
if ([[TFCollectionManager shareManagerWithProductionType:TFProductionTypeNovel] isCollectedWithProductionModel:self.bookModel]) {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusSuccess promptTitle:TFLocalizedString(@"已加入书架")];
[self.addBookRack setTitle:TFLocalizedString(@"已加入书架") forState:UIControlStateNormal];
[self.addBookRack mas_updateConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(self.addBookRack.intrinsicContentSize.width);
}];
[self.addBookRack setTitleColor:kGrayTextColor forState:UIControlStateNormal];
self.addBookRack.enabled = NO;
} else {
[self.addBookRack setTitle:TFLocalizedString(@"加入书架") forState:UIControlStateNormal];
[self.addBookRack mas_updateConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(self.addBookRack.intrinsicContentSize.width);
}];
[self.addBookRack setTitleColor:kBlackColor forState:UIControlStateNormal];
self.addBookRack.enabled = YES;
}
[TFUtilsHelper synchronizationRackProductionWithProduction_id:self.bookModel.production_id productionType:TFProductionTypeNovel complete:nil];
}
- (void)commentClick
{
WS(weakSelf)
TFCommentsViewController *vc = [[TFCommentsViewController alloc] init];
vc.production_id = self.bookModel.production_id;
vc.chapter_id = [[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeAi] getReadingRecordChapter_idWithProduction_id:self.bookModel.production_id];
vc.productionType = TFProductionTypeNovel;
vc.commentsSuccessBlock = ^(TFCommentsListModel *commentModel) {
TFProductionModel *t_model = weakSelf.bookModel;
// 评论数++
t_model.total_comment ++;
// 评论数组model添加
NSMutableArray *t_array = [NSMutableArray arrayWithArray:weakSelf.audioPlayPageModel.comment.list];
[t_array insertObject:commentModel atIndex:0];
weakSelf.audioPlayPageModel.comment.list = [t_array copy];
weakSelf.bookModel = t_model;
[weakSelf.mainTableViewGroup reloadData];
weakSelf.commentConnerLabel.text = [NSString stringWithFormat:@"%@", weakSelf.audioPlayPageModel.comment_total_count > 99?@"99+":[TFUtilsHelper formatStringWithInteger:weakSelf.audioPlayPageModel.comment_total_count]];
};
[self.navigationController pushViewController:vc animated:YES];
}
- (void)toolBarButtonClick:(TFButton *)sender
{
if (sender.tag == 0) { // 分享
[TFShareManager shareWithProduction_id:NSStringFromInteger(self.bookModel.production_id) chapter_id:nil type:TFShareTypeAudio];
}
if (sender.tag == 1) {
[self commentClick];
}
}
- (void)netRequest
{
WS(weakSelf)
NSInteger chapter_id = [[TFReadRecordManager shareManagerWithProductionType:TFProductionTypeAi] getReadingRecordChapter_idWithProduction_id:self.bookModel.production_id];
if (chapter_id == 0) {
TFProductionChapterModel *t_model = [self.bookModel.chapter_list firstObject];
chapter_id = t_model.chapter_id;
}
[TFNetworkTools POST:Ai_Audio_Detail parameters:@{@"book_id":[TFUtilsHelper formatStringWithInteger:self.bookModel.production_id]?:@"", @"chapter_id":[TFUtilsHelper formatStringWithInteger:chapter_id]} model:WXYZ_PlayPageModel.class success:^(BOOL isSuccess, WXYZ_PlayPageModel * _Nullable t_model, TFNetworkRequestModel * _Nonnull requestModel) {
if (isSuccess) {
weakSelf.audioPlayPageModel = t_model;
weakSelf.commentConnerLabel.text = [NSString stringWithFormat:@"%@", weakSelf.audioPlayPageModel.comment_total_count > 99?@"99+":[TFUtilsHelper formatStringWithInteger:weakSelf.audioPlayPageModel.comment_total_count]];
weakSelf.headerView.relationModel = weakSelf.audioPlayPageModel.relation;
}
weakSelf.needRefresh = YES;
[weakSelf.mainTableViewGroup reloadData];
dispatch_async(dispatch_get_main_queue(), ^{
weakSelf.needRefresh = NO;
});
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
weakSelf.needRefresh = YES;
[weakSelf.mainTableViewGroup reloadData];
dispatch_async(dispatch_get_main_queue(), ^{
weakSelf.needRefresh = NO;
});
}];
}
- (void)requestChapterCommentWithChapter_id:(NSInteger)chapter_id
{
WS(weakSelf)
[TFNetworkTools POST:Book_Comment_List parameters:@{@"page_num":@"1", @"book_id":[TFUtilsHelper formatStringWithInteger:self.bookModel.production_id]?:@"", @"chapter_id":[TFUtilsHelper formatStringWithInteger:chapter_id]} model:TFCommentsModel.class success:^(BOOL isSuccess, TFCommentsModel * _Nullable t_model, TFNetworkRequestModel * _Nonnull requestModel) {
if (isSuccess) {
weakSelf.audioPlayPageModel.comment.list = t_model.list;
weakSelf.needRefresh = YES;
[weakSelf.mainTableViewGroup reloadData];
dispatch_async(dispatch_get_main_queue(), ^{
weakSelf.needRefresh = NO;
});
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
weakSelf.needRefresh = YES;
[weakSelf.mainTableViewGroup reloadData];
dispatch_async(dispatch_get_main_queue(), ^{
weakSelf.needRefresh = NO;
});
}];
}
- (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 ([commentTextView.text isEqualToString:@""]) {
return;
}
NSString *t_text = commentTextView.text;
commentTextView.text = @"";
WS(weakSelf)
[TFNetworkTools POST:Book_Comment_Post parameters:@{@"book_id":[TFUtilsHelper formatStringWithInteger:self.bookModel.production_id]?:@"", @"chapter_id":[TFUtilsHelper formatStringWithInteger:self.chapterModel.chapter_id], @"content":t_text} model:TFCommentsListModel.class success:^(BOOL isSuccess, TFCommentsListModel * _Nullable t_model, TFNetworkRequestModel * _Nonnull requestModel) {
if (isSuccess) {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusSuccess promptTitle:TFLocalizedString(@"评论成功")];
// 评论数组model添加
NSMutableArray *t_array = [NSMutableArray arrayWithArray:weakSelf.audioPlayPageModel.comment.list];
[t_array insertObject:t_model atIndex:0];
weakSelf.audioPlayPageModel.comment.list = [t_array copy];
weakSelf.audioPlayPageModel.comment_total_count++;
[weakSelf.mainTableViewGroup reloadSection:2 withRowAnimation:UITableViewRowAnimationNone];
weakSelf.commentConnerLabel.text = [NSString stringWithFormat:@"%@", weakSelf.audioPlayPageModel.comment_total_count > 99?@"99+":[TFUtilsHelper formatStringWithInteger:weakSelf.audioPlayPageModel.comment_total_count]];
} else if (Compare_Json_isEqualTo(requestModel.code, 315)) {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusSuccess promptTitle:requestModel.msg];
} else {
commentTextView.text = t_text;
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:requestModel.msg];
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
[TFPromptManager showPromptWithError:error defaultText:nil];
}];
}
@end
@@ -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
@@ -0,0 +1,71 @@
//
// WXYZ_GiftMonthlyPassModel.h
// WXReader
//
// Created by LL on 2020/5/28.
// Copyright © 2020 Andrew. All rights reserved.
//
#import <Foundation/Foundation.h>
@class WXYZ_GiftMonthlyPassInfoModel, WXYZ_GiftMonthlyPassListModel;
NS_ASSUME_NONNULL_BEGIN
@interface WXYZ_GiftMonthlyPassModel : NSObject
/// 月票信息
@property (nonatomic, strong) WXYZ_GiftMonthlyPassInfoModel *info;
/// 月票列表
@property (nonatomic, strong) NSArray<WXYZ_GiftMonthlyPassListModel *> *list;
@end
@interface WXYZ_GiftMonthlyPassInfoModel : NSObject
@property (nonatomic, assign) NSInteger book_id;
/// 作品名称
@property (nonatomic, copy) NSString *name;
@property (nonatomic, copy) NSString *cover;
/// 本月获得月票数量
@property (nonatomic, copy) NSString *stickerNumber;
/// 排名
@property (nonatomic, copy) NSString *ranking;
/// 和上一名排行的距离
@property (nonatomic, copy) NSString *last_distance;
/// 剩余的月票
@property (nonatomic, copy) NSString *ticket_remain;
/// 月票规则
@property (nonatomic, copy) NSString *ticket_rule;
/// 是否可投
@property (nonatomic, assign) NSInteger can_vote;
/// 投票说明
@property (nonatomic, copy) NSString *monthly_tips;
@end
@interface WXYZ_GiftMonthlyPassListModel : NSObject
@property (nonatomic, copy) NSString *title;
/// 月票展示数量
@property (nonatomic, assign) NSInteger num;
/// 是否可选中
@property (nonatomic, assign, getter=isEnabled) NSInteger enabled;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,45 @@
//
// WXYZ_GiftMonthlyPassModel.m
// WXReader
//
// Created by LL on 2020/5/28.
// Copyright © 2020 Andrew. All rights reserved.
//
#import "WXYZ_GiftMonthlyPassModel.h"
@implementation WXYZ_GiftMonthlyPassModel
+ (NSDictionary<NSString *, id> *)modelCustomPropertyMapper {
return @{
@"info" : @"ticket_info",
@"list" : @"ticket_option"
};
}
+ (NSDictionary<NSString *,id> *)modelContainerPropertyGenericClass{
return @{
@"info" : WXYZ_GiftMonthlyPassInfoModel.class,
@"list" : WXYZ_GiftMonthlyPassListModel.class
};
}
@end
@implementation WXYZ_GiftMonthlyPassInfoModel
+ (NSDictionary<NSString *, id> *)modelCustomPropertyMapper {
return @{
@"stickerNumber" : @"current_month_get",
@"ranking" : @"rank_tips",
@"ticket_remain" : @"user_remain",
};
}
@end
@implementation WXYZ_GiftMonthlyPassListModel
@end
@@ -0,0 +1,28 @@
//
// WXYZ_GiftMonthlyPassView.h
// WXReader
//
// Created by LL on 2020/5/28.
// Copyright © 2020 Andrew. All rights reserved.
//
#import <UIKit/UIKit.h>
@class WXYZ_GiftView;
@class TFProductionModel;
NS_ASSUME_NONNULL_BEGIN
@interface WXYZ_GiftMonthlyPassView : UIView
- (instancetype)initWithFrame:(CGRect)frame bookModel:(TFProductionModel *)bookModel;
/// 月票余额返回
@property (nonatomic, copy) void(^ticketNumBlock)(NSInteger ticketNumber);
@property (nonatomic, weak) WXYZ_GiftView *giftView;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,320 @@
//
// WXYZ_GiftMonthlyPassView.m
// WXReader
//
// Created by LL on 2020/5/28.
// Copyright © 2020 Andrew. All rights reserved.
//
#import "WXYZ_GiftMonthlyPassView.h"
#import "WXYZ_GiftMonthlyPassModel.h"
#import "NSObject+Observer.h"
#import "TFReaderBookManager.h"
#import "WXYZ_TickectAlertModel.h"
#import "TFProductionCoverView.h"
#import "WXYZ_GiftView.h"
#import "TFRechargeViewController.h"
#import "TFWebViewController.h"
#import "TFGiftAlertView.h"
@interface WXYZ_GiftMonthlyPassView ()
@property (nonatomic, strong) TFProductionModel *bookModel;
@property (nonatomic, strong) WXYZ_GiftMonthlyPassModel *monthlyPassModel;
/// 当前选择按钮的下标
@property (nonatomic, assign) NSInteger selectedIndex;
@property (nonatomic, strong) NSArray<UIButton *> *tickectBtnArray;
@property (nonatomic, weak) UIView *alertView;
@property (nonatomic, weak) UIButton *voteBtn;
@end
@implementation WXYZ_GiftMonthlyPassView
- (instancetype)initWithFrame:(CGRect)frame bookModel:(TFProductionModel *)bookModel {
if (self = [super initWithFrame:frame]) {
self.bookModel = bookModel;
[self initialize];
[self netRequest];
[self createSubviews];
}
return self;
}
- (void)initialize {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(netRequest) name:Notification_Login_Success object:nil];
}
- (void)createSubviews {
TFProductionCoverView *coverImageView = [[TFProductionCoverView alloc] initWithProductionType:TFProductionTypeNovel coverDirection:TFProductionCoverDirectionVertical];
[self addSubview:coverImageView];
[coverImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self).offset(kMargin);
make.left.equalTo(self).offset(kMoreHalfMargin);
make.size.mas_equalTo(CGSizeMake(55.0, 74.0));
}];
UILabel *nameLabel = [[UILabel alloc] init];
nameLabel.backgroundColor = [UIColor clearColor];
nameLabel.textColor = kBlackColor;
nameLabel.font = kFont14;
[self addSubview:nameLabel];
[nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(coverImageView).offset(16);
make.left.equalTo(coverImageView.mas_right).offset(kHalfMargin);
}];
UILabel *tickerLabel = [[UILabel alloc] init];
tickerLabel.backgroundColor = [UIColor clearColor];
[self addSubview:tickerLabel];
UILabel *rankLabel = [[UILabel alloc] init];
rankLabel.backgroundColor = [UIColor clearColor];
[self addSubview:rankLabel];
UILabel *last_distanceLabel = [[UILabel alloc] init];
last_distanceLabel.backgroundColor = [UIColor clearColor];
last_distanceLabel.textAlignment = NSTextAlignmentLeft;
[self addSubview:last_distanceLabel];
NSArray<UILabel *> *labelArr = @[tickerLabel, rankLabel, last_distanceLabel];
[labelArr mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing:0 leadSpacing:80 tailSpacing:0];
[labelArr mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(coverImageView).offset(-kHalfMargin);
}];
UIView *bottomView = [[UIView alloc] init];
bottomView.backgroundColor = kGrayViewColor;
[self addSubview:bottomView];
[bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.bottom.equalTo(self);
make.height.mas_equalTo(65.0 + PUB_TABBAR_OFFSET);
}];
UILabel *remainLabel = [[UILabel alloc] init];
remainLabel.backgroundColor = [UIColor clearColor];
[bottomView addSubview:remainLabel];
[remainLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(bottomView).offset(kMoreHalfMargin + 1.0f);
make.left.equalTo(bottomView).offset(kMoreHalfMargin);
}];
UIImageView *helpImageView = [[UIImageView alloc] init];
helpImageView.image = [UIImage imageNamed:@"book_help"];
[bottomView addSubview:helpImageView];
[helpImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(remainLabel);
make.left.equalTo(remainLabel.mas_right).offset(kHalfMargin);
make.size.mas_equalTo(CGSizeMake(kMoreHalfMargin, kMoreHalfMargin));
}];
helpImageView.userInteractionEnabled = YES;
WS(weakSelf)
[helpImageView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithActionBlock:^(id _Nonnull sender) {
[weakSelf.giftView removeFromSuperview];
[[NSNotificationCenter defaultCenter] postNotificationName:NSNotification_Reader_Push object:@""];
TFWebViewController *vc = [[TFWebViewController alloc] init];
vc.URLString = weakSelf.monthlyPassModel.info.ticket_rule;
vc.navTitle = TFLocalizedString(@"月票说明");
vc.isPresentState = NO;
[[TFViewHelper getCurrentNavigationController] pushViewController:vc animated:YES];
}]];
helpImageView.hidden = YES;
UILabel *detailLabel = [[UILabel alloc] init];
detailLabel.numberOfLines = 2;
detailLabel.backgroundColor = [UIColor clearColor];
[bottomView addSubview:detailLabel];
[detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(remainLabel.mas_bottom).offset(2.5);
make.left.equalTo(remainLabel);
}];
UIButton *voteBtn = [UIButton buttonWithType:UIButtonTypeCustom];
self.voteBtn = voteBtn;
[voteBtn setImage:[UIImage imageNamed:TFLocalizedString(@"book_ticketBtn")] forState:UIControlStateNormal];
voteBtn.layer.cornerRadius = 19.0f;
voteBtn.layer.masksToBounds = YES;
[voteBtn addTarget:self action:@selector(voteEvent) forControlEvents:UIControlEventTouchUpInside];
[bottomView addSubview:voteBtn];
[voteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(bottomView).offset(kMoreHalfMargin);
make.right.equalTo(bottomView).offset(-kMoreHalfMargin);
make.size.mas_equalTo(CGSizeMake(105.0f, 38.0f));
}];
[detailLabel mas_updateConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(voteBtn.mas_left).offset(-kQuarterMargin);
}];
[remainLabel mas_updateConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(voteBtn.mas_left).offset(-kQuarterMargin);
}];
[self addObserver:KEY_PATH(self, monthlyPassModel) complete:^(WXYZ_GiftMonthlyPassView * _Nonnull obj, id _Nullable oldVal, WXYZ_GiftMonthlyPassModel * _Nullable newVal) {
coverImageView.coverImageUrl = newVal.info.cover;
nameLabel.text = newVal.info.name ? : @"";
tickerLabel.attributedText = [obj attributeStringWithStr:newVal.info.stickerNumber ? : @"" speFont:kFont16 speColor:kBlackColor];
rankLabel.attributedText = [obj attributeStringWithStr:newVal.info.ranking ? : @"" speFont:kFont16 speColor:kBlackColor];
last_distanceLabel.attributedText = [obj attributeStringWithStr:newVal.info.last_distance ? : @"" speFont:kFont16 speColor:kBlackColor];
NSString *prefix = TFLocalizedString(@"拥有");
NSString *suffix = TFLocalizedString(@"月票");
NSMutableAttributedString *atr = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@%@%@", prefix, newVal.info.ticket_remain, suffix] attributes:@{NSFontAttributeName : kFont14, NSForegroundColorAttributeName : kBlackColor}];
[atr addAttribute:NSForegroundColorAttributeName value:kMainColor range:NSMakeRange(prefix.length, newVal.info.ticket_remain.length)];
remainLabel.attributedText = atr;
detailLabel.attributedText = [obj attributeStringWithStr:newVal.info.monthly_tips speFont:kFont11 speColor:kMainColor];
if (newVal.info.can_vote == 1) {
voteBtn.alpha = 1;
voteBtn.enabled = YES;
} else {
voteBtn.alpha = 0.5;
voteBtn.enabled = NO;
}
NSMutableArray<UIButton *> *btnArr = [NSMutableArray array];
if (obj.tickectBtnArray.count == 0) {
obj.tickectBtnArray = btnArr;
NSInteger index = 0;
for (WXYZ_GiftMonthlyPassListModel *model in newVal.list) {
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
NSString *text = [NSString stringWithFormat:@"%@\n%@", model.title, TFLocalizedString(@"月票")];
NSMutableAttributedString *atr = [[NSMutableAttributedString alloc] initWithString:text attributes:@{NSForegroundColorAttributeName : kBlackColor, NSFontAttributeName : kFont11}];
[atr addAttribute:NSFontAttributeName value:kFont15 range:NSMakeRange(0, model.title.length)];
if (model.enabled == 0) {
[atr addAttribute:NSForegroundColorAttributeName value:kColorRGB(153, 153, 153) range:NSMakeRange(0, atr.length)];
button.enabled = NO;
}
[button setAttributedTitle:atr forState:UIControlStateNormal];
[button setTitleEdgeInsets:UIEdgeInsetsMake(0, 5.0, 0, 5.0)];
button.titleLabel.numberOfLines = 0;
button.titleLabel.textAlignment = NSTextAlignmentCenter;
button.layer.cornerRadius = 2.5;
button.layer.masksToBounds = YES;
button.layer.borderWidth = 0.5;
button.layer.borderColor = kColorRGB(221, 221, 221).CGColor;
button.tag = index;
[button addTarget:obj action:@selector(tickectOptionEvent:) forControlEvents:UIControlEventTouchUpInside];
[obj addSubview:button];
[btnArr addObject:button];
index++;
}
[btnArr mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing:kQuarterMargin leadSpacing:15.0 tailSpacing:15.0];
[btnArr mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(coverImageView.mas_bottom).offset(24.0);
make.height.equalTo(btnArr.firstObject.mas_width);
}];
[btnArr.firstObject sendActionsForControlEvents:UIControlEventTouchUpInside];
}
}];
}
- (void)tickectOptionEvent:(UIButton *)button {
if (self.monthlyPassModel.list[button.tag].enabled == 1) {
NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithAttributedString:button.currentAttributedTitle];
[str setAttribute:NSForegroundColorAttributeName value:kMainColor];
[button setAttributedTitle:str forState:UIControlStateNormal];
button.layer.borderColor = kMainColor.CGColor;
self.selectedIndex = button.tag;
}
for (UIButton *obj in self.tickectBtnArray) {
if (obj != button) {
NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithAttributedString:obj.currentAttributedTitle];
[str setAttribute:NSForegroundColorAttributeName value:self.monthlyPassModel.list[obj.tag].enabled ? kBlackColor : kColorRGB(153, 153, 153)];
[obj setAttributedTitle:str forState:UIControlStateNormal];
obj.layer.borderColor = kColorRGB(221, 221, 221).CGColor;
}
}
if (self.monthlyPassModel.info.can_vote == 1) {
self.voteBtn.alpha = 1;
self.voteBtn.enabled = YES;
} else {
self.voteBtn.alpha = 0.5;
self.voteBtn.enabled = NO;
}
}
// 投月票
- (void)voteEvent {
if (self.selectedIndex == -1) {
return;
}
if (!TFUserInfoManager.isLogin) {
[TFLoginOptionsViewController presentLoginView:nil];
return;
}
WXYZ_GiftMonthlyPassListModel *model = self.monthlyPassModel.list[self.selectedIndex];
NSDictionary *params = @{
@"book_id" : @(self.bookModel.production_id),
@"chapter_id" : @([TFReaderBookManager sharedManager].chapter_id),
@"num" : @(model.num),
};
WS(weakSelf)
[TFNetworkTools POST:Book_Reward_Ticket_Vote parameters:params model:WXYZ_TickectAlertModel.class success:^(BOOL isSuccess, WXYZ_TickectAlertModel * _Nullable t_model, TFNetworkRequestModel * _Nonnull requestModel) {
if (isSuccess) {
[weakSelf netRequest];
NSString *text = [NSString stringWithFormat:@"%@", requestModel.data[@"ticket_num"]];
[[NSNotificationCenter defaultCenter] postNotificationName:@"changeTicket" object:text];
!weakSelf.ticketNumBlock ?: weakSelf.ticketNumBlock([text integerValue]);
[TFReaderBookManager sharedManager].ticket_num = text ?: @"";
[TFPromptManager showPromptViewWithStatus:TFPromptStatusSuccess promptTitle:TFLocalizedString(@"投票成功")];
} else if (Compare_Json_isEqualTo(requestModel.code, 902)) {
[weakSelf showAlert:t_model t_model:weakSelf.monthlyPassModel.list[weakSelf.selectedIndex] production_id:weakSelf.bookModel.production_id ticketNumBlock:weakSelf.ticketNumBlock];
[weakSelf.giftView hide];
} else {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:requestModel.msg];
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
[TFPromptManager showPromptWithError:error defaultText:nil];
}];
}
- (NSMutableAttributedString *)attributeStringWithStr:(NSString *)str speFont:(UIFont *)speFont speColor:(UIColor *)speColor {
NSRange range = [str rangeOfString:@"###.*###" options:NSRegularExpressionSearch];
if (range.length == 0) range = NSMakeRange(0, 0);
NSString *suffix = [[str substringWithRange:range] stringByReplacingOccurrencesOfString:@"#" withString:@""];
suffix = [NSString stringWithFormat:@" %@ ", suffix];
NSMutableString *prefix = [NSMutableString stringWithString:[str stringByReplacingCharactersInRange:range withString:@""]];
[prefix insertString:suffix atIndex:range.location];
NSMutableAttributedString *atr = [[NSMutableAttributedString alloc] initWithString:prefix attributes:@{NSFontAttributeName : kFont11, NSForegroundColorAttributeName : kGrayTextColor}];
[atr addAttributes:@{NSFontAttributeName : speFont, NSForegroundColorAttributeName : speColor} range:NSMakeRange(range.location, suffix.length)];
return atr;
}
- (void)netRequest {
WS(weakSelf)
[TFNetworkTools POST:Book_Gift_Montyly_Pass parameters:@{@"book_id":@(self.bookModel.production_id)} model:WXYZ_GiftMonthlyPassModel.class success:^(BOOL isSuccess, id _Nullable t_model, TFNetworkRequestModel * _Nonnull requestModel) {
if (isSuccess) {
weakSelf.monthlyPassModel = t_model;
} else {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:requestModel.msg];
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
[TFPromptManager showPromptWithError:error defaultText:nil];
}];
}
- (void)showAlert:(WXYZ_TickectAlertModel *)model t_model:(WXYZ_GiftMonthlyPassListModel *)t_model production_id:(NSInteger)production_id ticketNumBlock:(void(^)(NSInteger number))ticketNumBlock
{
TFGiftAlertView *alertView = [[TFGiftAlertView alloc] init];
[alertView setAlertModel:model giftModel:t_model production_id:production_id ticketBlock:ticketNumBlock];
[alertView showAlertView];
}
@end
@@ -0,0 +1,49 @@
//
// WXYZ_GiftRewardList.h
// WXReader
//
// Created by LL on 2020/5/28.
// Copyright © 2020 Andrew. All rights reserved.
//
#import <Foundation/Foundation.h>
@class WXYZ_GiftRewardListModel, WXYZ_GiftUserModel;
NS_ASSUME_NONNULL_BEGIN
@interface WXYZ_GiftRewardModel : NSObject
@property (nonatomic, copy) NSArray<WXYZ_GiftRewardListModel *> *list;
@property (nonatomic, copy) NSArray<NSString *> *announce_list;
@property (nonatomic, strong) WXYZ_GiftUserModel *user;
@end
@interface WXYZ_GiftRewardListModel : NSObject
@property (nonatomic, assign) NSInteger gift_id;
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *icon;
/// 奖励文案
@property (nonatomic, copy) NSString *gift_price;
/// 角标
@property (nonatomic, copy) NSString *flag;
@end
@interface WXYZ_GiftUserModel : NSObject
@property (nonatomic, assign) NSInteger goldRemain;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,42 @@
//
// WXYZ_GiftRewardList.m
// WXReader
//
// Created by LL on 2020/5/28.
// Copyright © 2020 Andrew. All rights reserved.
//
#import "WXYZ_GiftRewardModel.h"
@implementation WXYZ_GiftRewardModel
+ (NSDictionary<NSString *, id> *)modelCustomPropertyMapper {
return @{
@"list" : @"gift_option",
@"announce_list" : @"broadcast_list"
};
}
+ (NSDictionary<NSString *,id> *)modelContainerPropertyGenericClass{
return @{
@"list" : WXYZ_GiftRewardListModel.class
};
}
@end
@implementation WXYZ_GiftRewardListModel
+ (NSDictionary<NSString *, id> *)modelCustomPropertyMapper {
return @{
@"awardTitle" : @"award_money"
};
}
@end
@implementation WXYZ_GiftUserModel
@end
@@ -0,0 +1,39 @@
//
// WXYZ_GiftRewardView.h
// WXReader
//
// Created by LL on 2020/5/28.
// Copyright © 2020 Andrew. All rights reserved.
//
#import <UIKit/UIKit.h>
@class WXYZ_GiftView;
@class WXYZ_GiftRewardListModel;
NS_ASSUME_NONNULL_BEGIN
@interface WXYZ_GiftRewardView : UIView
@property (nonatomic, weak) WXYZ_GiftView *giftView;
@property (nonatomic, strong) TFProductionModel *bookModel;
/// 打赏余额返回
@property (nonatomic, copy) void(^giftNumBlock)(NSInteger giftNumber);
- (instancetype)initWithBookModel:(TFProductionModel *)bookModel;
@end
@interface WXYZ_GiftRewardCell : UICollectionViewCell
@property (nonatomic, strong) WXYZ_GiftRewardListModel *giftRewardModel;
- (void)setSelected:(BOOL)selected;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,354 @@
//
// WXYZ_GiftRewardView.m
// WXReader
//
// Created by LL on 2020/5/28.
// Copyright © 2020 Andrew. All rights reserved.
//
#import "WXYZ_GiftRewardView.h"
#import "NSObject+Observer.h"
#import "WXYZ_GiftRewardModel.h"
#import "LLPageControl.h"
#import "WXYZ_AnnouncementView.h"
#import "TFReaderBookManager.h"
#import "TFRechargeViewController.h"
#import "WXYZ_GiftView.h"
@interface WXYZ_GiftRewardView ()<UICollectionViewDataSource, UICollectionViewDelegate>
@property (nonatomic, strong) NSArray<WXYZ_GiftRewardListModel *> *dataSourceArray;
@property (nonatomic, strong) WXYZ_GiftRewardModel *giftRewardModel;
@property (nonatomic, weak) UICollectionView *mainCollectionView;
@property (nonatomic, weak) LLPageControl *pageControl;
@property (nonatomic, weak) WXYZ_AnnouncementView *announcementView;
@property (nonatomic, weak) UILabel *remainLabel;
@property (nonatomic, assign) NSInteger selectedIndex;
@end
@implementation WXYZ_GiftRewardView
- (instancetype)initWithBookModel:(TFProductionModel *)bookModel {
if (self = [super init]) {
self.bookModel = bookModel;
[self initialize];
[self createSubviews];
[self netRequest];
}
return self;
}
- (void)initialize {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loginSuccess) name:Notification_Login_Success object:nil];
}
- (void)createSubviews {
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
flowLayout.itemSize = CGSizeMake((SCREEN_WIDTH - 2.0 * kMoreHalfMargin - 3 * kHalfMargin) / 4.0, 127.0);
flowLayout.minimumInteritemSpacing = kHalfMargin;
flowLayout.minimumLineSpacing = kHalfMargin;
flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
UICollectionView *mainCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout];
self.mainCollectionView = mainCollectionView;
mainCollectionView.showsHorizontalScrollIndicator = NO;
mainCollectionView.showsVerticalScrollIndicator = NO;
mainCollectionView.backgroundColor = [UIColor clearColor];
mainCollectionView.pagingEnabled = YES;
mainCollectionView.dataSource = self;
mainCollectionView.delegate = self;
mainCollectionView.contentInset = UIEdgeInsetsMake(0, 0, 0, kMoreHalfMargin);
[mainCollectionView registerClass:WXYZ_GiftRewardCell.class forCellWithReuseIdentifier:@"Identifier"];
[self addSubview:mainCollectionView];
[mainCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self).offset(15);
make.right.equalTo(self).offset(0);
make.top.equalTo(self).offset(kMoreHalfMargin);
make.height.mas_equalTo(127.0);
}];
// [mainCollectionView addObserver:KEY_PATH(mainCollectionView, contentSize) complete:^(UICollectionView * _Nonnull obj, id _Nullable oldVal, id _Nullable newVal) {
// CGSize size = [newVal CGSizeValue];
// [obj mas_updateConstraints:^(MASConstraintMaker *make) {
// make.height.mas_equalTo(size.height);
// }];
// [obj.superview setNeedsLayout];
// [obj.superview layoutIfNeeded];
// }];
LLPageControl *pageControl = [LLPageControl pageControlWithRadius:3.5 spacing:6.0f numberOfPages:1];
self.pageControl = pageControl;
pageControl.currentPageIndicatorTintColor = kMainColor;
pageControl.pageIndicatorTintColor = kColorRGB(225, 225, 225);
[self addSubview:pageControl];
[pageControl mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(mainCollectionView.mas_bottom).offset(12.0);
make.centerX.equalTo(self);
}];
WXYZ_AnnouncementView *announcementView = [[WXYZ_AnnouncementView alloc] init];
self.announcementView = announcementView;
announcementView.backgroundColor = kColorRGB(249, 248, 253);
announcementView.layer.cornerRadius = 14.0f;
announcementView.layer.masksToBounds = YES;
announcementView.textFont = kFont11;
announcementView.textColor = kGrayTextColor;
announcementView.isCenter = YES;
announcementView.duration = 5.0f;
announcementView.userInteractionEnabled = NO;
[self addSubview:announcementView];
[announcementView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(pageControl.mas_bottom).offset(17.0f);
make.left.equalTo(self).offset(kMoreHalfMargin);
make.right.equalTo(self).offset(-kMoreHalfMargin);
make.height.equalTo(announcementView.mas_width).multipliedBy(28.0 / 345.0);
}];
UIView *bottomView = [[UIView alloc] init];
bottomView.backgroundColor = kColorRGB(249, 248, 253);
[self addSubview:bottomView];
[bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(announcementView.mas_bottom).offset(17.0f);
make.left.right.equalTo(self);
make.height.mas_equalTo(65.0f);
}];
UILabel *remainLabel = [[UILabel alloc] init];
self.remainLabel = remainLabel;
remainLabel.backgroundColor = [UIColor clearColor];
[self addSubview:remainLabel];
[remainLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(bottomView).offset(kMoreHalfMargin);
make.top.equalTo(bottomView.mas_top).offset(15.0);
}];
UIButton *rewardBtn = [UIButton buttonWithType:UIButtonTypeCustom];
rewardBtn.layer.cornerRadius = 19.0f;
[rewardBtn setImage:[UIImage imageNamed:TFLocalizedString(@"book_giftBtn")] forState:UIControlStateNormal];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(rewardEvent)];
[rewardBtn addGestureRecognizer:tap];
[bottomView addSubview:rewardBtn];
[rewardBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(bottomView).offset(6.0);
make.right.equalTo(bottomView).offset(-kMoreHalfMargin);
make.size.mas_equalTo(CGSizeMake(105, 38));
}];
UIView *splitLine = [[UIView alloc] init];
splitLine.backgroundColor = [UIColor clearColor];
[self addSubview:splitLine];
[splitLine mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(0.1);
make.left.right.bottom.equalTo(self);
make.top.equalTo(bottomView.mas_bottom).priorityLow();
}];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return self.dataSourceArray.count;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
WXYZ_GiftRewardCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Identifier" forIndexPath:indexPath];
[cell setGiftRewardModel:self.dataSourceArray[indexPath.row]];
[cell setSelected:self.selectedIndex == indexPath.row];
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
self.selectedIndex = indexPath.row;
[collectionView reloadData];
}
- (void)loginSuccess {
NSString *prefix = TFLocalizedString(@"余额:");
NSString *remain = [NSString stringWithFormat:@"%zd", TFUserInfoManager.shareInstance.masterRemain];
NSString *suffix = TFSystemInfoManager.masterUnit;
NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@%@ %@", prefix, remain, suffix] attributes:@{NSForegroundColorAttributeName: kGrayTextColor, NSFontAttributeName: kFont14}];
[str addAttribute:NSForegroundColorAttributeName value:kMainColor range:NSMakeRange(prefix.length, remain.length)];
self.remainLabel.attributedText = str;
}
- (void)rewardEvent {
if (!TFUserInfoManager.isLogin) {
[TFLoginOptionsViewController presentLoginView:nil];
return;
}
WXYZ_GiftRewardListModel *model = self.dataSourceArray[self.selectedIndex];
NSDictionary *params = @{
@"book_id" : @(self.bookModel.production_id),
@"chapter_id" : @([TFReaderBookManager sharedManager].chapter_id),
@"gift_id" : @(model.gift_id)
};
WS(weakSelf)
[TFNetworkTools POST:Book_Reward_Gift_Send parameters:params model:nil success:^(BOOL isSuccess, NSDictionary *_Nullable t_model, TFNetworkRequestModel *requestModel) {
if (isSuccess) {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusSuccess promptTitle:TFLocalizedString(@"打赏成功")];
NSString *text = [NSString stringWithFormat:@"%@", t_model[@"data"][@"reward_num"]];
[[NSNotificationCenter defaultCenter] postNotificationName:@"changeReward" object:text];
!weakSelf.giftNumBlock ?: weakSelf.giftNumBlock([text integerValue]);
[weakSelf.giftView hide];
} else if (Compare_Json_isEqualTo(requestModel.code, 802)) {
[[NSNotificationCenter defaultCenter] postNotificationName:NSNotification_Reader_Push object:@""];
[[TFViewHelper getCurrentNavigationController] pushViewController:[[TFRechargeViewController alloc] init] animated:YES];
} else {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:requestModel.msg];
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
[TFPromptManager showPromptWithError:error defaultText:nil];
}];
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
// 计算偏移量更新分页控件
NSUInteger page = CGRectGetMinX(scrollView.bounds) / scrollView.contentOffset.x;
if (scrollView.contentOffset.x == 0) {
page = 0;
}
self.pageControl.currentPage = page;
}
- (void)netRequest {
WS(weakSelf)
[TFNetworkTools POST:Gift_List parameters:@{@"book_id":@(self.bookModel.production_id)} model:WXYZ_GiftRewardModel.class success:^(BOOL isSuccess, WXYZ_GiftRewardModel *_Nullable t_model, TFNetworkRequestModel *requestModel) {
if (isSuccess) {
weakSelf.giftRewardModel = t_model;
weakSelf.dataSourceArray = t_model.list;
weakSelf.pageControl.numberOfPages = ceil(weakSelf.dataSourceArray.count / 4.0);
NSMutableArray<TFAnnouncementModel *> *arr = [NSMutableArray array];
for (NSString *str in t_model.announce_list) {
TFAnnouncementModel *tt_model = [[TFAnnouncementModel alloc] init];
tt_model.content = @"";
tt_model.title = str;
[arr addObject:tt_model];
}
weakSelf.announcementView.modelArr = arr;
NSString *prefix = TFLocalizedString(@"余额:");
NSString *remain = [NSString stringWithFormat:@"%zd", t_model.user.goldRemain];
NSString *suffix = TFSystemInfoManager.masterUnit;
NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@%@ %@", prefix, remain, suffix] attributes:@{NSForegroundColorAttributeName: kGrayTextColor, NSFontAttributeName: kFont14}];
[str addAttribute:NSForegroundColorAttributeName value:kMainColor range:NSMakeRange(prefix.length, remain.length)];
weakSelf.remainLabel.attributedText = str;
[weakSelf.mainCollectionView reloadData];
} else {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:requestModel.msg];
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
[TFPromptManager showPromptWithError:error defaultText:nil];
}];
}
@end
@implementation WXYZ_GiftRewardCell
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
[self createSubviews];
}
return self;
}
- (void)createSubviews {
self.contentView.layer.cornerRadius = 2.5;
self.contentView.layer.borderColor = kMainColor.CGColor;
self.contentView.layer.borderWidth = 0.0f;
self.contentView.backgroundColor = [UIColor clearColor];
UILabel *flagLabel = [[UILabel alloc] init];
flagLabel.font = kFont10;
flagLabel.textColor = [UIColor whiteColor];
flagLabel.backgroundColor = kColorRGB(255, 83, 81);
flagLabel.preferredMaxLayoutWidth = CGRectGetWidth(self.contentView.bounds) - kHalfMargin;
flagLabel.textAlignment = NSTextAlignmentCenter;
flagLabel.layer.cornerRadius = 2.0f;
flagLabel.numberOfLines = 0;
flagLabel.layer.masksToBounds = YES;
[self.contentView addSubview:flagLabel];
[flagLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.right.equalTo(self.contentView);
}];
UIImageView *coverImageView = [[UIImageView alloc] init];
coverImageView.backgroundColor = [UIColor clearColor];
[self.contentView addSubview:coverImageView];
[self.contentView sendSubviewToBack:coverImageView];
[coverImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.contentView).offset(kMargin);
make.centerX.equalTo(self.contentView);
make.size.mas_equalTo(CGSizeMake(50.0, 50.0));
}];
UILabel *subtitle = [[UILabel alloc] init];
subtitle.textColor = kGrayTextColor;
subtitle.font = kFont10;
subtitle.textAlignment = NSTextAlignmentCenter;
subtitle.numberOfLines = 0;
subtitle.backgroundColor = [UIColor clearColor];
[self.contentView addSubview:subtitle];
[subtitle mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(self.contentView).offset(-kQuarterMargin);
make.left.equalTo(self.contentView).offset(kQuarterMargin);
make.right.equalTo(self.contentView).offset(-kQuarterMargin);
}];
UILabel *titleLabel = [[UILabel alloc] init];
titleLabel.textColor = kBlackColor;
titleLabel.font = kFont13;
titleLabel.textAlignment = NSTextAlignmentCenter;
titleLabel.backgroundColor = [UIColor clearColor];
[self.contentView addSubview:titleLabel];
[titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(subtitle.mas_top).offset(- kQuarterMargin);
make.left.equalTo(self.contentView).offset(kQuarterMargin);
make.right.equalTo(self.contentView).offset(-kQuarterMargin);
}];
[self addObserver:KEY_PATH(self, giftRewardModel) complete:^(WXYZ_GiftRewardCell * _Nonnull obj, id _Nullable oldVal, WXYZ_GiftRewardListModel * _Nullable newVal) {
flagLabel.text = newVal.flag ?: @"";
CGFloat maxWidth = CGRectGetWidth(obj.contentView.bounds) - kHalfMargin;
if (flagLabel.intrinsicContentSize.width + 12 < maxWidth) {
maxWidth = flagLabel.intrinsicContentSize.width + 12;
}
[flagLabel mas_updateConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(maxWidth);
make.height.mas_equalTo(flagLabel.intrinsicContentSize.height + kQuarterMargin);
}];
flagLabel.hidden = newVal.flag.length == 0;
[coverImageView setImageWithURL:[NSURL URLWithString:newVal.icon ?: @""] placeholder:HoldImage];
titleLabel.text = newVal.title ?: @"";
subtitle.text = newVal.gift_price ?: @"";
}];
}
//- (UICollectionViewLayoutAttributes*)preferredLayoutAttributesFittingAttributes:(UICollectionViewLayoutAttributes*)layoutAttributes {
// [self setNeedsLayout];
// [self layoutIfNeeded];
// CGSize size = [self.contentView systemLayoutSizeFittingSize:layoutAttributes.size];
// CGRect cellFrame = layoutAttributes.frame;
// cellFrame.size.height = size.height;
// layoutAttributes.frame = cellFrame;
// return layoutAttributes;
//}
- (void)setSelected:(BOOL)selected {
if (selected) {
self.contentView.layer.borderWidth = 1.0f;
} else {
self.contentView.layer.borderWidth = 0.0f;
}
}
@end
@@ -0,0 +1,35 @@
//
// WXYZ_GiftView.h
// WXReader
//
// Created by LL on 2020/5/27.
// Copyright © 2020 Andrew. All rights reserved.
//
#import <UIKit/UIKit.h>
@class TFProductionModel;
NS_ASSUME_NONNULL_BEGIN
/// 阅读器礼物视图
@interface WXYZ_GiftView : UIView
/// 月票余额返回
@property (nonatomic, copy) void(^ticketNumBlock)(NSInteger ticketNumber);
/// 打赏余额返回
@property (nonatomic, copy) void(^giftNumBlock)(NSInteger giftNumber);
/// 是否选中月票页面
@property (nonatomic, assign) BOOL isTicket;
- (instancetype)initWithFrame:(CGRect)frame bookModel:(TFProductionModel *)bookModel;
- (void)hide;
- (void)show;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,257 @@
//
// WXYZ_GiftView.m
// WXReader
//
// Created by LL on 2020/5/27.
// Copyright © 2020 Andrew. All rights reserved.
//
#import "WXYZ_GiftView.h"
#import "UIView+LayoutCallback.h"
#import "SGPageTitleView.h"
#import "WXYZ_GiftRewardView.h"
#import "WXYZ_GiftMonthlyPassView.h"
#import "AppDelegate.h"
@interface WXYZ_GiftView ()<SGPageTitleViewDelegate, UIScrollViewDelegate>
@property (nonatomic, weak) UIView *mainView;
@property (nonatomic, weak) UIView *backView;
@property (nonatomic, weak) SGPageTitleView *pageTitleView;
@property (nonatomic, weak) UIScrollView *scrollView;
@property (nonatomic, strong) TFProductionModel *bookModel;
@property (nonatomic, weak) WXYZ_GiftRewardView *rewardView;
@property (nonatomic, weak) WXYZ_GiftMonthlyPassView *monthlyPassView;
@property (nonatomic, strong) NSMutableArray<NSString *> *titleArr;
/// mainView视图约束
@property (nonatomic, strong) MASConstraint *mainViewConstraint;
@end
@implementation WXYZ_GiftView
- (instancetype)initWithFrame:(CGRect)frame bookModel:(TFProductionModel *)bookModel {
if (self = [super initWithFrame:frame]) {
self.bookModel = bookModel;
[self createSubviews];
}
return self;
}
- (void)createSubviews {
self.backgroundColor = kBlackTransparentColor;
[[TFViewHelper getCurrentViewController].view addSubview:self];
[self mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo([TFViewHelper getCurrentViewController].view);
}];
UIView *backView = [[UIView alloc] init];
self.backView = backView;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hide)];
[backView addGestureRecognizer:tap];
backView.backgroundColor = [UIColor clearColor];
[self addSubview:backView];
[backView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self);
}];
UIView *mainView = [[UIView alloc] init];
self.mainView = mainView;
mainView.backgroundColor = [UIColor whiteColor];
mainView.frameBlock = ^(UIView * _Nonnull view) {
UIBezierPath *corner = [UIBezierPath bezierPathWithRoundedRect:view.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(12.0, 12.0)];
CAShapeLayer *layer = [CAShapeLayer layer];
layer.path = corner.CGPath;
view.layer.mask = layer;
};
[self addSubview:mainView];
[mainView mas_makeConstraints:^(MASConstraintMaker *make) {
self.mainViewConstraint = make.top.equalTo(backView.mas_bottom);
make.left.width.equalTo(backView);
}];
SGPageTitleViewConfigure *pageConfigure = [[SGPageTitleViewConfigure alloc] init];
pageConfigure.indicatorColor = kColorRGB(253, 154, 99);
pageConfigure.indicatorStyle = SGIndicatorStyleDynamic;
pageConfigure.indicatorHeight = 3;
pageConfigure.indicatorFixedWidth = 20;
pageConfigure.indicatorDynamicWidth = 20;
pageConfigure.indicatorCornerRadius = 3.0;
pageConfigure.indicatorToBottomDistance = 5;
pageConfigure.titleFont = kFont15;
pageConfigure.titleSelectedFont = kFont16;
pageConfigure.titleColor = kGrayTextColor;
pageConfigure.titleSelectedColor = kBlackColor;
pageConfigure.showBottomSeparator = NO;
AppDelegate *app = (AppDelegate *)kRCodeSync([UIApplication sharedApplication].delegate);
NSMutableArray<NSString *> *titleArr = [NSMutableArray array];
self.titleArr = titleArr;
if (app.checkSettingModel.system_setting.novel_reward_switch == 1) {
[titleArr addObject:TFLocalizedString(@"打赏")];
}
if (app.checkSettingModel.system_setting.monthly_ticket_switch == 1) {
[titleArr addObject:TFLocalizedString(@"月票")];
}
CGFloat width1 = [TFViewHelper getDynamicWidthWithLabelFont:kFont14 labelHeight:50.0 labelText:TFLocalizedString(@"打赏") maxWidth:200.0];
CGFloat width2 = [TFViewHelper getDynamicWidthWithLabelFont:kFont17 labelHeight:50.0 labelText:TFLocalizedString(@"月票") maxWidth:200.0];
CGFloat width = width1 + width2 + kLabelHeight + kMargin;
SGPageTitleView *pageTitleView = [SGPageTitleView pageTitleViewWithFrame:CGRectZero delegate:self titleNames:titleArr configure:pageConfigure];
self.pageTitleView = pageTitleView;
pageTitleView.backgroundColor = [UIColor clearColor];
[mainView addSubview:pageTitleView];
[pageTitleView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(mainView).offset(0);
make.centerX.equalTo(mainView);
make.width.mas_equalTo(width);
make.height.mas_equalTo(50);
}];
UIView *pageTitleSplitLine = [[UIView alloc] init];
pageTitleSplitLine.backgroundColor = kGrayLineColor;
[mainView addSubview:pageTitleSplitLine];
[pageTitleSplitLine mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.width.equalTo(mainView);
make.top.equalTo(pageTitleView.mas_bottom);
make.height.mas_equalTo(kCellLineHeight);
}];
UIScrollView *scrollView = [[UIScrollView alloc] init];
self.scrollView = scrollView;
scrollView.backgroundColor = [UIColor clearColor];
scrollView.bounces = NO;
scrollView.showsVerticalScrollIndicator = NO;
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.delegate = self;
scrollView.pagingEnabled = YES;
[mainView addSubview:scrollView];
[scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(pageTitleSplitLine.mas_bottom);
make.left.width.equalTo(mainView);
make.height.mas_equalTo(271 + PUB_TABBAR_OFFSET);
}];
WXYZ_GiftRewardView *rewardView = [[WXYZ_GiftRewardView alloc] initWithBookModel:self.bookModel];
self.rewardView = rewardView;
rewardView.giftView = self;
rewardView.backgroundColor = [UIColor clearColor];
WXYZ_GiftMonthlyPassView *monthlyPassView = [[WXYZ_GiftMonthlyPassView alloc] initWithFrame:CGRectZero bookModel:self.bookModel];
self.monthlyPassView = monthlyPassView;
monthlyPassView.giftView = self;
monthlyPassView.backgroundColor = [UIColor clearColor];
if (app.checkSettingModel.system_setting.novel_reward_switch == 1 && app.checkSettingModel.system_setting.monthly_ticket_switch == 1) {
[scrollView addSubview:rewardView];
[scrollView addSubview:monthlyPassView];
[rewardView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.left.width.height.equalTo(scrollView);
}];
[monthlyPassView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.height.right.equalTo(scrollView);
make.left.equalTo(rewardView.mas_right);
make.width.equalTo(rewardView);
}];
} else if (app.checkSettingModel.system_setting.novel_reward_switch == 1) {
[scrollView addSubview:rewardView];
[rewardView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.left.width.height.equalTo(scrollView);
make.right.equalTo(scrollView);
}];
// monthlyPassView.hidden = YES;
} else if (app.checkSettingModel.system_setting.monthly_ticket_switch == 1) {
[scrollView addSubview:monthlyPassView];
[monthlyPassView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.left.width.height.equalTo(scrollView);
make.right.equalTo(scrollView);
}];
// rewardView.hidden = YES;
}
UIView *splitLine = [[UIView alloc] init];
splitLine.backgroundColor = [UIColor clearColor];
[mainView addSubview:splitLine];
[splitLine mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(0.1);
make.left.right.bottom.equalTo(mainView);
make.top.equalTo(scrollView.mas_bottom).priorityLow();
}];
[self setNeedsLayout];
[self layoutIfNeeded];
}
- (void)setGiftNumBlock:(void (^)(NSInteger))giftNumBlock {
_giftNumBlock = giftNumBlock;
self.rewardView.giftNumBlock = giftNumBlock;
}
- (void)setTicketNumBlock:(void (^)(NSInteger))ticketNumBlock {
_ticketNumBlock = ticketNumBlock;
self.monthlyPassView.ticketNumBlock = ticketNumBlock;
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
// 计算偏移量更新分页控件
NSUInteger page = scrollView.contentOffset.x / CGRectGetWidth(scrollView.bounds);
self.pageTitleView.resetSelectedIndex = page;
}
- (void)pageTitleView:(SGPageTitleView *)pageTitleView selectedIndex:(NSInteger)selectedIndex {
[self.scrollView setContentOffset:CGPointMake(SCREEN_WIDTH * selectedIndex, 0) animated:YES];
}
- (void)setIsTicket:(BOOL)isTicket {
if (isTicket) {
if (self.titleArr.count > 1) {
self.pageTitleView.resetSelectedIndex = 1;
[self.scrollView setContentOffset:CGPointMake(SCREEN_WIDTH * 1, 0) animated:NO];
}
} else {
self.pageTitleView.resetSelectedIndex = 0;
[self.scrollView setContentOffset:CGPointMake(SCREEN_WIDTH * 0, 0) animated:NO];
}
}
- (void)show {
[UIView animateWithDuration:kAnimatedDuration animations:^{
[self.mainViewConstraint uninstall];
[self.mainView mas_updateConstraints:^(MASConstraintMaker *make) {
self.mainViewConstraint = make.top.equalTo(self.mas_bottom).offset(-CGRectGetHeight(self.mainView.frame));
}];
[self.mainView.superview layoutIfNeeded];
}];
}
- (void)hide {
[UIView animateWithDuration:kAnimatedDuration animations:^{
[self.mainViewConstraint uninstall];
[self.mainView mas_updateConstraints:^(MASConstraintMaker *make) {
self.mainViewConstraint = make.top.equalTo(self.mas_bottom);
}];
[self.mainView.superview layoutIfNeeded];
} completion:^(BOOL finished) {
if (finished) {
[self removeFromSuperview];
}
}];
}
@end
@@ -0,0 +1,35 @@
//
// WXYZ_TickectAlertModel.h
// WXReader
//
// Created by LL on 2020/6/1.
// Copyright © 2020 Andrew. All rights reserved.
//
#import <Foundation/Foundation.h>
@class WXYZ_TickectAlertItemsModel;
NS_ASSUME_NONNULL_BEGIN
@interface WXYZ_TickectAlertModel : NSObject
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSArray<NSString *> *desc;
@property (nonatomic, copy) NSArray<WXYZ_TickectAlertItemsModel *> *items;
@end
@interface WXYZ_TickectAlertItemsModel : NSObject
@property (nonatomic, copy) NSString *title;
/// 动作 recharge去充值 exchange金币抵扣
@property (nonatomic, copy) NSString *action;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,24 @@
//
// WXYZ_TickectAlertModel.m
// WXReader
//
// Created by LL on 2020/6/1.
// Copyright © 2020 Andrew. All rights reserved.
//
#import "WXYZ_TickectAlertModel.h"
@implementation WXYZ_TickectAlertModel
+ (NSDictionary<NSString *,id> *)modelContainerPropertyGenericClass{
return @{
@"items" : WXYZ_TickectAlertItemsModel.class
};
}
@end
@implementation WXYZ_TickectAlertItemsModel
@end
@@ -0,0 +1,31 @@
//
// WXYZ_BookReaderBottomBar.h
// WXReader
//
// Created by Andrew on 2018/6/12.
// Copyright © 2018年 Andrew. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface WXYZ_BookReaderBottomBar : UIView
// 正在自动阅读
@property (nonatomic, assign) BOOL autoReading;
// 显示工具栏
- (void)showToolBar;
// 隐藏工具栏
- (void)hiddenToolBar;
// 显示底部菜单按钮
- (void)showMenuView;
// 显示自动阅读栏
- (void)showAutoReadToolBar;
// 停止自动阅读
- (void)stopAutoRead;
@end
@@ -0,0 +1,426 @@
//
// WXYZ_BookReaderBottomBar.m
// TFReader
//
// Created by Andrew on 2018/6/12.
// Copyright © 2018年 Andrew. All rights reserved.
//
#import "WXYZ_BookReaderBottomBar.h"
#import "TFSliderView.h"
#import "WXYZ_BookReaderMenuBar.h"
#import "WXYZ_BookReaderBottomSettingBar.h"
#import "TFReaderSettingHelper.h"
#import "TFReaderBookManager.h"
#import "AppDelegate.h"
#import "TFWebViewController.h"
#define ToolBar_Normal_Height (60 + PUB_TABBAR_OFFSET)
#define ToolBarSettingView_Height ((50 * 4) + kHalfMargin)
#define ToolBarAutoReadView_Height (ToolBar_Normal_Height + 20 + kMargin)
#define ToolBar_Large_Height (ToolBar_Normal_Height + ToolBarSettingView_Height)
#define animateDuration 0.2f
@interface WXYZ_BookReaderBottomBar () <TFSliderViewDelegate>
{
// 菜单按钮
UIView *menuView;
// 菜单栏设置背景
WXYZ_BookReaderBottomSettingBar *settingBackView;
// 自动阅读按钮
TFButton *autoReadButton;
// 分割线
UIView *grayLine;
// 亮度滑块
TFSliderView *brightnessSlider;
// 阅读速度滑块
TFSliderView *autoReadSpeedSlider;
// 夜间模式
UIButton *nightModeButton;
TFReaderSettingHelper *functionalManager;
TFButton *directoryButton;
TFButton *brightnessButton;
TFButton *fontSetButton;
#if TF_Comments_Mode
TFButton *commentButton;
#endif
}
@end
@implementation WXYZ_BookReaderBottomBar
- (instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
[self initialize];
[self createSubViews];
}
return self;
}
- (void)initialize
{
self.backgroundColor = [UIColor whiteColor];
functionalManager = [TFReaderSettingHelper sharedManager];
}
- (void)createSubViews
{
UIImageView *topLine = [[UIImageView alloc] initWithFrame:CGRectMake(0, - 10, self.width, 10)];
topLine.image = [UIImage imageNamed:@"tapbar_top_line"];
topLine.userInteractionEnabled = YES;
[self addSubview:topLine];
menuView = [[UIView alloc] init];
menuView.backgroundColor = [UIColor whiteColor];
[self addSubview:menuView];
[menuView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.bottom.mas_equalTo(self.mas_bottom).offset(- PUB_TABBAR_OFFSET);
make.width.mas_equalTo(SCREEN_WIDTH);
make.height.mas_equalTo(ToolBar_Normal_Height - PUB_TABBAR_OFFSET);
}];
#pragma mark - 目录按钮
directoryButton = [[TFButton alloc] initWithFrame:CGRectZero buttonTitle:TFLocalizedString(@"目录") buttonImageName:@"book_menu_directory" buttonIndicator:TFButtonIndicatorTitleBottom];
directoryButton.tag = 0;
directoryButton.graphicDistance = 5;
directoryButton.buttonImageScale = 0.5;
[directoryButton addTarget:self action:@selector(toolBarButtonClick:) forControlEvents:UIControlEventTouchUpInside];
[menuView addSubview:directoryButton];
#pragma mark - 亮度
brightnessButton = [[TFButton alloc] initWithFrame:CGRectZero buttonTitle:TFLocalizedString(@"亮度") buttonImageName:@"book_menu_brightness_higher" buttonIndicator:TFButtonIndicatorTitleBottom];
brightnessButton.tag = 1;
brightnessButton.graphicDistance = 5;
brightnessButton.buttonImageScale = 0.5;
[brightnessButton addTarget:self action:@selector(toolBarButtonClick:) forControlEvents:UIControlEventTouchUpInside];
[menuView addSubview:brightnessButton];
#pragma mark - 字体设置
fontSetButton = [[TFButton alloc] initWithFrame:CGRectZero buttonTitle:TFLocalizedString(@"设置") buttonImageName:@"book_menu_setting" buttonIndicator:TFButtonIndicatorTitleBottom];
fontSetButton.tag = 2;
fontSetButton.graphicDistance = 5.5;
fontSetButton.buttonImageScale = 0.45;
[fontSetButton addTarget:self action:@selector(toolBarButtonClick:) forControlEvents:UIControlEventTouchUpInside];
[menuView addSubview:fontSetButton];
#pragma mark - 评论
#if TF_Comments_Mode
commentButton = [[TFButton alloc] initWithFrame:CGRectZero buttonTitle:TFLocalizedString(@"评论") buttonImageName:@"book_menu_comment_icon" buttonIndicator:TFButtonIndicatorTitleBottom];
commentButton.tag = 3;
commentButton.graphicDistance = 5;
commentButton.buttonImageScale = 0.45;
[commentButton addTarget:self action:@selector(toolBarButtonClick:) forControlEvents:UIControlEventTouchUpInside];
[menuView addSubview:commentButton];
#endif
NSArray *buttonMenuArr = [NSArray arrayWithObjects:directoryButton, brightnessButton, fontSetButton,
#if TF_Comments_Mode
commentButton,
#endif
nil];
[buttonMenuArr mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedItemLength:(SCREEN_WIDTH / buttonMenuArr.count) leadSpacing:0 tailSpacing:0];
[buttonMenuArr mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(8);
make.height.mas_equalTo(menuView.mas_height).with.offset(- 16);
}];
#pragma mark - 亮度调节按钮
brightnessSlider = [[TFSliderView alloc] initWithFrame:CGRectMake(kMargin, kMargin, SCREEN_WIDTH - 2 * kMargin, ToolBar_Normal_Height - 2 * kMargin - PUB_TABBAR_OFFSET) sliderCutPointCount:1];
brightnessSlider.minimumValue = 0.01;
brightnessSlider.tag = 0;
brightnessSlider.hidden = YES;
brightnessSlider.sliderValue = [functionalManager getBrightness];
brightnessSlider.delegate = self;
brightnessSlider.minimumTintColor = kMainColor;
brightnessSlider.leftImageName = @"book_menu_brightness_lower";
brightnessSlider.rightImageName = @"book_menu_brightness_higher";
[self addSubview:brightnessSlider];
#pragma mark - 菜单栏设置背景
settingBackView = [[WXYZ_BookReaderBottomSettingBar alloc] initWithFrame:CGRectMake(0, 0, self.width, ToolBarSettingView_Height)];
settingBackView.hidden = YES;
[self addSubview:settingBackView];
#pragma mark - 自动阅读按钮
autoReadButton = [[TFButton alloc] initWithFrame:CGRectZero buttonTitle:TFLocalizedString(@"开启自动阅读") buttonImageName:@"book_menu_auto_read_icon" buttonIndicator:TFButtonIndicatorTitleRight];
autoReadButton.graphicDistance = 0;
autoReadButton.buttonImageScale = 0.4;
autoReadButton.hidden = YES;
autoReadButton.buttonTintColor = kBlackColor;
[autoReadButton addTarget:self action:@selector(autoReadButtonClick) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:autoReadButton];
[autoReadButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.mas_equalTo(self.mas_bottom).with.offset(- PUB_TABBAR_OFFSET);
make.centerX.mas_equalTo(settingBackView.mas_centerX);
make.width.mas_equalTo(SCREEN_WIDTH);
make.height.mas_equalTo(45);
}];
// 横线
grayLine = [[UIView alloc] init];
grayLine.hidden = YES;
grayLine.backgroundColor = kColorRGBA(247, 247, 247, 1);
[self addSubview:grayLine];
[grayLine mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(0);
make.bottom.mas_equalTo(autoReadButton.mas_top);
make.width.mas_equalTo(SCREEN_WIDTH);
make.height.mas_equalTo(5);
}];
#pragma mark - 阅读速度调节
autoReadSpeedSlider = [[TFSliderView alloc] initWithFrame:CGRectMake(kMargin, kHalfMargin, SCREEN_WIDTH - 2 * kMargin, 30) sliderCutPointCount:10];
autoReadSpeedSlider.tag = 1;
autoReadSpeedSlider.hidden = YES;
autoReadSpeedSlider.stepSlider = YES;
autoReadSpeedSlider.delegate = self;
autoReadSpeedSlider.invertedValue = YES;
autoReadSpeedSlider.sliderValue = 10 - [functionalManager getReadSpeed] / 5;
autoReadSpeedSlider.leftImageName = @"book_menu_auto_read_slow";
autoReadSpeedSlider.rightImageName = @"book_menu_auto_read_fast";
[self addSubview:autoReadSpeedSlider];
nightModeButton = [UIButton buttonWithType:UIButtonTypeCustom];
nightModeButton.tag = 10000;
nightModeButton.adjustsImageWhenHighlighted = NO;
nightModeButton.contentVerticalAlignment = UIControlContentVerticalAlignmentFill;
nightModeButton.contentHorizontalAlignment = UIControlContentVerticalAlignmentFill;
if ([functionalManager getNightModeState] == TFReaderPatternModeNight) {
[nightModeButton setImage:[UIImage imageNamed:@"book_menu_reader_night"] forState:UIControlStateNormal];
} else {
[nightModeButton setImage:[UIImage imageNamed:@"book_menu_reader_day"] forState:UIControlStateNormal];
}
[nightModeButton addTarget:self action:@selector(nightModeClick:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:nightModeButton];
[nightModeButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.height.mas_equalTo(40);
make.right.mas_equalTo(self.mas_right).with.offset(- kMargin);
make.bottom.mas_equalTo(menuView.mas_top).with.offset(- kMargin);
}];
}
- (void)reloadTabbar
{
[self removeAllSubviews];
[self createSubViews];
}
// 菜单栏按钮点击
- (void)toolBarButtonClick:(UIButton *)sender
{
switch (sender.tag) {
case 0:// 目录
[[NSNotificationCenter defaultCenter] postNotificationName:NSNotification_Reader_Push object:@"WXBookDirectoryViewController"];
[self hiddenToolBar];
break;
case 1:// 亮度
brightnessSlider.hidden = NO;
break;
case 2:// 设置
settingBackView.hidden = NO;
[self showLargeToolBar];
break;
case 3:// 评论
[[NSNotificationCenter defaultCenter] postNotificationName:NSNotification_Reader_Push object:@"TFCommentsViewController"];
[self hiddenToolBar];
break;
default:
break;
}
[self hiddenMenuView];
}
// 显示底部菜单按钮
- (void)showMenuView
{
menuView.hidden = NO;
}
// 隐藏底部菜单按钮
- (void)hiddenMenuView
{
[self hiddenNavBar];
menuView.hidden = YES;
}
// 夜间模式
- (void)nightModeClick:(UIButton *)sender
{
if ([functionalManager getNightModeState] == TFReaderPatternModeNight) {
[functionalManager setNightModeState:TFReaderPatternModeDaytime];
[sender setImage:[UIImage imageNamed:@"book_menu_reader_day"] forState:UIControlStateNormal];
} else {
[functionalManager setNightModeState:TFReaderPatternModeNight];
[sender setImage:[UIImage imageNamed:@"book_menu_reader_night"] forState:UIControlStateNormal];
}
[[WXYZ_BookReaderMenuBar sharedManager] hiddend];
}
// 隐藏导航栏
- (void)hiddenNavBar
{
[[NSNotificationCenter defaultCenter] postNotificationName:NSNotification_Hidden_ToolNav object:nil];
}
// 显示工具栏
- (void)showToolBar
{
self.hidden = NO;
menuView.hidden = NO;
if ([functionalManager getNightModeState] == TFReaderPatternModeNight) {
[nightModeButton setImage:[UIImage imageNamed:@"book_menu_reader_night"] forState:UIControlStateNormal];
} else {
[nightModeButton setImage:[UIImage imageNamed:@"book_menu_reader_day"] forState:UIControlStateNormal];
}
[UIView animateWithDuration:animateDuration animations:^{
self.frame = CGRectMake(0, SCREEN_HEIGHT - ToolBar_Normal_Height, SCREEN_WIDTH, ToolBar_Normal_Height);
self->nightModeButton.alpha = 1;
} completion:^(BOOL finished) {
}];
autoReadButton.buttonTitle = TFLocalizedString(@"开启自动阅读");
[autoReadButton setNeedsLayout];
[autoReadButton layoutIfNeeded];
directoryButton.buttonTitle = TFLocalizedString(@"目录");
brightnessButton.buttonTitle = TFLocalizedString(@"亮度");
fontSetButton.buttonTitle = TFLocalizedString(@"设置");
commentButton.buttonTitle = TFLocalizedString(@"评论");
}
// 显示自动阅读栏
- (void)showAutoReadToolBar
{
nightModeButton.alpha = 0;
self.hidden = NO;
[UIView animateWithDuration:animateDuration animations:^{
self.frame = CGRectMake(0, SCREEN_HEIGHT - ToolBarAutoReadView_Height, SCREEN_WIDTH, ToolBarAutoReadView_Height);
} completion:^(BOOL finished) {
self->autoReadButton.hidden = NO;
self->autoReadSpeedSlider.hidden = NO;
self->settingBackView.hidden = YES;
self->grayLine.hidden = NO;
}];
}
// 显示多选工具栏
- (void)showLargeToolBar
{
nightModeButton.alpha = 0;
[UIView animateWithDuration:animateDuration animations:^{
self.frame = CGRectMake(0, SCREEN_HEIGHT - ToolBar_Large_Height, SCREEN_WIDTH, ToolBar_Large_Height);
} completion:^(BOOL finished) {
self->grayLine.hidden = NO;
self->autoReadButton.hidden = NO;
}];
}
// 隐藏工具栏
- (void)hiddenToolBar
{
brightnessSlider.hidden = YES;
settingBackView.hidden = YES;
grayLine.hidden = YES;
autoReadButton.hidden = YES;
autoReadSpeedSlider.hidden = YES;
if (_autoReading && functionalManager.state == TFReaderAutoReadStatePause) {
[functionalManager setAutoReaderState:TFReaderAutoReadStateResume];
}
[UIView animateWithDuration:animateDuration animations:^{
self.frame = CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, ToolBar_Normal_Height);
self->nightModeButton.alpha = 0;
} completion:^(BOOL finished) {
self.hidden = YES;
}];
}
#pragma mark - 按钮点击事件
- (void)sliderValueEndChanged:(CGFloat)endValue slider:(TFSliderView *)sender
{
// 设置亮度
if (sender.tag == 0) {
[functionalManager setBrightness:endValue];
} else {// 设置阅读速度
[functionalManager setReadSpeed:(NSInteger)((endValue + 1) * 5)];
}
}
// 关闭自动阅读
- (void)stopAutoRead
{
if (_autoReading) {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusSuccess promptTitle:TFLocalizedString(@"自动阅读已关闭")];
}
_autoReading = NO;
[functionalManager setAutoReaderState:TFReaderAutoReadStateStop];
autoReadButton.buttonImageName = @"book_menu_auto_read_icon";
autoReadButton.buttonTitle = TFLocalizedString(@"开启自动阅读");
autoReadButton.buttonTintColor = kBlackColor;
[self hiddenToolBar];
[self hiddenNavBar];
[[WXYZ_BookReaderMenuBar sharedManager] hiddend];
}
// 自动阅读
- (void)autoReadButtonClick
{
if (_autoReading) {
[self stopAutoRead];
} else {
_autoReading = YES;
autoReadButton.buttonImageName = @"book_menu_auto_read_exit";
autoReadButton.buttonTitle = TFLocalizedString(@"关闭自动阅读");
autoReadButton.buttonTintColor = [UIColor colorWithRed: 241.0/255.0 green: 83.0/255.0 blue: 29.0/255.0 alpha: 1.0];
[functionalManager setAutoReaderState:TFReaderAutoReadStateStart];
[self hiddenToolBar];
[self hiddenNavBar];
[[WXYZ_BookReaderMenuBar sharedManager] hiddend];
}
}
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
UIView *view = [super hitTest:point withEvent:event];
if (view == nil) {
// 超出父视图的按钮tag值为10000
CGPoint tempoint = [[self viewWithTag:10000] convertPoint:point fromView:self];
if (CGRectContainsPoint([self viewWithTag:10000].bounds, tempoint)) {
view = [self viewWithTag:10000];
}
}
return view;
}
@end
@@ -0,0 +1,13 @@
//
// WXYZ_BookReaderBottomSettingBar.h
// WXReader
//
// Created by Andrew on 2018/6/12.
// Copyright © 2018年 Andrew. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface WXYZ_BookReaderBottomSettingBar : UIView
@end
@@ -0,0 +1,522 @@
//
// WXYZ_BookReaderBottomSettingBar.m
// TFReader
//
// Created by Andrew on 2018/6/12.
// Copyright © 2018年 Andrew. All rights reserved.
//
#import "WXYZ_BookReaderBottomSettingBar.h"
#import "TFReaderSettingHelper.h"
#define ToolBarSettingView_Height ((50 * 4) + kHalfMargin)
@implementation WXYZ_BookReaderBottomSettingBar
{
// 字号显示
UILabel *fontSizeLabel;
UIButton *decreaseFontBtn;
UIButton *increaseFontBtn;
TFReaderSettingHelper *functionalManager;
UIScrollView *backgroundScorll;
}
- (instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
self.backgroundColor = [UIColor whiteColor];
functionalManager = [TFReaderSettingHelper sharedManager];
[self createSubViews];
}
return self;
}
- (void)createSubViews
{
CGFloat titleHeight = 50;
CGFloat titleWidth = 50;
CGFloat factoryButtonWidth = (SCREEN_WIDTH - titleWidth - 6 * kHalfMargin) / 4;
CGFloat factoryButtonHeight = 30;
#pragma mark - 字号
UILabel *fontTitle = [[UILabel alloc] init];
fontTitle.text = TFLocalizedString(@"字号");
fontTitle.textAlignment = NSTextAlignmentCenter;
fontTitle.textColor = kGrayTextColor;
fontTitle.font = kFont13;
[self addSubview:fontTitle];
[fontTitle mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.mas_left).with.offset(kHalfMargin);
make.top.mas_equalTo(self.mas_top).with.offset(kHalfMargin);
make.width.mas_equalTo(titleWidth);
make.height.mas_equalTo(titleHeight);
}];
#pragma mark - 字号减小
decreaseFontBtn = [self factorySettingButtonWithBackViewImageName:@"book_menu_font_sub" buttonTitle:nil tag:0 fitImageView:YES];
decreaseFontBtn.adjustsImageWhenHighlighted = NO;
[decreaseFontBtn addTarget:self action:@selector(fontSizeChangeClick:) forControlEvents:UIControlEventTouchUpInside];
[decreaseFontBtn addTarget:self action:@selector(fontSizeChangeHighlighted:) forControlEvents:UIControlEventTouchDown];
[self addSubview:decreaseFontBtn];
[decreaseFontBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(fontTitle.mas_right).with.offset(kHalfMargin);
make.centerY.mas_equalTo(fontTitle.mas_centerY);
make.width.mas_equalTo(factoryButtonWidth);
make.height.mas_equalTo(factoryButtonHeight);
}];
#pragma mark - 字号增加
increaseFontBtn = [self factorySettingButtonWithBackViewImageName:@"book_menu_font_add" buttonTitle:nil tag:1 fitImageView:YES];
increaseFontBtn.adjustsImageWhenHighlighted = NO;
[increaseFontBtn addTarget:self action:@selector(fontSizeChangeClick:) forControlEvents:UIControlEventTouchUpInside];
[increaseFontBtn addTarget:self action:@selector(fontSizeChangeHighlighted:) forControlEvents:UIControlEventTouchDown];
[self addSubview:increaseFontBtn];
[increaseFontBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(self.mas_right).with.offset(- kMargin);
make.centerY.mas_equalTo(decreaseFontBtn.mas_centerY);
make.width.mas_equalTo(decreaseFontBtn.mas_width);
make.height.mas_equalTo(decreaseFontBtn.mas_height);
}];
if ([functionalManager getReaderFontSize] == [functionalManager getReaderMinFontSize]) {
decreaseFontBtn.imageView.tintColor = kGrayTextColor;
} else if ([functionalManager getReaderFontSize] == [functionalManager getReaderMaxFontSize]) {
increaseFontBtn.imageView.tintColor = kGrayTextColor;
}
#pragma mark - 显示字号
fontSizeLabel = [[UILabel alloc] init];
fontSizeLabel.textAlignment = NSTextAlignmentCenter;
fontSizeLabel.font = kFont15;
fontSizeLabel.text = [NSString stringWithFormat:@"%.lf",[functionalManager getReaderFontSize]];
fontSizeLabel.textColor = kBlackColor;
[self addSubview:fontSizeLabel];
[fontSizeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(decreaseFontBtn.mas_right);
make.right.mas_equalTo(increaseFontBtn.mas_left);
make.centerY.mas_equalTo(decreaseFontBtn.mas_centerY);
make.height.mas_equalTo(decreaseFontBtn.mas_height);
}];
#pragma mark - 字体间距
UILabel *spaceLineTitle = [[UILabel alloc] init];
spaceLineTitle.text = TFLocalizedString(@"间距");
spaceLineTitle.textAlignment = NSTextAlignmentCenter;
spaceLineTitle.textColor = kGrayTextColor;
spaceLineTitle.font = kFont13;
[self addSubview:spaceLineTitle];
[spaceLineTitle mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.mas_left).with.offset(kHalfMargin);
make.top.mas_equalTo(fontTitle.mas_bottom);
make.width.mas_equalTo(titleWidth);
make.height.mas_equalTo(titleHeight);
}];
#pragma mark - 字体间距大
UIButton *lineSpacingSmall = [self factorySettingButtonWithBackViewImageName:@"book_menu_line_spacing_big" buttonTitle:nil tag:10 fitImageView:YES];
[lineSpacingSmall addTarget:self action:@selector(lineSpacingChangeClick:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:lineSpacingSmall];
[lineSpacingSmall mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(decreaseFontBtn.mas_left);
make.centerY.mas_equalTo(spaceLineTitle.mas_centerY);
make.width.mas_equalTo(decreaseFontBtn.mas_width);
make.height.mas_equalTo(decreaseFontBtn.mas_height);
}];
#pragma mark - 字体间距中
UIButton *lineSpacingMedium = [self factorySettingButtonWithBackViewImageName:@"book_menu_line_spacing_medium" buttonTitle:nil tag:11 fitImageView:YES];
[lineSpacingMedium addTarget:self action:@selector(lineSpacingChangeClick:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:lineSpacingMedium];
[lineSpacingMedium mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(fontSizeLabel.mas_centerX);
make.centerY.mas_equalTo(spaceLineTitle.mas_centerY);
make.width.mas_equalTo(decreaseFontBtn.mas_width);
make.height.mas_equalTo(decreaseFontBtn.mas_height);
}];
#pragma mark - 字体间距小
UIButton *lineSpacingBig = [self factorySettingButtonWithBackViewImageName:@"book_menu_line_spacing_small" buttonTitle:nil tag:12 fitImageView:YES];
[lineSpacingBig addTarget:self action:@selector(lineSpacingChangeClick:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:lineSpacingBig];
[lineSpacingBig mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(self.mas_right).with.offset(- kMargin);
make.centerY.mas_equalTo(spaceLineTitle.mas_centerY);
make.width.mas_equalTo(decreaseFontBtn.mas_width);
make.height.mas_equalTo(decreaseFontBtn.mas_height);
}];
CGFloat t_lineSpacing = [functionalManager getReaderLinesSpacing];
if (t_lineSpacing == line_spacing_small) {
lineSpacingSmall.backgroundColor = kMainColor;
lineSpacingSmall.imageView.tintColor = kWhiteColor;
} else if (t_lineSpacing == line_spacing_medium) {
lineSpacingMedium.backgroundColor = kMainColor;
lineSpacingMedium.imageView.tintColor = kWhiteColor;
} else {
lineSpacingBig.backgroundColor = kMainColor;
lineSpacingBig.imageView.tintColor = kWhiteColor;
}
#pragma mark - 翻页
UILabel *pageTitle = [[UILabel alloc] init];
pageTitle.text = TFLocalizedString(@"翻页");
pageTitle.textAlignment = NSTextAlignmentCenter;
pageTitle.textColor = kGrayTextColor;
pageTitle.font = kFont13;
[self addSubview:pageTitle];
[pageTitle mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.mas_left).with.offset(kHalfMargin);
make.top.mas_equalTo(spaceLineTitle.mas_bottom);
make.width.mas_equalTo(titleWidth);
make.height.mas_equalTo(titleHeight);
}];
#pragma mark - 仿真
UIButton *pageCurlButton = [self factorySettingButtonWithBackViewImageName:nil buttonTitle:TFLocalizedString(@"仿真") tag:100 fitImageView:YES];
[pageCurlButton addTarget:self action:@selector(transitionStyleChangeClick:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:pageCurlButton];
[pageCurlButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(decreaseFontBtn.mas_left);
make.centerY.mas_equalTo(pageTitle.mas_centerY);
make.width.mas_equalTo(decreaseFontBtn.mas_width);
make.height.mas_equalTo(decreaseFontBtn.mas_height);
}];
#pragma mark - 滚动
UIButton *scrollButton = [self factorySettingButtonWithBackViewImageName:nil buttonTitle:TFLocalizedString(@"滑动") tag:101 fitImageView:YES];
[scrollButton addTarget:self action:@selector(transitionStyleChangeClick:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:scrollButton];
[scrollButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(pageCurlButton.mas_right).with.offset(7);
make.centerY.mas_equalTo(pageTitle.mas_centerY);
make.width.mas_equalTo(decreaseFontBtn.mas_width);
make.height.mas_equalTo(decreaseFontBtn.mas_height);
}];
#pragma mark - 覆盖
UIButton *coverButton = [self factorySettingButtonWithBackViewImageName:nil buttonTitle:TFLocalizedString(@"覆盖") tag:102 fitImageView:YES];
[coverButton addTarget:self action:@selector(transitionStyleChangeClick:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:coverButton];
[coverButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(scrollButton.mas_right).with.offset(7);
make.centerY.mas_equalTo(pageTitle.mas_centerY);
make.width.mas_equalTo(decreaseFontBtn.mas_width);
make.height.mas_equalTo(decreaseFontBtn.mas_height);
}];
#pragma mark - 无效果
UIButton *noneButton = [self factorySettingButtonWithBackViewImageName:nil buttonTitle:TFLocalizedString(@"") tag:103 fitImageView:YES];
[noneButton addTarget:self action:@selector(transitionStyleChangeClick:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:noneButton];
[noneButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(coverButton.mas_right).with.offset(7);
make.centerY.mas_equalTo(pageTitle.mas_centerY);
make.width.mas_equalTo(decreaseFontBtn.mas_width);
make.height.mas_equalTo(decreaseFontBtn.mas_height);
}];
switch ([functionalManager getTransitionStyle]) {
case TFReaderTransitionStylePageCurl:
pageCurlButton.selected = YES;
pageCurlButton.backgroundColor = kMainColor;
break;
case TFReaderTransitionStyleScroll:
scrollButton.selected = YES;
scrollButton.backgroundColor = kMainColor;
break;
case TFReaderTransitionStyleCover:
coverButton.selected = YES;
coverButton.backgroundColor = kMainColor;
break;
case TFReaderTransitionStyleNone:
noneButton.selected = YES;
noneButton.backgroundColor = kMainColor;
break;
default:
break;
}
#pragma mark - 背景
UILabel *backViewTitle = [[UILabel alloc] init];
backViewTitle.text = TFLocalizedString(@"背景");
backViewTitle.textAlignment = NSTextAlignmentCenter;
backViewTitle.textColor = kGrayTextColor;
backViewTitle.font = kFont13;
[self addSubview:backViewTitle];
[backViewTitle mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.mas_left).with.offset(kHalfMargin);
make.top.mas_equalTo(pageTitle.mas_bottom);
make.width.mas_equalTo(titleWidth);
make.height.mas_equalTo(titleHeight);
}];
#pragma mark - 背景滚动
backgroundScorll = [[UIScrollView alloc] init];
backgroundScorll.backgroundColor = kWhiteColor;
backgroundScorll.showsVerticalScrollIndicator = NO;
backgroundScorll.showsHorizontalScrollIndicator = NO;
[self addSubview:backgroundScorll];
[backgroundScorll mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(decreaseFontBtn.mas_left);
make.right.mas_equalTo(self.mas_right).with.offset(- kMargin);
make.centerY.mas_equalTo(backViewTitle.mas_centerY);
make.height.mas_equalTo(backViewTitle.mas_height);
}];
[backgroundScorll setNeedsLayout];
[backgroundScorll layoutIfNeeded];
NSMutableArray *backgroundImageArr = [[functionalManager getReaderBackgroundColorModeArray] mutableCopy];
[backgroundImageArr removeLastObject];
NSUInteger buttonNum = backgroundImageArr.count;//每行多少按钮
CGFloat button_W = factoryButtonHeight + 5; //按钮宽
CGFloat button_H = factoryButtonHeight + 5; //按钮高
CGFloat space_X = (CGRectGetWidth(backgroundScorll.bounds) - (button_W * buttonNum)) / (buttonNum - 1);// 按钮间距
for (int i = 0; i < backgroundImageArr.count; i++) {
int loc = i % buttonNum;//列号
CGFloat button_X = (space_X + button_W) * loc;
UIButton *button = [self factorySettingButtonWithBackViewImageName:@"" buttonTitle:nil tag:i fitImageView:NO];
button.tintColor = kMainColor;
button.layer.contents = (id)[UIImage imageNamed:[[functionalManager getReaderBackgroundColorModeArray] objectAtIndex:i]].CGImage;
button.layer.cornerRadius = 4;
button.clipsToBounds = YES;
button.tag = i;
button.contentVerticalAlignment = UIControlContentVerticalAlignmentFill;
button.contentHorizontalAlignment = UIControlContentVerticalAlignmentFill;
[button setImageEdgeInsets:UIEdgeInsetsMake(factoryButtonHeight * 0.5, factoryButtonHeight * 0.5, 0, 0)];
[button addTarget:self action:@selector(changeBackgroundImageClick:) forControlEvents:UIControlEventTouchUpInside];
[backgroundScorll addSubview:button];
[button mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(button_X);
make.centerY.mas_equalTo(backgroundScorll.mas_centerY);
make.width.mas_equalTo(button_W);
make.height.mas_equalTo(button_H);
}];
if (i == TFReaderBackColorWhite) {
button.layer.borderColor = kColorRGBA(235, 235, 241, 1).CGColor;
button.layer.borderWidth = 0.8;
}
if ([functionalManager getReaderBackgroundColorMode] == i) {
[button setImage:[[UIImage imageNamed:@"book_setting_select"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
}
}
backgroundScorll.contentSize = CGSizeMake((button_W + kHalfMargin) * backgroundImageArr.count, 0);
[[NSNotificationCenter defaultCenter] addObserverForName:Notification_Switch_Language object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * _Nonnull note) {
fontTitle.text = TFLocalizedString(@"字号");
spaceLineTitle.text = TFLocalizedString(@"间距");
pageTitle.text = TFLocalizedString(@"翻页");
pageCurlButton.titleLabel.text = TFLocalizedString(@"仿真");
[pageCurlButton setTitle:TFLocalizedString(@"仿真") forState:UIControlStateNormal];
scrollButton.titleLabel.text = TFLocalizedString(@"滑动");
[scrollButton setTitle:TFLocalizedString(@"滑动") forState:UIControlStateNormal];
coverButton.titleLabel.text = TFLocalizedString(@"覆盖");
[coverButton setTitle:TFLocalizedString(@"覆盖") forState:UIControlStateNormal];
noneButton.titleLabel.text = TFLocalizedString(@"");
[noneButton setTitle:TFLocalizedString(@"") forState:UIControlStateNormal];
backViewTitle.text = TFLocalizedString(@"背景");
}];
}
#pragma mark - 点击事件
// 改变字号
- (void)fontSizeChangeClick:(UIButton *)sender
{
sender.backgroundColor = kColorRGBA(235, 235, 241, 1);
sender.imageView.tintColor = kBlackColor;
CGFloat temp_font = [functionalManager getReaderFontSize];
if (sender.tag == 0) {
if (temp_font == [functionalManager getReaderMinFontSize]) {
sender.imageView.tintColor = kGrayTextColor;
return;
}
[functionalManager setReaderFontSize:temp_font - 1];
fontSizeLabel.text = [NSString stringWithFormat:@"%.lf",[functionalManager getReaderFontSize]];
} else {
if (temp_font == [functionalManager getReaderMaxFontSize]) {
sender.imageView.tintColor = kGrayTextColor;
return;
}
[functionalManager setReaderFontSize:temp_font + 1];
fontSizeLabel.text = [NSString stringWithFormat:@"%.lf",[functionalManager getReaderFontSize]];
}
if ([functionalManager getReaderFontSize] == [functionalManager getReaderMinFontSize]) {
decreaseFontBtn.imageView.tintColor = kGrayTextColor;
} else if ([functionalManager getReaderFontSize] == [functionalManager getReaderMaxFontSize]) {
increaseFontBtn.imageView.tintColor = kGrayTextColor;
} else {
decreaseFontBtn.imageView.tintColor = kBlackColor;
increaseFontBtn.imageView.tintColor = kBlackColor;
}
}
- (void)fontSizeChangeHighlighted:(UIButton *)sender
{
if (sender.tag == 0 && [functionalManager getReaderFontSize] == [functionalManager getReaderMinFontSize]) {
return;
}
if (sender.tag == 1 && [functionalManager getReaderFontSize] == [functionalManager getReaderMaxFontSize]) {
return;
}
sender.backgroundColor = kMainColor;
sender.imageView.tintColor = kWhiteColor;
}
// 改变背景色
- (void)changeBackgroundImageClick:(UIButton *)sender
{
[backgroundScorll.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if ([obj isKindOfClass:[UIButton class]]) {
UIButton *t_btn = (UIButton *)obj;
[t_btn setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
}
}];
[sender setImage:[[UIImage imageNamed:@"book_setting_select"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
[functionalManager setNightModeState:TFReaderPatternModeDaytime];
[functionalManager setReaderBackgroundColor:sender.tag];
}
// 设置翻页类型
- (void)transitionStyleChangeClick:(UIButton *)sender
{
for (UIView *t_view in self.subviews) {
if ([t_view isKindOfClass:[UIButton class]] && (t_view.tag == 100 || t_view.tag == 101 || t_view.tag == 102 || t_view.tag == 103)) {
UIButton *t_button = (UIButton *)t_view;
t_button.backgroundColor = kColorRGBA(235, 235, 241, 1);
t_button.selected = NO;
}
}
switch (sender.tag) {
case 100:
[functionalManager setTransitionStyle:TFReaderTransitionStylePageCurl];
break;
case 101:
[functionalManager setTransitionStyle:TFReaderTransitionStyleScroll];
break;
case 102:
[functionalManager setTransitionStyle:TFReaderTransitionStyleCover];
break;
case 103:
[functionalManager setTransitionStyle:TFReaderTransitionStyleNone];
break;
default:
break;
}
sender.selected = YES;
sender.backgroundColor = kMainColor;
}
// 设置字间距
- (void)lineSpacingChangeClick:(UIButton *)sender
{
for (UIView *t_view in self.subviews) {
if ([t_view isKindOfClass:[UIButton class]] && (t_view.tag == 10 || t_view.tag == 11 || t_view.tag == 12)) {
UIButton *t_button = (UIButton *)t_view;
t_button.backgroundColor = kColorRGBA(235, 235, 241, 1);
t_button.imageView.tintColor = kBlackColor;
}
}
switch (sender.tag) {
case 10:
[functionalManager setReaderLinesSpacing:line_spacing_small];
break;
case 11:
[functionalManager setReaderLinesSpacing:line_spacing_medium];
break;
case 12:
[functionalManager setReaderLinesSpacing:line_spacing_big];
break;
default:
break;
}
sender.imageView.tintColor = kWhiteColor;
sender.backgroundColor = kMainColor;
}
- (UIButton *)factorySettingButtonWithBackViewImageName:(NSString *)imageName buttonTitle:(NSString *)title tag:(NSInteger)tag fitImageView:(BOOL)fitImage
{
UIButton *t_factory = [UIButton buttonWithType:UIButtonTypeCustom];
t_factory.backgroundColor = kColorRGBA(235, 235, 241, 1);
t_factory.layer.cornerRadius = 2;
t_factory.tag = tag;
[t_factory.titleLabel setTextAlignment:NSTextAlignmentCenter];
if (title.length > 0) {
t_factory.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
[t_factory setTitle:title forState:0];
[t_factory.titleLabel setFont:kMainFont];
[t_factory setTitleColor:kBlackColor forState:UIControlStateNormal];
[t_factory setTitleColor:kWhiteColor forState:UIControlStateSelected];
} else {
if (imageName.length > 0) {
t_factory.imageView.tintColor = kBlackColor;
t_factory.contentVerticalAlignment = UIControlContentVerticalAlignmentFill;
t_factory.contentHorizontalAlignment = UIControlContentVerticalAlignmentFill;
[t_factory setImage:[[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
[t_factory setImage:[[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateHighlighted];
}
if (fitImage) {
t_factory.imageView.contentMode = UIViewContentModeScaleAspectFit;
} else {
t_factory.imageView.tintColor = kMainColor;
}
}
return t_factory;
}
- (void)setHidden:(BOOL)hidden {
[super setHidden:hidden];
if (!hidden) {
[backgroundScorll.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if ([obj isKindOfClass:[UIButton class]]) {
UIButton *t_btn = (UIButton *)obj;
if ([functionalManager getReaderBackgroundColorMode] == t_btn.tag) {
[t_btn setImage:[UIImage imageNamed:@"book_setting_select"] forState:UIControlStateNormal];
} else {
[t_btn setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
}
}
}];
}
}
@end
@@ -0,0 +1,21 @@
//
// WXBookReaderToolBar.h
// WXReader
//
// Created by Andrew on 2018/5/30.
// Copyright © 2018年 Andrew. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface WXYZ_BookReaderMenuBar : UIView
interface_singleton
- (void)hiddend;
- (void)show;
- (void)stopAutoRead;
@end
@@ -0,0 +1,131 @@
//
// WXBookReaderToolBar.m
// TFReader
//
// Created by Andrew on 2018/5/30.
// Copyright © 2018年 Andrew. All rights reserved.
//
#import "WXYZ_BookReaderMenuBar.h"
#import "TFReaderSettingHelper.h"
#import "WXYZ_BookReaderTopBar.h"
#import "WXYZ_BookReaderBottomBar.h"
#if TF_Enable_Ai
#import "WXYZ_TouchAssistantView.h"
#endif
#define ToolBar_Normal_Height (60 + PUB_TABBAR_OFFSET)
@interface WXYZ_BookReaderMenuBar ()
{
// 导航条
WXYZ_BookReaderTopBar *navBar;
// 工具条
WXYZ_BookReaderBottomBar *toolBar;
TFReaderSettingHelper *functionalManager;
}
@end
@implementation WXYZ_BookReaderMenuBar
implementation_singleton(WXYZ_BookReaderMenuBar)
- (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];
[kMainWindow addSubview:self];
self.hidden = YES;
functionalManager = [TFReaderSettingHelper sharedManager];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(hiddend) name:NSNotification_Hidden_Bottom_ToolNav object:nil];
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint toolBarPoint = [toolBar.layer convertPoint:[touch locationInView:self] fromLayer:self.layer];
CGPoint navBarPoint = [navBar.layer convertPoint:[touch locationInView:self] fromLayer:self.layer];
if (![toolBar.layer containsPoint:toolBarPoint] && ![navBar.layer containsPoint:navBarPoint]) {
[self hiddend];
}
}
- (void)hiddend
{
if (functionalManager.state == TFReaderAutoReadStateStart && self.hidden) {
[self show];
return;
}
[navBar hiddenNavBarCompletion:^{
self.hidden = YES;
}];
[toolBar hiddenToolBar];
#if TF_Enable_Ai
[[WXYZ_TouchAssistantView sharedManager] hiddenAssistiveTouchView];
#endif
}
- (void)show
{
[kMainWindow bringSubviewToFront:self];
self.hidden = NO;
if (!toolBar.autoReading) {
[navBar showNavBarCompletion:^{
}];
[toolBar showToolBar];
} else {
[functionalManager setAutoReaderState:TFReaderAutoReadStatePause];
[navBar hiddenNavBarCompletion:^{
}];
[toolBar showAutoReadToolBar];
}
#if TF_Enable_Ai
[[WXYZ_TouchAssistantView sharedManager] showAssistiveTouchView];
#endif
}
- (void)createSubViews
{
navBar = [[WXYZ_BookReaderTopBar alloc] initWithFrame:CGRectMake(0, - PUB_NAVBAR_HEIGHT, SCREEN_WIDTH, PUB_NAVBAR_HEIGHT)];
[self addSubview:navBar];
toolBar = [[WXYZ_BookReaderBottomBar alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, ToolBar_Normal_Height)];
[self addSubview:toolBar];
}
- (void)stopAutoRead
{
[toolBar stopAutoRead];
}
- (void)popViewContriller
{
[[NSNotificationCenter defaultCenter] postNotificationName:NSNotification_Reader_Back object:nil];
[self stopAutoRead];
}
@end
@@ -0,0 +1,13 @@
//
// WXYZ_BookReaderMenuPayView.h
// WXReader
//
// Created by Andrew on 2018/7/15.
// Copyright © 2018年 Andrew. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface WXYZ_BookReaderMenuPayView : UIView
@end
@@ -0,0 +1,167 @@
//
// WXYZ_BookReaderMenuPayView.m
// WXReader
//
// Created by Andrew on 2018/7/15.
// Copyright © 2018年 Andrew. All rights reserved.
//
#import "WXYZ_BookReaderMenuPayView.h"
#import "TFRechargeViewController.h"
#import "WXYZ_ChapterBottomPayBar.h"
#import "TFReaderSettingHelper.h"
#import "TFReaderBookManager.h"
@interface WXYZ_BookReaderMenuPayView ()
{
TFReaderSettingHelper *functionalManager;
}
@end
@implementation WXYZ_BookReaderMenuPayView
- (instancetype)init
{
if (self = [super init]) {
[self initialize];
[self createSubViews];
}
return self;
}
- (void)initialize
{
self.frame = CGRectMake(0, SCREEN_HEIGHT / 2 - PUB_TABBAR_OFFSET - 2 * kMargin, SCREEN_WIDTH, SCREEN_HEIGHT / 2);
self.backgroundColor = [UIColor clearColor];
functionalManager = [TFReaderSettingHelper sharedManager];
}
- (void)createSubViews
{
UIButton *buyBulkButton = [UIButton buttonWithType:UIButtonTypeCustom];
buyBulkButton.layer.cornerRadius = 4;
buyBulkButton.layer.borderColor = [functionalManager getReaderTextColor].CGColor;
buyBulkButton.layer.borderWidth = 0.7;
buyBulkButton.clipsToBounds = YES;
[buyBulkButton setTitle:TFLocalizedString(@"批量购买更优惠") forState:UIControlStateNormal];
[buyBulkButton setTitleColor:[functionalManager getReaderTextColor] forState:UIControlStateNormal];
[buyBulkButton.titleLabel setFont:kMainFont];
[buyBulkButton addTarget:self action:@selector(buyBulkButtonClick) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:buyBulkButton];
[buyBulkButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.mas_equalTo(self.mas_bottom).with.offset(- 2 * kMargin);
make.left.mas_equalTo(self.mas_left).with.offset(2 * kMargin);
make.right.mas_equalTo(self.mas_right).with.offset(- 2 * kMargin);
make.height.mas_equalTo(40);
}];
UIButton *buyButton = [UIButton buttonWithType:UIButtonTypeCustom];
buyButton.layer.cornerRadius = 4;
buyButton.layer.borderColor = [functionalManager getReaderTextColor].CGColor;
buyButton.layer.borderWidth = 0.7;
buyButton.clipsToBounds = YES;
[buyButton setTitle:TFLocalizedString(@"确定购买") forState:UIControlStateNormal];
[buyButton setTitleColor:[functionalManager getReaderTextColor] forState:UIControlStateNormal];
[buyButton.titleLabel setFont:kMainFont];
[buyButton addTarget:self action:@selector(buyCurrentChapter) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:buyButton];
[buyButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.mas_equalTo(buyBulkButton.mas_top).with.offset(- 15);
make.left.mas_equalTo(buyBulkButton.mas_left);
make.right.mas_equalTo(buyBulkButton.mas_right);
make.height.mas_equalTo(buyBulkButton.mas_height);
}];
UILabel *titleLabel = [[UILabel alloc] init];
titleLabel.text = TFLocalizedString(@"支持正版");
titleLabel.textColor = [functionalManager getReaderTextColor];
titleLabel.backgroundColor = [UIColor clearColor];
titleLabel.font = kFont10;
titleLabel.textAlignment = NSTextAlignmentCenter;
[self addSubview:titleLabel];
[titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self.mas_centerX);
make.bottom.mas_equalTo(buyButton.mas_top).with.offset( - 2 * kMargin);
make.width.mas_equalTo(100);
make.height.mas_equalTo(20);
}];
UIView *leftLine = [[UIView alloc] init];
leftLine.backgroundColor = [functionalManager getReaderTextColor];
[self addSubview:leftLine];
[leftLine mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(titleLabel.mas_centerY);
make.left.mas_equalTo(buyBulkButton.mas_left);
make.right.mas_equalTo(titleLabel.mas_left).with.offset(- kHalfMargin);
make.height.mas_equalTo(kCellLineHeight);
}];
UIView *rightLine = [[UIView alloc] init];
rightLine.backgroundColor = [functionalManager getReaderTextColor];
[self addSubview:rightLine];
[rightLine mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(titleLabel.mas_centerY);
make.left.mas_equalTo(titleLabel.mas_right).with.offset(kHalfMargin);
make.right.mas_equalTo(buyBulkButton.mas_right);
make.height.mas_equalTo(kCellLineHeight);
}];
}
- (void)buyBulkButtonClick
{
TFReaderBookManager *bookManager = [TFReaderBookManager sharedManager];
TFProductionChapterModel *t_model = [[TFProductionChapterModel alloc] init];
t_model.production_id = bookManager.book_id;
t_model.chapter_id = bookManager.chapter_id;
WXYZ_ChapterBottomPayBar *payBar = [[WXYZ_ChapterBottomPayBar alloc] initWithChapterModel:t_model barType:WXYZ_BottomPayBarTypeBuyChapter productionType:TFProductionTypeNovel];
[payBar showBottomPayBar];
}
- (void)buyCurrentChapter
{
if (!TFUserInfoManager.isLogin) {
[TFLoginOptionsViewController presentLoginView:nil];
return;
}
TFReaderBookManager *bookManager = [TFReaderBookManager sharedManager];
TFProductionChapterModel *t_model = [[TFProductionChapterModel alloc] init];
t_model.production_id = bookManager.book_id;
t_model.chapter_id = bookManager.chapter_id;
[TFNetworkTools POST:Book_Buy_Chapter parameters:@{@"book_id":[TFUtilsHelper formatStringWithInteger:bookManager.book_id], @"chapter_id":[TFUtilsHelper formatStringWithInteger:bookManager.chapter_id], @"num":@"1"} model:nil success:^(BOOL isSuccess, id _Nullable t_model, TFNetworkRequestModel * _Nonnull requestModel) {
if (isSuccess) {
NSArray<NSString *> *t_arr = [requestModel.data objectForKey:@"chapter_ids"];
[TFPromptManager showPromptViewWithStatus:TFPromptStatusSuccess promptTitle:TFLocalizedString(@"购买成功")];
NSInteger index = [TFReaderBookManager sharedManager].currentChapterIndex;
[TFReaderBookManager sharedManager].bookModel.chapter_list[index].is_preview = NO;
[[NSNotificationCenter defaultCenter] postNotificationName:NSNotification_Retry_Chapter object:nil];
[[NSNotificationCenter defaultCenter] postNotificationName:Notification_Production_Pay_Success object:t_arr];
} else if (requestModel.code == 802) {
[[NSNotificationCenter defaultCenter] postNotificationName:NSNotification_Reader_Push object:@"TFRechargeViewController"];
} else {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:requestModel.msg];
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
[TFPromptManager showPromptWithError:error defaultText:nil];
}];
}
@end
@@ -0,0 +1,19 @@
//
// WXYZ_BookReaderTopBar.h
// WXReader
//
// Created by Andrew on 2018/6/12.
// Copyright © 2018年 Andrew. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface WXYZ_BookReaderTopBar : UIView
// 显示导航条
- (void)showNavBarCompletion:(void(^)(void))completion;
// 隐藏导航条
- (void)hiddenNavBarCompletion:(void(^)(void))completion;
@end
@@ -0,0 +1,302 @@
//
// WXYZ_BookReaderTopBar.m
// TFReader
//
// Created by Andrew on 2018/6/12.
// Copyright © 2018年 Andrew. All rights reserved.
//
#import "WXYZ_BookReaderTopBar.h"
#import "TFReaderSettingHelper.h"
#import "TFReaderBookManager.h"
#import "TFShareManager.h"
#if TF_Download_Mode
#import "TFNovelDownloadMenuView.h"
#import "TFReaderBookManager.h"
#endif
#if TF_Enable_Ai
#import "WXYZ_BookAiPlayPageViewController.h"
#import "TFAudioPlayViewController.h"
#import "WXYZ_AudioSettingHelper.h"
#endif
#import "TFReadRecordManager.h"
#import "WXYZ_MoreView.h"
#import "WXYZ_GiftView.h"
#import "AppDelegate.h"
@interface WXYZ_BookReaderTopBar ()
@property (nonatomic, assign) BOOL navBarShowing;
@property (nonatomic, strong) NSMutableArray<UIButton *> *buttonMenuArr;
@property (nonatomic, strong) UIButton *radioButton;
@end
@implementation WXYZ_BookReaderTopBar
{
TFReaderSettingHelper *functionalManager;
UIButton *moreButton;
}
- (instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
[self initialize];
[self createSubViews];
}
return self;
}
- (void)initialize
{
self.backgroundColor = [UIColor whiteColor];
functionalManager = [TFReaderSettingHelper sharedManager];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(hiddenNavBar) name:NSNotification_Hidden_ToolNav object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(languageSwitch) name:Notification_Switch_Language object:nil];
}
- (void)languageSwitch {
for (UIView *obj in self.subviews) {
[obj removeFromSuperview];
}
[self createSubViews];
}
- (void)createSubViews
{
UIImageView *bottomLine = [[UIImageView alloc] initWithFrame:CGRectMake(0, PUB_NAVBAR_HEIGHT, self.width, 10)];
bottomLine.userInteractionEnabled = YES;
bottomLine.image = [UIImage imageNamed:@"navbar_bottom_line"];
[self addSubview:bottomLine];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0.0f, PUB_NAVBAR_HEIGHT - 64.0f, 64.0f, 64.0f);
button.backgroundColor = [UIColor clearColor];
button.adjustsImageWhenHighlighted = NO;
[button.titleLabel setFont:kMainFont];
[button setTitleColor:kBlackColor forState:UIControlStateNormal];
[button setImage:[[UIImage imageNamed:@"public_back"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
[button setImageEdgeInsets:UIEdgeInsetsMake(30, 14, 10, 26)];
[button setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
[button setTintColor:kBlackColor];
[button addTarget:self action:@selector(popViewController) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:button];
UIView *menuView = [[UIView alloc] init];
menuView.backgroundColor = [UIColor clearColor];
[self addSubview:menuView];
moreButton = [UIButton buttonWithType:UIButtonTypeCustom];
moreButton.backgroundColor = [UIColor clearColor];
moreButton.tintColor = kBlackColor;
[moreButton.titleLabel setFont:kMainFont];
[moreButton setImage:[[UIImage imageNamed:@"book_more"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
[moreButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
[moreButton addTarget:self action:@selector(moreEvent) forControlEvents:UIControlEventTouchUpInside];
moreButton.imageEdgeInsets = UIEdgeInsetsMake(-10, -10, -10, -10);
[menuView addSubview:moreButton];
moreButton.hidden = NO;
#if TF_Download_Mode
UIButton *downloadButton = [UIButton buttonWithType:UIButtonTypeCustom];
downloadButton.hidden = NO;
downloadButton.adjustsImageWhenHighlighted = NO;
downloadButton.tintColor = kBlackColor;
[downloadButton setImage:[[UIImage imageNamed:@"public_download"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
[downloadButton setImageEdgeInsets:UIEdgeInsetsMake(11, 11, 11, 11)];
[downloadButton addTarget:self action:@selector(downloadButtonClick) forControlEvents:UIControlEventTouchUpInside];
[menuView addSubview:downloadButton];
downloadButton.hidden = NO;
#endif
//#if TF_Enable_Ai
UIButton *radioButton = [UIButton buttonWithType:UIButtonTypeCustom];
self.radioButton = radioButton;
radioButton.hidden = NO;
radioButton.adjustsImageWhenHighlighted = NO;
radioButton.tintColor = kBlackColor;
[radioButton setImage:[[UIImage imageNamed:@"audio_book"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
[radioButton setImageEdgeInsets:UIEdgeInsetsMake(10, 10, 10, 10)];
[radioButton addTarget:self action:@selector(radioButtonClick) forControlEvents:UIControlEventTouchUpInside];
[menuView addSubview:radioButton];
radioButton.hidden = NO;
//#endif
#if TF_Enable_Gift
UIButton *giftButton = [UIButton buttonWithType:UIButtonTypeCustom];
giftButton.hidden = NO;
giftButton.adjustsImageWhenHighlighted = NO;
giftButton.tintColor = kBlackColor;
[giftButton setImage:[[UIImage imageNamed:@"book_gift"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
[giftButton setImageEdgeInsets:UIEdgeInsetsMake(10, 10, 10, 10)];
[giftButton addTarget:self action:@selector(giftButtonClick) forControlEvents:UIControlEventTouchUpInside];
[menuView addSubview:giftButton];
#endif
NSMutableArray *buttonMenuArr = [NSMutableArray arrayWithObjects:
#if TF_Download_Mode
downloadButton,
#endif
moreButton,
nil];
self.buttonMenuArr = buttonMenuArr;
#if TF_Enable_Ai
if ([TFUtilsHelper getAiReadSwitchState]) {
[buttonMenuArr insertObject:radioButton atIndex:0];
} else {
radioButton.hidden = YES;
}
#endif
#if TF_Enable_Gift
AppDelegate *app = (AppDelegate *)kRCodeSync([UIApplication sharedApplication].delegate);
TFCheckSettingModel *model = app.checkSettingModel;
if (TF_Enable_Gift && (model.system_setting.novel_reward_switch == 1 || model.system_setting.monthly_ticket_switch == 1)) {
[buttonMenuArr insertObject:giftButton atIndex:0];
giftButton.hidden = NO;
} else {
giftButton.hidden = YES;
}
#endif
[menuView mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(self.mas_right).with.offset(- kHalfMargin);
make.bottom.mas_equalTo(self.mas_bottom);
make.width.mas_equalTo(40 * buttonMenuArr.count + (buttonMenuArr.count - 1) * kHalfMargin);
make.height.mas_equalTo(40);
}];
[buttonMenuArr mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing:10 leadSpacing:0 tailSpacing:0];
[buttonMenuArr mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(0);
make.height.mas_equalTo(40);
make.width.mas_equalTo(40);
}];
}
// 隐藏导航条
- (void)hiddenNavBarCompletion:(void(^)(void))completion
{
if (!_navBarShowing && functionalManager.state != TFReaderAutoReadStatePause && functionalManager.state != TFReaderAutoReadStateStop) {
return;
}
[functionalManager hiddenStatusBar];
[UIView animateWithDuration:kAnimatedDurationFast animations:^{
self.frame = CGRectMake(0, - PUB_NAVBAR_HEIGHT, SCREEN_WIDTH, PUB_NAVBAR_HEIGHT);
} completion:^(BOOL finished) {
if (completion) {
self.navBarShowing = NO;
!completion ?: completion();
}
}];
}
- (void)hiddenNavBar
{
[self hiddenNavBarCompletion:nil];
}
// 显示导航条
- (void)showNavBarCompletion:(void(^)(void))completion
{
if (_navBarShowing) {
return;
}
[functionalManager showStatusBar];
[TFViewHelper setStateBarDefaultStyle];
[UIView animateWithDuration:kAnimatedDurationFast animations:^{
self.frame = CGRectMake(0, 0, SCREEN_WIDTH, PUB_NAVBAR_HEIGHT);
} completion:^(BOOL finished) {
if (completion) {
self.navBarShowing = YES;
!completion ?: completion();
}
}];
}
#if TF_Download_Mode
- (void)downloadButtonClick
{
TFNovelDownloadMenuView *downloadBar = [[TFNovelDownloadMenuView alloc] init];
downloadBar.book_id = [TFUtilsHelper formatStringWithInteger:[TFReaderBookManager sharedManager].book_id];
downloadBar.chapter_id = [TFUtilsHelper formatStringWithInteger:[TFReaderBookManager sharedManager].chapter_id];
[kMainWindow addSubview:downloadBar];
[downloadBar showDownloadPayView];
[[NSNotificationCenter defaultCenter] postNotificationName:NSNotification_Hidden_Bottom_ToolNav object:nil];
}
#endif
#if TF_Enable_Ai
- (void)radioButtonClick
{
if ([TFNetworkManager networkingStatus] == NO) {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:TFLocalizedString(@"听书功能仅支持在线使用")];
return;
}
TFProductionModel *bookModel = [TFReaderBookManager sharedManager].bookModel;
TFProductionChapterModel *bookChapterModel = [[TFProductionChapterModel alloc] init];
for (TFProductionChapterModel *t_model in bookModel.chapter_list) {
if (t_model.chapter_id == [TFReaderBookManager sharedManager].chapter_id) {
bookChapterModel = t_model;
break;
}
}
WXYZ_BookAiPlayPageViewController *vc = [WXYZ_BookAiPlayPageViewController sharedManager];
[vc loadDataWithBookModel:bookModel chapterModel:bookChapterModel];
if ([[WXYZ_AudioSettingHelper sharedManager] isPlayPageShowingWithProductionType:TFProductionTypeAi]) {
[vc popViewController];
} else if (![[WXYZ_AudioSettingHelper sharedManager] isPlayPageShowingWithProductionType:TFProductionTypeAi] && [[WXYZ_AudioSettingHelper sharedManager] isPlayPageShowingWithProductionType:TFProductionTypeAudio]) {
[[TFAudioPlayViewController sharedManager] popViewController];
UINavigationController *nav = [TFViewHelper getCurrentNavigationController];
if ([nav.viewControllers.lastObject isKindOfClass:TFAudioDetailViewController.class]) {
TFNavigationController *t_nav = [[TFNavigationController alloc] initWithRootViewController:vc];
[[TFViewHelper getCurrentViewController] presentViewController:t_nav animated:YES completion:nil];
} else {
[[TFAudioPlayViewController sharedManager] popViewController];
}
} else if ([[WXYZ_AudioSettingHelper sharedManager] isPlayPageShowingWithProductionType:TFProductionTypeAi] && [[WXYZ_AudioSettingHelper sharedManager] isPlayPageShowingWithProductionType:TFProductionTypeAudio]) {
[[TFAudioPlayViewController sharedManager] popViewController];
[[TFAudioPlayViewController sharedManager] popViewController];
} else {
TFNavigationController *nav = [[TFNavigationController alloc] initWithRootViewController:vc];
nav.view.tag = 2345;
[[TFViewHelper getWindowRootController] presentViewController:nav animated:YES completion:nil];
}
[[NSNotificationCenter defaultCenter] postNotificationName:NSNotification_Hidden_Bottom_ToolNav object:nil];
}
#endif
- (void)giftButtonClick {
WXYZ_GiftView *mainView = [[WXYZ_GiftView alloc] initWithFrame:CGRectZero bookModel:[TFReaderBookManager sharedManager].bookModel];
[mainView show];
[[NSNotificationCenter defaultCenter] postNotificationName:NSNotification_Hidden_Bottom_ToolNav object:nil];
}
// 返回
- (void)popViewController
{
[[NSNotificationCenter defaultCenter] postNotificationName:NSNotification_Reader_Back object:nil];
}
- (void)moreEvent {
WXYZ_MoreView *mainView = [[WXYZ_MoreView alloc] init];
[mainView show];
}
@end
@@ -0,0 +1,22 @@
//
// WXYZ_MoreView.h
// WXReader
//
// Created by LL on 2020/5/22.
// Copyright © 2020 Andrew. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
/// 阅读器更多功能视图
@interface WXYZ_MoreView : UIView
- (void)hide;
- (void)show;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,392 @@
//
// WXYZ_MoreView.m
// WXReader
//
// Created by LL on 2020/5/22.
// Copyright © 2020 Andrew. All rights reserved.
//
#import "WXYZ_MoreView.h"
#import "UIView+LayoutCallback.h"
#import "NSObject+Observer.h"
#import "TFReaderBookManager.h"
#import "TFCollectionManager.h"
#import "TFNovelDetailViewController.h"
#import "TFShareManager.h"
#import "TFReadRecordManager.h"
#import "TFBookMarkModel.h"
#import "WXYZ_BookReaderMenuBar.h"
@interface WXYZ_MoreCell : UICollectionViewCell
- (void)setDict:(NSDictionary <NSString *, NSString *> *)dict;
@end
typedef NS_ENUM(NSInteger, ReaderBookStyle) {
ReaderBookDetail = 0,
ReaderBookMark,
ReaderBookRack,
ReaderBookShare,
};
@interface WXYZ_MoreView ()<UICollectionViewDataSource, UICollectionViewDelegate>
@property (nonatomic, strong) NSArray<NSDictionary *> *moreDict;
@property (nonatomic, weak) UIView *mainView;
/// 背景视图
@property (nonatomic, weak) UIView *emptyView;
@property (nonatomic, strong) TFProductionModel *bookModel;
@property (nonatomic, strong) TFReaderBookManager *bookManager;
/// 书签状态
@property (nonatomic, assign) BOOL markStatus;
/// 书签Model
@property (nonatomic, strong) TFBookMarkModel *markModel;
/// 是不是封面
@property (nonatomic, assign) BOOL isCover;
@end
@implementation WXYZ_MoreView
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
[self initialize];
[self createSubviews];
}
return self;
}
- (void)initialize {
self.bookModel = [TFReaderBookManager sharedManager].bookModel;
self.bookManager = [TFReaderBookManager sharedManager];
// 章节内容
NSString *chapterContent = [self.bookManager getChapterContent];
// 页面内容
NSString *pageContent = [self.bookManager getChapterDetailContent];
NSRange range = [chapterContent rangeOfString:pageContent];
if (self.isCover) {// 封面不能添加书签
self.markStatus = NO;
} else {
// 获取当前章节所有的书签
NSArray<TFBookMarkModel *> *markArr = [TFReadRecordManager bookMark:[TFUtilsHelper formatStringWithInteger:self.bookManager.book_id] chapterID:[TFUtilsHelper formatStringWithInteger:self.bookManager.chapter_id]];
for (TFBookMarkModel *t_model in markArr) {
if (t_model.specificIndex >= range.location && t_model.specificIndex < (range.location + range.length)) {
self.markModel = t_model;
self.markStatus = YES;
break;
}
}
}
}
- (void)createSubviews {
self.backgroundColor = kBlackTransparentColor;
[kMainWindow addSubview:self];
[self mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(kMainWindow);
}];
UIView *emptyView = [[UIView alloc] init];
self.emptyView = emptyView;
emptyView.backgroundColor = [UIColor clearColor];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hide)];
[emptyView addGestureRecognizer:tap];
[self addSubview:emptyView];
[emptyView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self);
}];
UIView *mainView = [[UIView alloc] init];
self.mainView = mainView;
mainView.backgroundColor = [UIColor whiteColor];
mainView.frameBlock = ^(UIView * _Nonnull view) {
UIBezierPath *corner = [UIBezierPath bezierPathWithRoundedRect:view.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(12.0, 12.0)];
CAShapeLayer *layer = [CAShapeLayer layer];
layer.path = corner.CGPath;
view.layer.mask = layer;
};
[self addSubview:mainView];
[mainView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.mas_bottom);
make.left.right.equalTo(self);
make.height.mas_equalTo(100 + 25 + 25 + PUB_TABBAR_HEIGHT);
}];
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
flowLayout.estimatedItemSize = CGSizeMake(62.0, 60.0f);
CGFloat spacing = (SCREEN_WIDTH - (2 * kMargin) - (self.moreDict.count * flowLayout.estimatedItemSize.width)) / (self.moreDict.count - 1);
spacing = spacing < kMargin ? kMargin : spacing;
flowLayout.minimumInteritemSpacing = spacing;
flowLayout.minimumLineSpacing = kMargin;
UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout];
collectionView.dataSource = self;
collectionView.delegate = self;
[collectionView registerClass:[WXYZ_MoreCell class] forCellWithReuseIdentifier:@"Identifier"];
collectionView.backgroundColor = [UIColor clearColor];
collectionView.showsVerticalScrollIndicator = NO;
collectionView.showsHorizontalScrollIndicator = NO;
[mainView addSubview:collectionView];
[collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(mainView).offset(25);
make.left.equalTo(mainView).offset(kMargin);
make.right.equalTo(mainView).offset(- kMargin);
make.height.mas_equalTo(100);
}];
[collectionView addObserver:KEY_PATH(collectionView, contentSize) complete:^(UICollectionView * _Nonnull obj, id _Nullable oldVal, id _Nullable newVal) {
CGSize size = [newVal CGSizeValue];
[obj mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(size.height);
}];
}];
UIButton *closeButton = [UIButton buttonWithType:UIButtonTypeSystem];
[closeButton setTitle:TFLocalizedString(@"关闭") forState:UIControlStateNormal];
[closeButton setTitleColor:kBlackColor forState:UIControlStateNormal];
[closeButton setTitleEdgeInsets:UIEdgeInsetsMake(0, 0, PUB_TABBAR_OFFSET / 2, 0)];
closeButton.titleLabel.font = kFont16;
[mainView addSubview:closeButton];
[closeButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(PUB_TABBAR_HEIGHT);
make.left.width.equalTo(mainView);
make.top.equalTo(collectionView.mas_bottom).offset(25.0f);
}];
tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hide)];
[closeButton addGestureRecognizer:tap];
UIView *splitLine = [[UIView alloc] init];
splitLine.backgroundColor = kGrayLineColor;
[mainView addSubview:splitLine];
[splitLine mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(0.5);
make.left.width.top.equalTo(closeButton);
}];
[self setNeedsLayout];
[self layoutIfNeeded];
}
- (void)show {
[UIView animateWithDuration:kAnimatedDuration animations:^{
[self.mainView mas_updateConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.mas_bottom).offset(- CGRectGetHeight(self.mainView.frame));
}];
[self.mainView.superview layoutIfNeeded];
}];
}
- (void)hide {
[UIView animateWithDuration:kAnimatedDuration animations:^{
[self.mainView mas_updateConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.mas_bottom);
}];
[self.mainView.superview layoutIfNeeded];
} completion:^(BOOL finished) {
if (finished) {
[self removeFromSuperview];
[[WXYZ_BookReaderMenuBar sharedManager] hiddend];
}
}];
}
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
CGPoint emptyPoint = [self convertPoint:point toView:self.mainView];
if ([self.mainView pointInside:emptyPoint withEvent:event]) {
return [super hitTest:point withEvent:event];
} else {
return self.emptyView;
}
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return self.moreDict.count;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
WXYZ_MoreCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Identifier" forIndexPath:indexPath];
[cell setDict:self.moreDict[indexPath.row].allValues.firstObject];
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
NSDictionary *dict = self.moreDict[indexPath.row];
ReaderBookStyle style = [dict.allKeys.firstObject integerValue];
switch (style) {
case ReaderBookDetail:
{
[self hide];
UINavigationController *nav = [TFViewHelper getCurrentNavigationController];
if (nav.viewControllers.count > 1) {
UIViewController *tmp = nav.viewControllers[nav.viewControllers.count - 2];
if ([tmp isKindOfClass:TFNovelDetailViewController.class]) {
[nav popViewControllerAnimated:YES];
return;
}
}
[[NSNotificationCenter defaultCenter] postNotificationName:NSNotification_Reader_Push object:@"TFNovelDetailViewController"];
}
break;
case ReaderBookMark:
{
if (self.isCover) {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:TFLocalizedString(@"当前页不支持加书签")];
return;
}
NSString *pageContent = [self.bookManager getChapterDetailContent];
if ([pageContent isEqualToString:@"\uFFFC"]) {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:TFLocalizedString(@"当前页不支持加书签")];
return;
}
NSDictionary *dict = nil;
if (self.markStatus) {
// 移除书签
[TFReadRecordManager removeBookMark:self.markModel];
dict = @{@(ReaderBookMark) : @{TFLocalizedString(@"添加书签") : @"book_add_mark"}};
self.markStatus = NO;
} else {
// 添加书签
self.markModel = [TFReadRecordManager addBookMark:[TFUtilsHelper formatStringWithInteger:self.bookManager.book_id] chapterID:[TFUtilsHelper formatStringWithInteger:self.bookManager.chapter_id] chapterSort:self.bookManager.currentChapterIndex chapterTitle:[self.bookManager getChapterTitle] chapterContent:[self.bookManager getChapterContent] pageContent:pageContent];
dict = @{@(ReaderBookMark) : @{TFLocalizedString(@"取消书签") : @"book_remove_mark"}};
self.markStatus = YES;
}
NSMutableArray<NSDictionary *> *arr = [NSMutableArray arrayWithArray:self.moreDict];
[arr replaceObjectAtIndex:indexPath.row withObject:dict];
self.moreDict = [arr copy];
[collectionView reloadData];
}
break;
case ReaderBookRack:
{
if ([[TFCollectionManager shareManagerWithProductionType:TFProductionTypeNovel] isCollectedWithProductionModel:self.bookModel]) break;
if ([[TFCollectionManager shareManagerWithProductionType:TFProductionTypeNovel] addCollectionWithProductionModel:self.bookModel atIndex:0]) {
[TFUtilsHelper synchronizationRackProductionWithProduction_id:self.bookModel.production_id productionType:TFProductionTypeNovel complete:nil];
NSDictionary *dict = @{@(ReaderBookRack) : @{TFLocalizedString(@"已加入书架") : @"book_remove_rack"}};
NSMutableArray<NSDictionary *> *arr = [NSMutableArray arrayWithArray:self.moreDict];
[arr replaceObjectAtIndex:indexPath.row withObject:dict];
self.moreDict = [arr copy];
[collectionView reloadData];
} else {
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:TFLocalizedString(@"添加失败")];
}
}
break;
case ReaderBookShare:
{
[self hide];
[[NSNotificationCenter defaultCenter] postNotificationName:NSNotification_Hidden_ToolNav object:nil];
[[NSNotificationCenter defaultCenter] postNotificationName:NSNotification_Hidden_Bottom_ToolNav object:nil];
[TFShareManager shareWithProduction_id:NSStringFromInteger(self.bookModel.production_id) chapter_id:NSStringFromInteger(self.bookManager.chapter_id) type:TFShareTypeBook];
}
break;
default:
break;
};
}
- (NSArray<NSDictionary *> *)moreDict {
if (!_moreDict) {
NSMutableArray<NSDictionary *> *arr = [NSMutableArray array];
[arr addObject:@{@(ReaderBookDetail) : @{TFLocalizedString(@"书籍详情") : @"book_detail"}}];
if (self.markStatus) {
[arr addObject:@{@(ReaderBookMark) : @{TFLocalizedString(@"取消书签") : @"book_remove_mark"}}];
} else {
[arr addObject:@{@(ReaderBookMark) : @{TFLocalizedString(@"添加书签") : @"book_add_mark"}}];
}
if ([[TFCollectionManager shareManagerWithProductionType:TFProductionTypeNovel] isCollectedWithProductionModel:self.bookModel]) {
[arr addObject:@{@(ReaderBookRack) : @{TFLocalizedString(@"已加入书架") : @"book_remove_rack"}}];
} else {
[arr addObject:@{@(ReaderBookRack) : @{TFLocalizedString(@"加入书架") : @"book_add_rack"}}];
}
[arr addObject:@{@(ReaderBookShare) : @{TFLocalizedString(@"分享") : @"book_share"}}];
_moreDict = [arr copy];
}
return _moreDict;
}
- (BOOL)isCover {
return self.bookManager.currentChapterIndex == 0 && self.bookManager.currentPagerIndex == 0;
}
@end
@implementation WXYZ_MoreCell {
UIImageView *_coverImageView;
UILabel *_titleLabel;
}
- (instancetype)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
[self createSubviews];
}
return self;
}
- (void)createSubviews {
_coverImageView = [[UIImageView alloc] init];
_coverImageView.contentMode = UIViewContentModeScaleAspectFill;
_coverImageView.clipsToBounds = YES;
_coverImageView.userInteractionEnabled = NO;
_coverImageView.backgroundColor = [UIColor clearColor];
[self.contentView addSubview:_coverImageView];
[_coverImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.left.width.equalTo(self.contentView);
make.height.equalTo(_coverImageView.mas_width);
}];
_titleLabel = [[UILabel alloc] init];
_titleLabel.textColor = kBlackColor;
_titleLabel.font = kFont13;
_titleLabel.backgroundColor = [UIColor clearColor];
[self.contentView addSubview:_titleLabel];
[_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(_coverImageView.mas_bottom).offset(14.0f);
make.centerX.equalTo(self.contentView);
make.bottom.equalTo(self.contentView).priorityLow();
}];
}
- (void)setDict:(NSDictionary <NSString *, NSString *> *)dict {
_coverImageView.image = [UIImage imageNamed:dict.allValues.firstObject];
_titleLabel.text = dict.allKeys.firstObject ?: @"";
}
- (UICollectionViewLayoutAttributes*)preferredLayoutAttributesFittingAttributes:(UICollectionViewLayoutAttributes*)layoutAttributes {
[self setNeedsLayout];
[self layoutIfNeeded];
CGSize size = [self.contentView systemLayoutSizeFittingSize:layoutAttributes.size];
CGRect cellFrame = layoutAttributes.frame;
cellFrame.size.height = size.height;
layoutAttributes.frame = cellFrame;
return layoutAttributes;
}
@end