31 |
import dk.thoerup.android.traininfo.common.DepartureEntry; |
import dk.thoerup.android.traininfo.common.DepartureEntry; |
32 |
import dk.thoerup.android.traininfo.common.MetroBean; |
import dk.thoerup.android.traininfo.common.MetroBean; |
33 |
import dk.thoerup.android.traininfo.common.MetroBean.MetroEntry; |
import dk.thoerup.android.traininfo.common.MetroBean.MetroEntry; |
34 |
import dk.thoerup.android.traininfo.common.StationBean.StationEntry; |
import dk.thoerup.android.traininfo.common.StationEntry; |
35 |
import dk.thoerup.traininfo.provider.DepartureProvider; |
import dk.thoerup.traininfo.provider.DepartureProvider; |
36 |
import dk.thoerup.traininfo.provider.MetroProvider; |
import dk.thoerup.traininfo.provider.MetroProvider; |
37 |
import dk.thoerup.traininfo.provider.ProviderFactory; |
import dk.thoerup.traininfo.provider.ProviderFactory; |
429 |
|
|
430 |
|
|
431 |
pgDialog.dismiss(); |
pgDialog.dismiss(); |
432 |
|
//TODO: differentiate whether it was a communication error with my backend |
433 |
if (departures != null) { |
//or that the backend failed because bane.dk was unavailable |
434 |
|
if (departures != null && departures.errorCode == null) { |
435 |
commFailCounter = 0; |
commFailCounter = 0; |
436 |
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 |
437 |
adapter.setDepartures(departures.entries); |
adapter.setDepartures(departures.entries); |
453 |
}); |
}); |
454 |
} |
} |
455 |
|
|
456 |
if (departures.entries.size() != 0) { |
if (departures.entries.size() == 0) { |
457 |
int msgId = (arrival==false) ? R.string.departurelist_nodepartures : R.string.departurelist_noarrivals; |
int msgId = (arrival==false) ? R.string.departurelist_nodepartures : R.string.departurelist_noarrivals; |
458 |
MessageBox.showMessage(DepartureList.this, getString(msgId), false); |
MessageBox.showMessage(DepartureList.this, getString(msgId), false); |
459 |
} |
} |
460 |
} else { // communication or parse error |
} else { // communication or parse error |
461 |
commFailCounter++; |
commFailCounter++; |
462 |
AlertDialog.Builder builder = new AlertDialog.Builder(DepartureList.this); |
AlertDialog.Builder builder = new AlertDialog.Builder(DepartureList.this); |
463 |
builder.setMessage("Error finding departures"); |
|
464 |
|
if (departures != null && departures.errorCode != null ) { //got an error xml back |
465 |
|
commFailCounter = 10; |
466 |
|
builder.setMessage( getString(R.string.no_backend) ); |
467 |
|
} else { |
468 |
|
builder.setMessage( getString(R.string.departurelist_fetcherror) ); |
469 |
|
} |
470 |
builder.setCancelable(true); |
builder.setCancelable(true); |
471 |
|
|
472 |
if (commFailCounter < 3) { |
if (commFailCounter < 3) { |
473 |
builder.setPositiveButton(getString(generic_retry), new DialogInterface.OnClickListener() { |
builder.setPositiveButton(getString(generic_retry), new DialogInterface.OnClickListener() { |
474 |
public void onClick(DialogInterface dialog, int id) { |
public void onClick(DialogInterface dialog, int id) { |
485 |
} |
} |
486 |
}); |
}); |
487 |
|
|
488 |
try { |
try { //TODO: is this still necessary after the 0.9.4.1 fix ? |
489 |
builder.show(); |
builder.show(); |
490 |
} catch (android.view.WindowManager.BadTokenException e) { |
} catch (android.view.WindowManager.BadTokenException e) { |
491 |
Log.i("DepartureList", "BadTokenException"); // this can happen if the user switched away from this activity, while doInBackground was running |
Log.i("DepartureList", "BadTokenException"); // this can happen if the user switched away from this activity, while doInBackground was running |
591 |
builder.setNegativeButton(getString(generic_cancel), new DialogInterface.OnClickListener() { |
builder.setNegativeButton(getString(generic_cancel), new DialogInterface.OnClickListener() { |
592 |
public void onClick(DialogInterface dialog, int id) { |
public void onClick(DialogInterface dialog, int id) { |
593 |
dialog.dismiss(); |
dialog.dismiss(); |
594 |
DepartureList.this.finish(); |
DepartureList.this.finish(); //TODO: should we really close the activity ?? |
595 |
} |
} |
596 |
}); |
}); |
597 |
|
|
598 |
try { |
try { //TODO: is this still necessary after the 0.9.4.1 fix ? |
599 |
builder.show(); |
builder.show(); |
600 |
} catch (android.view.WindowManager.BadTokenException e) { |
} catch (android.view.WindowManager.BadTokenException e) { |
601 |
Log.i("DepartureList", "BadTokenException"); // this can happen if the user switched away from this activity, while doInBackground was running |
Log.i("DepartureList", "BadTokenException"); // this can happen if the user switched away from this activity, while doInBackground was running |