Skip to content

Commit

Permalink
Modified SiteStatsTableHeaderView to inject expected period count
Browse files Browse the repository at this point in the history
  • Loading branch information
sabaranski committed May 17, 2019
1 parent dca8baa commit f11a8e4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ class SiteStatsPeriodTableViewController: UITableViewController {
return nil
}

cell.configure(date: selectedDate, period: selectedPeriod, delegate: self)
let periodCount = 10
cell.configure(date: selectedDate, period: .day, delegate: self, expectedPeriodCount: periodCount)
viewModel?.statsBarChartViewDelegate = cell

return cell
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ class SiteStatsTableHeaderView: UITableViewHeaderFooterView, NibLoadable {

// Limits how far back the date chooser can go.
// Corresponds to the number of bars shown on the Overview chart.
private static let expectedPeriodCount = 14
static let defaultPeriodCount = 14
private var expectedPeriodCount = SiteStatsTableHeaderView.defaultPeriodCount
private var backLimit: Int {
return -(SiteStatsTableHeaderView.expectedPeriodCount - 1)
return -(expectedPeriodCount - 1)
}

private lazy var calendar: Calendar = {
Expand All @@ -42,10 +43,11 @@ class SiteStatsTableHeaderView: UITableViewHeaderFooterView, NibLoadable {
applyStyles()
}

func configure(date: Date?, period: StatsPeriodUnit?, delegate: SiteStatsTableHeaderDelegate) {
func configure(date: Date?, period: StatsPeriodUnit?, delegate: SiteStatsTableHeaderDelegate, expectedPeriodCount: Int) {
self.date = date
self.period = period
self.delegate = delegate
self.expectedPeriodCount = expectedPeriodCount
dateLabel.text = displayDate()
updateButtonStates()
}
Expand Down Expand Up @@ -186,7 +188,7 @@ private extension SiteStatsTableHeaderView {

extension SiteStatsTableHeaderView: StatsBarChartViewDelegate {
func statsBarChartValueSelected(_ statsBarChartView: StatsBarChartView, entryIndex: Int, entryCount: Int) {
guard let period = period, entryCount > 0, entryCount <= SiteStatsTableHeaderView.expectedPeriodCount else {
guard let period = period, entryCount > 0, entryCount <= SiteStatsTableHeaderView.defaultPeriodCount else {
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ class PostStatsTableViewController: UITableViewController, StoryboardLoadable {
return nil
}

cell.configure(date: selectedDate, period: .day, delegate: self)
let periodCount = SiteStatsTableHeaderView.defaultPeriodCount
cell.configure(date: selectedDate, period: .day, delegate: self, expectedPeriodCount: periodCount)
viewModel?.statsBarChartViewDelegate = cell

return cell
Expand Down

0 comments on commit f11a8e4

Please sign in to comment.