This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
syntax = "proto2"; | |
message HomeCardResponse { | |
repeated CardContainer container = 1; | |
} | |
message CardContainer { | |
required Card card = 1; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func updateProgress(_ progress: Float) { | |
if self.progressView == nil { | |
let progressView = UIView() | |
progressView.backgroundColor = .black | |
progressView.translatesAutoresizingMaskIntoConstraints = false | |
self.addSubview(progressView) | |
let trailingConstraint = | |
progressView.leadingAnchor.constraint(equalTo: self.leadingAnchor) | |
NSLayoutConstraint.activate([ | |
progressView.topAnchor.constraint(equalTo: self.topAnchor), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func setupWorkout(_ workout: Workout) { | |
stackView.arrangedSubviews.forEach { view in | |
view.removeFromSuperview() | |
stackView.removeArrangedSubview(view) | |
} | |
workout.workoutSegments.forEach { workoutSegment in | |
let view = UIView() | |
view.translatesAutoresizingMaskIntoConstraints = false | |
let barView = UIView() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func color() -> UIColor { | |
switch self.highPower() { | |
case let p where p <= 0.6 : | |
return .gray | |
case let p where p < 0.76: | |
return .blue | |
case let p where p < 0.90: | |
return .green | |
case let p where p < 1.05: | |
return .yellow |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if let _ = message["sendReminder"] { | |
[1, 2, 3, 4, 5].forEach { count in | |
DispatchQueue.main.asyncAfter(deadline: .now() + count) { | |
self.playNotification() | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if let calories = message["calories"] as? Int, | |
let distance = message["distance"] as? Int, | |
let start = message["start"] as? Date, | |
let end = message["end"] as? Date | |
{ | |
let calorieQuantityType = HKQuantityType.quantityType(forIdentifier: .activeEnergyBurned)! | |
let calorieQuantity = HKQuantity(unit: .kilocalorie(), doubleValue: Double(calories)) | |
let caloriesBurned = HKQuantitySample(type: calorieQuantityType, quantity: calorieQuantity, start: start, end: end) | |
let distanceQuantityType = HKQuantityType.quantityType(forIdentifier: .distanceCycling)! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func workoutBuilder(_ workoutBuilder: HKLiveWorkoutBuilder, didCollectDataOf collectedTypes: Set<HKSampleType>) { | |
for type in collectedTypes { | |
guard let quantityType = type as? HKQuantityType else { | |
return | |
} | |
switch quantityType { | |
case HKQuantityType.quantityType(forIdentifier: .heartRate): | |
guard let statistics = workoutBuilder.statistics(for: quantityType), | |
let value = statistics.mostRecentQuantity()?.doubleValue(for: heartRateUnit) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
self.workoutSession = session | |
self.workoutBuilder = workoutSession.associatedWorkoutBuilder() | |
self.workoutBuilder.dataSource = | |
HKLiveWorkoutDataSource(healthStore: healthStore, | |
workoutConfiguration: workoutConfiguration) | |
self.workoutSession.delegate = self | |
self.workoutBuilder.delegate = self | |
self.workoutBuilder.beginCollection(withStart: Date()) { (_, _) in } | |
session.startActivity(with: Date()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func wattage(for ftp: Int, interval: TimeInterval) -> Int { | |
switch self { | |
case .warmup(duration: let duration, powerLow: let powerLow, powerHigh: let powerHigh): | |
return Int((((interval / duration) * (powerHigh - powerLow)) + powerLow) * Double(ftp)) | |
case .steady(duration: _, power: let power): | |
return Int(power * Double(ftp)) | |
case .intervals(reps: _, onDuration: _, offDuration: _, onPower: _, offPower: _): | |
return 0 | |
case .cooldown(duration: let duration, powerLow: let powerLow, powerHigh: let powerHigh): | |
return Int(((((duration - interval) / duration) * (powerHigh - powerLow)) + powerLow) * Double(ftp)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum WorkoutSegment { | |
case warmup(duration: TimeInterval, powerLow: Double, powerHigh: Double) | |
case intervals(reps: Int, onDuration: TimeInterval, offDuration: TimeInterval, onPower: Double, | |
offPower: Double) | |
case steady(duration: TimeInterval, power: Double) | |
case cooldown(duration: TimeInterval, powerLow: Double, powerHigh: Double) | |
} |
NewerOlder