Tweak disappearing messages indicator.

This commit is contained in:
Matthew Chen 2018-07-10 13:27:35 -04:00
parent ec7365971e
commit d42ff03ecd
56 changed files with 519 additions and 0 deletions

View File

@ -43,6 +43,7 @@
340FC8D0205BF2FA007AEB0F /* OWSBackupIO.m in Sources */ = {isa = PBXBuildFile; fileRef = 340FC8CE205BF2FA007AEB0F /* OWSBackupIO.m */; };
341F2C0F1F2B8AE700D07D6B /* DebugUIMisc.m in Sources */ = {isa = PBXBuildFile; fileRef = 341F2C0E1F2B8AE700D07D6B /* DebugUIMisc.m */; };
34277A5E20751BDC006049F2 /* OWSQuotedMessageView.m in Sources */ = {isa = PBXBuildFile; fileRef = 34277A5C20751BDC006049F2 /* OWSQuotedMessageView.m */; };
3427C64320F500E000EEC730 /* OWSMessageTimerView.m in Sources */ = {isa = PBXBuildFile; fileRef = 3427C64220F500DF00EEC730 /* OWSMessageTimerView.m */; };
3430FE181F7751D4000EC51B /* GiphyAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3430FE171F7751D4000EC51B /* GiphyAPI.swift */; };
34330A5A1E7875FB00DF2FB9 /* fontawesome-webfont.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 34330A591E7875FB00DF2FB9 /* fontawesome-webfont.ttf */; };
34330A5C1E787A9800DF2FB9 /* dripicons-v2.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 34330A5B1E787A9800DF2FB9 /* dripicons-v2.ttf */; };
@ -641,6 +642,8 @@
341F2C0E1F2B8AE700D07D6B /* DebugUIMisc.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DebugUIMisc.m; sourceTree = "<group>"; };
34277A5C20751BDC006049F2 /* OWSQuotedMessageView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSQuotedMessageView.m; sourceTree = "<group>"; };
34277A5D20751BDC006049F2 /* OWSQuotedMessageView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSQuotedMessageView.h; sourceTree = "<group>"; };
3427C64120F500DE00EEC730 /* OWSMessageTimerView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSMessageTimerView.h; sourceTree = "<group>"; };
3427C64220F500DF00EEC730 /* OWSMessageTimerView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSMessageTimerView.m; sourceTree = "<group>"; };
3430FE171F7751D4000EC51B /* GiphyAPI.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GiphyAPI.swift; sourceTree = "<group>"; };
34330A591E7875FB00DF2FB9 /* fontawesome-webfont.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "fontawesome-webfont.ttf"; sourceTree = "<group>"; };
34330A5B1E787A9800DF2FB9 /* dripicons-v2.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "dripicons-v2.ttf"; sourceTree = "<group>"; };
@ -1771,6 +1774,8 @@
34D920E620E179C200D51158 /* OWSMessageFooterView.m */,
34DBF000206BD5A400025978 /* OWSMessageTextView.h */,
34DBEFFF206BD5A400025978 /* OWSMessageTextView.m */,
3427C64120F500DE00EEC730 /* OWSMessageTimerView.h */,
3427C64220F500DF00EEC730 /* OWSMessageTimerView.m */,
34277A5D20751BDC006049F2 /* OWSQuotedMessageView.h */,
34277A5C20751BDC006049F2 /* OWSQuotedMessageView.m */,
34D1F0A51F867BFC0066283D /* OWSSystemMessageCell.h */,
@ -3363,6 +3368,7 @@
45A663C51F92EC760027B59E /* GroupTableViewCell.swift in Sources */,
34CA631B2097806F00E526A0 /* OWSContactShareView.m in Sources */,
34D1F0861F8678AA0066283D /* ConversationViewController.m in Sources */,
3427C64320F500E000EEC730 /* OWSMessageTimerView.m in Sources */,
B90418E6183E9DD40038554A /* DateUtil.m in Sources */,
340FC8BD204DAC8D007AEB0F /* ShowGroupMembersViewController.m in Sources */,
459311FC1D75C948008DD4F0 /* OWSDeviceTableViewCell.m in Sources */,

View File

