1
0
mirror of https://github.com/danog/Telegram.git synced 2024-12-04 10:27:46 +01:00
Telegram/Watch/Extension/TGNeoForwardHeaderViewModel.m

87 lines
2.7 KiB
Mathematica
Raw Normal View History

2015-10-01 18:19:52 +02:00
#import "TGNeoForwardHeaderViewModel.h"
#import "TGNeoLabelViewModel.h"
#import "TGBridgeUser.h"
2016-02-25 01:03:51 +01:00
#import "TGBridgeChat.h"
2015-10-01 18:19:52 +02:00
const CGFloat TGNeoForwardHeaderHeight = 29;
@interface TGNeoForwardHeaderViewModel ()
{
TGNeoLabelViewModel *_forwardedModel;
TGNeoLabelViewModel *_authorNameModel;
}
@end
@implementation TGNeoForwardHeaderViewModel
2016-02-25 01:03:51 +01:00
- (instancetype)initWithOutgoing:(bool)outgoing
2015-10-01 18:19:52 +02:00
{
self = [super init];
if (self != nil)
{
2016-02-25 01:03:51 +01:00
_forwardedModel = [[TGNeoLabelViewModel alloc] initWithText:TGLocalized(@"Watch.Message.ForwardedFrom") font:[UIFont systemFontOfSize:12] color:[self subtitleColorForOutgoing:outgoing] attributes:nil];
2015-10-01 18:19:52 +02:00
_forwardedModel.multiline = false;
[self addSubmodel:_forwardedModel];
2016-02-25 01:03:51 +01:00
}
return self;
}
- (instancetype)initWithForwardAttachment:(TGBridgeForwardedMessageMediaAttachment *)attachment user:(TGBridgeUser *)user outgoing:(bool)outgoing
{
self = [self initWithOutgoing:outgoing];
if (self != nil)
{
2015-10-01 18:19:52 +02:00
_authorNameModel = [[TGNeoLabelViewModel alloc] initWithText:[user displayName] font:[UIFont systemFontOfSize:12 weight:UIFontWeightMedium] color:[self normalColorForOutgoing:outgoing] attributes:nil];
2016-02-25 01:03:51 +01:00
_authorNameModel.multiline = false;
[self addSubmodel:_authorNameModel];
}
return self;
}
- (instancetype)initWithForwardAttachment:(TGBridgeForwardedMessageMediaAttachment *)attachment chat:(TGBridgeChat *)chat outgoing:(bool)outgoing
{
self = [self initWithOutgoing:outgoing];
if (self != nil)
{
_authorNameModel = [[TGNeoLabelViewModel alloc] initWithText:chat.groupTitle font:[UIFont systemFontOfSize:12 weight:UIFontWeightMedium] color:[self normalColorForOutgoing:outgoing] attributes:nil];
2015-10-01 18:19:52 +02:00
_authorNameModel.multiline = false;
[self addSubmodel:_authorNameModel];
}
return self;
}
- (UIColor *)normalColorForOutgoing:(bool)outgoing
{
if (outgoing)
return [UIColor whiteColor];
else
return [UIColor hexColor:0x1f97f8];
}
- (UIColor *)subtitleColorForOutgoing:(bool)outgoing
{
if (outgoing)
return [UIColor whiteColor];
else
return [UIColor blackColor];
}
- (CGSize)contentSizeWithContainerSize:(CGSize)containerSize
{
CGSize forwardedSize = [_forwardedModel contentSizeWithContainerSize:containerSize];
CGSize nameSize = [_authorNameModel contentSizeWithContainerSize:containerSize];
return CGSizeMake(MIN(MAX(forwardedSize.width, nameSize.width), containerSize.width), TGNeoForwardHeaderHeight);
}
- (void)setFrame:(CGRect)frame
{
[super setFrame:frame];
_forwardedModel.frame = CGRectMake(0, 0, frame.size.width, 20);
_authorNameModel.frame = CGRectMake(0, 14.5f, frame.size.width, 20);
}
@end