forked from strongbox-password-safe/Strongbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustomFieldTableCell.m
98 lines (75 loc) · 2.75 KB
/
CustomFieldTableCell.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
87
88
89
90
91
92
93
94
95
96
97
98
//
// CustomFieldTableCell.m
// Strongbox-iOS
//
// Created by Mark on 26/03/2019.
// Copyright © 2014-2021 Mark McGuill. All rights reserved.
//
#import "CustomFieldTableCell.h"
#import "ColoredStringHelper.h"
#import "AppPreferences.h"
NSString *const CustomFieldCellHeightChanged = @"CustomFieldCellHeightChangedNotification";
@interface CustomFieldTableCell ()
@property (weak, nonatomic) IBOutlet UILabel *keyLabel;
@property (weak, nonatomic) IBOutlet UILabel *valueLabel;
@property (weak, nonatomic) IBOutlet UIButton *buttonShowHide;
@property NSString* _key;
@property NSString* _value;
@property BOOL _concealed;
@property BOOL _showShowHideButton;
@end
@implementation CustomFieldTableCell
- (NSString *)key {
return self._key;
}
- (void)setKey:(NSString *)key {
self._key = key;
self.keyLabel.text = key;
}
- (NSString *)value {
return self._value;
}
- (void)setValue:(NSString *)value {
self._value = value;
self.valueLabel.text = value;
}
- (BOOL)concealed {
return self._concealed;
}
- (void)setConcealed:(BOOL)concealed {
self._concealed = concealed;
[self bindConcealed];
}
- (BOOL)isHideable {
return self._showShowHideButton;
}
- (void)setIsHideable:(BOOL)showShowHideButton {
self._showShowHideButton = showShowHideButton;
self.buttonShowHide.hidden = !showShowHideButton;
}
- (IBAction)toggleShowHide:(id)sender {
self._concealed = !self._concealed;
[self bindConcealed];
}
- (void)bindConcealed {
if(self._concealed) {
[self.buttonShowHide setImage:[UIImage imageNamed:@"visible"] forState:UIControlStateNormal];
self.valueLabel.text = NSLocalizedString(@"generic_masked_protected_field_text", @"*****************");
self.valueLabel.textColor = [UIColor lightGrayColor];
}
else {
[self.buttonShowHide setImage:[UIImage imageNamed:@"invisible"] forState:UIControlStateNormal];
BOOL dark = NO;
if (@available(iOS 12.0, *)) {
dark = self.traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark;
}
BOOL colorBlind = AppPreferences.sharedInstance.colorizeUseColorBlindPalette;
self.valueLabel.attributedText = [ColoredStringHelper getColorizedAttributedString:self._value
colorize:self.colorize
darkMode:dark
colorBlind:colorBlind
font:self.valueLabel.font];
}
[[NSNotificationCenter defaultCenter] postNotificationName:CustomFieldCellHeightChanged object:self];
}
@end