@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "timer00_12@1x.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "timer00_12@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "timer00_12@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 217 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 318 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 656 B

View File

@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "timer05_12@1x.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "timer05_12@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "timer05_12@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 249 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 432 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 758 B

View File

@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "timer10_12@1x.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "timer10_12@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "timer10_12@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 255 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 433 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 759 B

View File

@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "timer15_12@1x.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "timer15_12@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "timer15_12@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 244 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 398 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 685 B

View File

@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "timer20_12@1x.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "timer20_12@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "timer20_12@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 268 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 486 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 815 B

View File

@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "timer25_12@1x.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "timer25_12@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "timer25_12@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 272 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 504 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 860 B

View File

@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "timer30_12@1x.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "timer30_12@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "timer30_12@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 267 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 446 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 782 B

View File

@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "timer35_12@1x.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "timer35_12@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "timer35_12@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 282 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 545 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 862 B

View File

@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "timer40_12@1x.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "timer40_12@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "timer40_12@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 289 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 554 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 900 B

View File

@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "timer45_12@1x.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "timer45_12@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "timer45_12@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 251 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 482 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 759 B

View File

@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "timer50_12@1x.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "timer50_12@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "timer50_12@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 302 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 599 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 932 B

View File

@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "timer55_12@1x.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "timer55_12@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "timer55_12@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 312 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 621 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 962 B

View File

@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "timer60_12@1x.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "timer60_12@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "timer60_12@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 272 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 539 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 864 B

View File

@ -4,6 +4,7 @@
#import "OWSMessageFooterView.h"
#import "DateUtil.h"
#import "OWSMessageTimerView.h"
#import "Signal-Swift.h"
#import <QuartzCore/QuartzCore.h>
@ -13,6 +14,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic) UILabel *timestampLabel;
@property (nonatomic) UIImageView *statusIndicatorImageView;
@property (nonatomic, nullable) OWSMessageTimerView *messageTimerView;
@end
@ -160,6 +162,19 @@ NS_ASSUME_NONNULL_BEGIN
return messageStatus == MessageReceiptStatusFailed;
}
- (BOOL)isDisappearingMessage:(ConversationViewItem *)viewItem
{
OWSAssert(viewItem);
if (viewItem.interaction.interactionType != OWSInteractionType_OutgoingMessage
&& viewItem.interaction.interactionType != OWSInteractionType_IncomingMessage) {
return NO;
}
TSMessage *message = (TSMessage *)viewItem.interaction;
return message.shouldStartExpireTimer;
}
- (void)configureLabelsWithConversationViewItem:(ConversationViewItem *)viewItem
{
OWSAssert(viewItem);
@ -218,6 +233,11 @@ NS_ASSUME_NONNULL_BEGIN
result.width += (self.maxImageWidth + self.hSpacing);
}
}
if ([self isDisappearingMessage:viewItem]) {
result.width += ([OWSMessageTimerView measureSize].width + self.hSpacing);
}
return CGSizeCeil(result);
}
@ -236,6 +256,9 @@ NS_ASSUME_NONNULL_BEGIN
- (void)prepareForReuse
{
[self.statusIndicatorImageView.layer removeAllAnimations];
[self.messageTimerView removeFromSuperview];
self.messageTimerView = nil;
}
@end

View File

