@@ -7,6 +7,10 @@ class StatsMostPopularTimeInsightsCell: StatsBaseCell {
77
88 // MARK: - Subviews
99
10+ private var outerStackView : UIStackView !
11+
12+ private var noDataLabel : UILabel !
13+
1014 private var topLeftLabel : UILabel !
1115 private var middleLeftLabel : UILabel !
1216 private var bottomLeftLabel : UILabel !
@@ -27,20 +31,31 @@ class StatsMostPopularTimeInsightsCell: StatsBaseCell {
2731 fatalError ( )
2832 }
2933
34+ override func prepareForReuse( ) {
35+ super. prepareForReuse ( )
36+
37+ displayNoData ( show: false )
38+ }
39+
3040 // MARK: - View Configuration
3141
3242 private func configureView( ) {
33- let stackView = makeOuterStackView ( )
34- contentView. addSubview ( stackView )
43+ outerStackView = makeOuterStackView ( )
44+ contentView. addSubview ( outerStackView )
3545
36- topConstraint = stackView . topAnchor. constraint ( equalTo: contentView. topAnchor, constant: StatsBaseCell . Metrics. padding)
46+ topConstraint = outerStackView . topAnchor. constraint ( equalTo: contentView. topAnchor, constant: StatsBaseCell . Metrics. padding)
3747
3848 NSLayoutConstraint . activate ( [
3949 topConstraint,
40- stackView . bottomAnchor. constraint ( equalTo: contentView. bottomAnchor, constant: - StatsBaseCell. Metrics. padding) ,
41- stackView . leadingAnchor. constraint ( equalTo: contentView. leadingAnchor, constant: StatsBaseCell . Metrics. padding) ,
42- stackView . trailingAnchor. constraint ( equalTo: contentView. trailingAnchor, constant: - StatsBaseCell. Metrics. padding) ,
50+ outerStackView . bottomAnchor. constraint ( equalTo: contentView. bottomAnchor, constant: - StatsBaseCell. Metrics. padding) ,
51+ outerStackView . leadingAnchor. constraint ( equalTo: contentView. leadingAnchor, constant: StatsBaseCell . Metrics. padding) ,
52+ outerStackView . trailingAnchor. constraint ( equalTo: contentView. trailingAnchor, constant: - StatsBaseCell. Metrics. padding) ,
4353 ] )
54+
55+ noDataLabel = makeNoDataLabel ( )
56+ contentView. addSubview ( noDataLabel)
57+ outerStackView. pinSubviewToAllEdges ( noDataLabel)
58+ noDataLabel. isHidden = true
4459 }
4560
4661 private func makeOuterStackView( ) -> UIStackView {
@@ -112,6 +127,7 @@ class StatsMostPopularTimeInsightsCell: StatsBaseCell {
112127 let middleLabel = UILabel ( )
113128 middleLabel. textColor = . text
114129 middleLabel. font = . preferredFont( forTextStyle: . title1) . bold ( )
130+ middleLabel. adjustsFontSizeToFitWidth = true
115131
116132 let bottomLabel = UILabel ( )
117133 bottomLabel. textColor = . textSubtle
@@ -123,29 +139,52 @@ class StatsMostPopularTimeInsightsCell: StatsBaseCell {
123139 return ( topLabel: topLabel, middleLabel: middleLabel, bottomLabel: bottomLabel)
124140 }
125141
142+ private func makeNoDataLabel( ) -> UILabel {
143+ let label = UILabel ( )
144+ label. translatesAutoresizingMaskIntoConstraints = false
145+ label. font = . preferredFont( forTextStyle: . body)
146+ label. textColor = . textSubtle
147+ label. numberOfLines = 0
148+ label. text = TextContent . noData
149+
150+ return label
151+ }
152+
153+ private func displayNoData( show: Bool ) {
154+ outerStackView. subviews. forEach ( { $0. isHidden = show } )
155+ noDataLabel. isHidden = !show
156+ }
157+
126158 // MARK: Public configuration
127159
128160 func configure( data: StatsMostPopularTimeData ? , siteStatsInsightsDelegate: SiteStatsInsightsDelegate ? ) {
129161 self . data = data
130162 self . statSection = . insightsMostPopularTime
131163 self . siteStatsInsightsDelegate = siteStatsInsightsDelegate
132164
133- if let data = data {
134- topLeftLabel. text = data. mostPopularDayTitle
135- middleLeftLabel. text = data. mostPopularDay
136- bottomLeftLabel. text = data. dayPercentage
137-
138- topRightLabel. text = data. mostPopularTimeTitle
139- middleRightLabel. text = data. mostPopularTime
140- bottomRightLabel. text = data. timePercentage
165+ guard let data = data else {
166+ displayNoData ( show: true )
167+ return
141168 }
169+
170+ topLeftLabel. text = data. mostPopularDayTitle
171+ middleLeftLabel. text = data. mostPopularDay
172+ bottomLeftLabel. text = data. dayPercentage
173+
174+ topRightLabel. text = data. mostPopularTimeTitle
175+ middleRightLabel. text = data. mostPopularTime
176+ bottomRightLabel. text = data. timePercentage
142177 }
143178
144179 private enum Metrics {
145- static let horizontalStackViewSpacing : CGFloat = 32 .0
180+ static let horizontalStackViewSpacing : CGFloat = 16 .0
146181 static let verticalStackViewSpacing : CGFloat = 8.0
147182 static let dividerWidth : CGFloat = 1.0
148183 }
184+
185+ private enum TextContent {
186+ static let noData = NSLocalizedString ( " stats.insights.mostPopularTime.noData " , value: " Not enough activity. Check back later when your site's had more visitors! " , comment: " Hint displayed on the 'Most Popular Time' stats card when a user's site hasn't yet received enough traffic. " )
187+ }
149188}
150189
151190// MARK: - Data / View Model
0 commit comments