Commit ec1615bb cgx

完善评论模块中点赞和评论数逻辑

1 个父辈 267a0e14
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
#import "TestFlutterController.h" #import "TestFlutterController.h"
#import "DynamicDetailController.h" #import "DynamicDetailController.h"
@interface CommunityController () <CommunityViewDelegate, DynamicControllerDelegate> @interface CommunityController () <CommunityViewDelegate, DynamicControllerDelegate, DynamicDetailControllerDelegate>
@property (nonatomic, strong) CommunityView *communityView; @property (nonatomic, strong) CommunityView *communityView;
@property (nonatomic, strong) TestFlutterController *flutterEngine; @property (nonatomic, strong) TestFlutterController *flutterEngine;
@property (nonatomic, assign) int offset; @property (nonatomic, assign) int offset;
...@@ -125,6 +125,7 @@ ...@@ -125,6 +125,7 @@
} }
DynamicDetailController *detailVC = [DynamicDetailController new]; DynamicDetailController *detailVC = [DynamicDetailController new];
detailVC.comDynModel = comDynModel; detailVC.comDynModel = comDynModel;
detailVC.delegate = self;
[self.navigationController pushViewController:detailVC animated:YES]; [self.navigationController pushViewController:detailVC animated:YES];
} }
...@@ -168,6 +169,11 @@ ...@@ -168,6 +169,11 @@
[self.communityView insertUserDyModel:model]; [self.communityView insertUserDyModel:model];
} }
#pragma mark - DynamicDetailControllerDelegate
- (void)updateLikeOrRemark {
[self.communityView updateLikeOrRemarkView];
}
#pragma mark - lazy #pragma mark - lazy
- (CommunityView *)communityView { - (CommunityView *)communityView {
if (!_communityView) { if (!_communityView) {
......
...@@ -8,11 +8,18 @@ ...@@ -8,11 +8,18 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import "ComDynModel.h" #import "ComDynModel.h"
@protocol DynamicDetailControllerDelegate <NSObject>
/// 更新点赞或者评论
- (void)updateLikeOrRemark;
@end
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
/// 动态详情页 /// 动态详情页
@interface DynamicDetailController : UIViewController @interface DynamicDetailController : UIViewController
@property (nonatomic, weak) id<DynamicDetailControllerDelegate> delegate;
@property (nonatomic, strong) ComDynModel *comDynModel; @property (nonatomic, strong) ComDynModel *comDynModel;
@end @end
......
...@@ -7,12 +7,14 @@ ...@@ -7,12 +7,14 @@
#import "DynamicDetailController.h" #import "DynamicDetailController.h"
#import "DynamicDetailView.h" #import "DynamicDetailView.h"
#import "ComListViewModel.h"
#import "ComDetailViewModel.h" #import "ComDetailViewModel.h"
#import "ReplyListController.h" #import "ReplyListController.h"
@interface DynamicDetailController () <DynamicDetailViewDelegate> @interface DynamicDetailController () <DynamicDetailViewDelegate>
@property (nonatomic, strong) DynamicDetailView *detailView; @property (nonatomic, strong) DynamicDetailView *detailView;
@property (nonatomic, strong) ComDetailViewModel *comDetailViewModel; @property (nonatomic, strong) ComDetailViewModel *comDetailViewModel;
@property (nonatomic, strong) NSURLSessionDataTask *likeDataTask;
@end @end
@implementation DynamicDetailController @implementation DynamicDetailController
...@@ -28,10 +30,10 @@ ...@@ -28,10 +30,10 @@
self.comDetailViewModel = [ComDetailViewModel new]; self.comDetailViewModel = [ComDetailViewModel new];
[self.detailView updateBottomView:self.comDynModel]; // 查询动态评论列表请求
[self.comDetailViewModel queryDynamicCommentListWithTalkID:self.comDynModel.dynamicID completion:^(ComDetailViewModel * _Nonnull requestModel) { [self.comDetailViewModel queryDynamicCommentListWithTalkID:self.comDynModel.dynamicID completion:^(ComDetailViewModel * _Nonnull requestModel) {
if (requestModel.resCode == DSResCodeSuccess) { if (requestModel.resCode == DSResCodeSuccess) {
[self.detailView updateBottomView:self.comDynModel];
[self.detailView updateDetailView:requestModel.groupDatas]; [self.detailView updateDetailView:requestModel.groupDatas];
} else { } else {
...@@ -46,13 +48,18 @@ ...@@ -46,13 +48,18 @@
[self.comDetailViewModel userCommentDynamicWithTalkID:self.comDynModel.dynamicID content:content completion:^(ComDetailViewModel * _Nonnull requestModel) { [self.comDetailViewModel userCommentDynamicWithTalkID:self.comDynModel.dynamicID content:content completion:^(ComDetailViewModel * _Nonnull requestModel) {
[DSProgressHUD dissmissProgressHUD]; [DSProgressHUD dissmissProgressHUD];
if (requestModel.resCode == DSResCodeSuccess) { if (requestModel.resCode == DSResCodeSuccess) {
// 更新评论数
self.comDynModel.remarkCount += 1;
[self.detailView updateRemarkCount:self.comDynModel.remarkCount];
if (self.delegate && [self.delegate respondsToSelector:@selector(updateLikeOrRemark)]) {
[self.delegate updateLikeOrRemark];
}
[self.detailView updateCommentSection:requestModel.groupDatas]; [self.detailView updateCommentSection:requestModel.groupDatas];
} else { } else {
} }
}]; }];
} else if (tag == 2) { // 回复评论
} }
} }
...@@ -62,9 +69,39 @@ ...@@ -62,9 +69,39 @@
[self.navigationController pushViewController:replyList animated:YES]; [self.navigationController pushViewController:replyList animated:YES];
} }
#pragma mark - 品牌模式 - (void)fireTapDetailLikeBtn {
- (NaviStyle)navigationBarStyle { // 1、用户点赞或取消点赞直接响应UI变化
return NaviStyleDefault; if (self.comDynModel.isLike) {
self.comDynModel.likeCount--;
} else {
self.comDynModel.likeCount++;
}
self.comDynModel.isLike = !self.comDynModel.isLike;
[self.detailView updateLikeStateAndLikeCount:self.comDynModel];
// 2、更新点赞或取消点赞请求
if (self.likeDataTask) { [self.likeDataTask cancel]; }
self.likeDataTask = [ComListViewModel userDynamicPraiseWithTalkID:self.comDynModel.dynamicID completion:^(ComListViewModel * _Nonnull requestModel) {
if (requestModel.resCode == DSResCodeSuccess) {
// 3、更新成功回调刷新社区列表点赞数据
if (self.delegate && [self.delegate respondsToSelector:@selector(updateLikeOrRemark)]) {
[self.delegate updateLikeOrRemark];
}
} else {
// 4、如果请求失败,延迟执行回退
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
// 修改数据model
if (self.comDynModel.isLike) {
self.comDynModel.likeCount--;
} else {
self.comDynModel.likeCount++;
}
self.comDynModel.isLike = !self.comDynModel.isLike;
[self.detailView updateLikeStateAndLikeCount:self.comDynModel];
[DSProgressHUD showToast:requestModel.errMessage];
});
}
}];
} }
#pragma mark - lazy #pragma mark - lazy
...@@ -75,4 +112,9 @@ ...@@ -75,4 +112,9 @@
return _detailView; return _detailView;
} }
#pragma mark - 品牌模式
- (NaviStyle)navigationBarStyle {
return NaviStyleDefault;
}
@end @end
...@@ -58,6 +58,8 @@ NS_ASSUME_NONNULL_BEGIN ...@@ -58,6 +58,8 @@ NS_ASSUME_NONNULL_BEGIN
/// 显示举报、取消弹框 /// 显示举报、取消弹框
- (void)showInformCancelView; - (void)showInformCancelView;
/// 更新社区动态列表点赞或者评论view
- (void)updateLikeOrRemarkView;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END
...@@ -69,6 +69,10 @@ ...@@ -69,6 +69,10 @@
[self.informCancelView display]; [self.informCancelView display];
} }
- (void)updateLikeOrRemarkView {
[self.listView reloadData];
}
#pragma mark - Action #pragma mark - Action
- (void)tapAction:(UITapGestureRecognizer *)tapGR { - (void)tapAction:(UITapGestureRecognizer *)tapGR {
if (self.delegate && [self.delegate respondsToSelector:@selector(tapCommunityHeaderModule:)]) { if (self.delegate && [self.delegate respondsToSelector:@selector(tapCommunityHeaderModule:)]) {
......
...@@ -11,10 +11,17 @@ ...@@ -11,10 +11,17 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@protocol DynamicDetailViewDelegate <NSObject> @protocol DynamicDetailViewDelegate <NSObject>
/// 评论或者回复回调
/// @param tag tag
/// @param content 内容
- (void)fireCommentOrReply:(NSInteger)tag content:(NSString *)content; - (void)fireCommentOrReply:(NSInteger)tag content:(NSString *)content;
/// 进入回复列表页 /// 进入回复列表页
/// @param commentID 评论id /// @param commentID 评论id
- (void)jumpReplyListView:(int)commentID; - (void)jumpReplyListView:(int)commentID;
/// 评论详情点赞回调
- (void)fireTapDetailLikeBtn;
@end @end
/// 动态详情自定义view /// 动态详情自定义view
...@@ -26,6 +33,14 @@ NS_ASSUME_NONNULL_BEGIN ...@@ -26,6 +33,14 @@ NS_ASSUME_NONNULL_BEGIN
/// @param model 社区动态列表传递过来的model /// @param model 社区动态列表传递过来的model
- (void)updateBottomView:(ComDynModel *)model; - (void)updateBottomView:(ComDynModel *)model;
/// 更新点赞状态和点赞数
/// @param model model
- (void)updateLikeStateAndLikeCount:(ComDynModel *)model;
/// 更新评论数
/// @param remarkCount remarkCount
- (void)updateRemarkCount:(int)remarkCount;
/// 更新动态详情页面 /// 更新动态详情页面
/// @param groupData 分组数据 /// @param groupData 分组数据
- (void)updateDetailView:(NSArray *)groupData; - (void)updateDetailView:(NSArray *)groupData;
......
...@@ -46,7 +46,15 @@ ...@@ -46,7 +46,15 @@
#pragma mark - public #pragma mark - public
- (void)updateBottomView:(ComDynModel *)model { - (void)updateBottomView:(ComDynModel *)model {
[self.interactView updateLikeCount:model.likeCount remarkCount:model.remarkCount]; [self.interactView updateLikeBtnState:model.isLike likeCount:model.likeCount remarkCount:model.remarkCount];
}
- (void)updateLikeStateAndLikeCount:(ComDynModel *)model {
[self.interactView updateLikeBtnState:model.isLike likeCount:model.likeCount];
}
- (void)updateRemarkCount:(int)remarkCount {
[self.interactView updateRemarkCount:remarkCount];
} }
- (void)updateDetailView:(NSArray *)groupData { - (void)updateDetailView:(NSArray *)groupData {
...@@ -71,6 +79,12 @@ ...@@ -71,6 +79,12 @@
} }
} }
- (void)didTapDetailLikeBtn {
if (self.delegate && [self.delegate respondsToSelector:@selector(fireTapDetailLikeBtn)]) {
[self.delegate fireTapDetailLikeBtn];
}
}
#pragma mark - UITableViewDelegate, UITableViewDataSource #pragma mark - UITableViewDelegate, UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return self.detailListArr.count; return self.detailListArr.count;
...@@ -166,8 +180,8 @@ ...@@ -166,8 +180,8 @@
[weakSelf.dynamicDetailView reloadSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationNone]; [weakSelf.dynamicDetailView reloadSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationNone];
}; };
cell.lookAllRelpyListBlock = ^{ cell.lookAllRelpyListBlock = ^{
if (self.delegate && [self.delegate respondsToSelector:@selector(jumpReplyListView:)]) { if (weakSelf.delegate && [weakSelf.delegate respondsToSelector:@selector(jumpReplyListView:)]) {
[self.delegate jumpReplyListView:comReplyModel.commentModel.comment_id]; [weakSelf.delegate jumpReplyListView:comReplyModel.commentModel.comment_id];
} }
}; };
return cell; return cell;
......
...@@ -10,7 +10,13 @@ ...@@ -10,7 +10,13 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@protocol InteractViewDelegate <NSObject> @protocol InteractViewDelegate <NSObject>
/// 评论或者回复(回复目前放在动态通知处理,后期可能会放在正文评论详情处理)
/// @param tag 1:评论,2:回复
/// @param content 内容
- (void)commentOrReply:(NSInteger)tag content:(NSString *)content; - (void)commentOrReply:(NSInteger)tag content:(NSString *)content;
/// 点击详情点赞按钮
- (void)didTapDetailLikeBtn;
@end @end
/// 互动区域(点赞、评论) /// 互动区域(点赞、评论)
...@@ -18,7 +24,9 @@ NS_ASSUME_NONNULL_BEGIN ...@@ -18,7 +24,9 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, weak) id<InteractViewDelegate> delegate; @property (nonatomic, weak) id<InteractViewDelegate> delegate;
- (void)updateLikeCount:(int)likeCount remarkCount:(int)remarkCount; - (void)updateLikeBtnState:(BOOL)isLike likeCount:(int)likeCount remarkCount:(int)remarkCount;
- (void)updateLikeBtnState:(BOOL)isLike likeCount:(int)likeCount;
- (void)updateRemarkCount:(int)remarkCount;
/// 弹出回复输入框 /// 弹出回复输入框
/// @param commentUser @评论者 /// @param commentUser @评论者
......
...@@ -6,11 +6,12 @@ ...@@ -6,11 +6,12 @@
// //
#import "InteractView.h" #import "InteractView.h"
#import "LikeButton.h"
#import "TextInputAlertView.h" #import "TextInputAlertView.h"
@interface InteractView () @interface InteractView ()
@property (nonatomic, strong) UILabel *tapLab; @property (nonatomic, strong) UILabel *tapLab;
@property (nonatomic, strong) UIButton *likeBtn; @property (nonatomic, strong) LikeButton *likeBtn;
@property (nonatomic, strong) UIButton *remarkCountBtn; @property (nonatomic, strong) UIButton *remarkCountBtn;
@property (nonatomic, strong) TextInputAlertView *textInputAlertView; @property (nonatomic, strong) TextInputAlertView *textInputAlertView;
@end @end
...@@ -45,13 +46,29 @@ ...@@ -45,13 +46,29 @@
return self; return self;
} }
#pragma mark - private
- (void)popTextInputView { - (void)popTextInputView {
[self.textInputAlertView showTextInputAlertView]; [self.textInputAlertView showTextInputAlertView];
} }
- (void)detailTapLikeBtn {
if (self.delegate && [self.delegate respondsToSelector:@selector(didTapDetailLikeBtn)]) {
[self.delegate didTapDetailLikeBtn];
}
}
#pragma mark - public #pragma mark - public
- (void)updateLikeCount:(int)likeCount remarkCount:(int)remarkCount { - (void)updateLikeBtnState:(BOOL)isLike likeCount:(int)likeCount remarkCount:(int)remarkCount {
[self.likeBtn setTitle:[NSString stringWithFormat:@"%d", likeCount] forState:UIControlStateNormal]; [self.likeBtn updateLikeBtnState:isLike likeCount:likeCount];
[self.remarkCountBtn setTitle:[NSString stringWithFormat:@"%d", remarkCount] forState:UIControlStateNormal];
}
- (void)updateLikeBtnState:(BOOL)isLike likeCount:(int)likeCount {
[self.likeBtn executeAnimation];
[self.likeBtn updateLikeBtnState:isLike likeCount:likeCount];
}
- (void)updateRemarkCount:(int)remarkCount {
[self.remarkCountBtn setTitle:[NSString stringWithFormat:@"%d", remarkCount] forState:UIControlStateNormal]; [self.remarkCountBtn setTitle:[NSString stringWithFormat:@"%d", remarkCount] forState:UIControlStateNormal];
} }
...@@ -77,12 +94,10 @@ ...@@ -77,12 +94,10 @@
return _tapLab; return _tapLab;
} }
- (UIButton *)likeBtn { - (LikeButton *)likeBtn {
if (!_likeBtn) { if (!_likeBtn) {
_likeBtn = [UIButton btnWithTitle:@"" font:SysFont(12)]; _likeBtn = [[LikeButton alloc] initWithNormalImg:nil nightNormalImg:nil selectedImg:nil nightSelectedImg:nil];
[_likeBtn dk_setTitleColorPicker:DKColorPickerWithColors(SmallTextColor, ColorFromHexA(0xFFFFFF, .3), DSWhite) forState:UIControlStateNormal]; [_likeBtn addTarget:self action:@selector(detailTapLikeBtn) forControlEvents:UIControlEventTouchUpInside];
[_likeBtn dk_setImage:DKImagePickerWithNames(@"ic_shequ_dianza", @"dk_ic_shequ_dianza", @"ic_shequ_dianza") forState:UIControlStateNormal];
_likeBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 9, 0, 0);
} }
return _likeBtn; return _likeBtn;
} }
...@@ -90,6 +105,7 @@ ...@@ -90,6 +105,7 @@
- (UIButton *)remarkCountBtn { - (UIButton *)remarkCountBtn {
if (!_remarkCountBtn) { if (!_remarkCountBtn) {
_remarkCountBtn = [UIButton btnWithTitle:@"" font:SysFont(12)]; _remarkCountBtn = [UIButton btnWithTitle:@"" font:SysFont(12)];
_remarkCountBtn.userInteractionEnabled = NO;
[_remarkCountBtn dk_setTitleColorPicker:DKColorPickerWithColors(SmallTextColor, ColorFromHexA(0xFFFFFF, .3), DSWhite) forState:UIControlStateNormal]; [_remarkCountBtn dk_setTitleColorPicker:DKColorPickerWithColors(SmallTextColor, ColorFromHexA(0xFFFFFF, .3), DSWhite) forState:UIControlStateNormal];
[_remarkCountBtn dk_setImage:DKImagePickerWithNames(@"ic_shequ_pinlun", @"dk_ic_shequ_pinlun", @"ic_shequ_pinlun") forState:UIControlStateNormal]; [_remarkCountBtn dk_setImage:DKImagePickerWithNames(@"ic_shequ_pinlun", @"dk_ic_shequ_pinlun", @"ic_shequ_pinlun") forState:UIControlStateNormal];
_remarkCountBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 9, 0, 0); _remarkCountBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 9, 0, 0);
......
...@@ -110,9 +110,14 @@ ...@@ -110,9 +110,14 @@
- (void)replyAction:(UIButton *)sender { - (void)replyAction:(UIButton *)sender {
NSString *content = self.textView.text; NSString *content = self.textView.text;
if (sender.tag == 2) { if (sender.tag == 2) { // 回复
content = [content componentsSeparatedByString:self.commentUserFlag].lastObject; content = [content componentsSeparatedByString:self.commentUserFlag].lastObject;
} }
NSString *triStr = [NSString trimString:content];
if (triStr.length == 0) {
[DSProgressHUD showToast:@"请输入评论内容"];
return;
}
if (self.tapFinishBlock) { if (self.tapFinishBlock) {
self.tapFinishBlock(sender.tag, content); self.tapFinishBlock(sender.tag, content);
} }
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!