Skip to content

Commit

Permalink
#119 If an activity is skipped under 1 min, the time will be rounded …
Browse files Browse the repository at this point in the history
…to 1 min when updating activity
  • Loading branch information
kperusko committed Feb 12, 2016
1 parent eaf86ef commit 97c8967
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions DesignStudioExpress/ViewModels/RunningDesignStudio.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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() {
Expand Down

0 comments on commit 97c8967

Please sign in to comment.