小说绘上架版本
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
//
|
||||
// TFCommentsModel.h
|
||||
// TFReader
|
||||
//
|
||||
// Created by 谢腾飞 on 2020/12/13.
|
||||
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
@class TFCommentsListModel, TFPagingModel;
|
||||
|
||||
@interface TFCommentsModel : TFPagingModel
|
||||
|
||||
@property (nonatomic ,strong) NSArray<TFCommentsListModel *> *list;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
||||
@interface TFCommentsListModel : NSObject
|
||||
|
||||
@property (nonatomic ,copy) NSString *avatar; //评论用户头像
|
||||
@property (nonatomic ,assign) NSInteger comment_id; //评论id
|
||||
@property (nonatomic ,assign) NSInteger uid; //评论用户uid
|
||||
@property (nonatomic ,copy) NSString *time; //评论时间
|
||||
@property (nonatomic ,copy) NSString *nickname; //评论人昵称
|
||||
@property (nonatomic ,copy) NSString *content; //评论内容
|
||||
@property (nonatomic ,assign) NSInteger like_num; //点赞数
|
||||
@property (nonatomic ,copy) NSString *reply_info; //回复的评论内容
|
||||
@property (nonatomic ,assign) NSInteger is_vip; //是否为VIP ,0否 1是
|
||||
@property (nonatomic ,assign) NSInteger comment_num; //评论数
|
||||
@property (nonatomic ,copy) NSString *name_title; // 评论的书籍
|
||||
@property (nonatomic ,assign) NSInteger reply_num; // 评论回复数
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -0,0 +1,24 @@
|
||||
//
|
||||
// TFCommentsModel.m
|
||||
// TFReader
|
||||
//
|
||||
// Created by 谢腾飞 on 2020/12/13.
|
||||
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TFCommentsModel.h"
|
||||
|
||||
@implementation TFCommentsModel
|
||||
|
||||
+ (NSDictionary<NSString *,id> *)modelContainerPropertyGenericClass
|
||||
{
|
||||
return @{@"list" : [TFCommentsListModel class]};
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
||||
@implementation TFCommentsListModel
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,23 @@
|
||||
//
|
||||
// TFCommentsViewCell.h
|
||||
// TFReader
|
||||
//
|
||||
// Created by 谢腾飞 on 2020/12/13.
|
||||
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import <YYKit.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface TFCommentsViewCell : TFBasicTableViewCell
|
||||
|
||||
@property (nonatomic, strong) TFCommentsListModel *commentModel;
|
||||
|
||||
/// 预览列表分割线和正常列表不一样
|
||||
- (void)setIsPreview:(BOOL)isPreview lastRow:(BOOL)lastRow;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -0,0 +1,184 @@
|
||||
//
|
||||
// TFCommentsViewCell.m
|
||||
// TFReader
|
||||
//
|
||||
// Created by 谢腾飞 on 2020/12/13.
|
||||
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TFCommentsViewCell.h"
|
||||
|
||||
@interface TFCommentsViewCell ()
|
||||
|
||||
@property (nonatomic ,strong) UIImageView *avatarView; // 头像
|
||||
@property (nonatomic ,strong) UILabel *nicknameLabel; // 昵称
|
||||
@property (nonatomic ,strong) UILabel *commentLabel; // 评论
|
||||
@property (nonatomic ,strong) YYLabel *replyCommentLabel; // 二级评论
|
||||
@property (nonatomic ,strong) UILabel *timeLabel; // 发布时间
|
||||
@property (nonatomic ,strong) UIImageView *vipView;
|
||||
|
||||
@end
|
||||
|
||||
@implementation TFCommentsViewCell
|
||||
|
||||
- (void)createSubviews
|
||||
{
|
||||
[super createSubviews];
|
||||
|
||||
// 头像
|
||||
self.avatarView = [[UIImageView alloc] initWithCornerRadiusAdvance:35.0f / 2 rectCornerType:UIRectCornerAllCorners];
|
||||
[self.contentView addSubview:self.avatarView];
|
||||
|
||||
[self.avatarView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(self.contentView.mas_left).with.offset(kMargin);
|
||||
make.top.mas_equalTo(self.contentView.mas_top).with.offset(kHalfMargin);
|
||||
make.width.height.mas_equalTo(35.0f);
|
||||
}];
|
||||
|
||||
// 昵称
|
||||
self.nicknameLabel = [[UILabel alloc] init];
|
||||
self.nicknameLabel.textColor = kGrayTextDeepColor;
|
||||
self.nicknameLabel.font = kFont13;
|
||||
self.nicknameLabel.textAlignment = NSTextAlignmentLeft;
|
||||
[self.contentView addSubview:self.nicknameLabel];
|
||||
|
||||
[self.nicknameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(self.avatarView.mas_right).with.offset(kHalfMargin);
|
||||
make.top.mas_equalTo(self.avatarView.mas_top);
|
||||
make.width.mas_equalTo(200);
|
||||
make.height.mas_equalTo(self.avatarView.mas_height).multipliedBy(0.6);
|
||||
}];
|
||||
|
||||
self.timeLabel = [[UILabel alloc] init];
|
||||
self.timeLabel.textAlignment = NSTextAlignmentLeft;
|
||||
self.timeLabel.font = kFont10;
|
||||
self.timeLabel.textColor = kGrayTextColor;
|
||||
[self.contentView addSubview:self.timeLabel];
|
||||
|
||||
[self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(self.nicknameLabel.mas_left);
|
||||
make.bottom.mas_equalTo(self.avatarView.mas_bottom);
|
||||
make.right.mas_equalTo(self.contentView.mas_right);
|
||||
make.height.mas_equalTo(self.avatarView.mas_height).multipliedBy(0.4);
|
||||
}];
|
||||
|
||||
self.vipView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"public_vip_select"]];
|
||||
self.vipView.hidden = YES;
|
||||
[self addSubview:self.vipView];
|
||||
|
||||
[self.vipView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(self.nicknameLabel.mas_right);
|
||||
make.centerY.mas_equalTo(self.nicknameLabel.mas_centerY);
|
||||
make.height.mas_equalTo(10);
|
||||
make.width.mas_equalTo(kGeometricWidth(10, 138, 48));
|
||||
}];
|
||||
|
||||
// 二级评论
|
||||
self.replyCommentLabel = [[YYLabel alloc] init];
|
||||
self.replyCommentLabel.textAlignment = NSTextAlignmentLeft;
|
||||
self.replyCommentLabel.textColor = kGrayTextDeepColor;
|
||||
self.replyCommentLabel.font = kFont13;
|
||||
self.replyCommentLabel.backgroundColor = kGrayViewColor;
|
||||
self.replyCommentLabel.numberOfLines = 0;
|
||||
self.replyCommentLabel.textContainerInset = UIEdgeInsetsMake(6, 5, 4, 5);
|
||||
[self.contentView addSubview:self.replyCommentLabel];
|
||||
|
||||
[self.replyCommentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(self.nicknameLabel.mas_left);
|
||||
make.top.mas_equalTo(self.avatarView.mas_bottom);
|
||||
make.right.mas_equalTo(self.contentView.mas_right).with.offset(- kMargin);
|
||||
make.height.mas_equalTo(CGFLOAT_MIN);
|
||||
}];
|
||||
|
||||
// 评论
|
||||
self.commentLabel = [[UILabel alloc] init];
|
||||
self.commentLabel.textAlignment = NSTextAlignmentLeft;
|
||||
self.commentLabel.font = kMainFont;
|
||||
self.commentLabel.numberOfLines = 0;
|
||||
self.commentLabel.textColor = kBlackColor;
|
||||
[self.contentView addSubview:self.commentLabel];
|
||||
|
||||
[self.commentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(self.nicknameLabel.mas_left);
|
||||
make.right.mas_equalTo(self.contentView.mas_right).with.offset(- kMargin);
|
||||
make.top.mas_equalTo(self.replyCommentLabel.mas_bottom).with.offset(kHalfMargin);
|
||||
make.height.mas_equalTo(200);
|
||||
make.bottom.mas_equalTo(self.contentView.mas_bottom).with.offset(- kHalfMargin).priorityLow();
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)setIsPreview:(BOOL)isPreview lastRow:(BOOL)lastRow
|
||||
{
|
||||
if (isPreview && !lastRow) {
|
||||
[self.lineView mas_remakeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.equalTo(self.commentLabel);
|
||||
make.height.mas_equalTo(kCellLineHeight);
|
||||
make.right.equalTo(self.contentView);
|
||||
make.bottom.mas_equalTo(self.contentView.mas_bottom).with.offset(-kCellLineHeight);
|
||||
}];
|
||||
return;
|
||||
}
|
||||
|
||||
if (isPreview && lastRow) {
|
||||
[self.lineView mas_remakeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.equalTo(self.avatarView);
|
||||
make.height.mas_equalTo(kCellLineHeight);
|
||||
make.right.equalTo(self.contentView);
|
||||
make.bottom.mas_equalTo(self.contentView.mas_bottom).with.offset(-kCellLineHeight);
|
||||
}];
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setCommentModel:(TFCommentsListModel *)commentModel
|
||||
{
|
||||
if (!commentModel) return;
|
||||
|
||||
_commentModel = commentModel;
|
||||
|
||||
self.timeLabel.text = [NSString stringWithFormat:@"%@",commentModel.time?:@""];
|
||||
self.commentLabel.text = [NSString stringWithFormat:@"%@",commentModel.content?:@""];
|
||||
|
||||
if (commentModel.reply_info.length > 0) {
|
||||
CGFloat replyHeight = [TFViewHelper getDynamicHeightWithLabelFont:kFont11 labelWidth:(SCREEN_WIDTH - 2 * kMargin - 35.0f - kHalfMargin) labelText:commentModel.reply_info ? : @""];
|
||||
NSString *replyInfo = [NSString stringWithFormat:@"%@",commentModel.reply_info ? : @""];
|
||||
|
||||
NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
|
||||
style.lineSpacing = 3;
|
||||
|
||||
NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:replyInfo];
|
||||
[attrString addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, replyInfo.length)];
|
||||
[attrString addAttribute:NSFontAttributeName value:kFont11 range:NSMakeRange(0, replyInfo.length)];
|
||||
|
||||
self.replyCommentLabel.attributedText = attrString;
|
||||
[self.replyCommentLabel mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.mas_equalTo(self.avatarView.mas_bottom).with.offset(kHalfMargin);
|
||||
make.height.mas_equalTo(replyHeight);
|
||||
}];
|
||||
} else {
|
||||
self.replyCommentLabel.attributedText = [[NSMutableAttributedString alloc] initWithString:@""];
|
||||
[self.replyCommentLabel mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.mas_equalTo(self.avatarView.mas_bottom);
|
||||
make.height.mas_equalTo(CGFLOAT_MIN);
|
||||
}];
|
||||
}
|
||||
|
||||
[self.commentLabel mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.height.mas_equalTo([TFViewHelper getDynamicHeightWithLabelFont:self.commentLabel.font labelWidth:(SCREEN_WIDTH - 35.0f - 2 * kMargin) labelText:self.commentLabel.text] - kHalfMargin);
|
||||
}];
|
||||
|
||||
[self.avatarView setImageWithURL:[NSURL URLWithString:commentModel.avatar?:@""] placeholder:HoldUserAvatar options:YYWebImageOptionSetImageWithFadeAnimation completion:nil];
|
||||
|
||||
self.nicknameLabel.text = [NSString stringWithFormat:@"%@",commentModel.nickname?:@""];
|
||||
[self.nicknameLabel mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.width.mas_equalTo([TFViewHelper getDynamicWidthWithLabel:self.nicknameLabel maxWidth:SCREEN_WIDTH - 35 - 2 * kMargin]);
|
||||
}];
|
||||
|
||||
if (commentModel.is_vip == 1) {
|
||||
self.vipView.hidden = NO;
|
||||
} else {
|
||||
self.vipView.hidden = YES;
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// TFCommentsViewController.h
|
||||
// TFReader
|
||||
//
|
||||
// Created by 谢腾飞 on 2020/12/13.
|
||||
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
@class TFCommentsListModel;
|
||||
typedef void(^CommentsSuccessBlock)(TFCommentsListModel *commentModel);
|
||||
|
||||
@interface TFCommentsViewController : TFBasicViewController
|
||||
// 作品id
|
||||
@property (nonatomic ,assign) NSInteger production_id;
|
||||
@property (nonatomic ,assign) NSInteger chapter_id;
|
||||
@property (nonatomic ,assign) NSInteger comment_id;
|
||||
@property (nonatomic ,assign) BOOL pushFromReader;
|
||||
@property (nonatomic ,copy) CommentsSuccessBlock commentsSuccessBlock;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -0,0 +1,429 @@
|
||||
//
|
||||
// TFCommentsViewController.m
|
||||
// TFReader
|
||||
//
|
||||
// Created by 谢腾飞 on 2020/12/13.
|
||||
// Copyright © 2020 xtfei_2011@126.com. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TFCommentsViewController.h"
|
||||
#import "TFCommentsViewCell.h"
|
||||
#import "CXTextView.h"
|
||||
|
||||
@interface TFCommentsViewController ()<UITableViewDelegate, UITableViewDataSource, UIGestureRecognizerDelegate, UITextViewDelegate>
|
||||
|
||||
@property (nonatomic ,strong) CXTextView *commentTextView;
|
||||
@property (nonatomic ,strong) UIView *commentBottomView;
|
||||
@property (nonatomic ,strong) TFCommentsModel *commentModel;
|
||||
@property (nonatomic ,assign) CGFloat keyboardHeight;
|
||||
@property (nonatomic ,assign) CGFloat commentViewHeight;
|
||||
|
||||
@end
|
||||
|
||||
@implementation TFCommentsViewController
|
||||
|
||||
- (void)viewWillAppear:(BOOL)animated
|
||||
{
|
||||
[super viewWillAppear:animated];
|
||||
|
||||
[self setStatusBarDefaultStyle];
|
||||
}
|
||||
|
||||
- (void)viewDidLoad
|
||||
{
|
||||
[super viewDidLoad];
|
||||
|
||||
[self initialize];
|
||||
[self createSubviews];
|
||||
}
|
||||
|
||||
- (void)initialize
|
||||
{
|
||||
if (self.chapter_id > 0) {
|
||||
if (self.productionType == TFProductionTypeComic) {
|
||||
[self setNavigationBarTitle:TFLocalizedString(@"评论")];
|
||||
} else {
|
||||
[self setNavigationBarTitle:[NSString stringWithFormat:@"%@ (0)", TFLocalizedString(@"本章评论")]];
|
||||
}
|
||||
} else {
|
||||
[self setNavigationBarTitle:[NSString stringWithFormat:@"%@ (0)", TFLocalizedString(@"书评")]];
|
||||
}
|
||||
|
||||
self.commentViewHeight = 30;
|
||||
|
||||
NSArray *viewControllers = self.navigationController.viewControllers;
|
||||
|
||||
if (viewControllers.count <= 1) {
|
||||
UIButton *closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
closeButton.frame = CGRectMake(kHalfMargin, PUB_NAVBAR_OFFSET + 20, 44, 44);
|
||||
closeButton.imageEdgeInsets = UIEdgeInsetsMake(12, 12, 12, 12);
|
||||
[closeButton setImage:[UIImage imageNamed:@"public_close"] forState:UIControlStateNormal];
|
||||
[closeButton addTarget:self action:@selector(popViewController) forControlEvents:UIControlEventTouchUpInside];
|
||||
|
||||
[self setNavigationBarLeftButton:closeButton];
|
||||
}
|
||||
|
||||
if (self.pushFromReader) {
|
||||
id target = self.navigationController.interactivePopGestureRecognizer.delegate;
|
||||
|
||||
UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:target action:NSSelectorFromString(@"handleNavigationTransition:")];
|
||||
panGesture.delegate = self;
|
||||
[self.view addGestureRecognizer:panGesture];
|
||||
|
||||
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
|
||||
}
|
||||
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(netRequest) name:Notification_Reload_BookDetail object:nil];
|
||||
// 增加监听,当键盘出现或改变时收出消息
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:)name:UIKeyboardWillShowNotification object:nil];
|
||||
// 增加监听,当键退出时收出消息
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:)name:UIKeyboardWillHideNotification object:nil];
|
||||
}
|
||||
|
||||
- (void)createSubviews
|
||||
{
|
||||
self.mainTableView.delegate = self;
|
||||
self.mainTableView.dataSource = self;
|
||||
[self.view addSubview:self.mainTableView];
|
||||
|
||||
[self.mainTableView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(0);
|
||||
make.top.mas_equalTo(PUB_NAVBAR_HEIGHT);
|
||||
make.width.mas_equalTo(self.view.mas_width);
|
||||
make.height.mas_equalTo(self.view.mas_height).with.offset(- PUB_NAVBAR_HEIGHT - PUB_TABBAR_HEIGHT);
|
||||
}];
|
||||
|
||||
self.commentBottomView = [[UIView alloc] init];
|
||||
self.commentBottomView.backgroundColor = kGrayViewColor;
|
||||
[self.view addSubview:self.commentBottomView];
|
||||
|
||||
[self.commentBottomView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(0);
|
||||
make.bottom.mas_equalTo(self.view.mas_bottom);
|
||||
make.width.mas_equalTo(self.view.mas_width);
|
||||
make.height.mas_equalTo(PUB_TABBAR_HEIGHT);
|
||||
}];
|
||||
|
||||
|
||||
WS(weakSelf)
|
||||
self.commentTextView = [[CXTextView alloc] initWithFrame:CGRectMake(kHalfMargin, kQuarterMargin, SCREEN_WIDTH - kMargin, 30)];
|
||||
self.commentTextView.placeholder = TFLocalizedString(@"说点什么吧");
|
||||
self.commentTextView.maxLine = 5;
|
||||
self.commentTextView.maxLength = 200;
|
||||
self.commentTextView.font = kMainFont;
|
||||
self.commentTextView.backgroundColor = [UIColor whiteColor];
|
||||
self.commentTextView.layer.cornerRadius = 15;
|
||||
|
||||
self.commentTextView.textHeightChangeBlock = ^(CGFloat height) {
|
||||
SS(strongSelf)
|
||||
strongSelf.commentViewHeight = height;
|
||||
|
||||
[weakSelf.commentBottomView mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.height.mas_equalTo(strongSelf.keyboardHeight + height + kHalfMargin);
|
||||
}];
|
||||
};
|
||||
|
||||
self.commentTextView.returnHandlerBlock = ^{
|
||||
[weakSelf sendCommentNetRequest];
|
||||
[[[UIApplication sharedApplication] keyWindow] endEditing:YES];
|
||||
};
|
||||
|
||||
[self.commentBottomView addSubview:self.commentTextView];
|
||||
|
||||
self.mainTableView.mj_header = [TFRefreshHeader headerWithRefreshingBlock:^{
|
||||
weakSelf.currentPageNumber = 1;
|
||||
[weakSelf netRequest];
|
||||
}];
|
||||
[self.mainTableView.mj_header beginRefreshing];
|
||||
|
||||
self.mainTableView.mj_footer = [TFRefreshFooter footerWithRefreshingBlock:^{
|
||||
weakSelf.currentPageNumber ++;
|
||||
[weakSelf netRequest];
|
||||
}];
|
||||
|
||||
[self setEmptyOnView:self.mainTableView title:TFLocalizedString(@"暂无评论内容") tapBlock:^{
|
||||
}];
|
||||
}
|
||||
|
||||
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
|
||||
{
|
||||
return self.dataSourceArray.count;
|
||||
}
|
||||
|
||||
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
static NSString *cellID = @"TFCommentsViewCell";
|
||||
TFCommentsViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
|
||||
if (!cell) {
|
||||
cell = [[TFCommentsViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
|
||||
}
|
||||
cell.commentModel = [self.dataSourceArray objectOrNilAtIndex:indexPath.row];
|
||||
cell.hiddenEndLine = indexPath.row == self.dataSourceArray.count - 1;
|
||||
|
||||
if (self.chapter_id > 0) {
|
||||
if (self.productionType == TFProductionTypeComic) {
|
||||
[self setNavigationBarTitle:TFLocalizedString(@"评论")];
|
||||
} else {
|
||||
[self setNavigationBarTitle:[NSString stringWithFormat:@"%@ (%@)", TFLocalizedString(@"本章评论"), [TFUtilsHelper formatStringWithInteger:self.commentModel.total_count]]];
|
||||
}
|
||||
} else {
|
||||
[self setNavigationBarTitle:[NSString stringWithFormat:@"%@ (%@)", TFLocalizedString(@"书评"), [TFUtilsHelper formatStringWithInteger:self.commentModel.total_count]]];
|
||||
}
|
||||
|
||||
return cell;
|
||||
}
|
||||
|
||||
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
|
||||
{
|
||||
TFCommentsListModel *t_model = [self.dataSourceArray objectOrNilAtIndex:indexPath.row];
|
||||
[self.commentTextView textViewBecomeFirstResponder];
|
||||
|
||||
self.comment_id = t_model.comment_id;
|
||||
}
|
||||
|
||||
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
|
||||
{
|
||||
return CGFLOAT_MIN;
|
||||
}
|
||||
|
||||
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
|
||||
{
|
||||
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, CGFLOAT_MIN)];
|
||||
view.backgroundColor = [UIColor clearColor];
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
|
||||
{
|
||||
return CGFLOAT_MIN;
|
||||
}
|
||||
|
||||
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
|
||||
{
|
||||
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, CGFLOAT_MIN)];
|
||||
view.backgroundColor = [UIColor clearColor];
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
|
||||
{
|
||||
if (scrollView == self.mainTableView) {
|
||||
[[[UIApplication sharedApplication] keyWindow] endEditing:YES];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setComment_id:(NSInteger)comment_id
|
||||
{
|
||||
_comment_id = comment_id;
|
||||
|
||||
[self resetCommentTextViewPlaceHolder];
|
||||
}
|
||||
|
||||
- (void)resetCommentTextViewPlaceHolder
|
||||
{
|
||||
if (!self.dataSourceArray || self.dataSourceArray.count == 0) {
|
||||
return;
|
||||
}
|
||||
for (TFCommentsListModel *t_model in self.dataSourceArray) {
|
||||
if (t_model.comment_id == self.comment_id) {
|
||||
self.commentTextView.placeholder = [NSString stringWithFormat:@"%@ @%@", TFLocalizedString(@"回复"), [TFUtilsHelper formatStringWithObject:t_model.nickname]];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 当键盘出现或改变时调用
|
||||
- (void)keyboardWillShow:(NSNotification *)notification
|
||||
{
|
||||
// 获取键盘的高度
|
||||
self.keyboardHeight = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size.height;
|
||||
[self.commentBottomView mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.height.mas_equalTo(self.keyboardHeight + self.commentViewHeight + kHalfMargin + kQuarterMargin);
|
||||
}];
|
||||
[self.commentBottomView.superview layoutIfNeeded];
|
||||
}
|
||||
|
||||
// 当键退出时调用
|
||||
- (void)keyboardWillHide:(NSNotification *)notification
|
||||
{
|
||||
self.keyboardHeight = PUB_TABBAR_OFFSET;
|
||||
[self.commentBottomView mas_updateConstraints:^(MASConstraintMaker *make) {
|
||||
make.height.mas_equalTo(self.commentViewHeight + PUB_TABBAR_OFFSET + (PUB_TABBAR_HEIGHT - PUB_TABBAR_OFFSET - 30));
|
||||
}];
|
||||
[self.commentBottomView.superview layoutIfNeeded];
|
||||
}
|
||||
|
||||
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
|
||||
{
|
||||
if (![self.commentBottomView pointInside:[self.commentBottomView convertPoint:[[touches anyObject] locationInView:self.view] fromView:self.view] withEvent:event]) {
|
||||
[[[UIApplication sharedApplication] keyWindow] endEditing:YES];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)netRequest
|
||||
{
|
||||
NSString *url = @"";
|
||||
NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
|
||||
|
||||
switch (self.productionType) {
|
||||
case TFProductionTypeNovel:
|
||||
url = Book_Comment_List;
|
||||
parameters[@"book_id"] = [TFUtilsHelper formatStringWithInteger:self.production_id] ? : @"";
|
||||
parameters[@"page_num"] = [TFUtilsHelper formatStringWithInteger:self.currentPageNumber];
|
||||
|
||||
break;
|
||||
|
||||
case TFProductionTypeComic:
|
||||
url = Comic_Comment_List;
|
||||
parameters[@"comic_id"] = [TFUtilsHelper formatStringWithInteger:self.production_id] ? : @"";
|
||||
parameters[@"page_num"] = [TFUtilsHelper formatStringWithInteger:self.currentPageNumber];
|
||||
|
||||
break;
|
||||
|
||||
case TFProductionTypeAudio:
|
||||
url = Audio_Comment_List;
|
||||
parameters[@"audio_id"] = [TFUtilsHelper formatStringWithInteger:self.production_id] ? : @"";
|
||||
parameters[@"page_num"] = [TFUtilsHelper formatStringWithInteger:self.currentPageNumber];
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (self.chapter_id > 0) {
|
||||
[parameters setObject:[TFUtilsHelper formatStringWithInteger:self.chapter_id] ? : @"" forKey:@"chapter_id"];
|
||||
}
|
||||
|
||||
WS(weakSelf)
|
||||
[TFNetworkTools POST:url parameters:parameters model:TFCommentsModel.class success:^(BOOL isSuccess, TFCommentsModel *_Nullable t_model, TFNetworkRequestModel *requestModel) {
|
||||
|
||||
[weakSelf.mainTableView endRefreshing];
|
||||
|
||||
if (isSuccess) {
|
||||
if (weakSelf.currentPageNumber == 1) {
|
||||
[weakSelf.mainTableView showRefreshFooter];
|
||||
[weakSelf.dataSourceArray removeAllObjects];
|
||||
weakSelf.dataSourceArray = [NSMutableArray arrayWithArray:t_model.list];
|
||||
} else {
|
||||
[weakSelf.dataSourceArray addObjectsFromArray:t_model.list];
|
||||
}
|
||||
if (t_model.total_page <= t_model.current_page) {
|
||||
[weakSelf.mainTableView hideRefreshFooter];
|
||||
}
|
||||
|
||||
[weakSelf resetCommentTextViewPlaceHolder];
|
||||
|
||||
weakSelf.commentModel = t_model;
|
||||
} else {
|
||||
[weakSelf.mainTableView hideRefreshFooter];
|
||||
}
|
||||
|
||||
[weakSelf.mainTableView reloadData];
|
||||
[weakSelf.mainTableView xtfei_endLoading];
|
||||
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
|
||||
[weakSelf.mainTableView endRefreshing];
|
||||
[weakSelf.mainTableView xtfei_endLoading];
|
||||
[weakSelf.mainTableView hideRefreshFooter];
|
||||
[TFPromptManager showPromptWithError:error defaultText:nil];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)sendCommentNetRequest
|
||||
{
|
||||
if (!TFUserInfoManager.isLogin) {
|
||||
TFAlertView *alert = [[TFAlertView alloc] init];
|
||||
alert.alertDetailContent = TFLocalizedString(@"登录后才可以进行评论");
|
||||
alert.confirmTitle = TFLocalizedString(@"去登录");
|
||||
alert.cancelTitle = TFLocalizedString(@"暂不");
|
||||
alert.confirmButtonClickBlock = ^{
|
||||
[TFLoginOptionsViewController presentLoginView:nil];
|
||||
};
|
||||
[alert showAlertView];
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ([self.commentTextView.text isEqualToString:@""]) {
|
||||
return;
|
||||
}
|
||||
|
||||
NSString *t_text = self.commentTextView.text;
|
||||
self.commentTextView.text = @"";
|
||||
|
||||
NSString *url = @"";
|
||||
NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
|
||||
switch (self.productionType) {
|
||||
case TFProductionTypeNovel:
|
||||
url = Book_Comment_Post;
|
||||
parameters = [NSMutableDictionary dictionaryWithDictionary:@{@"book_id":[TFUtilsHelper formatStringWithInteger:self.production_id] ? : @"", @"content":t_text}];
|
||||
break;
|
||||
|
||||
case TFProductionTypeComic:
|
||||
url = Comic_Comment_Post;
|
||||
parameters = [NSMutableDictionary dictionaryWithDictionary:@{@"comic_id":[TFUtilsHelper formatStringWithInteger:self.production_id] ? : @"", @"content":t_text}];
|
||||
break;
|
||||
|
||||
case TFProductionTypeAudio:
|
||||
url = Audio_Comment_Post;
|
||||
parameters = [NSMutableDictionary dictionaryWithDictionary:@{@"audio_id":[TFUtilsHelper formatStringWithInteger:self.production_id] ? : @"", @"content":t_text}];
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (self.chapter_id > 0) {
|
||||
[parameters setObject:[TFUtilsHelper formatStringWithInteger:self.chapter_id] forKey:@"chapter_id"];
|
||||
}
|
||||
|
||||
if (self.comment_id && self.comment_id != 0) {
|
||||
[parameters setObject:[TFUtilsHelper formatStringWithInteger:self.comment_id] forKey:@"comment_id"];
|
||||
}
|
||||
|
||||
WS(weakSelf)
|
||||
[TFNetworkTools POST:url parameters:parameters model:TFCommentsListModel.class success:^(BOOL isSuccess, TFCommentsListModel *_Nullable t_model, TFNetworkRequestModel *requestModel) {
|
||||
if (isSuccess) {
|
||||
weakSelf.comment_id = 0;
|
||||
weakSelf.commentTextView.placeholder = TFLocalizedString(@"说点什么吧");
|
||||
|
||||
[TFPromptManager showPromptViewWithStatus:TFPromptStatusSuccess promptTitle:TFLocalizedString(@"评论成功")];
|
||||
|
||||
!weakSelf.commentsSuccessBlock ?: weakSelf.commentsSuccessBlock(t_model);
|
||||
|
||||
if (t_model) {
|
||||
[weakSelf.dataSourceArray insertObject:t_model atIndex:0];
|
||||
}
|
||||
|
||||
weakSelf.commentModel.total_count ++;
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:@"changeComment" object:[NSString stringWithFormat:@"%zd", weakSelf.commentModel.total_count]];
|
||||
|
||||
[weakSelf.mainTableView reloadData];
|
||||
[weakSelf.mainTableView xtfei_endLoading];
|
||||
|
||||
} else if (Compare_Json_isEqualTo(requestModel.code, 315)) {
|
||||
weakSelf.comment_id = 0;
|
||||
weakSelf.commentTextView.placeholder = TFLocalizedString(@"说点什么吧");
|
||||
[TFPromptManager showPromptViewWithStatus:TFPromptStatusSuccess promptTitle:requestModel.msg];
|
||||
} else if (Compare_Json_isEqualTo(requestModel.code, 318)) {
|
||||
weakSelf.commentTextView.text = @"";
|
||||
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:requestModel.msg];
|
||||
} else {
|
||||
weakSelf.commentTextView.text = t_text;
|
||||
[TFPromptManager showPromptViewWithStatus:TFPromptStatusError promptTitle:requestModel.msg];
|
||||
}
|
||||
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
|
||||
[TFPromptManager showPromptWithError:error defaultText:TFLocalizedString(@"评论失败")];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)popViewController
|
||||
{
|
||||
[super popViewController];
|
||||
|
||||
[self dismissViewControllerAnimated:YES completion:nil];
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user