From 1d1390b2a1bc71abb452f2524ed4d7c134f79ef6 Mon Sep 17 00:00:00 2001 From: Sam Steele Date: Thu, 17 Jun 2021 07:11:36 -0400 Subject: [PATCH] Delay updating the Hand-Off message text --- IRCCloud/Classes/MainViewController.h | 1 + IRCCloud/Classes/MainViewController.m | 25 ++++++++++++++++++++----- build-scripts/BUILD | 2 +- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/IRCCloud/Classes/MainViewController.h b/IRCCloud/Classes/MainViewController.h index d571158ee..eb86cb856 100644 --- a/IRCCloud/Classes/MainViewController.h +++ b/IRCCloud/Classes/MainViewController.h @@ -118,6 +118,7 @@ BOOL _ignoreInsetChanges; NSString *_msgid; UIView *_leftBorder, *_rightBorder; + NSTimer *_handoffTimer; } @property (nonatomic) int cidToOpen; @property (nonatomic) int bidToOpen; diff --git a/IRCCloud/Classes/MainViewController.m b/IRCCloud/Classes/MainViewController.m index acdbdf800..caa810e2b 100644 --- a/IRCCloud/Classes/MainViewController.m +++ b/IRCCloud/Classes/MainViewController.m @@ -2545,15 +2545,29 @@ -(void)expandingTextViewDidChange:(UIExpandingTextView *)expandingTextView { } else { [self performSelectorOnMainThread:@selector(scheduleSuggestionsTimer) withObject:nil waitUntilDone:NO]; } - [[self userActivity] setNeedsSave:YES]; - [self userActivityWillSave:[self userActivity]]; - if(self->_buffer) { - self->_buffer.draft = expandingTextView.text.length ? expandingTextView.text : nil; - } UIColor *c = ([NetworkConnection sharedInstance].state == kIRCCloudStateConnected)?([UIColor isDarkTheme]?[UIColor whiteColor]:[UIColor unreadBlueColor]):[UIColor textareaBackgroundColor]; [self->_sendBtn setTitleColor:c forState:UIControlStateNormal]; [self->_sendBtn setTitleColor:c forState:UIControlStateDisabled]; [self->_sendBtn setTitleColor:c forState:UIControlStateHighlighted]; + + if(self->_handoffTimer) + [self->_handoffTimer invalidate]; + self->_handoffTimer = [NSTimer scheduledTimerWithTimeInterval:0.25 target:self selector:@selector(_updateHandoffTimer) userInfo:nil repeats:NO]; +} + +-(void)_cancelHandoffTimer { + if(self->_handoffTimer) + [self->_handoffTimer invalidate]; + _handoffTimer = nil; +} + +-(void)_updateHandoffTimer { + _handoffTimer = nil; + [[self userActivity] setNeedsSave:YES]; + [self userActivityWillSave:[self userActivity]]; + if(self->_buffer) { + self->_buffer.draft = _message.text.length ? _message.text : nil; + } } -(BOOL)expandingTextViewShouldReturn:(UIExpandingTextView *)expandingTextView { @@ -2843,6 +2857,7 @@ -(void)launchURL:(NSURL *)url { -(void)bufferSelected:(int)bid { [self performSelectorOnMainThread:@selector(cancelSuggestionsTimer) withObject:nil waitUntilDone:NO]; + [self performSelectorOnMainThread:@selector(_cancelHandoffTimer) withObject:nil waitUntilDone:NO]; _sortedChannels = nil; _sortedUsers = nil; BOOL changed = (self->_buffer && _buffer.bid != bid) || !_buffer; diff --git a/build-scripts/BUILD b/build-scripts/BUILD index a3090d211..9a1371776 100644 --- a/build-scripts/BUILD +++ b/build-scripts/BUILD @@ -1 +1 @@ -168 \ No newline at end of file +169 \ No newline at end of file