123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- //
- // InformationCell.m
- // WFChat UIKit
- //
- // Created by WF Chat on 2017/9/1.
- // Copyright © 2017年 WildFireChat. All rights reserved.
- //
- #import "WFCUInformationCell.h"
- #import <WFChatClient/WFCChatClient.h>
- #import "WFCUUtilities.h"
- #define TEXT_TOP_PADDING 6
- #define TEXT_BUTTOM_PADDING 6
- #define TEXT_LEFT_PADDING 8
- #define TEXT_RIGHT_PADDING 8
- #define TEXT_LABEL_TOP_PADDING TEXT_TOP_PADDING + 4
- #define TEXT_LABEL_BUTTOM_PADDING TEXT_BUTTOM_PADDING + 4
- #define TEXT_LABEL_LEFT_PADDING 30
- #define TEXT_LABEL_RIGHT_PADDING 30
- @implementation WFCUInformationCell
- + (CGSize)sizeForCell:(WFCUMessageModel *)msgModel withViewWidth:(CGFloat)width {
- CGFloat height = [super hightForHeaderArea:msgModel];
- NSString *infoText;
- if ([msgModel.message.content isKindOfClass:[WFCCNotificationMessageContent class]]) {
- WFCCNotificationMessageContent *content = (WFCCNotificationMessageContent *)msgModel.message.content;
- infoText = [content formatNotification:msgModel.message];
- } else {
- infoText = [msgModel.message digest];
- }
- CGSize size = [WFCUUtilities getTextDrawingSize:infoText font:[UIFont systemFontOfSize:14] constrainedSize:CGSizeMake(width - TEXT_LABEL_LEFT_PADDING - TEXT_LABEL_RIGHT_PADDING - TEXT_LEFT_PADDING - TEXT_RIGHT_PADDING, 8000)];
- size.height += TEXT_LABEL_TOP_PADDING + TEXT_LABEL_BUTTOM_PADDING + TEXT_TOP_PADDING + TEXT_BUTTOM_PADDING;
- size.height += height;
- return CGSizeMake(width, size.height);
- }
- - (void)setModel:(WFCUMessageModel *)model {
- [super setModel:model];
-
- __weak typeof(self)ws = self;
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onUserInfoUpdated:) name:kUserInfoUpdated object:nil];
- NSString *infoText;
- if ([model.message.content isKindOfClass:[WFCCNotificationMessageContent class]]) {
- WFCCNotificationMessageContent *content = (WFCCNotificationMessageContent *)model.message.content;
- infoText = [content formatNotification:model.message];
- } else {
- infoText = [model.message digest];
- }
-
- CGFloat width = self.contentView.bounds.size.width;
-
- CGSize size = [WFCUUtilities getTextDrawingSize:infoText font:[UIFont systemFontOfSize:14] constrainedSize:CGSizeMake(width - TEXT_LABEL_LEFT_PADDING - TEXT_LABEL_RIGHT_PADDING - TEXT_LEFT_PADDING - TEXT_RIGHT_PADDING, 8000)];
-
-
- self.infoLabel.text = infoText;
- self.infoLabel.layoutMargins = UIEdgeInsetsMake(TEXT_TOP_PADDING, TEXT_LEFT_PADDING, TEXT_BUTTOM_PADDING, TEXT_RIGHT_PADDING);
- CGFloat timeLableEnd = 0;
- if (!self.timeLabel.hidden) {
- timeLableEnd = self.timeLabel.frame.size.height + self.timeLabel.frame.origin.y;
- }
- self.infoLabel.frame = CGRectMake((width - size.width)/2 - 8, timeLableEnd + TEXT_LABEL_TOP_PADDING, size.width + 16, size.height + TEXT_TOP_PADDING + TEXT_BUTTOM_PADDING);
- // self.infoLabel.textAlignment = NSTextAlignmentCenter;
- }
- - (void)onUserInfoUpdated:(NSNotification *)notification {
- NSArray<WFCCUserInfo *> *userInfoList = notification.userInfo[@"userInfoList"];
- BOOL needUpdate = false;
- for (WFCCUserInfo *userInfo in userInfoList) {
- if ([self.model.message.content isKindOfClass:[WFCCAddGroupeMemberNotificationContent class]]) {
- WFCCAddGroupeMemberNotificationContent *cnt = (WFCCAddGroupeMemberNotificationContent *)self.model.message.content;
- if ([cnt.invitor isEqualToString:userInfo.userId] || [cnt.invitees containsObject:userInfo.userId]) {
- needUpdate = true;
- break;
- }
- } else if ([self.model.message.content isKindOfClass:[WFCCCreateGroupNotificationContent class]]) {
- WFCCCreateGroupNotificationContent *cnt = (WFCCCreateGroupNotificationContent *)self.model.message.content;
- if ([cnt.creator isEqualToString:userInfo.userId]) {
- needUpdate = true;
- break;
- }
- }
- }
-
- if (needUpdate) {
- [self setModel:self.model];
- }
- }
- - (UILabel *)infoLabel {
- if (!_infoLabel) {
- _infoLabel = [[UILabel alloc] init];
- _infoLabel.numberOfLines = 0;
- _infoLabel.font = [UIFont systemFontOfSize:14];
-
- _infoLabel.textColor = [UIColor whiteColor];
- _infoLabel.numberOfLines = 0;
- _infoLabel.lineBreakMode = NSLineBreakByTruncatingTail;
- _infoLabel.textAlignment = NSTextAlignmentCenter;
- _infoLabel.font = [UIFont systemFontOfSize:14.f];
- _infoLabel.layer.masksToBounds = YES;
- _infoLabel.layer.cornerRadius = 5.f;
- _infoLabel.textAlignment = NSTextAlignmentCenter;
- _infoLabel.backgroundColor = [UIColor colorWithRed:201/255.f green:201/255.f blue:201/255.f alpha:1.f];
-
- [self.contentView addSubview:_infoLabel];
- }
- return _infoLabel;
- }
- - (void)dealloc {
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- }
- @end
|