Commit 53296024 cgx

社区动态列表、点赞逻辑处理

1 个父辈 b3ebe4bc
...@@ -57,6 +57,7 @@ ...@@ -57,6 +57,7 @@
D02D082A287BCEF3005C3A00 /* SRTipsView.m in Sources */ = {isa = PBXBuildFile; fileRef = D02D0829287BCEF3005C3A00 /* SRTipsView.m */; }; D02D082A287BCEF3005C3A00 /* SRTipsView.m in Sources */ = {isa = PBXBuildFile; fileRef = D02D0829287BCEF3005C3A00 /* SRTipsView.m */; };
D02D082D287BD05D005C3A00 /* ReadyListController.m in Sources */ = {isa = PBXBuildFile; fileRef = D02D082C287BD05D005C3A00 /* ReadyListController.m */; }; D02D082D287BD05D005C3A00 /* ReadyListController.m in Sources */ = {isa = PBXBuildFile; fileRef = D02D082C287BD05D005C3A00 /* ReadyListController.m */; };
D02E85882882A594002DAD7E /* PrepareItemsCell.m in Sources */ = {isa = PBXBuildFile; fileRef = D02E85872882A594002DAD7E /* PrepareItemsCell.m */; }; D02E85882882A594002DAD7E /* PrepareItemsCell.m in Sources */ = {isa = PBXBuildFile; fileRef = D02E85872882A594002DAD7E /* PrepareItemsCell.m */; };
D030796F28E3E32A00ED96BF /* LikeButton.m in Sources */ = {isa = PBXBuildFile; fileRef = D030796E28E3E32A00ED96BF /* LikeButton.m */; };
D030C1B8284775930014946F /* RelaxTrainController.m in Sources */ = {isa = PBXBuildFile; fileRef = D030C1B7284775930014946F /* RelaxTrainController.m */; }; D030C1B8284775930014946F /* RelaxTrainController.m in Sources */ = {isa = PBXBuildFile; fileRef = D030C1B7284775930014946F /* RelaxTrainController.m */; };
D0336163285035AB005573CF /* DailyBgView.m in Sources */ = {isa = PBXBuildFile; fileRef = D0336162285035AB005573CF /* DailyBgView.m */; }; D0336163285035AB005573CF /* DailyBgView.m in Sources */ = {isa = PBXBuildFile; fileRef = D0336162285035AB005573CF /* DailyBgView.m */; };
D03559E42887DE4400168402 /* NSObject+AutoCancelRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = D03559E32887DE4400168402 /* NSObject+AutoCancelRequest.m */; }; D03559E42887DE4400168402 /* NSObject+AutoCancelRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = D03559E32887DE4400168402 /* NSObject+AutoCancelRequest.m */; };
...@@ -380,6 +381,8 @@ ...@@ -380,6 +381,8 @@
D02D082C287BD05D005C3A00 /* ReadyListController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ReadyListController.m; sourceTree = "<group>"; }; D02D082C287BD05D005C3A00 /* ReadyListController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ReadyListController.m; sourceTree = "<group>"; };
D02E85862882A594002DAD7E /* PrepareItemsCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PrepareItemsCell.h; sourceTree = "<group>"; }; D02E85862882A594002DAD7E /* PrepareItemsCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PrepareItemsCell.h; sourceTree = "<group>"; };
D02E85872882A594002DAD7E /* PrepareItemsCell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PrepareItemsCell.m; sourceTree = "<group>"; }; D02E85872882A594002DAD7E /* PrepareItemsCell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PrepareItemsCell.m; sourceTree = "<group>"; };
D030796D28E3E32A00ED96BF /* LikeButton.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LikeButton.h; sourceTree = "<group>"; };
D030796E28E3E32A00ED96BF /* LikeButton.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LikeButton.m; sourceTree = "<group>"; };
D030C1B6284775930014946F /* RelaxTrainController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RelaxTrainController.h; sourceTree = "<group>"; }; D030C1B6284775930014946F /* RelaxTrainController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RelaxTrainController.h; sourceTree = "<group>"; };
D030C1B7284775930014946F /* RelaxTrainController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RelaxTrainController.m; sourceTree = "<group>"; }; D030C1B7284775930014946F /* RelaxTrainController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RelaxTrainController.m; sourceTree = "<group>"; };
D0336161285035AB005573CF /* DailyBgView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DailyBgView.h; sourceTree = "<group>"; }; D0336161285035AB005573CF /* DailyBgView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DailyBgView.h; sourceTree = "<group>"; };
...@@ -1163,6 +1166,15 @@ ...@@ -1163,6 +1166,15 @@
path = SleepReady; path = SleepReady;
sourceTree = "<group>"; sourceTree = "<group>";
}; };
D030796628E3D92700ED96BF /* LikeButton */ = {
isa = PBXGroup;
children = (
D030796D28E3E32A00ED96BF /* LikeButton.h */,
D030796E28E3E32A00ED96BF /* LikeButton.m */,
);
path = LikeButton;
sourceTree = "<group>";
};
D03559E12887DE4400168402 /* YRAutoCancelRequest */ = { D03559E12887DE4400168402 /* YRAutoCancelRequest */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
...@@ -1449,6 +1461,7 @@ ...@@ -1449,6 +1461,7 @@
D0A3BB8D28D959F800F58781 /* View */ = { D0A3BB8D28D959F800F58781 /* View */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
D030796628E3D92700ED96BF /* LikeButton */,
D02B7E5A28E2A28500218EF7 /* ComDynamicCell.h */, D02B7E5A28E2A28500218EF7 /* ComDynamicCell.h */,
D02B7E5B28E2A28500218EF7 /* ComDynamicCell.m */, D02B7E5B28E2A28500218EF7 /* ComDynamicCell.m */,
D0A3BB9028D95A2B00F58781 /* CommunityView.h */, D0A3BB9028D95A2B00F58781 /* CommunityView.h */,
...@@ -2566,6 +2579,7 @@ ...@@ -2566,6 +2579,7 @@
D0A72E3F282B89AD00EED7BE /* DSHomeView.m in Sources */, D0A72E3F282B89AD00EED7BE /* DSHomeView.m in Sources */,
D01814E8280020F900583D4E /* CWPageControl.m in Sources */, D01814E8280020F900583D4E /* CWPageControl.m in Sources */,
D027EE3027FB52DA004BBA61 /* UIImage+Extras.m in Sources */, D027EE3027FB52DA004BBA61 /* UIImage+Extras.m in Sources */,
D030796F28E3E32A00ED96BF /* LikeButton.m in Sources */,
D037C49A284F4F0D000F3089 /* DailyTaskCell.m in Sources */, D037C49A284F4F0D000F3089 /* DailyTaskCell.m in Sources */,
D043DD55285B11860043A4CE /* VersionUpdateBox.m in Sources */, D043DD55285B11860043A4CE /* VersionUpdateBox.m in Sources */,
D0A7510E282E2FEF00589B0E /* NoisePlayView.m in Sources */, D0A7510E282E2FEF00589B0E /* NoisePlayView.m in Sources */,
......
...@@ -7,13 +7,13 @@ ...@@ -7,13 +7,13 @@
#import "CommunityController.h" #import "CommunityController.h"
#import "CommunityView.h" #import "CommunityView.h"
#import "TestFlutterController.h"
#import "ComListViewModel.h" #import "ComListViewModel.h"
#import "TestFlutterController.h"
@interface CommunityController () <CommunityViewDelegate> @interface CommunityController () <CommunityViewDelegate>
@property (nonatomic, strong) CommunityView *communityView; @property (nonatomic, strong) CommunityView *communityView;
@property (nonatomic, strong) TestFlutterController *flutterEngine; @property (nonatomic, strong) TestFlutterController *flutterEngine;
@property (nonatomic, strong) ComListViewModel *comListViewModel; @property (nonatomic, assign) int offset;
@end @end
@implementation CommunityController @implementation CommunityController
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
[self setupUI]; [self setupUI];
self.comListViewModel = [ComListViewModel new]; self.offset = 1;
} }
- (void)setupUI { - (void)setupUI {
...@@ -43,20 +43,41 @@ ...@@ -43,20 +43,41 @@
} }
- (void)messageAction { - (void)messageAction {
if (![LoginUtils getUserLoginData]) {
[LoginUtils jumpToLoginControllerWithTarget:self];
return;
}
self.flutterEngine = [TestFlutterController new]; self.flutterEngine = [TestFlutterController new];
[self.navigationController pushViewController:self.flutterEngine animated:YES]; [self.navigationController pushViewController:self.flutterEngine animated:YES];
} }
#pragma mark - CommunityViewDelegate #pragma mark - CommunityViewDelegate
- (void)tapCommunityHeaderModule:(NSInteger)index { - (void)tapCommunityHeaderModule:(NSInteger)index {
if (![LoginUtils getUserLoginData]) {
[LoginUtils jumpToLoginControllerWithTarget:self];
return;
}
NSString *clsName = index == 1 ? @"ArticleController" : @"EvaluateController"; NSString *clsName = index == 1 ? @"ArticleController" : @"EvaluateController";
[self.navigationController pushViewController:[NSClassFromString(clsName) new] animated:YES]; [self.navigationController pushViewController:[NSClassFromString(clsName) new] animated:YES];
} }
- (void)getDynamicListRequest:(BOOL)loadMore { - (void)getDynamicListRequest:(BOOL)loadMore {
[self.comListViewModel getComListWithCompletion:^(ComListViewModel * _Nonnull requestModel) { if (loadMore == NO) { self.offset = 1; }
[ComListViewModel querySleepDynamicListWithOffset:self.offset completion:^(ComListViewModel * _Nonnull requestModel) {
if (requestModel.resCode == DSResCodeSuccess) { if (requestModel.resCode == DSResCodeSuccess) {
if (loadMore) {
if (self.offset > requestModel.totalCount) {
[DSProgressHUD showToast:@"无更多动态"];
[self.communityView updateCommunityMoments:loadMore listArr:@[]];
return;
}
}
self.offset++;
[self.communityView updateCommunityMoments:loadMore listArr:requestModel.listArr]; [self.communityView updateCommunityMoments:loadMore listArr:requestModel.listArr];
} else {
[DSProgressHUD showToast:requestModel.errMessage];
[self.communityView endRefreshing:loadMore];
} }
}]; }];
} }
...@@ -78,9 +99,47 @@ ...@@ -78,9 +99,47 @@
} }
- (void)didSelectItem:(NSIndexPath *)indexPath { - (void)didSelectItem:(NSIndexPath *)indexPath {
if (![LoginUtils getUserLoginData]) {
[LoginUtils jumpToLoginControllerWithTarget:self];
return;
}
[self.navigationController pushViewController:[NSClassFromString(@"DynamicDetailController") new] animated:YES]; [self.navigationController pushViewController:[NSClassFromString(@"DynamicDetailController") new] animated:YES];
} }
- (void)didTapLikeItem:(ComDynModel *)comDynModel cell:(ComDynamicCell *)cell {
if (![LoginUtils getUserLoginData]) {
[LoginUtils jumpToLoginControllerWithTarget:self];
return;
}
// 1、用户点赞或取消点赞直接响应UI变化
if (comDynModel.isLike) {
comDynModel.likeCount--;
} else {
comDynModel.likeCount++;
}
comDynModel.isLike = !comDynModel.isLike;
[cell fireLikeAnimate];
[cell updateLikeUI];
// 2、更新点赞或取消点赞请求
[ComListViewModel userDynamicPraiseWithTalkID:comDynModel.dynamicID completion:^(ComListViewModel * _Nonnull requestModel) {
// 3、如果请求失败,延迟执行回退
if (requestModel.resCode != DSResCodeSuccess) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
// 修改数据model
if (comDynModel.isLike) {
comDynModel.likeCount--;
} else {
comDynModel.likeCount++;
}
comDynModel.isLike = !comDynModel.isLike;
[cell updateLikeUI];
[DSProgressHUD showToast:requestModel.errMessage];
});
}
}];
}
#pragma mark - lazy #pragma mark - lazy
- (CommunityView *)communityView { - (CommunityView *)communityView {
if (!_communityView) { if (!_communityView) {
......
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
<array> <array>
<string>https://img2.ydniu.com/sleep_ssmain/relax/1653288028602_1yFqHL.jpg</string> <string>https://img2.ydniu.com/sleep_ssmain/relax/1653288028602_1yFqHL.jpg</string>
</array> </array>
<key>isLike</key>
<false/>
<key>likeCount</key> <key>likeCount</key>
<integer>2</integer> <integer>2</integer>
<key>remarkCount</key> <key>remarkCount</key>
...@@ -38,6 +40,8 @@ ...@@ -38,6 +40,8 @@
<string>https://img2.ydniu.com/sleep_ssmain/relax/1653288005388_7wuK9n.jpg</string> <string>https://img2.ydniu.com/sleep_ssmain/relax/1653288005388_7wuK9n.jpg</string>
<string>https://img2.ydniu.com/sleep_ssmain/relax/1653277874846_BzEuFF.jpg</string> <string>https://img2.ydniu.com/sleep_ssmain/relax/1653277874846_BzEuFF.jpg</string>
</array> </array>
<key>isLike</key>
<true/>
<key>likeCount</key> <key>likeCount</key>
<integer>33</integer> <integer>33</integer>
<key>remarkCount</key> <key>remarkCount</key>
...@@ -57,6 +61,8 @@ ...@@ -57,6 +61,8 @@
<string>https://img2.ydniu.com/sleep_ssmain/relax/1653288005388_7wuK9n.jpg</string> <string>https://img2.ydniu.com/sleep_ssmain/relax/1653288005388_7wuK9n.jpg</string>
<string>https://img2.ydniu.com/sleep_ssmain/relax/1653277874846_BzEuFF.jpg</string> <string>https://img2.ydniu.com/sleep_ssmain/relax/1653277874846_BzEuFF.jpg</string>
</array> </array>
<key>isLike</key>
<true/>
<key>likeCount</key> <key>likeCount</key>
<integer>33</integer> <integer>33</integer>
<key>remarkCount</key> <key>remarkCount</key>
...@@ -77,6 +83,8 @@ ...@@ -77,6 +83,8 @@
<string>https://img2.ydniu.com/sleep_ssmain/relax/1653301114665_lwDNUG.jpg</string> <string>https://img2.ydniu.com/sleep_ssmain/relax/1653301114665_lwDNUG.jpg</string>
<string>https://img2.ydniu.com/sleep_ssmain/relax/1653301150570_zfQ0jW.jpg</string> <string>https://img2.ydniu.com/sleep_ssmain/relax/1653301150570_zfQ0jW.jpg</string>
</array> </array>
<key>isLike</key>
<false/>
<key>likeCount</key> <key>likeCount</key>
<integer>0</integer> <integer>0</integer>
<key>remarkCount</key> <key>remarkCount</key>
...@@ -97,6 +105,8 @@ ...@@ -97,6 +105,8 @@
<string>https://img2.ydniu.com/sleep_ssmain/relax/1653301114665_lwDNUG.jpg</string> <string>https://img2.ydniu.com/sleep_ssmain/relax/1653301114665_lwDNUG.jpg</string>
<string>https://img2.ydniu.com/sleep_ssmain/relax/1653301150570_zfQ0jW.jpg</string> <string>https://img2.ydniu.com/sleep_ssmain/relax/1653301150570_zfQ0jW.jpg</string>
</array> </array>
<key>isLike</key>
<false/>
<key>likeCount</key> <key>likeCount</key>
<integer>0</integer> <integer>0</integer>
<key>remarkCount</key> <key>remarkCount</key>
...@@ -117,6 +127,8 @@ ...@@ -117,6 +127,8 @@
<string>https://img2.ydniu.com/sleep_ssmain/relax/1653301114665_lwDNUG.jpg</string> <string>https://img2.ydniu.com/sleep_ssmain/relax/1653301114665_lwDNUG.jpg</string>
<string>https://img2.ydniu.com/sleep_ssmain/relax/1653301150570_zfQ0jW.jpg</string> <string>https://img2.ydniu.com/sleep_ssmain/relax/1653301150570_zfQ0jW.jpg</string>
</array> </array>
<key>isLike</key>
<false/>
<key>likeCount</key> <key>likeCount</key>
<integer>0</integer> <integer>0</integer>
<key>remarkCount</key> <key>remarkCount</key>
...@@ -131,6 +143,8 @@ ...@@ -131,6 +143,8 @@
<string>3天前</string> <string>3天前</string>
<key>content</key> <key>content</key>
<string>觉知当下,与家人建立和谐关系觉知当下,与家人建立和谐关系觉知当下,与家人建立和谐关系觉知当下,与家人建立和谐关系觉知当下,与家人建立和谐关系觉知当下,与家人建立和谐关系觉知当下,与家人建立和谐关系&quot;觉知当下,与家人建立和谐关系&quot;觉知当下,与家人建立和谐关系觉知当下,与家人建立和谐关系&quot;觉知当下,与家人建立和谐关系&quot;觉知当下,与家人建立和谐关系&quot;觉知当下,与家人建立和谐关系&quot;觉知当下,与家人建立和谐关系&quot;</string> <string>觉知当下,与家人建立和谐关系觉知当下,与家人建立和谐关系觉知当下,与家人建立和谐关系觉知当下,与家人建立和谐关系觉知当下,与家人建立和谐关系觉知当下,与家人建立和谐关系觉知当下,与家人建立和谐关系&quot;觉知当下,与家人建立和谐关系&quot;觉知当下,与家人建立和谐关系觉知当下,与家人建立和谐关系&quot;觉知当下,与家人建立和谐关系&quot;觉知当下,与家人建立和谐关系&quot;觉知当下,与家人建立和谐关系&quot;觉知当下,与家人建立和谐关系&quot;</string>
<key>isLike</key>
<false/>
<key>likeCount</key> <key>likeCount</key>
<integer>2</integer> <integer>2</integer>
<key>remarkCount</key> <key>remarkCount</key>
...@@ -149,6 +163,8 @@ ...@@ -149,6 +163,8 @@
<array> <array>
<string>https://img2.ydniu.com/sleep_ssmain/relax/1653288028602_1yFqHL.jpg</string> <string>https://img2.ydniu.com/sleep_ssmain/relax/1653288028602_1yFqHL.jpg</string>
</array> </array>
<key>isLike</key>
<false/>
<key>likeCount</key> <key>likeCount</key>
<integer>2</integer> <integer>2</integer>
<key>remarkCount</key> <key>remarkCount</key>
...@@ -167,6 +183,8 @@ ...@@ -167,6 +183,8 @@
<array> <array>
<string>https://img2.ydniu.com/sleep_ssmain/relax/1653288028602_1yFqHL.jpg</string> <string>https://img2.ydniu.com/sleep_ssmain/relax/1653288028602_1yFqHL.jpg</string>
</array> </array>
<key>isLike</key>
<false/>
<key>likeCount</key> <key>likeCount</key>
<integer>2</integer> <integer>2</integer>
<key>remarkCount</key> <key>remarkCount</key>
......
...@@ -11,6 +11,10 @@ NS_ASSUME_NONNULL_BEGIN ...@@ -11,6 +11,10 @@ NS_ASSUME_NONNULL_BEGIN
/// 社区动态列表数据model /// 社区动态列表数据model
@interface ComDynModel : NSObject @interface ComDynModel : NSObject
/// 动态ID
@property (nonatomic, assign) int dynamicID;
/// 用户ID
@property (nonatomic, assign) int userID;
/// 用户头像URL /// 用户头像URL
@property (nonatomic, copy) NSString *userIcon; @property (nonatomic, copy) NSString *userIcon;
/// 用户名 /// 用户名
...@@ -20,7 +24,9 @@ NS_ASSUME_NONNULL_BEGIN ...@@ -20,7 +24,9 @@ NS_ASSUME_NONNULL_BEGIN
/// 动态内容 /// 动态内容
@property (nonatomic, copy) NSString *content; @property (nonatomic, copy) NSString *content;
/// 图片链接 /// 图片链接
@property (nonatomic, copy) NSArray *imgUrls; @property (nonatomic, copy) NSString *imgUrls;
/// 自己是否点赞
@property (nonatomic, assign) BOOL isLike;
/// 点赞数 /// 点赞数
@property (nonatomic, assign) int likeCount; @property (nonatomic, assign) int likeCount;
/// 评论数 /// 评论数
...@@ -32,6 +38,8 @@ NS_ASSUME_NONNULL_BEGIN ...@@ -32,6 +38,8 @@ NS_ASSUME_NONNULL_BEGIN
- (CGFloat)imgHeight; - (CGFloat)imgHeight;
/// 动态cell高度 /// 动态cell高度
- (CGFloat)cellHeight; - (CGFloat)cellHeight;
- (NSArray *)getImgUrlsArr:(NSString *)imgUrls;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END
...@@ -9,6 +9,27 @@ ...@@ -9,6 +9,27 @@
@implementation ComDynModel @implementation ComDynModel
+ (nullable NSDictionary<NSString *, id> *)modelCustomPropertyMapper {
return @{@"dynamicID" : @"id",
@"userID" : @"user_id",
@"userIcon" : @"user_profile",
@"userName" : @"nick_name",
@"time" : @"publish_time",
@"imgUrls" : @"imgs_url",
@"likeCount" : @"total_praise",
@"remarkCount" : @"total_comments",
@"isLike" : @"is_praise",
};
}
//- (BOOL)modelCustomTransformFromDictionary:(NSDictionary *)dic {
// NSNumber *timestamp = dic[@"is_praise"];
// if (![timestamp isKindOfClass:[NSNumber class]]) return NO;
// _createdAt = [NSDate dateWithTimeIntervalSince1970:timestamp.floatValue];
// return YES;
//}
#pragma mark - public
- (CGFloat)contentHeight { - (CGFloat)contentHeight {
CGFloat contentW = kScreenWidth - 60; CGFloat contentW = kScreenWidth - 60;
NSString *content = self.content; NSString *content = self.content;
...@@ -21,29 +42,33 @@ ...@@ -21,29 +42,33 @@
if (iPhone5) { if (iPhone5) {
return 100; return 100;
} else { } else {
switch (self.imgUrls.count) { NSArray *imgUrls = [self getImgUrlsArr:self.imgUrls];
case 1: case 2: if (imgUrls.count == 1 || imgUrls.count == 2) {
return 150; return 150;
break; } else if (imgUrls.count == 3) {
case 3: return 95;
return 95;
break;
default:
return 0;
break;
} }
return 0;
} }
} }
return 0; return 0;
} }
- (CGFloat)cellHeight { - (CGFloat)cellHeight {
NSArray *imgUrls = [self getImgUrlsArr:self.imgUrls];
CGFloat topH = 67; CGFloat topH = 67;
CGFloat bottomH = (self.imgUrls && self.imgUrls.count) ? 52 : 56; CGFloat bottomH = imgUrls.count ? 52 : 56;
CGFloat contentH = [self contentHeight]; CGFloat contentH = [self contentHeight];
CGFloat imgTextSpace = (self.imgUrls && self.imgUrls.count) ? 12 : 0; CGFloat imgTextSpace = imgUrls.count ? 12 : 0;
CGFloat imgH = [self imgHeight]; CGFloat imgH = [self imgHeight];
return topH + bottomH + contentH + imgTextSpace + imgH; return topH + bottomH + contentH + imgTextSpace + imgH;
} }
- (NSArray *)getImgUrlsArr:(NSString *)imgUrls {
if (imgUrls && imgUrls.length) {
return [imgUrls componentsSeparatedByString:@"|"];
}
return @[];
}
@end @end
...@@ -8,11 +8,22 @@ ...@@ -8,11 +8,22 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import "ComDynModel.h" #import "ComDynModel.h"
typedef void(^TapLikeBlock)(void);
typedef void(^TapRemarkBlock)(void);
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
/// 社区动态Cell /// 社区动态Cell
@interface ComDynamicCell : UITableViewCell @interface ComDynamicCell : UITableViewCell
@property (nonatomic, strong) ComDynModel *model; @property (nonatomic, strong) ComDynModel *model;
@property (nonatomic, copy) TapLikeBlock tapLikeBlock;
@property (nonatomic, copy) TapRemarkBlock tapRemarkBlock;
/// 启动点赞动画
- (void)fireLikeAnimate;
/// 更新点赞UI
- (void)updateLikeUI;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#import "ComDynamicCell.h" #import "ComDynamicCell.h"
#import "GKPhotoBrowser.h" #import "GKPhotoBrowser.h"
#import "LikeButton.h"
@interface ComDynamicCell () @interface ComDynamicCell ()
@property (nonatomic, strong) UIImageView *userIcon; @property (nonatomic, strong) UIImageView *userIcon;
...@@ -15,7 +16,7 @@ ...@@ -15,7 +16,7 @@
@property (nonatomic, strong) UIButton *informBtn; @property (nonatomic, strong) UIButton *informBtn;
@property (nonatomic, strong) UIView *imgContainerView; @property (nonatomic, strong) UIView *imgContainerView;
@property (nonatomic, strong) UILabel *contentLab; @property (nonatomic, strong) UILabel *contentLab;
@property (nonatomic, strong) UIButton *likeBtn; @property (nonatomic, strong) LikeButton *likeBtn;
@property (nonatomic, strong) UIButton *remarkCountBtn; @property (nonatomic, strong) UIButton *remarkCountBtn;
@property (nonatomic, strong) NSMutableArray *photos; @property (nonatomic, strong) NSMutableArray *photos;
@end @end
...@@ -71,6 +72,15 @@ ...@@ -71,6 +72,15 @@
return self; return self;
} }
#pragma mark - public
- (void)fireLikeAnimate {
[self.likeBtn executeAnimation];
}
- (void)updateLikeUI {
[self.likeBtn updateLikeBtnState:self.model.isLike likeCount:self.model.likeCount];
}
#pragma mark - setter #pragma mark - setter
- (void)setModel:(ComDynModel *)model { - (void)setModel:(ComDynModel *)model {
_model = model; _model = model;
...@@ -79,7 +89,7 @@ ...@@ -79,7 +89,7 @@
self.userNameLab.text = model.userName; self.userNameLab.text = model.userName;
self.timeLab.text = model.time; self.timeLab.text = model.time;
self.contentLab.text = model.content; self.contentLab.text = model.content;
[self.likeBtn setTitle:[NSString stringWithFormat:@"%d", model.likeCount] forState:UIControlStateNormal]; [self.likeBtn updateLikeBtnState:model.isLike likeCount:model.likeCount];
[self.remarkCountBtn setTitle:[NSString stringWithFormat:@"%d", model.remarkCount] forState:UIControlStateNormal]; [self.remarkCountBtn setTitle:[NSString stringWithFormat:@"%d", model.remarkCount] forState:UIControlStateNormal];
[self.contentLab mas_remakeConstraints:^(MASConstraintMaker *make) { [self.contentLab mas_remakeConstraints:^(MASConstraintMaker *make) {
...@@ -96,21 +106,22 @@ ...@@ -96,21 +106,22 @@
[self.photos removeAllObjects]; [self.photos removeAllObjects];
// 再添加 // 再添加
CGFloat imgContainerViewH = [model imgHeight]; CGFloat imgContainerViewH = [model imgHeight];
[self.imgContainerView mas_makeConstraints:^(MASConstraintMaker *make) { [self.imgContainerView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.contentLab.mas_bottom).offset(12); make.top.equalTo(self.contentLab.mas_bottom).offset(12);
make.left.equalTo(self.contentView).offset(15); make.left.equalTo(self.contentView).offset(15);
make.right.equalTo(self.contentView).offset(-15); make.right.equalTo(self.contentView).offset(-15);
make.height.equalTo(@(imgContainerViewH)); make.height.equalTo(@(imgContainerViewH));
}]; }];
if (imgContainerViewH > 0) { if (imgContainerViewH > 0) {
CGFloat itemCount = model.imgUrls.count; NSArray *imgUrlArr = [model getImgUrlsArr:model.imgUrls];
CGFloat itemCount = imgUrlArr.count;
CGFloat itemSpace = itemCount > 1 ? (kScreenWidth - 60 - imgContainerViewH * itemCount) / (itemCount - 1) : 0; CGFloat itemSpace = itemCount > 1 ? (kScreenWidth - 60 - imgContainerViewH * itemCount) / (itemCount - 1) : 0;
for (int index = 0; index < itemCount; index++) { for (int index = 0; index < itemCount; index++) {
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(index*(imgContainerViewH + itemSpace), 0, imgContainerViewH, imgContainerViewH)]; UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(index*(imgContainerViewH + itemSpace), 0, imgContainerViewH, imgContainerViewH)];
[imgView cornerRadius:12]; [imgView cornerRadius:12];
imgView.tag = index; imgView.tag = index;
imgView.userInteractionEnabled = YES; imgView.userInteractionEnabled = YES;
[imgView yy_setImageWithURL:[NSURL URLWithString:model.imgUrls[index]] placeholder:[UIImage defaultPlaceholderWithSize:imgView.size]]; [imgView yy_setImageWithURL:[NSURL URLWithString:imgUrlArr[index]] placeholder:[UIImage defaultPlaceholderWithSize:imgView.size]];
imgView.dk_alphaPicker = DKAlphaPickerWithAlphas(1.f, 0.5f, 0.1f); imgView.dk_alphaPicker = DKAlphaPickerWithAlphas(1.f, 0.5f, 0.1f);
[self.imgContainerView addSubview:imgView]; [self.imgContainerView addSubview:imgView];
...@@ -118,7 +129,7 @@ ...@@ -118,7 +129,7 @@
[imgView addGestureRecognizer:tapGR]; [imgView addGestureRecognizer:tapGR];
GKPhoto *photo = [GKPhoto new]; GKPhoto *photo = [GKPhoto new];
photo.url = [NSURL URLWithString:model.imgUrls[index]]; photo.url = [NSURL URLWithString:imgUrlArr[index]];
photo.sourceImageView = imgView; photo.sourceImageView = imgView;
[self.photos addObject:photo]; [self.photos addObject:photo];
} }
...@@ -187,12 +198,19 @@ ...@@ -187,12 +198,19 @@
return _contentLab; return _contentLab;
} }
- (UIButton *)likeBtn { - (void)likeOrRemarkAction:(UIButton *)sender {
if (sender.tag == 1) {
if (self.tapLikeBlock) { self.tapLikeBlock(); }
} else {
if (self.tapRemarkBlock) { self.tapRemarkBlock(); }
}
}
- (LikeButton *)likeBtn {
if (!_likeBtn) { if (!_likeBtn) {
_likeBtn = [UIButton btnWithTitle:@"0" font:SysFont(12)]; _likeBtn = [[LikeButton alloc] initWithNormalImg:nil selectedImg:nil];
[_likeBtn dk_setTitleColorPicker:DKColorPickerWithColors(SmallTextColor, DSWhite, DSWhite) forState:UIControlStateNormal]; _likeBtn.tag = 1;
[_likeBtn setImage:[UIImage imageNamed:@"ic_shequ_dianza"] forState:UIControlStateNormal]; [_likeBtn addTarget:self action:@selector(likeOrRemarkAction:) forControlEvents:UIControlEventTouchUpInside];
_likeBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 2, 0, 0);
} }
return _likeBtn; return _likeBtn;
} }
...@@ -200,9 +218,11 @@ ...@@ -200,9 +218,11 @@
- (UIButton *)remarkCountBtn { - (UIButton *)remarkCountBtn {
if (!_remarkCountBtn) { if (!_remarkCountBtn) {
_remarkCountBtn = [UIButton btnWithTitle:@"0" font:SysFont(12)]; _remarkCountBtn = [UIButton btnWithTitle:@"0" font:SysFont(12)];
_remarkCountBtn.tag = 2;
[_remarkCountBtn dk_setTitleColorPicker:DKColorPickerWithColors(SmallTextColor, DSWhite, DSWhite) forState:UIControlStateNormal]; [_remarkCountBtn dk_setTitleColorPicker:DKColorPickerWithColors(SmallTextColor, DSWhite, DSWhite) forState:UIControlStateNormal];
[_remarkCountBtn setImage:[UIImage imageNamed:@"ic_shequ_pinlun"] forState:UIControlStateNormal]; [_remarkCountBtn setImage:[UIImage imageNamed:@"ic_shequ_pinlun"] forState:UIControlStateNormal];
_remarkCountBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 2, 0, 0); _remarkCountBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 2, 0, 0);
[_remarkCountBtn addTarget:self action:@selector(likeOrRemarkAction:) forControlEvents:UIControlEventTouchUpInside];
} }
return _remarkCountBtn; return _remarkCountBtn;
} }
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
// //
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import "ComDynamicCell.h"
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
...@@ -23,6 +24,11 @@ NS_ASSUME_NONNULL_BEGIN ...@@ -23,6 +24,11 @@ NS_ASSUME_NONNULL_BEGIN
/// 点击动态进入动态详情 /// 点击动态进入动态详情
/// @param indexPath indexPath /// @param indexPath indexPath
- (void)didSelectItem:(NSIndexPath *)indexPath; - (void)didSelectItem:(NSIndexPath *)indexPath;
/// 点赞按钮
/// @param comDynModel 动态数据model
/// @param cell cell
- (void)didTapLikeItem:(ComDynModel *)comDynModel cell:(ComDynamicCell *)cell;
@end @end
/// 社区主视图 /// 社区主视图
...@@ -35,6 +41,9 @@ NS_ASSUME_NONNULL_BEGIN ...@@ -35,6 +41,9 @@ NS_ASSUME_NONNULL_BEGIN
/// 更新社区动态 /// 更新社区动态
- (void)updateCommunityMoments:(BOOL)loadMore listArr:(NSArray *)listArr; - (void)updateCommunityMoments:(BOOL)loadMore listArr:(NSArray *)listArr;
/// 结束加载动画
- (void)endRefreshing:(BOOL)loadMore;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
// //
#import "CommunityView.h" #import "CommunityView.h"
#import "ComDynamicCell.h"
@interface CommunityView () <UITableViewDelegate, UITableViewDataSource> @interface CommunityView () <UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) UIView *headView; @property (nonatomic, strong) UIView *headView;
...@@ -42,16 +41,20 @@ ...@@ -42,16 +41,20 @@
#pragma mark - public #pragma mark - public
- (void)updateCommunityMoments:(BOOL)loadMore listArr:(NSArray *)listArr { - (void)updateCommunityMoments:(BOOL)loadMore listArr:(NSArray *)listArr {
self.listArr = [NSMutableArray arrayWithArray:listArr];
if (loadMore) { if (loadMore) {
[self.listArr addObjectsFromArray:listArr]; [self.listArr addObjectsFromArray:listArr];
[self.listView.mj_footer endRefreshing]; [self.listView.mj_footer endRefreshing];
} else { } else {
self.listArr = [NSMutableArray arrayWithArray:listArr];
[self.listView.mj_header endRefreshing]; [self.listView.mj_header endRefreshing];
} }
[self.listView reloadData]; [self.listView reloadData];
} }
- (void)endRefreshing:(BOOL)loadMore {
loadMore ? [self.listView.mj_footer endRefreshing] : [self.listView.mj_header endRefreshing];
}
#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:)]) {
...@@ -97,7 +100,18 @@ ...@@ -97,7 +100,18 @@
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
ComDynamicCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([ComDynamicCell class])]; ComDynamicCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([ComDynamicCell class])];
cell.model = self.listArr[indexPath.section]; ComDynModel *model = self.listArr[indexPath.section];
cell.model = model;
WS(weakSelf);
__weak ComDynamicCell * weakCell = (ComDynamicCell *)cell;
cell.tapLikeBlock = ^{
if (weakSelf.delegate && [weakSelf.delegate respondsToSelector:@selector(didTapLikeItem:cell:)]) {
[weakSelf.delegate didTapLikeItem:model cell:weakCell];
}
};
cell.tapRemarkBlock = ^{
[weakSelf tableView:tableView didSelectRowAtIndexPath:indexPath];
};
return cell; return cell;
} }
......
//
// LikeButton.h
// DreamSleep
//
// Created by peter on 2022/9/28.
//
#import <UIKit/UIKit.h>
typedef void (^LikeBlock)(void);
/// 封装点赞按钮
@interface LikeButton : UIButton
@property (nonatomic, copy) LikeBlock likeBlock;
- (instancetype)initWithNormalImg:(UIImage *)normalImg selectedImg:(UIImage *)selectedImg;
- (void)updateLikeBtnState:(BOOL)isLike likeCount:(int)likeCount;
- (void)executeAnimation;
@end
//
// LikeButton.m
// DreamSleep
//
// Created by peter on 2022/9/28.
//
#import "LikeButton.h"
@interface LikeButton ()
@property (nonatomic, strong) UIButton *aniIcon;
@property (nonatomic, strong) UILabel *countLab;
@property (nonatomic, strong) CAEmitterLayer *emitterLayer;
@property (nonatomic, strong) UIView *explodeAnimationView;
@property (nonatomic, strong) UIImage *normalIcon;
@property (nonatomic, strong) UIImage *selectedIcon;
@end
@implementation LikeButton
- (instancetype)initWithNormalImg:(UIImage *)normalImg selectedImg:(UIImage *)selectedImg {
if (self = [super init]) {
self.normalIcon = normalImg ?: [UIImage imageNamed:@"ic_shequ_dianza"];
self.selectedIcon = selectedImg ?: [UIImage imageNamed:@"ic_shequ_yidianza"];
[self addSubview:self.aniIcon];
[self addSubview:self.countLab];
[self.aniIcon insertSubview:self.explodeAnimationView atIndex:0];
[self.aniIcon mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self).offset(26);
make.centerY.equalTo(self);
make.size.mas_equalTo(CGSizeMake(30, 30));
}];
[self.countLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.aniIcon.mas_right).offset(2);
make.centerY.equalTo(self.aniIcon);
}];
[self.explodeAnimationView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.top.bottom.right.equalTo(self.aniIcon);
}];
[self layoutIfNeeded];
self.emitterLayer.emitterPosition = self.explodeAnimationView.center;
}
return self;
}
#pragma mark - public
- (void)updateLikeBtnState:(BOOL)isLike likeCount:(int)likeCount {
self.aniIcon.selected = isLike;
UIColor *dayColor = self.aniIcon.selected ? ColorFromHex(0xF04B77) : SmallTextColor;
self.countLab.dk_textColorPicker = DKColorPickerWithColors(dayColor, DSWhite, DSWhite);
self.countLab.text = [NSString stringWithFormat:@"%d", likeCount];
}
- (void)executeAnimation {
if (self.aniIcon.selected) {
[self popInsideWithDuration:0.5];
} else {
[self popOutsideWithDuration:0.5];
[self emitAnimate];
};
}
#pragma mark - 点赞、取消点赞
- (void)popOutsideWithDuration:(NSTimeInterval)duringTime {
__weak typeof(self) weakSelf = self;
self.transform = CGAffineTransformIdentity;
[UIView animateKeyframesWithDuration: duringTime delay: 0 options: 0 animations: ^{
[UIView addKeyframeWithRelativeStartTime: 0
relativeDuration: 1 / 3.0
animations: ^{
typeof(self) strongSelf = weakSelf;
strongSelf.aniIcon.transform = CGAffineTransformMakeScale(1.5, 1.5);
}];
[UIView addKeyframeWithRelativeStartTime: 1 / 3.0
relativeDuration: 1 / 3.0
animations: ^{
typeof(self) strongSelf = weakSelf;
strongSelf.aniIcon.transform = CGAffineTransformMakeScale(0.8, 0.8);
}];
[UIView addKeyframeWithRelativeStartTime: 2 / 3.0
relativeDuration: 1 / 3.0
animations: ^{
typeof(self) strongSelf = weakSelf;
strongSelf.aniIcon.transform = CGAffineTransformMakeScale(1.0, 1.0);
}];
} completion:^(BOOL finished) {}];
}
- (void)popInsideWithDuration:(NSTimeInterval)duringTime {
__weak typeof(self) weakSelf = self;
self.aniIcon.transform = CGAffineTransformIdentity;
[UIView animateKeyframesWithDuration: duringTime delay: 0 options: 0 animations: ^{
[UIView addKeyframeWithRelativeStartTime: 0
relativeDuration: 1 / 2.0
animations: ^{
typeof(self) strongSelf = weakSelf;
strongSelf.aniIcon.transform = CGAffineTransformMakeScale(0.8, 0.8);
}];
[UIView addKeyframeWithRelativeStartTime: 1 / 2.0
relativeDuration: 1 / 2.0
animations: ^{
typeof(self) strongSelf = weakSelf;
strongSelf.aniIcon.transform = CGAffineTransformMakeScale(1.0, 1.0);
}];
} completion:^(BOOL finished) {}];
}
#pragma mark - 粒子动画
- (void)emitAnimate {
dispatch_time_t delay = dispatch_time(DISPATCH_TIME_NOW, 0.2 * NSEC_PER_SEC);
dispatch_after(delay, dispatch_get_main_queue(), ^{
self.emitterLayer.beginTime = CACurrentMediaTime();
CABasicAnimation *ani = [CABasicAnimation animationWithKeyPath: @"emitterCells.explosion.birthRate"];
ani.fromValue = @0;
ani.toValue = @500;
[self->_emitterLayer addAnimation: ani forKey: nil];
});
}
#pragma mark - lazy
- (UIButton *)aniIcon {
if (!_aniIcon) {
_aniIcon = [UIButton new];
_aniIcon.userInteractionEnabled = NO;
[_aniIcon setImage:self.normalIcon forState:UIControlStateNormal];
[_aniIcon setImage:self.selectedIcon forState: UIControlStateSelected];
}
return _aniIcon;
}
- (UILabel *)countLab {
if (!_countLab) {
_countLab = [UILabel labWithFont:SysFont(12)];
}
return _countLab;
}
- (UIView *)explodeAnimationView {
if (!_explodeAnimationView) {
_explodeAnimationView = [UIView new];
_explodeAnimationView.clipsToBounds = NO;
_explodeAnimationView.userInteractionEnabled = NO;
CAEmitterCell *emitter = [CAEmitterCell emitterCell];
emitter.contents = (id)self.selectedIcon.CGImage;
emitter.name = @"explosion";
emitter.alphaRange = 0.2f;
emitter.alphaSpeed = -1.f;
emitter.lifetime = 0.7f;
emitter.lifetimeRange = 0.3f;
emitter.birthRate = 0;
emitter.velocity = 40.0f;
emitter.velocityRange = 10.0f;
emitter.emissionRange = M_PI_4;
emitter.scale = 0.05f;
emitter.scaleRange = 0.02;
_emitterLayer = [CAEmitterLayer layer];
_emitterLayer.name = @"emitterLayer";
_emitterLayer.emitterShape = kCAEmitterLayerCircle;
_emitterLayer.emitterMode = kCAEmitterLayerOutline;
_emitterLayer.emitterPosition = self.center;
_emitterLayer.emitterSize = CGSizeMake(25, 0);
_emitterLayer.renderMode = kCAEmitterLayerOldestFirst;
_emitterLayer.masksToBounds = NO;
_emitterLayer.emitterCells = @[emitter];
_emitterLayer.frame = [UIScreen mainScreen].bounds;
[_explodeAnimationView.layer addSublayer: _emitterLayer];
}
return _explodeAnimationView;
}
@end
...@@ -11,10 +11,22 @@ NS_ASSUME_NONNULL_BEGIN ...@@ -11,10 +11,22 @@ NS_ASSUME_NONNULL_BEGIN
@interface ComListViewModel : DSNetworkTool @interface ComListViewModel : DSNetworkTool
@property (nonatomic, assign) int offset;
@property (nonatomic, assign) int limit;
@property (nonatomic, assign) int totalCount;
@property (nonatomic, strong) NSArray *listArr; @property (nonatomic, strong) NSArray *listArr;
- (void)getComListWithCompletion:(void (^)(ComListViewModel *requestModel))completion; - (void)getComListWithCompletion:(void (^)(ComListViewModel *requestModel))completion;
/// 社区动态查询列表接口
/// @param offset offset
/// @param completion completion
+ (NSURLSessionDataTask *)querySleepDynamicListWithOffset:(int)offset completion:(void (^)(ComListViewModel *requestModel))completion;
/// 用户点赞、取消点赞接口
/// @param talkID talkID
/// @param completion completion
+ (NSURLSessionDataTask *)userDynamicPraiseWithTalkID:(int)talkID completion:(void (^)(ComListViewModel *requestModel))completion;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END
...@@ -24,27 +24,47 @@ ...@@ -24,27 +24,47 @@
requestModel.listArr = [tmpArr copy]; requestModel.listArr = [tmpArr copy];
DSLog(@"apiDic:%@", apiDic); DSLog(@"apiDic:%@", apiDic);
completion(requestModel); completion(requestModel);
// NSString *api = @"query_ssmian_knowledge_list";
// NSString *argStr = [NSString stringWithFormat:@"query{%@}", api];
// return [self httpPostBodyRequestWithAPI:api params:@{@"query" : argStr} view:nil hasNetActivity:YES loadingInfo:nil hasFailInfo:NO success:^(NSDictionary * _Nonnull apiDic) {
// DSLog(@"文章咨询数据接口apiDic:%@", apiDic);
// requestModel.resCode = DSResCodeSuccess;
// NSDictionary *resultDic = apiDic[@"result"];
//
// completion(requestModel);
// } failure:^(id _Nonnull failureInfo) {
// requestModel.resCode = [failureInfo[@"errorCode"] integerValue];
// requestModel.errMessage = failureInfo[@"errMessage"];
// completion(requestModel);
// }];
} }
- (NSArray *)listArr { + (NSURLSessionDataTask *)querySleepDynamicListWithOffset:(int)offset completion:(void (^)(ComListViewModel *requestModel))completion {
if (!_listArr) { ComListViewModel * requestModel = [[ComListViewModel alloc] init];
_listArr = [NSArray array]; NSString *api = @"query_sleep_dynamic_list";
} NSString *argStr = [NSString stringWithFormat:@"query{%@(offset:%d)}", api, offset];
return _listArr; return [self httpPostBodyRequestWithAPI:api params:@{@"query" : argStr} view:nil hasNetActivity:YES loadingInfo:nil hasFailInfo:NO success:^(NSDictionary * _Nonnull apiDic) {
DSLog(@"社区动态查询列表接口apiDic:%@", apiDic);
requestModel.resCode = DSResCodeSuccess;
NSDictionary *resultDic = apiDic[@"result"];
NSArray *data_list = resultDic[@"data_list"];
NSMutableArray *tmpArr = [NSMutableArray array];
for (int i = 0; i < data_list.count; i++) {
ComDynModel *model = [ComDynModel yy_modelWithDictionary:data_list[i]];
[tmpArr addObject:model];
}
requestModel.listArr = [tmpArr copy];
requestModel.offset = [resultDic[@"offset"] intValue];
requestModel.limit = [resultDic[@"limit"] intValue];
requestModel.totalCount = [resultDic[@"count"] intValue];
completion(requestModel);
} failure:^(id _Nonnull failureInfo) {
requestModel.resCode = [failureInfo[@"errorCode"] integerValue];
requestModel.errMessage = failureInfo[@"errMessage"];
completion(requestModel);
}];
}
+ (NSURLSessionDataTask *)userDynamicPraiseWithTalkID:(int)talkID completion:(void (^)(ComListViewModel *requestModel))completion {
ComListViewModel * requestModel = [[ComListViewModel alloc] init];
NSString *api = @"user_dynamic_praise";
NSString *argStr = [NSString stringWithFormat:@"mutation{%@(talk_id:%d)}", api, talkID];
return [self httpPostBodyRequestWithAPI:api params:@{@"query" : argStr} view:nil hasNetActivity:YES loadingInfo:nil hasFailInfo:NO success:^(NSDictionary * _Nonnull apiDic) {
DSLog(@"用户动态点赞、取消点赞接口apiDic:%@", apiDic);
requestModel.resCode = DSResCodeSuccess;
completion(requestModel);
} failure:^(id _Nonnull failureInfo) {
requestModel.resCode = [failureInfo[@"errorCode"] integerValue];
requestModel.errMessage = failureInfo[@"errMessage"];
completion(requestModel);
}];
} }
@end @end
{
"images" : [
{
"filename" : "ic_shequ_yidianza.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "ic_shequ_yidianza@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "ic_shequ_yidianza@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!