Skip to content

Commit a6c7d29

Browse files
committed
Merge branch 'progress-ring'
2 parents a537c34 + 8fb0117 commit a6c7d29

File tree

6 files changed

+134
-154
lines changed

6 files changed

+134
-154
lines changed

Authenticator.xcodeproj/project.pbxproj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
1D60589B0D05DD56006BFB54 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; };
1212
43B5E4365C6C4081AEF41717 /* libPods.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 9B03839CF35E4014987A36CA /* libPods.a */; };
1313
8B0028B511EB75920092DE18 /* OTPScannerOverlayView.m in Sources */ = {isa = PBXBuildFile; fileRef = 8B0028B411EB75920092DE18 /* OTPScannerOverlayView.m */; };
14-
8B45557811932B5D00ABD707 /* OTPClock.m in Sources */ = {isa = PBXBuildFile; fileRef = 8B45557711932B5D00ABD707 /* OTPClock.m */; };
1514
8BF23A7213D4EF7000F3FD82 /* UIColor+OTP.m in Sources */ = {isa = PBXBuildFile; fileRef = 8BF23A7113D4EF7000F3FD82 /* UIColor+OTP.m */; };
1615
C9044FC31821BD63002C3C3F /* OTPToken+Persistence.m in Sources */ = {isa = PBXBuildFile; fileRef = C9044FC21821BD63002C3C3F /* OTPToken+Persistence.m */; };
1716
C9044FC71821C466002C3C3F /* OTPToken+Serialization.m in Sources */ = {isa = PBXBuildFile; fileRef = C9044FC61821C466002C3C3F /* OTPToken+Serialization.m */; };
@@ -33,6 +32,7 @@
3332
C9C6CCA21842E331000100C2 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C9C6CCA11842E331000100C2 /* Images.xcassets */; };
3433
C9D6C83F1906BD68004F0E08 /* OTPSegmentedControlCell.m in Sources */ = {isa = PBXBuildFile; fileRef = C9D6C83E1906BD68004F0E08 /* OTPSegmentedControlCell.m */; };
3534
C9D6C8461906CD54004F0E08 /* OTPTextFieldCell.m in Sources */ = {isa = PBXBuildFile; fileRef = C9D6C8451906CD54004F0E08 /* OTPTextFieldCell.m */; };
35+
C9D6C84C19075044004F0E08 /* OTPProgressRing.m in Sources */ = {isa = PBXBuildFile; fileRef = C9D6C84B19075044004F0E08 /* OTPProgressRing.m */; };
3636
C9F75C951843D01500B6FA14 /* iTunesArtwork in Resources */ = {isa = PBXBuildFile; fileRef = C9F75C931843D01500B6FA14 /* iTunesArtwork */; };
3737
C9F75C961843D01500B6FA14 /* iTunesArtwork@2x in Resources */ = {isa = PBXBuildFile; fileRef = C9F75C941843D01500B6FA14 /* iTunesArtwork@2x */; };
3838
C9F75C9C1843D31A00B6FA14 /* OTPTokenManager.m in Sources */ = {isa = PBXBuildFile; fileRef = C9F75C9B1843D31A00B6FA14 /* OTPTokenManager.m */; };
@@ -59,8 +59,6 @@
5959
8B0028B311EB75920092DE18 /* OTPScannerOverlayView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OTPScannerOverlayView.h; sourceTree = "<group>"; };
6060
8B0028B411EB75920092DE18 /* OTPScannerOverlayView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OTPScannerOverlayView.m; sourceTree = "<group>"; };
6161
8B2B8AE1118BA49F00437315 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = README.md; sourceTree = "<group>"; };
62-
8B45557611932B5D00ABD707 /* OTPClock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OTPClock.h; sourceTree = "<group>"; };
63-
8B45557711932B5D00ABD707 /* OTPClock.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OTPClock.m; sourceTree = "<group>"; };
6462
8BF23A7013D4EF7000F3FD82 /* UIColor+OTP.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIColor+OTP.h"; sourceTree = "<group>"; };
6563
8BF23A7113D4EF7000F3FD82 /* UIColor+OTP.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIColor+OTP.m"; sourceTree = "<group>"; };
6664
8BF5147F118799AE005C936F /* Authenticator-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Authenticator-Info.plist"; sourceTree = "<group>"; };
@@ -103,6 +101,8 @@
103101
C9D6C83E1906BD68004F0E08 /* OTPSegmentedControlCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OTPSegmentedControlCell.m; sourceTree = "<group>"; };
104102
C9D6C8441906CD54004F0E08 /* OTPTextFieldCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OTPTextFieldCell.h; sourceTree = "<group>"; };
105103
C9D6C8451906CD54004F0E08 /* OTPTextFieldCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OTPTextFieldCell.m; sourceTree = "<group>"; };
104+
C9D6C84A19075044004F0E08 /* OTPProgressRing.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OTPProgressRing.h; sourceTree = "<group>"; };
105+
C9D6C84B19075044004F0E08 /* OTPProgressRing.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OTPProgressRing.m; sourceTree = "<group>"; };
106106
C9F75C931843D01500B6FA14 /* iTunesArtwork */ = {isa = PBXFileReference; explicitFileType = image.png; path = iTunesArtwork; sourceTree = "<group>"; };
107107
C9F75C941843D01500B6FA14 /* iTunesArtwork@2x */ = {isa = PBXFileReference; explicitFileType = image.png; path = "iTunesArtwork@2x"; sourceTree = "<group>"; };
108108
C9F75C9A1843D31A00B6FA14 /* OTPTokenManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OTPTokenManager.h; sourceTree = "<group>"; };
@@ -262,9 +262,9 @@
262262
C9F75CA11843F9BE00B6FA14 /* OTPTokenListViewController.m */,
263263
C9F75C9A1843D31A00B6FA14 /* OTPTokenManager.h */,
264264
C9F75C9B1843D31A00B6FA14 /* OTPTokenManager.m */,
265-
8B45557611932B5D00ABD707 /* OTPClock.h */,
266-
8B45557711932B5D00ABD707 /* OTPClock.m */,
267265
C98C1C4517D2EDF500A07D3F /* Cells */,
266+
C9D6C84A19075044004F0E08 /* OTPProgressRing.h */,
267+
C9D6C84B19075044004F0E08 /* OTPProgressRing.m */,
268268
);
269269
name = Display;
270270
sourceTree = "<group>";
@@ -465,8 +465,8 @@
465465
C9044FC71821C466002C3C3F /* OTPToken+Serialization.m in Sources */,
466466
C958CC51182A1FDD00DD47D0 /* OTPTokenType.m in Sources */,
467467
C9F75CA21843F9BE00B6FA14 /* OTPTokenListViewController.m in Sources */,
468+
C9D6C84C19075044004F0E08 /* OTPProgressRing.m in Sources */,
468469
C9044FC31821BD63002C3C3F /* OTPToken+Persistence.m in Sources */,
469-
8B45557811932B5D00ABD707 /* OTPClock.m in Sources */,
470470
C99069D1180CBAC900BAEF53 /* OTPScannerViewController.m in Sources */,
471471
C9D6C83F1906BD68004F0E08 /* OTPSegmentedControlCell.m in Sources */,
472472
8B0028B511EB75920092DE18 /* OTPScannerOverlayView.m in Sources */,

