/[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 918 by torben, Sat Jun 26 11:02:53 2010 UTC revision 1028 by torben, Wed Sep 8 06:25:13 2010 UTC
# Line 22  import android.util.Log; Line 22  import android.util.Log;
22  import android.view.View;  import android.view.View;
23  import android.widget.ListView;  import android.widget.ListView;
24  import android.widget.TextView;  import android.widget.TextView;
 import android.widget.Toast;  
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 30  import dk.thoerup.traininfo.util.Message Line 29  import dk.thoerup.traininfo.util.Message
29  public class TimetableList extends ListActivity {  public class TimetableList extends ListActivity {
30                    
31          private static final int DLG_PROGRESS = 8000;          private static final int DLG_PROGRESS = 8000;
32          DepartureBean departure;          DepartureEntry departure;
33          TimetableListAdapter adapter;          TimetableListAdapter adapter;
34          TimetableFetcher fetcher;          TimetableFetcher fetcher;
35          List<TimetableBean> timetables;          List<TimetableBean> timetables;
36            int commFailCounter = 0;
37                    
38          TimetableProvider provider;          TimetableProvider provider;
39    
# Line 51  public class TimetableList extends ListA Line 51  public class TimetableList extends ListA
51    
52                                    
53                  Intent launchedBy = getIntent();                  Intent launchedBy = getIntent();
54                  departure = (DepartureBean) launchedBy.getSerializableExtra("departure");                  departure = (DepartureEntry) launchedBy.getSerializableExtra("departure");
55                                    
56                  ((TextView)findViewById(R.id.Train)).setText(departure.getTrainNumber());                  ((TextView)findViewById(R.id.Train)).setText(departure.getTrainNumber());
57                  ((TextView)findViewById(R.id.Status)).setText(departure.getStatus());                  ((TextView)findViewById(R.id.Status)).setText(departure.getStatus());
# Line 59  public class TimetableList extends ListA Line 59  public class TimetableList extends ListA
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(departure.getLastUpdateString(this));
61                                                                                                    
62                    ProviderFactory.purgeOldEntries(); //cleanup before fetching more data
63                                    
64                  if (savedInstanceState == null) {                  if (savedInstanceState == null) {
65                          startTimetableFetcher();                          startTimetableFetcher();
# Line 136  public class TimetableList extends ListA Line 137  public class TimetableList extends ListA
137                    
138          class TimetableFetcher extends AsyncTask<String,Void,Void> {          class TimetableFetcher extends AsyncTask<String,Void,Void> {
139                                    
                 boolean success;  
140                                    
141                  @Override                  @Override
142                  protected void onPostExecute(Void result) {                  protected void onPostExecute(Void result) {
# Line 144  public class TimetableList extends ListA Line 144  public class TimetableList extends ListA
144                          dismissDialog(DLG_PROGRESS);                          dismissDialog(DLG_PROGRESS);
145                    
146                                                    
147                          if (success) {                          if (timetables != null) {
148                                    commFailCounter = 0;
149                                  TimetableList.this.getListView().invalidateViews();                                  TimetableList.this.getListView().invalidateViews();
150                                  adapter.setTimetable(timetables);                                  adapter.setTimetable(timetables);
151                                  if (timetables.size() == 0) {                                  if (timetables.size() == 0) {
152                                          MessageBox.showMessage(TimetableList.this, getString(timetablelist_nodata), true);                                          MessageBox.showMessage(TimetableList.this, getString(timetablelist_nodata), true);
153                                  }                                  }
154                          } else { // communication or parse error                          } else { // communication or parse error
155                                    commFailCounter++;
156                                  AlertDialog.Builder builder = new AlertDialog.Builder(TimetableList.this);                                                                                AlertDialog.Builder builder = new AlertDialog.Builder(TimetableList.this);                                              
157                                  builder.setMessage(getString(timetablelist_fetcherror));                                  builder.setMessage(getString(timetablelist_fetcherror));
158                                  builder.setCancelable(true);                                  builder.setCancelable(true);
159                                  builder.setPositiveButton(getString(generic_retry), new DialogInterface.OnClickListener() {                                  if (commFailCounter < 3) {
160                                          public void onClick(DialogInterface dialog, int id) {                                          builder.setPositiveButton(getString(generic_retry), new DialogInterface.OnClickListener() {
161                                                  dialog.dismiss();                                                  public void onClick(DialogInterface dialog, int id) {
162                                                  startTimetableFetcher();                                                          dialog.dismiss();
163                                                                                                            startTimetableFetcher();
164                                          }                                                          
165                                  });                                                  }
166                                            });
167                                    }
168                                  builder.setNegativeButton(getString(generic_cancel), new DialogInterface.OnClickListener() {                                  builder.setNegativeButton(getString(generic_cancel), new DialogInterface.OnClickListener() {
169                                          public void onClick(DialogInterface dialog, int id) {                                          public void onClick(DialogInterface dialog, int id) {
170                                                  dialog.dismiss();                                                  dialog.dismiss();
# Line 182  public class TimetableList extends ListA Line 186  public class TimetableList extends ListA
186                  protected Void doInBackground(String... arg0) {                  protected Void doInBackground(String... arg0) {
187                          String type = arg0[0];                          String type = arg0[0];
188                          String trainID = arg0[1];                          String trainID = arg0[1];
189                          success = provider.lookupTimetable(type, trainID);                          timetables = provider.lookupTimetable(type, trainID);
                         timetables = provider.getTimetable(type, trainID);  
190                                                    
191                          return null;                          return null;
192                  }                  }

Legend:
Removed from v.918  
changed lines
  Added in v.1028

  ViewVC Help
Powered by ViewVC 1.1.20