Files
yinmeng-ios/xplan-ios/Main/Monents/View/XPMonentsDetailViewController.m

468 lines
17 KiB
Mathematica
Raw Normal View History

2022-06-22 20:38:57 +08:00
//
// XPMonentsDetailViewController.m
// xplan-ios
//
// Created by on 2022/6/22.
//
#import "XPMonentsDetailViewController.h"
///Third
#import <Masonry/Masonry.h>
#import <MJRefresh/MJRefresh.h>
///Tool
#import "XPMonentsLayoutConfig.h"
#import "ThemeColor.h"
2022-08-17 18:55:45 +08:00
#import "QEmotionHelper.h"
#import "QKeyboardManager.h"
2022-08-25 21:17:23 +08:00
#import "TTPopup.h"
2022-06-22 20:38:57 +08:00
///Model
#import "MonentsInfoModel.h"
#import "MonentsCommentModel.h"
2022-08-25 21:17:23 +08:00
#import "MonentsCommentReplyModel.h"
2022-06-22 20:38:57 +08:00
///View
#import "XPMonentsTableViewCell.h"
#import "XPMonentsCommentTableViewCell.h"
#import "XPMonentsEmptyTableViewCell.h"
2022-08-17 18:55:45 +08:00
#import "QInputBarView.h"
#import "QKeyboardManager.h"
#import "QEmotionBoardView.h"
2022-06-22 20:38:57 +08:00
///P
#import "XPMonentDetailPresenter.h"
#import "XPMonentsDetailProtocol.h"
2022-08-17 18:55:45 +08:00
@interface XPMonentsDetailViewController ()<UITableViewDelegate, UITableViewDataSource, XPMonentsDetailProtocol, XPMonentsCommentTableViewCellDelegate, XPMonentsTableViewCellDelegate, QInputBarViewDelegate, QInputBarViewDataSource,InputBoardDataSource ,InputBoardDelegate , QEmotionBoardViewDelegate>
2022-06-22 20:38:57 +08:00
///
@property (nonatomic,strong) UITableView *tableView;
///
2022-06-24 18:51:04 +08:00
@property (nonatomic,strong) NSMutableArray<MonentsCommentModel *> *datasource;
///view
@property (nonatomic,strong) UIView * sectionView;
///
@property (nonatomic,strong) UILabel *commentLabel;
2022-08-17 18:55:45 +08:00
@property(nonatomic,strong)QInputBarView *inputBarView;
@property(nonatomic,strong)QKeyboardManager *keyboardManager;
///
2022-08-25 21:17:23 +08:00
@property (nonatomic,strong) NSString *commentId;
2022-06-22 20:38:57 +08:00
@end
@implementation XPMonentsDetailViewController
- (__kindof id)createPresenter {
return [[XPMonentDetailPresenter alloc] init];
}
- (void)viewDidLoad {
[super viewDidLoad];
[self initHeaderAndFooterRrfresh];
[self initSubViews];
[self initSubViewConstraints];
}
#pragma mark -
- (void)initHeaderAndFooterRrfresh {
MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(headerRefresh)];
header.stateLabel.font = [UIFont systemFontOfSize:10.0];
header.lastUpdatedTimeLabel.font = [UIFont systemFontOfSize:10.0];
header.stateLabel.textColor = [ThemeColor secondTextColor];
header.lastUpdatedTimeLabel.textColor = [ThemeColor secondTextColor];
self.tableView.mj_header = header;
MJRefreshBackNormalFooter *footer = [MJRefreshBackNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(footerRefresh)];
footer.stateLabel.textColor = [ThemeColor secondTextColor];
footer.stateLabel.font = [UIFont systemFontOfSize:10.0];
self.tableView.mj_footer = footer;
[self headerRefresh];
}
- (void)headerRefresh {
[self.presenter getMonentsDetail:self.monentsInfo.dynamicId];
[self.presenter getMonentsCommentList:self.monentsInfo.dynamicId timestamp:@"" status:0];
}
- (void)footerRefresh {
NSString *timestamp = @"";
if (self.datasource.count > 0) {
MonentsCommentModel * commentInfo = [self.datasource lastObject];
timestamp = commentInfo.publishTime;
}
2022-06-24 18:51:04 +08:00
[self.presenter getMonentsCommentList:self.monentsInfo.dynamicId timestamp:timestamp status:1];
2022-06-22 20:38:57 +08:00
}
#pragma mark - Private Method
2022-08-17 18:55:45 +08:00
- (void)initInputView {
// frameaddBottomInputBarViewframe
// ViewTextFieldViewController
_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;
//addBottomInputBarViewdelegatedelegate
_keyboardManager.delegate = self;
[_keyboardManager addBottomInputBarView:_inputBarView belowViewController:NO];
//
[_keyboardManager bindTextView:_inputBarView.inputTextView];
}
- (void)sendTextMessage:(NSString *)inputText {
if (inputText.length > 0) {
[_keyboardManager hideAllBoardView];
2022-08-25 21:17:23 +08:00
if (self.commentId && self.commentId.length > 0) {
[self.presenter replayCommon:self.commentId dynamicId:self.monentsInfo.dynamicId content:inputText];
2022-08-17 18:55:45 +08:00
} else {
[self.presenter commontMonents:self.monentsInfo.dynamicId content:inputText];
}
self.inputBarView.inputTextView.text = nil;
} else {
[self showErrorToast:@"请输入您要评论的内容"];
}
}
2022-06-22 20:38:57 +08:00
- (void)initSubViews {
self.title = @"详情";
[self.view addSubview:self.tableView];
2022-06-24 18:51:04 +08:00
[self.sectionView addSubview:self.commentLabel];
2022-08-17 18:55:45 +08:00
[self initInputView];
2022-06-22 20:38:57 +08:00
}
- (void)initSubViewConstraints {
[self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
2022-08-17 18:55:45 +08:00
make.left.right.top.mas_equalTo(self.view);
make.bottom.mas_equalTo(self.view).offset(-UIInputBarViewMinHeight);
2022-06-22 20:38:57 +08:00
}];
2022-06-24 18:51:04 +08:00
[self.commentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.sectionView).offset(15);
make.centerY.mas_equalTo(self.sectionView);
}];
2022-06-22 20:38:57 +08:00
}
#pragma mark - UITableViewDelegate And UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (section == 0) {
return 1;
}
return self.datasource.count > 0 ? self.datasource.count : 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 0) {
[XPMonentsLayoutConfig layoutMonentsModel:self.monentsInfo];
return self.monentsInfo.rowHeight;
} else if(indexPath.section == 1) {
if (self.datasource.count > 0) {
MonentsCommentModel * commentInfo = [self.datasource objectAtIndex:indexPath.row];
return [XPMonentsLayoutConfig commentCommentRowHeight:commentInfo];
} else {
return 400;
}
}
return 0;
}
2022-06-24 18:51:04 +08:00
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
if (section == 1) {
return 44;
}
return 0.0;;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
self.commentLabel.text = [NSString stringWithFormat:@"所有评论(%@)", self.monentsInfo.commentCount];
return self.sectionView;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return 0.0f;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
return [UIView new];
}
2022-06-22 20:38:57 +08:00
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section ==0) {
XPMonentsTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPMonentsTableViewCell class])];
2022-06-27 20:04:54 +08:00
cell.delegate = self;
2022-06-22 20:38:57 +08:00
cell.monentsInfo = self.monentsInfo;
return cell;
} else {
if (self.datasource.count > 0) {
XPMonentsCommentTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPMonentsCommentTableViewCell class])];
cell.commentInfo = [self.datasource objectAtIndex:indexPath.row];
2022-06-24 18:51:04 +08:00
cell.delegate = self;
2022-06-22 20:38:57 +08:00
return cell;
} else {
XPMonentsEmptyTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([XPMonentsEmptyTableViewCell class])];
return cell;
}
}
}
2022-08-17 18:55:45 +08:00
- (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];
2022-08-25 21:17:23 +08:00
self.commentId = monent.commentId;
2022-08-17 18:55:45 +08:00
self.inputBarView.inputTextView.placeholder = [NSString stringWithFormat:@"回复: %@", monent.nick];
[self.inputBarView textViewBecomeFirstResponder];
}
}
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
[_keyboardManager hideAllBoardView];
}
2022-06-24 18:51:04 +08:00
#pragma mark - XPMonentsCommentTableViewCellDelegate
- (void)xPMonentsCommentTableViewCell:(XPMonentsCommentTableViewCell *)view didClickMoreReply:(MonentsCommentModel *)commentInfo {
[self.presenter getMonentsCommentReplyList:self.monentsInfo.dynamicId commentId:commentInfo.commentId timestamp:commentInfo.replyInfo.nextTimestamp];
}
2022-08-25 21:17:23 +08:00
- (void)xPMonentsCommentTableViewCell:(XPMonentsCommentTableViewCell *)view didClickCommon:(MonentsReplyModel *)commentInfo {
if (commentInfo) {
self.commentId = commentInfo.replyId;
self.inputBarView.inputTextView.placeholder = [NSString stringWithFormat:@"回复: %@", commentInfo.nick];
[self.inputBarView textViewBecomeFirstResponder];
}
}
2022-06-27 20:04:54 +08:00
#pragma mark - XPMonentsTableViewCellDelegate
- (void)xPMonentsTableViewCell:(XPMonentsTableViewCell *)view didClickLike:(MonentsInfoModel *)monentsInfo {
[self.presenter likeMonent:monentsInfo.dynamicId status:!monentsInfo.isLike likedUid:monentsInfo.uid worldId:[NSString stringWithFormat:@"%ld", monentsInfo.worldId]];
}
2022-08-24 15:51:41 +08:00
- (void)xPMonentsTableViewCell:(XPMonentsTableViewCell *)view didClicDelete:(MonentsInfoModel *)monentsInfo {
2022-08-25 21:17:23 +08:00
[TTPopup alertWithMessage:@"删除后不可恢复\n确定删除该动态吗" confirmHandler:^{
[self.presenter deleteMonents:monentsInfo.dynamicId worldId:[NSString stringWithFormat:@"%ld", monentsInfo.worldId]];
} cancelHandler:^{
}];
}
- (void)xPMonentsTableViewCell:(XPMonentsTableViewCell *)view didClicCommon:(MonentsInfoModel *)monentsInfo {
if (monentsInfo) {
self.commentId = nil;
self.inputBarView.inputTextView.placeholder = @"发表评论";
[self.inputBarView textViewBecomeFirstResponder];
}
2022-08-24 15:51:41 +08:00
}
2022-08-17 18:55:45 +08:00
#pragma mark - InputBoardDataSource
//@return Viewframe
- (UIView *)keyboardManagerExtendBoardView:(QKeyboardManager *)keyboardManager {
UIView *boardView = [UIView new];
boardView.backgroundColor = UIColor.blueColor;
return boardView;
}
//@return Viewframe
- (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 {
2022-08-25 21:17:23 +08:00
self.commentId = nil;
2022-08-17 18:55:45 +08:00
_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];
}
2022-06-22 20:38:57 +08:00
#pragma mark - XPMonentsDetailProtocol
- (void)getMonentsDetailSuccess:(MonentsInfoModel *)commentInfo {
self.monentsInfo = commentInfo;
[self.tableView reloadData];
}
- (void)getMonentsCommentListSuccess:(MonentsCommentListModel *)commentInfo state:(int)state{
if (state == 0) {
[self.datasource removeAllObjects];
[self.tableView.mj_header endRefreshing];
} else {
[self.tableView.mj_footer endRefreshing];
}
if (commentInfo.commentList.count > 0) {
[self.datasource addObjectsFromArray:commentInfo.commentList];
}
[self.tableView reloadData];
}
2022-06-24 18:51:04 +08:00
- (void)getMonentsCommentReplyListSuccess:(MonentsCommentReplyModel *)replyInfo commentId:(nonnull NSString *)commentId {
if (commentId) {
__block MonentsCommentModel * commentInfo;
[self.datasource enumerateObjectsUsingBlock:^(MonentsCommentModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if ([obj.commentId isEqualToString:commentId]) {
commentInfo = obj;
*stop = YES;
}
}];
if (commentInfo) {
NSMutableArray * replyList= commentInfo.replyInfo.replyList.mutableCopy;
[replyList addObjectsFromArray:replyInfo.replyList];
commentInfo.replyInfo.replyList = replyList.copy;
commentInfo.replyInfo.leftCount = replyInfo.leftCount;
commentInfo.replyInfo.nextTimestamp = replyInfo.nextTimestamp;
commentInfo.isReloadHeight = YES;
}
[self.tableView reloadData];
}
}
2022-06-27 20:04:54 +08:00
- (void)likeMonentsSuccess:(NSString *)dynamicId status:(BOOL)status {
if ([self.monentsInfo.dynamicId isEqualToString:dynamicId]) {
NSInteger count = self.monentsInfo.likeCount.integerValue;
self.monentsInfo.isLike = status;
if (status) {
count += 1;
} else {
count -= 1;
}
self.monentsInfo.likeCount = [NSString stringWithFormat:@"%ld", count];
[self.tableView reloadData];
}
}
2022-08-17 18:55:45 +08:00
- (void)replyMonentsSuccess {
[self.presenter getMonentsCommentList:self.monentsInfo.dynamicId timestamp:@"" status:0];
}
- (void)commonMonentsSuccess {
[self.presenter getMonentsCommentList:self.monentsInfo.dynamicId timestamp:@"" status:0];
}
2022-08-24 15:51:41 +08:00
- (void)deleteMonentsSuccess:(NSString *)monentsInfo {
[self showSuccessToast:@"删除成功"];
[self.navigationController popViewControllerAnimated:YES];
2022-08-25 21:17:23 +08:00
if (self.delegate && [self.delegate respondsToSelector:@selector(xPMonentsDetailViewController:deleteMonents:)]) {
[self.delegate xPMonentsDetailViewController:self deleteMonents:self.monentsInfo.dynamicId];
}
2022-08-24 15:51:41 +08:00
}
2022-06-27 20:04:54 +08:00
2022-06-22 20:38:57 +08:00
#pragma mark - Getters And Setters
- (UITableView *)tableView {
if (!_tableView) {
2022-06-24 18:51:04 +08:00
_tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
2022-06-22 20:38:57 +08:00
_tableView.delegate = self;
_tableView.dataSource = self;
_tableView.tableFooterView = [UIView new];
2022-06-24 18:51:04 +08:00
_tableView.tableFooterView = [UIView new];
2022-06-22 20:38:57 +08:00
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
_tableView.backgroundColor = [UIColor clearColor];
if (@available(iOS 11.0, *)) {
_tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}
[_tableView registerClass:[XPMonentsTableViewCell class] forCellReuseIdentifier:NSStringFromClass([XPMonentsTableViewCell class])];
[_tableView registerClass:[XPMonentsCommentTableViewCell class] forCellReuseIdentifier:NSStringFromClass([XPMonentsCommentTableViewCell class])];
[_tableView registerClass:[XPMonentsEmptyTableViewCell class] forCellReuseIdentifier:NSStringFromClass([XPMonentsEmptyTableViewCell class])];
2022-06-24 18:51:04 +08:00
}
2022-06-22 20:38:57 +08:00
return _tableView;
}
2022-06-24 18:51:04 +08:00
- (UIView *)sectionView {
if (!_sectionView) {
_sectionView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 44)];
_sectionView.backgroundColor = [UIColor clearColor];
}
return _sectionView;
}
- (UILabel *)commentLabel {
if (!_commentLabel) {
_commentLabel = [[UILabel alloc] init];
_commentLabel.font = [UIFont systemFontOfSize:14];
_commentLabel.textColor = [ThemeColor mainTextColor];
}
return _commentLabel;
}
2022-06-22 20:38:57 +08:00
- (NSMutableArray *)datasource {
if (!_datasource) {
_datasource = [NSMutableArray array];
}
return _datasource;
}
@end