Skip to content

Commit 0758b33

Browse files
committed
- Workout list/details updated in real time while working out also on watchOS
- Fixed update on iOS when viewing inside choices
1 parent 51e4705 commit 0758b33

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

Gym Tracker Core/ExecuteWorkoutController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -645,11 +645,11 @@ public class ExecuteWorkoutController: NSObject {
645645
}
646646

647647
public func isManaging(_ p: GTPart) -> Bool {
648-
return p.parentHierarchy.contains { ($0 as? GTWorkout) == workout }
648+
return workoutIterator.isManaging(p)
649649
}
650650

651651
public func isManaging(_ s: GTSet) -> Bool {
652-
return isManaging(s.exercize)
652+
return workoutIterator.isManaging(s.exercize)
653653
}
654654

655655
public func secondaryInfoChange(for s: GTSet, forProposingChange: Bool = false) -> Double {

Gym Tracker Core/WorkoutIterator.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,10 @@ public class WorkoutIterator: IteratorProtocol {
323323

324324
// MARK: - Manage cache of secondary info changes
325325

326+
public func isManaging(_ p: GTPart) -> Bool {
327+
return exercizes.contains { $0.contains(p) }
328+
}
329+
326330
/// Fetch the secondary info change for the given exercize.
327331
/// - returns: The secondary info change for the given exercize ignoring the workout progress.
328332
func secondaryInfoChange(for e: GTSimpleSetsExercize) -> Double {

Gym Tracker watchOS Extension/ExecuteWorkoutIC.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ class ExecuteWorkoutInterfaceController: WKInterfaceController, ExecuteWorkoutCo
223223
}
224224

225225
func globallyUpdateSecondaryInfoChange() {
226-
#warning("Implement me")
226+
appDelegate.executeWorkoutDetail?.reloadDetails(from: workoutController)
227227
}
228228

229229
}

Gym Tracker watchOS Extension/WorkoutDetailIC.swift

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ class WorkoutDetailInterfaceController: WKInterfaceController {
2626

2727
private var workout: GTWorkout!
2828
private var delegate: WorkoutListInterfaceController?
29+
30+
private var choices: [GTChoice: Int32]?
2931

3032
override func awake(withContext context: Any?) {
3133
super.awake(withContext: context)
@@ -48,7 +50,7 @@ class WorkoutDetailInterfaceController: WKInterfaceController {
4850
updateButton()
4951
}
5052

51-
func reloadData(checkExistence: Bool = true, choices: [GTChoice: Int32]? = nil) {
53+
func reloadData(checkExistence: Bool = true, choices: [GTChoice: Int32]? = nil, withController ctrl: ExecuteWorkoutController? = nil) {
5254
if checkExistence {
5355
guard workout.stillExists(inDataManager: appDelegate.dataManager), !workout.archived else {
5456
if delegate != nil {
@@ -60,6 +62,7 @@ class WorkoutDetailInterfaceController: WKInterfaceController {
6062
}
6163
}
6264

65+
self.choices = choices
6366
workoutName.setText(workout.name)
6467
let exercizes = workout.exercizeList
6568
let exCell = "exercize"
@@ -90,7 +93,11 @@ class WorkoutDetailInterfaceController: WKInterfaceController {
9093
row.setRest(r.rest)
9194
} else if let se = p as? GTSetsExercize {
9295
let row = table.rowController(at: i) as! ExercizeCell
93-
row.detailLabel.setText(se.summary)
96+
if let curWrkt = ctrl {
97+
row.detailLabel.setAttributedText(se.summaryWithSecondaryInfoChange(from: curWrkt))
98+
} else {
99+
row.detailLabel.setText(se.summary)
100+
}
94101
row.accessoryWidth = 21
95102
row.showAccessory(false)
96103

@@ -110,6 +117,10 @@ class WorkoutDetailInterfaceController: WKInterfaceController {
110117
}
111118
}
112119
}
120+
121+
func reloadDetails(from ctrl: ExecuteWorkoutController) {
122+
reloadData(checkExistence: false, choices: self.choices, withController: ctrl)
123+
}
113124

114125
override func willActivate() {
115126
// This method is called when watch view controller is about to be visible to user

0 commit comments

Comments
 (0)