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

Diff of /android/TrainInfo/src/dk/thoerup/traininfo/TimetableList.java

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

revision 1027 by torben, Wed Sep 8 06:03:45 2010 UTC revision 1257 by torben, Mon Apr 4 15:28:12 2011 UTC
# Line 7  import static dk.thoerup.traininfo.R.str Line 7  import static dk.thoerup.traininfo.R.str
7  import static dk.thoerup.traininfo.R.string.timetablelist_fetcherror;  import static dk.thoerup.traininfo.R.string.timetablelist_fetcherror;
8  import static dk.thoerup.traininfo.R.string.timetablelist_nodata;  import static dk.thoerup.traininfo.R.string.timetablelist_nodata;
9    
10  import java.util.ArrayList;  import java.util.regex.Pattern;
 import java.util.List;  
11    
12  import android.app.AlertDialog;  import android.app.AlertDialog;
13  import android.app.Dialog;  import android.app.Dialog;
# Line 22  import android.util.Log; Line 21  import android.util.Log;
21  import android.view.View;  import android.view.View;
22  import android.widget.ListView;  import android.widget.ListView;
23  import android.widget.TextView;  import android.widget.TextView;
24    import dk.thoerup.android.traininfo.common.DepartureEntry;
25    import dk.thoerup.android.traininfo.common.StationBean.StationEntry;
26    import dk.thoerup.android.traininfo.common.TimetableBean;
27    import dk.thoerup.android.traininfo.common.TimetableEntry;
28  import dk.thoerup.traininfo.provider.ProviderFactory;  import dk.thoerup.traininfo.provider.ProviderFactory;
29  import dk.thoerup.traininfo.provider.TimetableProvider;  import dk.thoerup.traininfo.provider.TimetableProvider;
30  import dk.thoerup.traininfo.util.MessageBox;  import dk.thoerup.traininfo.util.MessageBox;
# Line 32  public class TimetableList extends ListA Line 35  public class TimetableList extends ListA
35          DepartureEntry departure;          DepartureEntry departure;
36          TimetableListAdapter adapter;          TimetableListAdapter adapter;
37          TimetableFetcher fetcher;          TimetableFetcher fetcher;
38          List<TimetableBean> timetables;          TimetableBean timetables;
39          int commFailCounter = 0;          int commFailCounter = 0;
40                    
41          TimetableProvider provider;          TimetableProvider provider;
42    
43          @SuppressWarnings("unchecked")  
44          @Override          @Override
45          protected void onCreate(Bundle savedInstanceState) {          protected void onCreate(Bundle savedInstanceState) {
46                  super.onCreate(savedInstanceState);                  super.onCreate(savedInstanceState);
# Line 54  public class TimetableList extends ListA Line 57  public class TimetableList extends ListA
57                  departure = (DepartureEntry) launchedBy.getSerializableExtra("departure");                  departure = (DepartureEntry) launchedBy.getSerializableExtra("departure");
58                                    
59                  ((TextView)findViewById(R.id.Train)).setText(departure.getTrainNumber());                  ((TextView)findViewById(R.id.Train)).setText(departure.getTrainNumber());
60                  ((TextView)findViewById(R.id.Status)).setText(departure.getStatus());                                  
61                  ((TextView)findViewById(R.id.Location)).setText(departure.getLocation());                  ((TextView)findViewById(R.id.Location)).setText(departure.getLocation());              
62                  ((TextView)findViewById(R.id.Note)).setText(departure.getNote());                  ((TextView)findViewById(R.id.Updated)).setText( getLastUpdateString( departure.getUpdated() ));
63                  ((TextView)findViewById(R.id.Updated)).setText(departure.getLastUpdateString(this));                  
64                    String status = departure.getStatus() != null ? departure.getStatus() : "";            
65                    if ( Pattern.matches("[0-9]+.+min", status) ) {
66                            status += " " + this.getString(R.string.departurebean_delayed);
67                    }
68                    String note = departure.getNote() != null ? departure.getNote() : "";
69                    note = note.replace("Aflyst", this.getString(R.string.timetablelist_cancelled) );
70                    note = note.replace("Kører kun til", this.getString(R.string.timetablelist_goesonlyto) );
71                    
72                    // tilføj:
73                    // * afgår fra
74                    // * eksterne forhold
75                    // * teknisk fejl på et signal
76    
77                    
78                    
79                    ((TextView)findViewById(R.id.Status)).setText(status);
80                    ((TextView)findViewById(R.id.Note)).setText(note);
81                    
82    
83                    
84                    
85                                                                                                    
86                                    
87                    ProviderFactory.purgeOldEntries(); //cleanup before fetching more data
88                    
89                  if (savedInstanceState == null) {                  if (savedInstanceState == null) {
90                          startTimetableFetcher();                          startTimetableFetcher();
91                  } else {                  } else {
92                          timetables = (List<TimetableBean>) savedInstanceState.getSerializable("timetables");                          timetables = (TimetableBean) savedInstanceState.getSerializable("timetables");
93                          adapter.setTimetable(timetables);                          adapter.setTimetable(timetables);
94                  }                  }
95          }          }
           
         @Override  
         protected void onStart() {  
                 super.onStart();  
                 ProviderFactory.purgeOldEntries();  
         }  
