Skip to content

Commit

Permalink
Merge pull request #10 from wildhart/v1.33
Browse files Browse the repository at this point in the history
Use cached platforms every time, tidy alarm window
  • Loading branch information
wildhart committed Oct 29, 2015
2 parents 5d2eac0 + 215af94 commit 19362bd
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 29 deletions.
32 changes: 16 additions & 16 deletions appinfo.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
{
Expand All @@ -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"
}
]
Expand All @@ -69,7 +69,7 @@
"shortName": "Chch Bus",
"uuid": "6094e32b-cc6b-40cb-8761-2dc79d8ee554",
"versionCode": 1,
"versionLabel": "1.32",
"versionLabel": "1.33",
"watchapp": {
"watchface": false
}
Expand Down
20 changes: 15 additions & 5 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
20 changes: 12 additions & 8 deletions src/pebble-js-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
}
}
};
Expand All @@ -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);
}
}

0 comments on commit 19362bd

Please sign in to comment.