/[projects]/android/TrainInfo/src/dk/thoerup/traininfo/provider/XmlTimetableProvider.java
ViewVC logotype

Diff of /android/TrainInfo/src/dk/thoerup/traininfo/provider/XmlTimetableProvider.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 698 by torben, Sat Oct 3 10:55:43 2009 UTC revision 699 by torben, Mon May 3 11:19:18 2010 UTC
# Line 23  public class XmlTimetableProvider implem Line 23  public class XmlTimetableProvider implem
23          AndroidTimeoutCache<String,List<TimetableBean>> departureCache = new AndroidTimeoutCache<String,List<TimetableBean>>(CACHE_TIMEOUT);          AndroidTimeoutCache<String,List<TimetableBean>> departureCache = new AndroidTimeoutCache<String,List<TimetableBean>>(CACHE_TIMEOUT);
24                    
25          @Override          @Override
26          public List<TimetableBean> getTimetable(String trainID) {          public List<TimetableBean> getTimetable(String type, String trainID) {
27                  List<TimetableBean> list = departureCache.get(trainID);                  String key = type + "-" + trainID;
28                    List<TimetableBean> list = departureCache.get(key);
29                                    
30                  if (list == null) {                                      if (list == null) {                    
31                          list = new ArrayList<TimetableBean>();                          list = new ArrayList<TimetableBean>();
# Line 34  public class XmlTimetableProvider implem Line 35  public class XmlTimetableProvider implem
35          }          }
36    
37          @Override          @Override
38          public boolean lookupTimetable(String trainID) {          public boolean lookupTimetable(String type, String trainID) {
39                  boolean success;                  boolean success;
40                                    
41                  timetables = departureCache.get(trainID);                  String trainNumber = extractTrainNumber(trainID);
42                    
43                    String key = type + "-" + trainID;
44                    timetables = departureCache.get(key);
45                    
46                  if (timetables == null) {                                        if (timetables == null) {                      
47                          success = lookupTimetableWorker(trainID);                          success = lookupTimetableWorker(type, trainNumber);
48                                                    
49                          if (success) {                                            if (success) {                  
50                                  departureCache.put(trainID, timetables);                                  departureCache.put(key, timetables);
51                          }                          }
52                                                    
53                  } else {                  } else {
# Line 55  public class XmlTimetableProvider implem Line 59  public class XmlTimetableProvider implem
59          }          }
60                    
61    
62          public boolean lookupTimetableWorker(String trainID) {          public boolean lookupTimetableWorker(String type, String trainNumber) {
63                  boolean success = false;                  boolean success = false;
64                  String url = XmlUtil.SERVICE_BASE + "/TimetableServlet?train=" + trainID.replace(" ", "%20") ;                  String url = XmlUtil.SERVICE_BASE + "/TimetableServlet?train=" + trainNumber + "&type=" + type;
65                  Log.i("url", url);                  Log.i("url", url);
66                  try {                  try {
67                          timetables = new ArrayList<TimetableBean>();                          timetables = new ArrayList<TimetableBean>();
# Line 116  public class XmlTimetableProvider implem Line 120  public class XmlTimetableProvider implem
120                  } catch (Exception e) {                  } catch (Exception e) {
121                          Log.e("XmlStationProvider", "lookupStations: ", e);                          Log.e("XmlStationProvider", "lookupStations: ", e);
122                  }                  }
123    
124                  return success;                  return success;
125    
126          }          }
127            
128            private String extractTrainNumber (String trainID) {
129    
130                    String parts[]  = trainID.split(" ");
131                    if (parts.length == 2) {
132                            return parts[1];
133                    } else {
134                            return parts[0];
135                    }
136            }
137    
138  }  }

Legend:
Removed from v.698  
changed lines
  Added in v.699

  ViewVC Help
Powered by ViewVC 1.1.20