/[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 1065 by torben, Wed Sep 8 06:25:13 2010 UTC revision 1066 by torben, Thu Sep 16 15:32:42 2010 UTC
# Line 6  import static dk.thoerup.traininfo.R.str Line 6  import static dk.thoerup.traininfo.R.str
6  import static dk.thoerup.traininfo.R.string.timetablelist_fetchdata;  import static dk.thoerup.traininfo.R.string.timetablelist_fetchdata;
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;
   
 import java.util.ArrayList;  
 import java.util.List;  
   
9  import android.app.AlertDialog;  import android.app.AlertDialog;
10  import android.app.Dialog;  import android.app.Dialog;
11  import android.app.ListActivity;  import android.app.ListActivity;
# Line 22  import android.util.Log; Line 18  import android.util.Log;
18  import android.view.View;  import android.view.View;
19  import android.widget.ListView;  import android.widget.ListView;
20  import android.widget.TextView;  import android.widget.TextView;
21    import dk.thoerup.android.traininfo.common.DepartureEntry;
22    import dk.thoerup.android.traininfo.common.TimetableBean;
23    import dk.thoerup.android.traininfo.common.TimetableEntry;
24    import dk.thoerup.android.traininfo.common.StationBean.StationEntry;
25  import dk.thoerup.traininfo.provider.ProviderFactory;  import dk.thoerup.traininfo.provider.ProviderFactory;
26  import dk.thoerup.traininfo.provider.TimetableProvider;  import dk.thoerup.traininfo.provider.TimetableProvider;
27  import dk.thoerup.traininfo.util.MessageBox;  import dk.thoerup.traininfo.util.MessageBox;
# Line 32  public class TimetableList extends ListA Line 32  public class TimetableList extends ListA
32          DepartureEntry departure;          DepartureEntry departure;
33          TimetableListAdapter adapter;          TimetableListAdapter adapter;
34          TimetableFetcher fetcher;          TimetableFetcher fetcher;
35          List<TimetableBean> timetables;          TimetableBean timetables;
36          int commFailCounter = 0;          int commFailCounter = 0;
37                    
38          TimetableProvider provider;          TimetableProvider provider;
# Line 57  public class TimetableList extends ListA Line 57  public class TimetableList extends ListA
57                  ((TextView)findViewById(R.id.Status)).setText(departure.getStatus());                  ((TextView)findViewById(R.id.Status)).setText(departure.getStatus());
58                  ((TextView)findViewById(R.id.Location)).setText(departure.getLocation());                  ((TextView)findViewById(R.id.Location)).setText(departure.getLocation());
59                  ((TextView)findViewById(R.id.Note)).setText(departure.getNote());                  ((TextView)findViewById(R.id.Note)).setText(departure.getNote());
60                  ((TextView)findViewById(R.id.Updated)).setText(departure.getLastUpdateString(this));                  ((TextView)findViewById(R.id.Updated)).setText( getLastUpdateString( departure.getUpdated() ));
61                                                                                                    
62                    
63                  ProviderFactory.purgeOldEntries(); //cleanup before fetching more data                  ProviderFactory.purgeOldEntries(); //cleanup before fetching more data
64                                    
65                  if (savedInstanceState == null) {                  if (savedInstanceState == null) {
66                          startTimetableFetcher();                          startTimetableFetcher();
67                  } else {                  } else {
68                          timetables = (List<TimetableBean>) savedInstanceState.getSerializable("timetables");                          timetables = (TimetableBean) savedInstanceState.getSerializable("timetables");
69                          adapter.setTimetable(timetables);                          adapter.setTimetable(timetables);
70                  }                  }
71          }          }
# Line 82  public class TimetableList extends ListA Line 83  public class TimetableList extends ListA
83          protected void onListItemClick(ListView l, View v, int position, long id) {          protected void onListItemClick(ListView l, View v, int position, long id) {
84                  super.onListItemClick(l, v, position, id);                  super.onListItemClick(l, v, position, id);
85    
86                  TimetableBean tt = timetables.get(position);                  TimetableEntry tt = timetables.entries.get(position);
87                                    
88                  StationBean station = new StationBean();                  StationEntry station = new StationEntry();
89                  station.setName( tt.getStation() );                  station.setName( tt.getStation() );
90                  station.setId( tt.getStationId() );                  station.setId( tt.getStationId() );
91                  station.setRegional(true);                  station.setIsRegional(true);
92                    
93                                    
94                  Intent intent = new Intent(this, DepartureList.class);                  Intent intent = new Intent(this, DepartureList.class);
95                  intent.putExtra("stationbean", station);                  intent.putExtra("stationbean", station);
# Line 101  public class TimetableList extends ListA Line 103  public class TimetableList extends ListA
103      public void onSaveInstanceState(Bundle outState)      public void onSaveInstanceState(Bundle outState)
104      {                {          
105          dismissDialog(DLG_PROGRESS);          dismissDialog(DLG_PROGRESS);
106          outState.putSerializable("timetables", (ArrayList<TimetableBean>) timetables);          outState.putSerializable("timetables", (TimetableBean) timetables);
107      }      }
108    
109                    
# Line 135  public class TimetableList extends ListA Line 137  public class TimetableList extends ListA
137                  fetcher.execute(departure.getType(), departure.getTrainNumber());                  fetcher.execute(departure.getType(), departure.getTrainNumber());
138          }          }
139                    
140            
141            public String getLastUpdateString(int lastUpdate) {
142                    String minutes = this.getString(R.string.departurebean_minutes);
143                    String unknown = this.getString(R.string.departurebean_unknown);
144                    switch (lastUpdate) {
145                    case 1:
146                            return "<3 " + minutes;
147                    case 2:
148                            return "3-10 " + minutes;
149                    case 3:
150                            return ">3 " + minutes;
151                    case 4:
152                            return unknown;
153                    default:
154                            return "";
155                    }
156            }
157    
158            
159          class TimetableFetcher extends AsyncTask<String,Void,Void> {          class TimetableFetcher extends AsyncTask<String,Void,Void> {
160                                    
161                                    
# Line 148  public class TimetableList extends ListA Line 169  public class TimetableList extends ListA
169                                  commFailCounter = 0;                                  commFailCounter = 0;
170                                  TimetableList.this.getListView().invalidateViews();                                  TimetableList.this.getListView().invalidateViews();
171                                  adapter.setTimetable(timetables);                                  adapter.setTimetable(timetables);
172                                  if (timetables.size() == 0) {                                  if (timetables.entries.size() == 0) {
173                                          MessageBox.showMessage(TimetableList.this, getString(timetablelist_nodata), true);                                          MessageBox.showMessage(TimetableList.this, getString(timetablelist_nodata), true);
174                                  }                                  }
175                          } else { // communication or parse error                          } else { // communication or parse error

Legend:
Removed from v.1065  
changed lines
  Added in v.1066

  ViewVC Help
Powered by ViewVC 1.1.20