Skip to content

Commit 1ccd61b

Browse files
committed
Stats: Add new Total cell for Insights
1 parent 4f01d65 commit 1ccd61b

File tree

5 files changed

+106
-2
lines changed

5 files changed

+106
-2
lines changed

WordPress/Classes/ViewRelated/Stats/Extensions/WPStyleGuide+Stats.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ extension WPStyleGuide {
203203
static let subTitleFont = WPStyleGuide.fontForTextStyle(.footnote, fontWeight: .medium)
204204
static let summaryFont = WPStyleGuide.fontForTextStyle(.subheadline, fontWeight: .regular)
205205
static let substringHighlightFont = WPStyleGuide.fontForTextStyle(.subheadline, fontWeight: .semibold)
206+
static let insightsCountFont = UIFont.preferredFont(forTextStyle: .title1).bold()
206207

207208
static let tableBackgroundColor = UIColor.listBackground
208209
static let cellBackgroundColor = UIColor.listForeground

WordPress/Classes/ViewRelated/Stats/Insights/StatsLatestPostSummaryInsightsCell.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ class StatsLatestPostSummaryInsightsCell: StatsBaseCell, LatestPostSummaryConfig
147147
topLabel.textColor = .text
148148
topLabel.text = title
149149

150-
countLabel.font = UIFont.preferredFont(forTextStyle: .title1).bold()
150+
countLabel.font = Style.insightsCountFont
151151
countLabel.textColor = .text
152152
countLabel.adjustsFontSizeToFitWidth = true
153153
countLabel.text = "0"

WordPress/Classes/ViewRelated/Stats/Insights/StatsMostPopularTimeInsightsCell.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class StatsMostPopularTimeInsightsCell: StatsBaseCell {
126126

127127
let middleLabel = UILabel()
128128
middleLabel.textColor = .text
129-
middleLabel.font = .preferredFont(forTextStyle: .title1).bold()
129+
middleLabel.font = WPStyleGuide.Stats.insightsCountFont
130130
middleLabel.adjustsFontSizeToFitWidth = true
131131

132132
let bottomLabel = UILabel()
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import UIKit
2+
import WordPressShared
3+
4+
5+
struct StatsTotalInsightsData {
6+
var count: String
7+
var comparison: String = ""
8+
}
9+
10+
class StatsTotalInsightsCell: StatsBaseCell {
11+
private weak var siteStatsInsightsDelegate: SiteStatsInsightsDelegate?
12+
private var lastPostInsight: StatsLastPostInsight?
13+
14+
private let outerStackView = UIStackView()
15+
private let topInnerStackView = UIStackView()
16+
private let countLabel = UILabel()
17+
private let comparisonLabel = UILabel()
18+
private let graphView = UIView()
19+
20+
// MARK: - Initialization
21+
22+
required override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
23+
super.init(style: style, reuseIdentifier: reuseIdentifier)
24+
25+
configureView()
26+
}
27+
28+
required init(coder: NSCoder) {
29+
fatalError()
30+
}
31+
32+
private func configureView() {
33+
configureStackViews()
34+
configureGraphView()
35+
configureLabels()
36+
configureConstraints()
37+
}
38+
39+
private func configureStackViews() {
40+
outerStackView.translatesAutoresizingMaskIntoConstraints = false
41+
outerStackView.axis = .vertical
42+
outerStackView.spacing = Metrics.stackViewSpacing
43+
contentView.addSubview(outerStackView)
44+
45+
topInnerStackView.axis = .horizontal
46+
topInnerStackView.spacing = Metrics.stackViewSpacing
47+
48+
topInnerStackView.addArrangedSubviews([countLabel, graphView])
49+
outerStackView.addArrangedSubviews([topInnerStackView, comparisonLabel])
50+
}
51+
52+
private func configureGraphView() {
53+
graphView.translatesAutoresizingMaskIntoConstraints = false
54+
graphView.backgroundColor = .secondarySystemBackground
55+
graphView.setContentHuggingPriority(.required, for: .horizontal)
56+
graphView.setContentHuggingPriority(.required, for: .vertical)
57+
}
58+
59+
private func configureLabels() {
60+
countLabel.font = WPStyleGuide.Stats.insightsCountFont
61+
countLabel.textColor = .text
62+
countLabel.text = "0"
63+
countLabel.adjustsFontSizeToFitWidth = true
64+
countLabel.setContentHuggingPriority(.defaultLow, for: .horizontal)
65+
countLabel.setContentHuggingPriority(.required, for: .vertical)
66+
67+
comparisonLabel.font = .preferredFont(forTextStyle: .body)
68+
comparisonLabel.textColor = .textSubtle
69+
comparisonLabel.text = "+87 (40%) compared to last week"
70+
}
71+
72+
private func configureConstraints() {
73+
topConstraint = outerStackView.topAnchor.constraint(equalTo: contentView.topAnchor, constant: StatsBaseCell.Metrics.padding)
74+
75+
NSLayoutConstraint.activate([
76+
topConstraint,
77+
outerStackView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: -StatsBaseCell.Metrics.padding),
78+
outerStackView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: StatsBaseCell.Metrics.padding),
79+
outerStackView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -StatsBaseCell.Metrics.padding),
80+
graphView.widthAnchor.constraint(equalTo: graphView.heightAnchor, multiplier: 2.55),
81+
graphView.heightAnchor.constraint(equalTo: countLabel.heightAnchor)
82+
])
83+
}
84+
85+
// TODO: This will need updating to pass some graph data too.
86+
// Assuming this will be something like a small array of ints
87+
func configure(count: String, statSection: StatSection, siteStatsInsightsDelegate: SiteStatsInsightsDelegate?) {
88+
self.statSection = statSection
89+
self.siteStatsInsightsDelegate = siteStatsInsightsDelegate
90+
91+
countLabel.text = count
92+
}
93+
94+
private enum Metrics {
95+
static let stackViewSpacing: CGFloat = 8.0
96+
}
97+
}

