-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathFLEXNetworkTransactionCell.m
More file actions
137 lines (111 loc) · 5.71 KB
/
FLEXNetworkTransactionCell.m
File metadata and controls
137 lines (111 loc) · 5.71 KB
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
//
// FLEXNetworkTransactionCell.m
// Flipboard
//
// Created by Ryan Olson on 2/8/15.
// Copyright (c) 2020 FLEX Team. All rights reserved.
//
#import "FLEXColor.h"
#import "FLEXNetworkTransactionCell.h"
#import "FLEXNetworkTransaction.h"
#import "FLEXUtility.h"
#import "FLEXResources.h"
NSString * const kFLEXNetworkTransactionCellIdentifier = @"kFLEXNetworkTransactionCellIdentifier";
@interface FLEXNetworkTransactionCell ()
@property (nonatomic) UIImageView *thumbnailImageView;
@property (nonatomic) UILabel *nameLabel;
@property (nonatomic) UILabel *pathLabel;
@property (nonatomic) UILabel *transactionDetailsLabel;
@end
@implementation FLEXNetworkTransactionCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
// Force LTR layout for FLEX network cells
if (@available(iOS 9.0, *)) {
self.semanticContentAttribute = UISemanticContentAttributeForceLeftToRight;
self.contentView.semanticContentAttribute = UISemanticContentAttributeForceLeftToRight;
}
self.nameLabel = [UILabel new];
self.nameLabel.font = UIFont.flex_defaultTableCellFont;
self.nameLabel.textAlignment = NSTextAlignmentLeft;
if (@available(iOS 9.0, *)) {
self.nameLabel.semanticContentAttribute = UISemanticContentAttributeForceLeftToRight;
}
[self.contentView addSubview:self.nameLabel];
self.pathLabel = [UILabel new];
self.pathLabel.font = UIFont.flex_defaultTableCellFont;
self.pathLabel.textColor = [UIColor colorWithWhite:0.4 alpha:1.0];
self.pathLabel.lineBreakMode = NSLineBreakByTruncatingMiddle;
self.pathLabel.textAlignment = NSTextAlignmentLeft;
if (@available(iOS 9.0, *)) {
self.pathLabel.semanticContentAttribute = UISemanticContentAttributeForceLeftToRight;
}
[self.contentView addSubview:self.pathLabel];
self.thumbnailImageView = [UIImageView new];
self.thumbnailImageView.layer.borderColor = UIColor.blackColor.CGColor;
self.thumbnailImageView.layer.borderWidth = 1.0;
self.thumbnailImageView.contentMode = UIViewContentModeScaleAspectFit;
if (@available(iOS 9.0, *)) {
self.thumbnailImageView.semanticContentAttribute = UISemanticContentAttributeForceLeftToRight;
}
[self.contentView addSubview:self.thumbnailImageView];
self.transactionDetailsLabel = [UILabel new];
self.transactionDetailsLabel.font = [UIFont systemFontOfSize:10.0];
self.transactionDetailsLabel.textColor = [UIColor colorWithWhite:0.65 alpha:1.0];
self.transactionDetailsLabel.textAlignment = NSTextAlignmentLeft;
if (@available(iOS 9.0, *)) {
self.transactionDetailsLabel.semanticContentAttribute = UISemanticContentAttributeForceLeftToRight;
}
[self.contentView addSubview:self.transactionDetailsLabel];
}
return self;
}
- (void)setTransaction:(FLEXNetworkTransaction *)transaction {
if (_transaction != transaction) {
_transaction = transaction;
[self setNeedsLayout];
}
}
- (void)layoutSubviews {
[super layoutSubviews];
const CGFloat kVerticalPadding = 8.0;
const CGFloat kLeftPadding = 10.0;
const CGFloat kImageDimension = 32.0;
CGFloat thumbnailOriginY = round((self.contentView.bounds.size.height - kImageDimension) / 2.0);
self.thumbnailImageView.frame = CGRectMake(kLeftPadding, thumbnailOriginY, kImageDimension, kImageDimension);
self.thumbnailImageView.image = self.transaction.thumbnail;
CGFloat textOriginX = CGRectGetMaxX(self.thumbnailImageView.frame) + kLeftPadding;
CGFloat availableTextWidth = self.contentView.bounds.size.width - textOriginX;
self.nameLabel.text = [self nameLabelText];
CGSize nameLabelPreferredSize = [self.nameLabel sizeThatFits:CGSizeMake(availableTextWidth, CGFLOAT_MAX)];
self.nameLabel.frame = CGRectMake(textOriginX, kVerticalPadding, availableTextWidth, nameLabelPreferredSize.height);
self.nameLabel.textColor = self.transaction.displayAsError ? UIColor.redColor : FLEXColor.primaryTextColor;
self.pathLabel.text = [self pathLabelText];
CGSize pathLabelPreferredSize = [self.pathLabel sizeThatFits:CGSizeMake(availableTextWidth, CGFLOAT_MAX)];
CGFloat pathLabelOriginY = ceil((self.contentView.bounds.size.height - pathLabelPreferredSize.height) / 2.0);
self.pathLabel.frame = CGRectMake(textOriginX, pathLabelOriginY, availableTextWidth, pathLabelPreferredSize.height);
self.transactionDetailsLabel.text = [self transactionDetailsLabelText];
CGSize transactionLabelPreferredSize = [self.transactionDetailsLabel sizeThatFits:CGSizeMake(availableTextWidth, CGFLOAT_MAX)];
CGFloat transactionDetailsOriginX = textOriginX;
CGFloat transactionDetailsLabelOriginY = CGRectGetMaxY(self.contentView.bounds) - kVerticalPadding - transactionLabelPreferredSize.height;
CGFloat transactionDetailsLabelWidth = self.contentView.bounds.size.width - transactionDetailsOriginX;
self.transactionDetailsLabel.frame = CGRectMake(transactionDetailsOriginX, transactionDetailsLabelOriginY, transactionDetailsLabelWidth, transactionLabelPreferredSize.height);
}
- (NSString *)nameLabelText {
return self.transaction.primaryDescription;
}
- (NSString *)pathLabelText {
return self.transaction.secondaryDescription;
}
- (NSString *)transactionDetailsLabelText {
return self.transaction.tertiaryDescription;
}
+ (CGFloat)preferredCellHeight {
return 65.0;
}
+ (NSString *)reuseID {
return kFLEXNetworkTransactionCellIdentifier;
}
@end