mirror of https://github.com/espruino/BangleApps
myprofile: Add birthday setting
parent
799c0b4e89
commit
16cc803b86
|
@ -4,12 +4,14 @@ Configure your personal profile. All settings are optional and are only stored o
|
|||
|
||||
## Available settings
|
||||
|
||||
| Setting | Description | Displayed in | Stored in | Default value | How to measure |
|
||||
| ------------- | ------------------------------- | ------------------- | --------- | ------------- | ----------------------------------------------------------------- |
|
||||
| HR max | maximum heart rate | BPM | BPM | 60 | Use maximum value when exercising.<br/> If unsure set to 220-age. |
|
||||
| HR min | minimum heart rate | BPM | BPM | 200 | Measure your heart rate after waking up |
|
||||
| Stride length | distance traveled with one step | local length unit | meter | 0 (=not set) | Walk 10 steps and divide the travelled distance by 10 |
|
||||
| Setting | Description | Displayed in | Stored in | Default value | How to measure |
|
||||
| ------------- | ------------------------------- | ------------------- | ------------ | ------------- | ----------------------------------------------------------------- |
|
||||
| Birthday | Used to calculate age | year, month, day | 'YYYY-MM-DD' | 01.01.1970 | - |
|
||||
| HR max | maximum heart rate | BPM | BPM | 60 | Use maximum value when exercising.<br/> If unsure set to 220-age. |
|
||||
| HR min | minimum heart rate | BPM | BPM | 200 | Measure your heart rate after waking up |
|
||||
| Stride length | distance traveled with one step | local length unit | meter | 0 (=not set) | Walk 10 steps and divide the travelled distance by 10 |
|
||||
|
||||
## Developer notes
|
||||
|
||||
Feel free to add additional settings
|
||||
- Feel free to add additional settings.
|
||||
- For values without reasonable defaults never assume that a value is set. Always check the value before using it.
|
||||
|
|
|
@ -5,47 +5,110 @@
|
|||
minHrm: 60,
|
||||
maxHrm: 200,
|
||||
strideLength: 0, // 0 = not set
|
||||
birthday: '1970-01-01',
|
||||
}, require('Storage').readJSON(FILE, true) || {});
|
||||
|
||||
function writeProfile() {
|
||||
require('Storage').writeJSON(FILE, myprofile);
|
||||
}
|
||||
|
||||
// Show the menu
|
||||
E.showMenu({
|
||||
"" : { "title" : /*LANG*/"My Profile" },
|
||||
const ageMenu = () => {
|
||||
const date = new Date(myprofile.birthday);
|
||||
|
||||
"< Back" : () => back(),
|
||||
E.showMenu({
|
||||
"" : { "title" : /*LANG*/"Birthday" },
|
||||
|
||||
/*LANG*/'HR max': {
|
||||
format: v => /*LANG*/`${v} BPM`,
|
||||
value: myprofile.maxHrm,
|
||||
min: 30, max: 220,
|
||||
onchange: v => {
|
||||
myprofile.maxHrm = v;
|
||||
writeProfile();
|
||||
}
|
||||
},
|
||||
|
||||
/*LANG*/'HR min': {
|
||||
format: v => /*LANG*/`${v} BPM`,
|
||||
value: myprofile.minHrm,
|
||||
min: 30, max: 220,
|
||||
onchange: v => {
|
||||
myprofile.minHrm = v;
|
||||
writeProfile();
|
||||
}
|
||||
},
|
||||
|
||||
/*LANG*/"Stride length": {
|
||||
value: myprofile.strideLength,
|
||||
min:0.00,
|
||||
step:0.01,
|
||||
format: v => v ? require("locale").distance(v, 2) : '-',
|
||||
onchange: v => {
|
||||
myprofile.strideLength=v;
|
||||
writeProfile();
|
||||
"< Back" : () => {
|
||||
if (date != new Date(myprofile.birthday)) {
|
||||
if (date > new Date()) {
|
||||
E.showPrompt(/*LANG*/"Birthday must not be in future!", {
|
||||
buttons : {"Ok":true},
|
||||
}).then(() => ageMenu());
|
||||
} else {
|
||||
// Birthday changed
|
||||
const age = (new Date()).getFullYear() - date.getFullYear();
|
||||
const newMaxHRM = 220-age;
|
||||
E.showPrompt(/*LANG*/`Set HR max to ${newMaxHRM} calculated from age?`).then(function(v) {
|
||||
myprofile.birthday = date.getFullYear() + "-" + (date.getMonth() + 1).toString().padStart(2, '0') + "-" + date.getDate().toString().padStart(2, '0');
|
||||
if (v) {
|
||||
myprofile.maxHrm = newMaxHRM;
|
||||
writeProfile();
|
||||
}
|
||||
mainMenu();
|
||||
});
|
||||
}
|
||||
} else {
|
||||
mainMenu();
|
||||
}
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
/*LANG*/"Day": {
|
||||
value: date ? date.getDate() : null,
|
||||
min: 1,
|
||||
max: 31,
|
||||
wrap: true,
|
||||
onchange: v => {
|
||||
date.setDate(v);
|
||||
}
|
||||
},
|
||||
/*LANG*/"Month": {
|
||||
value: date ? date.getMonth() + 1 : null,
|
||||
format: v => require("date_utils").month(v),
|
||||
onchange: v => {
|
||||
date.setMonth((v+11)%12);
|
||||
}
|
||||
},
|
||||
/*LANG*/"Year": {
|
||||
value: date ? date.getFullYear() : null,
|
||||
min: 1900,
|
||||
max: (new Date()).getFullYear(),
|
||||
onchange: v => {
|
||||
date.setFullYear(v);
|
||||
}
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
const mainMenu = () => {
|
||||
E.showMenu({
|
||||
"" : { "title" : /*LANG*/"My Profile" },
|
||||
|
||||
"< Back" : () => back(),
|
||||
|
||||
/*LANG*/"Birthday" : () => ageMenu(),
|
||||
|
||||
/*LANG*/'HR max': {
|
||||
format: v => /*LANG*/`${v} BPM`,
|
||||
value: myprofile.maxHrm,
|
||||
min: 30, max: 220,
|
||||
onchange: v => {
|
||||
myprofile.maxHrm = v;
|
||||
writeProfile();
|
||||
}
|
||||
},
|
||||
|
||||
/*LANG*/'HR min': {
|
||||
format: v => /*LANG*/`${v} BPM`,
|
||||
value: myprofile.minHrm,
|
||||
min: 30, max: 220,
|
||||
onchange: v => {
|
||||
myprofile.minHrm = v;
|
||||
writeProfile();
|
||||
}
|
||||
},
|
||||
|
||||
/*LANG*/"Stride length": {
|
||||
value: myprofile.strideLength,
|
||||
min:0.00,
|
||||
step:0.01,
|
||||
format: v => v ? require("locale").distance(v, 2) : '-',
|
||||
onchange: v => {
|
||||
myprofile.strideLength=v;
|
||||
writeProfile();
|
||||
},
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
mainMenu();
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue