aboutsummaryrefslogtreecommitdiff
path: root/src/Model
diff options
context:
space:
mode:
authorJoris Guyonvarch2015-03-19 00:55:50 +0100
committerJoris Guyonvarch2015-03-19 01:00:22 +0100
commitaf9465f928f28344aa59a407adb21e5ac047a0f9 (patch)
tree903327b8b8053933b95e2766b115ee48ecce9ef8 /src/Model
parent7ca7887ae82c09270869ed6737f94a99e210665c (diff)
Adding a Ringing state that animate the color, does not ring a sound for the moment
Diffstat (limited to 'src/Model')
-rw-r--r--src/Model/Timer.elm27
-rw-r--r--src/Model/TimerState.elm8
2 files changed, 22 insertions, 13 deletions
diff --git a/src/Model/Timer.elm b/src/Model/Timer.elm
index 754a62a..b73016d 100644
--- a/src/Model/Timer.elm
+++ b/src/Model/Timer.elm
@@ -8,12 +8,14 @@ module Model.Timer
import List
import Time (Time)
+import Model.TimerState (..)
+
type alias Timer =
{ creationTime : Time
, name : String
, initialTime : Time
, currentTime : Time
- , isRunning : Bool
+ , state : TimerState
}
initialTimer : Time -> String -> Timer
@@ -23,23 +25,22 @@ initialTimer creationTime name =
, name = name
, initialTime = initialTime
, currentTime = initTime initialTime
- , isRunning = False
+ , state = Idle
}
substractTimerTime : Time -> Timer -> Timer
substractTimerTime time timer =
- if timer.isRunning
+ if timer.state == Running
then
- if timer.currentTime - time <= 0.0
- then
- { timer
- | currentTime <- 0.0
- , isRunning <- False
- }
- else
- { timer
- | currentTime <- timer.currentTime - time
- }
+ let newTime = timer.currentTime - time
+ in if newTime <= 0.0
+ then
+ { timer
+ | currentTime <- 0.0
+ , state <- Ringing
+ }
+ else
+ { timer | currentTime <- newTime }
else
timer
diff --git a/src/Model/TimerState.elm b/src/Model/TimerState.elm
new file mode 100644
index 0000000..dbbcb80
--- /dev/null
+++ b/src/Model/TimerState.elm
@@ -0,0 +1,8 @@
+module Model.TimerState
+ ( TimerState(..)
+ ) where
+
+type TimerState =
+ Idle
+ | Running
+ | Ringing