Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions manifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@
<iq:product id="descentmk2s"/>
<iq:product id="descentmk343mm"/>
<iq:product id="descentmk351mm"/>
<iq:product id="edge1030"/>
<iq:product id="edge1030bontrager"/>
<iq:product id="edge1030plus"/>
<iq:product id="edge1040"/>
<iq:product id="edge1050"/>
<iq:product id="edge520plus"/>
<iq:product id="edge530"/>
<iq:product id="edge540"/>
<iq:product id="edge820"/>
<iq:product id="edge830"/>
<iq:product id="edge840"/>
<iq:product id="edge1030"/>
<iq:product id="edge1030bontrager"/>
<iq:product id="edge1030plus"/>
<iq:product id="edge1040"/>
<iq:product id="edge1050"/>
<iq:product id="edge_520"/>
<iq:product id="edge_1000"/>
<iq:product id="edge_520"/>
<iq:product id="edgeexplore"/>
<iq:product id="edgeexplore2"/>
<iq:product id="enduro"/>
Expand Down Expand Up @@ -65,13 +65,12 @@
<iq:product id="fenix7x"/>
<iq:product id="fenix7xpro"/>
<iq:product id="fenix7xpronowifi"/>
<iq:product id="fenix8solar47mm"/>
<iq:product id="fenix8solar51mm"/>
<iq:product id="fenix843mm"/>
<iq:product id="fenix847mm"/>
<iq:product id="fenix8solar47mm"/>
<iq:product id="fenix8solar51mm"/>
<iq:product id="fenixchronos"/>
<iq:product id="fenixe"/>
<iq:product id="fr55"/>
<iq:product id="fr165"/>
<iq:product id="fr165m"/>
<iq:product id="fr230"/>
Expand All @@ -84,6 +83,7 @@
<iq:product id="fr255sm"/>
<iq:product id="fr265"/>
<iq:product id="fr265s"/>
<iq:product id="fr55"/>
<iq:product id="fr630"/>
<iq:product id="fr645"/>
<iq:product id="fr645m"/>
Expand Down Expand Up @@ -139,12 +139,14 @@
<iq:product id="vivoactive5"/>
<iq:product id="vivoactive_hr"/>
</iq:products>
<iq:permissions/>
<iq:permissions>
<iq:uses-permission id="Background"/>
</iq:permissions>
<iq:languages>
<iq:language>eng</iq:language>
<iq:language>pol</iq:language>
<iq:language>spa</iq:language>
</iq:languages>
<iq:barrels/>
</iq:application>
</iq:manifest>
</iq:manifest>
6 changes: 3 additions & 3 deletions resources/settings/settings.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<settings>
<setting propertyKey="@Properties.pomodoroLength" title="@Strings.PomodoroLength">
<settingConfig type="numeric" min="1" />
<settingConfig type="numeric" min="5" />
</setting>
<setting propertyKey="@Properties.shortBreakLength" title="@Strings.ShortBreakLength">
<settingConfig type="numeric" min="1" />
<settingConfig type="numeric" min="5" />
</setting>
<setting propertyKey="@Properties.longBreakLength" title="@Strings.LongBreakLength">
<settingConfig type="numeric" min="1" />
<settingConfig type="numeric" min="5" />
</setting>
<setting propertyKey="@Properties.numberOfPomodorosBeforeLongBreak" title="@Strings.NumberOfPomodorosBeforeLongBreak">
<settingConfig type="numeric" min="1" />
Expand Down
28 changes: 11 additions & 17 deletions source/GarmodoroApp.mc
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
using Toybox.Application as App;
using Toybox.Timer as Timer;
using Toybox.System;

(:background)
class GarmodoroApp extends App.AppBase {
function initialize() {
AppBase.initialize();
}

function initialize() {
AppBase.initialize();
}
function getInitialView() {
return [new GarmodoroView(), new GarmodoroDelegate()];
}

function onStart(state) {
timer = new Timer.Timer();
tickTimer = new Timer.Timer();
}

function onStop(state) {
tickTimer.stop();
timer.stop();
}

function getInitialView() {
return [ new GarmodoroView(), new GarmodoroDelegate() ];
}
public function getServiceDelegate() as [System.ServiceDelegate] {
return [new GarmodoroServiceDelegate()];
}
}
71 changes: 45 additions & 26 deletions source/GarmodoroDelegate.mc
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
using Toybox.Application as App;
using Toybox.Attention as Attention;
using Toybox.WatchUi as Ui;
using Toybox.System;


var timer;
var tickTimer;
var minutes = 0;
var pomodoroNumber = 1;
var isPomodoroTimerStarted = false;
var isBreakTimerStarted = false;

