//
//  SDTimeLineCellModel.m
//  GSD_WeiXin(wechat)
//
//  Created by gsd on 16/2/25.
//  Copyright © 2016年 GSD. All rights reserved.
//

/*
 
 *********************************************************************************
 *
 * GSD_WeiXin
 *
 * QQ交流群: 459274049
 * Email : gsdios@126.com
 * GitHub: https://github.com/gsdios/GSD_WeiXin
 * 新浪微博:GSD_iOS
 *
 * 此“高仿微信”用到了很高效方便的自动布局库SDAutoLayout（一行代码搞定自动布局）
 * SDAutoLayout地址：https://github.com/gsdios/SDAutoLayout
 * SDAutoLayout视频教程：http://www.letv.com/ptv/vplay/24038772.html
 * SDAutoLayout用法示例：https://github.com/gsdios/SDAutoLayout/blob/master/README.md
 *
 *********************************************************************************
 
 */

#import "SDTimeLineCellModel.h"

#import <UIKit/UIKit.h>

extern const CGFloat contentLabelFontSize;
extern CGFloat maxContentLabelHeight;

@implementation SDTimeLineCellModel
{
    CGFloat _lastContentWidth;
}

@synthesize friendContent = _friendContent;

+ (NSDictionary *)mj_objectClassInArray{
    return @{@"list" : [SDTimeLineCellCommentItemModel class]};
}

- (void)setFriendContent:(NSString *)friendContent {
    _friendContent = friendContent;
    NSMutableAttributedString *attString = [[NSMutableAttributedString alloc] initWithString:_friendContent];
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    paragraphStyle.lineSpacing = 4.0f;
    [attString addAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:16]} range:NSMakeRange(0, _friendContent.length)];
    [attString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, _friendContent.length)];
    self.attributedFriendContent = attString;
    CGFloat contentW = [UIScreen mainScreen].bounds.size.width - 80;
    if (contentW != _lastContentWidth) {
        _lastContentWidth = contentW;
        CGRect textRect = [_attributedFriendContent boundingRectWithSize:CGSizeMake(contentW, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading context:nil];
        if (textRect.size.height > maxContentLabelHeight) {
            _shouldShowMoreButton = YES;
        } else {
            _shouldShowMoreButton = NO;
        }
    }
}

- (NSString *)friendContent {
//    CGFloat contentW = [UIScreen mainScreen].bounds.size.width - 80;
//    if (contentW != _lastContentWidth) {
//        _lastContentWidth = contentW;
//        CGRect textRect = [_friendContent boundingRectWithSize:CGSizeMake(contentW, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:contentLabelFontSize]} context:nil];
//        if (textRect.size.height > maxContentLabelHeight) {
//            _shouldShowMoreButton = YES;
//        } else {
//            _shouldShowMoreButton = NO;
//        }
//    }
    return _friendContent;
}

- (void)setFriendImgUrl:(NSString *)friendImgUrl {
    _friendImgUrl = friendImgUrl;
    NSArray *imgUrls = [_friendImgUrl componentsSeparatedByString:@","];
    if (imgUrls.count == 1){
        NSString *friendImg = [NSString stringWithFormat:@"%@%@",[SLHttpCenter SharedInstance].serverUrl, imgUrls.firstObject];
        [[SDWebImageManager sharedManager] loadImageWithURL:[NSURL URLWithString:friendImg] options:0 progress:nil completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, SDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) {
            if (image) {
                self.imageSize = image.size;
            }
        }];
    }
}

- (void)setIsOpening:(BOOL)isOpening
{
    if (!_shouldShowMoreButton) {
        _isOpening = NO;
    } else {
        _isOpening = isOpening;
    }
}


@end


@implementation SDTimeLineCellLikeItemModel


@end

@implementation SDTimeLineCellCommentItemModel


@end