WordPress/WordPress.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,8 @@
311311
1782BE841E70063100A91E7D /* MediaItemViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1782BE831E70063100A91E7D /* MediaItemViewController.swift */; };
312312
17870A702816F2A000D1C627 /* StatsLatestPostSummaryInsightsCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17870A6F2816F2A000D1C627 /* StatsLatestPostSummaryInsightsCell.swift */; };
313313
17870A712816F2A000D1C627 /* StatsLatestPostSummaryInsightsCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17870A6F2816F2A000D1C627 /* StatsLatestPostSummaryInsightsCell.swift */; };
314+
17870A74281FBEC100D1C627 /* StatsTotalInsightsCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17870A73281FBEC000D1C627 /* StatsTotalInsightsCell.swift */; };
315+
17870A75281FBEC100D1C627 /* StatsTotalInsightsCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17870A73281FBEC000D1C627 /* StatsTotalInsightsCell.swift */; };
314316
1788106F260E488B00A98BD8 /* UnifiedPrologueNotificationsContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1788106E260E488B00A98BD8 /* UnifiedPrologueNotificationsContentView.swift */; };
315317
178810B52611D25600A98BD8 /* Text+BoldSubString.swift in Sources */ = {isa = PBXBuildFile; fileRef = 178810B42611D25600A98BD8 /* Text+BoldSubString.swift */; };
316318
178810D92612037900A98BD8 /* UnifiedPrologueReaderContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 178810D82612037800A98BD8 /* UnifiedPrologueReaderContentView.swift */; };
@@ -5129,6 +5131,7 @@
51295131
1782BE831E70063100A91E7D /* MediaItemViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MediaItemViewController.swift; sourceTree = "<group>"; };
51305132
17870A6F2816F2A000D1C627 /* StatsLatestPostSummaryInsightsCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatsLatestPostSummaryInsightsCell.swift; sourceTree = "<group>"; };
51315133
17870A72281847D500D1C627 /* WordPress 139.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "WordPress 139.xcdatamodel"; sourceTree = "<group>"; };
5134+
17870A73281FBEC000D1C627 /* StatsTotalInsightsCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatsTotalInsightsCell.swift; sourceTree = "<group>"; };
51325135
1788106E260E488B00A98BD8 /* UnifiedPrologueNotificationsContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnifiedPrologueNotificationsContentView.swift; sourceTree = "<group>"; };
51335136
178810B42611D25600A98BD8 /* Text+BoldSubString.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Text+BoldSubString.swift"; sourceTree = "<group>"; };
51345137
178810D82612037800A98BD8 /* UnifiedPrologueReaderContentView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UnifiedPrologueReaderContentView.swift; sourceTree = "<group>"; };
@@ -12186,6 +12189,7 @@
1218612189
176CE91527FB44C100F1E32B /* StatsBaseCell.swift */,
1218712190
17ABD3512811A48900B1E9CB /* StatsMostPopularTimeInsightsCell.swift */,
1218812191
17870A6F2816F2A000D1C627 /* StatsLatestPostSummaryInsightsCell.swift */,
12192+
17870A73281FBEC000D1C627 /* StatsTotalInsightsCell.swift */,
1218912193
);
1219012194
path = Insights;
1219112195
sourceTree = "<group>";
@@ -18599,6 +18603,7 @@
1859918603
9A38DC6A218899FB006A409B /* DiffTitleValue.swift in Sources */,
1860018604
B0AC50DD251E96270039E022 /* ReaderCommentsViewController.swift in Sources */,
1860118605
73856E5B21E1602400773CD9 /* SiteCreationRequest+Validation.swift in Sources */,
18606+
17870A74281FBEC100D1C627 /* StatsTotalInsightsCell.swift in Sources */,
1860218607
7E4123BA20F4097B00DF8486 /* FormattableContentGroup.swift in Sources */,
1860318608
08216FD21CDBF96000304BA7 /* MenuItemSourceViewController.m in Sources */,
1860418609
74558369201A1FD3007809BB /* WPReusableTableViewCells.swift in Sources */,
@@ -20384,6 +20389,7 @@
2038420389
FABB21E52602FC2C00C8785C /* MediaQuotaCell.swift in Sources */,
2038520390
FABB21E62602FC2C00C8785C /* PartScreenPresentationController.swift in Sources */,
2038620391
FABB21E72602FC2C00C8785C /* WPRichTextImage.swift in Sources */,
20392+
17870A75281FBEC100D1C627 /* StatsTotalInsightsCell.swift in Sources */,
2038720393
FABB21E82602FC2C00C8785C /* FormattableContentRange.swift in Sources */,
2038820394
FABB21E92602FC2C00C8785C /* MenuItemSourceHeaderView.m in Sources */,
2038920395
98622EA0274C59A400061A5F /* ReaderDetailCommentsTableViewDelegate.swift in Sources */,

0 commit comments

Comments
 (0)