Initial UI design
This commit is contained in:
@@ -29,7 +29,13 @@
|
|||||||
],
|
],
|
||||||
"projectType": "native",
|
"projectType": "native",
|
||||||
"resources": {
|
"resources": {
|
||||||
"media": []
|
"media": [
|
||||||
|
{
|
||||||
|
"type": "raw",
|
||||||
|
"name": "SLEEP_ICON",
|
||||||
|
"file": "sleep.pdc"
|
||||||
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"sdkVersion": "3",
|
"sdkVersion": "3",
|
||||||
"targetPlatforms": [
|
"targetPlatforms": [
|
||||||
|
|||||||
BIN
resources/sleep.pdc
Normal file
BIN
resources/sleep.pdc
Normal file
Binary file not shown.
92
src/c/main.c
92
src/c/main.c
@@ -4,14 +4,16 @@
|
|||||||
|
|
||||||
// declare window statics
|
// declare window statics
|
||||||
static Window *s_main_window;
|
static Window *s_main_window;
|
||||||
static TextLayer *s_sleep_time_header_layer;
|
|
||||||
static TextLayer *s_sleep_time_layer;
|
static TextLayer *s_sleep_time_layer;
|
||||||
static TextLayer *s_last_watched_header_layer;
|
|
||||||
static TextLayer *s_last_watched_layer;
|
static TextLayer *s_last_watched_layer;
|
||||||
static TextLayer *s_pin_notice_layer;
|
static Layer *s_button_bar_layer;
|
||||||
|
static Layer *s_sleep_bar_layer;
|
||||||
|
static Layer *s_sleep_icon_layer;
|
||||||
|
static GDrawCommandImage *s_sleep_icon;
|
||||||
|
|
||||||
// declare time tracking statics
|
// declare time tracking statics
|
||||||
static time_t s_sleep_timestamp;
|
static time_t s_sleep_timestamp;
|
||||||
|
static bool s_sleep_data_accessible;
|
||||||
|
|
||||||
static void send_sleep_time_to_pkjs() {
|
static void send_sleep_time_to_pkjs() {
|
||||||
DictionaryIterator *out;
|
DictionaryIterator *out;
|
||||||
@@ -31,7 +33,7 @@ static void send_sleep_time_to_pkjs() {
|
|||||||
static void inbox_received_handler_watched(DictionaryIterator *iter, void *context) {
|
static void inbox_received_handler_watched(DictionaryIterator *iter, void *context) {
|
||||||
Tuple *watched_tuple = dict_find(iter, MESSAGE_KEY_PKJS_LAST_WATCHED);
|
Tuple *watched_tuple = dict_find(iter, MESSAGE_KEY_PKJS_LAST_WATCHED);
|
||||||
if (watched_tuple) {
|
if (watched_tuple) {
|
||||||
APP_LOG(APP_LOG_LEVEL_INFO, "Received PKJS_LAST_WATCHED, displaying...");
|
// APP_LOG(APP_LOG_LEVEL_INFO, "Received PKJS_LAST_WATCHED, displaying...");
|
||||||
text_layer_set_text(s_last_watched_layer, watched_tuple->value->cstring);
|
text_layer_set_text(s_last_watched_layer, watched_tuple->value->cstring);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -39,7 +41,7 @@ static void inbox_received_handler_watched(DictionaryIterator *iter, void *conte
|
|||||||
static void inbox_received_handler_ready(DictionaryIterator *iter, void *context) {
|
static void inbox_received_handler_ready(DictionaryIterator *iter, void *context) {
|
||||||
Tuple *ready_tuple = dict_find(iter, MESSAGE_KEY_PKJS_READY);
|
Tuple *ready_tuple = dict_find(iter, MESSAGE_KEY_PKJS_READY);
|
||||||
if (ready_tuple) {
|
if (ready_tuple) {
|
||||||
APP_LOG(APP_LOG_LEVEL_INFO, "Received PKJS_READY, calling PKJS...");
|
// APP_LOG(APP_LOG_LEVEL_INFO, "Received PKJS_READY, calling PKJS...");
|
||||||
send_sleep_time_to_pkjs();
|
send_sleep_time_to_pkjs();
|
||||||
app_message_register_inbox_received(inbox_received_handler_watched);
|
app_message_register_inbox_received(inbox_received_handler_watched);
|
||||||
}
|
}
|
||||||
@@ -56,53 +58,77 @@ static void update_sleep_time(time_t start, time_t end) {
|
|||||||
cb_update_sleep_time, NULL);
|
cb_update_sleep_time, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void button_bar_update_proc(Layer *layer, GContext *ctx) {
|
||||||
|
graphics_context_set_fill_color(ctx, GColorLiberty);
|
||||||
|
graphics_fill_rect(ctx, layer_get_bounds(layer), 0, GCornerNone);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void sleep_bar_update_proc(Layer *layer, GContext *ctx) {
|
||||||
|
graphics_context_set_fill_color(ctx, GColorVividViolet);
|
||||||
|
graphics_fill_rect(ctx, layer_get_bounds(layer), 0, GCornerNone);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void sleep_icon_update_proc(Layer *layer, GContext *ctx) {
|
||||||
|
gdraw_command_image_draw(ctx, s_sleep_icon, GPoint(0, 0));
|
||||||
|
}
|
||||||
|
|
||||||
static void main_window_load(Window *window) {
|
static void main_window_load(Window *window) {
|
||||||
s_sleep_time_header_layer = text_layer_create(GRect(6, 0, PBL_DISPLAY_WIDTH, 30));
|
// button bar
|
||||||
text_layer_set_background_color(s_sleep_time_header_layer, GColorClear);
|
s_button_bar_layer = layer_create(GRect(PBL_DISPLAY_WIDTH - 25, 0, 25, PBL_DISPLAY_HEIGHT));
|
||||||
text_layer_set_font(s_sleep_time_header_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD));
|
layer_set_update_proc(s_button_bar_layer, button_bar_update_proc);
|
||||||
text_layer_set_text(s_sleep_time_header_layer, "Last Sleep");
|
|
||||||
s_sleep_time_layer = text_layer_create(GRect(10, 24, PBL_DISPLAY_WIDTH, 30));
|
// sleep bar
|
||||||
|
s_sleep_bar_layer = layer_create(GRect(0, 0, PBL_DISPLAY_WIDTH, PBL_IF_ROUND_ELSE(49, 31)));
|
||||||
|
layer_set_update_proc(s_sleep_bar_layer, sleep_bar_update_proc);
|
||||||
|
|
||||||
|
// sleep icon
|
||||||
|
s_sleep_icon_layer = layer_create(GRect(PBL_IF_ROUND_ELSE((PBL_DISPLAY_WIDTH / 2) - 13, 4), 4, PBL_DISPLAY_WIDTH, 50));
|
||||||
|
layer_set_update_proc(s_sleep_icon_layer, sleep_icon_update_proc);
|
||||||
|
|
||||||
|
// sleep time
|
||||||
|
s_sleep_time_layer = text_layer_create(GRect(0, PBL_IF_ROUND_ELSE(24, -2), PBL_DISPLAY_WIDTH, 30));
|
||||||
text_layer_set_background_color(s_sleep_time_layer, GColorClear);
|
text_layer_set_background_color(s_sleep_time_layer, GColorClear);
|
||||||
text_layer_set_font(s_sleep_time_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24));
|
text_layer_set_font(s_sleep_time_layer, fonts_get_system_font(PBL_IF_ROUND_ELSE(FONT_KEY_GOTHIC_18_BOLD, FONT_KEY_GOTHIC_24_BOLD)));
|
||||||
|
text_layer_set_text_alignment(s_sleep_time_layer, GTextAlignmentCenter);
|
||||||
|
text_layer_set_text_color(s_sleep_time_layer, GColorWhite);
|
||||||
if (s_sleep_timestamp != 0) {
|
if (s_sleep_timestamp != 0) {
|
||||||
static char buffer[8];
|
static char buffer[8];
|
||||||
struct tm *timeinfo = localtime(&s_sleep_timestamp);
|
struct tm *timeinfo = localtime(&s_sleep_timestamp);
|
||||||
strftime(buffer, sizeof(buffer), clock_is_24h_style() ? "%H:%M" : "%I:%M", timeinfo);
|
strftime(buffer, sizeof(buffer), clock_is_24h_style() ? "%H:%M" : "%I:%M", timeinfo);
|
||||||
text_layer_set_text(s_sleep_time_layer, buffer);
|
text_layer_set_text(s_sleep_time_layer, buffer);
|
||||||
} else {
|
} else {
|
||||||
text_layer_set_text(s_sleep_time_layer, "N/A (rough night?)");
|
text_layer_set_text(s_sleep_time_layer, "No sleep last night");
|
||||||
}
|
}
|
||||||
s_last_watched_header_layer = text_layer_create(GRect(6, 72, PBL_DISPLAY_WIDTH, 30));
|
|
||||||
text_layer_set_background_color(s_last_watched_header_layer, GColorClear);
|
// watched title
|
||||||
text_layer_set_font(s_last_watched_header_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD));
|
s_last_watched_layer = text_layer_create(GRect(0, PBL_DISPLAY_HEIGHT / 2 - 24, PBL_DISPLAY_WIDTH - 4, PBL_DISPLAY_HEIGHT));
|
||||||
text_layer_set_text(s_last_watched_header_layer, "Last Episode");
|
text_layer_set_background_color(s_last_watched_layer, GColorClear);
|
||||||
s_last_watched_layer = text_layer_create(GRect(10, 96, PBL_DISPLAY_WIDTH, PBL_DISPLAY_HEIGHT));
|
text_layer_set_font(s_last_watched_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24));
|
||||||
|
if (s_sleep_data_accessible) {
|
||||||
|
text_layer_set_text(s_last_watched_layer, "N/A"); // default - will be updated before display
|
||||||
|
} else {
|
||||||
|
text_layer_set_text(s_last_watched_layer, "Sleep data inaccessible!\nEnsure Pebble Health is enabled.");
|
||||||
|
}
|
||||||
|
|
||||||
#if PBL_ROUND
|
#if PBL_ROUND
|
||||||
text_layer_set_text_alignment(s_last_watched_layer, GTextAlignmentCenter);
|
text_layer_set_text_alignment(s_last_watched_layer, GTextAlignmentCenter);
|
||||||
#endif
|
#endif
|
||||||
text_layer_set_background_color(s_last_watched_layer, GColorClear);
|
|
||||||
text_layer_set_font(s_last_watched_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24));
|
|
||||||
text_layer_set_text(s_last_watched_layer, "N/A"); // default - will be updated before display
|
|
||||||
s_pin_notice_layer = text_layer_create(GRect(0, PBL_DISPLAY_HEIGHT - 50, PBL_DISPLAY_WIDTH, 50));
|
|
||||||
text_layer_set_background_color(s_pin_notice_layer, GColorClear);
|
|
||||||
text_layer_set_font(s_pin_notice_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14));
|
|
||||||
text_layer_set_text_alignment(s_pin_notice_layer, GTextAlignmentCenter);
|
|
||||||
|
|
||||||
// add layers as children to windows
|
// add layers as children to windows
|
||||||
Layer *window_layer = window_get_root_layer(window);
|
Layer *window_layer = window_get_root_layer(window);
|
||||||
layer_add_child(window_layer, text_layer_get_layer(s_sleep_time_header_layer));
|
layer_add_child(window_layer, s_button_bar_layer);
|
||||||
|
layer_add_child(window_layer, s_sleep_bar_layer);
|
||||||
|
layer_add_child(window_layer, s_sleep_icon_layer);
|
||||||
layer_add_child(window_layer, text_layer_get_layer(s_sleep_time_layer));
|
layer_add_child(window_layer, text_layer_get_layer(s_sleep_time_layer));
|
||||||
layer_add_child(window_layer, text_layer_get_layer(s_last_watched_header_layer));
|
|
||||||
layer_add_child(window_layer, text_layer_get_layer(s_last_watched_layer));
|
layer_add_child(window_layer, text_layer_get_layer(s_last_watched_layer));
|
||||||
layer_add_child(window_layer, text_layer_get_layer(s_pin_notice_layer));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void main_window_unload(Window *window) {
|
static void main_window_unload(Window *window) {
|
||||||
text_layer_destroy(s_sleep_time_header_layer);
|
layer_destroy(s_sleep_icon_layer);
|
||||||
|
layer_destroy(s_sleep_bar_layer);
|
||||||
|
layer_destroy(s_button_bar_layer);
|
||||||
text_layer_destroy(s_sleep_time_layer);
|
text_layer_destroy(s_sleep_time_layer);
|
||||||
text_layer_destroy(s_last_watched_header_layer);
|
|
||||||
text_layer_destroy(s_last_watched_layer);
|
text_layer_destroy(s_last_watched_layer);
|
||||||
text_layer_destroy(s_pin_notice_layer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void init() {
|
static void init() {
|
||||||
@@ -120,11 +146,15 @@ static void init() {
|
|||||||
time_t end = time(NULL);
|
time_t end = time(NULL);
|
||||||
time_t start = end - (SECONDS_PER_DAY * 1.5);
|
time_t start = end - (SECONDS_PER_DAY * 1.5);
|
||||||
if (health_service_any_activity_accessible(HealthActivitySleep, start, end) == HealthServiceAccessibilityMaskAvailable) {
|
if (health_service_any_activity_accessible(HealthActivitySleep, start, end) == HealthServiceAccessibilityMaskAvailable) {
|
||||||
|
s_sleep_data_accessible = true;
|
||||||
update_sleep_time(start, end);
|
update_sleep_time(start, end);
|
||||||
} else {
|
} else {
|
||||||
APP_LOG(APP_LOG_LEVEL_DEBUG, "Sleep activity inaccessible", NULL);
|
s_sleep_data_accessible = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// load PDCs
|
||||||
|
s_sleep_icon = gdraw_command_image_create_with_resource(RESOURCE_ID_SLEEP_ICON);
|
||||||
|
|
||||||
window_stack_push(s_main_window, true);
|
window_stack_push(s_main_window, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ function callAPI(fullURL, apiKey, isJellyfin, trackedUser, sleepTimestamp) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (lastWatched != "") {
|
if (lastWatched != "") {
|
||||||
console.log("Last watched: " + lastWatched);
|
//console.log("Last watched: " + lastWatched);
|
||||||
var dict = { 'PKJS_LAST_WATCHED': lastWatched }
|
var dict = { 'PKJS_LAST_WATCHED': lastWatched }
|
||||||
Pebble.sendAppMessage(dict);
|
Pebble.sendAppMessage(dict);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user