Authenticator/Classes/OTPClock.h

Lines changed: 0 additions & 27 deletions
This file was deleted.

Authenticator/Classes/OTPClock.m

Lines changed: 0 additions & 112 deletions
This file was deleted.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//
2+
// OTPProgressRing.h
3+
// Authenticator
4+
//
5+
// Copyright (c) 2014 Matt Rubin
6+
//
7+
// Permission is hereby granted, free of charge, to any person obtaining a copy of
8+
// this software and associated documentation files (the "Software"), to deal in
9+
// the Software without restriction, including without limitation the rights to
10+
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11+
// the Software, and to permit persons to whom the Software is furnished to do so,
12+
// subject to the following conditions:
13+
//
14+
// The above copyright notice and this permission notice shall be included in all
15+
// copies or substantial portions of the Software.
16+
//
17+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19+
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20+
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21+
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22+
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23+
//
24+
25+
@import UIKit;
26+
27+
28+
@interface OTPProgressRing : UIView
29+
30+
@property (nonatomic) NSTimeInterval period;
31+
32+
@end
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
//
2+
// OTPProgressRing.m
3+
// Authenticator
4+
//
5+
// Copyright (c) 2014 Matt Rubin
6+
//
7+
// Permission is hereby granted, free of charge, to any person obtaining a copy of
8+
// this software and associated documentation files (the "Software"), to deal in
9+
// the Software without restriction, including without limitation the rights to
10+
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11+
// the Software, and to permit persons to whom the Software is furnished to do so,
12+
// subject to the following conditions:
13+
//
14+
// The above copyright notice and this permission notice shall be included in all
15+
// copies or substantial portions of the Software.
16+
//
17+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19+
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20+
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21+
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22+
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23+
//
24+
25+
#import "OTPProgressRing.h"
26+
27+
28+
static const CGFloat OTPProgressRingLineWidth = 1.5;
29+
30+
31+
@interface OTPProgressRing ()
32+
33+
@property (nonatomic, strong) NSTimer *timer;
34+
35+
@end
36+
37+
38+
@implementation OTPProgressRing
39+
40+
- (id)initWithFrame:(CGRect)frame
41+
{
42+
self = [super initWithFrame:frame];
43+
if (self) {
44+
self.opaque = NO;
45+
self.timer = [NSTimer scheduledTimerWithTimeInterval:0.01
46+
target:self
47+
selector:@selector(update)
48+
userInfo:nil
49+
repeats:YES];
50+
}
51+
return self;
52+
}
53+
54+
- (void)dealloc
55+
{
56+
[self.timer invalidate];
57+
}
58+
59+
- (void)update
60+
{
61+
[super setNeedsDisplay];
62+
}
63+
64+
- (void)drawRect:(CGRect)rect
65+
{
66+
CGContextRef context = UIGraphicsGetCurrentContext();
67+
68+
CGContextSetLineWidth(context, OTPProgressRingLineWidth);
69+
CGRect ringRect = CGRectInset(self.bounds, OTPProgressRingLineWidth/2, OTPProgressRingLineWidth/2);
70+
71+
CGContextSetStrokeColorWithColor(context, [self.tintColor colorWithAlphaComponent:(CGFloat)0.2].CGColor);
72+
CGContextStrokeEllipseInRect(context, ringRect);
73+
74+
CGFloat progress = (CGFloat)(fmod([NSDate date].timeIntervalSince1970, self.period) / self.period);
75+
76+
CGContextSetStrokeColorWithColor(context, self.tintColor.CGColor);
77+
CGContextAddArc(context,
78+
CGRectGetMidX(ringRect),
79+
CGRectGetMidY(ringRect),
80+
CGRectGetWidth(ringRect)/2,
81+
(CGFloat) - M_PI_2,
82+
(CGFloat)(2 * M_PI * progress - M_PI_2),
83+
1);
84+
CGContextStrokePath(context);
85+
}
86+
87+
@end

