ComDynModel.m
2.0 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//
// ComDynModel.m
// DreamSleep
//
// Created by peter on 2022/9/27.
//
#import "ComDynModel.h"
@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 contentW = kScreenWidth - 60;
NSString *content = self.content;
CGFloat contentH = [UILabel getHeightByWidth:contentW text:content font:SysFont(14)];
return contentH > 100 ? 100 : contentH;
}
- (CGFloat)imgHeight {
if (self.imgUrls) {
if (iPhone5) {
return 100;
} else {
NSArray *imgUrls = [self getImgUrlsArr:self.imgUrls];
if (imgUrls.count == 1 || imgUrls.count == 2) {
return 150;
} else if (imgUrls.count == 3) {
return 95;
}
return 0;
}
}
return 0;
}
- (CGFloat)cellHeight {
NSArray *imgUrls = [self getImgUrlsArr:self.imgUrls];
CGFloat topH = 67;
CGFloat bottomH = imgUrls.count ? 52 : 56;
CGFloat contentH = [self contentHeight];
CGFloat imgTextSpace = imgUrls.count ? 12 : 0;
CGFloat imgH = [self imgHeight];
return topH + bottomH + contentH + imgTextSpace + imgH;
}
- (NSArray *)getImgUrlsArr:(NSString *)imgUrls {
if (imgUrls && imgUrls.length) {
return [imgUrls componentsSeparatedByString:@"|"];
}
return @[];
}
@end