From 8f9311a6ac5ffcb5cc15b01826b391d59ebcbbcd Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Tue, 24 Oct 2017 19:02:27 -0700 Subject: [PATCH] Show timer in navbar without reload // FREEBIE --- .../ConversationViewController.m | 40 ++++++++++++++----- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m index 7555588de..c73c92901 100644 --- a/Signal/src/ViewControllers/ConversationView/ConversationViewController.m +++ b/Signal/src/ViewControllers/ConversationView/ConversationViewController.m @@ -180,6 +180,7 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) { @property (nonatomic) UILabel *navigationBarTitleLabel; @property (nonatomic) UILabel *navigationBarSubtitleLabel; @property (nonatomic, nullable) UIView *bannerView; +@property (nonatomic, nullable) OWSDisappearingMessagesConfiguration *disappearingMessagesConfiguration; // Back Button Unread Count @property (nonatomic, readonly) UIView *backButtonUnreadCountView; @@ -578,9 +579,12 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) { // unless it ever becomes possible to load this VC without going via the HomeViewController. [self.contactsManager requestSystemContactsOnce]; - OWSDisappearingMessagesConfiguration *configuration = - [OWSDisappearingMessagesConfiguration fetchObjectWithUniqueID:self.thread.uniqueId]; - [self setBarButtonItemsForDisappearingMessagesConfiguration:configuration]; + [self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *_Nonnull transaction) { + self.disappearingMessagesConfiguration = + [OWSDisappearingMessagesConfiguration fetchObjectWithUniqueID:self.thread.uniqueId transaction:transaction]; + }]; + + [self updateBarButtonItems]; [self setNavigationTitle]; [self updateLastVisibleTimestamp]; @@ -1046,9 +1050,7 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) { self.navigationBarTitleLabel.attributedText = name; // Changing the title requires relayout of the nav bar contents. - OWSDisappearingMessagesConfiguration *configuration = - [OWSDisappearingMessagesConfiguration fetchObjectWithUniqueID:self.thread.uniqueId]; - [self setBarButtonItemsForDisappearingMessagesConfiguration:configuration]; + [self updateBarButtonItems]; } - (void)createHeaderViews @@ -1127,8 +1129,7 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) { self.navigationItem.leftBarButtonItem = backItem; } -- (void)setBarButtonItemsForDisappearingMessagesConfiguration: - (OWSDisappearingMessagesConfiguration *)disappearingMessagesConfiguration +- (void)updateBarButtonItems { // We want to leave space for the "back" button, the "timer" button, and the "call" // button, and all of the whitespace around these views. There @@ -1139,7 +1140,7 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) { if ([self canCall]) { rightBarButtonItemCount++; } - if (disappearingMessagesConfiguration.isEnabled) { + if (self.disappearingMessagesConfiguration.isEnabled) { rightBarButtonItemCount++; } CGFloat barButtonSize = 0; @@ -1205,7 +1206,7 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) { [barButtons addObject:[[UIBarButtonItem alloc] initWithCustomView:callButton]]; } - if (disappearingMessagesConfiguration.isEnabled) { + if (self.disappearingMessagesConfiguration.isEnabled) { UIButton *timerButton = [UIButton buttonWithType:UIButtonTypeCustom]; UIImage *image = [UIImage imageNamed:@"button_timer_white"]; [timerButton setImage:image forState:UIControlStateNormal]; @@ -1225,7 +1226,7 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) { NSString *formatString = NSLocalizedString( @"DISAPPEARING_MESSAGES_HINT", @"Accessibility hint that contains current timeout information"); timerButton.accessibilityHint = - [NSString stringWithFormat:formatString, [disappearingMessagesConfiguration durationString]]; + [NSString stringWithFormat:formatString, self.disappearingMessagesConfiguration.durationString]; [timerButton addTarget:self action:@selector(didTapTimerInNavbar:) forControlEvents:UIControlEventTouchUpInside]; @@ -1520,6 +1521,18 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) { } } +- (void)setDisappearingMessagesConfiguration: + (nullable OWSDisappearingMessagesConfiguration *)disappearingMessagesConfiguration +{ + if (_disappearingMessagesConfiguration.isEnabled == disappearingMessagesConfiguration.isEnabled + && _disappearingMessagesConfiguration.durationSeconds == disappearingMessagesConfiguration.durationSeconds) { + return; + } + + _disappearingMessagesConfiguration = disappearingMessagesConfiguration; + [self updateBarButtonItems]; +} + - (void)updateMessageMappingRangeOptions:(MessagesRangeSizeMode)mode { // The "old" range length may have been increased by insertions of new messages @@ -2789,6 +2802,11 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) { [self setNavigationTitle]; } + [self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *_Nonnull transaction) { + self.disappearingMessagesConfiguration = + [OWSDisappearingMessagesConfiguration fetchObjectWithUniqueID:self.thread.uniqueId transaction:transaction]; + }]; + if (![[self.uiDatabaseConnection ext:TSMessageDatabaseViewExtensionName] hasChangesForGroup:self.thread.uniqueId inNotifications:notifications]) { [self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {