From 87e53a0e93a0df38631b029acfc43926abd98aca Mon Sep 17 00:00:00 2001 From: fkuepper Date: Wed, 29 Mar 2017 14:42:48 +0200 Subject: [PATCH] Version 1.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Status-Bar - Detaildarstellung für PTR angepasst --- package.json | 2 +- src/c/bahn_interface.c | 30 +++++++++++++++--------------- src/c/bahn_interface.h | 4 ++-- src/c/mybahn_settings.c | 2 +- src/c/resources.c | 2 +- src/pkjs/bahn-interface.js | 12 ++++++++---- 6 files changed, 28 insertions(+), 24 deletions(-) diff --git a/package.json b/package.json index 36f5ac4..7f56f0c 100644 --- a/package.json +++ b/package.json @@ -109,5 +109,5 @@ "watchface": false } }, - "version": "1.0.0" + "version": "1.1.0" } diff --git a/src/c/bahn_interface.c b/src/c/bahn_interface.c index 3a6e6f2..1106339 100644 --- a/src/c/bahn_interface.c +++ b/src/c/bahn_interface.c @@ -157,44 +157,44 @@ bool BahnInterface_handle_app_message(DictionaryIterator *iter, void *context) { return true; } -static int prv_combine_product_code(AllowedProducts* p1, AllowedProducts* p2) { +static int prv_get_product_code(AllowedProducts* p) { + if (p->allow_all) { + return 1023; + } int result = 0; - if (p1->ice || p2->ice || p1->allow_all || p2->allow_all) { + if (p->ice) { result +=1; } - if (p1->ic || p2->ic || p1->allow_all || p2->allow_all) { + if (p->ic) { result +=2; } - if (p1->ir || p2->ir || p1->allow_all || p2->allow_all) { + if (p->ir) { result +=4; } - if (p1->zug || p2->zug || p1->allow_all || p2->allow_all) { + if (p->zug) { result +=8; } - if (p1->sbahn || p2->sbahn || p1->allow_all || p2->allow_all) { + if (p->sbahn) { result +=16; } - if (p1->bus || p2->bus || p1->allow_all || p2->allow_all) { + if (p->bus) { result +=32; } - if (p1->schiff || p2->schiff || p1->allow_all || p2->allow_all) { + if (p->schiff) { result +=64; } - if (p1->ubahn || p2->ubahn || p1->allow_all || p2->allow_all) { + if (p->ubahn) { result +=128; } - if (p1->tram || p2->tram || p1->allow_all || p2->allow_all) { + if (p->tram) { result +=256; } - if (p1->ast || p2->ast || p1->allow_all || p2->allow_all) { + if (p->ast) { result +=512; } return result; } -static int prv_get_product_code(AllowedProducts* products) { - return prv_combine_product_code(products, products); -} int get_products_for_connection(int valid_connection_index) { return prv_get_product_code(MyBahnSettings_get_allowed_products_for_connection(valid_connection_index)); @@ -205,7 +205,7 @@ int get_products_for_station_to_station(int from_station_index, int to_station_i StationConfig* s2 = MyBahnSettings_get_valid_station(to_station_index); AllowedProducts* p1 = s1->use_default_products ? MyBahnSettings_get_default_products() : &s1->allowed_products; AllowedProducts* p2 = s2->use_default_products ? MyBahnSettings_get_default_products() : &s2->allowed_products; - return prv_combine_product_code(p1, p2); + return prv_get_product_code(p1) | prv_get_product_code(p2); } void BahnInterface_init() { diff --git a/src/c/bahn_interface.h b/src/c/bahn_interface.h index 0e46f68..297f84b 100644 --- a/src/c/bahn_interface.h +++ b/src/c/bahn_interface.h @@ -3,8 +3,8 @@ #define CONNECTION_RESULT_TITLE_LENGTH 20 #define CONNECTION_RESULT_SUBTITLE_LENGTH 25 -#define CONNECTION_RESULT_DETAIL_LINK_LENGTH 172 -#define CONNECTION_DETAILS_LENGTH 1024 +#define CONNECTION_RESULT_DETAIL_LINK_LENGTH 128 +#define CONNECTION_DETAILS_LENGTH 768 #define MAX_CONNECTION_RESULTS 20 typedef struct { diff --git a/src/c/mybahn_settings.c b/src/c/mybahn_settings.c index 28cfc83..a0703be 100644 --- a/src/c/mybahn_settings.c +++ b/src/c/mybahn_settings.c @@ -2,7 +2,7 @@ #include "resources.h" #include "mybahn_settings.h" -// #define CREATE_DUMMY_SETTINGS +//#define CREATE_DUMMY_SETTINGS static MyBahnSettings settings; static void prv_validate_station(StationConfig* station) { diff --git a/src/c/resources.c b/src/c/resources.c index 8d2eee2..a9567a0 100644 --- a/src/c/resources.c +++ b/src/c/resources.c @@ -22,7 +22,7 @@ GRect computeEffectiveWindowBounds(Window* window, StatusBarLayer* status_bar_la } StatusBarLayer* addStatusBar(Window* window) { - return NULL; + //return NULL; StatusBarLayer* status_bar = status_bar_layer_create(); Layer *window_layer = window_get_root_layer(window); diff --git a/src/pkjs/bahn-interface.js b/src/pkjs/bahn-interface.js index c010f59..517a50a 100644 --- a/src/pkjs/bahn-interface.js +++ b/src/pkjs/bahn-interface.js @@ -1,4 +1,5 @@ var baseUrl = 'http://mobil.bahn.de/bin/query.exe/dox?start=1&rt=1'; +var detailsUrlBase = 'http://reiseauskunft.bahn.de/bin/query2.exe/dox?'; function xhrRequest(url, type, callback) { var xhr = new XMLHttpRequest(); @@ -62,7 +63,7 @@ function extractConnectionResultInfos(text) { var frueherLink = text.match(frueherExp); if (frueherLink) { - frueherLink = frueherLink[1].replace(ampExp, "&"); + frueherLink = frueherLink[1].replace(ampExp, "&").substring(detailsUrlBase.length); results.push({moreLink: frueherLink, earlier: true}); } @@ -73,7 +74,7 @@ function extractConnectionResultInfos(text) { var detailLink = connectionInfo.match(detailLinkExp); if (detailLink) { - result.detailLink = detailLink[1].replace(ampExp, "&"); + result.detailLink = detailLink[1].replace(ampExp, "&").substring(detailsUrlBase.length); } zeitExp.lastIndex = 0; @@ -124,7 +125,7 @@ function extractConnectionResultInfos(text) { var spaeterLink = text.match(spaeterExp); if (spaeterLink) { - spaeterLink = spaeterLink[1].replace(ampExp, "&"); + spaeterLink = spaeterLink[1].replace(ampExp, "&").substring(detailsUrlBase.length); results.push({moreLink: spaeterLink, later: true}); } return results; @@ -244,6 +245,9 @@ function extractHimDetails(himDetailsUrl) { } function getConnectionsFromUrl(url, resultCallback) { + if (url.substring(0, 4) != 'http') { + url = detailsUrlBase + url; + } xhrRequest(url, 'GET', function(responseText) { var results = extractConnectionResultInfos(responseText); resultCallback(results); @@ -260,7 +264,7 @@ function getConnections(startKey, zielKey, journeyProducts, resultCallback) { } function getConnectionDetailInfos(detailLink, resultCallback) { - xhrRequest(detailLink, 'GET', function(responseText){ + xhrRequest(detailsUrlBase + detailLink, 'GET', function(responseText){ var result = extractConnectionDetailInfos(responseText); resultCallback(result); });