From 215af945b566042ddc953449cd29fb12b6d84660 Mon Sep 17 00:00:00 2001 From: wildhart Date: Thu, 29 Oct 2015 14:09:38 +1300 Subject: [PATCH] Use cached platforms every time, tidy alarm window --- appinfo.json | 32 ++++++++++++++++---------------- src/main.c | 20 +++++++++++++++----- src/pebble-js-app.js | 20 ++++++++++++-------- 3 files changed, 43 insertions(+), 29 deletions(-) diff --git a/appinfo.json b/appinfo.json index 226fd81..3db4e0e 100644 --- a/appinfo.json +++ b/appinfo.json @@ -18,19 +18,18 @@ "resources": { "media": [ { - "file": "images/down.png", - "name": "IMAGE_DOWN", + "file": "images/up.png", + "name": "IMAGE_UP", "type": "png" }, { - "file": "images/menu_icon.png", - "menuIcon": true, - "name": "IMAGE_APP_ICON", + "file": "images/tick.png", + "name": "IMAGE_TICK", "type": "png" }, { - "file": "images/bell.png", - "name": "IMAGE_BELL", + "file": "images/right.png", + "name": "IMAGE_RIGHT", "type": "png" }, { @@ -44,23 +43,24 @@ "type": "png" }, { - "file": "images/tick.png", - "name": "IMAGE_TICK", + "file": "images/option_menu_box.png", + "name": "IMAGE_OPTION_BOX", "type": "png" }, { - "file": "images/right.png", - "name": "IMAGE_RIGHT", + "file": "images/menu_icon.png", + "menuIcon": true, + "name": "IMAGE_APP_ICON", "type": "png" }, { - "file": "images/up.png", - "name": "IMAGE_UP", + "file": "images/down.png", + "name": "IMAGE_DOWN", "type": "png" }, { - "file": "images/option_menu_box.png", - "name": "IMAGE_OPTION_BOX", + "file": "images/bell.png", + "name": "IMAGE_BELL", "type": "png" } ] @@ -69,7 +69,7 @@ "shortName": "Chch Bus", "uuid": "6094e32b-cc6b-40cb-8761-2dc79d8ee554", "versionCode": 1, - "versionLabel": "1.32", + "versionLabel": "1.33", "watchapp": { "watchface": false } diff --git a/src/main.c b/src/main.c index 812c3b6..e39de5d 100644 --- a/src/main.c +++ b/src/main.c @@ -1284,22 +1284,32 @@ static void distance_layer_update_callback(Layer *layer, GContext *ctx) { // scr GFont font_roboto_condensed_21 = fonts_get_system_font(FONT_KEY_ROBOTO_CONDENSED_21); GFont font_gothic_18 = fonts_get_system_font(FONT_KEY_GOTHIC_18); - GRect gr_road = GRect(2, 20, 120, 24); - GRect gr_name = GRect(2, 44, 120, 20); + GRect gr_road = GRect(3, 20, 118-17, 24); + GRect gr_name = GRect(3, 44, 118, 20); + GRect gr_heading = GRect(3+118-20, 20, 20, 24); GRect gr_alarm = GRect(60, 125, 60, 21); GRect gr_invert; char text[10]; if (distance_selection==0) { - gr_invert=GRect(gr_road.origin.x, gr_road.origin.y+5, gr_road.size.w, gr_name.origin.y+gr_name.size.h-gr_road.origin.y); + gr_invert=GRect(gr_road.origin.x-1, gr_road.origin.y+5, gr_name.size.w+2, gr_name.origin.y+gr_name.size.h-gr_road.origin.y); } else if (distance_selection==1) { gr_invert = GRect(64, 126, 58, 24); } graphics_fill_rect(ctx, gr_invert, 2, GCornersAll); + char road_only[MAX_ROAD_LENGTH+1]; + strncpy(road_only,platforms[distance_alarm.Platform_index].Road,MAX_ROAD_LENGTH); + char *heading=strstr(road_only," -"); + if (heading) { + *heading='\0'; + heading+=3; + } + graphics_context_set_text_color(ctx, distance_selection==0?GColorWhite:GColorBlack); - graphics_draw_text(ctx, platforms[distance_alarm.Platform_index].Road, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), gr_road, GTextOverflowModeFill, GTextAlignmentCenter, NULL); - graphics_draw_text(ctx, platforms[distance_alarm.Platform_index].Name, font_gothic_18, gr_name, GTextOverflowModeFill, GTextAlignmentCenter, NULL); + graphics_draw_text(ctx, road_only, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), gr_road, GTextOverflowModeFill, GTextAlignmentLeft, NULL); + if (heading) graphics_draw_text(ctx, heading, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), gr_heading, GTextOverflowModeFill, GTextAlignmentRight, NULL); + graphics_draw_text(ctx, platforms[distance_alarm.Platform_index].Name, font_gothic_18, gr_name, GTextOverflowModeFill, GTextAlignmentLeft, NULL); graphics_context_set_text_color(ctx, distance_selection==1?GColorWhite:GColorBlack); if (distance_alarm.km) snprintf(text,10,"%d km",distance_alarm.km); else snprintf(text,10,"off"); diff --git a/src/pebble-js-app.js b/src/pebble-js-app.js index a1d9a06..592ffaa 100644 --- a/src/pebble-js-app.js +++ b/src/pebble-js-app.js @@ -264,10 +264,15 @@ function distance(lat1, lon1, lat2, lon2) { // all parameters should already be function get_platforms(reason) { var date=new Date(); var old_date=localStorage.getItem("platforms_date"); - if (old_date && (date-old_date) < 7 * 24 * 60 * 60 * 1000 ) { // if data is less than 7 days old (in milliseconds) - console.log("Using cached platform data"); + if (old_date) { + console.log("Parsing cached platform data"); parse_platforms(localStorage.getItem('platforms'), reason); - return; + if ((date-old_date) < 7 * 24 * 60 * 60 * 1000 ) { // if data is less than 7 days old (in milliseconds) + return; + } else { + console.log("Cache is old."); + reason=''; + } } var req = new XMLHttpRequest(); req.open('GET', 'http://rtt.metroinfo.org.nz/rtt/public/utility/file.aspx?ContentType=SQLXML&Name=JPPlatform', true); @@ -276,16 +281,13 @@ function get_platforms(reason) { if (req.readyState == 4) { if(req.status == 200) { //console.log('AJAX Resonse: ' + req.responseText); + console.log("Caching new platform data..."); localStorage.setItem('platforms',req.responseText); localStorage.setItem('platforms_date',date.valueOf()); // milliseconds console.log("Parsing new platform data..."); parse_platforms(req.responseText,reason); } else { console.log("Couldn't fetch platforms (status="+req.status+")"); - if (old_date) { - console.log("Using cached platform data"); - parse_platforms(localStorage.getItem('platforms'),reason); - } } } }; @@ -307,5 +309,7 @@ function parse_platforms(platforms, reason) { obj.Long *= deg2rad; platformsOBJ[obj.PlatformNo]=obj; } - if (reason=='location') get_location(); else check_platform(reason); + if (reason) { + if (reason=='location') get_location(); else check_platform(reason); + } } \ No newline at end of file