动态评论
This commit is contained in:
@@ -12,6 +12,8 @@
|
||||
///Tool
|
||||
#import "XPMonentsLayoutConfig.h"
|
||||
#import "ThemeColor.h"
|
||||
#import "QEmotionHelper.h"
|
||||
#import "QKeyboardManager.h"
|
||||
///Model
|
||||
#import "MonentsInfoModel.h"
|
||||
#import "MonentsCommentModel.h"
|
||||
@@ -19,11 +21,14 @@
|
||||
#import "XPMonentsTableViewCell.h"
|
||||
#import "XPMonentsCommentTableViewCell.h"
|
||||
#import "XPMonentsEmptyTableViewCell.h"
|
||||
#import "QInputBarView.h"
|
||||
#import "QKeyboardManager.h"
|
||||
#import "QEmotionBoardView.h"
|
||||
///P
|
||||
#import "XPMonentDetailPresenter.h"
|
||||
#import "XPMonentsDetailProtocol.h"
|
||||
|
||||
@interface XPMonentsDetailViewController ()<UITableViewDelegate, UITableViewDataSource, XPMonentsDetailProtocol, XPMonentsCommentTableViewCellDelegate, XPMonentsTableViewCellDelegate>
|
||||
@interface XPMonentsDetailViewController ()<UITableViewDelegate, UITableViewDataSource, XPMonentsDetailProtocol, XPMonentsCommentTableViewCellDelegate, XPMonentsTableViewCellDelegate, QInputBarViewDelegate, QInputBarViewDataSource,InputBoardDataSource ,InputBoardDelegate , QEmotionBoardViewDelegate>
|
||||
///列表
|
||||
@property (nonatomic,strong) UITableView *tableView;
|
||||
///数据源
|
||||
@@ -32,6 +37,10 @@
|
||||
@property (nonatomic,strong) UIView * sectionView;
|
||||
///评论的个数
|
||||
@property (nonatomic,strong) UILabel *commentLabel;
|
||||
@property(nonatomic,strong)QInputBarView *inputBarView;
|
||||
@property(nonatomic,strong)QKeyboardManager *keyboardManager;
|
||||
///当前选中的评论信息
|
||||
@property (nonatomic,strong) MonentsCommentModel *selectCommonInfo;
|
||||
@end
|
||||
|
||||
@implementation XPMonentsDetailViewController
|
||||
@@ -80,15 +89,52 @@
|
||||
|
||||
|
||||
#pragma mark - Private Method
|
||||
- (void)initInputView {
|
||||
// 初始化输入工具条,frame可以先这样临时设置,下面的addBottomInputBarView方法会重置输入条frame
|
||||
// 如果你想要自定义输入条View,请参考TextFieldViewController代码
|
||||
_inputBarView = [[QInputBarView alloc] initWithFrame:CGRectMake(0,0,self.view.frame.size.width,UIInputBarViewMinHeight)];
|
||||
QInputBarViewConfiguration *inputBarViewConfiguration = [QInputBarViewConfiguration defaultInputBarViewConfiguration];
|
||||
inputBarViewConfiguration.voiceButtonHidden = YES;//隐藏语音按钮
|
||||
inputBarViewConfiguration.extendButtonHidden = YES;//隐藏拓展按钮
|
||||
[_inputBarView setupWithConfiguration:inputBarViewConfiguration];
|
||||
_inputBarView.delegate = self;
|
||||
|
||||
//keyboard管理类,用来管理键盘,各大面板的切换
|
||||
_keyboardManager = [[QKeyboardManager alloc] initWithViewController:self];
|
||||
_keyboardManager.dataSource = self;
|
||||
//因为addBottomInputBarView方法会立刻触发delegate,所以这里需要先设置delegate
|
||||
_keyboardManager.delegate = self;
|
||||
[_keyboardManager addBottomInputBarView:_inputBarView belowViewController:NO];
|
||||
|
||||
//把输入框(如果有的话)绑定给管理类
|
||||
[_keyboardManager bindTextView:_inputBarView.inputTextView];
|
||||
}
|
||||
|
||||
- (void)sendTextMessage:(NSString *)inputText {
|
||||
if (inputText.length > 0) {
|
||||
[_keyboardManager hideAllBoardView];
|
||||
if (self.selectCommonInfo && self.selectCommonInfo.commentId.length > 0) {
|
||||
[self.presenter replayCommon:self.selectCommonInfo.commentId dynamicId:self.monentsInfo.dynamicId content:inputText];
|
||||
} else {
|
||||
[self.presenter commontMonents:self.monentsInfo.dynamicId content:inputText];
|
||||
}
|
||||
self.inputBarView.inputTextView.text = nil;
|
||||
} else {
|
||||
[self showErrorToast:@"请输入您要评论的内容"];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)initSubViews {
|
||||
self.title = @"详情";
|
||||
[self.view addSubview:self.tableView];
|
||||
[self.sectionView addSubview:self.commentLabel];
|
||||
[self initInputView];
|
||||
}
|
||||
|
||||
- (void)initSubViewConstraints {
|
||||
[self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.edges.mas_equalTo(self.view);
|
||||
make.left.right.top.mas_equalTo(self.view);
|
||||
make.bottom.mas_equalTo(self.view).offset(-UIInputBarViewMinHeight);
|
||||
}];
|
||||
|
||||
[self.commentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
@@ -163,6 +209,22 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
[tableView deselectRowAtIndexPath:indexPath animated:YES];
|
||||
if (indexPath.section == 1) {
|
||||
if (self.datasource.count > 0) {
|
||||
MonentsCommentModel* monent = [self.datasource objectAtIndex:indexPath.row];
|
||||
self.selectCommonInfo = monent;
|
||||
self.inputBarView.inputTextView.placeholder = [NSString stringWithFormat:@"回复: %@", monent.nick];
|
||||
[self.inputBarView textViewBecomeFirstResponder];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
|
||||
[_keyboardManager hideAllBoardView];
|
||||
}
|
||||
|
||||
#pragma mark - XPMonentsCommentTableViewCellDelegate
|
||||
- (void)xPMonentsCommentTableViewCell:(XPMonentsCommentTableViewCell *)view didClickMoreReply:(MonentsCommentModel *)commentInfo {
|
||||
[self.presenter getMonentsCommentReplyList:self.monentsInfo.dynamicId commentId:commentInfo.commentId timestamp:commentInfo.replyInfo.nextTimestamp];
|
||||
@@ -173,6 +235,92 @@
|
||||
[self.presenter likeMonent:monentsInfo.dynamicId status:!monentsInfo.isLike likedUid:monentsInfo.uid worldId:[NSString stringWithFormat:@"%ld", monentsInfo.worldId]];
|
||||
}
|
||||
|
||||
#pragma mark - InputBoardDataSource
|
||||
//@return 点加号按钮弹出的拓展面板View,且无需设置frame
|
||||
- (UIView *)keyboardManagerExtendBoardView:(QKeyboardManager *)keyboardManager {
|
||||
UIView *boardView = [UIView new];
|
||||
boardView.backgroundColor = UIColor.blueColor;
|
||||
return boardView;
|
||||
}
|
||||
|
||||
//@return 点表情按钮弹出的表情面板View,且无需设置frame
|
||||
- (UIView *)keyboardManagerEmotionBoardView:(QKeyboardManager *)keyboardManager {
|
||||
QEmotionBoardView *emotionView = [[QEmotionBoardView alloc] init];
|
||||
QEmotionHelper *faceManager = [QEmotionHelper sharedEmotionHelper];
|
||||
emotionView.emotions = faceManager.emotionArray;
|
||||
emotionView.delegate = self;
|
||||
if (@available(iOS 11.0, *)) {
|
||||
NSBundle *bundle = [NSBundle bundleForClass:[self class]];
|
||||
emotionView.backgroundColor = [UIColor colorNamed:@"q_input_extend_bg" inBundle:bundle compatibleWithTraitCollection:nil];
|
||||
} else {
|
||||
emotionView.backgroundColor = [UIColor colorWithRed:(246)/255.0f green:(246)/255.0f blue:(246)/255.0f alpha:1];
|
||||
}
|
||||
return emotionView;
|
||||
}
|
||||
|
||||
//@return 点表情按钮弹出的表情面板View的高度
|
||||
- (CGFloat)keyboardManagerEmotionBoardHeight:(QKeyboardManager *)keyboardManager {
|
||||
return 294;
|
||||
}
|
||||
|
||||
//@return 点加号按钮弹出的拓展面板View的高度
|
||||
- (CGFloat)keyboardManagerExtendBoardHeight:(QKeyboardManager *)keyboardManager {
|
||||
return 174;
|
||||
}
|
||||
|
||||
- (QInputBarViewConfiguration *)inputBarViewConfiguration {
|
||||
//输入条配置,子类可以重写
|
||||
QInputBarViewConfiguration *inputBarViewConfiguration = [QInputBarViewConfiguration defaultInputBarViewConfiguration];
|
||||
inputBarViewConfiguration.voiceButtonHidden = YES;//隐藏语音按钮
|
||||
inputBarViewConfiguration.extendButtonHidden = YES;//隐藏拓展按钮
|
||||
return inputBarViewConfiguration;
|
||||
}
|
||||
|
||||
//点击表情按钮,切换到表情面板
|
||||
- (void)inputBarView:(QInputBarView *)inputBarView onEmotionButtonClick:(UIButton *)emotionSwitchButton {
|
||||
if (emotionSwitchButton.isSelected) {
|
||||
[_keyboardManager switchToEmotionBoardKeyboard];
|
||||
} else {
|
||||
self.selectCommonInfo = nil;
|
||||
_inputBarView.inputTextView.placeholder = @"发表评论";
|
||||
[_inputBarView textViewBecomeFirstResponder];
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - QEmotionBoardViewDelegate
|
||||
/**
|
||||
* 选中表情时的回调
|
||||
* @param index 被选中的表情在`emotions`里的索引
|
||||
* @param emotion 被选中的表情对应的`QMUIEmotion`对象
|
||||
*/
|
||||
- (void)emotionView:(QEmotionBoardView *)emotionView didSelectEmotion:(QEmotion *)emotion atIndex:(NSInteger)index {
|
||||
//把😊插入到输入栏
|
||||
[_inputBarView insertEmotion:emotion.displayName];
|
||||
}
|
||||
|
||||
// 删除按钮的点击事件回调
|
||||
- (void)emotionViewDidSelectDeleteButton:(QEmotionBoardView *)emotionView {
|
||||
if (![_inputBarView deleteEmotion]){
|
||||
//根据当前的光标,这次点击删除按钮并没有删除表情,那么就删除文字
|
||||
[_inputBarView.inputTextView deleteBackward];
|
||||
}
|
||||
}
|
||||
|
||||
// 发送按钮的点击事件回调
|
||||
- (void)emotionViewDidSelectSendButton:(QEmotionBoardView *)emotionView {
|
||||
[self sendTextMessage:[_inputBarView textViewInputNormalText]];
|
||||
}
|
||||
|
||||
|
||||
#pragma mark -
|
||||
/**
|
||||
* 点击了系统键盘的发送按钮
|
||||
* @param inputNormalText :"害~你好啊[微笑]"
|
||||
*/
|
||||
- (void)inputBarView:(QInputBarView *)inputBarView onKeyboardSendClick:(NSString *)inputNormalText {
|
||||
[self sendTextMessage:inputNormalText];
|
||||
}
|
||||
|
||||
#pragma mark - XPMonentsDetailProtocol
|
||||
- (void)getMonentsDetailSuccess:(MonentsInfoModel *)commentInfo {
|
||||
self.monentsInfo = commentInfo;
|
||||
@@ -229,6 +377,14 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (void)replyMonentsSuccess {
|
||||
[self.presenter getMonentsCommentList:self.monentsInfo.dynamicId timestamp:@"" status:0];
|
||||
}
|
||||
|
||||
- (void)commonMonentsSuccess {
|
||||
[self.presenter getMonentsCommentList:self.monentsInfo.dynamicId timestamp:@"" status:0];
|
||||
}
|
||||
|
||||
|
||||
#pragma mark - Getters And Setters
|
||||
- (UITableView *)tableView {
|
||||
|
Reference in New Issue
Block a user