pull/731/head
Ryan Zhao 8 months ago
parent 3d1b930ede
commit 83a64c5ca1

@ -7,7 +7,6 @@
objects = {
/* Begin PBXBuildFile section */
3427C64320F500E000EEC730 /* OWSMessageTimerView.m in Sources */ = {isa = PBXBuildFile; fileRef = 3427C64220F500DF00EEC730 /* OWSMessageTimerView.m */; };
3430FE181F7751D4000EC51B /* GiphyAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3430FE171F7751D4000EC51B /* GiphyAPI.swift */; };
34661FB820C1C0D60056EDD6 /* message_sent.aiff in Resources */ = {isa = PBXBuildFile; fileRef = 34661FB720C1C0D60056EDD6 /* message_sent.aiff */; };
346B66311F4E29B200E5122F /* CropScaleImageViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 346B66301F4E29B200E5122F /* CropScaleImageViewController.swift */; };
@ -1130,8 +1129,6 @@
285705D20F792E174C8A9BBA /* Pods-GlobalDependencies-FrameworkAndExtensionDependencies-SessionNotificationServiceExtension.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-GlobalDependencies-FrameworkAndExtensionDependencies-SessionNotificationServiceExtension.debug.xcconfig"; path = "Target Support Files/Pods-GlobalDependencies-FrameworkAndExtensionDependencies-SessionNotificationServiceExtension/Pods-GlobalDependencies-FrameworkAndExtensionDependencies-SessionNotificationServiceExtension.debug.xcconfig"; sourceTree = "<group>"; };
29E827FDF6C1032BB985740C /* Pods_GlobalDependencies_FrameworkAndExtensionDependencies_SessionNotificationServiceExtension.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_GlobalDependencies_FrameworkAndExtensionDependencies_SessionNotificationServiceExtension.framework; sourceTree = BUILT_PRODUCTS_DIR; };
34040971CC7AF9C8A6C1E838 /* Pods-GlobalDependencies-Session.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-GlobalDependencies-Session.debug.xcconfig"; path = "Target Support Files/Pods-GlobalDependencies-Session/Pods-GlobalDependencies-Session.debug.xcconfig"; 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>"; };
34480B371FD092A900BC14EF /* SignalShareExtension-Bridging-Header.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "SignalShareExtension-Bridging-Header.h"; sourceTree = "<group>"; };
34661FB720C1C0D60056EDD6 /* message_sent.aiff */ = {isa = PBXFileReference; lastKnownFileType = audio.aiff; name = message_sent.aiff; path = Session/Meta/AudioFiles/message_sent.aiff; sourceTree = SOURCE_ROOT; };
@ -2841,8 +2838,6 @@
isa = PBXGroup;
children = (
B84A89BB25DE328A0040017D /* ProfilePictureVC.swift */,
3427C64120F500DE00EEC730 /* OWSMessageTimerView.h */,
3427C64220F500DF00EEC730 /* OWSMessageTimerView.m */,
FD7115EA28C5D78E00B47552 /* ThreadSettingsViewModel.swift */,
FD7115F328C71EB200B47552 /* ThreadDisappearingMessagesSettingsViewModel.swift */,
);
@ -6388,7 +6383,6 @@
FD37E9CC28A1E578003AE748 /* AppearanceViewController.swift in Sources */,
B8EB20F02640F7F000773E52 /* OpenGroupInvitationView.swift in Sources */,
C328254025CA55880062D0A7 /* ContextMenuVC.swift in Sources */,
3427C64320F500E000EEC730 /* OWSMessageTimerView.m in Sources */,
B8269D2925C7A4B400488AB4 /* InputView.swift in Sources */,
FD71162E28E168C700B47552 /* SettingsViewModel.swift in Sources */,
);

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

@ -1,192 +0,0 @@
//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWSMessageTimerView.h"
#import "OWSMath.h"
#import "UIView+OWS.h"
#import <QuartzCore/QuartzCore.h>
#import <SignalCoreKit/OWSAsserts.h>
#import <PureLayout/PureLayout.h>
#import <SignalCoreKit/NSDate+OWS.h>
#import <SessionUtilitiesKit/NSTimer+Proxying.h>
#import <SessionSnodeKit/SessionSnodeKit.h>
NS_ASSUME_NONNULL_BEGIN
const CGFloat kDisappearingMessageIconSize = 12.f;
@interface OWSMessageTimerView ()
@property (nonatomic) uint32_t initialDurationSeconds;
@property (nonatomic) uint64_t expirationTimestamp;
@property (nonatomic, nullable) NSTimer *animationTimer;
// 0 == about to expire, 12 == just started countdown.
@property (nonatomic) NSInteger progress12;
@end
#pragma mark -
@implementation OWSMessageTimerView
- (void)dealloc
{
[self clearAnimation];
}
- (instancetype)init
{
self = [super initWithFrame:CGRectZero];
if (!self) {
return self;
}
[self commonInit];
return self;
}
- (void)commonInit
{
self.imageView = [UIImageView new];
[self addSubview:self.imageView];
[self.imageView ows_autoPinToSuperviewEdges];
[self.imageView autoSetDimension:ALDimensionWidth toSize:kDisappearingMessageIconSize];
[self.imageView autoSetDimension:ALDimensionHeight toSize:kDisappearingMessageIconSize];
}
- (void)configureWithExpirationTimestamp:(uint64_t)expirationTimestamp
initialDurationSeconds:(uint32_t)initialDurationSeconds
{
self.expirationTimestamp = expirationTimestamp;
self.initialDurationSeconds = initialDurationSeconds;
[self updateProgress12];
[self updateIcon];
[self startAnimation];
}
- (void)updateProgress12
{
BOOL hasStartedCountdown = self.expirationTimestamp > 0;
if (!hasStartedCountdown) {
self.progress12 = 12;
return;
}
uint64_t nowTimestamp = [SNSnodeAPI currentOffsetTimestampMs];
CGFloat secondsLeft
= (self.expirationTimestamp > nowTimestamp ? (self.expirationTimestamp - nowTimestamp) / 1000.f : 0.f);
CGFloat progress = 0.f;
if (self.initialDurationSeconds > 0) {
progress = CGFloatClamp(secondsLeft / self.initialDurationSeconds, 0.f, 1.f);
}
OWSAssertDebug(progress >= 0.f);
OWSAssertDebug(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];
}
- (UIImage *)progressIcon
{
OWSAssertDebug(self.progress12 >= 0);
OWSAssertDebug(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;
}
OWSAssertDebug(image);
OWSAssertDebug(image.size.width == kDisappearingMessageIconSize);
OWSAssertDebug(image.size.height == kDisappearingMessageIconSize);
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
{
return CGSizeMake(kDisappearingMessageIconSize, kDisappearingMessageIconSize);
}
@end
NS_ASSUME_NONNULL_END

@ -4,5 +4,4 @@
// Separate iOS Frameworks from other imports.
#import "OWSAudioPlayer.h"
#import "OWSBezierPathView.h"
#import "OWSMessageTimerView.h"
#import "OWSWindowManager.h"

Loading…
Cancel
Save