--- android/TrainInfo/src/dk/thoerup/traininfo/TimetableList.java 2010/03/17 15:27:11 630 +++ android/TrainInfo/src/dk/thoerup/traininfo/TimetableList.java 2010/08/03 06:12:10 1007 @@ -10,25 +10,26 @@ import java.util.ArrayList; import java.util.List; -import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; +import android.app.ListActivity; import android.app.ProgressDialog; import android.content.DialogInterface; import android.content.Intent; import android.os.AsyncTask; import android.os.Bundle; import android.util.Log; +import android.view.View; import android.widget.ListView; import android.widget.TextView; import dk.thoerup.traininfo.provider.ProviderFactory; import dk.thoerup.traininfo.provider.TimetableProvider; import dk.thoerup.traininfo.util.MessageBox; -public class TimetableList extends Activity { +public class TimetableList extends ListActivity { private static final int DLG_PROGRESS = 8000; - DepartureBean departure; + DepartureEntry departure; TimetableListAdapter adapter; TimetableFetcher fetcher; List timetables; @@ -43,14 +44,13 @@ provider = ProviderFactory.getTimetableProvider(); - adapter = new TimetableListAdapter(this); - - ListView lv = (ListView) findViewById(R.id.List); - lv.setAdapter(adapter); + adapter = new TimetableListAdapter(this); + setListAdapter(adapter); + Intent launchedBy = getIntent(); - departure = (DepartureBean) launchedBy.getSerializableExtra("departure"); + departure = (DepartureEntry) launchedBy.getSerializableExtra("departure"); ((TextView)findViewById(R.id.Train)).setText(departure.getTrainNumber()); ((TextView)findViewById(R.id.Status)).setText(departure.getStatus()); @@ -66,8 +66,36 @@ adapter.setTimetable(timetables); } } + + @Override + protected void onDestroy() { + super.onDestroy(); + + if (fetcher != null) { + fetcher.cancel(true); + } + } - @Override + @Override + protected void onListItemClick(ListView l, View v, int position, long id) { + super.onListItemClick(l, v, position, id); + + TimetableBean tt = timetables.get(position); + + StationBean station = new StationBean(); + station.setName( tt.getStation() ); + station.setId( tt.getStationId() ); + station.setRegional(true); + + Intent intent = new Intent(this, DepartureList.class); + intent.putExtra("stationbean", station); + startActivity(intent); + + } + + + + @Override public void onSaveInstanceState(Bundle outState) { dismissDialog(DLG_PROGRESS); @@ -102,12 +130,11 @@ void startTimetableFetcher() { showDialog(DLG_PROGRESS); fetcher = new TimetableFetcher(); - fetcher.execute(departure.getTrainNumber()); + fetcher.execute(departure.getType(), departure.getTrainNumber()); } class TimetableFetcher extends AsyncTask { - boolean success; @Override protected void onPostExecute(Void result) { @@ -115,10 +142,11 @@ dismissDialog(DLG_PROGRESS); - if (success) { + if (timetables != null) { + TimetableList.this.getListView().invalidateViews(); adapter.setTimetable(timetables); if (timetables.size() == 0) { - MessageBox.showMessage(TimetableList.this, getString(timetablelist_nodata)); + MessageBox.showMessage(TimetableList.this, getString(timetablelist_nodata), true); } } else { // communication or parse error AlertDialog.Builder builder = new AlertDialog.Builder(TimetableList.this); @@ -134,6 +162,7 @@ builder.setNegativeButton(getString(generic_cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.dismiss(); + TimetableList.this.finish(); } }); @@ -149,9 +178,9 @@ @Override protected Void doInBackground(String... arg0) { - String trainID = arg0[0]; - success = provider.lookupTimetable(trainID); - timetables = provider.getTimetable(trainID); + String type = arg0[0]; + String trainID = arg0[1]; + timetables = provider.lookupTimetable(type, trainID); return null; }