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)))
}
}

View File

@@ -9,7 +9,7 @@
/* Begin PBXBuildFile section */
0057EC2B224C4CDB00C49288 /* icons in Resources */ = {isa = PBXBuildFile; fileRef = 0057EC2A224C4CDB00C49288 /* icons */; };
00A5B42822009F590024E00C /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00A5B42722009F590024E00C /* AppDelegate.swift */; };
00A5B42A22009F590024E00C /* ListHabitsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00A5B42922009F590024E00C /* ListHabitsController.swift */; };
00A5B42A22009F590024E00C /* MainScreenController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00A5B42922009F590024E00C /* MainScreenController.swift */; };
00A5B42F22009F5A0024E00C /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 00A5B42E22009F5A0024E00C /* Assets.xcassets */; };
00C0C6A52246537A003D8AF0 /* IosFilesTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00C0C6A122465365003D8AF0 /* IosFilesTest.swift */; };
00C0C6A62246537E003D8AF0 /* IosDatabaseTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00C0C6A222465365003D8AF0 /* IosDatabaseTest.swift */; };
@@ -59,7 +59,7 @@
0057EC2A224C4CDB00C49288 /* icons */ = {isa = PBXFileReference; lastKnownFileType = folder; path = icons; sourceTree = "<group>"; };
00A5B42422009F590024E00C /* uhabits.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = uhabits.app; sourceTree = BUILT_PRODUCTS_DIR; };
00A5B42722009F590024E00C /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
00A5B42922009F590024E00C /* ListHabitsController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListHabitsController.swift; sourceTree = "<group>"; };
00A5B42922009F590024E00C /* MainScreenController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainScreenController.swift; sourceTree = "<group>"; };
00A5B42E22009F5A0024E00C /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
00A5B43322009F5A0024E00C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
00A5B43822009F5A0024E00C /* uhabitsTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = uhabitsTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -107,7 +107,7 @@
isa = PBXGroup;
children = (
00D48BD22200AC1600CC4527 /* EditHabitController.swift */,
00A5B42922009F590024E00C /* ListHabitsController.swift */,
00A5B42922009F590024E00C /* MainScreenController.swift */,
00C0C6DE224A35FC003D8AF0 /* ShowHabitController.swift */,
);
path = Frontend;
@@ -317,7 +317,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "cd ../core\n./gradlew linkDebugFrameworkIOS\n";
shellScript = "cd ../core\n./gradlew linkIOS\n";
};
/* End PBXShellScriptBuildPhase section */
@@ -332,7 +332,7 @@
00C0C6E0224A3602003D8AF0 /* ShowHabitController.swift in Sources */,
00C0C6A8224654A2003D8AF0 /* IosDatabase.swift in Sources */,
00C0C6DB2247E6B0003D8AF0 /* IosDates.swift in Sources */,
00A5B42A22009F590024E00C /* ListHabitsController.swift in Sources */,
00A5B42A22009F590024E00C /* MainScreenController.swift in Sources */,
00A5B42822009F590024E00C /* AppDelegate.swift in Sources */,
00D48BD32200AC1600CC4527 /* EditHabitController.swift in Sources */,
);

View File

@@ -83,7 +83,8 @@
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "00A5B42322009F590024E00C"
@@ -91,7 +92,7 @@
BlueprintName = "uhabits"
ReferencedContainer = "container:uhabits.xcodeproj">
</BuildableReference>
</MacroExpansion>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">