-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathSponsorSegmentView.m
86 lines (76 loc) · 3.77 KB
/
SponsorSegmentView.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#import "Headers/SponsorSegmentView.h"
#import "Headers/Localization.h"
@implementation SponsorSegmentView
- (instancetype)initWithFrame:(CGRect)frame sponsorSegment:(SponsorSegment *)segment editable:(BOOL)editable {
self = [super initWithFrame:frame];
if (self) {
self.sponsorSegment = segment;
self.editable = editable;
NSString *category;
if ([segment.category isEqualToString:@"sponsor"]) {
category = LOC(@"Sponsor");
}
else if ([segment.category isEqualToString:@"intro"]) {
category = LOC(@"Intermission");
}
else if ([segment.category isEqualToString:@"outro"]) {
category = LOC(@"Outro");
}
else if ([segment.category isEqualToString:@"interaction"]) {
category = LOC(@"Interaction");
}
else if ([segment.category isEqualToString:@"selfpromo"]) {
category = LOC(@"SelfPromo");
}
else if ([segment.category isEqualToString:@"music_offtopic"]) {
category = LOC(@"Non-Music");
}
self.categoryLabel = [[UILabel alloc] initWithFrame:self.frame];
self.segmentLabel = [[UILabel alloc] initWithFrame:self.frame];
self.categoryLabel.text = category;
NSInteger startSeconds = lroundf(segment.startTime);
NSInteger startHours = startSeconds / 3600;
NSInteger startMinutes = (startSeconds - (startHours * 3600)) / 60;
startSeconds = startSeconds %60;
NSString *startTime;
if (startHours >= 1) {
startTime = [NSString stringWithFormat:@"%ld:%02ld:%02ld", startHours, startMinutes, startSeconds];
}
else {
startTime = [NSString stringWithFormat:@"%ld:%02ld", startMinutes, startSeconds];
}
NSInteger endSeconds = lroundf(segment.endTime);
NSInteger endHours = endSeconds / 3600;
NSInteger endMinutes = (endSeconds - (endHours * 3600)) / 60;
endSeconds = endSeconds %60;
NSString *endTime;
if (endHours >= 1) {
endTime = [NSString stringWithFormat:@"%ld:%02ld:%02ld", endHours, endMinutes, endSeconds];
}
else {
endTime = [NSString stringWithFormat:@"%ld:%02ld", endMinutes, endSeconds];
}
self.segmentLabel.text = [NSString stringWithFormat:@"%@ %@ %@ %@", LOC(@"From"), startTime, LOC(@"to"), endTime];
[self addSubview:self.categoryLabel];
self.categoryLabel.adjustsFontSizeToFitWidth = YES;
self.categoryLabel.font = [UIFont systemFontOfSize:12];
self.categoryLabel.textAlignment = NSTextAlignmentCenter;
self.categoryLabel.translatesAutoresizingMaskIntoConstraints = NO;
[self addSubview:self.segmentLabel];
self.segmentLabel.adjustsFontSizeToFitWidth = YES;
self.segmentLabel.font = [UIFont systemFontOfSize:12];
self.segmentLabel.textAlignment = NSTextAlignmentCenter;
self.segmentLabel.translatesAutoresizingMaskIntoConstraints = NO;
[self.segmentLabel.widthAnchor constraintEqualToAnchor:self.widthAnchor].active = YES;
[self.segmentLabel.heightAnchor constraintEqualToConstant:self.frame.size.height/2].active = YES;
[self.categoryLabel.widthAnchor constraintEqualToAnchor:self.widthAnchor].active = YES;
[self.categoryLabel.heightAnchor constraintEqualToConstant:self.frame.size.height/2].active = YES;
[self.categoryLabel.topAnchor constraintEqualToAnchor:self.segmentLabel.bottomAnchor].active = YES;
self.backgroundColor = UIColor.systemGray4Color;
self.layer.cornerRadius = 10;
self.segmentLabel.layer.cornerRadius = 10;
self.categoryLabel.layer.cornerRadius = 10;
}
return self;
}
@end