6 |
import static dk.thoerup.traininfo.R.string.timetablelist_fetchdata; |
import static dk.thoerup.traininfo.R.string.timetablelist_fetchdata; |
7 |
import static dk.thoerup.traininfo.R.string.timetablelist_fetcherror; |
import static dk.thoerup.traininfo.R.string.timetablelist_fetcherror; |
8 |
import static dk.thoerup.traininfo.R.string.timetablelist_nodata; |
import static dk.thoerup.traininfo.R.string.timetablelist_nodata; |
9 |
|
|
10 |
|
import java.util.regex.Pattern; |
11 |
|
|
12 |
import android.app.AlertDialog; |
import android.app.AlertDialog; |
13 |
import android.app.Dialog; |
import android.app.Dialog; |
14 |
import android.app.ListActivity; |
import android.app.ListActivity; |
21 |
import android.view.View; |
import android.view.View; |
22 |
import android.widget.ListView; |
import android.widget.ListView; |
23 |
import android.widget.TextView; |
import android.widget.TextView; |
24 |
|
import android.widget.Toast; |
25 |
import dk.thoerup.android.traininfo.common.DepartureEntry; |
import dk.thoerup.android.traininfo.common.DepartureEntry; |
26 |
|
import dk.thoerup.android.traininfo.common.StationEntry; |
27 |
import dk.thoerup.android.traininfo.common.TimetableBean; |
import dk.thoerup.android.traininfo.common.TimetableBean; |
28 |
import dk.thoerup.android.traininfo.common.TimetableEntry; |
import dk.thoerup.android.traininfo.common.TimetableEntry; |
|
import dk.thoerup.android.traininfo.common.StationBean.StationEntry; |
|
29 |
import dk.thoerup.traininfo.provider.ProviderFactory; |
import dk.thoerup.traininfo.provider.ProviderFactory; |
30 |
import dk.thoerup.traininfo.provider.TimetableProvider; |
import dk.thoerup.traininfo.provider.TimetableProvider; |
31 |
import dk.thoerup.traininfo.util.MessageBox; |
import dk.thoerup.traininfo.util.MessageBox; |
41 |
|
|
42 |
TimetableProvider provider; |
TimetableProvider provider; |
43 |
|
|
44 |
@SuppressWarnings("unchecked") |
|
45 |
@Override |
@Override |
46 |
protected void onCreate(Bundle savedInstanceState) { |
protected void onCreate(Bundle savedInstanceState) { |
47 |
super.onCreate(savedInstanceState); |
super.onCreate(savedInstanceState); |
58 |
departure = (DepartureEntry) launchedBy.getSerializableExtra("departure"); |
departure = (DepartureEntry) launchedBy.getSerializableExtra("departure"); |
59 |
|
|
60 |
((TextView)findViewById(R.id.Train)).setText(departure.getTrainNumber()); |
((TextView)findViewById(R.id.Train)).setText(departure.getTrainNumber()); |
61 |
((TextView)findViewById(R.id.Status)).setText(departure.getStatus()); |
|
62 |
((TextView)findViewById(R.id.Location)).setText(departure.getLocation()); |
((TextView)findViewById(R.id.Location)).setText(departure.getLocation()); |
|
((TextView)findViewById(R.id.Note)).setText(departure.getNote()); |
|
63 |
((TextView)findViewById(R.id.Updated)).setText( getLastUpdateString( departure.getUpdated() )); |
((TextView)findViewById(R.id.Updated)).setText( getLastUpdateString( departure.getUpdated() )); |
64 |
|
|
65 |
|
String status = departure.getStatus() != null ? departure.getStatus() : ""; |
66 |
|
if ( Pattern.matches("[0-9]+.+min", status) ) { |
67 |
|
status += " " + this.getString(R.string.departurebean_delayed); |
68 |
|
} |
69 |
|
String note = departure.getNote() != null ? departure.getNote() : ""; |
70 |
|
note = note.replace("Aflyst", this.getString(R.string.timetablelist_cancelled) ); |
71 |
|
note = note.replace("Kører kun til", this.getString(R.string.timetablelist_goesonlyto) ); |
72 |
|
note = note.replace("Afgår fra", this.getString(R.string.timetablelist_startsat) ); |
73 |
|
note = note.replace("Erstattet af", this.getString(R.string.timetablelist_replacedby) ); |
74 |
|
note = note.replace("Eksterne forhold", this.getString(R.string.timetablelist_externalconditions) ); |
75 |
|
note = note.replace("Teknisk fejl på et signal", this.getString(R.string.timetablelist_technicalerroronsignal) ); |
76 |
|
note = note.replace("Materielforhold", this.getString(R.string.timetablelist_equipmentrelated) ); |
77 |
|
note = note.replace("Passagerforhold", this.getString(R.string.timetablelist_passengerrelated) ); |
78 |
|
note = note.replace("Forventet rettidig afgang", this.getString(R.string.timetablelist_expectedtimelydeparture) ); |
79 |
|
|
80 |
|
|
81 |
|
|
82 |
|
((TextView)findViewById(R.id.Status)).setText(status); |
83 |
|
((TextView)findViewById(R.id.Note)).setText(note); |
84 |
|
|
85 |
|
|
86 |
ProviderFactory.purgeOldEntries(); //cleanup before fetching more data |
ProviderFactory.purgeOldEntries(); //cleanup before fetching more data |
87 |
|
|
106 |
protected void onListItemClick(ListView l, View v, int position, long id) { |
protected void onListItemClick(ListView l, View v, int position, long id) { |
107 |
super.onListItemClick(l, v, position, id); |
super.onListItemClick(l, v, position, id); |
108 |
|
|
109 |
TimetableEntry tt = timetables.entries.get(position); |
if (timetables == null || timetables.entries == null || timetables.entries.size() == 0) { |
110 |
|
Toast.makeText(this, "No timetables in list !?", Toast.LENGTH_LONG).show(); //TODO Translate |
111 |
StationEntry station = new StationEntry(); |
return; |
112 |
station.setName( tt.getStation() ); |
} |
|
station.setId( tt.getStationId() ); |
|
|
station.setIsRegional(true); |
|
113 |
|
|
114 |
|
TimetableEntry tt = timetables.entries.get(position); |
115 |
|
|
116 |
|
|
117 |
Intent intent = new Intent(this, DepartureList.class); |
Intent intent = new Intent(this, DepartureList.class); |
118 |
intent.putExtra("stationbean", station); |
intent.putExtra("stationbean", tt.getStationEntry() ); |
119 |
startActivity(intent); |
startActivity(intent); |
120 |
|
|
121 |
} |
} |
187 |
super.onPostExecute(result); |
super.onPostExecute(result); |
188 |
dismissDialog(DLG_PROGRESS); |
dismissDialog(DLG_PROGRESS); |
189 |
|
|
190 |
|
|
191 |
if (timetables != null) { |
if (timetables != null && timetables.errorCode == null) { |
192 |
commFailCounter = 0; |
commFailCounter = 0; |
193 |
TimetableList.this.getListView().invalidateViews(); |
TimetableList.this.getListView().invalidateViews(); |
194 |
adapter.setTimetable(timetables); |
adapter.setTimetable(timetables); |
198 |
} else { // communication or parse error |
} else { // communication or parse error |
199 |
commFailCounter++; |
commFailCounter++; |
200 |
AlertDialog.Builder builder = new AlertDialog.Builder(TimetableList.this); |
AlertDialog.Builder builder = new AlertDialog.Builder(TimetableList.this); |
201 |
builder.setMessage(getString(timetablelist_fetcherror)); |
|
202 |
|
|
203 |
|
if (timetables != null && timetables.errorCode != null ) { //got an error xml back |
204 |
|
commFailCounter = 10; |
205 |
|
builder.setMessage( getString(R.string.no_backend) ); |
206 |
|
} else { |
207 |
|
builder.setMessage(getString(timetablelist_fetcherror)); |
208 |
|
} |
209 |
|
|
210 |
builder.setCancelable(true); |
builder.setCancelable(true); |
211 |
if (commFailCounter < 3) { |
if (commFailCounter < 3) { |
212 |
builder.setPositiveButton(getString(generic_retry), new DialogInterface.OnClickListener() { |
builder.setPositiveButton(getString(generic_retry), new DialogInterface.OnClickListener() { |