ComDynModel.m 2.0 KB
//
//  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