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
1 change: 1 addition & 0 deletions source/Delegates/SettingsDelegate.mc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//Unused. Previous placeholder
import Toybox.Lang;
import Toybox.System;
import Toybox.WatchUi;
Expand Down
55 changes: 55 additions & 0 deletions source/Delegates/SettingsMenuDelegate.mc
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import Toybox.WatchUi;
import Toybox.Application;
import Toybox.Lang;

class SettingsMenuDelegate extends WatchUi.Menu2InputDelegate {

function initialize(menu as WatchUi.Menu2) {
Menu2InputDelegate.initialize();
}

function onSelect(item) as Void {
var id = item.getId();

if (id == :settings_cadence) {
var app = Application.getApp() as GarminApp;
var minCadence = app.getMinCadence();
var maxCadence = app.getMaxCadence();

var cadenceMenu = new WatchUi.Menu2({
:title => Lang.format("Cadence: $1$ - $2$", [minCadence, maxCadence])
});

cadenceMenu.addItem(new WatchUi.MenuItem("Min +5", null, :item_inc_min, null));
cadenceMenu.addItem(new WatchUi.MenuItem("Min -5", null, :item_dec_min, null));
cadenceMenu.addItem(new WatchUi.MenuItem("Max +5", null, :item_inc_max, null));
cadenceMenu.addItem(new WatchUi.MenuItem("Max -5", null, :item_dec_max, null));

WatchUi.pushView(cadenceMenu, new SelectCadenceDelegate(cadenceMenu), WatchUi.SLIDE_LEFT);
return;
}

if (id == :settings_reset_stats) {
var app = Application.getApp() as GarminApp;
app.resetStatistics();

WatchUi.requestUpdate();

//Show confirmation screen
var done = new WatchUi.Menu2({ :title => "Reset" });
done.addItem(new WatchUi.MenuItem("Statistics cleared", null, :ok, null));
WatchUi.pushView(done, new StaticMenuDelegate(done), WatchUi.SLIDE_LEFT);

return;
}

//Alerts/Brightness/Font Size: placeholder for now
var todo = new WatchUi.Menu2({ :title => "Coming soon" });
todo.addItem(new WatchUi.MenuItem("Not implemented yet", null, :todo, null));
WatchUi.pushView(todo, new StaticMenuDelegate(todo), WatchUi.SLIDE_LEFT);
}

function onBack() as Void {
WatchUi.popView(WatchUi.SLIDE_DOWN);
}
}
21 changes: 13 additions & 8 deletions source/Delegates/SimpleViewDelegate.mc
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,24 @@ class SimpleViewDelegate extends WatchUi.BehaviorDelegate {
BehaviorDelegate.initialize();
}

function onMenu() as Boolean {
var settingsView = new SettingsView();

//Switches the screen to settings view by holding up button
WatchUi.pushView(settingsView, new SettingsDelegate(settingsView), WatchUi.SLIDE_UP);
function onMenu() as Boolean {

return true;
}
var menu = new WatchUi.Menu2({ :title => "Settings" });

menu.addItem(new WatchUi.MenuItem("Cadence Threshold", null, :settings_cadence, null));
menu.addItem(new WatchUi.MenuItem("Alerts", null, :settings_alerts, null));
menu.addItem(new WatchUi.MenuItem("Brightness", null, :settings_brightness, null));
menu.addItem(new WatchUi.MenuItem("Font Size", null, :settings_font_size, null));
menu.addItem(new WatchUi.MenuItem("Reset Statistics", null, :settings_reset_stats, null));
//Switches the screen to settings view by holding up button
WatchUi.pushView(menu, new SettingsMenuDelegate(menu), WatchUi.SLIDE_UP);
return true;
}

function onNextPage() as Boolean {
var advancedView = new AdvancedView();

// Switches the screen to advanced view by holding down button
//Switches the screen to advanced view by holding down button
WatchUi.pushView(advancedView, new AdvancedViewDelegate(advancedView), WatchUi.SLIDE_DOWN);

return true;
Expand Down
19 changes: 19 additions & 0 deletions source/Delegates/StaticMenuDelegate.mc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import Toybox.WatchUi;

class StaticMenuDelegate extends WatchUi.Menu2InputDelegate {

private var _menu as WatchUi.Menu2;

function initialize(menu as WatchUi.Menu2) {
Menu2InputDelegate.initialize();
_menu = menu;
}

function onSelect(item) as Void {
//Placeholder: do nothing for now
}

function onBack() as Void {
WatchUi.popView(WatchUi.SLIDE_DOWN);
}
}
30 changes: 30 additions & 0 deletions source/GarminApp.mc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ class GarminApp extends Application.AppBase {
const BASELINE_AVG_CADENCE = 150;
const HEIGHT_BASELINE = 170;
const STEP_RATE = 6;
//for persistent settings
const PROP_MIN_CADENCE = "minCadence";
const PROP_MAX_CADENCE = "maxCadence";

private var _idealMinCadence = 90;
private var _idealMaxCadence = 100;
Expand All @@ -33,6 +36,7 @@ class GarminApp extends Application.AppBase {

// onStart() is called on application start up
function onStart(state as Dictionary?) as Void {
loadSettings();
_historyTimer = new Timer.Timer();
_historyTimer.start(method(:updateZoneHistory), 1000, true);
}
Expand All @@ -44,6 +48,23 @@ class GarminApp extends Application.AppBase {
}
}

//Persistent Settings
function loadSettings() as Void {
var min = Application.Storage.getValue(PROP_MIN_CADENCE);
var max = Application.Storage.getValue(PROP_MAX_CADENCE);

if (min != null) { _idealMinCadence = min as Number; }
if (max != null) { _idealMaxCadence = max as Number; }
if (_idealMinCadence >= _idealMaxCadence) {
_idealMinCadence = 90;
_idealMaxCadence = 100;
}
}

function saveSettings() as Void {
Application.Storage.setValue(PROP_MIN_CADENCE, _idealMinCadence);
Application.Storage.setValue(PROP_MAX_CADENCE, _idealMaxCadence);
}

// Zone history management
function updateZoneHistory() as Void {
Expand All @@ -60,6 +81,13 @@ class GarminApp extends Application.AppBase {

}

//Reset Statistics
function resetStatistics() as Void {
_zoneHistory = new [MAX_BARS];
_historyIndex = 0;
_historyCount = 0;
}

function getMinCadence() as Number {
return _idealMinCadence;
}
Expand All @@ -70,10 +98,12 @@ class GarminApp extends Application.AppBase {

function setMinCadence(value as Number) as Void {
_idealMinCadence = value;
saveSettings();
}

function setMaxCadence(value as Number) as Void {
_idealMaxCadence = value;
saveSettings();
}

function getZoneHistory() as Array<Float?> {
Expand Down
1 change: 1 addition & 0 deletions source/Views/SettingsView.mc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//Unused. Previous placeholder
import Toybox.Graphics;
import Toybox.WatchUi;
import Toybox.System;
Expand Down