diff --git a/source/Delegates/SettingsDelegate.mc b/source/Delegates/SettingsDelegate.mc index 8caa6df..95da6fc 100644 --- a/source/Delegates/SettingsDelegate.mc +++ b/source/Delegates/SettingsDelegate.mc @@ -1,3 +1,4 @@ +//Unused. Previous placeholder import Toybox.Lang; import Toybox.System; import Toybox.WatchUi; diff --git a/source/Delegates/SettingsMenuDelegate.mc b/source/Delegates/SettingsMenuDelegate.mc new file mode 100644 index 0000000..2638db9 --- /dev/null +++ b/source/Delegates/SettingsMenuDelegate.mc @@ -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); + } +} \ No newline at end of file diff --git a/source/Delegates/SimpleViewDelegate.mc b/source/Delegates/SimpleViewDelegate.mc index 07b0876..230fad4 100644 --- a/source/Delegates/SimpleViewDelegate.mc +++ b/source/Delegates/SimpleViewDelegate.mc @@ -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; diff --git a/source/Delegates/StaticMenuDelegate.mc b/source/Delegates/StaticMenuDelegate.mc new file mode 100644 index 0000000..59abb24 --- /dev/null +++ b/source/Delegates/StaticMenuDelegate.mc @@ -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); + } +} diff --git a/source/GarminApp.mc b/source/GarminApp.mc index c086aac..1a3a8f6 100644 --- a/source/GarminApp.mc +++ b/source/GarminApp.mc @@ -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; @@ -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); } @@ -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 { @@ -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; } @@ -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 { diff --git a/source/Views/SettingsView.mc b/source/Views/SettingsView.mc index 54234bc..4fd71c2 100644 --- a/source/Views/SettingsView.mc +++ b/source/Views/SettingsView.mc @@ -1,3 +1,4 @@ +//Unused. Previous placeholder import Toybox.Graphics; import Toybox.WatchUi; import Toybox.System;