Skip to content

Commit

Permalink
- Workout list/details updated in real time while working out also on…
Browse files Browse the repository at this point in the history
… watchOS

- Fixed update on iOS when viewing inside choices
  • Loading branch information
piscoTech committed Oct 8, 2018
1 parent 51e4705 commit 0758b33
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Gym Tracker Core/ExecuteWorkoutController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -645,11 +645,11 @@ public class ExecuteWorkoutController: NSObject {
}

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

public func isManaging(_ s: GTSet) -> Bool {
return isManaging(s.exercize)
return workoutIterator.isManaging(s.exercize)
}

public func secondaryInfoChange(for s: GTSet, forProposingChange: Bool = false) -> Double {
Expand Down
4 changes: 4 additions & 0 deletions Gym Tracker Core/WorkoutIterator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,10 @@ public class WorkoutIterator: IteratorProtocol {

// MARK: - Manage cache of secondary info changes

public func isManaging(_ p: GTPart) -> Bool {
return exercizes.contains { $0.contains(p) }
}

/// Fetch the secondary info change for the given exercize.
/// - returns: The secondary info change for the given exercize ignoring the workout progress.
func secondaryInfoChange(for e: GTSimpleSetsExercize) -> Double {
Expand Down
2 changes: 1 addition & 1 deletion Gym Tracker watchOS Extension/ExecuteWorkoutIC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ class ExecuteWorkoutInterfaceController: WKInterfaceController, ExecuteWorkoutCo
}

func globallyUpdateSecondaryInfoChange() {
#warning("Implement me")
appDelegate.executeWorkoutDetail?.reloadDetails(from: workoutController)
}

}
15 changes: 13 additions & 2 deletions Gym Tracker watchOS Extension/WorkoutDetailIC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class WorkoutDetailInterfaceController: WKInterfaceController {

private var workout: GTWorkout!
private var delegate: WorkoutListInterfaceController?

private var choices: [GTChoice: Int32]?

override func awake(withContext context: Any?) {
super.awake(withContext: context)
Expand All @@ -48,7 +50,7 @@ class WorkoutDetailInterfaceController: WKInterfaceController {
updateButton()
}

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

self.choices = choices
workoutName.setText(workout.name)
let exercizes = workout.exercizeList
let exCell = "exercize"
Expand Down Expand Up @@ -90,7 +93,11 @@ class WorkoutDetailInterfaceController: WKInterfaceController {
row.setRest(r.rest)
} else if let se = p as? GTSetsExercize {
let row = table.rowController(at: i) as! ExercizeCell
row.detailLabel.setText(se.summary)
if let curWrkt = ctrl {
row.detailLabel.setAttributedText(se.summaryWithSecondaryInfoChange(from: curWrkt))
} else {
row.detailLabel.setText(se.summary)
}
row.accessoryWidth = 21
row.showAccessory(false)

Expand All @@ -110,6 +117,10 @@ class WorkoutDetailInterfaceController: WKInterfaceController {
}
}
}

func reloadDetails(from ctrl: ExecuteWorkoutController) {
reloadData(checkExistence: false, choices: self.choices, withController: ctrl)
}

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

0 comments on commit 0758b33

Please sign in to comment.