Authenticator/Classes/OTPTokenListViewController.m

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#import "OTPTokenListViewController.h"
2626
#import "OTPTokenManager.h"
2727
#import "OTPTokenCell.h"
28-
#import "OTPClock.h"
28+
#import "OTPProgressRing.h"
2929
#import "OTPToken.h"
3030
#import "OTPTokenEntryViewController.h"
3131
#import "OTPScannerViewController.h"
@@ -34,7 +34,7 @@
3434
@interface OTPTokenListViewController ()
3535

3636
@property (nonatomic, strong) OTPTokenManager *tokenManager;
37-
@property (nonatomic, strong) OTPClock *clock;
37+
@property (nonatomic, strong) OTPProgressRing *ring;
3838
@property (nonatomic, strong) UIBarButtonItem *addButtonItem;
3939

4040
@end
@@ -61,10 +61,10 @@ - (void)viewDidLoad
6161
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
6262
self.tableView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
6363

64-
self.clock = [[OTPClock alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
65-
self.clock.period = [OTPToken defaultPeriod];
66-
UIBarButtonItem *clockBarItem = [[UIBarButtonItem alloc] initWithCustomView:self.clock];
67-
self.navigationItem.leftBarButtonItem = clockBarItem;
64+
self.ring = [[OTPProgressRing alloc] initWithFrame:CGRectMake(0, 0, 22, 22)];
65+
self.ring.period = [OTPToken defaultPeriod];
66+
UIBarButtonItem *ringBarItem = [[UIBarButtonItem alloc] initWithCustomView:self.ring];
67+
self.navigationItem.leftBarButtonItem = ringBarItem;
6868

6969
self.addButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addToken)];
7070
self.toolbarItems = @[self.editButtonItem,
@@ -77,11 +77,11 @@ - (void)viewDidLoad
7777

7878
- (void)update
7979
{
80-
// Show the countdown clock only if a time-based token is active
81-
self.clock.hidden = YES;
80+
// Show the countdown ring only if a time-based token is active
81+
self.ring.hidden = YES;
8282
for (OTPToken *token in self.tokenManager.tokens) {
8383
if (token.type == OTPTokenTypeTimer) {
84-
self.clock.hidden = NO;
84+
self.ring.hidden = NO;
8585
break;
8686
}
8787
}

0 commit comments

Comments
 (0)