Remove DateCalculator

This commit is contained in:
2019-03-30 20:36:14 -05:00
parent 70a79856f2
commit aa6b13f3a6
23 changed files with 278 additions and 235 deletions

View File

@@ -26,7 +26,6 @@ import UIKit
databaseOpener: IosDatabaseOpener(withLog: StandardLog()),
fileOpener: IosFileOpener(),
log: StandardLog(),
dateCalculator: IosLocalDateCalculator(),
taskRunner: SequentialTaskRunner())
func application(_ application: UIApplication,
@@ -35,7 +34,7 @@ import UIKit
window = UIWindow(frame: UIScreen.main.bounds)
if let window = window {
let nav = UINavigationController()
nav.viewControllers = [ListHabitsController(withBackend: backend)]
nav.viewControllers = [MainScreenController(withBackend: backend)]
window.backgroundColor = UIColor.white
window.rootViewController = nav
window.makeKeyAndVisible()

View File

@@ -19,7 +19,7 @@
import UIKit
class ListHabitsCell : UITableViewCell {
class MainScreenCell : UITableViewCell {
var ring: ComponentView
var label = UILabel()
var buttons: [ComponentView] = []
@@ -48,7 +48,7 @@ class ListHabitsCell : UITableViewCell {
label.heightAnchor.constraint(equalToConstant: size).isActive = true
stack.addArrangedSubview(label)
for _ in 1...4 {
for _ in 1...3 {
let btn = ComponentView(frame: frame, component: nil)
btn.backgroundColor = .white
btn.widthAnchor.constraint(equalToConstant: size).isActive = true
@@ -88,7 +88,7 @@ class ListHabitsCell : UITableViewCell {
}
}
class ListHabitsController: UITableViewController, MainScreenDataSourceListener {
class MainScreenController: UITableViewController, MainScreenDataSourceListener {
var backend: Backend
var dataSource: MainScreenDataSource
var data: MainScreenDataSource.Data?
@@ -119,7 +119,7 @@ class ListHabitsController: UITableViewController, MainScreenDataSourceListener
target: self,
action: #selector(self.onCreateHabitClicked))
]
tableView.register(ListHabitsCell.self, forCellReuseIdentifier: "cell")
tableView.register(MainScreenCell.self, forCellReuseIdentifier: "cell")
tableView.backgroundColor = theme.headerBackgroundColor.uicolor
}
@@ -140,7 +140,7 @@ class ListHabitsController: UITableViewController, MainScreenDataSourceListener
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let row = indexPath.row
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! ListHabitsCell
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! MainScreenCell
let color = theme.color(paletteIndex: data!.colors[row].index)
cell.label.text = data!.names[row]
cell.setColor(color)
@@ -149,10 +149,9 @@ class ListHabitsController: UITableViewController, MainScreenDataSourceListener
override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let component = HabitListHeader(today: LocalDate(year: 2019, month: 3, day: 24),
nButtons: 4,
nButtons: 3,
theme: theme,
fmt: IosLocalDateFormatter(),
calc: IosLocalDateCalculator())
fmt: IosLocalDateFormatter())
return ComponentView(frame: CGRect(x: 0, y: 0, width: 100, height: CGFloat(theme.checkmarkButtonSize)),
component: component)
}

View File

@@ -47,7 +47,6 @@ class ShowHabitController : UITableViewController {
let component = CalendarChart(today: LocalDate(year: 2019, month: 3, day: 15),
color: color,
theme: theme,
dateCalculator: IosLocalDateCalculator(),
dateFormatter: IosLocalDateFormatter())
let cell = UITableViewCell()
let view = ComponentView(frame: cell.frame, component: component)

View File

@@ -54,35 +54,3 @@ class IosLocalDateFormatter : NSObject, LocalDateFormatter {
return fmt.string(from: date.iosDate)
}
}
class IosLocalDateCalculator : NSObject, LocalDateCalculator {
func toTimestamp(date: LocalDate) -> Timestamp {
return Timestamp(unixTimeInMillis: Int64(date.iosDate.timeIntervalSince1970 * 1000))
}
func fromTimestamp(timestamp: Timestamp) -> LocalDate {
return Date.init(timeIntervalSince1970: Double(timestamp.unixTimeInMillis / 1000)).localDate
}
let calendar = Calendar(identifier: .gregorian)
func dayOfWeek(date: LocalDate) -> DayOfWeek {
let weekday = calendar.component(.weekday, from: date.iosDate)
switch(weekday) {
case 1: return DayOfWeek.sunday
case 2: return DayOfWeek.monday
case 3: return DayOfWeek.tuesday
case 4: return DayOfWeek.wednesday
case 5: return DayOfWeek.thursday
case 6: return DayOfWeek.friday
default: return DayOfWeek.saturday
}
}
func plusDays(date: LocalDate, days: Int32) -> LocalDate {
let d2 = date.iosDate.addingTimeInterval(24.0 * 60 * 60 * Double(days))
return LocalDate(year: Int32(calendar.component(.year, from: d2)),
month: Int32(calendar.component(.month, from: d2)),
day: Int32(calendar.component(.day, from: d2)))
}
}