--- android/TrainInfo/src/dk/thoerup/traininfo/TimetableList.java 2010/09/16 15:32:42 1066 +++ android/TrainInfo/src/dk/thoerup/traininfo/TimetableList.java 2011/05/02 16:08:01 1416 @@ -6,6 +6,9 @@ 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.regex.Pattern; + import android.app.AlertDialog; import android.app.Dialog; import android.app.ListActivity; @@ -19,9 +22,9 @@ import android.widget.ListView; import android.widget.TextView; import dk.thoerup.android.traininfo.common.DepartureEntry; +import dk.thoerup.android.traininfo.common.StationEntry; 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; @@ -37,7 +40,7 @@ TimetableProvider provider; - @SuppressWarnings("unchecked") + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -54,11 +57,30 @@ departure = (DepartureEntry) launchedBy.getSerializableExtra("departure"); ((TextView)findViewById(R.id.Train)).setText(departure.getTrainNumber()); - ((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.Location)).setText(departure.getLocation()); ((TextView)findViewById(R.id.Updated)).setText( getLastUpdateString( departure.getUpdated() )); - + + String status = departure.getStatus() != null ? departure.getStatus() : ""; + if ( Pattern.matches("[0-9]+.+min", status) ) { + status += " " + this.getString(R.string.departurebean_delayed); + } + String note = departure.getNote() != null ? departure.getNote() : ""; + note = note.replace("Aflyst", this.getString(R.string.timetablelist_cancelled) ); + note = note.replace("Kører kun til", this.getString(R.string.timetablelist_goesonlyto) ); + note = note.replace("Afgår fra", this.getString(R.string.timetablelist_startsat) ); + note = note.replace("Erstattet af", this.getString(R.string.timetablelist_replacedby) ); + note = note.replace("Eksterne forhold", this.getString(R.string.timetablelist_externalconditions) ); + note = note.replace("Teknisk fejl på et signal", this.getString(R.string.timetablelist_technicalerroronsignal) ); + note = note.replace("Materielforhold", this.getString(R.string.timetablelist_equipmentrelated) ); + note = note.replace("Passagerforhold", this.getString(R.string.timetablelist_passengerrelated) ); + note = note.replace("Forventet rettidig afgang", this.getString(R.string.timetablelist_expectedtimelydeparture) ); + + + + ((TextView)findViewById(R.id.Status)).setText(status); + ((TextView)findViewById(R.id.Note)).setText(note); + ProviderFactory.purgeOldEntries(); //cleanup before fetching more data @@ -84,15 +106,10 @@ super.onListItemClick(l, v, position, id); TimetableEntry tt = timetables.entries.get(position); - - StationEntry station = new StationEntry(); - station.setName( tt.getStation() ); - station.setId( tt.getStationId() ); - station.setIsRegional(true); - + Intent intent = new Intent(this, DepartureList.class); - intent.putExtra("stationbean", station); + intent.putExtra("stationbean", tt.getStationEntry() ); startActivity(intent); } @@ -164,8 +181,8 @@ super.onPostExecute(result); dismissDialog(DLG_PROGRESS); - - if (timetables != null) { + //TODO: differentiate between a communication error and a downed bane.dk site + if (timetables != null && timetables.errorCode == null) { commFailCounter = 0; TimetableList.this.getListView().invalidateViews(); adapter.setTimetable(timetables); @@ -175,7 +192,15 @@ } else { // communication or parse error commFailCounter++; AlertDialog.Builder builder = new AlertDialog.Builder(TimetableList.this); - builder.setMessage(getString(timetablelist_fetcherror)); + + + if (timetables != null && timetables.errorCode != null ) { //got an error xml back + commFailCounter = 10; + builder.setMessage( getString(R.string.no_backend) ); + } else { + builder.setMessage(getString(timetablelist_fetcherror)); + } + builder.setCancelable(true); if (commFailCounter < 3) { builder.setPositiveButton(getString(generic_retry), new DialogInterface.OnClickListener() {