@ -0,0 +1,22 @@
//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface OWSMessageTimerView : UIView
- (instancetype)init NS_UNAVAILABLE;
- (instancetype)initWithFrame:(CGRect)frame NS_UNAVAILABLE;
- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder NS_UNAVAILABLE;
- (instancetype)initWithExpiration:(uint64_t)expirationTimestamp
initialDurationSeconds:(uint32_t)initialDurationSeconds NS_DESIGNATED_INITIALIZER;
+ (CGSize)measureSize;
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,169 @@
//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWSMessageTimerView.h"
#import "ConversationViewController.h"
#import "NSDate+OWS.h"
#import "OWSMath.h"
#import "UIColor+OWS.h"
#import "UIView+OWS.h"
#import <QuartzCore/QuartzCore.h>
#import <SignalServiceKit/NSTimer+OWS.h>
NS_ASSUME_NONNULL_BEGIN
const CGFloat kDisappearingMessageIconSize = 12.f;
@interface OWSMessageTimerView ()
@property (nonatomic) uint32_t initialDurationSeconds;
@property (nonatomic) uint64_t expirationTimestamp;
@property (nonatomic) UIColor *tintColor;
@property (nonatomic) UIImageView *imageView;
@property (nonatomic, nullable) NSTimer *animationTimer;
@property (nonatomic) NSInteger progress12;
@end
#pragma mark -
@implementation OWSMessageTimerView
- (void)dealloc
{
[self.animationTimer invalidate];
self.animationTimer = nil;
}
- (instancetype)initWithExpiration:(uint64_t)expirationTimestamp
initialDurationSeconds:(uint32_t)initialDurationSeconds
tintColor:(UIColor *)tintColor;
{
self = [super initWithFrame:CGRectZero];
if (!self) {
return self;
}
self.expirationTimestamp = expirationTimestamp;
self.initialDurationSeconds = initialDurationSeconds;
self.tintColor = tintColor;
[self commonInit];
return self;
}
- (void)commonInit
{
self.imageView = [UIImageView new];
[self addSubview:self.imageView];
[self.imageView autoPinToSuperviewEdges];
[self.imageView autoSetDimension:ALDimensionWidth toSize:kDisappearingMessageIconSize];
[self.imageView autoSetDimension:ALDimensionHeight toSize:kDisappearingMessageIconSize];
[self updateProgress12];
[self updateIcon];
self.animationTimer = [NSTimer weakScheduledTimerWithTimeInterval:1.f
target:self
selector:@selector(updateProgress12)
userInfo:nil
repeats:YES];
}
- (void)updateProgress12
{
CGFloat secondsLeft = MAX(0, (self.expirationTimestamp - [NSDate ows_millisecondTimeStamp]) / 1000.f);
CGFloat progress = 0.f;
if (self.initialDurationSeconds > 0) {
progress = CGFloatClamp(1.f - (secondsLeft / self.initialDurationSeconds), 0.f, 1.f);
}
OWSAssert(progress >= 0.f);
OWSAssert(progress <= 1.f);
self.progress12 = (NSInteger)round(CGFloatClamp(progress, 0.f, 1.f) * 12);
}
- (void)setProgress12:(NSInteger)progress12
{
if (_progress12 == progress12) {
return;
}
_progress12 = progress12;
[self updateIcon];
}
- (void)updateIcon
{
self.imageView.image = [[self progressIcon] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
self.imageView.tintColor = self.tintColor;
}
- (UIImage *)progressIcon
{
OWSAssert(self.progress12 >= 0);
OWSAssert(self.progress12 <= 12);
UIImage *_Nullable image;
switch (self.progress12) {
default:
case 0:
image = [UIImage imageNamed:@"disappearing_message_00"];
break;
case 1:
image = [UIImage imageNamed:@"disappearing_message_05"];
break;
case 2:
image = [UIImage imageNamed:@"disappearing_message_10"];
break;
case 3:
image = [UIImage imageNamed:@"disappearing_message_15"];
break;
case 4:
image = [UIImage imageNamed:@"disappearing_message_20"];
break;
case 5:
image = [UIImage imageNamed:@"disappearing_message_25"];
break;
case 6:
image = [UIImage imageNamed:@"disappearing_message_30"];
break;
case 7:
image = [UIImage imageNamed:@"disappearing_message_35"];
break;
case 8:
image = [UIImage imageNamed:@"disappearing_message_40"];
break;
case 9:
image = [UIImage imageNamed:@"disappearing_message_45"];
break;
case 10:
image = [UIImage imageNamed:@"disappearing_message_50"];
break;
case 11:
image = [UIImage imageNamed:@"disappearing_message_55"];
break;
case 12:
image = [UIImage imageNamed:@"disappearing_message_60"];
break;
}
OWSAssert(image);
OWSAssert(image.size.width == kDisappearingMessageIconSize);
OWSAssert(image.size.height == kDisappearingMessageIconSize);
return image;
}
+ (CGSize)measureSize
{
return CGSizeMake(kDisappearingMessageIconSize, kDisappearingMessageIconSize);
}
@end
NS_ASSUME_NONNULL_END