--- android/TrainInfo/src/dk/thoerup/traininfo/provider/XmlTimetableProvider.java 2010/05/03 10:10:36 698 +++ android/TrainInfo/src/dk/thoerup/traininfo/provider/XmlTimetableProvider.java 2010/05/03 11:19:18 699 @@ -23,8 +23,9 @@ AndroidTimeoutCache> departureCache = new AndroidTimeoutCache>(CACHE_TIMEOUT); @Override - public List getTimetable(String trainID) { - List list = departureCache.get(trainID); + public List getTimetable(String type, String trainID) { + String key = type + "-" + trainID; + List list = departureCache.get(key); if (list == null) { list = new ArrayList(); @@ -34,16 +35,19 @@ } @Override - public boolean lookupTimetable(String trainID) { + public boolean lookupTimetable(String type, String trainID) { boolean success; - timetables = departureCache.get(trainID); + String trainNumber = extractTrainNumber(trainID); + + String key = type + "-" + trainID; + timetables = departureCache.get(key); if (timetables == null) { - success = lookupTimetableWorker(trainID); + success = lookupTimetableWorker(type, trainNumber); if (success) { - departureCache.put(trainID, timetables); + departureCache.put(key, timetables); } } else { @@ -55,9 +59,9 @@ } - public boolean lookupTimetableWorker(String trainID) { + public boolean lookupTimetableWorker(String type, String trainNumber) { boolean success = false; - String url = XmlUtil.SERVICE_BASE + "/TimetableServlet?train=" + trainID.replace(" ", "%20") ; + String url = XmlUtil.SERVICE_BASE + "/TimetableServlet?train=" + trainNumber + "&type=" + type; Log.i("url", url); try { timetables = new ArrayList(); @@ -116,8 +120,19 @@ } catch (Exception e) { Log.e("XmlStationProvider", "lookupStations: ", e); } + return success; } + + private String extractTrainNumber (String trainID) { + + String parts[] = trainID.split(" "); + if (parts.length == 2) { + return parts[1]; + } else { + return parts[0]; + } + } }