From 97c8967fb771472c4eb6335827edee02e58b6a90 Mon Sep 17 00:00:00 2001 From: Kristijan Perusko Date: Fri, 12 Feb 2016 13:52:05 -0500 Subject: [PATCH] #119 If an activity is skipped under 1 min, the time will be rounded to 1 min when updating activity --- .../ViewModels/RunningDesignStudio.swift | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/DesignStudioExpress/ViewModels/RunningDesignStudio.swift b/DesignStudioExpress/ViewModels/RunningDesignStudio.swift index e9d0642..7d66a15 100644 --- a/DesignStudioExpress/ViewModels/RunningDesignStudio.swift +++ b/DesignStudioExpress/ViewModels/RunningDesignStudio.swift @@ -319,13 +319,29 @@ class RunningDesignStudio: NSObject { self.moveToNextChallenge() } + private func moveToNextActivity() -> Bool { + self.updateCurrentActivity() + + let result = self.moveActivityPointer() + + if result { + self.updateDesignStudioActivityIdx() + } + + self.startCurrentActivity() + + return result + } // update the duration of the activity to the actual duration of the activity // and status of the activity (finished) private func updateCurrentActivity() { do { if let diff = self.currentActivityStart?.timeIntervalSinceNow { - let duration = Int(round(-diff / 60)) // convert seconds to minutes + var duration = Int(round(-diff / 60)) // convert seconds to minutes + if duration < 1 { + duration = 1 + } try realm.write { self.currentActivity?.duration = duration self.currentActivity?.finished = true @@ -336,20 +352,6 @@ class RunningDesignStudio: NSObject { } } - private func moveToNextActivity() -> Bool { - self.updateCurrentActivity() - - let result = self.moveActivityPointer() - - if result { - self.updateDesignStudioActivityIdx() - } - - self.startCurrentActivity() - - return result - } - private func moveActivityPointer() -> Bool { // move the pointer if let nextActivityIdx = self.getNextActivityIdx() {