Skip to content

Commit

Permalink
- Workout components now expose their description/summary with and wi…
Browse files Browse the repository at this point in the history
…thout considering the secondary info change

- Workout list/details now is updated in real time while working out reporting also the secondary info change (only iOS for now)
- Hacky fix for conflict between UIAppearance proxy and attributed string for text color on iOS
  • Loading branch information
piscoTech committed Oct 8, 2018
1 parent 5b0d1bb commit 51e4705
Show file tree
Hide file tree
Showing 19 changed files with 100 additions and 32 deletions.
4 changes: 2 additions & 2 deletions Gym Tracker Core/Double.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import Foundation

extension Double {

func secondaryInfoDescription(withChange change: Double) -> NSAttributedString? {
public func secondaryInfoDescription(withChange change: Double) -> NSAttributedString? {
guard self > 0 || change > 0 else {
return nil
}

return self.secondaryInfoDescriptionEvenForZero(withChange: change)
}

func secondaryInfoDescriptionEvenForZero(withChange change: Double) -> NSAttributedString {
public func secondaryInfoDescriptionEvenForZero(withChange change: Double) -> NSAttributedString {
let w = max(0, self)
let res = NSMutableAttributedString(string: w.toString())
let actCh = change > 0 ? change : max(change, -w)
Expand Down
8 changes: 8 additions & 0 deletions Gym Tracker Core/ExecuteWorkoutController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,14 @@ public class ExecuteWorkoutController: NSObject {
displayStep()
}

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

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

public func secondaryInfoChange(for s: GTSet, forProposingChange: Bool = false) -> Double {
guard !forProposingChange else {
return workoutIterator.secondaryInfoChange(for: s.exercize)
Expand Down
4 changes: 4 additions & 0 deletions Gym Tracker Core/GTExercize.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@ public class GTExercize: GTPart {
fatalError("Abstract property not implemented")
}

public func summaryWithSecondaryInfoChange(from ctrl: ExecuteWorkoutController) -> NSAttributedString {
return NSAttributedString(string: summary)
}

}
11 changes: 10 additions & 1 deletion Gym Tracker Core/GTRepsSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,16 @@ final public class GTRepsSet: GTSet {
@NSManaged private var weight: Double

override public var description: String {
return "\(reps)\(timesSign)\(weight.toString())kg"
return "\(reps)\(timesSign)\(weight.toString())\(GTRepsSet.kgLabel.string)"
}

public override func descriptionWithSecondaryInfoChange(from ctrl: ExecuteWorkoutController) -> NSAttributedString {
let ch = ctrl.secondaryInfoChange(for: self)
let res = NSMutableAttributedString(string: "\(reps)\(timesSign)")
res.append(weight.secondaryInfoDescriptionEvenForZero(withChange: ch))
res.append(GTRepsSet.kgLabel)

return res
}

override class func loadWithID(_ id: String, fromDataManager dataManager: DataManager) -> GTRepsSet? {
Expand Down
8 changes: 8 additions & 0 deletions Gym Tracker Core/GTSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ public class GTSet: GTDataObject {
@NSManaged final public var order: Int32

@NSManaged final public private(set) var rest: TimeInterval

override public var description: String {
fatalError("Abstract property not implemented")
}

public func descriptionWithSecondaryInfoChange(from ctrl: ExecuteWorkoutController) -> NSAttributedString {
return NSAttributedString(string: description)
}

override public var isValid: Bool {
// A low-level CoreData access is needed to check validity
Expand Down
4 changes: 4 additions & 0 deletions Gym Tracker Core/GTSimpleSetsExercize.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ public class GTSimpleSetsExercize: GTSetsExercize {
return setList.map { $0.description }.joined(separator: ", ")
}

public override func summaryWithSecondaryInfoChange(from ctrl: ExecuteWorkoutController) -> NSAttributedString {
return setList.map { $0.descriptionWithSecondaryInfoChange(from: ctrl) }.joined(separator: ", ")
}

///Set the name of the exercize.
public func set(name n: String) {
self.name = n.trimmingCharacters(in: .whitespacesAndNewlines)
Expand Down
4 changes: 2 additions & 2 deletions Gym Tracker Core/Info iOS.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>3.0</string>
<string>3.0.1</string>
<key>CFBundleVersion</key>
<string>13</string>
<string>14</string>
</dict>
</plist>
4 changes: 2 additions & 2 deletions Gym Tracker Core/Info watchOS.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>3.0</string>
<string>3.0.1</string>
<key>CFBundleVersion</key>
<string>13</string>
<string>14</string>
</dict>
</plist>
4 changes: 2 additions & 2 deletions Gym Tracker Notifications/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
<key>CFBundlePackageType</key>
<string>XPC!</string>
<key>CFBundleShortVersionString</key>
<string>3.0</string>
<string>3.0.1</string>
<key>CFBundleVersion</key>
<string>13</string>
<string>14</string>
<key>NSExtension</key>
<dict>
<key>NSExtensionAttributes</key>
Expand Down
4 changes: 2 additions & 2 deletions Gym Tracker iOS/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ extension AppDelegate: ExecuteWorkoutControllerDelegate {
guard !(workoutController?.isMirroring ?? true) else {
return
}
#warning("Check that the right value for weight change is selected")

var notifications = [UNNotificationRequest]()
let presentNow = UNTimeIntervalNotificationTrigger(timeInterval: GTNotification.immediateNotificationDelay, repeats: false)
if isRest {
Expand Down Expand Up @@ -528,7 +528,7 @@ extension AppDelegate: ExecuteWorkoutControllerDelegate {
}

func globallyUpdateSecondaryInfoChange() {
#warning("Implement me")
workoutList?.globallyUpdateSecondaryInfoChange()
}

}
Expand Down
13 changes: 8 additions & 5 deletions Gym Tracker iOS/CurrentWorkoutVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ class CurrentWorkoutViewController: UIViewController {

appDelegate.currentWorkout = self

for b in [setDoneBtn!, restDoneBtn!] {
b.clipsToBounds = true
b.layer.cornerRadius = 5
for b in [setDoneBtn, restDoneBtn] {
b?.clipsToBounds = true
b?.layer.cornerRadius = 5
}

for l in [bpmLbl!, timerLbl!, restTimerLbl!] {
l.font = l.font?.makeMonospacedDigit()
for l in [bpmLbl, timerLbl, restTimerLbl] {
l?.font = l?.font?.makeMonospacedDigit()
}

// This method is always called during app launch by the app delegate and as soon as the view is loaded it also updates it as appropriate
Expand Down Expand Up @@ -136,6 +136,7 @@ class CurrentWorkoutViewController: UIViewController {
}

func setCurrentSetText(_ text: NSAttributedString) {
currentSetInfoLbl.textColor = UILabel.appearance().textColor
currentSetInfoLbl.attributedText = text
}

Expand All @@ -144,6 +145,7 @@ class CurrentWorkoutViewController: UIViewController {
}

func setOtherSetsText(_ text: NSAttributedString) {
otherSetsLbl.textColor = UILabel.appearance().textColor
otherSetsLbl.attributedText = text
}

Expand Down Expand Up @@ -241,6 +243,7 @@ class CurrentWorkoutViewController: UIViewController {
}

func setNextUpText(_ text: NSAttributedString) {
nextUpLbl.textColor = UILabel.appearance().textColor
nextUpLbl.attributedText = text
}

Expand Down
16 changes: 10 additions & 6 deletions Gym Tracker iOS/ExercizeTVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,18 @@ class ExercizeTableViewController: UITableViewController, UITextFieldDelegate, U
tableView.reloadData()
}

func updateSecondaryInfoChange() {
tableView.reloadSections([1], with: .automatic)
}

func exercizeUpdated(_ e: GTPart) {}

func dismissPresentedController() {}

// MARK: - Table view data source

private enum SetCellType {
case reps, rest, picker
case set, rest, picker
}

override func numberOfSections(in tableView: UITableView) -> Int {
Expand Down Expand Up @@ -146,10 +150,10 @@ class ExercizeTableViewController: UITableViewController, UITextFieldDelegate, U
cell.set(rest: s.rest)

return cell
case .reps:
case .set:
let cell = tableView.dequeueReusableCell(withIdentifier: "set", for: indexPath) as! SetCell
cell.set = s
cell.isEnabled = editMode
cell.set = s

return cell
case .picker:
Expand Down Expand Up @@ -212,7 +216,7 @@ class ExercizeTableViewController: UITableViewController, UITextFieldDelegate, U
// MARK: - Delete set

override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
return editMode && indexPath.section == 1 && setCellType(for: indexPath) == .reps
return editMode && indexPath.section == 1 && setCellType(for: indexPath) == .set
}

override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
Expand Down Expand Up @@ -320,9 +324,9 @@ class ExercizeTableViewController: UITableViewController, UITextFieldDelegate, U
}
}

return row % 2 == 0 ? .reps : .rest
return row % 2 == 0 ? .set : .rest
} else { // No rests
return .reps
return .set
}
}

Expand Down
4 changes: 2 additions & 2 deletions Gym Tracker iOS/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>3.0</string>
<string>3.0.1</string>
<key>CFBundleVersion</key>
<string>13</string>
<string>14</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>LSSupportsOpeningDocumentsInPlace</key>
Expand Down
8 changes: 8 additions & 0 deletions Gym Tracker iOS/PartCollectionTVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import GymTrackerCore
func addDeletedEntities(_ del: [GTDataObject])
func exercizeUpdated(_ e: GTPart)
func updateView(global: Bool)
func updateSecondaryInfoChange()
func dismissPresentedController()

var partCollection: GTDataObject { get }
Expand Down Expand Up @@ -246,6 +247,13 @@ class PartCollectionTableViewController<T: GTDataObject>: UITableViewController,
subCollection?.updateView(global: false)
exercizeController?.updateView()
}

func updateSecondaryInfoChange() {
subCollection?.updateSecondaryInfoChange()
exercizeController?.updateSecondaryInfoChange()

tableView.reloadSections([mainSectionIndex], with: .automatic)
}

// MARK: - Table view data source

Expand Down
22 changes: 19 additions & 3 deletions Gym Tracker iOS/Table View Cells.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,12 @@ class ExercizeTableViewCell: UITableViewCell {

name.text = exercize.title
name.font = exercize is GTSimpleSetsExercize ? ExercizeTableViewCell.normalFont : ExercizeTableViewCell.italicFont
exercizeInfo.text = exercize.summary
if let curWrkt = appDelegate.workoutController, curWrkt.isManaging(exercize) {
exercizeInfo.textColor = UILabel.appearance().textColor
exercizeInfo.attributedText = exercize.summaryWithSecondaryInfoChange(from: curWrkt)
} else {
exercizeInfo.text = exercize.summary
}

isCircuit.isHidden = true
isChoice.isHidden = true
Expand Down Expand Up @@ -110,8 +115,19 @@ class SetCell: UITableViewCell, UITextFieldDelegate {
}

private func updateView() {
self.repsCount.text = set.mainInfo > 0 ? "\(set.mainInfo)" : ""
self.weight.text = set.secondaryInfo > 0 ? set.secondaryInfo.toString() : ""
self.repsCount.text = set.mainInfo > 0 || !isEnabled ? "\(set.mainInfo)" : ""
if !isEnabled {
if let curWrkt = appDelegate.workoutController, curWrkt.isManaging(set) {
let ch = curWrkt.secondaryInfoChange(for: set)
// Avoid the appearance color overriding the color of the attributed string
self.weight.textColor = UITextField.appearance().textColor
self.weight.attributedText = set.secondaryInfo.secondaryInfoDescriptionEvenForZero(withChange: ch)
} else {
self.weight.text = set.secondaryInfo.toString()
}
} else {
self.weight.text = set.secondaryInfo > 0 ? set.secondaryInfo.toString() : ""
}
}

func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
Expand Down
4 changes: 4 additions & 0 deletions Gym Tracker iOS/WorkoutListTVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,10 @@ class WorkoutListTableViewController: UITableViewController {
tableView.endUpdates()
}
}

func globallyUpdateSecondaryInfoChange() {
workoutController?.updateSecondaryInfoChange()
}

// MARK: - Navigation

Expand Down
4 changes: 2 additions & 2 deletions Gym Tracker watchOS Extension/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
<key>CFBundlePackageType</key>
<string>XPC!</string>
<key>CFBundleShortVersionString</key>
<string>3.0</string>
<string>3.0.1</string>
<key>CFBundleVersion</key>
<string>13</string>
<string>14</string>
<key>NSExtension</key>
<dict>
<key>NSExtensionAttributes</key>
Expand Down
4 changes: 2 additions & 2 deletions Gym Tracker watchOS/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>3.0</string>
<string>3.0.1</string>
<key>CFBundleVersion</key>
<string>13</string>
<string>14</string>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
Expand Down
2 changes: 1 addition & 1 deletion Gym Tracker.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@
7ADC03BC1E78A187005BDC25 /* GymTracker.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = GymTracker.xcdatamodel; sourceTree = "<group>"; };
7ADC03BE1E78A187005BDC25 /* GTRepsSet.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GTRepsSet.swift; sourceTree = "<group>"; };
7ADC03BF1E78A187005BDC25 /* GTWorkout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GTWorkout.swift; sourceTree = "<group>"; };
7ADC03C91E78A328005BDC25 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
7ADC03C91E78A328005BDC25 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = AppDelegate.swift; sourceTree = "<group>"; };
7ADC03CC1E78A328005BDC25 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
7ADC03CE1E78A328005BDC25 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
7ADC03CF1E78A328005BDC25 /* ExercizeTVC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExercizeTVC.swift; sourceTree = "<group>"; };
Expand Down

0 comments on commit 51e4705

Please sign in to comment.