From cedd0a053e0ab6ecc18977827037bc5651f774e4 Mon Sep 17 00:00:00 2001 From: Tom Gruen Date: Sun, 5 Apr 2020 21:34:17 +0200 Subject: [PATCH 01/22] added developer_key.* to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 219983d..54f99c7 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ .settings *.swp +developer_key.* \ No newline at end of file From bd35f964dc04a79b88dd55ffdcf823c1a33d505b Mon Sep 17 00:00:00 2001 From: Tom Gruen Date: Sun, 5 Apr 2020 21:39:46 +0200 Subject: [PATCH 02/22] added new file Pomodoro.mc - created a module that will act as a namespace for all pomodoro related functionality --- source/Pomodoro.mc | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 source/Pomodoro.mc diff --git a/source/Pomodoro.mc b/source/Pomodoro.mc new file mode 100644 index 0000000..77be9e5 --- /dev/null +++ b/source/Pomodoro.mc @@ -0,0 +1,5 @@ +// encapsulates the core Pomodoro functionality + +module Pomodoro { +// TODO: move pomodoro code from other files here +} \ No newline at end of file From b14574f254375b795893a1d0496f1f166059feaa Mon Sep 17 00:00:00 2001 From: Tom Gruen Date: Sun, 5 Apr 2020 21:58:01 +0200 Subject: [PATCH 03/22] moved Pomodoro code from GarmodoroApp.mc to Pomodoro.mc --- source/GarmodoroApp.mc | 8 +++----- source/Pomodoro.mc | 18 +++++++++++++++++- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/source/GarmodoroApp.mc b/source/GarmodoroApp.mc index 4512b7c..474cbf2 100644 --- a/source/GarmodoroApp.mc +++ b/source/GarmodoroApp.mc @@ -1,20 +1,18 @@ using Toybox.Application as App; -using Toybox.Timer as Timer; +using Pomodoro; class GarmodoroApp extends App.AppBase { function initialize() { AppBase.initialize(); + Pomodoro.initialize(); } function onStart(state) { - timer = new Timer.Timer(); - tickTimer = new Timer.Timer(); } function onStop(state) { - tickTimer.stop(); - timer.stop(); + Pomodoro.stopTimers(); } function getInitialView() { diff --git a/source/Pomodoro.mc b/source/Pomodoro.mc index 77be9e5..44104f4 100644 --- a/source/Pomodoro.mc +++ b/source/Pomodoro.mc @@ -1,5 +1,21 @@ -// encapsulates the core Pomodoro functionality +// this file encapsulates the core Pomodoro functionality. +using Toybox.Timer as Timer; + +// TODO: move global variables concerning Pomodoro to here +// TODO: move Pomodoro global variables into module Pomodoro + +// acts a a singleton, hence no class module Pomodoro { // TODO: move pomodoro code from other files here + + function initialize() { + timer = new Timer.Timer(); + tickTimer = new Timer.Timer(); + } + + function stopTimers() { + tickTimer.stop(); + timer.stop(); + } } \ No newline at end of file From 07abde2f5de89d486ebbc9546962f9cebef3911e Mon Sep 17 00:00:00 2001 From: Tom Gruen Date: Sun, 5 Apr 2020 22:12:32 +0200 Subject: [PATCH 04/22] moved code from StopMenuDelgate.mc to Pomodoro.mc --- source/Pomodoro.mc | 14 ++++++++++++++ source/StopMenuDelegate.mc | 12 ++---------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/source/Pomodoro.mc b/source/Pomodoro.mc index 44104f4..34884dc 100644 --- a/source/Pomodoro.mc +++ b/source/Pomodoro.mc @@ -9,6 +9,7 @@ using Toybox.Timer as Timer; module Pomodoro { // TODO: move pomodoro code from other files here + // called when app is started for the first time function initialize() { timer = new Timer.Timer(); tickTimer = new Timer.Timer(); @@ -18,4 +19,17 @@ module Pomodoro { tickTimer.stop(); timer.stop(); } + + // called when "reset" action is selected in menu + function resetFromMenu() { + play( 9 ); // Attention.TONE_RESET + ping( 50, 1500 ); + + stopTimers(); + + resetMinutes(); + pomodoroNumber = 1; + isPomodoroTimerStarted = false; + isBreakTimerStarted = false; + } } \ No newline at end of file diff --git a/source/StopMenuDelegate.mc b/source/StopMenuDelegate.mc index c07936d..e9dbc6e 100644 --- a/source/StopMenuDelegate.mc +++ b/source/StopMenuDelegate.mc @@ -1,6 +1,7 @@ using Toybox.Attention as Attention; using Toybox.System as System; using Toybox.WatchUi as Ui; +using Pomodoro; class StopMenuDelegate extends Ui.MenuInputDelegate { function initialize() { @@ -9,16 +10,7 @@ class StopMenuDelegate extends Ui.MenuInputDelegate { function onMenuItem( item ) { if ( item == :restart ) { - play( 9 ); // Attention.TONE_RESET - ping( 50, 1500 ); - - tickTimer.stop(); - timer.stop(); - - resetMinutes(); - pomodoroNumber = 1; - isPomodoroTimerStarted = false; - isBreakTimerStarted = false; + Pomodoro.resetFromMenu(); Ui.requestUpdate(); } else if ( item == :exit ) { From a4f72fbf543353249f2787304447506bfbd67001 Mon Sep 17 00:00:00 2001 From: Tom Gruen Date: Sun, 5 Apr 2020 22:46:30 +0200 Subject: [PATCH 05/22] moved code from GarmodoroView.mc to Pomodoro.mc --- source/GarmodoroView.mc | 30 ++++++++++++++++++++---------- source/Pomodoro.mc | 25 ++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 11 deletions(-) diff --git a/source/GarmodoroView.mc b/source/GarmodoroView.mc index 72454c9..877744c 100644 --- a/source/GarmodoroView.mc +++ b/source/GarmodoroView.mc @@ -4,6 +4,7 @@ using Toybox.System as System; using Toybox.Time; using Toybox.Time.Gregorian; using Toybox.Lang; +using Pomodoro; class GarmodoroView extends Ui.View { hidden var pomodoroSubtitle; @@ -56,38 +57,47 @@ class GarmodoroView extends Ui.View { function onUpdate( dc ) { dc.setColor( Gfx.COLOR_TRANSPARENT, Gfx.COLOR_BLACK ); dc.clear(); - if ( isBreakTimerStarted ) { + if ( Pomodoro.isInBreakState() ) { + var labelForBreak = Pomodoro.isLongBreak2() ? + me.longBreakLabel : + me.shortBreakLabel; dc.setColor( Gfx.COLOR_GREEN, Gfx.COLOR_TRANSPARENT ); - dc.drawText( me.centerX, me.pomodoroOffset, Gfx.FONT_MEDIUM, isLongBreak() ? me.longBreakLabel : me.shortBreakLabel, Gfx.TEXT_JUSTIFY_CENTER ); + dc.drawText( me.centerX, me.pomodoroOffset, Gfx.FONT_MEDIUM, + labelForBreak, Gfx.TEXT_JUSTIFY_CENTER ); me.drawMinutes( dc ); dc.setColor( Gfx.COLOR_DK_GREEN, Gfx.COLOR_TRANSPARENT ); me.drawCaption( dc ); - } else if ( isPomodoroTimerStarted ) { + } else if ( Pomodoro.isInRunningState() ) { dc.setColor( Gfx.COLOR_YELLOW, Gfx.COLOR_TRANSPARENT ); me.drawMinutes( dc ); dc.setColor( Gfx.COLOR_ORANGE, Gfx.COLOR_TRANSPARENT ); me.drawCaption( dc ); - } else { + } else { // Pomodoro is in ready state dc.setColor( Gfx.COLOR_ORANGE, Gfx.COLOR_TRANSPARENT ); - dc.drawText( me.centerX, me.readyLabelOffset, Gfx.FONT_LARGE, me.readyLabel, Gfx.TEXT_JUSTIFY_CENTER ); + dc.drawText( me.centerX, me.readyLabelOffset, Gfx.FONT_LARGE, + me.readyLabel, Gfx.TEXT_JUSTIFY_CENTER ); } - if ( ! isBreakTimerStarted ) { + if ( ! Pomodoro.isInBreakState() ) { dc.setColor( Gfx.COLOR_LT_GRAY, Gfx.COLOR_TRANSPARENT ); - dc.drawText( me.centerX, me.pomodoroOffset, Gfx.FONT_MEDIUM, "Pomodoro #" + pomodoroNumber, Gfx.TEXT_JUSTIFY_CENTER ); + dc.drawText( me.centerX, me.pomodoroOffset, Gfx.FONT_MEDIUM, "Pomodoro #" + + Pomodoro.getIteration(), Gfx.TEXT_JUSTIFY_CENTER ); } dc.setColor( Gfx.COLOR_LT_GRAY, Gfx.COLOR_TRANSPARENT ); - dc.drawText( self.centerX, self.timeOffset, Gfx.FONT_NUMBER_MILD, self.getTime(), Gfx.TEXT_JUSTIFY_CENTER ); + dc.drawText( self.centerX, self.timeOffset, Gfx.FONT_NUMBER_MILD, + self.getTime(), Gfx.TEXT_JUSTIFY_CENTER ); } hidden function drawMinutes( dc ) { - dc.drawText( me.centerX, me.minutesOffset, Gfx.FONT_NUMBER_THAI_HOT, minutes.format( "%02d" ), Gfx.TEXT_JUSTIFY_CENTER ); + dc.drawText( me.centerX, me.minutesOffset, Gfx.FONT_NUMBER_THAI_HOT, + Pomodoro.getMinutesLeft().format( "%02d" ), Gfx.TEXT_JUSTIFY_CENTER ); } hidden function drawCaption( dc ) { - dc.drawText( me.centerX, me.captionOffset, Gfx.FONT_TINY, me.pomodoroSubtitle, Gfx.TEXT_JUSTIFY_CENTER ); + dc.drawText( me.centerX, me.captionOffset, Gfx.FONT_TINY, + me.pomodoroSubtitle, Gfx.TEXT_JUSTIFY_CENTER ); } function onHide() { diff --git a/source/Pomodoro.mc b/source/Pomodoro.mc index 34884dc..36036bf 100644 --- a/source/Pomodoro.mc +++ b/source/Pomodoro.mc @@ -32,4 +32,27 @@ module Pomodoro { isPomodoroTimerStarted = false; isBreakTimerStarted = false; } -} \ No newline at end of file + + // for displaying + function getMinutesLeft() { + return minutes; + } + + // for displaying + function getIteration() { + return pomodoroNumber; + } + + function isInBreakState() { + return isBreakTimerStarted; + } + + function isInRunningState() { + return isPomodoroTimerStarted; + } + + // TODO: inline isLongBreak() and rename + function isLongBreak2() { + return isLongBreak(); + } +} From 2a03501d9dc9213e44c8fe932a0031643724d9f4 Mon Sep 17 00:00:00 2001 From: Tom Gruen Date: Sun, 5 Apr 2020 22:52:39 +0200 Subject: [PATCH 06/22] moved globals from GarmodoroDelegate.mc to Pomodoro.mc --- source/GarmodoroDelegate.mc | 28 ---------------------------- source/Pomodoro.mc | 31 ++++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 29 deletions(-) diff --git a/source/GarmodoroDelegate.mc b/source/GarmodoroDelegate.mc index f0d4af4..976d4e2 100644 --- a/source/GarmodoroDelegate.mc +++ b/source/GarmodoroDelegate.mc @@ -1,34 +1,6 @@ using Toybox.Application as App; -using Toybox.Attention as Attention; using Toybox.WatchUi as Ui; -var timer; -var tickTimer; -var minutes = 0; -var pomodoroNumber = 1; -var isPomodoroTimerStarted = false; -var isBreakTimerStarted = false; - -function ping( dutyCycle, length ) { - if ( Attention has :vibrate ) { - Attention.vibrate( [ new Attention.VibeProfile( dutyCycle, length ) ] ); - } -} - -function play( tone ) { - if ( Attention has :playTone && ! App.getApp().getProperty( "muteSounds" ) ) { - Attention.playTone( tone ); - } -} - -function isLongBreak() { - return ( pomodoroNumber % App.getApp().getProperty( "numberOfPomodorosBeforeLongBreak" ) ) == 0; -} - -function resetMinutes() { - minutes = App.getApp().getProperty( "pomodoroLength" ); -} - class GarmodoroDelegate extends Ui.BehaviorDelegate { function initialize() { Ui.BehaviorDelegate.initialize(); diff --git a/source/Pomodoro.mc b/source/Pomodoro.mc index 36036bf..8bd5c5f 100644 --- a/source/Pomodoro.mc +++ b/source/Pomodoro.mc @@ -1,9 +1,38 @@ // this file encapsulates the core Pomodoro functionality. +using Toybox.Application as App; +using Toybox.Attention as Attention; using Toybox.Timer as Timer; -// TODO: move global variables concerning Pomodoro to here +// global variables and functions // TODO: move Pomodoro global variables into module Pomodoro +var timer; +var tickTimer; +var minutes = 0; +var pomodoroNumber = 1; +var isPomodoroTimerStarted = false; +var isBreakTimerStarted = false; + +function ping( dutyCycle, length ) { + if ( Attention has :vibrate ) { + Attention.vibrate( [ new Attention.VibeProfile( dutyCycle, length ) ] ); + } +} + +function play( tone ) { + if ( Attention has :playTone && ! App.getApp().getProperty( "muteSounds" ) ) { + Attention.playTone( tone ); + } +} + +function isLongBreak() { + return ( pomodoroNumber % App.getApp().getProperty( "numberOfPomodorosBeforeLongBreak" ) ) == 0; +} + +function resetMinutes() { + minutes = App.getApp().getProperty( "pomodoroLength" ); +} + // acts a a singleton, hence no class module Pomodoro { From 07c542205edafcfa913bcfadc09f87b7a4600883 Mon Sep 17 00:00:00 2001 From: Tom Gruen Date: Sun, 5 Apr 2020 23:16:35 +0200 Subject: [PATCH 07/22] moved shouldTick() to globals and added plan for next refactorings in TODOs --- source/GarmodoroDelegate.mc | 16 +++++++++------- source/Pomodoro.mc | 3 +++ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/source/GarmodoroDelegate.mc b/source/GarmodoroDelegate.mc index 976d4e2..e4253d4 100644 --- a/source/GarmodoroDelegate.mc +++ b/source/GarmodoroDelegate.mc @@ -6,6 +6,7 @@ class GarmodoroDelegate extends Ui.BehaviorDelegate { Ui.BehaviorDelegate.initialize(); } + // TODO move to Pomodoro.countdownRunningMinutes() function pomodoroCallback() { minutes -= 1; @@ -24,6 +25,8 @@ class GarmodoroDelegate extends Ui.BehaviorDelegate { Ui.requestUpdate(); } + // TODO move to Pomodoro.countdownBreakMinutes() + // TODO merge this with Pomodoro.countdownRunningMinutes() function breakCallback() { minutes -= 1; @@ -40,10 +43,7 @@ class GarmodoroDelegate extends Ui.BehaviorDelegate { Ui.requestUpdate(); } - function shouldTick() { - return App.getApp().getProperty( "tickStrength" ) > 0; - } - + // TODO: move to Pomodoro.makeTickingSound() function tickCallback() { ping( App.getApp().getProperty( "tickStrength" ), App.getApp().getProperty( "tickDuration" ) ); } @@ -65,19 +65,21 @@ class GarmodoroDelegate extends Ui.BehaviorDelegate { if ( isBreakTimerStarted || isPomodoroTimerStarted ) { Ui.pushView( new Rez.Menus.StopMenu(), new StopMenuDelegate(), Ui.SLIDE_UP ); return true; - } + } // else: we are in ready state + // TODO: extract to Pomodoro.beginPomodoro() play( 1 ); // Attention.TONE_START ping( 75, 1500 ); resetMinutes(); timer.start( method( :pomodoroCallback ), 60 * 1000, true ); + isPomodoroTimerStarted = true; + + // TODO: extract to Pomodoro.beginTicking() if ( me.shouldTick() ) { tickTimer.start( method( :tickCallback ), 1000, true ); } - isPomodoroTimerStarted = true; Ui.requestUpdate(); - return true; } } diff --git a/source/Pomodoro.mc b/source/Pomodoro.mc index 8bd5c5f..3481f5a 100644 --- a/source/Pomodoro.mc +++ b/source/Pomodoro.mc @@ -33,6 +33,9 @@ function resetMinutes() { minutes = App.getApp().getProperty( "pomodoroLength" ); } +function shouldTick() { + return App.getApp().getProperty( "tickStrength" ) > 0; +} // acts a a singleton, hence no class module Pomodoro { From 2b322e31a5968c1b49fc19437690592862b4bb9c Mon Sep 17 00:00:00 2001 From: Tom Gruen Date: Mon, 6 Apr 2020 22:35:32 +0200 Subject: [PATCH 08/22] moved code from GarmodoroDelegate.mc to Pomodoro.mc --- source/GarmodoroDelegate.mc | 58 +++--------------------------- source/Pomodoro.mc | 72 +++++++++++++++++++++++++++++++++++-- 2 files changed, 74 insertions(+), 56 deletions(-) diff --git a/source/GarmodoroDelegate.mc b/source/GarmodoroDelegate.mc index e4253d4..d2e190f 100644 --- a/source/GarmodoroDelegate.mc +++ b/source/GarmodoroDelegate.mc @@ -1,53 +1,12 @@ using Toybox.Application as App; using Toybox.WatchUi as Ui; +using Pomodoro; class GarmodoroDelegate extends Ui.BehaviorDelegate { function initialize() { Ui.BehaviorDelegate.initialize(); } - // TODO move to Pomodoro.countdownRunningMinutes() - function pomodoroCallback() { - minutes -= 1; - - if ( minutes == 0 ) { - play( 10 ); // Attention.TONE_LAP - ping( 100, 1500 ); - tickTimer.stop(); - timer.stop(); - isPomodoroTimerStarted = false; - minutes = App.getApp().getProperty( isLongBreak() ? "longBreakLength" : "shortBreakLength" ); - - timer.start( method( :breakCallback ), 60 * 1000, true ); - isBreakTimerStarted = true; - } - - Ui.requestUpdate(); - } - - // TODO move to Pomodoro.countdownBreakMinutes() - // TODO merge this with Pomodoro.countdownRunningMinutes() - function breakCallback() { - minutes -= 1; - - if ( minutes == 0 ) { - play( 7 ); // Attention.TONE_INTERVAL_ALERT - ping( 100, 1500 ); - timer.stop(); - - isBreakTimerStarted = false; - pomodoroNumber += 1; - resetMinutes(); - } - - Ui.requestUpdate(); - } - - // TODO: move to Pomodoro.makeTickingSound() - function tickCallback() { - ping( App.getApp().getProperty( "tickStrength" ), App.getApp().getProperty( "tickDuration" ) ); - } - function onBack() { Ui.popView( Ui.SLIDE_RIGHT ); return true; @@ -63,21 +22,12 @@ class GarmodoroDelegate extends Ui.BehaviorDelegate { function onSelect() { if ( isBreakTimerStarted || isPomodoroTimerStarted ) { - Ui.pushView( new Rez.Menus.StopMenu(), new StopMenuDelegate(), Ui.SLIDE_UP ); + Ui.pushView( new Rez.Menus.StopMenu(), + new StopMenuDelegate(), Ui.SLIDE_UP ); return true; } // else: we are in ready state - // TODO: extract to Pomodoro.beginPomodoro() - play( 1 ); // Attention.TONE_START - ping( 75, 1500 ); - resetMinutes(); - timer.start( method( :pomodoroCallback ), 60 * 1000, true ); - isPomodoroTimerStarted = true; - - // TODO: extract to Pomodoro.beginTicking() - if ( me.shouldTick() ) { - tickTimer.start( method( :tickCallback ), 1000, true ); - } + Pomodoro.beginPomodoro(); Ui.requestUpdate(); return true; diff --git a/source/Pomodoro.mc b/source/Pomodoro.mc index 3481f5a..f6ed94a 100644 --- a/source/Pomodoro.mc +++ b/source/Pomodoro.mc @@ -1,8 +1,10 @@ // this file encapsulates the core Pomodoro functionality. using Toybox.Application as App; +using Toybox.WatchUi as Ui; using Toybox.Attention as Attention; using Toybox.Timer as Timer; +using Toybox.Lang as Lang; // global variables and functions // TODO: move Pomodoro global variables into module Pomodoro @@ -39,8 +41,6 @@ function shouldTick() { // acts a a singleton, hence no class module Pomodoro { -// TODO: move pomodoro code from other files here - // called when app is started for the first time function initialize() { timer = new Timer.Timer(); @@ -87,4 +87,72 @@ module Pomodoro { function isLongBreak2() { return isLongBreak(); } + + function countdownMinutesInRunning() { + minutes -= 1; + + if ( minutes == 0 ) { + // TODO extract to beginBreak() + play( 10 ); // Attention.TONE_LAP + ping( 100, 1500 ); + tickTimer.stop(); + timer.stop(); + isPomodoroTimerStarted = false; + minutes = App.getApp().getProperty( isLongBreak() ? + "longBreakLength" : + "shortBreakLength" ); + var breakTimerRoutine = + new Lang.Method(Pomodoro, :countdownMinutesInBreak); + timer.start( breakTimerRoutine, 60 * 1000, true ); + isBreakTimerStarted = true; + } + + Ui.requestUpdate(); + } + + // TODO merge this with Pomodoro.countdownMinutesInRunning() + function countdownMinutesInBreak() { + minutes -= 1; + + if ( minutes == 0 ) { + // TODO: extract to beginReadyState() + play( 7 ); // Attention.TONE_INTERVAL_ALERT + ping( 100, 1500 ); + timer.stop(); + + isBreakTimerStarted = false; + pomodoroNumber += 1; + resetMinutes(); + } + + Ui.requestUpdate(); + } + + function makeTickingSound() { + var strength = App.getApp().getProperty( "tickStrength" ); + var duration = App.getApp().getProperty( "tickDuration" ); + ping( strength, duration ); + } + + // start ticking once a second, if enabled + function beginTicking() { + if ( shouldTick() ) { + var tickTimerRoutine = + new Lang.Method(Pomodoro, :makeTickingSound); + tickTimer.start( tickTimerRoutine, 1000, true ); + } + } + + // begin pomodoro countdown + function beginPomodoro() { + play( 1 ); // Attention.TONE_START + ping( 75, 1500 ); + resetMinutes(); + var pomodoroTimerRoutine = + new Lang.Method(Pomodoro, :countdownMinutesInRunning); + timer.start( pomodoroTimerRoutine, 60 * 1000, true ); + isPomodoroTimerStarted = true; + + beginTicking(); + } } From 32ebbed73bc116e7a3a6da5bd35c1f6059dd8baf Mon Sep 17 00:00:00 2001 From: Tom Gruen Date: Mon, 6 Apr 2020 22:56:07 +0200 Subject: [PATCH 09/22] cleaned up GarmodoroDelegate --- source/GarmodoroDelegate.mc | 26 +++++++++++++++----------- source/Pomodoro.mc | 5 +++++ 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/source/GarmodoroDelegate.mc b/source/GarmodoroDelegate.mc index d2e190f..e073eb4 100644 --- a/source/GarmodoroDelegate.mc +++ b/source/GarmodoroDelegate.mc @@ -12,6 +12,18 @@ class GarmodoroDelegate extends Ui.BehaviorDelegate { return true; } + function onSelect() { + if ( Pomodoro.isInReadyState() ) { + Pomodoro.beginPomodoro(); + Ui.requestUpdate(); + } else { // pomodoro is in running or break state + displayStopMenu(); + } + return true; + } + + // TODO: add onMenu() if supported on all watches + function onNextMode() { return true; } @@ -20,16 +32,8 @@ class GarmodoroDelegate extends Ui.BehaviorDelegate { return true; } - function onSelect() { - if ( isBreakTimerStarted || isPomodoroTimerStarted ) { - Ui.pushView( new Rez.Menus.StopMenu(), - new StopMenuDelegate(), Ui.SLIDE_UP ); - return true; - } // else: we are in ready state - - Pomodoro.beginPomodoro(); - - Ui.requestUpdate(); - return true; + function displayStopMenu() { + Ui.pushView( new Rez.Menus.StopMenu(), + new StopMenuDelegate(), Ui.SLIDE_UP ); } } diff --git a/source/Pomodoro.mc b/source/Pomodoro.mc index f6ed94a..08ee783 100644 --- a/source/Pomodoro.mc +++ b/source/Pomodoro.mc @@ -83,6 +83,11 @@ module Pomodoro { return isPomodoroTimerStarted; } + function isInReadyState() { + return ! isPomodoroTimerStarted && + ! isBreakTimerStarted; + } + // TODO: inline isLongBreak() and rename function isLongBreak2() { return isLongBreak(); From 8994b50dacc915de51f7b1cfe2b1ec48ddba70c6 Mon Sep 17 00:00:00 2001 From: Tom Gruen Date: Mon, 6 Apr 2020 23:04:24 +0200 Subject: [PATCH 10/22] moved globals into module Pomodoro --- source/Pomodoro.mc | 56 +++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/source/Pomodoro.mc b/source/Pomodoro.mc index 08ee783..4a5d727 100644 --- a/source/Pomodoro.mc +++ b/source/Pomodoro.mc @@ -6,41 +6,41 @@ using Toybox.Attention as Attention; using Toybox.Timer as Timer; using Toybox.Lang as Lang; -// global variables and functions -// TODO: move Pomodoro global variables into module Pomodoro -var timer; -var tickTimer; -var minutes = 0; -var pomodoroNumber = 1; -var isPomodoroTimerStarted = false; -var isBreakTimerStarted = false; - -function ping( dutyCycle, length ) { - if ( Attention has :vibrate ) { - Attention.vibrate( [ new Attention.VibeProfile( dutyCycle, length ) ] ); +// acts a a singleton, hence no class +module Pomodoro { + var timer; + var tickTimer; + var minutes = 0; + var pomodoroNumber = 1; + var isPomodoroTimerStarted = false; + var isBreakTimerStarted = false; + + function ping( dutyCycle, length ) { + if ( Attention has :vibrate ) { + Attention.vibrate([ new Attention.VibeProfile( dutyCycle, length ) ] ); + } } -} -function play( tone ) { - if ( Attention has :playTone && ! App.getApp().getProperty( "muteSounds" ) ) { - Attention.playTone( tone ); + function play( tone ) { + var isMuted = App.getApp().getProperty( "muteSounds" ); + if ( ! isMuted && Attention has :playTone ) { + Attention.playTone( tone ); + } } -} -function isLongBreak() { - return ( pomodoroNumber % App.getApp().getProperty( "numberOfPomodorosBeforeLongBreak" ) ) == 0; -} + function isLongBreak() { + var groupLength = App.getApp().getProperty( "numberOfPomodorosBeforeLongBreak" ); + return ( pomodoroNumber % groupLength ) == 0; + } -function resetMinutes() { - minutes = App.getApp().getProperty( "pomodoroLength" ); -} + function resetMinutes() { + minutes = App.getApp().getProperty( "pomodoroLength" ); + } -function shouldTick() { - return App.getApp().getProperty( "tickStrength" ) > 0; -} + function shouldTick() { + return App.getApp().getProperty( "tickStrength" ) > 0; + } -// acts a a singleton, hence no class -module Pomodoro { // called when app is started for the first time function initialize() { timer = new Timer.Timer(); From 0c1b3a2045f6791140cbeed68cefbec6099bf720 Mon Sep 17 00:00:00 2001 From: Tom Gruen Date: Mon, 6 Apr 2020 23:10:54 +0200 Subject: [PATCH 11/22] removed refactoring leftover isLongBreak2() --- source/GarmodoroView.mc | 2 +- source/Pomodoro.mc | 10 +++------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/source/GarmodoroView.mc b/source/GarmodoroView.mc index 877744c..32dd458 100644 --- a/source/GarmodoroView.mc +++ b/source/GarmodoroView.mc @@ -58,7 +58,7 @@ class GarmodoroView extends Ui.View { dc.setColor( Gfx.COLOR_TRANSPARENT, Gfx.COLOR_BLACK ); dc.clear(); if ( Pomodoro.isInBreakState() ) { - var labelForBreak = Pomodoro.isLongBreak2() ? + var labelForBreak = Pomodoro.isLongBreak() ? me.longBreakLabel : me.shortBreakLabel; dc.setColor( Gfx.COLOR_GREEN, Gfx.COLOR_TRANSPARENT ); diff --git a/source/Pomodoro.mc b/source/Pomodoro.mc index 4a5d727..8d94a01 100644 --- a/source/Pomodoro.mc +++ b/source/Pomodoro.mc @@ -88,11 +88,6 @@ module Pomodoro { ! isBreakTimerStarted; } - // TODO: inline isLongBreak() and rename - function isLongBreak2() { - return isLongBreak(); - } - function countdownMinutesInRunning() { minutes -= 1; @@ -103,9 +98,10 @@ module Pomodoro { tickTimer.stop(); timer.stop(); isPomodoroTimerStarted = false; - minutes = App.getApp().getProperty( isLongBreak() ? + var breakVariant = isLongBreak() ? "longBreakLength" : - "shortBreakLength" ); + "shortBreakLength"; + minutes = App.getApp().getProperty( breakVariant ); var breakTimerRoutine = new Lang.Method(Pomodoro, :countdownMinutesInBreak); timer.start( breakTimerRoutine, 60 * 1000, true ); From fb029e8befb108b336a3a264444951d29cb1fe9a Mon Sep 17 00:00:00 2001 From: Tom Gruen Date: Mon, 6 Apr 2020 23:50:56 +0200 Subject: [PATCH 12/22] refactoring: better names and order of functions --- source/GarmodoroDelegate.mc | 2 +- source/Pomodoro.mc | 135 +++++++++++++++++++----------------- 2 files changed, 74 insertions(+), 63 deletions(-) diff --git a/source/GarmodoroDelegate.mc b/source/GarmodoroDelegate.mc index e073eb4..088e92f 100644 --- a/source/GarmodoroDelegate.mc +++ b/source/GarmodoroDelegate.mc @@ -14,7 +14,7 @@ class GarmodoroDelegate extends Ui.BehaviorDelegate { function onSelect() { if ( Pomodoro.isInReadyState() ) { - Pomodoro.beginPomodoro(); + Pomodoro.beginPomodoroCountdown(); Ui.requestUpdate(); } else { // pomodoro is in running or break state displayStopMenu(); diff --git a/source/Pomodoro.mc b/source/Pomodoro.mc index 8d94a01..8704f6a 100644 --- a/source/Pomodoro.mc +++ b/source/Pomodoro.mc @@ -15,56 +15,41 @@ module Pomodoro { var isPomodoroTimerStarted = false; var isBreakTimerStarted = false; - function ping( dutyCycle, length ) { + // called when app is started for the first time + function initialize() { + timer = new Timer.Timer(); + tickTimer = new Timer.Timer(); + } + + function vibrate( dutyCycle, length ) { if ( Attention has :vibrate ) { Attention.vibrate([ new Attention.VibeProfile( dutyCycle, length ) ] ); } } - function play( tone ) { + // if not muted + function playAttentionTone( tone ) { var isMuted = App.getApp().getProperty( "muteSounds" ); if ( ! isMuted && Attention has :playTone ) { Attention.playTone( tone ); } } - function isLongBreak() { - var groupLength = App.getApp().getProperty( "numberOfPomodorosBeforeLongBreak" ); - return ( pomodoroNumber % groupLength ) == 0; + function resetMinutesForPomodoro() { + minutes = App.getApp().getProperty( "pomodoroLength" ); } - function resetMinutes() { - minutes = App.getApp().getProperty( "pomodoroLength" ); + function resetMinutesForBreak() { + var breakVariant = isLongBreak() ? + "longBreakLength" : + "shortBreakLength"; + minutes = App.getApp().getProperty( breakVariant ); } function shouldTick() { return App.getApp().getProperty( "tickStrength" ) > 0; } - // called when app is started for the first time - function initialize() { - timer = new Timer.Timer(); - tickTimer = new Timer.Timer(); - } - - function stopTimers() { - tickTimer.stop(); - timer.stop(); - } - - // called when "reset" action is selected in menu - function resetFromMenu() { - play( 9 ); // Attention.TONE_RESET - ping( 50, 1500 ); - - stopTimers(); - - resetMinutes(); - pomodoroNumber = 1; - isPomodoroTimerStarted = false; - isBreakTimerStarted = false; - } - // for displaying function getMinutesLeft() { return minutes; @@ -88,24 +73,28 @@ module Pomodoro { ! isBreakTimerStarted; } + function stopTimers() { + tickTimer.stop(); + timer.stop(); + } + + // called when "reset" action is selected in menu + function resetFromMenu() { + playAttentionTone( 9 ); // Attention.TONE_RESET + vibrate( 50, 1500 ); + + stopTimers(); + resetMinutesForPomodoro(); + pomodoroNumber = 1; + isPomodoroTimerStarted = false; + isBreakTimerStarted = false; + } + function countdownMinutesInRunning() { minutes -= 1; if ( minutes == 0 ) { - // TODO extract to beginBreak() - play( 10 ); // Attention.TONE_LAP - ping( 100, 1500 ); - tickTimer.stop(); - timer.stop(); - isPomodoroTimerStarted = false; - var breakVariant = isLongBreak() ? - "longBreakLength" : - "shortBreakLength"; - minutes = App.getApp().getProperty( breakVariant ); - var breakTimerRoutine = - new Lang.Method(Pomodoro, :countdownMinutesInBreak); - timer.start( breakTimerRoutine, 60 * 1000, true ); - isBreakTimerStarted = true; + beginBreakCountdown(); } Ui.requestUpdate(); @@ -116,27 +105,33 @@ module Pomodoro { minutes -= 1; if ( minutes == 0 ) { - // TODO: extract to beginReadyState() - play( 7 ); // Attention.TONE_INTERVAL_ALERT - ping( 100, 1500 ); - timer.stop(); - - isBreakTimerStarted = false; - pomodoroNumber += 1; - resetMinutes(); + beginReadyState(); } Ui.requestUpdate(); } + function beginReadyState() { + playAttentionTone( 7 ); // Attention.TONE_INTERVAL_ALERT + vibrate( 100, 1500 ); + timer.stop(); + isBreakTimerStarted = false; + pomodoroNumber += 1; + } + + function isLongBreak() { + var groupLength = App.getApp().getProperty( "numberOfPomodorosBeforeLongBreak" ); + return ( pomodoroNumber % groupLength ) == 0; + } + function makeTickingSound() { var strength = App.getApp().getProperty( "tickStrength" ); var duration = App.getApp().getProperty( "tickDuration" ); - ping( strength, duration ); + vibrate( strength, duration ); } - // start ticking once a second, if enabled - function beginTicking() { + // one tick every second + function beginTickingIfEnabled() { if ( shouldTick() ) { var tickTimerRoutine = new Lang.Method(Pomodoro, :makeTickingSound); @@ -144,16 +139,32 @@ module Pomodoro { } } - // begin pomodoro countdown - function beginPomodoro() { - play( 1 ); // Attention.TONE_START - ping( 75, 1500 ); - resetMinutes(); + function beginPomodoroCountdown() { + playAttentionTone( 1 ); // Attention.TONE_START + vibrate( 75, 1500 ); + + resetMinutesForPomodoro(); + var pomodoroTimerRoutine = new Lang.Method(Pomodoro, :countdownMinutesInRunning); timer.start( pomodoroTimerRoutine, 60 * 1000, true ); isPomodoroTimerStarted = true; - beginTicking(); + beginTickingIfEnabled(); + } + + function beginBreakCountdown() + { + playAttentionTone( 10 ); // Attention.TONE_LAP + vibrate( 100, 1500 ); + + stopTimers(); + isPomodoroTimerStarted = false; + resetMinutesForBreak(); + + var breakTimerRoutine = + new Lang.Method(Pomodoro, :countdownMinutesInBreak); + timer.start( breakTimerRoutine, 60 * 1000, true ); + isBreakTimerStarted = true; } } From f3bae4bc4fc2cced19d4ddf637b8d7b1b4610d67 Mon Sep 17 00:00:00 2001 From: Tom Gruen Date: Tue, 7 Apr 2020 00:06:49 +0200 Subject: [PATCH 13/22] merge minute countdown routines for pomodoro and break states --- source/Pomodoro.mc | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/source/Pomodoro.mc b/source/Pomodoro.mc index 8704f6a..934f6a6 100644 --- a/source/Pomodoro.mc +++ b/source/Pomodoro.mc @@ -90,25 +90,26 @@ module Pomodoro { isBreakTimerStarted = false; } - function countdownMinutesInRunning() { + function countdownMinutes() { minutes -= 1; if ( minutes == 0 ) { - beginBreakCountdown(); + if( isInRunningState() ) { + beginBreakCountdown(); + } else if (isInBreakState()) { + beginReadyState(); + } else { + // will never be called in ready state + } } Ui.requestUpdate(); } - // TODO merge this with Pomodoro.countdownMinutesInRunning() - function countdownMinutesInBreak() { - minutes -= 1; - - if ( minutes == 0 ) { - beginReadyState(); - } - - Ui.requestUpdate(); + function beginCountdown() { + var timerRoutine = + new Lang.Method(Pomodoro, :countdownMinutes); + timer.start( timerRoutine, 60 * 1000, true ); } function beginReadyState() { @@ -144,12 +145,8 @@ module Pomodoro { vibrate( 75, 1500 ); resetMinutesForPomodoro(); - - var pomodoroTimerRoutine = - new Lang.Method(Pomodoro, :countdownMinutesInRunning); - timer.start( pomodoroTimerRoutine, 60 * 1000, true ); + beginCountdown(); isPomodoroTimerStarted = true; - beginTickingIfEnabled(); } @@ -161,10 +158,7 @@ module Pomodoro { stopTimers(); isPomodoroTimerStarted = false; resetMinutesForBreak(); - - var breakTimerRoutine = - new Lang.Method(Pomodoro, :countdownMinutesInBreak); - timer.start( breakTimerRoutine, 60 * 1000, true ); + beginCountdown(); isBreakTimerStarted = true; } } From 52be38a32a8a71929abb423645c10665d67aeaac Mon Sep 17 00:00:00 2001 From: Tom Gruen Date: Tue, 7 Apr 2020 19:56:19 +0200 Subject: [PATCH 14/22] cleaned up GarmodoroView --- source/GarmodoroView.mc | 104 ++++++++++++++++++++++++++-------------- 1 file changed, 69 insertions(+), 35 deletions(-) diff --git a/source/GarmodoroView.mc b/source/GarmodoroView.mc index 32dd458..a702143 100644 --- a/source/GarmodoroView.mc +++ b/source/GarmodoroView.mc @@ -12,9 +12,11 @@ class GarmodoroView extends Ui.View { hidden var longBreakLabel; hidden var readyLabel; + // all elements are centered in X direction hidden var centerX; hidden var centerY; + // all offsets are in Y direction hidden var pomodoroOffset; hidden var captionOffset; hidden var readyLabelOffset; @@ -25,15 +27,18 @@ class GarmodoroView extends Ui.View { View.initialize(); } - function onLayout( dc ) { + function loadResources() { pomodoroSubtitle = Ui.loadResource( Rez.Strings.PomodoroSubtitle ); shortBreakLabel = Ui.loadResource( Rez.Strings.ShortBreakLabel ); longBreakLabel = Ui.loadResource( Rez.Strings.LongBreakLabel ); readyLabel = Ui.loadResource( Rez.Strings.ReadyLabel ); + } + function calculateDrawingPositions() { var height = dc.getHeight(); centerX = dc.getWidth() / 2; centerY = height / 2; + var mediumOffset = Gfx.getFontHeight( Gfx.FONT_MEDIUM ); var mediumOffsetHalf = mediumOffset / 2; var mildOffset = Gfx.getFontHeight( Gfx.FONT_NUMBER_MILD ); @@ -46,61 +51,90 @@ class GarmodoroView extends Ui.View { me.timeOffset -= 5; } - me.readyLabelOffset = me.centerY - ( Gfx.getFontHeight( Gfx.FONT_LARGE ) / 2 ); - me.minutesOffset = me.centerY - ( Gfx.getFontHeight( Gfx.FONT_NUMBER_THAI_HOT ) / 2 ); - me.captionOffset = me.timeOffset - Gfx.getFontHeight( Gfx.FONT_TINY ); + me.readyLabelOffset = me.centerY - + ( Gfx.getFontHeight( Gfx.FONT_LARGE ) / 2 ); + me.minutesOffset = me.centerY - + ( Gfx.getFontHeight( Gfx.FONT_NUMBER_THAI_HOT ) / 2 ); + me.captionOffset = me.timeOffset - + Gfx.getFontHeight( Gfx.FONT_TINY ); + } + + function onLayout( dc ) { + // TODO can we move these to initialize() ? + me.loadResources(); + me.calculateDrawingPositions(); } function onShow() { } + function onHide() { + } + function onUpdate( dc ) { - dc.setColor( Gfx.COLOR_TRANSPARENT, Gfx.COLOR_BLACK ); - dc.clear(); + me.drawBackground( dc, Gfx.COLOR_BLACK ); + if ( Pomodoro.isInBreakState() ) { - var labelForBreak = Pomodoro.isLongBreak() ? - me.longBreakLabel : - me.shortBreakLabel; - dc.setColor( Gfx.COLOR_GREEN, Gfx.COLOR_TRANSPARENT ); - dc.drawText( me.centerX, me.pomodoroOffset, Gfx.FONT_MEDIUM, - labelForBreak, Gfx.TEXT_JUSTIFY_CENTER ); - me.drawMinutes( dc ); - - dc.setColor( Gfx.COLOR_DK_GREEN, Gfx.COLOR_TRANSPARENT ); - me.drawCaption( dc ); + me.drawBreakLabel( dc, Gfx.COLOR_GREEN ); + me.drawMinutes( dc, Gfx.COLOR_GREEN ); + me.drawCaption( dc, Gfx.COLOR_DK_GREEN ); } else if ( Pomodoro.isInRunningState() ) { - dc.setColor( Gfx.COLOR_YELLOW, Gfx.COLOR_TRANSPARENT ); - me.drawMinutes( dc ); - dc.setColor( Gfx.COLOR_ORANGE, Gfx.COLOR_TRANSPARENT ); - me.drawCaption( dc ); + me.drawPomodoroLabel( dc, Gfx.COLOR_LT_GRAY ); + me.drawMinutes( dc, Gfx.COLOR_YELLOW ); + me.drawCaption( dc, Gfx.COLOR_ORANGE ); } else { // Pomodoro is in ready state - dc.setColor( Gfx.COLOR_ORANGE, Gfx.COLOR_TRANSPARENT ); - dc.drawText( me.centerX, me.readyLabelOffset, Gfx.FONT_LARGE, - me.readyLabel, Gfx.TEXT_JUSTIFY_CENTER ); + me.drawPomodoroLabel( dc, Gfx.COLOR_LT_GRAY ); + me.drawReadyLabel( dc, Gfx.COLOR_ORANGE ); } - if ( ! Pomodoro.isInBreakState() ) { - dc.setColor( Gfx.COLOR_LT_GRAY, Gfx.COLOR_TRANSPARENT ); - dc.drawText( me.centerX, me.pomodoroOffset, Gfx.FONT_MEDIUM, "Pomodoro #" + - Pomodoro.getIteration(), Gfx.TEXT_JUSTIFY_CENTER ); - } + drawTime( dc, Gfx.COLOR_LT_GRAY ); + } - dc.setColor( Gfx.COLOR_LT_GRAY, Gfx.COLOR_TRANSPARENT ); - dc.drawText( self.centerX, self.timeOffset, Gfx.FONT_NUMBER_MILD, - self.getTime(), Gfx.TEXT_JUSTIFY_CENTER ); + hidden function drawBackground( dc, backgroundColor ) { + dc.setColor( Gfx.COLOR_TRANSPARENT, backgroundColor ); + dc.clear(); } - hidden function drawMinutes( dc ) { + hidden function drawPomodoroLabel( dc, foregroundColor ) { + var pomodoroLabel = "Pomodoro #" + Pomodoro.getIteration(); + dc.setColor( foregroundColor, Gfx.COLOR_TRANSPARENT ); + dc.drawText( me.centerX, me.pomodoroOffset, Gfx.FONT_MEDIUM, + pomodoroLabel, Gfx.TEXT_JUSTIFY_CENTER ); + } + + hidden function drawBreakLabel( dc, foregroundColor ) { + var labelForBreak = Pomodoro.isLongBreak() ? + me.longBreakLabel : + me.shortBreakLabel; + dc.setColor( foregroundColor, Gfx.COLOR_TRANSPARENT ); + dc.drawText( me.centerX, me.pomodoroOffset, Gfx.FONT_MEDIUM, + labelForBreak, Gfx.TEXT_JUSTIFY_CENTER ); + } + + hidden function drawReadyLabel( dc, foregroundColor ) { + dc.setColor( foregroundColor, Gfx.COLOR_TRANSPARENT ); + dc.drawText( me.centerX, me.readyLabelOffset, Gfx.FONT_LARGE, + me.readyLabel, Gfx.TEXT_JUSTIFY_CENTER ); + } + + hidden function drawMinutes( dc, foregroundColor ) { + // TODO inline format() in getMinutesLeft() + var minutesAsText = Pomodoro.getMinutesLeft().format( "%02d" ); + dc.setColor( foregroundColor, Gfx.COLOR_TRANSPARENT ); dc.drawText( me.centerX, me.minutesOffset, Gfx.FONT_NUMBER_THAI_HOT, - Pomodoro.getMinutesLeft().format( "%02d" ), Gfx.TEXT_JUSTIFY_CENTER ); + minutesAsText, Gfx.TEXT_JUSTIFY_CENTER ); } - hidden function drawCaption( dc ) { + hidden function drawCaption( dc, foregroundColor ) { + dc.setColor( foregroundColor, Gfx.COLOR_TRANSPARENT ); dc.drawText( me.centerX, me.captionOffset, Gfx.FONT_TINY, me.pomodoroSubtitle, Gfx.TEXT_JUSTIFY_CENTER ); } - function onHide() { + hidden function drawTime( dc, foregroundColor ) { + dc.setColor( foregroundColor, Gfx.COLOR_TRANSPARENT ); + dc.drawText( self.centerX, self.timeOffset, Gfx.FONT_NUMBER_MILD, + self.getTime(), Gfx.TEXT_JUSTIFY_CENTER ); } function getTime() { From bf26dabe481d839be56d3bbe7df80435120e8377 Mon Sep 17 00:00:00 2001 From: Tom Gruen Date: Tue, 7 Apr 2020 22:18:22 +0200 Subject: [PATCH 15/22] renamed variables and restructured GarmodoroView --- source/GarmodoroView.mc | 54 +++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/source/GarmodoroView.mc b/source/GarmodoroView.mc index a702143..4ba541e 100644 --- a/source/GarmodoroView.mc +++ b/source/GarmodoroView.mc @@ -14,7 +14,6 @@ class GarmodoroView extends Ui.View { // all elements are centered in X direction hidden var centerX; - hidden var centerY; // all offsets are in Y direction hidden var pomodoroOffset; @@ -27,36 +26,45 @@ class GarmodoroView extends Ui.View { View.initialize(); } - function loadResources() { + hidden function loadResources() { pomodoroSubtitle = Ui.loadResource( Rez.Strings.PomodoroSubtitle ); shortBreakLabel = Ui.loadResource( Rez.Strings.ShortBreakLabel ); longBreakLabel = Ui.loadResource( Rez.Strings.LongBreakLabel ); readyLabel = Ui.loadResource( Rez.Strings.ReadyLabel ); } - function calculateDrawingPositions() { - var height = dc.getHeight(); - centerX = dc.getWidth() / 2; - centerY = height / 2; + hidden function calculateDrawingPositions() { + me.centerX = dc.getWidth() / 2; - var mediumOffset = Gfx.getFontHeight( Gfx.FONT_MEDIUM ); - var mediumOffsetHalf = mediumOffset / 2; - var mildOffset = Gfx.getFontHeight( Gfx.FONT_NUMBER_MILD ); + // offsets relative to the top and bottom of the watch face + me.pomodoroOffset = 5; + + var heightOfFontMild = Gfx.getFontHeight( Gfx.FONT_NUMBER_MILD ); + me.timeOffset = height - heightOfFontMild; + + // offsets relative to the center + var centerY = dc.getHeight() / 2; + var heightOfFontLarge = Gfx.getFontHeight( Gfx.FONT_LARGE ); + me.readyLabelOffset = me.centerY - heightOfFontLarge /2; + + var heightOfFontHot = Gfx.getFontHeight( Gfx.FONT_NUMBER_THAI_HOT ); + me.minutesOffset = me.centerY - heightOfFontHot / 2; + + var heightOfFontTiny = Gfx.getFontHeight( Gfx.FONT_TINY ); + me.captionOffset = me.timeOffset - heightOfFontTiny; + + me.adjustOffsetsForRoundScreen(); + } + + // 'special' case: non rectangular screens + hidden function adjustOffsetsForRoundScreen() { var screenShape = System.getDeviceSettings().screenShape; + if ( screenShape != System.SCREEN_SHAPE_RECTANGLE ) { + var heightOfFontMedium = Gfx.getFontHeight( Gfx.FONT_MEDIUM ); + me.pomodoroOffset += heightOfFontMedium; - me.timeOffset = height - mildOffset; - me.pomodoroOffset = 5; - if ( System.SCREEN_SHAPE_RECTANGLE != screenShape ) { - me.pomodoroOffset += mediumOffset; me.timeOffset -= 5; } - - me.readyLabelOffset = me.centerY - - ( Gfx.getFontHeight( Gfx.FONT_LARGE ) / 2 ); - me.minutesOffset = me.centerY - - ( Gfx.getFontHeight( Gfx.FONT_NUMBER_THAI_HOT ) / 2 ); - me.captionOffset = me.timeOffset - - Gfx.getFontHeight( Gfx.FONT_TINY ); } function onLayout( dc ) { @@ -133,11 +141,11 @@ class GarmodoroView extends Ui.View { hidden function drawTime( dc, foregroundColor ) { dc.setColor( foregroundColor, Gfx.COLOR_TRANSPARENT ); - dc.drawText( self.centerX, self.timeOffset, Gfx.FONT_NUMBER_MILD, - self.getTime(), Gfx.TEXT_JUSTIFY_CENTER ); + dc.drawText( me.centerX, me.timeOffset, Gfx.FONT_NUMBER_MILD, + me.getTime(), Gfx.TEXT_JUSTIFY_CENTER ); } - function getTime() { + hidden function getTime() { var today = Gregorian.info( Time.now(), Time.FORMAT_SHORT ); return Lang.format( "$1$:$2$", [ today.hour.format( "%02d" ), From c8684168146ca080c6cdb42865ab4daa3bd3c6f4 Mon Sep 17 00:00:00 2001 From: Tom Gruen Date: Tue, 7 Apr 2020 22:46:09 +0200 Subject: [PATCH 16/22] bugfix: device context dc needed in calculateDrawingPositions() --- source/GarmodoroView.mc | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/source/GarmodoroView.mc b/source/GarmodoroView.mc index 4ba541e..a94d0dc 100644 --- a/source/GarmodoroView.mc +++ b/source/GarmodoroView.mc @@ -33,7 +33,7 @@ class GarmodoroView extends Ui.View { readyLabel = Ui.loadResource( Rez.Strings.ReadyLabel ); } - hidden function calculateDrawingPositions() { + hidden function calculateDrawingPositions( dc ) { me.centerX = dc.getWidth() / 2; // offsets relative to the top and bottom of the watch face @@ -48,7 +48,7 @@ class GarmodoroView extends Ui.View { me.readyLabelOffset = me.centerY - heightOfFontLarge /2; var heightOfFontHot = Gfx.getFontHeight( Gfx.FONT_NUMBER_THAI_HOT ); - me.minutesOffset = me.centerY - heightOfFontHot / 2; + me.minutesOffset = me.centerY - heightOfFontHot / 2; var heightOfFontTiny = Gfx.getFontHeight( Gfx.FONT_TINY ); me.captionOffset = me.timeOffset - heightOfFontTiny; @@ -68,9 +68,8 @@ class GarmodoroView extends Ui.View { } function onLayout( dc ) { - // TODO can we move these to initialize() ? me.loadResources(); - me.calculateDrawingPositions(); + me.calculateDrawingPositions( dc ); } function onShow() { From 174d4a40fa83f13199a0c461233cf1e4dd7aa488 Mon Sep 17 00:00:00 2001 From: Tom Gruen Date: Tue, 7 Apr 2020 22:59:46 +0200 Subject: [PATCH 17/22] renamed variables and reordered code in Pomodoro.mc --- source/Pomodoro.mc | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/source/Pomodoro.mc b/source/Pomodoro.mc index 934f6a6..7124401 100644 --- a/source/Pomodoro.mc +++ b/source/Pomodoro.mc @@ -8,16 +8,17 @@ using Toybox.Lang as Lang; // acts a a singleton, hence no class module Pomodoro { - var timer; + var minuteTimer; var tickTimer; - var minutes = 0; + var minutesLeft = 0; var pomodoroNumber = 1; + // TODO: represent pomodoro state in one variable var isPomodoroTimerStarted = false; var isBreakTimerStarted = false; // called when app is started for the first time function initialize() { - timer = new Timer.Timer(); + minuteTimer = new Timer.Timer(); tickTimer = new Timer.Timer(); } @@ -36,14 +37,19 @@ module Pomodoro { } function resetMinutesForPomodoro() { - minutes = App.getApp().getProperty( "pomodoroLength" ); + minutesLeft = App.getApp().getProperty( "pomodoroLength" ); + } + + function isLongBreak() { + var groupLength = App.getApp().getProperty( "numberOfPomodorosBeforeLongBreak" ); + return ( pomodoroNumber % groupLength ) == 0; } function resetMinutesForBreak() { var breakVariant = isLongBreak() ? "longBreakLength" : "shortBreakLength"; - minutes = App.getApp().getProperty( breakVariant ); + minutesLeft = App.getApp().getProperty( breakVariant ); } function shouldTick() { @@ -52,7 +58,7 @@ module Pomodoro { // for displaying function getMinutesLeft() { - return minutes; + return minutesLeft; } // for displaying @@ -75,10 +81,10 @@ module Pomodoro { function stopTimers() { tickTimer.stop(); - timer.stop(); + minuteTimer.stop(); } - // called when "reset" action is selected in menu + // called on reset action in stop menu function resetFromMenu() { playAttentionTone( 9 ); // Attention.TONE_RESET vibrate( 50, 1500 ); @@ -91,9 +97,9 @@ module Pomodoro { } function countdownMinutes() { - minutes -= 1; + minutesLeft -= 1; - if ( minutes == 0 ) { + if ( minutesLeft == 0 ) { if( isInRunningState() ) { beginBreakCountdown(); } else if (isInBreakState()) { @@ -107,24 +113,19 @@ module Pomodoro { } function beginCountdown() { - var timerRoutine = - new Lang.Method(Pomodoro, :countdownMinutes); - timer.start( timerRoutine, 60 * 1000, true ); + var countdown = new Lang.Method(Pomodoro, :countdownMinutes); + minuteTimer.start( countdown, 60 * 1000, true ); } function beginReadyState() { playAttentionTone( 7 ); // Attention.TONE_INTERVAL_ALERT vibrate( 100, 1500 ); - timer.stop(); + // FIXME: time display will freeze, if minuteTimer is stopped + minuteTimer.stop(); isBreakTimerStarted = false; pomodoroNumber += 1; } - function isLongBreak() { - var groupLength = App.getApp().getProperty( "numberOfPomodorosBeforeLongBreak" ); - return ( pomodoroNumber % groupLength ) == 0; - } - function makeTickingSound() { var strength = App.getApp().getProperty( "tickStrength" ); var duration = App.getApp().getProperty( "tickDuration" ); @@ -134,9 +135,8 @@ module Pomodoro { // one tick every second function beginTickingIfEnabled() { if ( shouldTick() ) { - var tickTimerRoutine = - new Lang.Method(Pomodoro, :makeTickingSound); - tickTimer.start( tickTimerRoutine, 1000, true ); + var makeTick = new Lang.Method(Pomodoro, :makeTickingSound); + tickTimer.start( makeTick, 1000, true ); } } From f55368e28f6a5909fd14d8490a876139de47cca8 Mon Sep 17 00:00:00 2001 From: Tom Gruen Date: Tue, 7 Apr 2020 23:57:12 +0200 Subject: [PATCH 18/22] changed pomodoro state handling fixed centerY bug in GarmodoroView all TODOs finished --- source/GarmodoroDelegate.mc | 2 +- source/GarmodoroView.mc | 9 +++---- source/Pomodoro.mc | 52 ++++++++++++++++++++----------------- 3 files changed, 33 insertions(+), 30 deletions(-) diff --git a/source/GarmodoroDelegate.mc b/source/GarmodoroDelegate.mc index 088e92f..bdd6cbb 100644 --- a/source/GarmodoroDelegate.mc +++ b/source/GarmodoroDelegate.mc @@ -14,7 +14,7 @@ class GarmodoroDelegate extends Ui.BehaviorDelegate { function onSelect() { if ( Pomodoro.isInReadyState() ) { - Pomodoro.beginPomodoroCountdown(); + Pomodoro.beginRunningState(); Ui.requestUpdate(); } else { // pomodoro is in running or break state displayStopMenu(); diff --git a/source/GarmodoroView.mc b/source/GarmodoroView.mc index a94d0dc..e919773 100644 --- a/source/GarmodoroView.mc +++ b/source/GarmodoroView.mc @@ -45,10 +45,10 @@ class GarmodoroView extends Ui.View { // offsets relative to the center var centerY = dc.getHeight() / 2; var heightOfFontLarge = Gfx.getFontHeight( Gfx.FONT_LARGE ); - me.readyLabelOffset = me.centerY - heightOfFontLarge /2; + me.readyLabelOffset = centerY - heightOfFontLarge /2; var heightOfFontHot = Gfx.getFontHeight( Gfx.FONT_NUMBER_THAI_HOT ); - me.minutesOffset = me.centerY - heightOfFontHot / 2; + me.minutesOffset = centerY - heightOfFontHot / 2; var heightOfFontTiny = Gfx.getFontHeight( Gfx.FONT_TINY ); me.captionOffset = me.timeOffset - heightOfFontTiny; @@ -69,7 +69,7 @@ class GarmodoroView extends Ui.View { function onLayout( dc ) { me.loadResources(); - me.calculateDrawingPositions( dc ); + me.calculateDrawingPositions( dc ); } function onShow() { @@ -125,8 +125,7 @@ class GarmodoroView extends Ui.View { } hidden function drawMinutes( dc, foregroundColor ) { - // TODO inline format() in getMinutesLeft() - var minutesAsText = Pomodoro.getMinutesLeft().format( "%02d" ); + var minutesAsText = Pomodoro.getMinutesLeft(); dc.setColor( foregroundColor, Gfx.COLOR_TRANSPARENT ); dc.drawText( me.centerX, me.minutesOffset, Gfx.FONT_NUMBER_THAI_HOT, minutesAsText, Gfx.TEXT_JUSTIFY_CENTER ); diff --git a/source/Pomodoro.mc b/source/Pomodoro.mc index 7124401..b074a25 100644 --- a/source/Pomodoro.mc +++ b/source/Pomodoro.mc @@ -10,16 +10,22 @@ using Toybox.Lang as Lang; module Pomodoro { var minuteTimer; var tickTimer; + // pomodoro states: ready -> running -> break -> ready ... + enum { + stateReady, + stateRunning, + stateBreak + } + var currentState = stateReady; + var pomodoroIteration = 1; var minutesLeft = 0; - var pomodoroNumber = 1; - // TODO: represent pomodoro state in one variable - var isPomodoroTimerStarted = false; - var isBreakTimerStarted = false; // called when app is started for the first time function initialize() { minuteTimer = new Timer.Timer(); tickTimer = new Timer.Timer(); + // refreshes current time displayed on watch + beginCountdown(); } function vibrate( dutyCycle, length ) { @@ -42,7 +48,7 @@ module Pomodoro { function isLongBreak() { var groupLength = App.getApp().getProperty( "numberOfPomodorosBeforeLongBreak" ); - return ( pomodoroNumber % groupLength ) == 0; + return ( pomodoroIteration % groupLength ) == 0; } function resetMinutesForBreak() { @@ -58,25 +64,24 @@ module Pomodoro { // for displaying function getMinutesLeft() { - return minutesLeft; + return minutesLeft.format( "%02d" ); } // for displaying function getIteration() { - return pomodoroNumber; + return pomodoroIteration; } function isInBreakState() { - return isBreakTimerStarted; + return currentState == stateBreak; } function isInRunningState() { - return isPomodoroTimerStarted; + return currentState == stateRunning; } function isInReadyState() { - return ! isPomodoroTimerStarted && - ! isBreakTimerStarted; + return currentState == stateReady; } function stopTimers() { @@ -91,9 +96,8 @@ module Pomodoro { stopTimers(); resetMinutesForPomodoro(); - pomodoroNumber = 1; - isPomodoroTimerStarted = false; - isBreakTimerStarted = false; + pomodoroIteration = 1; + currentState = stateReady; } function countdownMinutes() { @@ -101,7 +105,7 @@ module Pomodoro { if ( minutesLeft == 0 ) { if( isInRunningState() ) { - beginBreakCountdown(); + beginBreakState(); } else if (isInBreakState()) { beginReadyState(); } else { @@ -120,10 +124,10 @@ module Pomodoro { function beginReadyState() { playAttentionTone( 7 ); // Attention.TONE_INTERVAL_ALERT vibrate( 100, 1500 ); - // FIXME: time display will freeze, if minuteTimer is stopped - minuteTimer.stop(); - isBreakTimerStarted = false; - pomodoroNumber += 1; + stopTimers(); + currentState = stateReady; + pomodoroIteration += 1; + beginCountdown(); } function makeTickingSound() { @@ -140,25 +144,25 @@ module Pomodoro { } } - function beginPomodoroCountdown() { + function beginRunningState() { playAttentionTone( 1 ); // Attention.TONE_START vibrate( 75, 1500 ); + stopTimers(); + currentState = stateRunning; resetMinutesForPomodoro(); beginCountdown(); - isPomodoroTimerStarted = true; beginTickingIfEnabled(); } - function beginBreakCountdown() + function beginBreakState() { playAttentionTone( 10 ); // Attention.TONE_LAP vibrate( 100, 1500 ); stopTimers(); - isPomodoroTimerStarted = false; + currentState = stateBreak; resetMinutesForBreak(); beginCountdown(); - isBreakTimerStarted = true; } } From c8bd31bd58d30df9b6fdd665b4f4f267c9369d20 Mon Sep 17 00:00:00 2001 From: Tom Gruen Date: Wed, 8 Apr 2020 00:15:52 +0200 Subject: [PATCH 19/22] created central function for state transitions --- source/Pomodoro.mc | 45 ++++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/source/Pomodoro.mc b/source/Pomodoro.mc index b074a25..70ce522 100644 --- a/source/Pomodoro.mc +++ b/source/Pomodoro.mc @@ -109,7 +109,7 @@ module Pomodoro { } else if (isInBreakState()) { beginReadyState(); } else { - // will never be called in ready state + // nothing in ready state } } @@ -122,12 +122,7 @@ module Pomodoro { } function beginReadyState() { - playAttentionTone( 7 ); // Attention.TONE_INTERVAL_ALERT - vibrate( 100, 1500 ); - stopTimers(); - currentState = stateReady; - pomodoroIteration += 1; - beginCountdown(); + transitionToState( stateReady ); } function makeTickingSound() { @@ -145,24 +140,36 @@ module Pomodoro { } function beginRunningState() { - playAttentionTone( 1 ); // Attention.TONE_START - vibrate( 75, 1500 ); - - stopTimers(); - currentState = stateRunning; - resetMinutesForPomodoro(); - beginCountdown(); - beginTickingIfEnabled(); + transitionToState( stateRunning ); } function beginBreakState() { - playAttentionTone( 10 ); // Attention.TONE_LAP - vibrate( 100, 1500 ); + transitionToState( stateBreak ); + } + function transitionToState( targetState ) { stopTimers(); - currentState = stateBreak; - resetMinutesForBreak(); + currentState = targetState; + + if(targetState == stateReady) { + playAttentionTone( 7 ); // Attention.TONE_INTERVAL_ALERT + vibrate( 100, 1500 ); + currentState = stateReady; + pomodoroIteration += 1; + } else if(targetState== stateRunning) { + playAttentionTone( 1 ); // Attention.TONE_START + vibrate( 75, 1500 ); + currentState = stateRunning; + resetMinutesForPomodoro(); + beginTickingIfEnabled(); + } else { // targetState == stateBreak + playAttentionTone( 10 ); // Attention.TONE_LAP + vibrate( 100, 1500 ); + currentState = stateBreak; + resetMinutesForBreak(); + } + beginCountdown(); } } From f5c05a2ad9d980bb6fdd2f1fd4831c088ca30072 Mon Sep 17 00:00:00 2001 From: Tom Gruen Date: Wed, 8 Apr 2020 00:41:41 +0200 Subject: [PATCH 20/22] used transitionToState() and removed intermediaries cached tickStrength and tickDuration to reduce battery strain --- source/GarmodoroDelegate.mc | 2 +- source/Pomodoro.mc | 42 ++++++++++++++----------------------- 2 files changed, 17 insertions(+), 27 deletions(-) diff --git a/source/GarmodoroDelegate.mc b/source/GarmodoroDelegate.mc index bdd6cbb..df2b066 100644 --- a/source/GarmodoroDelegate.mc +++ b/source/GarmodoroDelegate.mc @@ -14,7 +14,7 @@ class GarmodoroDelegate extends Ui.BehaviorDelegate { function onSelect() { if ( Pomodoro.isInReadyState() ) { - Pomodoro.beginRunningState(); + Pomodoro.transitionToState( Pomodoro.stateRunning ); Ui.requestUpdate(); } else { // pomodoro is in running or break state displayStopMenu(); diff --git a/source/Pomodoro.mc b/source/Pomodoro.mc index 70ce522..1bed55a 100644 --- a/source/Pomodoro.mc +++ b/source/Pomodoro.mc @@ -19,13 +19,18 @@ module Pomodoro { var currentState = stateReady; var pomodoroIteration = 1; var minutesLeft = 0; + // caching reduces battery load + var tickStrength; + var tickDuration; // called when app is started for the first time function initialize() { + tickStrength = App.getApp().getProperty( "tickStrength" ); + tickDuration = App.getApp().getProperty( "tickDuration" ); minuteTimer = new Timer.Timer(); tickTimer = new Timer.Timer(); // refreshes current time displayed on watch - beginCountdown(); + beginMinuteCountdown(); } function vibrate( dutyCycle, length ) { @@ -105,30 +110,24 @@ module Pomodoro { if ( minutesLeft == 0 ) { if( isInRunningState() ) { - beginBreakState(); + transitionToState( stateBreak ); } else if (isInBreakState()) { - beginReadyState(); + transitionToState( stateReady ); } else { - // nothing in ready state + // nothing to do in ready state } } Ui.requestUpdate(); } - function beginCountdown() { + function beginMinuteCountdown() { var countdown = new Lang.Method(Pomodoro, :countdownMinutes); minuteTimer.start( countdown, 60 * 1000, true ); } - function beginReadyState() { - transitionToState( stateReady ); - } - function makeTickingSound() { - var strength = App.getApp().getProperty( "tickStrength" ); - var duration = App.getApp().getProperty( "tickDuration" ); - vibrate( strength, duration ); + vibrate( tickStrength, tickDuration ); } // one tick every second @@ -139,25 +138,16 @@ module Pomodoro { } } - function beginRunningState() { - transitionToState( stateRunning ); - } - - function beginBreakState() - { - transitionToState( stateBreak ); - } - function transitionToState( targetState ) { stopTimers(); currentState = targetState; - - if(targetState == stateReady) { + + if( targetState == stateReady ) { playAttentionTone( 7 ); // Attention.TONE_INTERVAL_ALERT vibrate( 100, 1500 ); currentState = stateReady; pomodoroIteration += 1; - } else if(targetState== stateRunning) { + } else if( targetState== stateRunning ) { playAttentionTone( 1 ); // Attention.TONE_START vibrate( 75, 1500 ); currentState = stateRunning; @@ -169,7 +159,7 @@ module Pomodoro { currentState = stateBreak; resetMinutesForBreak(); } - - beginCountdown(); + + beginMinuteCountdown(); } } From 2703249e51cbbd8183465df5e484f2de200a60b5 Mon Sep 17 00:00:00 2001 From: Tom Gruen Date: Sat, 11 Apr 2020 13:44:10 +0200 Subject: [PATCH 21/22] finished refactoring: comments and code ordering bugfix: variable height should be dc.getHeight() --- source/GarmodoroDelegate.mc | 8 ++-- source/GarmodoroView.mc | 10 ++--- source/Pomodoro.mc | 75 ++++++++++++++++++------------------- 3 files changed, 46 insertions(+), 47 deletions(-) diff --git a/source/GarmodoroDelegate.mc b/source/GarmodoroDelegate.mc index df2b066..f65de74 100644 --- a/source/GarmodoroDelegate.mc +++ b/source/GarmodoroDelegate.mc @@ -17,13 +17,11 @@ class GarmodoroDelegate extends Ui.BehaviorDelegate { Pomodoro.transitionToState( Pomodoro.stateRunning ); Ui.requestUpdate(); } else { // pomodoro is in running or break state - displayStopMenu(); + onMenu(); } return true; } - // TODO: add onMenu() if supported on all watches - function onNextMode() { return true; } @@ -32,8 +30,10 @@ class GarmodoroDelegate extends Ui.BehaviorDelegate { return true; } - function displayStopMenu() { + // also called from onSelect() when Pomodoro running or in break + function onMenu() { Ui.pushView( new Rez.Menus.StopMenu(), new StopMenuDelegate(), Ui.SLIDE_UP ); + return true; } } diff --git a/source/GarmodoroView.mc b/source/GarmodoroView.mc index e919773..283921d 100644 --- a/source/GarmodoroView.mc +++ b/source/GarmodoroView.mc @@ -40,7 +40,7 @@ class GarmodoroView extends Ui.View { me.pomodoroOffset = 5; var heightOfFontMild = Gfx.getFontHeight( Gfx.FONT_NUMBER_MILD ); - me.timeOffset = height - heightOfFontMild; + me.timeOffset = dc.getHeight() - heightOfFontMild; // offsets relative to the center var centerY = dc.getHeight() / 2; @@ -94,7 +94,7 @@ class GarmodoroView extends Ui.View { me.drawReadyLabel( dc, Gfx.COLOR_ORANGE ); } - drawTime( dc, Gfx.COLOR_LT_GRAY ); + me.drawTime( dc, Gfx.COLOR_LT_GRAY ); } hidden function drawBackground( dc, backgroundColor ) { @@ -146,8 +146,8 @@ class GarmodoroView extends Ui.View { hidden function getTime() { var today = Gregorian.info( Time.now(), Time.FORMAT_SHORT ); return Lang.format( "$1$:$2$", [ - today.hour.format( "%02d" ), - today.min.format( "%02d" ), - ] ); + today.hour.format( "%02d" ), + today.min.format( "%02d" ), + ] ); } } diff --git a/source/Pomodoro.mc b/source/Pomodoro.mc index 1bed55a..d5b85d5 100644 --- a/source/Pomodoro.mc +++ b/source/Pomodoro.mc @@ -1,12 +1,10 @@ -// this file encapsulates the core Pomodoro functionality. - using Toybox.Application as App; using Toybox.WatchUi as Ui; using Toybox.Attention as Attention; using Toybox.Timer as Timer; using Toybox.Lang as Lang; -// acts a a singleton, hence no class +// core Pomodoro functionality is a singleton, hence no class module Pomodoro { var minuteTimer; var tickTimer; @@ -19,7 +17,7 @@ module Pomodoro { var currentState = stateReady; var pomodoroIteration = 1; var minutesLeft = 0; - // caching reduces battery load + // cached app properties to reduce battery load var tickStrength; var tickDuration; @@ -27,15 +25,17 @@ module Pomodoro { function initialize() { tickStrength = App.getApp().getProperty( "tickStrength" ); tickDuration = App.getApp().getProperty( "tickDuration" ); + minuteTimer = new Timer.Timer(); tickTimer = new Timer.Timer(); - // refreshes current time displayed on watch + // continuously refreshes current time displayed on watch beginMinuteCountdown(); } function vibrate( dutyCycle, length ) { if ( Attention has :vibrate ) { - Attention.vibrate([ new Attention.VibeProfile( dutyCycle, length ) ] ); + Attention.vibrate([ new Attention.VibeProfile( + dutyCycle, length ) ] ); } } @@ -47,12 +47,21 @@ module Pomodoro { } } - function resetMinutesForPomodoro() { - minutesLeft = App.getApp().getProperty( "pomodoroLength" ); + function isInBreakState() { + return currentState == stateBreak; + } + + function isInRunningState() { + return currentState == stateRunning; + } + + function isInReadyState() { + return currentState == stateReady; } function isLongBreak() { - var groupLength = App.getApp().getProperty( "numberOfPomodorosBeforeLongBreak" ); + var groupLength = App.getApp().getProperty( + "numberOfPomodorosBeforeLongBreak" ); return ( pomodoroIteration % groupLength ) == 0; } @@ -63,46 +72,27 @@ module Pomodoro { minutesLeft = App.getApp().getProperty( breakVariant ); } - function shouldTick() { - return App.getApp().getProperty( "tickStrength" ) > 0; + function resetMinutesForPomodoro() { + minutesLeft = App.getApp().getProperty( "pomodoroLength" ); } - // for displaying + // for GarmodoroView function getMinutesLeft() { return minutesLeft.format( "%02d" ); } - // for displaying + // for GarmodoroView function getIteration() { return pomodoroIteration; } - function isInBreakState() { - return currentState == stateBreak; - } - - function isInRunningState() { - return currentState == stateRunning; - } - - function isInReadyState() { - return currentState == stateReady; - } - - function stopTimers() { - tickTimer.stop(); - minuteTimer.stop(); - } - - // called on reset action in stop menu + // called by StopMenuDelegate function resetFromMenu() { playAttentionTone( 9 ); // Attention.TONE_RESET vibrate( 50, 1500 ); - stopTimers(); - resetMinutesForPomodoro(); - pomodoroIteration = 1; - currentState = stateReady; + pomodoroIteration = 0; + transitionToState( stateReady ); } function countdownMinutes() { @@ -130,6 +120,10 @@ module Pomodoro { vibrate( tickStrength, tickDuration ); } + function shouldTick() { + return App.getApp().getProperty( "tickStrength" ) > 0; + } + // one tick every second function beginTickingIfEnabled() { if ( shouldTick() ) { @@ -138,6 +132,11 @@ module Pomodoro { } } + function stopTimers() { + tickTimer.stop(); + minuteTimer.stop(); + } + function transitionToState( targetState ) { stopTimers(); currentState = targetState; @@ -145,18 +144,18 @@ module Pomodoro { if( targetState == stateReady ) { playAttentionTone( 7 ); // Attention.TONE_INTERVAL_ALERT vibrate( 100, 1500 ); - currentState = stateReady; + pomodoroIteration += 1; } else if( targetState== stateRunning ) { playAttentionTone( 1 ); // Attention.TONE_START vibrate( 75, 1500 ); - currentState = stateRunning; + resetMinutesForPomodoro(); beginTickingIfEnabled(); } else { // targetState == stateBreak playAttentionTone( 10 ); // Attention.TONE_LAP vibrate( 100, 1500 ); - currentState = stateBreak; + resetMinutesForBreak(); } From 90a7bbb59a48e6ce3bd36b1a70150e5b67106d9c Mon Sep 17 00:00:00 2001 From: Tom Gruen Date: Wed, 15 Apr 2020 19:37:34 +0200 Subject: [PATCH 22/22] handling of properties.mk - moved properties.mk to properties.mk.example - added properties.mk to .gitignore - added section in README.md Rationale: a new developer will have to change properties.mk . So an example file (properties.mk.example) is helpful, but the actual properties.mk file should not be checked into version control. --- .gitignore | 3 ++- README.md | 1 + properties.mk => properties.mk.example | 0 3 files changed, 3 insertions(+), 1 deletion(-) rename properties.mk => properties.mk.example (100%) diff --git a/.gitignore b/.gitignore index 54f99c7..ec71b99 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ .settings *.swp -developer_key.* \ No newline at end of file +developer_key.* +properties.mk \ No newline at end of file diff --git a/README.md b/README.md index 694aed0..dfa2d58 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ Pomodoro for Garmin devices using Connect IQ ## Development To run the project, you can either import the project into Eclipse the usual way. Or use the `Makefile`: + * Copy `properties.mk.example` to `properties.mk` * Edit `properties.mk` file and make sure the paths there are valid on your computer. Change the `DEVICE` variable if you want/need. * Run `make run` to build the project and run the Connect IQ simulator on the chosen `DEVICE`. diff --git a/properties.mk b/properties.mk.example similarity index 100% rename from properties.mk rename to properties.mk.example