小说绘上架版本

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