From 8e566bd7c6882aa5fad6595e474476a7d34848b1 Mon Sep 17 00:00:00 2001 From: Marius Ursache Date: Thu, 16 Nov 2017 09:06:14 +1100 Subject: [PATCH 01/28] Split expresion to workaround swift compiler bug: "Ambiguous use of 'filter'" --- .../Domain/RepositoryCategory.swift | 13 +++++++++---- .../Domain/RepositoryRoutine.swift | 18 ++++++++++++------ 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/BodyweightFitness/Domain/RepositoryCategory.swift b/BodyweightFitness/Domain/RepositoryCategory.swift index 44c159e..9b30928 100644 --- a/BodyweightFitness/Domain/RepositoryCategory.swift +++ b/BodyweightFitness/Domain/RepositoryCategory.swift @@ -39,15 +39,20 @@ class RepositoryCategoryHelper { } class func numberOfCompletedExercises(_ repositoryCategory: RepositoryCategory) -> Int { - return repositoryCategory.exercises.filter({ + // Split expresion to workaround swift compiler bug: "Ambiguous use of 'filter'" + let exercises = repositoryCategory.exercises + let completedExercises = exercises.filter { $0.visible && isCompleted($0) - }).count + } + return completedExercises.count } class func numberOfExercises(_ repositoryCategory: RepositoryCategory) -> Int { - return repositoryCategory.exercises.filter({ + let exercises = repositoryCategory.exercises + let visibleExercises = exercises.filter { $0.visible - }).count + } + return visibleExercises.count } } diff --git a/BodyweightFitness/Domain/RepositoryRoutine.swift b/BodyweightFitness/Domain/RepositoryRoutine.swift index aa3a9f0..5c4a495 100644 --- a/BodyweightFitness/Domain/RepositoryRoutine.swift +++ b/BodyweightFitness/Domain/RepositoryRoutine.swift @@ -79,15 +79,19 @@ class RepositoryRoutineHelper { } class func numberOfCompletedExercises(_ repositoryRoutine: RepositoryRoutine) -> Int { - return repositoryRoutine.exercises.filter({ + let exercises = repositoryRoutine.exercises + let completed = exercises.filter { $0.visible && isCompleted($0) - }).count + } + return completed.count } class func numberOfExercises(_ repositoryRoutine: RepositoryRoutine) -> Int { - return repositoryRoutine.exercises.filter({ + let exercises = repositoryRoutine.exercises + let visible = exercises.filter { $0.visible - }).count + } + return visible.count } func completedExercises() -> Int { @@ -112,9 +116,11 @@ class RepositoryRoutineHelper { } func totalExercises() -> Int { - return repositoryRoutine.exercises.filter({ + let exercises = repositoryRoutine.exercises + let visible = exercises.filter { $0.visible == true - }).count + } + return visible.count } func exercisesLeft() -> Int { From e55a27649f1dc595d517bbeca647ebf24a6d60f2 Mon Sep 17 00:00:00 2001 From: Marius Ursache Date: Thu, 16 Nov 2017 09:06:32 +1100 Subject: [PATCH 02/28] Fixed missing try/throw error --- BodyweightFitness/Domain/Routine.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/BodyweightFitness/Domain/Routine.swift b/BodyweightFitness/Domain/Routine.swift index 4fdf4e5..7627046 100644 --- a/BodyweightFitness/Domain/Routine.swift +++ b/BodyweightFitness/Domain/Routine.swift @@ -111,7 +111,7 @@ class Routine { var linkedRoutine: NSMutableArray = [] init(fileName: String) { - let json = JSON(data: loadRoutineFromFile(fileName)) + let json = try! JSON(data: loadRoutineFromFile(fileName)) self.routineId = json["routineId"].stringValue self.title = json["title"].stringValue @@ -123,7 +123,7 @@ class Routine { } init(fileName: String, dictionary: Dictionary) { - let json = JSON(data: loadRoutineFromFile(fileName)) + let json = try! JSON(data: loadRoutineFromFile(fileName)) self.routineId = json["routineId"].stringValue self.title = json["title"].stringValue From 0366ee298930e46a636eea4f9fffab96e1926ad0 Mon Sep 17 00:00:00 2001 From: Marius Ursache Date: Thu, 16 Nov 2017 09:11:33 +1100 Subject: [PATCH 03/28] Fixed CalendarViewController scrollingMode, missing delegate --- BodyweightFitness/Main/CalendarViewController.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/BodyweightFitness/Main/CalendarViewController.swift b/BodyweightFitness/Main/CalendarViewController.swift index eeb5b10..d55b8dd 100644 --- a/BodyweightFitness/Main/CalendarViewController.swift +++ b/BodyweightFitness/Main/CalendarViewController.swift @@ -55,7 +55,7 @@ class CalendarViewController: UIViewController { self.calendarView.calendarDelegate = self self.calendarView.calendarDataSource = self self.calendarView.allowsMultipleSelection = false - self.calendarView.scrollingMode = .stopAtEachCalendarFrameWidth + self.calendarView.scrollingMode = .stopAtEachCalendarFrame self.calendarView.isRangeSelectionUsed = false self.calendarView.reloadData() @@ -213,4 +213,7 @@ extension CalendarViewController: JTAppleCalendarViewDataSource, JTAppleCalendar } } } + + func calendar(_ calendar: JTAppleCalendarView, willDisplay cell: JTAppleCell, forItemAt date: Date, cellState: CellState, indexPath: IndexPath) { + } } From eaa0ee17b706c7cc433e8a78df209c8d201c0974 Mon Sep 17 00:00:00 2001 From: Marius Ursache Date: Thu, 16 Nov 2017 09:20:28 +1100 Subject: [PATCH 04/28] Fixed result not used warning --- BodyweightFitness/View/SnackBar.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BodyweightFitness/View/SnackBar.swift b/BodyweightFitness/View/SnackBar.swift index aa16abb..98ebf0b 100644 --- a/BodyweightFitness/View/SnackBar.swift +++ b/BodyweightFitness/View/SnackBar.swift @@ -392,7 +392,7 @@ open class CWStatusBarNotification : NSObject { self.firstFrameChange() }, completion: { (finished) -> () in if let delayInSeconds = self.notificationLabel?.scrollTime() { - performClosureAfterDelay(Double(delayInSeconds), closure: { + let _ = performClosureAfterDelay(Double(delayInSeconds), closure: { () -> () in completion() }) From d57bfc23d4bb85a3319fd5ea2b330467ca039665 Mon Sep 17 00:00:00 2001 From: Marius Ursache Date: Thu, 16 Nov 2017 09:21:31 +1100 Subject: [PATCH 05/28] Set Eureka Swift version to 4.0, to fix NSAttributedStringKey.foregroundColor error --- Podfile | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/Podfile b/Podfile index 3f81f19..339c7ce 100644 --- a/Podfile +++ b/Podfile @@ -1,5 +1,5 @@ # Uncomment the next line to define a global platform for your project -platform :ios, '9.0' +platform :ios, '10.0' target 'Bodyweight Fitness' do # Comment the next line if you're not using Swift and don't want to use dynamic frameworks @@ -12,7 +12,18 @@ target 'Bodyweight Fitness' do pod 'RxCocoa', '~> 3.0' pod 'JTAppleCalendar', '~> 7.0' pod 'Eureka', '~> 4.0.1' - + pod 'Fabric' pod 'Crashlytics' + + post_install do |installer| + installer.pods_project.targets.each do |target| + if ['Eureka'].include? target.name + target.build_configurations.each do |config| + config.build_settings['SWIFT_VERSION'] = '4.0' + end + end + end + end + end From b74eae51eca7dcb346c1aca97e0096a5282d33d7 Mon Sep 17 00:00:00 2001 From: Marius Ursache Date: Thu, 21 Dec 2017 22:15:10 +1100 Subject: [PATCH 06/28] Fixed home screen background colour MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed home screen background colour (white) when pulling the scrollview Abstract content view bg color is set to white, the home view controller bg color is set to primary, so on pull, on the top part, you’ll get the primary --- BodyweightFitness/AbstractViewController.swift | 2 +- BodyweightFitness/Main/HomeViewController.swift | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/BodyweightFitness/AbstractViewController.swift b/BodyweightFitness/AbstractViewController.swift index 31f9dbc..95357b8 100644 --- a/BodyweightFitness/AbstractViewController.swift +++ b/BodyweightFitness/AbstractViewController.swift @@ -53,7 +53,7 @@ class AbstractViewController: UIViewController { func createBackgroundView(height: Int = 50) { let view = UIView() view.backgroundColor = UIColor.primary() - + self.contentView.backgroundColor = UIColor.white self.contentView.addSubview(view) view.snp.makeConstraints { (make) -> Void in diff --git a/BodyweightFitness/Main/HomeViewController.swift b/BodyweightFitness/Main/HomeViewController.swift index ea2e3f3..077e4e2 100644 --- a/BodyweightFitness/Main/HomeViewController.swift +++ b/BodyweightFitness/Main/HomeViewController.swift @@ -10,6 +10,7 @@ class HomeViewController: AbstractViewController, MFMailComposeViewControllerDel override func viewDidLoad() { super.viewDidLoad() + self.view.backgroundColor = UIColor.primary() self.setNavigationBar() _ = RoutineStream.sharedInstance.repositoryObservable().subscribe(onNext: { (it) in From dc340e2c6caa16b994af26d042c87801441a4b4d Mon Sep 17 00:00:00 2001 From: Marius Ursache Date: Thu, 21 Dec 2017 22:20:02 +1100 Subject: [PATCH 07/28] Fixed test failing in other timezones --- .../Domain/RepositoryRoutineCompanionSpec.swift | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/BodyweightFitnessTests/Domain/RepositoryRoutineCompanionSpec.swift b/BodyweightFitnessTests/Domain/RepositoryRoutineCompanionSpec.swift index 8a9f873..0ffa0f2 100644 --- a/BodyweightFitnessTests/Domain/RepositoryRoutineCompanionSpec.swift +++ b/BodyweightFitnessTests/Domain/RepositoryRoutineCompanionSpec.swift @@ -9,7 +9,6 @@ class RepositoryRoutineCompanionSpec: QuickSpec { let dateFormatter = DateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss'Z'" - dateFormatter.timeZone = TimeZone(abbreviation: "GMT+0:00") return dateFormatter.date(from: from)! } @@ -30,18 +29,18 @@ class RepositoryRoutineCompanionSpec: QuickSpec { context("dateWithTime()") { it("should return start date and time in EEE, d MMMM YYYY - HH:mm format") { let repositoryRoutine = RepositoryRoutine() - repositoryRoutine.startTime = self.mockDate(from: "2017-08-07T12:13:00Z") + repositoryRoutine.startTime = self.mockDate(from: "2017-08-07T15:13:00Z") let companion = RepositoryRoutineCompanion(repositoryRoutine) - expect(companion.dateWithTime()).to(equal("Monday, 7 August 2017 - 13:13")) + expect(companion.dateWithTime()).to(equal("Monday, 7 August 2017 - 15:13")) } } context("startTime()") { it("should return start time in HH:mm format") { let repositoryRoutine = RepositoryRoutine() - repositoryRoutine.startTime = self.mockDate(from: "2017-08-07T12:13:21Z") + repositoryRoutine.startTime = self.mockDate(from: "2017-08-07T13:13:21Z") let companion = RepositoryRoutineCompanion(repositoryRoutine) @@ -52,8 +51,7 @@ class RepositoryRoutineCompanionSpec: QuickSpec { context("lastUpdatedTime()") { it("should return last updated time in HH:mm format") { let repositoryRoutine = RepositoryRoutine() - repositoryRoutine.lastUpdatedTime = self.mockDate(from: "2017-08-07T13:13:21Z") - + repositoryRoutine.lastUpdatedTime = self.mockDate(from: "2017-08-07T14:13:21Z") let companion = RepositoryRoutineCompanion(repositoryRoutine) expect(companion.lastUpdatedTime()).to(equal("14:13")) From 6327f61cbc06fc7289dc10e92040ae3be1ef3159 Mon Sep 17 00:00:00 2001 From: Marius Ursache Date: Thu, 21 Dec 2017 22:22:46 +1100 Subject: [PATCH 08/28] Move canSendMail check to start of function --- .../Main/CalendarViewController.swift | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/BodyweightFitness/Main/CalendarViewController.swift b/BodyweightFitness/Main/CalendarViewController.swift index 43c67f9..f9ac47a 100644 --- a/BodyweightFitness/Main/CalendarViewController.swift +++ b/BodyweightFitness/Main/CalendarViewController.swift @@ -174,6 +174,11 @@ class CalendarViewController: AbstractViewController, MFMailComposeViewControlle } @IBAction func exportWorkout(_ sender: CardButton) { + if !MFMailComposeViewController.canSendMail() { + print("Mail services are not available") + return + } + let mailString = NSMutableString() if let repositoryRoutine = sender.repositoryRoutine { @@ -252,16 +257,8 @@ class CalendarViewController: AbstractViewController, MFMailComposeViewControlle let data = mailString.data(using: String.Encoding.utf8.rawValue, allowLossyConversion: false) if let data = data { - if !MFMailComposeViewController.canSendMail() { - print("Mail services are not available") - return - } - let emailViewController = configuredMailComposeViewController(data, subject: emailTitle, messageBody: content as String) - - if MFMailComposeViewController.canSendMail() { - self.present(emailViewController, animated: true, completion: nil) - } + self.present(emailViewController, animated: true, completion: nil) } } } From f58dd621fba6789f6b33d01a95ee64e6d132b662 Mon Sep 17 00:00:00 2001 From: Marius Ursache Date: Thu, 21 Dec 2017 22:28:45 +1100 Subject: [PATCH 09/28] Moved CSV building to RepositoryRoutineCompanion --- .../Domain/RepositoryRoutineCompanion.swift | 42 +++++++++++++++++++ .../Main/CalendarViewController.swift | 34 ++------------- 2 files changed, 45 insertions(+), 31 deletions(-) diff --git a/BodyweightFitness/Domain/RepositoryRoutineCompanion.swift b/BodyweightFitness/Domain/RepositoryRoutineCompanion.swift index 391e0b8..173abec 100644 --- a/BodyweightFitness/Domain/RepositoryRoutineCompanion.swift +++ b/BodyweightFitness/Domain/RepositoryRoutineCompanion.swift @@ -67,6 +67,48 @@ class RepositoryRoutineCompanion { return Double(Int(interval) / 60) } + func exercisesAsCSV(weightUnit: String) -> String { + let exercises = self.repositoryRoutine.exercises.filter { (exercise) in + exercise.visible == true + } + + if exercises.isEmpty { + return "" + } + + let mailString = NSMutableString() + mailString.append("Date, Start Time, End Time, Workout Length, Routine, Exercise, Set Order, Weight, Weight Units, Reps, Minutes, Seconds\n") + + for exercise in exercises { + let title = exercise.title + var index = 1 + + for set in exercise.sets { + let (_, minutes, seconds) = secondsToHoursMinutesSeconds(set.seconds) + + mailString.append(String( + format: "%@,%@,%@,%@,%@,%@,%d,%f,%@,%d,%d,%d\n", + self.date(), + self.startTime(), + self.lastUpdatedTime(), + self.workoutLength(), + "\(self.repositoryRoutine.title) - \(self.repositoryRoutine.subtitle)", + title, + index, + set.weight, + weightUnit, + set.reps, + minutes, + seconds + )) + + index += 1 + } + } + + return mailString as String + } + fileprivate func stringFromTimeInterval(_ interval: TimeInterval) -> (Int, Int) { let interval = Int(interval) diff --git a/BodyweightFitness/Main/CalendarViewController.swift b/BodyweightFitness/Main/CalendarViewController.swift index f9ac47a..f42ba1b 100644 --- a/BodyweightFitness/Main/CalendarViewController.swift +++ b/BodyweightFitness/Main/CalendarViewController.swift @@ -179,41 +179,14 @@ class CalendarViewController: AbstractViewController, MFMailComposeViewControlle return } - let mailString = NSMutableString() + let weightUnit = getWeightUnit() if let repositoryRoutine = sender.repositoryRoutine { let companion = RepositoryRoutineCompanion(repositoryRoutine) let exercisesCompanion = ListOfRepositoryExercisesCompanion(repositoryRoutine.exercises) - mailString.append("Date, Start Time, End Time, Workout Length, Routine, Exercise, Set Order, Weight, Weight Units, Reps, Minutes, Seconds\n") - - for exercise in exercisesCompanion.visibleExercises() { - let title = exercise.title - let weightValue = getWeightUnit() - var index = 1 - - for set in exercise.sets { - let (_, minutes, seconds) = secondsToHoursMinutesSeconds(set.seconds) - - mailString.append(String( - format: "%@,%@,%@,%@,%@,%@,%d,%f,%@,%d,%d,%d\n", - companion.date(), - companion.startTime(), - companion.lastUpdatedTime(), - companion.workoutLength(), - "\(repositoryRoutine.title) - \(repositoryRoutine.subtitle)", - title, - index, - set.weight, - weightValue, - set.reps, - minutes, - seconds - )) - - index += 1 - } - } + let mailString = companion.exercisesAsCSV(weightUnit: weightUnit) + let data = mailString.data(using: String.Encoding.utf8, allowLossyConversion: false) let content = NSMutableString() let emailTitle = "\(repositoryRoutine.title) workout for \(companion.dateWithTime())" @@ -255,7 +228,6 @@ class CalendarViewController: AbstractViewController, MFMailComposeViewControlle } } - let data = mailString.data(using: String.Encoding.utf8.rawValue, allowLossyConversion: false) if let data = data { let emailViewController = configuredMailComposeViewController(data, subject: emailTitle, messageBody: content as String) self.present(emailViewController, animated: true, completion: nil) From cd7708c9b055bfbbf7d79a75b3d1d0e15af633a7 Mon Sep 17 00:00:00 2001 From: Marius Ursache Date: Thu, 21 Dec 2017 22:32:48 +1100 Subject: [PATCH 10/28] Added tests for exercisesAsCSV --- .../RepositoryRoutineCompanionSpec.swift | 77 +++++++++++++------ 1 file changed, 54 insertions(+), 23 deletions(-) diff --git a/BodyweightFitnessTests/Domain/RepositoryRoutineCompanionSpec.swift b/BodyweightFitnessTests/Domain/RepositoryRoutineCompanionSpec.swift index 0ffa0f2..842a4b0 100644 --- a/BodyweightFitnessTests/Domain/RepositoryRoutineCompanionSpec.swift +++ b/BodyweightFitnessTests/Domain/RepositoryRoutineCompanionSpec.swift @@ -13,6 +13,34 @@ class RepositoryRoutineCompanionSpec: QuickSpec { return dateFormatter.date(from: from)! } + var routineCompleted: RepositoryRoutine { + let completedSet = RepositorySet() + completedSet.isTimed = true + completedSet.seconds = 10 + + let firstExercise = RepositoryExercise() + firstExercise.visible = true + firstExercise.sets.append(completedSet) + + let secondExercise = RepositoryExercise() + secondExercise.visible = true + secondExercise.sets.append(completedSet) + + let thirdExercise = RepositoryExercise() + thirdExercise.visible = true + thirdExercise.sets.append(completedSet) + + let repositoryRoutine = RepositoryRoutine() + repositoryRoutine.exercises.append(firstExercise) + repositoryRoutine.exercises.append(secondExercise) + repositoryRoutine.exercises.append(thirdExercise) + + repositoryRoutine.startTime = self.mockDate(from: "2017-08-07T13:13:00Z") + repositoryRoutine.lastUpdatedTime = self.mockDate(from: "2017-08-07T15:13:21Z") + + return repositoryRoutine + } + override func spec() { describe("RepositoryRoutineCompanion") { context("date()") { @@ -60,29 +88,7 @@ class RepositoryRoutineCompanionSpec: QuickSpec { context("lastUpdatedTimeLabel()") { it("should return 'End Time' if all exercises are completed") { - let completedSet = RepositorySet() - completedSet.isTimed = true - completedSet.seconds = 10 - - let firstExercise = RepositoryExercise() - firstExercise.visible = true - firstExercise.sets.append(completedSet) - - let secondExercise = RepositoryExercise() - secondExercise.visible = true - secondExercise.sets.append(completedSet) - - let thirdExercise = RepositoryExercise() - thirdExercise.visible = true - thirdExercise.sets.append(completedSet) - - let repositoryRoutine = RepositoryRoutine() - repositoryRoutine.exercises.append(firstExercise) - repositoryRoutine.exercises.append(secondExercise) - repositoryRoutine.exercises.append(thirdExercise) - - let companion = RepositoryRoutineCompanion(repositoryRoutine) - + let companion = RepositoryRoutineCompanion(self.routineCompleted) expect(companion.lastUpdatedTimeLabel()).to(equal("End Time")) } @@ -211,6 +217,31 @@ class RepositoryRoutineCompanionSpec: QuickSpec { expect(companion.workoutLengthInMinutes()).to(equal(215)) } } + + context("email") { + let unit = "kg" + + it("exercisesAsCSV should return empty string") { + let companion = RepositoryRoutineCompanion(RepositoryRoutine()) + let csv = companion.exercisesAsCSV(weightUnit: unit) + expect(csv).to(beEmpty()) + } + + it("exercisesAsCSV should return correct CSV") { + let companion = RepositoryRoutineCompanion(self.routineCompleted) + let csv = companion.exercisesAsCSV(weightUnit: unit) + + let expected = + """ +Date, Start Time, End Time, Workout Length, Routine, Exercise, Set Order, Weight, Weight Units, Reps, Minutes, Seconds +Monday, 7 August 2017,13:13,15:13,2h, - ,,1,0.000000,kg,0,0,10 +Monday, 7 August 2017,13:13,15:13,2h, - ,,1,0.000000,kg,0,0,10 +Monday, 7 August 2017,13:13,15:13,2h, - ,,1,0.000000,kg,0,0,10 + +""" + expect(csv).to(equal(expected)) + } + } } } } From 8f96fd865f0ba117bb6e7fc4589a6f1d39c2d3ee Mon Sep 17 00:00:00 2001 From: Marius Ursache Date: Thu, 21 Dec 2017 22:35:34 +1100 Subject: [PATCH 11/28] Added method to build emailSubject --- .../Domain/RepositoryRoutineCompanion.swift | 4 ++++ .../RepositoryRoutineCompanionSpec.swift | 18 +++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/BodyweightFitness/Domain/RepositoryRoutineCompanion.swift b/BodyweightFitness/Domain/RepositoryRoutineCompanion.swift index 173abec..8999ffb 100644 --- a/BodyweightFitness/Domain/RepositoryRoutineCompanion.swift +++ b/BodyweightFitness/Domain/RepositoryRoutineCompanion.swift @@ -109,6 +109,10 @@ class RepositoryRoutineCompanion { return mailString as String } + func emailSubject() -> String { + return "\(self.repositoryRoutine.title) workout for \(self.dateWithTime())" + } + fileprivate func stringFromTimeInterval(_ interval: TimeInterval) -> (Int, Int) { let interval = Int(interval) diff --git a/BodyweightFitnessTests/Domain/RepositoryRoutineCompanionSpec.swift b/BodyweightFitnessTests/Domain/RepositoryRoutineCompanionSpec.swift index 842a4b0..f9e3d19 100644 --- a/BodyweightFitnessTests/Domain/RepositoryRoutineCompanionSpec.swift +++ b/BodyweightFitnessTests/Domain/RepositoryRoutineCompanionSpec.swift @@ -38,6 +38,9 @@ class RepositoryRoutineCompanionSpec: QuickSpec { repositoryRoutine.startTime = self.mockDate(from: "2017-08-07T13:13:00Z") repositoryRoutine.lastUpdatedTime = self.mockDate(from: "2017-08-07T15:13:21Z") + repositoryRoutine.title = "Bodyweight Fitness" + repositoryRoutine.subtitle = "Recommended Routine" + return repositoryRoutine } @@ -234,13 +237,22 @@ class RepositoryRoutineCompanionSpec: QuickSpec { let expected = """ Date, Start Time, End Time, Workout Length, Routine, Exercise, Set Order, Weight, Weight Units, Reps, Minutes, Seconds -Monday, 7 August 2017,13:13,15:13,2h, - ,,1,0.000000,kg,0,0,10 -Monday, 7 August 2017,13:13,15:13,2h, - ,,1,0.000000,kg,0,0,10 -Monday, 7 August 2017,13:13,15:13,2h, - ,,1,0.000000,kg,0,0,10 +Monday, 7 August 2017,13:13,15:13,2h,Bodyweight Fitness - Recommended Routine,,1,0.000000,kg,0,0,10 +Monday, 7 August 2017,13:13,15:13,2h,Bodyweight Fitness - Recommended Routine,,1,0.000000,kg,0,0,10 +Monday, 7 August 2017,13:13,15:13,2h,Bodyweight Fitness - Recommended Routine,,1,0.000000,kg,0,0,10 """ expect(csv).to(equal(expected)) } + + it("emailSubject should be correct") { + let companion = RepositoryRoutineCompanion(self.routineCompleted) + let subject = companion.emailSubject() + + let expected = "Bodyweight Fitness workout for Monday, 7 August 2017 - 13:13" + + expect(subject).to(equal(expected)) + } } } } From 3a4b4d9871b8a78308621f11f4fc588ffa6b32e6 Mon Sep 17 00:00:00 2001 From: Marius Ursache Date: Thu, 21 Dec 2017 22:41:08 +1100 Subject: [PATCH 12/28] Added method to build emailBody --- .../Domain/RepositoryRoutineCompanion.swift | 48 +++++++++++++++++++ .../RepositoryRoutineCompanionSpec.swift | 29 +++++++++++ 2 files changed, 77 insertions(+) diff --git a/BodyweightFitness/Domain/RepositoryRoutineCompanion.swift b/BodyweightFitness/Domain/RepositoryRoutineCompanion.swift index 8999ffb..a56213e 100644 --- a/BodyweightFitness/Domain/RepositoryRoutineCompanion.swift +++ b/BodyweightFitness/Domain/RepositoryRoutineCompanion.swift @@ -113,6 +113,54 @@ class RepositoryRoutineCompanion { return "\(self.repositoryRoutine.title) workout for \(self.dateWithTime())" } + func emailBody(weightUnit: String) -> String { + let content = NSMutableString() + content.append("Hello,\nThe following is your workout in Text/HTML format (CSV attached).") + + content.append("\n\nWorkout on \(self.dateWithTime()).") + content.append("\nLast Updated at \(self.lastUpdatedTime())") + content.append("\nWorkout length: \(self.workoutLength())") + + let exercises = self.repositoryRoutine.exercises.filter { (exercise) in + exercise.visible == true + } + + if exercises.isEmpty { + return content as String + } + + content.append("\n\n\(self.repositoryRoutine.title)\n\(self.repositoryRoutine.subtitle)") + + for exercise in exercises { + content.append("\n\n\(exercise.title)") + + var index = 1 + for set in exercise.sets { + let (_, minutes, seconds) = secondsToHoursMinutesSeconds(set.seconds) + + content.append("\nSet \(index)") + + if (set.isTimed) { + if minutes > 0 { + content.append(", Minutes: \(minutes)") + } + + content.append(", Seconds: \(seconds)") + } else { + content.append(", Reps: \(set.reps)") + + if set.weight > 0 { + content.append(", Weight: \(set.weight) \(weightUnit)") + } + } + + index += 1 + } + } + + return content as String + } + fileprivate func stringFromTimeInterval(_ interval: TimeInterval) -> (Int, Int) { let interval = Int(interval) diff --git a/BodyweightFitnessTests/Domain/RepositoryRoutineCompanionSpec.swift b/BodyweightFitnessTests/Domain/RepositoryRoutineCompanionSpec.swift index f9e3d19..e2e37e1 100644 --- a/BodyweightFitnessTests/Domain/RepositoryRoutineCompanionSpec.swift +++ b/BodyweightFitnessTests/Domain/RepositoryRoutineCompanionSpec.swift @@ -253,6 +253,35 @@ Monday, 7 August 2017,13:13,15:13,2h,Bodyweight Fitness - Recommended Routine,,1 expect(subject).to(equal(expected)) } + + it("emailBody should return correct body text") { + let companion = RepositoryRoutineCompanion(self.routineCompleted) + let body = companion.emailBody(weightUnit: unit) + + let expected = + """ +Hello, +The following is your workout in Text/HTML format (CSV attached). + +Workout on Monday, 7 August 2017 - 13:13. +Last Updated at 15:13 +Workout length: 2h + +Bodyweight Fitness +Recommended Routine + + +Set 1, Seconds: 10 + + +Set 1, Seconds: 10 + + +Set 1, Seconds: 10 +""" + + expect(body).to(equal(expected)) + } } } } From 8b12240c56154dbeed2f301138bf22b71e17f467 Mon Sep 17 00:00:00 2001 From: Marius Ursache Date: Thu, 21 Dec 2017 22:41:19 +1100 Subject: [PATCH 13/28] Compose email using refactored subject/body/csv --- .../Main/CalendarViewController.swift | 61 ++++--------------- 1 file changed, 12 insertions(+), 49 deletions(-) diff --git a/BodyweightFitness/Main/CalendarViewController.swift b/BodyweightFitness/Main/CalendarViewController.swift index f42ba1b..fee98a7 100644 --- a/BodyweightFitness/Main/CalendarViewController.swift +++ b/BodyweightFitness/Main/CalendarViewController.swift @@ -179,59 +179,22 @@ class CalendarViewController: AbstractViewController, MFMailComposeViewControlle return } - let weightUnit = getWeightUnit() - - if let repositoryRoutine = sender.repositoryRoutine { - let companion = RepositoryRoutineCompanion(repositoryRoutine) - let exercisesCompanion = ListOfRepositoryExercisesCompanion(repositoryRoutine.exercises) - - let mailString = companion.exercisesAsCSV(weightUnit: weightUnit) - let data = mailString.data(using: String.Encoding.utf8, allowLossyConversion: false) - - let content = NSMutableString() - let emailTitle = "\(repositoryRoutine.title) workout for \(companion.dateWithTime())" - - content.append("Hello,\nThe following is your workout in Text/HTML format (CSV attached).") - - content.append("\n\nWorkout on \(companion.dateWithTime()).") - content.append("\nLast Updated at \(companion.lastUpdatedTime())") - content.append("\nWorkout length: \(companion.workoutLength())") - - content.append("\n\n\(repositoryRoutine.title)\n\(repositoryRoutine.subtitle)") - - let weightUnit = getWeightUnit() - - for exercise in exercisesCompanion.visibleExercises() { - content.append("\n\n\(exercise.title)") - - var index = 1 - for set in exercise.sets { - let (_, minutes, seconds) = secondsToHoursMinutesSeconds(set.seconds) - - content.append("\nSet \(index)") - - if (set.isTimed) { - if minutes > 0 { - content.append(", Minutes: \(minutes)") - } + guard let routine = sender.repositoryRoutine else { + return + } - content.append(", Seconds: \(seconds)") - } else { - content.append(", Reps: \(set.reps)") + let weightUnit = getWeightUnit() - if set.weight > 0 { - content.append(", Weight: \(set.weight) \(weightUnit)") - } - } + let companion = RepositoryRoutineCompanion(routine) - index += 1 - } - } + let mailString = companion.exercisesAsCSV(weightUnit: weightUnit) + let data = mailString.data(using: String.Encoding.utf8, allowLossyConversion: false) + let subject = companion.emailSubject() + let body = companion.emailBody(weightUnit: weightUnit) - if let data = data { - let emailViewController = configuredMailComposeViewController(data, subject: emailTitle, messageBody: content as String) - self.present(emailViewController, animated: true, completion: nil) - } + if let data = data { + let emailViewController = configuredMailComposeViewController(data, subject: subject, messageBody: body) + self.present(emailViewController, animated: true, completion: nil) } } From 8c40017051e0f5f15a6bf91ae1992395c18fb2d7 Mon Sep 17 00:00:00 2001 From: Marius Ursache Date: Thu, 21 Dec 2017 22:43:08 +1100 Subject: [PATCH 14/28] Added property to generate unique workout csv names --- BodyweightFitness/Domain/RepositoryRoutineCompanion.swift | 4 ++++ .../Domain/RepositoryRoutineCompanionSpec.swift | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/BodyweightFitness/Domain/RepositoryRoutineCompanion.swift b/BodyweightFitness/Domain/RepositoryRoutineCompanion.swift index a56213e..7fdb8b2 100644 --- a/BodyweightFitness/Domain/RepositoryRoutineCompanion.swift +++ b/BodyweightFitness/Domain/RepositoryRoutineCompanion.swift @@ -109,6 +109,10 @@ class RepositoryRoutineCompanion { return mailString as String } + func csvName() -> String { + return "Workout-\(self.repositoryRoutine.title)-\(self.dateWithTime()).csv" + } + func emailSubject() -> String { return "\(self.repositoryRoutine.title) workout for \(self.dateWithTime())" } diff --git a/BodyweightFitnessTests/Domain/RepositoryRoutineCompanionSpec.swift b/BodyweightFitnessTests/Domain/RepositoryRoutineCompanionSpec.swift index e2e37e1..9774ad8 100644 --- a/BodyweightFitnessTests/Domain/RepositoryRoutineCompanionSpec.swift +++ b/BodyweightFitnessTests/Domain/RepositoryRoutineCompanionSpec.swift @@ -245,6 +245,14 @@ Monday, 7 August 2017,13:13,15:13,2h,Bodyweight Fitness - Recommended Routine,,1 expect(csv).to(equal(expected)) } + it("csvName should return correct filename") { + let companion = RepositoryRoutineCompanion(self.routineCompleted) + let csvName = companion.csvName() + + let expected = "Workout-Bodyweight Fitness-Monday, 7 August 2017 - 13:13.csv" + expect(csvName).to(equal(expected)) + } + it("emailSubject should be correct") { let companion = RepositoryRoutineCompanion(self.routineCompleted) let subject = companion.emailSubject() From de0c133e11450b8b353a2008e2cd31fa2b58664e Mon Sep 17 00:00:00 2001 From: Marius Ursache Date: Thu, 21 Dec 2017 22:47:11 +1100 Subject: [PATCH 15/28] Send email even if no exercises are completed --- .../Main/CalendarViewController.swift | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/BodyweightFitness/Main/CalendarViewController.swift b/BodyweightFitness/Main/CalendarViewController.swift index fee98a7..e7e0892 100644 --- a/BodyweightFitness/Main/CalendarViewController.swift +++ b/BodyweightFitness/Main/CalendarViewController.swift @@ -191,11 +191,10 @@ class CalendarViewController: AbstractViewController, MFMailComposeViewControlle let data = mailString.data(using: String.Encoding.utf8, allowLossyConversion: false) let subject = companion.emailSubject() let body = companion.emailBody(weightUnit: weightUnit) + let csvName = companion.csvName() - if let data = data { - let emailViewController = configuredMailComposeViewController(data, subject: subject, messageBody: body) - self.present(emailViewController, animated: true, completion: nil) - } + let emailViewController = configuredMailComposeViewController(subject: subject, messageBody: body, csv: data, csvName: csvName) + self.present(emailViewController, animated: true, completion: nil) } @IBAction func removeLoggedWorkout(_ sender: CardButton) { @@ -234,17 +233,22 @@ class CalendarViewController: AbstractViewController, MFMailComposeViewControlle } } - func configuredMailComposeViewController(_ data: Data, subject: String, messageBody: String) -> MFMailComposeViewController { + func configuredMailComposeViewController(subject: String, messageBody: String, csv: Data?, csvName: String) -> MFMailComposeViewController { let emailController = MFMailComposeViewController() emailController.mailComposeDelegate = self emailController.setSubject(subject) emailController.setMessageBody(messageBody, isHTML: false) - emailController.addAttachmentData(data, mimeType: "text/csv", fileName: "Workout.csv") + + if let data = csv { + emailController.addAttachmentData(data, mimeType: "text/csv", fileName: csvName) + } return emailController } + // MARK: - MFMailComposeViewControllerDelegate + func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) { controller.dismiss(animated: true, completion: nil) } From a2b30f3fc59ef7f10e40d62ebde035ab3fae7735 Mon Sep 17 00:00:00 2001 From: Marius Ursache Date: Thu, 21 Dec 2017 22:51:15 +1100 Subject: [PATCH 16/28] Return CSV NSData instead of String --- .../Domain/RepositoryRoutineCompanion.swift | 6 +++--- BodyweightFitness/Main/CalendarViewController.swift | 6 +++--- .../Domain/RepositoryRoutineCompanionSpec.swift | 9 +++++---- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/BodyweightFitness/Domain/RepositoryRoutineCompanion.swift b/BodyweightFitness/Domain/RepositoryRoutineCompanion.swift index 7fdb8b2..64daa3e 100644 --- a/BodyweightFitness/Domain/RepositoryRoutineCompanion.swift +++ b/BodyweightFitness/Domain/RepositoryRoutineCompanion.swift @@ -67,13 +67,13 @@ class RepositoryRoutineCompanion { return Double(Int(interval) / 60) } - func exercisesAsCSV(weightUnit: String) -> String { + func csv(weightUnit: String) -> Data? { let exercises = self.repositoryRoutine.exercises.filter { (exercise) in exercise.visible == true } if exercises.isEmpty { - return "" + return nil } let mailString = NSMutableString() @@ -106,7 +106,7 @@ class RepositoryRoutineCompanion { } } - return mailString as String + return mailString.data(using: String.Encoding.utf8.rawValue, allowLossyConversion: false) } func csvName() -> String { diff --git a/BodyweightFitness/Main/CalendarViewController.swift b/BodyweightFitness/Main/CalendarViewController.swift index e7e0892..17efe4a 100644 --- a/BodyweightFitness/Main/CalendarViewController.swift +++ b/BodyweightFitness/Main/CalendarViewController.swift @@ -187,10 +187,10 @@ class CalendarViewController: AbstractViewController, MFMailComposeViewControlle let companion = RepositoryRoutineCompanion(routine) - let mailString = companion.exercisesAsCSV(weightUnit: weightUnit) - let data = mailString.data(using: String.Encoding.utf8, allowLossyConversion: false) let subject = companion.emailSubject() let body = companion.emailBody(weightUnit: weightUnit) + + let csv = companion.csv(weightUnit: weightUnit) let csvName = companion.csvName() let emailViewController = configuredMailComposeViewController(subject: subject, messageBody: body, csv: data, csvName: csvName) @@ -248,7 +248,7 @@ class CalendarViewController: AbstractViewController, MFMailComposeViewControlle } // MARK: - MFMailComposeViewControllerDelegate - + func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) { controller.dismiss(animated: true, completion: nil) } diff --git a/BodyweightFitnessTests/Domain/RepositoryRoutineCompanionSpec.swift b/BodyweightFitnessTests/Domain/RepositoryRoutineCompanionSpec.swift index 9774ad8..07f409b 100644 --- a/BodyweightFitnessTests/Domain/RepositoryRoutineCompanionSpec.swift +++ b/BodyweightFitnessTests/Domain/RepositoryRoutineCompanionSpec.swift @@ -226,15 +226,15 @@ class RepositoryRoutineCompanionSpec: QuickSpec { it("exercisesAsCSV should return empty string") { let companion = RepositoryRoutineCompanion(RepositoryRoutine()) - let csv = companion.exercisesAsCSV(weightUnit: unit) - expect(csv).to(beEmpty()) + let csv = companion.csv(weightUnit: unit) + expect(csv).to(beNil()) } it("exercisesAsCSV should return correct CSV") { let companion = RepositoryRoutineCompanion(self.routineCompleted) - let csv = companion.exercisesAsCSV(weightUnit: unit) + let csv = companion.csv(weightUnit: unit) - let expected = + let expectedStr = """ Date, Start Time, End Time, Workout Length, Routine, Exercise, Set Order, Weight, Weight Units, Reps, Minutes, Seconds Monday, 7 August 2017,13:13,15:13,2h,Bodyweight Fitness - Recommended Routine,,1,0.000000,kg,0,0,10 @@ -242,6 +242,7 @@ Monday, 7 August 2017,13:13,15:13,2h,Bodyweight Fitness - Recommended Routine,,1 Monday, 7 August 2017,13:13,15:13,2h,Bodyweight Fitness - Recommended Routine,,1,0.000000,kg,0,0,10 """ + let expected = expectedStr.data(using: String.Encoding.utf8, allowLossyConversion: false) expect(csv).to(equal(expected)) } From 3f189368352bb493e775fff85876a9e7de9ae58c Mon Sep 17 00:00:00 2001 From: Marius Ursache Date: Fri, 22 Dec 2017 07:01:46 +1100 Subject: [PATCH 17/28] Fixed extra end (conflict artifact) --- Podfile | 1 - 1 file changed, 1 deletion(-) diff --git a/Podfile b/Podfile index d510c20..c12be3e 100644 --- a/Podfile +++ b/Podfile @@ -34,7 +34,6 @@ post_install do |installer| if ['Charts'].include? target.name target.build_configurations.each do |config| config.build_settings['SWIFT_VERSION'] = '4.0' - end end end end From 39d61fd6e7d5b27d132dcdbc565b632c83642f5b Mon Sep 17 00:00:00 2001 From: Marius Ursache Date: Fri, 22 Dec 2017 07:02:59 +1100 Subject: [PATCH 18/28] Revert "Fixed home screen background colour" This reverts commit b74eae51eca7dcb346c1aca97e0096a5282d33d7. --- BodyweightFitness/AbstractViewController.swift | 2 +- BodyweightFitness/Main/HomeViewController.swift | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/BodyweightFitness/AbstractViewController.swift b/BodyweightFitness/AbstractViewController.swift index 95357b8..31f9dbc 100644 --- a/BodyweightFitness/AbstractViewController.swift +++ b/BodyweightFitness/AbstractViewController.swift @@ -53,7 +53,7 @@ class AbstractViewController: UIViewController { func createBackgroundView(height: Int = 50) { let view = UIView() view.backgroundColor = UIColor.primary() - self.contentView.backgroundColor = UIColor.white + self.contentView.addSubview(view) view.snp.makeConstraints { (make) -> Void in diff --git a/BodyweightFitness/Main/HomeViewController.swift b/BodyweightFitness/Main/HomeViewController.swift index 077e4e2..ea2e3f3 100644 --- a/BodyweightFitness/Main/HomeViewController.swift +++ b/BodyweightFitness/Main/HomeViewController.swift @@ -10,7 +10,6 @@ class HomeViewController: AbstractViewController, MFMailComposeViewControllerDel override func viewDidLoad() { super.viewDidLoad() - self.view.backgroundColor = UIColor.primary() self.setNavigationBar() _ = RoutineStream.sharedInstance.repositoryObservable().subscribe(onNext: { (it) in From 60e94a481c3994205bf82e50843fad3007323e18 Mon Sep 17 00:00:00 2001 From: Marius Ursache Date: Sat, 6 Jan 2018 11:15:41 +1100 Subject: [PATCH 19/28] Fixed wrong csv body passed to email --- BodyweightFitness/Main/CalendarViewController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BodyweightFitness/Main/CalendarViewController.swift b/BodyweightFitness/Main/CalendarViewController.swift index 17efe4a..1a59e53 100644 --- a/BodyweightFitness/Main/CalendarViewController.swift +++ b/BodyweightFitness/Main/CalendarViewController.swift @@ -193,7 +193,7 @@ class CalendarViewController: AbstractViewController, MFMailComposeViewControlle let csv = companion.csv(weightUnit: weightUnit) let csvName = companion.csvName() - let emailViewController = configuredMailComposeViewController(subject: subject, messageBody: body, csv: data, csvName: csvName) + let emailViewController = configuredMailComposeViewController(subject: subject, messageBody: body, csv: csv, csvName: csvName) self.present(emailViewController, animated: true, completion: nil) } From b6fd1cd6ad4133ae2cfbbee7993b6b13abc999d4 Mon Sep 17 00:00:00 2001 From: Marius Ursache Date: Sat, 6 Jan 2018 11:29:46 +1100 Subject: [PATCH 20/28] Refactored date extensions to the same file --- BodyweightFitness/Date+Extensions.swift | 80 ++++++++++++++++++ .../Domain/RepositoryStream.swift | 83 ------------------- .../Main/HomeViewController.swift | 2 +- 3 files changed, 81 insertions(+), 84 deletions(-) diff --git a/BodyweightFitness/Date+Extensions.swift b/BodyweightFitness/Date+Extensions.swift index 5d0a690..d25c203 100644 --- a/BodyweightFitness/Date+Extensions.swift +++ b/BodyweightFitness/Date+Extensions.swift @@ -77,4 +77,84 @@ extension Date { //Return Result return isEqualTo } + + func timeAgo() -> String { + let calendar = Calendar.current + let now = Date() + let unitFlags: NSCalendar.Unit = [.second, .minute, .hour, .day, .weekOfYear, .month, .year] + let components = (calendar as NSCalendar).components(unitFlags, from: self, to: now, options: []) + + if components.year! >= 2 { + return "\(components.year!) years ago" + } + + if components.year! >= 1 { + return "Last year" + } + + if components.month! >= 2 { + return "\(components.month!) months ago" + } + + if components.month! >= 1 { + return "Last month" + } + + if components.weekOfYear! >= 2 { + return "\(components.weekOfYear!) weeks ago" + } + + if components.weekOfYear! >= 1 { + return "Last week" + } + + if components.day! >= 2 { + return "\(components.day!) days ago" + } + + if components.day! >= 1 { + return "Yesterday" + } + + if components.hour! >= 2 { + return "\(components.hour!) hours ago" + } + + if components.hour! >= 1 { + return "An hour ago" + } + + if components.minute! >= 2 { + return "\(components.minute!) minutes ago" + } + + if components.minute! >= 1 { + return "A minute ago" + } + + if components.second! >= 3 { + return "\(components.second!) seconds ago" + } + + return "Just now" + } + + static func changeDaysBy(_ days : Int) -> Date { + let startOfDay = Calendar.current.startOfDay(for: Date()) + + var components = DateComponents() + components.hour = 23 + components.minute = 59 + components.second = 59 + + let currentDate = (Calendar.current as NSCalendar).date( + byAdding: components, + to: startOfDay, + options: NSCalendar.Options(rawValue: 0))! + + var dateComponents = DateComponents() + dateComponents.day = days + return (Calendar.current as NSCalendar).date( + byAdding: dateComponents, to: currentDate, options: NSCalendar.Options(rawValue: 0))! + } } diff --git a/BodyweightFitness/Domain/RepositoryStream.swift b/BodyweightFitness/Domain/RepositoryStream.swift index 7b4eb8d..31ac5d6 100644 --- a/BodyweightFitness/Domain/RepositoryStream.swift +++ b/BodyweightFitness/Domain/RepositoryStream.swift @@ -1,89 +1,6 @@ import Foundation import RealmSwift -extension Date { - static func changeDaysBy(_ days : Int) -> Date { - let startOfDay = Calendar.current.startOfDay(for: Date()) - - var components = DateComponents() - components.hour = 23 - components.minute = 59 - components.second = 59 - - let currentDate = (Calendar.current as NSCalendar).date( - byAdding: components, - to: startOfDay, - options: NSCalendar.Options(rawValue: 0))! - - var dateComponents = DateComponents() - dateComponents.day = days - return (Calendar.current as NSCalendar).date( - byAdding: dateComponents, to: currentDate, options: NSCalendar.Options(rawValue: 0))! - } - - static func timeAgoSince(_ date: Date) -> String { - let calendar = Calendar.current - let now = Date() - let unitFlags: NSCalendar.Unit = [.second, .minute, .hour, .day, .weekOfYear, .month, .year] - let components = (calendar as NSCalendar).components(unitFlags, from: date, to: now, options: []) - - if components.year! >= 2 { - return "\(components.year!) years ago" - } - - if components.year! >= 1 { - return "Last year" - } - - if components.month! >= 2 { - return "\(components.month!) months ago" - } - - if components.month! >= 1 { - return "Last month" - } - - if components.weekOfYear! >= 2 { - return "\(components.weekOfYear!) weeks ago" - } - - if components.weekOfYear! >= 1 { - return "Last week" - } - - if components.day! >= 2 { - return "\(components.day!) days ago" - } - - if components.day! >= 1 { - return "Yesterday" - } - - if components.hour! >= 2 { - return "\(components.hour!) hours ago" - } - - if components.hour! >= 1 { - return "An hour ago" - } - - if components.minute! >= 2 { - return "\(components.minute!) minutes ago" - } - - if components.minute! >= 1 { - return "A minute ago" - } - - if components.second! >= 3 { - return "\(components.second!) seconds ago" - } - - return "Just now" - - } -} - final class RepositoryStream { static let sharedInstance = RepositoryStream() diff --git a/BodyweightFitness/Main/HomeViewController.swift b/BodyweightFitness/Main/HomeViewController.swift index ea2e3f3..db69df8 100644 --- a/BodyweightFitness/Main/HomeViewController.swift +++ b/BodyweightFitness/Main/HomeViewController.swift @@ -176,7 +176,7 @@ class HomeViewController: AbstractViewController, MFMailComposeViewControllerDel topRightLabel.textAlignment = .right if let workout = lastWorkout { - topRightLabel.text = String(Date.timeAgoSince(workout.startTime)) + topRightLabel.text = workout.startTime.timeAgo() } else { topRightLabel.text = String("Never") } From 3c455711b34d146b383c8929630287035e539b10 Mon Sep 17 00:00:00 2001 From: Marius Ursache Date: Sat, 6 Jan 2018 13:21:37 +1100 Subject: [PATCH 21/28] Moved interactions with child VC to WorkoutInteractionDelegate --- .../Workout/RestTimerViewController.swift | 13 ++- .../Workout/TimedViewController.swift | 8 +- .../Workout/WeightedViewController.swift | 10 +- .../Workout/WorkoutViewController.swift | 108 ++++++++++-------- 4 files changed, 78 insertions(+), 61 deletions(-) diff --git a/BodyweightFitness/Workout/RestTimerViewController.swift b/BodyweightFitness/Workout/RestTimerViewController.swift index dcc0968..2d5b2c5 100644 --- a/BodyweightFitness/Workout/RestTimerViewController.swift +++ b/BodyweightFitness/Workout/RestTimerViewController.swift @@ -9,8 +9,9 @@ class RestTimerViewController: UIViewController, AVAudioPlayerDelegate { @IBOutlet var previousButton: UIButton! @IBOutlet var nextButton: UIButton! - - var rootViewController: WorkoutViewController? = nil + + var delegate: WorkoutInteractionDelegate? + var current: Exercise = RoutineStream.sharedInstance.routine.getFirstExercise() var audioPlayer: AVAudioPlayer? @@ -100,7 +101,7 @@ class RestTimerViewController: UIViewController, AVAudioPlayerDelegate { seconds -= 1 if(seconds <= 0) { - self.rootViewController?.restTimerStopped() + self.delegate?.restTimerShouldStop() let defaults = Foundation.UserDefaults.standard if(defaults.object(forKey: "playAudioWhenTimerStops") != nil) { @@ -142,14 +143,14 @@ class RestTimerViewController: UIViewController, AVAudioPlayerDelegate { } @IBAction func stopButtonClicked(_ sender: AnyObject) { - self.rootViewController?.restTimerStopped() + self.delegate?.restTimerShouldStop() } @IBAction func previousButtonClicked(_ sender: AnyObject) { - self.rootViewController?.previousButtonClicked(sender) + self.delegate?.selectPreviousExercise() } @IBAction func nextButtonClicked(_ sender: AnyObject) { - self.rootViewController?.nextButtonClicked(sender) + self.delegate?.selectNextExercise() } } diff --git a/BodyweightFitness/Workout/TimedViewController.swift b/BodyweightFitness/Workout/TimedViewController.swift index 431d53b..bc9e23d 100644 --- a/BodyweightFitness/Workout/TimedViewController.swift +++ b/BodyweightFitness/Workout/TimedViewController.swift @@ -9,6 +9,8 @@ class TimedViewController: UIViewController, AVAudioPlayerDelegate { @IBOutlet var previousButton: UIButton! @IBOutlet var nextButton: UIButton! + + var delegate: WorkoutInteractionDelegate? var rootViewController: WorkoutViewController? = nil var current: Exercise = RoutineStream.sharedInstance.routine.getFirstExercise() @@ -212,7 +214,7 @@ class TimedViewController: UIViewController, AVAudioPlayerDelegate { } func showRestTimer() { - self.rootViewController?.restTimerShouldStart() + self.delegate?.restTimerShouldStart() } func showNotification(_ seconds: Int) { @@ -266,10 +268,10 @@ class TimedViewController: UIViewController, AVAudioPlayerDelegate { @IBAction func previousButtonClicked(_ sender: AnyObject) { - self.rootViewController?.previousButtonClicked(sender) + self.delegate?.selectPreviousExercise() } @IBAction func nextButtonClicked(_ sender: AnyObject) { - self.rootViewController?.nextButtonClicked(sender) + self.delegate?.selectNextExercise() } } diff --git a/BodyweightFitness/Workout/WeightedViewController.swift b/BodyweightFitness/Workout/WeightedViewController.swift index 3d7b5a2..016c888 100644 --- a/BodyweightFitness/Workout/WeightedViewController.swift +++ b/BodyweightFitness/Workout/WeightedViewController.swift @@ -7,7 +7,9 @@ class WeightedViewController: UIViewController { @IBOutlet var sets: UILabel! @IBOutlet var reps: UIButton! - + + var delegate: WorkoutInteractionDelegate? + var numberOfReps: Int = 5 var rootViewController: WorkoutViewController? = nil var current: Exercise = RoutineStream.sharedInstance.routine.getFirstExercise() @@ -66,7 +68,7 @@ class WeightedViewController: UIViewController { } func showRestTimer() { - self.rootViewController?.restTimerShouldStart() + self.delegate?.restTimerShouldStart() } func showNotification(_ set: Int, reps: Int) { @@ -127,11 +129,11 @@ class WeightedViewController: UIViewController { } @IBAction func previousButtonClicked(_ sender: AnyObject) { - self.rootViewController?.previousButtonClicked(sender) + self.delegate?.selectPreviousExercise() } @IBAction func nextButtonClicked(_ sender: AnyObject) { - self.rootViewController?.nextButtonClicked(sender) + self.delegate?.selectNextExercise() } @IBAction func increaseRepsClicked(_ sender: AnyObject) { diff --git a/BodyweightFitness/Workout/WorkoutViewController.swift b/BodyweightFitness/Workout/WorkoutViewController.swift index bce7467..cb540d7 100644 --- a/BodyweightFitness/Workout/WorkoutViewController.swift +++ b/BodyweightFitness/Workout/WorkoutViewController.swift @@ -1,9 +1,16 @@ import UIKit import AVFoundation +protocol WorkoutInteractionDelegate { + func selectPreviousExercise() + func selectNextExercise() + func restTimerShouldStart() + func restTimerShouldStop() +} + class WorkoutNavigationController: UINavigationController {} -class WorkoutViewController: UIViewController { +class WorkoutViewController: UIViewController, WorkoutInteractionDelegate { @IBOutlet var actionButton: UIButton! @IBOutlet var topView: UIView! @@ -25,10 +32,13 @@ class WorkoutViewController: UIViewController { super.viewDidLoad() _ = try? AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryAmbient) - - self.restTimerViewController.rootViewController = self + self.timedViewController.rootViewController = self self.weightedViewController.rootViewController = self + + self.weightedViewController.delegate = self + self.timedViewController.delegate = self + self.weightedViewController.delegate = self self.restTimerViewController.view.frame = self.topView.frame self.restTimerViewController.willMove(toParentViewController: self) @@ -131,34 +141,6 @@ class WorkoutViewController: UIViewController { self.navigationController?.present(logWorkoutController, animated: true, completion: nil) } - func restTimerShouldStart() { - if userDefaults.showRestTimer() { - let routineId = RoutineStream.sharedInstance.routine.routineId - - if let section = current.section { - if (section.sectionId == "section0") { - if userDefaults.showRestTimerAfterWarmup() { - showRestTimer() - } - } else if (section.sectionId == "section1") { - if userDefaults.showRestTimerAfterBodylineDrills() { - showRestTimer() - } - } else { - if (routineId != "routine0") { - if userDefaults.showRestTimerAfterFlexibilityExercises() { - showRestTimer() - } - } else { - showRestTimer() - } - } - } else { - showRestTimer() - } - } - } - fileprivate func showRestTimer() { self.restTimerViewController.startTimer() self.restTimerViewController.view.isHidden = false @@ -166,20 +148,7 @@ class WorkoutViewController: UIViewController { self.timedViewController.view.isHidden = true self.weightedViewController.view.isHidden = true } - - func restTimerStopped() { - self.restTimerViewController.stopTimer() - self.restTimerViewController.view.isHidden = true - - if current.isTimed() { - self.timedViewController.view.isHidden = false - self.weightedViewController.view.isHidden = true - } else { - self.timedViewController.view.isHidden = true - self.weightedViewController.view.isHidden = false - } - } - + internal func changeExercise(_ currentExercise: Exercise, updateTitle: Bool = true) { self.current = currentExercise @@ -371,15 +340,58 @@ class WorkoutViewController: UIViewController { self.present(alertController, animated: true, completion: nil) } - @IBAction func previousButtonClicked(_ sender: AnyObject) { + // MARK: - WorkoutInteractionDelegate + + func selectPreviousExercise() { if let previous = self.current.previous { changeExercise(previous) } } - - @IBAction func nextButtonClicked(_ sender: AnyObject) { + + func selectNextExercise() { if let next = self.current.next { changeExercise(next) } } + + func restTimerShouldStart() { + if userDefaults.showRestTimer() { + let routineId = RoutineStream.sharedInstance.routine.routineId + + if let section = current.section { + if (section.sectionId == "section0") { + if userDefaults.showRestTimerAfterWarmup() { + showRestTimer() + } + } else if (section.sectionId == "section1") { + if userDefaults.showRestTimerAfterBodylineDrills() { + showRestTimer() + } + } else { + if (routineId != "routine0") { + if userDefaults.showRestTimerAfterFlexibilityExercises() { + showRestTimer() + } + } else { + showRestTimer() + } + } + } else { + showRestTimer() + } + } + } + + func restTimerShouldStop() { + self.restTimerViewController.stopTimer() + self.restTimerViewController.view.isHidden = true + + if current.isTimed() { + self.timedViewController.view.isHidden = false + self.weightedViewController.view.isHidden = true + } else { + self.timedViewController.view.isHidden = true + self.weightedViewController.view.isHidden = false + } + } } From ea4ec8356aa5f44ec6131f02a10b94192e37d362 Mon Sep 17 00:00:00 2001 From: Marius Ursache Date: Sat, 6 Jan 2018 14:01:01 +1100 Subject: [PATCH 22/28] Extract logReps as separate function --- .../Workout/WeightedViewController.swift | 77 +++++++++++-------- 1 file changed, 44 insertions(+), 33 deletions(-) diff --git a/BodyweightFitness/Workout/WeightedViewController.swift b/BodyweightFitness/Workout/WeightedViewController.swift index 016c888..ef89425 100644 --- a/BodyweightFitness/Workout/WeightedViewController.swift +++ b/BodyweightFitness/Workout/WeightedViewController.swift @@ -154,42 +154,53 @@ class WeightedViewController: UIViewController { @IBAction func logReps(_ sender: AnyObject) { if let current = self.rootViewController?.current { - if (self.numberOfReps >= 1 && self.numberOfReps <= 25 && !current.isTimed()) { - let realm = RepositoryStream.sharedInstance.getRealm() - let repositoryRoutine = RepositoryStream.sharedInstance.getRepositoryRoutineForToday() - - if let repositoryExercise = repositoryRoutine.exercises.filter({ - $0.exerciseId == current.exerciseId - }).first { - let sets = repositoryExercise.sets - - try! realm.write { - if (sets.count == 1 && sets[0].reps == 0) { - sets[0].reps = self.numberOfReps - - self.showNotification(1, reps: self.numberOfReps) - self.showRestTimer() - } else if (sets.count >= 1 && sets.count < 9) { - let repositorySet = RepositorySet() - - repositorySet.exercise = repositoryExercise - repositorySet.isTimed = false - repositorySet.reps = self.numberOfReps - - sets.append(repositorySet) - - repositoryRoutine.lastUpdatedTime = Date() - } - - realm.add(repositoryRoutine, update: true) - - self.showNotification(sets.count, reps: self.numberOfReps) - self.showRestTimer() - } + self.logReps(exercise: current) + } + } - RoutineStream.sharedInstance.setRepository() + func logReps(exercise: Exercise) { + if (exercise.isTimed()) { + return + } + + let numberOfRepsIsValid = self.numberOfReps >= 1 && self.numberOfReps <= 25 + if (!numberOfRepsIsValid) { + return + } + + let realm = RepositoryStream.sharedInstance.getRealm() + let repositoryRoutine = RepositoryStream.sharedInstance.getRepositoryRoutineForToday() + + if let repositoryExercise = repositoryRoutine.exercises.filter({ + $0.exerciseId == exercise.exerciseId + }).first { + let sets = repositoryExercise.sets + + try! realm.write { + if (sets.count == 1 && sets[0].reps == 0) { + sets[0].reps = self.numberOfReps + + self.showNotification(1, reps: self.numberOfReps) + self.showRestTimer() + } else if (sets.count >= 1 && sets.count < 9) { + let repositorySet = RepositorySet() + + repositorySet.exercise = repositoryExercise + repositorySet.isTimed = false + repositorySet.reps = self.numberOfReps + + sets.append(repositorySet) + + repositoryRoutine.lastUpdatedTime = Date() } + + realm.add(repositoryRoutine, update: true) + + self.showNotification(sets.count, reps: self.numberOfReps) + self.showRestTimer() } + + RoutineStream.sharedInstance.setRepository() } } } From 6e01db15acbd9fc1a2f8f574bdf268d6c144e62c Mon Sep 17 00:00:00 2001 From: Marius Ursache Date: Sat, 6 Jan 2018 14:05:01 +1100 Subject: [PATCH 23/28] Refactor printSets to use exercise as param --- BodyweightFitness/Workout/WeightedViewController.swift | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/BodyweightFitness/Workout/WeightedViewController.swift b/BodyweightFitness/Workout/WeightedViewController.swift index ef89425..49bd453 100644 --- a/BodyweightFitness/Workout/WeightedViewController.swift +++ b/BodyweightFitness/Workout/WeightedViewController.swift @@ -28,7 +28,7 @@ class WeightedViewController: UIViewController { self.updateLabels() _ = RoutineStream.sharedInstance.repositoryObservable().subscribe(onNext: { (it) in - self.sets.text = self.printSets() + self.sets.text = self.printSets(exercise: self.rootViewController?.current) }) } @@ -55,7 +55,7 @@ class WeightedViewController: UIViewController { func updateLabels() { PersistenceManager.storeNumberOfReps(current.exerciseId, numberOfReps: self.numberOfReps) - self.sets.text = self.printSets() + self.sets.text = self.printSets(exercise: self.rootViewController?.current) self.reps.setTitle(printValue(self.numberOfReps), for: UIControlState()) } @@ -87,18 +87,18 @@ class WeightedViewController: UIViewController { self.updateLabels() } - func printSets() -> String { + func printSets(exercise: Exercise?) -> String { var numberOfSets = 0 var isEmpty = false let asString = NSMutableString() - if let current = self.rootViewController?.current { + if let exercise = exercise { if (RepositoryStream.sharedInstance.repositoryRoutineForTodayExists()) { let repositoryRoutine = RepositoryStream.sharedInstance.getRepositoryRoutineForToday() if let repositoryExercise = repositoryRoutine.exercises.filter({ - $0.exerciseId == current.exerciseId + $0.exerciseId == exercise.exerciseId }).first { for set in repositoryExercise.sets { if (repositoryExercise.sets.count == 1 && set.reps == 0) { From d7bb4e35a775d6107fe3e5ed066d1b7fa9c8a46a Mon Sep 17 00:00:00 2001 From: Marius Ursache Date: Sat, 6 Jan 2018 17:02:33 +1100 Subject: [PATCH 24/28] Extract update number of reps --- BodyweightFitness/Workout/WeightedViewController.swift | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/BodyweightFitness/Workout/WeightedViewController.swift b/BodyweightFitness/Workout/WeightedViewController.swift index 49bd453..c323bf9 100644 --- a/BodyweightFitness/Workout/WeightedViewController.swift +++ b/BodyweightFitness/Workout/WeightedViewController.swift @@ -53,11 +53,15 @@ class WeightedViewController: UIViewController { } func updateLabels() { - PersistenceManager.storeNumberOfReps(current.exerciseId, numberOfReps: self.numberOfReps) + self.update(numberOfReps: self.numberOfReps, for: self.current) self.sets.text = self.printSets(exercise: self.rootViewController?.current) self.reps.setTitle(printValue(self.numberOfReps), for: UIControlState()) } + + func update(numberOfReps: Int, for exercise: Exercise) { + PersistenceManager.storeNumberOfReps(exercise.exerciseId, numberOfReps: numberOfReps) + } func printValue(_ value: Int) -> String { if(value > 9) { From 73062edbf3e3504b48d4dfb6d2d465e06a00e7b1 Mon Sep 17 00:00:00 2001 From: Marius Ursache Date: Sat, 6 Jan 2018 17:40:51 +1100 Subject: [PATCH 25/28] Revert "Extract update number of reps" This reverts commit d7bb4e35a775d6107fe3e5ed066d1b7fa9c8a46a. --- BodyweightFitness/Workout/WeightedViewController.swift | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/BodyweightFitness/Workout/WeightedViewController.swift b/BodyweightFitness/Workout/WeightedViewController.swift index c323bf9..49bd453 100644 --- a/BodyweightFitness/Workout/WeightedViewController.swift +++ b/BodyweightFitness/Workout/WeightedViewController.swift @@ -53,15 +53,11 @@ class WeightedViewController: UIViewController { } func updateLabels() { - self.update(numberOfReps: self.numberOfReps, for: self.current) + PersistenceManager.storeNumberOfReps(current.exerciseId, numberOfReps: self.numberOfReps) self.sets.text = self.printSets(exercise: self.rootViewController?.current) self.reps.setTitle(printValue(self.numberOfReps), for: UIControlState()) } - - func update(numberOfReps: Int, for exercise: Exercise) { - PersistenceManager.storeNumberOfReps(exercise.exerciseId, numberOfReps: numberOfReps) - } func printValue(_ value: Int) -> String { if(value > 9) { From 9371939edc7001df6f88258cbf55f66205504fec Mon Sep 17 00:00:00 2001 From: Marius Ursache Date: Sat, 6 Jan 2018 17:40:55 +1100 Subject: [PATCH 26/28] Revert "Refactor printSets to use exercise as param" This reverts commit 6e01db15acbd9fc1a2f8f574bdf268d6c144e62c. --- BodyweightFitness/Workout/WeightedViewController.swift | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/BodyweightFitness/Workout/WeightedViewController.swift b/BodyweightFitness/Workout/WeightedViewController.swift index 49bd453..ef89425 100644 --- a/BodyweightFitness/Workout/WeightedViewController.swift +++ b/BodyweightFitness/Workout/WeightedViewController.swift @@ -28,7 +28,7 @@ class WeightedViewController: UIViewController { self.updateLabels() _ = RoutineStream.sharedInstance.repositoryObservable().subscribe(onNext: { (it) in - self.sets.text = self.printSets(exercise: self.rootViewController?.current) + self.sets.text = self.printSets() }) } @@ -55,7 +55,7 @@ class WeightedViewController: UIViewController { func updateLabels() { PersistenceManager.storeNumberOfReps(current.exerciseId, numberOfReps: self.numberOfReps) - self.sets.text = self.printSets(exercise: self.rootViewController?.current) + self.sets.text = self.printSets() self.reps.setTitle(printValue(self.numberOfReps), for: UIControlState()) } @@ -87,18 +87,18 @@ class WeightedViewController: UIViewController { self.updateLabels() } - func printSets(exercise: Exercise?) -> String { + func printSets() -> String { var numberOfSets = 0 var isEmpty = false let asString = NSMutableString() - if let exercise = exercise { + if let current = self.rootViewController?.current { if (RepositoryStream.sharedInstance.repositoryRoutineForTodayExists()) { let repositoryRoutine = RepositoryStream.sharedInstance.getRepositoryRoutineForToday() if let repositoryExercise = repositoryRoutine.exercises.filter({ - $0.exerciseId == exercise.exerciseId + $0.exerciseId == current.exerciseId }).first { for set in repositoryExercise.sets { if (repositoryExercise.sets.count == 1 && set.reps == 0) { From 2c7562a4dd794acc8d6b252e58c10ace3e77ad1f Mon Sep 17 00:00:00 2001 From: Marius Ursache Date: Sat, 6 Jan 2018 17:41:00 +1100 Subject: [PATCH 27/28] Revert "Extract logReps as separate function" This reverts commit ea4ec8356aa5f44ec6131f02a10b94192e37d362. --- .../Workout/WeightedViewController.swift | 77 ++++++++----------- 1 file changed, 33 insertions(+), 44 deletions(-) diff --git a/BodyweightFitness/Workout/WeightedViewController.swift b/BodyweightFitness/Workout/WeightedViewController.swift index ef89425..016c888 100644 --- a/BodyweightFitness/Workout/WeightedViewController.swift +++ b/BodyweightFitness/Workout/WeightedViewController.swift @@ -154,53 +154,42 @@ class WeightedViewController: UIViewController { @IBAction func logReps(_ sender: AnyObject) { if let current = self.rootViewController?.current { - self.logReps(exercise: current) - } - } - - func logReps(exercise: Exercise) { - if (exercise.isTimed()) { - return - } - - let numberOfRepsIsValid = self.numberOfReps >= 1 && self.numberOfReps <= 25 - if (!numberOfRepsIsValid) { - return - } - - let realm = RepositoryStream.sharedInstance.getRealm() - let repositoryRoutine = RepositoryStream.sharedInstance.getRepositoryRoutineForToday() - - if let repositoryExercise = repositoryRoutine.exercises.filter({ - $0.exerciseId == exercise.exerciseId - }).first { - let sets = repositoryExercise.sets - - try! realm.write { - if (sets.count == 1 && sets[0].reps == 0) { - sets[0].reps = self.numberOfReps - - self.showNotification(1, reps: self.numberOfReps) - self.showRestTimer() - } else if (sets.count >= 1 && sets.count < 9) { - let repositorySet = RepositorySet() - - repositorySet.exercise = repositoryExercise - repositorySet.isTimed = false - repositorySet.reps = self.numberOfReps - - sets.append(repositorySet) + if (self.numberOfReps >= 1 && self.numberOfReps <= 25 && !current.isTimed()) { + let realm = RepositoryStream.sharedInstance.getRealm() + let repositoryRoutine = RepositoryStream.sharedInstance.getRepositoryRoutineForToday() + + if let repositoryExercise = repositoryRoutine.exercises.filter({ + $0.exerciseId == current.exerciseId + }).first { + let sets = repositoryExercise.sets + + try! realm.write { + if (sets.count == 1 && sets[0].reps == 0) { + sets[0].reps = self.numberOfReps + + self.showNotification(1, reps: self.numberOfReps) + self.showRestTimer() + } else if (sets.count >= 1 && sets.count < 9) { + let repositorySet = RepositorySet() + + repositorySet.exercise = repositoryExercise + repositorySet.isTimed = false + repositorySet.reps = self.numberOfReps + + sets.append(repositorySet) + + repositoryRoutine.lastUpdatedTime = Date() + } + + realm.add(repositoryRoutine, update: true) + + self.showNotification(sets.count, reps: self.numberOfReps) + self.showRestTimer() + } - repositoryRoutine.lastUpdatedTime = Date() + RoutineStream.sharedInstance.setRepository() } - - realm.add(repositoryRoutine, update: true) - - self.showNotification(sets.count, reps: self.numberOfReps) - self.showRestTimer() } - - RoutineStream.sharedInstance.setRepository() } } } From 03c4e6c65c14b55bfa8aa1c9b94a7b75c690dd87 Mon Sep 17 00:00:00 2001 From: Marius Ursache Date: Sat, 6 Jan 2018 17:43:49 +1100 Subject: [PATCH 28/28] Fixed Issue #26 Fixed First exercise reps change is not persisted #26 --- BodyweightFitness/Workout/WeightedViewController.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/BodyweightFitness/Workout/WeightedViewController.swift b/BodyweightFitness/Workout/WeightedViewController.swift index 016c888..b9c5092 100644 --- a/BodyweightFitness/Workout/WeightedViewController.swift +++ b/BodyweightFitness/Workout/WeightedViewController.swift @@ -24,7 +24,8 @@ class WeightedViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() - + + self.numberOfReps = PersistenceManager.getNumberOfReps(self.current.exerciseId) self.updateLabels() _ = RoutineStream.sharedInstance.repositoryObservable().subscribe(onNext: { (it) in