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) { |
108 |
} else { |
} else { |
109 |
((TextView) findViewById(R.id.stationDistance)).setVisibility(View.GONE); |
((TextView) findViewById(R.id.stationDistance)).setVisibility(View.GONE); |
110 |
} |
} |
111 |
|
|
112 |
|
ProviderFactory.purgeOldEntries(); //cleanup before fetching more data |
113 |
|
|
114 |
if (station.isRegional() == false && station.isSTrain() == false) { |
if (station.isRegional() == false && station.isSTrain() == false) { |
115 |
getListView().setVisibility( View.GONE ); |
getListView().setVisibility( View.GONE ); |
281 |
|
|
282 |
class DepartureFetcher extends AsyncTask<Integer, Void, Void> { |
class DepartureFetcher extends AsyncTask<Integer, Void, Void> { |
283 |
|
|
|
boolean success; |
|
284 |
|
|
285 |
@Override |
@Override |
286 |
protected void onPostExecute(Void result) { |
protected void onPostExecute(Void result) { |
289 |
|
|
290 |
pgDialog.dismiss(); |
pgDialog.dismiss(); |
291 |
|
|
292 |
if (success) { |
if (departures != null) { |
293 |
|
commFailCounter = 0; |
294 |
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 |
295 |
adapter.setDepartures(departures.entries); |
adapter.setDepartures(departures.entries); |
296 |
DepartureList.this.getListView().setVisibility(View.VISIBLE); |
DepartureList.this.getListView().setVisibility(View.VISIBLE); |
304 |
MessageBox.showMessage(DepartureList.this, "No departures found", true); |
MessageBox.showMessage(DepartureList.this, "No departures found", true); |
305 |
} |
} |
306 |
} else { // communication or parse error |
} else { // communication or parse error |
307 |
|
commFailCounter++; |
308 |
AlertDialog.Builder builder = new AlertDialog.Builder(DepartureList.this); |
AlertDialog.Builder builder = new AlertDialog.Builder(DepartureList.this); |
309 |
builder.setMessage("Error finding departures"); |
builder.setMessage("Error finding departures"); |
310 |
builder.setCancelable(true); |
builder.setCancelable(true); |
311 |
builder.setPositiveButton(getString(generic_retry), new DialogInterface.OnClickListener() { |
if (commFailCounter < 3) { |
312 |
public void onClick(DialogInterface dialog, int id) { |
builder.setPositiveButton(getString(generic_retry), new DialogInterface.OnClickListener() { |
313 |
dialog.dismiss(); |
public void onClick(DialogInterface dialog, int id) { |
314 |
startDepartureFetcher(); |
dialog.dismiss(); |
315 |
|
startDepartureFetcher(); |
316 |
} |
|
317 |
}); |
} |
318 |
|
}); |
319 |
|
} |
320 |
builder.setNegativeButton(getString(generic_cancel), new DialogInterface.OnClickListener() { |
builder.setNegativeButton(getString(generic_cancel), new DialogInterface.OnClickListener() { |
321 |
public void onClick(DialogInterface dialog, int id) { |
public void onClick(DialogInterface dialog, int id) { |
322 |
dialog.dismiss(); |
dialog.dismiss(); |
334 |
|
|
335 |
@Override |
@Override |
336 |
protected Void doInBackground(Integer... params) { |
protected Void doInBackground(Integer... params) { |
337 |
success = provider.lookupDepartures(params[0], DepartureList.this.arrival); |
departures = provider.lookupDepartures(params[0], DepartureList.this.arrival); |
|
departures = provider.getDepartures(params[0], DepartureList.this.arrival); |
|
338 |
return null; |
return null; |
339 |
} |
} |
340 |
|
|