--- android/TrainInfo/src/dk/thoerup/traininfo/TimetableList.java 2010/08/24 19:36:27 1017 +++ android/TrainInfo/src/dk/thoerup/traininfo/TimetableList.java 2010/09/16 15:32:42 1066 @@ -6,10 +6,6 @@ import static dk.thoerup.traininfo.R.string.timetablelist_fetchdata; import static dk.thoerup.traininfo.R.string.timetablelist_fetcherror; import static dk.thoerup.traininfo.R.string.timetablelist_nodata; - -import java.util.ArrayList; -import java.util.List; - import android.app.AlertDialog; import android.app.Dialog; import android.app.ListActivity; @@ -22,6 +18,10 @@ import android.view.View; import android.widget.ListView; import android.widget.TextView; +import dk.thoerup.android.traininfo.common.DepartureEntry; +import dk.thoerup.android.traininfo.common.TimetableBean; +import dk.thoerup.android.traininfo.common.TimetableEntry; +import dk.thoerup.android.traininfo.common.StationBean.StationEntry; import dk.thoerup.traininfo.provider.ProviderFactory; import dk.thoerup.traininfo.provider.TimetableProvider; import dk.thoerup.traininfo.util.MessageBox; @@ -32,7 +32,7 @@ DepartureEntry departure; TimetableListAdapter adapter; TimetableFetcher fetcher; - List timetables; + TimetableBean timetables; int commFailCounter = 0; TimetableProvider provider; @@ -57,13 +57,15 @@ ((TextView)findViewById(R.id.Status)).setText(departure.getStatus()); ((TextView)findViewById(R.id.Location)).setText(departure.getLocation()); ((TextView)findViewById(R.id.Note)).setText(departure.getNote()); - ((TextView)findViewById(R.id.Updated)).setText(departure.getLastUpdateString(this)); + ((TextView)findViewById(R.id.Updated)).setText( getLastUpdateString( departure.getUpdated() )); + ProviderFactory.purgeOldEntries(); //cleanup before fetching more data + if (savedInstanceState == null) { startTimetableFetcher(); } else { - timetables = (List) savedInstanceState.getSerializable("timetables"); + timetables = (TimetableBean) savedInstanceState.getSerializable("timetables"); adapter.setTimetable(timetables); } } @@ -81,12 +83,13 @@ protected void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); - TimetableBean tt = timetables.get(position); + TimetableEntry tt = timetables.entries.get(position); - StationBean station = new StationBean(); + StationEntry station = new StationEntry(); station.setName( tt.getStation() ); station.setId( tt.getStationId() ); - station.setRegional(true); + station.setIsRegional(true); + Intent intent = new Intent(this, DepartureList.class); intent.putExtra("stationbean", station); @@ -100,7 +103,7 @@ public void onSaveInstanceState(Bundle outState) { dismissDialog(DLG_PROGRESS); - outState.putSerializable("timetables", (ArrayList) timetables); + outState.putSerializable("timetables", (TimetableBean) timetables); } @@ -134,6 +137,25 @@ fetcher.execute(departure.getType(), departure.getTrainNumber()); } + + public String getLastUpdateString(int lastUpdate) { + String minutes = this.getString(R.string.departurebean_minutes); + String unknown = this.getString(R.string.departurebean_unknown); + switch (lastUpdate) { + case 1: + return "<3 " + minutes; + case 2: + return "3-10 " + minutes; + case 3: + return ">3 " + minutes; + case 4: + return unknown; + default: + return ""; + } + } + + class TimetableFetcher extends AsyncTask { @@ -147,7 +169,7 @@ commFailCounter = 0; TimetableList.this.getListView().invalidateViews(); adapter.setTimetable(timetables); - if (timetables.size() == 0) { + if (timetables.entries.size() == 0) { MessageBox.showMessage(TimetableList.this, getString(timetablelist_nodata), true); } } else { // communication or parse error