96    
97          @Override          @Override
98          protected void onDestroy() {          protected void onDestroy() {
# Line 87  public class TimetableList extends ListA Line 107  public class TimetableList extends ListA
107          protected void onListItemClick(ListView l, View v, int position, long id) {          protected void onListItemClick(ListView l, View v, int position, long id) {
108                  super.onListItemClick(l, v, position, id);                  super.onListItemClick(l, v, position, id);
109    
110                  TimetableBean tt = timetables.get(position);                  TimetableEntry tt = timetables.entries.get(position);
111                                    
112                  StationBean station = new StationBean();                  StationEntry station = new StationEntry();
113                  station.setName( tt.getStation() );                  station.setName( tt.getStation() );
114                  station.setId( tt.getStationId() );                  station.setId( tt.getStationId() );
115                  station.setRegional(true);                  station.setIsRegional(true);
116                    
117                                    
118                  Intent intent = new Intent(this, DepartureList.class);                  Intent intent = new Intent(this, DepartureList.class);
119                  intent.putExtra("stationbean", station);                  intent.putExtra("stationbean", station);
# Line 106  public class TimetableList extends ListA Line 127  public class TimetableList extends ListA
127      public void onSaveInstanceState(Bundle outState)      public void onSaveInstanceState(Bundle outState)
128      {                {          
129          dismissDialog(DLG_PROGRESS);          dismissDialog(DLG_PROGRESS);
130          outState.putSerializable("timetables", (ArrayList<TimetableBean>) timetables);          outState.putSerializable("timetables", (TimetableBean) timetables);
131      }      }
132    
133                    
# Line 140  public class TimetableList extends ListA Line 161  public class TimetableList extends ListA
161                  fetcher.execute(departure.getType(), departure.getTrainNumber());                  fetcher.execute(departure.getType(), departure.getTrainNumber());
162          }          }
163                    
164            
165            public String getLastUpdateString(int lastUpdate) {
166                    String minutes = this.getString(R.string.departurebean_minutes);
167                    String unknown = this.getString(R.string.departurebean_unknown);
168                    switch (lastUpdate) {
169                    case 1:
170                            return "<3 " + minutes;
171                    case 2:
172                            return "3-10 " + minutes;
173                    case 3:
174                            return ">3 " + minutes;
175                    case 4:
176                            return unknown;
177                    default:
178                            return "";
179                    }
180            }
181    
182            
183          class TimetableFetcher extends AsyncTask<String,Void,Void> {          class TimetableFetcher extends AsyncTask<String,Void,Void> {
184                                    
185                                    
# Line 153  public class TimetableList extends ListA Line 193  public class TimetableList extends ListA
193                                  commFailCounter = 0;                                  commFailCounter = 0;
194                                  TimetableList.this.getListView().invalidateViews();                                  TimetableList.this.getListView().invalidateViews();
195                                  adapter.setTimetable(timetables);                                  adapter.setTimetable(timetables);
196                                  if (timetables.size() == 0) {                                  if (timetables.entries.size() == 0) {
197                                          MessageBox.showMessage(TimetableList.this, getString(timetablelist_nodata), true);                                          MessageBox.showMessage(TimetableList.this, getString(timetablelist_nodata), true);
198                                  }                                  }
199                          } else { // communication or parse error                          } else { // communication or parse error

Legend:
Removed from v.1027  
changed lines
  Added in v.1257

  ViewVC Help
Powered by ViewVC 1.1.20