/[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 630 by torben, Wed Mar 17 15:27:11 2010 UTC revision 1007 by torben, Tue Aug 3 06:12:10 2010 UTC
# Line 10  import static dk.thoerup.traininfo.R.str Line 10  import static dk.thoerup.traininfo.R.str
10  import java.util.ArrayList;  import java.util.ArrayList;
11  import java.util.List;  import java.util.List;
12    
 import android.app.Activity;  
13  import android.app.AlertDialog;  import android.app.AlertDialog;
14  import android.app.Dialog;  import android.app.Dialog;
15    import android.app.ListActivity;
16  import android.app.ProgressDialog;  import android.app.ProgressDialog;
17  import android.content.DialogInterface;  import android.content.DialogInterface;
18  import android.content.Intent;  import android.content.Intent;
19  import android.os.AsyncTask;  import android.os.AsyncTask;
20  import android.os.Bundle;  import android.os.Bundle;
21  import android.util.Log;  import android.util.Log;
22    import android.view.View;
23  import android.widget.ListView;  import android.widget.ListView;
24  import android.widget.TextView;  import android.widget.TextView;
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;
28    
29  public class TimetableList extends Activity {  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;
# Line 43  public class TimetableList extends Activ Line 44  public class TimetableList extends Activ
44                                    
45                  provider = ProviderFactory.getTimetableProvider();                  provider = ProviderFactory.getTimetableProvider();
46                                    
47                  adapter = new TimetableListAdapter(this);                  adapter = new TimetableListAdapter(this);              
48                                    setListAdapter(adapter);
49                  ListView lv = (ListView) findViewById(R.id.List);  
                 lv.setAdapter(adapter);  
50    
51                                    
52                  Intent launchedBy = getIntent();                  Intent launchedBy = getIntent();
53                  departure = (DepartureBean) launchedBy.getSerializableExtra("departure");                  departure = (DepartureEntry) launchedBy.getSerializableExtra("departure");
54                                    
55                  ((TextView)findViewById(R.id.Train)).setText(departure.getTrainNumber());                  ((TextView)findViewById(R.id.Train)).setText(departure.getTrainNumber());
56                  ((TextView)findViewById(R.id.Status)).setText(departure.getStatus());                  ((TextView)findViewById(R.id.Status)).setText(departure.getStatus());
# Line 66  public class TimetableList extends Activ Line 66  public class TimetableList extends Activ
66                          adapter.setTimetable(timetables);                          adapter.setTimetable(timetables);
67                  }                  }
68          }          }
69    
70            @Override
71            protected void onDestroy() {
72                    super.onDestroy();
73                    
74                    if (fetcher != null) {
75                            fetcher.cancel(true);
76                    }
77            }
78                    
79      @Override      @Override
80            protected void onListItemClick(ListView l, View v, int position, long id) {
81                    super.onListItemClick(l, v, position, id);
82    
83                    TimetableBean tt = timetables.get(position);
84                    
85                    StationBean station = new StationBean();
86                    station.setName( tt.getStation() );
87                    station.setId( tt.getStationId() );
88                    station.setRegional(true);
89                    
90                    Intent intent = new Intent(this, DepartureList.class);
91                    intent.putExtra("stationbean", station);
92                    startActivity(intent);
93                    
94            }
95        
96    
97    
98            @Override
99      public void onSaveInstanceState(Bundle outState)      public void onSaveInstanceState(Bundle outState)
100      {                {          
101          dismissDialog(DLG_PROGRESS);          dismissDialog(DLG_PROGRESS);
# Line 102  public class TimetableList extends Activ Line 130  public class TimetableList extends Activ
130          void startTimetableFetcher() {          void startTimetableFetcher() {
131                  showDialog(DLG_PROGRESS);                  showDialog(DLG_PROGRESS);
132                  fetcher = new TimetableFetcher();                  fetcher = new TimetableFetcher();
133                  fetcher.execute(departure.getTrainNumber());                  fetcher.execute(departure.getType(), departure.getTrainNumber());
134          }          }
135                    
136          class TimetableFetcher extends AsyncTask<String,Void,Void> {          class TimetableFetcher extends AsyncTask<String,Void,Void> {
137                                    
                 boolean success;  
138                                    
139                  @Override                  @Override
140                  protected void onPostExecute(Void result) {                  protected void onPostExecute(Void result) {
# Line 115  public class TimetableList extends Activ Line 142  public class TimetableList extends Activ
142                          dismissDialog(DLG_PROGRESS);                          dismissDialog(DLG_PROGRESS);
143                    
144                                                    
145                          if (success) {                          if (timetables != null) {
146                                    TimetableList.this.getListView().invalidateViews();
147                                  adapter.setTimetable(timetables);                                  adapter.setTimetable(timetables);
148                                  if (timetables.size() == 0) {                                  if (timetables.size() == 0) {
149                                          MessageBox.showMessage(TimetableList.this, getString(timetablelist_nodata));                                          MessageBox.showMessage(TimetableList.this, getString(timetablelist_nodata), true);
150                                  }                                  }
151                          } else { // communication or parse error                          } else { // communication or parse error
152                                  AlertDialog.Builder builder = new AlertDialog.Builder(TimetableList.this);                                                                                AlertDialog.Builder builder = new AlertDialog.Builder(TimetableList.this);                                              
# Line 134  public class TimetableList extends Activ Line 162  public class TimetableList extends Activ
162                                  builder.setNegativeButton(getString(generic_cancel), new DialogInterface.OnClickListener() {                                  builder.setNegativeButton(getString(generic_cancel), new DialogInterface.OnClickListener() {
163                                          public void onClick(DialogInterface dialog, int id) {                                          public void onClick(DialogInterface dialog, int id) {
164                                                  dialog.dismiss();                                                  dialog.dismiss();
165                                                    TimetableList.this.finish();
166                                          }                                                                                                }                                                      
167                                  });                                  });
168                                                                    
# Line 149  public class TimetableList extends Activ Line 178  public class TimetableList extends Activ
178                                    
179                  @Override                  @Override
180                  protected Void doInBackground(String... arg0) {                  protected Void doInBackground(String... arg0) {
181                          String trainID = arg0[0];                          String type = arg0[0];
182                          success = provider.lookupTimetable(trainID);                          String trainID = arg0[1];
183                          timetables = provider.getTimetable(trainID);                          timetables = provider.lookupTimetable(type, trainID);
184                                                    
185                          return null;                          return null;
186                  }                  }

Legend:
Removed from v.630  
changed lines
  Added in v.1007

  ViewVC Help
Powered by ViewVC 1.1.20