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; |
|
|
|
|
import java.util.ArrayList; |
|
|
import java.util.List; |
|
|
|
|
9 |
import android.app.AlertDialog; |
import android.app.AlertDialog; |
10 |
import android.app.Dialog; |
import android.app.Dialog; |
11 |
import android.app.ListActivity; |
import android.app.ListActivity; |
18 |
import android.view.View; |
import android.view.View; |
19 |
import android.widget.ListView; |
import android.widget.ListView; |
20 |
import android.widget.TextView; |
import android.widget.TextView; |
21 |
|
import dk.thoerup.android.traininfo.common.DepartureEntry; |
22 |
|
import dk.thoerup.android.traininfo.common.TimetableBean; |
23 |
|
import dk.thoerup.android.traininfo.common.TimetableEntry; |
24 |
|
import dk.thoerup.android.traininfo.common.StationBean.StationEntry; |
25 |
import dk.thoerup.traininfo.provider.ProviderFactory; |
import dk.thoerup.traininfo.provider.ProviderFactory; |
26 |
import dk.thoerup.traininfo.provider.TimetableProvider; |
import dk.thoerup.traininfo.provider.TimetableProvider; |
27 |
import dk.thoerup.traininfo.util.MessageBox; |
import dk.thoerup.traininfo.util.MessageBox; |
32 |
DepartureEntry departure; |
DepartureEntry departure; |
33 |
TimetableListAdapter adapter; |
TimetableListAdapter adapter; |
34 |
TimetableFetcher fetcher; |
TimetableFetcher fetcher; |
35 |
List<TimetableBean> timetables; |
TimetableBean timetables; |
36 |
int commFailCounter = 0; |
int commFailCounter = 0; |
37 |
|
|
38 |
TimetableProvider provider; |
TimetableProvider provider; |
57 |
((TextView)findViewById(R.id.Status)).setText(departure.getStatus()); |
((TextView)findViewById(R.id.Status)).setText(departure.getStatus()); |
58 |
((TextView)findViewById(R.id.Location)).setText(departure.getLocation()); |
((TextView)findViewById(R.id.Location)).setText(departure.getLocation()); |
59 |
((TextView)findViewById(R.id.Note)).setText(departure.getNote()); |
((TextView)findViewById(R.id.Note)).setText(departure.getNote()); |
60 |
((TextView)findViewById(R.id.Updated)).setText(departure.getLastUpdateString(this)); |
((TextView)findViewById(R.id.Updated)).setText( getLastUpdateString( departure.getUpdated() )); |
61 |
|
|
62 |
|
|
63 |
ProviderFactory.purgeOldEntries(); //cleanup before fetching more data |
ProviderFactory.purgeOldEntries(); //cleanup before fetching more data |
64 |
|
|
65 |
if (savedInstanceState == null) { |
if (savedInstanceState == null) { |
66 |
startTimetableFetcher(); |
startTimetableFetcher(); |
67 |
} else { |
} else { |
68 |
timetables = (List<TimetableBean>) savedInstanceState.getSerializable("timetables"); |
timetables = (TimetableBean) savedInstanceState.getSerializable("timetables"); |
69 |
adapter.setTimetable(timetables); |
adapter.setTimetable(timetables); |
70 |
} |
} |
71 |
} |
} |
83 |
protected void onListItemClick(ListView l, View v, int position, long id) { |
protected void onListItemClick(ListView l, View v, int position, long id) { |
84 |
super.onListItemClick(l, v, position, id); |
super.onListItemClick(l, v, position, id); |
85 |
|
|
86 |
TimetableBean tt = timetables.get(position); |
TimetableEntry tt = timetables.entries.get(position); |
87 |
|
|
88 |
StationBean station = new StationBean(); |
StationEntry station = new StationEntry(); |
89 |
station.setName( tt.getStation() ); |
station.setName( tt.getStation() ); |
90 |
station.setId( tt.getStationId() ); |
station.setId( tt.getStationId() ); |
91 |
station.setRegional(true); |
station.setIsRegional(true); |
92 |
|
|
93 |
|
|
94 |
Intent intent = new Intent(this, DepartureList.class); |
Intent intent = new Intent(this, DepartureList.class); |
95 |
intent.putExtra("stationbean", station); |
intent.putExtra("stationbean", station); |
103 |
public void onSaveInstanceState(Bundle outState) |
public void onSaveInstanceState(Bundle outState) |
104 |
{ |
{ |
105 |
dismissDialog(DLG_PROGRESS); |
dismissDialog(DLG_PROGRESS); |
106 |
outState.putSerializable("timetables", (ArrayList<TimetableBean>) timetables); |
outState.putSerializable("timetables", (TimetableBean) timetables); |
107 |
} |
} |
108 |
|
|
109 |
|
|
137 |
fetcher.execute(departure.getType(), departure.getTrainNumber()); |
fetcher.execute(departure.getType(), departure.getTrainNumber()); |
138 |
} |
} |
139 |
|
|
140 |
|
|
141 |
|
public String getLastUpdateString(int lastUpdate) { |
142 |
|
String minutes = this.getString(R.string.departurebean_minutes); |
143 |
|
String unknown = this.getString(R.string.departurebean_unknown); |
144 |
|
switch (lastUpdate) { |
145 |
|
case 1: |
146 |
|
return "<3 " + minutes; |
147 |
|
case 2: |
148 |
|
return "3-10 " + minutes; |
149 |
|
case 3: |
150 |
|
return ">3 " + minutes; |
151 |
|
case 4: |
152 |
|
return unknown; |
153 |
|
default: |
154 |
|
return ""; |
155 |
|
} |
156 |
|
} |
157 |
|
|
158 |
|
|
159 |
class TimetableFetcher extends AsyncTask<String,Void,Void> { |
class TimetableFetcher extends AsyncTask<String,Void,Void> { |
160 |
|
|
161 |
|
|
169 |
commFailCounter = 0; |
commFailCounter = 0; |
170 |
TimetableList.this.getListView().invalidateViews(); |
TimetableList.this.getListView().invalidateViews(); |
171 |
adapter.setTimetable(timetables); |
adapter.setTimetable(timetables); |
172 |
if (timetables.size() == 0) { |
if (timetables.entries.size() == 0) { |
173 |
MessageBox.showMessage(TimetableList.this, getString(timetablelist_nodata), true); |
MessageBox.showMessage(TimetableList.this, getString(timetablelist_nodata), true); |
174 |
} |
} |
175 |
} else { // communication or parse error |
} else { // communication or parse error |