function ping( dutyCycle, length ) {
if ( Attention has :vibrate ) {
Expand All @@ -26,49 +24,69 @@ function idleCallback() {
}

function isLongBreak() {
return ( pomodoroNumber % App.getApp().getProperty( "numberOfPomodorosBeforeLongBreak" ) ) == 0;
var pomodoroNumber = getStorageValue(POMODORO_NUMBER_PROPERTY_STORAGE_KEY, 1);
return (
pomodoroNumber %
App.getApp().getProperty("numberOfPomodorosBeforeLongBreak") ==
0
);
}

function resetMinutes() {
minutes = App.getApp().getProperty( "pomodoroLength" );
var minutes = App.getApp().getProperty("pomodoroLength");
var minutesAsSeconds = minutes * 60;
setEndTimeBySeconds(minutesAsSeconds);
}

class GarmodoroDelegate extends Ui.BehaviorDelegate {
function initialize() {
timer = new Timer.Timer();
tickTimer = new Timer.Timer();
Ui.BehaviorDelegate.initialize();
timer.start( method( :idleCallback ), 60 * 1000, true );
}
timer.start( method( :idleCallback ), 10 * 1000, true );
var isPomodoroTimerStarted = getStorageValue(POMODORO_TIMER_STARTED_PROPERTY_STORAGE_KEY, false);
var isBreakTimerStarted = getStorageValue(BREAK_TIMER_STARTED_PROPERTY_STORAGE_KEY, false);

function pomodoroCallback() {
minutes -= 1;
if(isPomodoroTimerStarted){
pomodoroCallback();
}

if(isBreakTimerStarted){
breakCallback();
}
}

if ( minutes == 0 ) {
function pomodoroCallback() {
var seconds = getSeconds();
if (seconds <= 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;
setStorageValue(POMODORO_TIMER_STARTED_PROPERTY_STORAGE_KEY, false);
var breakLengthInMinutes = App.getApp().getProperty(
isLongBreak() ? "longBreakLength" : "shortBreakLength"
);
setEndTimeBySeconds(breakLengthInMinutes * 60);
setStorageValue(BREAK_TIMER_STARTED_PROPERTY_STORAGE_KEY, true);
timer.start( method( :breakCallback ), 10 * 1000, true );
}

Ui.requestUpdate();
}

function breakCallback() {
minutes -= 1;

if ( minutes == 0 ) {
var seconds = getSeconds();
if ( seconds <= 0 ) {
play( 7 ); // Attention.TONE_INTERVAL_ALERT
ping( 100, 1500 );
timer.stop();

isBreakTimerStarted = false;
pomodoroNumber += 1;
setStorageValue(BREAK_TIMER_STARTED_PROPERTY_STORAGE_KEY, false);
var pomodoroNumber = getStorageValue(POMODORO_NUMBER_PROPERTY_STORAGE_KEY, 1);
setStorageValue(POMODORO_NUMBER_PROPERTY_STORAGE_KEY, pomodoroNumber + 1);
setStorageValue(POMODORO_TIMER_STARTED_PROPERTY_STORAGE_KEY, true);
resetMinutes();
timer.start( method( :idleCallback ), 60 * 1000, true );
timer.start( method( :idleCallback ), 10 * 1000, true );
}

Ui.requestUpdate();
Expand Down Expand Up @@ -96,6 +114,8 @@ class GarmodoroDelegate extends Ui.BehaviorDelegate {
}

function onSelect() {
var isBreakTimerStarted = getStorageValue(BREAK_TIMER_STARTED_PROPERTY_STORAGE_KEY, false);
var isPomodoroTimerStarted = getStorageValue(POMODORO_TIMER_STARTED_PROPERTY_STORAGE_KEY, false);
if ( isBreakTimerStarted || isPomodoroTimerStarted ) {
Ui.pushView( new Rez.Menus.StopMenu(), new StopMenuDelegate(), Ui.SLIDE_UP );
return true;
Expand All @@ -105,12 +125,11 @@ class GarmodoroDelegate extends Ui.BehaviorDelegate {
ping( 75, 1500 );
timer.stop();
resetMinutes();
timer.start( method( :pomodoroCallback ), 60 * 1000, true );
timer.start( method( :pomodoroCallback ), 10 * 1000, true );
if ( me.shouldTick() ) {
tickTimer.start( method( :tickCallback ), App.getApp().getProperty( "tickFrequency" ) * 1000, true );
}
isPomodoroTimerStarted = true;

setStorageValue(POMODORO_TIMER_STARTED_PROPERTY_STORAGE_KEY, true);
Ui.requestUpdate();

return true;
Expand Down
49 changes: 49 additions & 0 deletions source/GarmodoroPersistentStorage.mc
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using Toybox.Time;
using Toybox.Background;
using Toybox.Math;
using Toybox.Application.Storage;

const ENDTIME_PROPERTY_STORAGE_KEY = "end_time";
const POMODORO_NUMBER_PROPERTY_STORAGE_KEY = "pomodoro_number";
const POMODORO_TIMER_STARTED_PROPERTY_STORAGE_KEY = "pomodoro_timer_started";
const BREAK_TIMER_STARTED_PROPERTY_STORAGE_KEY = "break_timer_started";

function setEndTimeBySeconds(seconds) {
var date =
seconds != null ? Time.now().add(new Time.Duration(seconds)).value() : null;
Storage.setValue(ENDTIME_PROPERTY_STORAGE_KEY, date);
if (Background.getTemporalEventRegisteredTime() != null) {
Background.deleteTemporalEvent();
}
if (seconds != null) {
Background.registerForTemporalEvent(new Time.Duration(seconds));
}
}

function setStorageValue(key, value) {
Storage.setValue(key, value);
}

function getStorageValue(key, defaultValue) {
var value = Storage.getValue(key);
return value != null ? value : defaultValue;
}

function getSeconds() {
var currentTime = Time.now();
var endTime = getStorageValue(ENDTIME_PROPERTY_STORAGE_KEY, null);
if (endTime == null) {
return null;
}
var remainingSeconds = endTime - currentTime.value();
return remainingSeconds;
}

function getMinutes() {
var remainingSeconds = getSeconds();
if (remainingSeconds == null) {
return null;
}
var remainingMinutes = Math.ceil(remainingSeconds.toFloat() / 60); // Convert seconds to minutes
return remainingMinutes;
}
Loading