Skip to content

Commit

Permalink
(fix) A more reasonable water drinking default goal.
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveLeungYL committed Dec 5, 2024
1 parent 569f06b commit 26323ac
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
8 changes: 4 additions & 4 deletions Shared/DataModels/Units.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,18 @@ enum WaterUnits: Codable, Hashable {
// As suggested by the citation.
switch self {
case .oz:
return 100.0
return 80.0
case .ml:
return 3100.0
return 2400.0
}
}

var dailyGoalRange: [Double] {
switch self {
case .oz:
return Array(stride(from: 70.0, to: 160, by: 10.0))
return Array(stride(from: 50.0, to: 160, by: 5.0))
case .ml:
return Array(stride(from: 1900.0, to: 3700.0, by: 100.0))
return Array(stride(from: 1500.0, to: 3700.0, by: 100.0))
}
}
}
2 changes: 1 addition & 1 deletion Shared/DataModels/WaterTrackerConfigurations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class WaterTrackerConfiguration {
var dailyGoal: Double? = nil
var reminderTimeInterval: TimeInterval? = nil

init(waterUnit: WaterUnits = .ml, cupCapacity: Double = 600.0, dailyGoals: Double = 3100.0, reminderTimeInterval: TimeInterval = 7200.0) {
init(waterUnit: WaterUnits = .ml, cupCapacity: Double = 600.0, dailyGoals: Double = 2400.0, reminderTimeInterval: TimeInterval = 7200.0) {
self.waterUnit = waterUnit
self.cupCapacity = cupCapacity
self.dailyGoal = dailyGoals
Expand Down
6 changes: 3 additions & 3 deletions Shared/Widgets/AccessoryWidget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,21 +103,21 @@ let mockingData = fillEmptyData(drinkDataRaw: [], startDate: NSCalendar.current.
#Preview(as: .accessoryCircular) {
WaterTracker_Accessory_Widget()
} timeline: {
SimpleEntry(date: .now, configuration: ConfigurationAppIntent(), todayTotalDrinkNum: 1600.0, dailyGoal: 3100.0, dayData: mockingData, weekData: [], waterConfig: WaterTrackerConfigManager())
SimpleEntry(date: .now, configuration: ConfigurationAppIntent(), todayTotalDrinkNum: 1600.0, dailyGoal: 2400.0, dayData: mockingData, weekData: [], waterConfig: WaterTrackerConfigManager())
}

#Preview(as: .accessoryRectangular) {
WaterTracker_Accessory_Widget()
} timeline: {
SimpleEntry(date: .now, configuration: ConfigurationAppIntent(), todayTotalDrinkNum: 1600.0, dailyGoal: 3100.0, dayData: mockingData, weekData: [], waterConfig: WaterTrackerConfigManager())
SimpleEntry(date: .now, configuration: ConfigurationAppIntent(), todayTotalDrinkNum: 1600.0, dailyGoal: 2400.0, dayData: mockingData, weekData: [], waterConfig: WaterTrackerConfigManager())
}

#if os(iOS)

#Preview(as: .accessoryInline) {
WaterTracker_Accessory_Widget()
} timeline: {
SimpleEntry(date: .now, configuration: ConfigurationAppIntent(), todayTotalDrinkNum: 1600.0, dailyGoal: 3100.0, dayData: mockingData, weekData: [], waterConfig: WaterTrackerConfigManager())
SimpleEntry(date: .now, configuration: ConfigurationAppIntent(), todayTotalDrinkNum: 1600.0, dailyGoal: 2400.0, dayData: mockingData, weekData: [], waterConfig: WaterTrackerConfigManager())
}

#elseif os(watchOS)
Expand Down
6 changes: 3 additions & 3 deletions WaterTracker Watch Widget/WaterTracker_Watch_Widget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct Provider: AppIntentTimelineProvider {
func placeholder(in context: Context) -> SimpleEntry {
let mockDayData = fillEmptyData(drinkDataRaw: [], startDate: NSCalendar.current.date(byAdding: .hour, value: -24, to: getStartOfDate(date: Date()))!, endDate:getStartOfDate(date: Date()), gapUnit: .hour, isMock: false)
let mockWeekData = fillEmptyData(drinkDataRaw: [], startDate: NSCalendar.current.date(byAdding: .day, value: -7, to: getStartOfDate(date: Date()))!, endDate:getStartOfDate(date: Date()), gapUnit: .day, isMock: false)
return SimpleEntry(date: getStartOfDate(date: Date()), configuration: ConfigurationAppIntent(), todayTotalDrinkNum: 2400.0, dailyGoal: 3100.0, dayData: mockDayData, weekData: mockWeekData, waterConfig: config)
return SimpleEntry(date: getStartOfDate(date: Date()), configuration: ConfigurationAppIntent(), todayTotalDrinkNum: 2000.0, dailyGoal: 2400.0, dayData: mockDayData, weekData: mockWeekData, waterConfig: config)
}

func snapshot(for configuration: ConfigurationAppIntent, in context: Context) async -> SimpleEntry {
Expand All @@ -28,7 +28,7 @@ struct Provider: AppIntentTimelineProvider {
config.receiveUpdatedWaterTrackerConfig(modelContext: context)
_ = await healthKitManager.updateDrinkWaterOneDay(waterUnitInput: config.waterUnit)
_ = await healthKitManager.updateDrinkWaterWeek(waterUnitInput: config.waterUnit)
return SimpleEntry(date: getStartOfDate(date: Date()), configuration: configuration, todayTotalDrinkNum: 2400.0, dailyGoal: 3100.0, dayData: healthKitManager.drinkDayData, weekData: healthKitManager.drinkWeekData, waterConfig: config)
return SimpleEntry(date: getStartOfDate(date: Date()), configuration: configuration, todayTotalDrinkNum: 2000.0, dailyGoal: 2400.0, dayData: healthKitManager.drinkDayData, weekData: healthKitManager.drinkWeekData, waterConfig: config)
} catch {
fatalError("Cannot get model container for config. ")
}
Expand Down Expand Up @@ -142,5 +142,5 @@ struct WaterTracker_Watch_Widget: Widget {
WaterTracker_Watch_Widget(isDayView: true)
} timeline: {
let mockingData = fillEmptyData(drinkDataRaw: [], startDate: NSCalendar.current.date(byAdding: .hour, value: -24, to: getStartOfDate(date: Date()))!, endDate: getStartOfDate(date: Date()), gapUnit: .hour, isMock: true)
SimpleEntry(date: .now, configuration: ConfigurationAppIntent(), todayTotalDrinkNum: 3100.0, dailyGoal: 3100.0, dayData: mockingData, weekData: [], waterConfig: WaterTrackerConfigManager())
SimpleEntry(date: .now, configuration: ConfigurationAppIntent(), todayTotalDrinkNum: 2000.0, dailyGoal: 2400.0, dayData: mockingData, weekData: [], waterConfig: WaterTrackerConfigManager())
}
10 changes: 5 additions & 5 deletions WaterTracker Widget/WaterTracker_Widget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ struct Provider: AppIntentTimelineProvider {
func placeholder(in context: Context) -> SimpleEntry {
let mockDayData = fillEmptyData(drinkDataRaw: [], startDate: NSCalendar.current.date(byAdding: .hour, value: -24, to: getStartOfDate(date: Date()))!, endDate:getStartOfDate(date: Date()), gapUnit: .hour, isMock: false)
let mockWeekData = fillEmptyData(drinkDataRaw: [], startDate: NSCalendar.current.date(byAdding: .day, value: -7, to: getStartOfDate(date: Date()))!, endDate:getStartOfDate(date: Date()), gapUnit: .day, isMock: false)
let todayTotalDrinkNum = 2400.0
let dailyGoal = 3100.0
let todayTotalDrinkNum = 2000.0
let dailyGoal = 2400.0
return SimpleEntry(date: getStartOfDate(date: Date()), configuration: ConfigurationAppIntent(), todayTotalDrinkNum: todayTotalDrinkNum, dailyGoal: dailyGoal, dayData: mockDayData, weekData: mockWeekData, waterConfig: config)
}

Expand All @@ -28,8 +28,8 @@ struct Provider: AppIntentTimelineProvider {
let container = try ModelContainer(for: WaterTrackerConfiguration.self)
let context = ModelContext(container)
config.receiveUpdatedWaterTrackerConfig(modelContext: context)
let todayTotalDrinkNum = 2400.0
let dailyGoal = 3100.0
let todayTotalDrinkNum = 2000.0
let dailyGoal = 2400.0
_ = await healthKitManager.updateDrinkWaterOneDay(waterUnitInput: config.waterUnit)
return SimpleEntry(date: getStartOfDate(date: Date()), configuration: configuration, todayTotalDrinkNum: todayTotalDrinkNum, dailyGoal: dailyGoal, dayData: healthKitManager.drinkDayData, weekData: healthKitManager.drinkWeekData, waterConfig: config)
} catch {
Expand Down Expand Up @@ -140,5 +140,5 @@ struct WaterTracker_Widget: Widget {
WaterTracker_Widget()
} timeline: {
let mockingData = fillEmptyData(drinkDataRaw: [], startDate: NSCalendar.current.date(byAdding: .hour, value: -24, to: getStartOfDate(date: Date()))!, endDate: getStartOfDate(date: Date()), gapUnit: .hour, isMock: true)
SimpleEntry(date: .now, configuration: ConfigurationAppIntent(), todayTotalDrinkNum: 2500.0, dailyGoal: 3100.0, dayData: mockingData, weekData: [], waterConfig: WaterTrackerConfigManager())
SimpleEntry(date: .now, configuration: ConfigurationAppIntent(), todayTotalDrinkNum: 2000.0, dailyGoal: 2400.0, dayData: mockingData, weekData: [], waterConfig: WaterTrackerConfigManager())
}

0 comments on commit 26323ac

Please sign in to comment.