Tweak disappearing messages indicator.

pull/1/head
Matthew Chen 7 years ago
parent d42ff03ecd
commit 0038c9b3b3

@ -14,7 +14,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic) UILabel *timestampLabel; @property (nonatomic) UILabel *timestampLabel;
@property (nonatomic) UIImageView *statusIndicatorImageView; @property (nonatomic) UIImageView *statusIndicatorImageView;
@property (nonatomic, nullable) OWSMessageTimerView *messageTimerView; @property (nonatomic) OWSMessageTimerView *messageTimerView;
@end @end
@ -44,6 +44,9 @@ NS_ASSUME_NONNULL_BEGIN
self.timestampLabel = [UILabel new]; self.timestampLabel = [UILabel new];
[self addArrangedSubview:self.timestampLabel]; [self addArrangedSubview:self.timestampLabel];
self.messageTimerView = [OWSMessageTimerView new];
[self addArrangedSubview:self.messageTimerView];
self.statusIndicatorImageView = [UIImageView new]; self.statusIndicatorImageView = [UIImageView new];
[self.statusIndicatorImageView setContentHuggingHigh]; [self.statusIndicatorImageView setContentHuggingHigh];
[self addArrangedSubview:self.statusIndicatorImageView]; [self addArrangedSubview:self.statusIndicatorImageView];
@ -92,6 +95,18 @@ NS_ASSUME_NONNULL_BEGIN
} }
self.timestampLabel.textColor = textColor; self.timestampLabel.textColor = textColor;
if ([self isDisappearingMessage:viewItem]) {
TSMessage *message = (TSMessage *)viewItem.interaction;
uint64_t expirationTimestamp = message.expiresAt;
uint32_t expiresInSeconds = message.expiresInSeconds;
[self.messageTimerView configureWithExpirationTimestamp:expirationTimestamp
initialDurationSeconds:expiresInSeconds
tintColor:textColor];
self.messageTimerView.hidden = NO;
} else {
self.messageTimerView.hidden = YES;
}
if (viewItem.interaction.interactionType == OWSInteractionType_OutgoingMessage) { if (viewItem.interaction.interactionType == OWSInteractionType_OutgoingMessage) {
TSOutgoingMessage *outgoingMessage = (TSOutgoingMessage *)viewItem.interaction; TSOutgoingMessage *outgoingMessage = (TSOutgoingMessage *)viewItem.interaction;
@ -257,8 +272,7 @@ NS_ASSUME_NONNULL_BEGIN
{ {
[self.statusIndicatorImageView.layer removeAllAnimations]; [self.statusIndicatorImageView.layer removeAllAnimations];
[self.messageTimerView removeFromSuperview]; [self.messageTimerView prepareForReuse];
self.messageTimerView = nil;
} }
@end @end

@ -8,12 +8,15 @@ NS_ASSUME_NONNULL_BEGIN
@interface OWSMessageTimerView : UIView @interface OWSMessageTimerView : UIView
- (instancetype)init NS_UNAVAILABLE; - (instancetype)init NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithFrame:(CGRect)frame NS_UNAVAILABLE; - (instancetype)initWithFrame:(CGRect)frame NS_UNAVAILABLE;
- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder NS_UNAVAILABLE; - (nullable instancetype)initWithCoder:(NSCoder *)aDecoder NS_UNAVAILABLE;
- (instancetype)initWithExpiration:(uint64_t)expirationTimestamp - (void)configureWithExpirationTimestamp:(uint64_t)expirationTimestamp
initialDurationSeconds:(uint32_t)initialDurationSeconds NS_DESIGNATED_INITIALIZER; initialDurationSeconds:(uint32_t)initialDurationSeconds
tintColor:(UIColor *)tintColor;
- (void)prepareForReuse;
+ (CGSize)measureSize; + (CGSize)measureSize;

@ -25,6 +25,7 @@ const CGFloat kDisappearingMessageIconSize = 12.f;
@property (nonatomic, nullable) NSTimer *animationTimer; @property (nonatomic, nullable) NSTimer *animationTimer;
// 0 == about to expire, 12 == just started countdown.
@property (nonatomic) NSInteger progress12; @property (nonatomic) NSInteger progress12;
@ -36,23 +37,16 @@ const CGFloat kDisappearingMessageIconSize = 12.f;
- (void)dealloc - (void)dealloc
{ {
[self.animationTimer invalidate]; [self clearAnimation];
self.animationTimer = nil;
} }
- (instancetype)initWithExpiration:(uint64_t)expirationTimestamp - (instancetype)init
initialDurationSeconds:(uint32_t)initialDurationSeconds
tintColor:(UIColor *)tintColor;
{ {
self = [super initWithFrame:CGRectZero]; self = [super initWithFrame:CGRectZero];
if (!self) { if (!self) {
return self; return self;
} }
self.expirationTimestamp = expirationTimestamp;
self.initialDurationSeconds = initialDurationSeconds;
self.tintColor = tintColor;
[self commonInit]; [self commonInit];
return self; return self;
@ -65,15 +59,19 @@ const CGFloat kDisappearingMessageIconSize = 12.f;
[self.imageView autoPinToSuperviewEdges]; [self.imageView autoPinToSuperviewEdges];
[self.imageView autoSetDimension:ALDimensionWidth toSize:kDisappearingMessageIconSize]; [self.imageView autoSetDimension:ALDimensionWidth toSize:kDisappearingMessageIconSize];
[self.imageView autoSetDimension:ALDimensionHeight toSize:kDisappearingMessageIconSize]; [self.imageView autoSetDimension:ALDimensionHeight toSize:kDisappearingMessageIconSize];
}
- (void)configureWithExpirationTimestamp:(uint64_t)expirationTimestamp
initialDurationSeconds:(uint32_t)initialDurationSeconds
tintColor:(UIColor *)tintColor;
{
self.expirationTimestamp = expirationTimestamp;
self.initialDurationSeconds = initialDurationSeconds;
self.tintColor = tintColor;
[self updateProgress12]; [self updateProgress12];
[self updateIcon]; [self updateIcon];
[self startAnimation];
self.animationTimer = [NSTimer weakScheduledTimerWithTimeInterval:1.f
target:self
selector:@selector(updateProgress12)
userInfo:nil
repeats:YES];
} }
- (void)updateProgress12 - (void)updateProgress12
@ -81,7 +79,7 @@ const CGFloat kDisappearingMessageIconSize = 12.f;
CGFloat secondsLeft = MAX(0, (self.expirationTimestamp - [NSDate ows_millisecondTimeStamp]) / 1000.f); CGFloat secondsLeft = MAX(0, (self.expirationTimestamp - [NSDate ows_millisecondTimeStamp]) / 1000.f);
CGFloat progress = 0.f; CGFloat progress = 0.f;
if (self.initialDurationSeconds > 0) { if (self.initialDurationSeconds > 0) {
progress = CGFloatClamp(1.f - (secondsLeft / self.initialDurationSeconds), 0.f, 1.f); progress = CGFloatClamp(secondsLeft / self.initialDurationSeconds, 0.f, 1.f);
} }
OWSAssert(progress >= 0.f); OWSAssert(progress >= 0.f);
OWSAssert(progress <= 1.f); OWSAssert(progress <= 1.f);
@ -159,6 +157,28 @@ const CGFloat kDisappearingMessageIconSize = 12.f;
return image; return image;
} }
- (void)startAnimation
{
[self clearAnimation];
self.animationTimer = [NSTimer weakScheduledTimerWithTimeInterval:0.1f
target:self
selector:@selector(updateProgress12)
userInfo:nil
repeats:YES];
}
- (void)clearAnimation
{
[self.animationTimer invalidate];
self.animationTimer = nil;
}
- (void)prepareForReuse
{
[self clearAnimation];
}
+ (CGSize)measureSize + (CGSize)measureSize
{ {
return CGSizeMake(kDisappearingMessageIconSize, kDisappearingMessageIconSize); return CGSizeMake(kDisappearingMessageIconSize, kDisappearingMessageIconSize);

Loading…
Cancel
Save