Show timer in navbar without reload

// FREEBIE
This commit is contained in:
Michael Kirk 2017-10-24 19:02:27 -07:00
parent ec840340e2
commit 8f9311a6ac

View file

@ -180,6 +180,7 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
@property (nonatomic) UILabel *navigationBarTitleLabel; @property (nonatomic) UILabel *navigationBarTitleLabel;
@property (nonatomic) UILabel *navigationBarSubtitleLabel; @property (nonatomic) UILabel *navigationBarSubtitleLabel;
@property (nonatomic, nullable) UIView *bannerView; @property (nonatomic, nullable) UIView *bannerView;
@property (nonatomic, nullable) OWSDisappearingMessagesConfiguration *disappearingMessagesConfiguration;
// Back Button Unread Count // Back Button Unread Count
@property (nonatomic, readonly) UIView *backButtonUnreadCountView; @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. // unless it ever becomes possible to load this VC without going via the HomeViewController.
[self.contactsManager requestSystemContactsOnce]; [self.contactsManager requestSystemContactsOnce];
OWSDisappearingMessagesConfiguration *configuration = [self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *_Nonnull transaction) {
[OWSDisappearingMessagesConfiguration fetchObjectWithUniqueID:self.thread.uniqueId]; self.disappearingMessagesConfiguration =
[self setBarButtonItemsForDisappearingMessagesConfiguration:configuration]; [OWSDisappearingMessagesConfiguration fetchObjectWithUniqueID:self.thread.uniqueId transaction:transaction];
}];
[self updateBarButtonItems];
[self setNavigationTitle]; [self setNavigationTitle];
[self updateLastVisibleTimestamp]; [self updateLastVisibleTimestamp];
@ -1046,9 +1050,7 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
self.navigationBarTitleLabel.attributedText = name; self.navigationBarTitleLabel.attributedText = name;
// Changing the title requires relayout of the nav bar contents. // Changing the title requires relayout of the nav bar contents.
OWSDisappearingMessagesConfiguration *configuration = [self updateBarButtonItems];
[OWSDisappearingMessagesConfiguration fetchObjectWithUniqueID:self.thread.uniqueId];
[self setBarButtonItemsForDisappearingMessagesConfiguration:configuration];
} }
- (void)createHeaderViews - (void)createHeaderViews
@ -1127,8 +1129,7 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
self.navigationItem.leftBarButtonItem = backItem; self.navigationItem.leftBarButtonItem = backItem;
} }
- (void)setBarButtonItemsForDisappearingMessagesConfiguration: - (void)updateBarButtonItems
(OWSDisappearingMessagesConfiguration *)disappearingMessagesConfiguration
{ {
// We want to leave space for the "back" button, the "timer" button, and the "call" // 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 // button, and all of the whitespace around these views. There
@ -1139,7 +1140,7 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
if ([self canCall]) { if ([self canCall]) {
rightBarButtonItemCount++; rightBarButtonItemCount++;
} }
if (disappearingMessagesConfiguration.isEnabled) { if (self.disappearingMessagesConfiguration.isEnabled) {
rightBarButtonItemCount++; rightBarButtonItemCount++;
} }
CGFloat barButtonSize = 0; CGFloat barButtonSize = 0;
@ -1205,7 +1206,7 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
[barButtons addObject:[[UIBarButtonItem alloc] initWithCustomView:callButton]]; [barButtons addObject:[[UIBarButtonItem alloc] initWithCustomView:callButton]];
} }
if (disappearingMessagesConfiguration.isEnabled) { if (self.disappearingMessagesConfiguration.isEnabled) {
UIButton *timerButton = [UIButton buttonWithType:UIButtonTypeCustom]; UIButton *timerButton = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *image = [UIImage imageNamed:@"button_timer_white"]; UIImage *image = [UIImage imageNamed:@"button_timer_white"];
[timerButton setImage:image forState:UIControlStateNormal]; [timerButton setImage:image forState:UIControlStateNormal];
@ -1225,7 +1226,7 @@ typedef NS_ENUM(NSInteger, MessagesRangeSizeMode) {
NSString *formatString = NSLocalizedString( NSString *formatString = NSLocalizedString(
@"DISAPPEARING_MESSAGES_HINT", @"Accessibility hint that contains current timeout information"); @"DISAPPEARING_MESSAGES_HINT", @"Accessibility hint that contains current timeout information");
timerButton.accessibilityHint = timerButton.accessibilityHint =
[NSString stringWithFormat:formatString, [disappearingMessagesConfiguration durationString]]; [NSString stringWithFormat:formatString, self.disappearingMessagesConfiguration.durationString];
[timerButton addTarget:self [timerButton addTarget:self
action:@selector(didTapTimerInNavbar:) action:@selector(didTapTimerInNavbar:)
forControlEvents:UIControlEventTouchUpInside]; 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 - (void)updateMessageMappingRangeOptions:(MessagesRangeSizeMode)mode
{ {
// The "old" range length may have been increased by insertions of new messages // 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 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 if (![[self.uiDatabaseConnection ext:TSMessageDatabaseViewExtensionName] hasChangesForGroup:self.thread.uniqueId
inNotifications:notifications]) { inNotifications:notifications]) {
[self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) { [self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {