Add Send When Online shortcut

This commit is contained in:
Ilya Laktyushin
2023-03-09 20:03:26 +04:00
parent 838c352971
commit 656a0247fc
42 changed files with 1160 additions and 182 deletions

View File

@@ -105,6 +105,7 @@
bool _isDark;
CGRect _sendButtonFrame;
bool _canSendSilently;
bool _canSendWhenOnline;
bool _canSchedule;
bool _reminder;
bool _hasTimer;
@@ -117,6 +118,7 @@
UIView *_containerView;
UIView *_separatorView;
TGMediaPickerSendActionSheetItemView *_sendSilentlyButton;
TGMediaPickerSendActionSheetItemView *_sendWhenOnlineButton;
TGMediaPickerSendActionSheetItemView *_scheduleButton;
TGMediaPickerSendActionSheetItemView *_timerButton;
}
@@ -124,13 +126,14 @@
@implementation TGMediaPickerSendActionSheetController
- (instancetype)initWithContext:(id<LegacyComponentsContext>)context isDark:(bool)isDark sendButtonFrame:(CGRect)sendButtonFrame canSendSilently:(bool)canSendSilently canSchedule:(bool)canSchedule reminder:(bool)reminder hasTimer:(bool)hasTimer {
- (instancetype)initWithContext:(id<LegacyComponentsContext>)context isDark:(bool)isDark sendButtonFrame:(CGRect)sendButtonFrame canSendSilently:(bool)canSendSilently canSendWhenOnline:(bool)canSendWhenOnline canSchedule:(bool)canSchedule reminder:(bool)reminder hasTimer:(bool)hasTimer {
self = [super initWithContext:context];
if (self != nil) {
_context = context;
_isDark = isDark;
_sendButtonFrame = sendButtonFrame;
_canSendSilently = canSendSilently;
_canSendWhenOnline = canSendWhenOnline;
_canSchedule = canSchedule;
_reminder = reminder;
_hasTimer = hasTimer;
@@ -163,7 +166,7 @@
__weak TGMediaPickerSendActionSheetController *weakSelf = self;
if (_canSendSilently) {
_sendSilentlyButton = [[TGMediaPickerSendActionSheetItemView alloc] initWithTitle:TGLocalized(@"Conversation.SendMessage.SendSilently") icon:TGComponentsImageNamed(@"MediaMute") isDark:_isDark isLast:!_canSchedule && !_hasTimer];
_sendSilentlyButton = [[TGMediaPickerSendActionSheetItemView alloc] initWithTitle:TGLocalized(@"Conversation.SendMessage.SendSilently") icon:TGComponentsImageNamed(@"Editor/Silently") isDark:_isDark isLast:!_canSchedule && !_hasTimer && !_canSendWhenOnline];
_sendSilentlyButton.pressed = ^{
__strong TGMediaPickerSendActionSheetController *strongSelf = weakSelf;
[strongSelf sendSilentlyPressed];
@@ -171,8 +174,17 @@
[_containerView addSubview:_sendSilentlyButton];
}
if (_canSendWhenOnline) {
_sendWhenOnlineButton = [[TGMediaPickerSendActionSheetItemView alloc] initWithTitle:TGLocalized(@"Conversation.SendMessage.SendWhenOnline") icon:TGComponentsImageNamed(@"Editor/WhenOnline") isDark:_isDark isLast:!_canSchedule && !_hasTimer];
_sendWhenOnlineButton.pressed = ^{
__strong TGMediaPickerSendActionSheetController *strongSelf = weakSelf;
[strongSelf sendWhenOnlinePressed];
};
[_containerView addSubview:_sendWhenOnlineButton];
}
if (_canSchedule) {
_scheduleButton = [[TGMediaPickerSendActionSheetItemView alloc] initWithTitle:TGLocalized(_reminder ? @"Conversation.SendMessage.SetReminder" : @"Conversation.SendMessage.ScheduleMessage") icon:TGComponentsImageNamed(@"MediaSchedule") isDark:_isDark isLast:!_hasTimer];
_scheduleButton = [[TGMediaPickerSendActionSheetItemView alloc] initWithTitle:TGLocalized(_reminder ? @"Conversation.SendMessage.SetReminder" : @"Conversation.SendMessage.ScheduleMessage") icon:TGComponentsImageNamed(@"Editor/Schedule") isDark:_isDark isLast:!_hasTimer];
_scheduleButton.pressed = ^{
__strong TGMediaPickerSendActionSheetController *strongSelf = weakSelf;
[strongSelf schedulePressed];
@@ -295,8 +307,8 @@
CGFloat itemHeight = 44.0;
CGFloat containerWidth = 240.0;
CGFloat containerHeight = (_canSendSilently + _canSchedule + _hasTimer) * itemHeight;
containerWidth = MAX(containerWidth, MAX(_timerButton.buttonLabel.frame.size.width, MAX(_sendSilentlyButton.buttonLabel.frame.size.width, _scheduleButton.buttonLabel.frame.size.width)) + 84.0);
CGFloat containerHeight = (_canSendSilently + _canSchedule + _hasTimer + _canSendWhenOnline) * itemHeight;
containerWidth = MAX(containerWidth, MAX(_timerButton.buttonLabel.frame.size.width, MAX(_sendSilentlyButton.buttonLabel.frame.size.width, MAX(_sendWhenOnlineButton.buttonLabel.frame.size.width, _scheduleButton.buttonLabel.frame.size.width))) + 84.0);
if (!_dismissed) {
_containerView.frame = CGRectMake(CGRectGetMaxX(_sendButtonFrame) - containerWidth - 8.0, _sendButtonFrame.origin.y - containerHeight - 4.0, containerWidth, containerHeight);
}
@@ -305,6 +317,9 @@
_sendSilentlyButton.frame = CGRectMake(0.0, offset, containerWidth, itemHeight);
offset += _sendSilentlyButton.frame.size.height;
_sendWhenOnlineButton.frame = CGRectMake(0.0, offset, containerWidth, itemHeight);
offset += _sendWhenOnlineButton.frame.size.height;
_scheduleButton.frame = CGRectMake(0.0, offset, containerWidth, itemHeight);
offset += _scheduleButton.frame.size.height;
@@ -327,6 +342,14 @@
self.sendSilently();
}
- (void)sendWhenOnlinePressed {
[self animateOut:false];
if (self.sendWhenOnline != nil)
self.sendWhenOnline();
}
- (void)schedulePressed {
[self animateOut:false];