--- android/TrainInfo/src/dk/thoerup/traininfo/TimetableList.java 2010/06/26 10:50:34 917 +++ android/TrainInfo/src/dk/thoerup/traininfo/TimetableList.java 2010/09/08 06:03:45 1027 @@ -22,7 +22,6 @@ import android.view.View; import android.widget.ListView; import android.widget.TextView; -import android.widget.Toast; import dk.thoerup.traininfo.provider.ProviderFactory; import dk.thoerup.traininfo.provider.TimetableProvider; import dk.thoerup.traininfo.util.MessageBox; @@ -30,10 +29,11 @@ public class TimetableList extends ListActivity { private static final int DLG_PROGRESS = 8000; - DepartureBean departure; + DepartureEntry departure; TimetableListAdapter adapter; TimetableFetcher fetcher; List timetables; + int commFailCounter = 0; TimetableProvider provider; @@ -51,7 +51,7 @@ 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()); @@ -68,6 +68,20 @@ } } + @Override + protected void onStart() { + super.onStart(); + ProviderFactory.purgeOldEntries(); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + + if (fetcher != null) { + fetcher.cancel(true); + } + } @Override protected void onListItemClick(ListView l, View v, int position, long id) { @@ -128,7 +142,6 @@ class TimetableFetcher extends AsyncTask { - boolean success; @Override protected void onPostExecute(Void result) { @@ -136,23 +149,27 @@ dismissDialog(DLG_PROGRESS); - if (success) { + if (timetables != null) { + commFailCounter = 0; TimetableList.this.getListView().invalidateViews(); adapter.setTimetable(timetables); if (timetables.size() == 0) { MessageBox.showMessage(TimetableList.this, getString(timetablelist_nodata), true); } } else { // communication or parse error + commFailCounter++; AlertDialog.Builder builder = new AlertDialog.Builder(TimetableList.this); builder.setMessage(getString(timetablelist_fetcherror)); builder.setCancelable(true); - builder.setPositiveButton(getString(generic_retry), new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int id) { - dialog.dismiss(); - startTimetableFetcher(); - - } - }); + if (commFailCounter < 3) { + builder.setPositiveButton(getString(generic_retry), new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + dialog.dismiss(); + startTimetableFetcher(); + + } + }); + } builder.setNegativeButton(getString(generic_cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.dismiss(); @@ -174,8 +191,7 @@ protected Void doInBackground(String... arg0) { String type = arg0[0]; String trainID = arg0[1]; - success = provider.lookupTimetable(type, trainID); - timetables = provider.getTimetable(type, trainID); + timetables = provider.lookupTimetable(type, trainID); return null; }