Skip to content
This repository has been archived by the owner on Apr 27, 2020. It is now read-only.

Modify app glance #9

Merged
merged 6 commits into from
Dec 5, 2016
Merged
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
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
"breathsPerMinute",
"vibrationType",
"displayText",
"heartRateVariation"
"heartRateVariation",
"appGlanceEnabled",
"appGlanceType"
],
"projectType": "native",
"resources": {
Expand Down
64 changes: 45 additions & 19 deletions src/c/localize.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,53 @@ const char * localize_get_locale() {
return i18n_get_system_locale();
}

char * localize_get_app_glance_text(int minutes) {
switch (minutes) {
case 1:
if (strncmp(localize_get_locale(), "fr", 2) == 0) {
return "Dernière session: %d minute. Respirez maintenant!";
} else if (strncmp(localize_get_locale(), "es", 2) == 0) {
return "Última sesión: %d minuto. ¡Respira ahora!";
} else if (strncmp(localize_get_locale(), "de", 2) == 0) {
return "Letzte Sitzung: %d Minute. Atme jetzt!";
} else {
return "Last session: %d minute. Breathe now!";
char * localize_get_app_glance_text(int type, int minutes) {
switch (type) {
case 0:
switch (minutes) {
case 1:
if (strncmp(localize_get_locale(), "fr", 2) == 0) {
return "Dernière session: %d minute. Respirez maintenant!";
} else if (strncmp(localize_get_locale(), "es", 2) == 0) {
return "Última sesión: %d minuto. ¡Respira ahora!";
} else if (strncmp(localize_get_locale(), "de", 2) == 0) {
return "Letzte Sitzung: %d Minute. Atme jetzt!";
} else {
return "Last session: %d minute. Breathe now!";
}
default:
if (strncmp(localize_get_locale(), "fr", 2) == 0) {
return "Dernière session: %d minutes. Respirez maintenant!";
} else if (strncmp(localize_get_locale(), "es", 2) == 0) {
return "Última sesión: %d minutos. ¡Respira ahora!";
} else if (strncmp(localize_get_locale(), "de", 2) == 0) {
return "Letzte Sitzung: %d Minuten. Atme jetzt!";
} else {
return "Last session: %d minutes. Breathe now!";
}
}
default:
if (strncmp(localize_get_locale(), "fr", 2) == 0) {
return "Dernière session: %d minutes. Respirez maintenant!";
} else if (strncmp(localize_get_locale(), "es", 2) == 0) {
return "Última sesión: %d minutos. ¡Respira ahora!";
} else if (strncmp(localize_get_locale(), "de", 2) == 0) {
return "Letzte Sitzung: %d Minuten. Atme jetzt!";
} else {
return "Last session: %d minutes. Breathe now!";
switch (minutes) {
case 1:
if (strncmp(localize_get_locale(), "fr", 2) == 0) {
return "Total actuel: %d minute. Respirez maintenant!";
} else if (strncmp(localize_get_locale(), "es", 2) == 0) {
return "Total actual: %d minuto. ¡Respira ahora!";
} else if (strncmp(localize_get_locale(), "de", 2) == 0) {
return "Aktuelle Summe: %d Minute. Atme jetzt!";
} else {
return "Current total: %d minute. Breathe now!";
}
default:
if (strncmp(localize_get_locale(), "fr", 2) == 0) {
return "Total actuel: %d minutes. Respirez maintenant!";
} else if (strncmp(localize_get_locale(), "es", 2) == 0) {
return "Total actual: %d minutos. ¡Respira ahora!";
} else if (strncmp(localize_get_locale(), "de", 2) == 0) {
return "Aktuelle Summe: %d Minuten. Atme jetzt!";
} else {
return "Current total: %d minutes. Breathe now!";
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/c/localize.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const char * localize_get_locale();

char * localize_get_app_glance_text(int minutes);
char * localize_get_app_glance_text(int type, int minutes);
char * localize_get_breathe_text();
char * localize_get_well_done_text();
char * localize_get_inhale_text();
Expand Down
17 changes: 14 additions & 3 deletions src/c/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,20 @@ static void deinit() {
#if PBL_API_EXISTS(health_service_set_heart_rate_sample_period)
health_service_set_heart_rate_sample_period(0); // Reset heart rate sample period to default as to not waste too much battery
#endif
char app_glance_text[79];
snprintf(app_glance_text, sizeof(app_glance_text), localize_get_app_glance_text(data_read_last_duration_data()), data_read_last_duration_data());
app_glance_reload(appglance_update_app_glance, app_glance_text); // Reload app glance

if (settings_get_appGlanceEnabled()) { // Check if app glance is enabled
char app_glance_text[79];
if (settings_get_appGlanceType() == 0) { // Show last session time on app glance
snprintf(app_glance_text, sizeof(app_glance_text), localize_get_app_glance_text(settings_get_appGlanceType(), data_read_last_duration_data()), data_read_last_duration_data());
}
else { // Show total daily time on app glance
snprintf(app_glance_text, sizeof(app_glance_text), localize_get_app_glance_text(settings_get_appGlanceType(), data_read_breathe_persist_data()), data_read_breathe_persist_data());
}
app_glance_reload(appglance_update_app_glance, app_glance_text); // Reload app glance
}
else {
app_glance_reload(appglance_update_app_glance, NULL); // Clear app glance completely
}
}

int main(void) {
Expand Down
20 changes: 20 additions & 0 deletions src/c/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ void settings_init() {
settings.reminderHoursStart = 8;
settings.breathsPerMinute = 7;
settings.heartRateVariation = false;
settings.appGlanceEnabled = true;
settings.appGlanceType = 0;
persist_read_data(SETTINGS_KEY, &settings, sizeof(settings));
}

Expand Down Expand Up @@ -97,6 +99,16 @@ void settings_handle_settings(DictionaryIterator *iter, void *context) {
if (heart_rate_variation_t) {
settings.heartRateVariation = heart_rate_variation_t->value->int32 == 1;
}

Tuple *app_glance_enabled_t = dict_find(iter, MESSAGE_KEY_appGlanceEnabled);
if (app_glance_enabled_t) {
settings.appGlanceEnabled = app_glance_enabled_t->value->int32 == 1;
}

Tuple *app_glance_type_t = dict_find(iter, MESSAGE_KEY_appGlanceType);
if (app_glance_type_t) {
settings.appGlanceType = app_glance_type_t->value->int8;
}
}

GColor settings_get_backgroundColor() {
Expand Down Expand Up @@ -201,4 +213,12 @@ int settings_get_breathDuration() {

bool settings_get_heartRateVariation() {
return settings.heartRateVariation;
}

bool settings_get_appGlanceEnabled() {
return settings.appGlanceEnabled;
}

int settings_get_appGlanceType() {
return settings.appGlanceType;
}
6 changes: 5 additions & 1 deletion src/c/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ typedef struct ClaySettings {
int reminderHoursStart;
int breathsPerMinute;
bool heartRateVariation;
bool appGlanceEnabled;
int appGlanceType;
} ClaySettings;

void settings_init();
Expand All @@ -34,4 +36,6 @@ bool settings_get_rememberDuration();
int settings_get_reminderHoursStart();
int settings_get_breathsPerMinute();
int settings_get_breathDuration();
bool settings_get_heartRateVariation();
bool settings_get_heartRateVariation();
bool settings_get_appGlanceEnabled();
int settings_get_appGlanceType();
31 changes: 31 additions & 0 deletions src/pkjs/config-de.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,37 @@ module.exports = [
}
]
},
{
"type": "section",
"items": [
{
"type": "heading",
"defaultValue": "App-Blick",
},
{
"type": "toggle",
"messageKey": "appGlanceEnabled",
"defaultValue": true,
"label": "App-Blick-Text im app Menü anzeigen",
},
{
"type": "select",
"messageKey": "appGlanceType",
"defaultValue": "0",
"label": "App-Blick-Typ",
"options": [
{
"label": "Letzte Sitzung Mal",
"value": "0"
},
{
"label": "Aktuelle tägliche Summe",
"value": "1"
}
]
},
]
},
{
"type": "text",
"defaultValue": "<em><center>Vielen Dank an die Betatester: <br>Paula&nbsp;Bosca, Nikita&nbsp;Cheng, Ayush&nbsp;Gupta, Ellen&nbsp;Huang, Yvonne&nbsp;Tan, David&nbsp;Voicu, /u/dryingsocks, and /u/PiwwowPants.</center></em>",
Expand Down
31 changes: 31 additions & 0 deletions src/pkjs/config-es.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,37 @@ module.exports = [
}
]
},
{
"type": "section",
"items": [
{
"type": "heading",
"defaultValue": "Vista de la aplicación",
},
{
"type": "toggle",
"messageKey": "appGlanceEnabled",
"defaultValue": true,
"label": "Mostrar la aplicación breve texto en el menú de la aplicación",
},
{
"type": "select",
"messageKey": "appGlanceType",
"defaultValue": "0",
"label": "Tipo de vista de la aplicación",
"options": [
{
"label": "Último tiempo de la sesión",
"value": "0"
},
{
"label": "Total diario actual",
"value": "1"
}
]
},
]
},
{
"type": "text",
"defaultValue": "<em><center>Muchas gracias a los probadores beta: <br>Paula&nbsp;Bosca, Nikita&nbsp;Cheng, Ayush&nbsp;Gupta, Ellen&nbsp;Huang, Yvonne&nbsp;Tan, David&nbsp;Voicu, /u/dryingsocks, y /u/PiwwowPants</center></em>",
Expand Down
31 changes: 31 additions & 0 deletions src/pkjs/config-fr.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,37 @@ module.exports = [
}
]
},
{
"type": "section",
"items": [
{
"type": "heading",
"defaultValue": "Coup de œil App",
},
{
"type": "toggle",
"messageKey": "appGlanceEnabled",
"defaultValue": true,
"label": "Afficher app bref texte dans le menu app",
},
{
"type": "select",
"messageKey": "appGlanceType",
"defaultValue": "0",
"label": "Type de regard app",
"options": [
{
"label": "Dernière session fois",
"value": "0"
},
{
"label": "Total quotidien actuel",
"value": "1"
}
]
},
]
},
{
"type": "text",
"defaultValue": "<em><center>Un grand merci aux bêta-testeurs: <br>Paula&nbsp;Bosca, Nikita&nbsp;Cheng, Ayush&nbsp;Gupta, Ellen&nbsp;Huang, Yvonne&nbsp;Tan, David&nbsp;Voicu, /u/dryingsocks, et /u/PiwwowPants</center></em>",
Expand Down
31 changes: 31 additions & 0 deletions src/pkjs/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,37 @@ module.exports = [
}
]
},
{
"type": "section",
"items": [
{
"type": "heading",
"defaultValue": "App Glance",
},
{
"type": "toggle",
"messageKey": "appGlanceEnabled",
"defaultValue": true,
"label": "Display app glance text in the app menu",
},
{
"type": "select",
"messageKey": "appGlanceType",
"defaultValue": "0",
"label": "App Glance Type",
"options": [
{
"label": "Last session time",
"value": "0"
},
{
"label": "Current daily total",
"value": "1"
}
]
},
]
},
{
"type": "text",
"defaultValue": "<em><center>Many thanks to the beta testers: <br>Paula&nbsp;Bosca, Nikita&nbsp;Cheng, Ayush&nbsp;Gupta, Ellen&nbsp;Huang, Yvonne&nbsp;Tan, David&nbsp;Voicu, /u/dryingsocks, and /u/PiwwowPants.</center></em>",
Expand Down
12 changes: 12 additions & 0 deletions src/pkjs/custom-clay.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ module.exports = function(minified) {
}
}

function toggleAppGlance() {
if (this.get() !== false) {
clayConfig.getItemByMessageKey('appGlanceType').enable();
} else {
clayConfig.getItemByMessageKey('appGlanceType').disable();
}
}

clayConfig.on(clayConfig.EVENTS.AFTER_BUILD, function() {
var reminderSelect = clayConfig.getItemByMessageKey('reminderHours');
toggleReminder.call(reminderSelect);
Expand All @@ -28,5 +36,9 @@ module.exports = function(minified) {
var vibrationEnabledToggle = clayConfig.getItemByMessageKey('vibrationEnabled');
toggleVibration.call(vibrationEnabledToggle);
vibrationEnabledToggle.on('change', toggleVibration);

var appGlanceEnabledToggle = clayConfig.getItemByMessageKey('appGlanceEnabled');
toggleAppGlance.call(appGlanceEnabledToggle);
appGlanceEnabledToggle.on('change', toggleAppGlance);
});
};
3 changes: 3 additions & 0 deletions src/pkjs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Pebble.addEventListener('webviewclosed', function(e) {
dict[messageKeys.reminderHours] = parseInt(dict[messageKeys.reminderHours]);
dict[messageKeys.displayText] = parseInt(dict[messageKeys.displayText]);
dict[messageKeys.vibrationType] = parseInt(dict[messageKeys.vibrationType]);
dict[messageKeys.appGlanceType] = parseInt(dict[messageKeys.appGlanceType]);

// Log all the settings for fun
console.log('The reminderHours sent to Pebble is ' + dict[messageKeys.reminderHours] + '.');
Expand All @@ -51,6 +52,8 @@ Pebble.addEventListener('webviewclosed', function(e) {
console.log('The reminderHoursStart sent to Pebble is ' + dict[messageKeys.reminderHoursStart] + '.');
console.log('The breathsPerMinute sent to Pebble is ' + dict[messageKeys.breathsPerMinute] + '.');
console.log('The heartRateVariation sent to Pebble is ' + dict[messageKeys.heartRateVariation] + '.');
console.log('The appGlanceEnabled sent to Pebble is ' + dict[messageKeys.appGlanceEnabled] + '.');
console.log('The appGlanceType sent to Pebble is ' + dict[messageKeys.appGlanceType] + '.');

// Send settings values to watch side
Pebble.sendAppMessage(dict, function(e) {
Expand Down