2025-08-08 10:49:36 +08:00
|
|
|
//
|
|
|
|
|
// QXDynamicDetailViewController.m
|
|
|
|
|
// QXLive
|
|
|
|
|
//
|
|
|
|
|
// Created by 启星 on 2025/6/4.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#import "QXDynamicDetailViewController.h"
|
|
|
|
|
#import "QXDynamicListCell.h"
|
|
|
|
|
#import "QXDynamicNetwork.h"
|
|
|
|
|
#import "QXDynamicCommentCell.h"
|
|
|
|
|
#import "QXDynamicCommentHeaderView.h"
|
|
|
|
|
#import "QXDynamicCommentInputView.h"
|
|
|
|
|
#import "QXAlertView.h"
|
|
|
|
|
|
|
|
|
|
@interface QXDynamicDetailViewController ()<UITableViewDelegate,UITableViewDataSource,QXDynamicCommentHeaderViewDelegate,QXDynamicCommentInputViewDelegate>
|
|
|
|
|
@property (nonatomic,strong)UITableView *tableView;
|
|
|
|
|
@property (nonatomic,strong)QXDynamicModel *detailModel;
|
|
|
|
|
@property (nonatomic,strong)QXDynamicCommentModel *commentModel;
|
|
|
|
|
|
|
|
|
|
@property (nonatomic,strong)QXDynamicCommentInputView *commentView;
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@implementation QXDynamicDetailViewController
|
|
|
|
|
|
|
|
|
|
- (void)viewDidLoad {
|
|
|
|
|
[super viewDidLoad];
|
|
|
|
|
// Do any additional setup after loading the view.
|
|
|
|
|
}
|
|
|
|
|
-(void)viewWillAppear:(BOOL)animated{
|
|
|
|
|
[super viewWillAppear:animated];
|
|
|
|
|
[self.navigationController setNavigationBarHidden:NO animated:YES];
|
|
|
|
|
}
|
|
|
|
|
-(void)viewWillDisappear:(BOOL)animated{
|
|
|
|
|
[super viewWillDisappear:animated];
|
|
|
|
|
[self.commentView.textField resignFirstResponder];
|
|
|
|
|
}
|
|
|
|
|
-(void)setNavgationItems{
|
|
|
|
|
[super setNavgationItems];
|
|
|
|
|
self.navigationItem.title = QXText(@"动态详情");
|
|
|
|
|
}
|
|
|
|
|
-(void)initSubViews{
|
|
|
|
|
[self.view addSubview:self.tableView];
|
|
|
|
|
[self.view addSubview:self.commentView];
|
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
|
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
|
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-(void)getData{
|
|
|
|
|
self.page = 1;
|
|
|
|
|
MJWeakSelf
|
|
|
|
|
[QXDynamicNetwork dynamicPageWithId:self.model.id successBlock:^(QXDynamicModel * _Nonnull model) {
|
|
|
|
|
weakSelf.detailModel = model;
|
|
|
|
|
// [weakSelf.tableView reloadSection:0 withRowAnimation:(UITableViewRowAnimationNone)];
|
|
|
|
|
[weakSelf.tableView reloadData];
|
|
|
|
|
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
|
|
|
|
|
|
|
|
|
|
}];
|
|
|
|
|
[self getCommentListIsReload:YES];
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
-(void)getCommentListIsReload:(BOOL)isReload{
|
|
|
|
|
MJWeakSelf
|
|
|
|
|
[QXDynamicNetwork commentListWithId:self.model.id page:self.page successBlock:^(QXDynamicCommentModel *model) {
|
|
|
|
|
if (isReload) {
|
|
|
|
|
[weakSelf.dataArray removeAllObjects];
|
|
|
|
|
}
|
|
|
|
|
[weakSelf.dataArray addObjectsFromArray:model.list];
|
|
|
|
|
if (model.list.count == 0) {
|
|
|
|
|
weakSelf.tableView.mj_footer.state = MJRefreshStateNoMoreData;
|
|
|
|
|
}else{
|
|
|
|
|
[weakSelf.tableView.mj_footer endRefreshing];
|
|
|
|
|
}
|
|
|
|
|
weakSelf.commentModel = model;
|
|
|
|
|
weakSelf.detailModel.comment_num = model.total;
|
|
|
|
|
[weakSelf.tableView reloadData];
|
|
|
|
|
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
|
|
|
|
|
[weakSelf.tableView.mj_footer endRefreshing];
|
|
|
|
|
}];
|
|
|
|
|
}
|
|
|
|
|
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
|
|
|
|
|
return self.dataArray.count + 1;
|
|
|
|
|
}
|
|
|
|
|
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
|
|
|
|
|
if (section == 0) {
|
|
|
|
|
return 1;
|
|
|
|
|
}else{
|
|
|
|
|
QXDynamicCommentListModel *firsModel = self.dataArray[section-1];
|
|
|
|
|
return firsModel.replies.count;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
|
|
|
|
|
MJWeakSelf
|
|
|
|
|
if (indexPath.section == 0) {
|
|
|
|
|
QXDynamicListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"QXDynamicListCell" forIndexPath:indexPath];
|
|
|
|
|
cell.selectionStyle = NO;
|
|
|
|
|
cell.cellType = QXDynamicListCellDetail;
|
|
|
|
|
cell.model = self.detailModel?self.detailModel:self.model;
|
|
|
|
|
|
|
|
|
|
cell.onDeleteBlock = ^(QXDynamicModel * _Nonnull model) {
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
return cell;
|
|
|
|
|
}else{
|
|
|
|
|
QXDynamicCommentCell *cell = [QXDynamicCommentCell cellWithTableView:tableView];
|
|
|
|
|
QXDynamicCommentListModel *firsModel = self.dataArray[indexPath.section-1];
|
|
|
|
|
QXDynamicCommentListModel *model = firsModel.replies[indexPath.row];
|
|
|
|
|
if (firsModel.replies.count == 1 && indexPath.row == 0) {
|
|
|
|
|
cell.topCornerView.layer.cornerRadius = 12;
|
|
|
|
|
cell.bottomCornerView.layer.cornerRadius = 12;
|
|
|
|
|
}else{
|
|
|
|
|
if (indexPath.row == 0) {
|
|
|
|
|
cell.topCornerView.layer.cornerRadius = 12;
|
|
|
|
|
cell.bottomCornerView.layer.cornerRadius = 0;
|
|
|
|
|
}else if (indexPath.row == firsModel.replies.count-1){
|
|
|
|
|
cell.topCornerView.layer.cornerRadius = 0;
|
|
|
|
|
cell.bottomCornerView.layer.cornerRadius = 12;
|
|
|
|
|
}else{
|
|
|
|
|
cell.topCornerView.layer.cornerRadius = 0;
|
|
|
|
|
cell.bottomCornerView.layer.cornerRadius = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
cell.model = model;
|
|
|
|
|
cell.longPressBlock = ^(QXDynamicCommentListModel * _Nonnull model) {
|
|
|
|
|
UIAlertController *al = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:(UIAlertControllerStyleActionSheet)];
|
|
|
|
|
if ([model.user_id isEqualToString:[QXGlobal shareGlobal].loginModel.user_id]) {
|
|
|
|
|
[al addAction:[UIAlertAction actionWithTitle:QXText(@"删除") style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
|
|
|
|
|
[weakSelf didClickDeleteComment:model];
|
|
|
|
|
}]];
|
|
|
|
|
}
|
|
|
|
|
[al addAction:[UIAlertAction actionWithTitle:QXText(@"复制") style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
|
|
|
|
|
UIPasteboard *p = [UIPasteboard generalPasteboard];
|
|
|
|
|
p.string = [NSString stringWithFormat:@"%@", model.content];
|
|
|
|
|
showToast(@"已复制");
|
|
|
|
|
}]];
|
|
|
|
|
[al addAction:[UIAlertAction actionWithTitle:QXText(@"取消") style:(UIAlertActionStyleCancel) handler:^(UIAlertAction * _Nonnull action) {
|
|
|
|
|
|
|
|
|
|
}]];
|
|
|
|
|
[weakSelf presentViewController:al animated:YES completion:nil];
|
|
|
|
|
};
|
|
|
|
|
return cell;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
|
|
|
|
|
if (section == 0) {
|
|
|
|
|
return [UIView new];
|
|
|
|
|
}else{
|
|
|
|
|
MJWeakSelf
|
|
|
|
|
QXDynamicCommentListModel *firsModel = self.dataArray[section-1];
|
|
|
|
|
CGFloat height = [firsModel.content heightForFont:[UIFont systemFontOfSize:14] width:SCREEN_WIDTH-40-16*2-7];
|
|
|
|
|
QXDynamicCommentHeaderView *header = [[QXDynamicCommentHeaderView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, height+12+40+7+3+9)];
|
|
|
|
|
[header addTapBlock:^(id _Nonnull obj) {
|
2025-10-20 09:43:10 +08:00
|
|
|
// weakSelf.commentView.model = firsModel;
|
|
|
|
|
// weakSelf.commentView.textField.placeholder = [NSString stringWithFormat:@"回复:%@",firsModel.nickname];
|
|
|
|
|
// [weakSelf.commentView.textField becomeFirstResponder];
|
|
|
|
|
UIPasteboard *p = [UIPasteboard generalPasteboard];
|
|
|
|
|
p.string = [NSString stringWithFormat:@"%@", firsModel.content];
|
|
|
|
|
showToast(@"已复制");
|
2025-08-08 10:49:36 +08:00
|
|
|
}];
|
|
|
|
|
header.delegate = self;
|
|
|
|
|
header.model = firsModel;
|
|
|
|
|
return header;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
|
|
|
|
|
if (section == 0) {
|
|
|
|
|
UIView *footer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 64)];
|
|
|
|
|
footer.backgroundColor = RGB16(0xF6F6F6);
|
|
|
|
|
UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 30, SCREEN_WIDTH, 34)];
|
|
|
|
|
bgView.backgroundColor = [UIColor whiteColor];
|
|
|
|
|
[bgView addRoundedCornersWithRadius:16 byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerTopRight)];
|
|
|
|
|
[footer addSubview:bgView];
|
|
|
|
|
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(16, 12, SCREEN_WIDTH-32, 22)];
|
|
|
|
|
titleLabel.font = [UIFont boldSystemFontOfSize:16];
|
|
|
|
|
titleLabel.textColor = [UIColor blackColor];
|
|
|
|
|
[bgView addSubview:titleLabel];
|
|
|
|
|
titleLabel.text = [NSString localizedStringWithFormat:QXText(@"全部评论(%@)"),self.commentModel.total?self.commentModel.total:@"0"];
|
|
|
|
|
return footer;
|
|
|
|
|
}else{
|
|
|
|
|
return [UIView new];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
|
|
|
|
|
if (section == 0) {
|
|
|
|
|
return 0;
|
|
|
|
|
}else{
|
|
|
|
|
QXDynamicCommentListModel *firsModel = self.dataArray[section-1];
|
|
|
|
|
CGFloat height = [firsModel.content heightForFont:[UIFont systemFontOfSize:14] width:SCREEN_WIDTH-40-16*2-7];
|
|
|
|
|
return height+12+40+7+3+9;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
|
|
|
|
|
if (section == 0) {
|
|
|
|
|
return 64;
|
|
|
|
|
}else{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
|
|
|
|
|
if (indexPath.section == 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-10-20 09:43:10 +08:00
|
|
|
// QXDynamicCommentListModel *firsModel = self.dataArray[indexPath.section-1];
|
|
|
|
|
// QXDynamicCommentListModel *model = firsModel.replies[indexPath.row];
|
|
|
|
|
// self.commentView.model = model;
|
|
|
|
|
// self.commentView.textField.placeholder = [NSString stringWithFormat:@"回复:%@",model.nickname];
|
|
|
|
|
// [self.commentView.textField becomeFirstResponder];
|
2025-08-08 10:49:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-(void)didClickDeleteComment:(QXDynamicCommentListModel*)model{
|
|
|
|
|
MJWeakSelf
|
|
|
|
|
QXAlertView *al = [[QXAlertView alloc] initWithFrame:CGRectMake(0, 0, ScaleWidth(300), ScaleWidth(175))];
|
|
|
|
|
al.type = QXAlertViewTypeDeleteComment;
|
|
|
|
|
al.commitBlock = ^{
|
|
|
|
|
[weakSelf deleteCommentWithModel:model];
|
|
|
|
|
};
|
|
|
|
|
[[QXGlobal shareGlobal] showView:al popType:(PopViewTypeTopToCenter) tapDismiss:NO finishBlock:^{
|
|
|
|
|
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
-(void)deleteCommentWithModel:(QXDynamicCommentListModel*)model{
|
|
|
|
|
MJWeakSelf
|
|
|
|
|
[QXDynamicNetwork deleteCommentWithCommentId:model.id successBlock:^(NSDictionary * _Nonnull dict) {
|
|
|
|
|
weakSelf.page = 1;
|
|
|
|
|
[weakSelf getCommentListIsReload:YES];
|
|
|
|
|
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
|
|
|
|
|
|
|
|
|
|
}];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-(void)didClickReplyComment:(QXDynamicCommentListModel*)model{
|
2025-10-20 09:43:10 +08:00
|
|
|
self.commentView.model = model;
|
|
|
|
|
self.commentView.textField.placeholder = [NSString stringWithFormat:@"回复:%@",model.nickname];
|
|
|
|
|
[self.commentView.textField becomeFirstResponder];
|
2025-08-08 10:49:36 +08:00
|
|
|
}
|
|
|
|
|
#pragma mark - 评论
|
|
|
|
|
-(void)didClickSendWithText:(NSString*)text model:(nonnull QXDynamicCommentListModel *)model{
|
|
|
|
|
if ([text stringByReplacingOccurrencesOfString:@" " withString:@""].length == 0) {
|
|
|
|
|
showToast(@"请填写评论");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
NSString *pid = @"";
|
|
|
|
|
NSString *reply_to = @"";
|
|
|
|
|
if (model) {
|
|
|
|
|
pid = model.pid?model.pid:model.id;
|
|
|
|
|
reply_to = model.user_id;
|
|
|
|
|
}else{
|
|
|
|
|
pid = @"0";
|
|
|
|
|
reply_to = @"0";
|
|
|
|
|
}
|
|
|
|
|
self.commentView.textField.text = @"";
|
|
|
|
|
[self.view endEditing:YES];
|
|
|
|
|
MJWeakSelf
|
|
|
|
|
[QXDynamicNetwork commentDynamicWithId:self.detailModel.id pid:pid reply_to:reply_to content:text successBlock:^(NSDictionary * _Nonnull dict) {
|
|
|
|
|
weakSelf.page = 1;
|
|
|
|
|
[weakSelf getCommentListIsReload:YES];
|
|
|
|
|
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
|
|
|
|
|
|
|
|
|
|
}];
|
|
|
|
|
}
|
|
|
|
|
- (void)keyboardWillHide:(NSNotification *)notification {
|
|
|
|
|
self.commentView.model = nil;
|
|
|
|
|
self.commentView.textField.placeholder = @"快来发表评论吧";
|
|
|
|
|
[UIView animateWithDuration:0.3 animations:^{
|
|
|
|
|
self.commentView.y = SCREEN_HEIGHT-TabbarContentHeight;
|
|
|
|
|
}];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)keyboardWillShow:(NSNotification *)notification {
|
|
|
|
|
// CGRect keyboardFrame = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
|
|
|
|
|
// [UIView animateWithDuration:0.3 animations:^{
|
|
|
|
|
// self.commentView.y = keyboardFrame.origin.y+TabbarContentHeight;
|
|
|
|
|
// }];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)keyboardWillChangeFrame:(NSNotification *)notification {
|
|
|
|
|
CGRect keyboardFrame = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
|
|
|
|
|
[UIView animateWithDuration:0.15 animations:^{
|
|
|
|
|
self.commentView.y = keyboardFrame.origin.y-TabbarContentHeight;
|
|
|
|
|
}];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-(UITableView *)tableView{
|
|
|
|
|
if (!_tableView) {
|
|
|
|
|
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, NavContentHeight, SCREEN_WIDTH, SCREEN_HEIGHT-NavContentHeight-TabbarContentHeight) style:UITableViewStyleGrouped];
|
|
|
|
|
self.tableView.backgroundColor = [UIColor whiteColor];
|
|
|
|
|
self.tableView.delegate = self;
|
|
|
|
|
self.tableView.dataSource = self;
|
|
|
|
|
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
|
|
|
|
|
[self.tableView registerNib:[UINib nibWithNibName:@"QXDynamicListCell" bundle:nil] forCellReuseIdentifier:@"QXDynamicListCell"];
|
|
|
|
|
self.tableView.rowHeight = UITableViewAutomaticDimension;
|
|
|
|
|
self.tableView.estimatedRowHeight = 152;
|
|
|
|
|
[self.tableView addRoundedCornersWithRadius:16];
|
|
|
|
|
self.tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
|
|
|
|
|
MJWeakSelf
|
|
|
|
|
// _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
|
|
|
|
|
// weakSelf.page = 1;
|
|
|
|
|
// [weakSelf getDynamicList];
|
|
|
|
|
// }];
|
|
|
|
|
_tableView.mj_footer = [MJRefreshBackStateFooter footerWithRefreshingBlock:^{
|
|
|
|
|
weakSelf.page++;
|
|
|
|
|
[weakSelf getCommentListIsReload:NO];
|
|
|
|
|
}];
|
|
|
|
|
}
|
|
|
|
|
return _tableView;
|
|
|
|
|
}
|
|
|
|
|
-(QXDynamicCommentInputView *)commentView{
|
|
|
|
|
if (!_commentView) {
|
|
|
|
|
_commentView = [[QXDynamicCommentInputView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT-TabbarContentHeight, SCREEN_WIDTH, TabbarContentHeight)];
|
|
|
|
|
_commentView.delegate = self;
|
|
|
|
|
}
|
|
|
|
|
return _commentView;
|
|
|
|
|
}
|
|
|
|
|
@end
|