51 |
StationBean station; |
StationBean station; |
52 |
|
|
53 |
boolean arrival = false; |
boolean arrival = false; |
54 |
|
|
55 |
|
int commFailCounter = 0; |
56 |
|
|
57 |
@Override |
@Override |
58 |
protected void onCreate(Bundle savedInstanceState) { |
protected void onCreate(Bundle savedInstanceState) { |
137 |
} |
} |
138 |
} |
} |
139 |
|
|
140 |
|
@Override |
141 |
|
protected void onStart() { |
142 |
|
super.onStart(); |
143 |
|
ProviderFactory.purgeOldEntries(); |
144 |
|
} |
145 |
|
|
146 |
boolean hasNotifications() { |
boolean hasNotifications() { |
147 |
return (departures != null && departures.notifications.size() > 0); |
return (departures != null && departures.notifications.size() > 0); |
148 |
} |
} |
286 |
|
|
287 |
class DepartureFetcher extends AsyncTask<Integer, Void, Void> { |
class DepartureFetcher extends AsyncTask<Integer, Void, Void> { |
288 |
|
|
|
boolean success; |
|
289 |
|
|
290 |
@Override |
@Override |
291 |
protected void onPostExecute(Void result) { |
protected void onPostExecute(Void result) { |
294 |
|
|
295 |
pgDialog.dismiss(); |
pgDialog.dismiss(); |
296 |
|
|
297 |
if (success) { |
if (departures != null) { |
298 |
|
commFailCounter = 0; |
299 |
DepartureList.this.getListView().setVisibility(View.GONE); //Experimental, inspired by http://osdir.com/ml/Android-Developers/2010-04/msg01198.html |
DepartureList.this.getListView().setVisibility(View.GONE); //Experimental, inspired by http://osdir.com/ml/Android-Developers/2010-04/msg01198.html |
300 |
adapter.setDepartures(departures.entries); |
adapter.setDepartures(departures.entries); |
301 |
DepartureList.this.getListView().setVisibility(View.VISIBLE); |
DepartureList.this.getListView().setVisibility(View.VISIBLE); |
309 |
MessageBox.showMessage(DepartureList.this, "No departures found", true); |
MessageBox.showMessage(DepartureList.this, "No departures found", true); |
310 |
} |
} |
311 |
} else { // communication or parse error |
} else { // communication or parse error |
312 |
|
commFailCounter++; |
313 |
AlertDialog.Builder builder = new AlertDialog.Builder(DepartureList.this); |
AlertDialog.Builder builder = new AlertDialog.Builder(DepartureList.this); |
314 |
builder.setMessage("Error finding departures"); |
builder.setMessage("Error finding departures"); |
315 |
builder.setCancelable(true); |
builder.setCancelable(true); |
316 |
builder.setPositiveButton(getString(generic_retry), new DialogInterface.OnClickListener() { |
if (commFailCounter < 3) { |
317 |
public void onClick(DialogInterface dialog, int id) { |
builder.setPositiveButton(getString(generic_retry), new DialogInterface.OnClickListener() { |
318 |
dialog.dismiss(); |
public void onClick(DialogInterface dialog, int id) { |
319 |
startDepartureFetcher(); |
dialog.dismiss(); |
320 |
|
startDepartureFetcher(); |
321 |
} |
|
322 |
}); |
} |
323 |
|
}); |
324 |
|
} |
325 |
builder.setNegativeButton(getString(generic_cancel), new DialogInterface.OnClickListener() { |
builder.setNegativeButton(getString(generic_cancel), new DialogInterface.OnClickListener() { |
326 |
public void onClick(DialogInterface dialog, int id) { |
public void onClick(DialogInterface dialog, int id) { |
327 |
dialog.dismiss(); |
dialog.dismiss(); |
339 |
|
|
340 |
@Override |
@Override |
341 |
protected Void doInBackground(Integer... params) { |
protected Void doInBackground(Integer... params) { |
342 |
success = provider.lookupDepartures(params[0], DepartureList.this.arrival); |
departures = provider.lookupDepartures(params[0], DepartureList.this.arrival); |
|
departures = provider.getDepartures(params[0], DepartureList.this.arrival); |
|
343 |
return null; |
return null; |
344 |
} |
} |
345 |
|
|