Skip to content

Commit

Permalink
Now saving last meditation session selected. Added 45min and 1h medit…
Browse files Browse the repository at this point in the history
…ation session times. Added time including hours/minutes in saved activity name for Garmin Connect (notice that it will use default session time because it is not possible to update the session once it started recording).
  • Loading branch information
dliedke committed Jul 23, 2022
1 parent 7a35105 commit 29bbc58
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Meditate/manifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<!-- This is a generated file. It is highly recommended that you DO NOT edit this file. -->
<iq:manifest xmlns:iq="http://www.garmin.com/xml/connectiq" version="3">
<iq:application entry="MeditateApp" id="57843a03841b4410aff4e4c427c42caf" launcherIcon="@Drawables.launcherIcon" minSdkVersion="1.4.0" name="@Strings.AppName" type="watch-app" version="2.7.0">
<iq:application entry="MeditateApp" id="57843a03841b4410aff4e4c427c42caf" launcherIcon="@Drawables.launcherIcon" minSdkVersion="1.4.0" name="@Strings.AppName" type="watch-app" version="2.8.0">
<iq:products>
<iq:product id="fr235"/>
</iq:products>
Expand Down
19 changes: 19 additions & 0 deletions Meditate/source/TimeFormatter.mc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,25 @@ class TimeFormatter {
return formattedTime;
}

static function formatHours(timeInSec) {
var timeCalc = timeInSec;
var seconds = timeCalc % 60;
timeCalc /= 60;
var minutes = timeCalc % 60;
timeCalc /= 60;
var hours = timeCalc % 24;

var formattedTime;

if (hours == 1) {
formattedTime = Lang.format("$1$ hour", [hours.format("%02d")]);
} else {
formattedTime = Lang.format("$1$ hours", [hours.format("%02d")]);
}

return formattedTime;
}

static function formatMinutes(timeInSec) {
var timeCalc = timeInSec;
var seconds = timeCalc % 60;
Expand Down
25 changes: 24 additions & 1 deletion Meditate/source/activity/MeditateActivity.mc
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,34 @@ class MediteActivity extends HrvAlgorithms.HrvAndStressActivity {
function initialize(meditateModel, heartbeatIntervalsSensor) {

var fitSessionSpec;
fitSessionSpec = HrvAlgorithms.FitSessionSpec.createCardio("Meditating");
var sessionTime = meditateModel.getSessionTime();
fitSessionSpec = HrvAlgorithms.FitSessionSpec.createCardio(createSessionName(sessionTime, "Meditating"));

me.mMeditateModel = meditateModel;
HrvAlgorithms.HrvAndStressActivity.initialize(fitSessionSpec, meditateModel.getHrvTracking(), heartbeatIntervalsSensor);
}

protected function createSessionName(sessionTime, activityName) {

// Calculate session minutes and hours
var sessionTimeMinutes = Math.round(sessionTime / 60);
var sessionTimeHours = Math.round(sessionTimeMinutes / 60);
var sessionName;

// Create the Connect activity name showing the number of hours/minutes for the meditate session
if (sessionTimeHours == 0) {
sessionName = Lang.format("$1$ $2$min 🙏", [activityName, sessionTimeMinutes]);
} else {
sessionTimeMinutes = sessionTimeMinutes % 60;
if (sessionTimeMinutes == 0){
sessionName = Lang.format("$1$ $2$h 🙏", [activityName, sessionTimeHours]);
} else {
sessionName = Lang.format("$1$ $2$h $3$min 🙏", [activityName, sessionTimeHours, sessionTimeMinutes]);
}
}

return sessionName;
}

protected function onBeforeStart(fitSession) {
mMeditateModel.isTimerRunning = true;
Expand Down
38 changes: 18 additions & 20 deletions Meditate/source/sessionSettings/SessionModel.mc
Original file line number Diff line number Diff line change
Expand Up @@ -95,33 +95,31 @@ class SessionModel {
me.activityType = "Meditate";
}

// 15s for testing
// 45min
if (index == 6) {
me.time = 45 * 60;
me.color = Gfx.COLOR_GREEN;
me.vibePattern = VibePattern.LongContinuous;
me.activityType = "Meditate";
}

// 1h
if (index == 7) {
me.time = 60 * 60;
me.color = Gfx.COLOR_YELLOW;
me.vibePattern = VibePattern.LongContinuous;
me.activityType = "Meditate";
}

// 15s for testing
if (index == 8) {
me.time = 15;
me.color = Gfx.COLOR_GREEN;
me.vibePattern = VibePattern.LongContinuous;
me.activityType = "Meditate";
}
}

function copyNonNullFieldsFromSession(otherSession) {
if (otherSession.time != null) {
me.time = otherSession.time;
}
if (otherSession.color != null) {
me.color = otherSession.color;
}
if (otherSession.vibePattern != null) {
me.vibePattern = otherSession.vibePattern;
}
if (otherSession.activityType != null) {
me.activityType = otherSession.activityType;
}
if (otherSession.hrvTracking != null) {
me.hrvTracking = otherSession.hrvTracking;
}
}


var time;
var color;
var vibePattern;
Expand Down
6 changes: 4 additions & 2 deletions Meditate/source/sessionSettings/SessionPickerDelegate.mc
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,10 @@ class SessionPickerDelegate extends ScreenPicker.ScreenPickerDelegate {
details.title = activityTypeText + " " + (me.mSelectedPageIndex + 1);
details.titleColor = session.color;

if (session.time > 59) {
details.detailLines[1].value.text = " " + TimeFormatter.formatMinutes(session.time);
if (session.time >= 60*60) {
details.detailLines[1].value.text = " " + TimeFormatter.formatHours(session.time);
} else if (session.time > 59) {
details.detailLines[1].value.text = " " + TimeFormatter.formatMinutes(session.time);
} else {
details.detailLines[1].value.text = " " + TimeFormatter.formatSeconds(session.time);
}
Expand Down
17 changes: 13 additions & 4 deletions Meditate/source/storage/SessionStorage.mc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ using Toybox.Graphics as Gfx;
class SessionStorage {
function initialize() {
mSelectedSessionIndex = 0;
me.mSessionsCount = 7;
me.mSessionsCount = 9;
me.loadSelectedSession();
}

Expand All @@ -13,21 +13,30 @@ class SessionStorage {

function selectSession(index) {
me.mSelectedSessionIndex = index;
App.getApp().setProperty("meditateApp_selectedSession", index);
}

function loadSelectedSession() {

var sessionIndex = App.getApp().getProperty("meditateApp_selectedSession");

if (sessionIndex == null) {
me.mSelectedSessionIndex = 0;
} else {
me.mSelectedSessionIndex = sessionIndex;
}

var session = new SessionModel();
session.reset(me.mSelectedSessionIndex);
return session;

}

function getSessionsCount() {
return 7;
return 9;
}

function getSelectedSessionIndex() {
return 0;
return me.mSelectedSessionIndex;
}
}

0 comments on commit 29bbc58

Please sign in to comment.