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) { |
73 |
|
|
74 |
final Button departureBtn = (Button) findViewById(R.id.departurebtn); |
final Button departureBtn = (Button) findViewById(R.id.departurebtn); |
75 |
final Button arrivalBtn = (Button) findViewById(R.id.arrivalbtn); |
final Button arrivalBtn = (Button) findViewById(R.id.arrivalbtn); |
76 |
|
final Button metroBtn = (Button) findViewById(R.id.metrobtn); |
77 |
|
|
78 |
departureBtn.setOnClickListener( new OnClickListener() { |
departureBtn.setOnClickListener( new OnClickListener() { |
79 |
@Override |
@Override |
80 |
public void onClick(View arg0) { |
public void onClick(View arg0) { |
81 |
arrivalBtn.setBackgroundResource(R.drawable.custom_button); |
arrivalBtn.setBackgroundResource(R.drawable.custom_button); |
82 |
departureBtn.setBackgroundResource(R.drawable.custom_button_hilight); |
departureBtn.setBackgroundResource(R.drawable.custom_button_hilight); |
83 |
|
metroBtn.setBackgroundResource(R.drawable.custom_button); |
84 |
arrival = false; |
arrival = false; |
85 |
startDepartureFetcher(); |
startDepartureFetcher(); |
86 |
} |
} |
90 |
public void onClick(View arg0) { |
public void onClick(View arg0) { |
91 |
arrivalBtn.setBackgroundResource(R.drawable.custom_button_hilight); |
arrivalBtn.setBackgroundResource(R.drawable.custom_button_hilight); |
92 |
departureBtn.setBackgroundResource(R.drawable.custom_button); |
departureBtn.setBackgroundResource(R.drawable.custom_button); |
93 |
|
metroBtn.setBackgroundResource(R.drawable.custom_button); |
94 |
arrival = true; |
arrival = true; |
95 |
startDepartureFetcher(); |
startDepartureFetcher(); |
96 |
} |
} |
97 |
}); |
}); |
98 |
|
|
99 |
|
metroBtn.setOnClickListener( new OnClickListener() { |
100 |
|
@Override |
101 |
|
public void onClick(View v) { |
102 |
|
arrivalBtn.setBackgroundResource(R.drawable.custom_button); |
103 |
|
departureBtn.setBackgroundResource(R.drawable.custom_button); |
104 |
|
metroBtn.setBackgroundResource(R.drawable.custom_button_hilight); |
105 |
|
} |
106 |
|
}); |
107 |
|
|
108 |
|
|
109 |
|
|
110 |
|
|
120 |
} else { |
} else { |
121 |
((TextView) findViewById(R.id.stationDistance)).setVisibility(View.GONE); |
((TextView) findViewById(R.id.stationDistance)).setVisibility(View.GONE); |
122 |
} |
} |
123 |
|
|
124 |
|
ProviderFactory.purgeOldEntries(); //cleanup before fetching more data |
125 |
|
|
126 |
|
Log.e("Station", station.toCSV() ); |
127 |
|
|
128 |
|
if (station.isMetro() == false) { |
129 |
|
metroBtn.setVisibility( View.GONE ); |
130 |
|
} |
131 |
|
|
132 |
if (station.isRegional() == false && station.isSTrain() == false) { |
if (station.isRegional() == false && station.isSTrain() == false) { |
133 |
getListView().setVisibility( View.GONE ); |
getListView().setVisibility( View.GONE ); |
134 |
findViewById(R.id.metroonly).setVisibility( View.VISIBLE ); |
findViewById(R.id.metroonly).setVisibility( View.VISIBLE ); |
135 |
departureBtn.setVisibility( View.GONE ); |
departureBtn.setVisibility( View.GONE ); |
136 |
arrivalBtn.setVisibility(View.GONE); |
arrivalBtn.setVisibility(View.GONE); |
137 |
|
metroBtn.setVisibility( View.GONE ); |
138 |
|
|
139 |
} else { |
} else { |
140 |
provider = ProviderFactory.getDepartureProvider(); |
provider = ProviderFactory.getDepartureProvider(); |
300 |
|
|
301 |
class DepartureFetcher extends AsyncTask<Integer, Void, Void> { |
class DepartureFetcher extends AsyncTask<Integer, Void, Void> { |
302 |
|
|
|
boolean success; |
|
303 |
|
|
304 |
@Override |
@Override |
305 |
protected void onPostExecute(Void result) { |
protected void onPostExecute(Void result) { |
308 |
|
|
309 |
pgDialog.dismiss(); |
pgDialog.dismiss(); |
310 |
|
|
311 |
if (success) { |
if (departures != null) { |
312 |
|
commFailCounter = 0; |
313 |
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 |
314 |
adapter.setDepartures(departures.entries); |
adapter.setDepartures(departures.entries); |
315 |
DepartureList.this.getListView().setVisibility(View.VISIBLE); |
DepartureList.this.getListView().setVisibility(View.VISIBLE); |
323 |
MessageBox.showMessage(DepartureList.this, "No departures found", true); |
MessageBox.showMessage(DepartureList.this, "No departures found", true); |
324 |
} |
} |
325 |
} else { // communication or parse error |
} else { // communication or parse error |
326 |
|
commFailCounter++; |
327 |
AlertDialog.Builder builder = new AlertDialog.Builder(DepartureList.this); |
AlertDialog.Builder builder = new AlertDialog.Builder(DepartureList.this); |
328 |
builder.setMessage("Error finding departures"); |
builder.setMessage("Error finding departures"); |
329 |
builder.setCancelable(true); |
builder.setCancelable(true); |
330 |
builder.setPositiveButton(getString(generic_retry), new DialogInterface.OnClickListener() { |
if (commFailCounter < 3) { |
331 |
public void onClick(DialogInterface dialog, int id) { |
builder.setPositiveButton(getString(generic_retry), new DialogInterface.OnClickListener() { |
332 |
dialog.dismiss(); |
public void onClick(DialogInterface dialog, int id) { |
333 |
startDepartureFetcher(); |
dialog.dismiss(); |
334 |
|
startDepartureFetcher(); |
335 |
} |
|
336 |
}); |
} |
337 |
|
}); |
338 |
|
} |
339 |
builder.setNegativeButton(getString(generic_cancel), new DialogInterface.OnClickListener() { |
builder.setNegativeButton(getString(generic_cancel), new DialogInterface.OnClickListener() { |
340 |
public void onClick(DialogInterface dialog, int id) { |
public void onClick(DialogInterface dialog, int id) { |
341 |
dialog.dismiss(); |
dialog.dismiss(); |
353 |
|
|
354 |
@Override |
@Override |
355 |
protected Void doInBackground(Integer... params) { |
protected Void doInBackground(Integer... params) { |
356 |
success = provider.lookupDepartures(params[0], DepartureList.this.arrival); |
departures = provider.lookupDepartures(params[0], DepartureList.this.arrival); |
|
departures = provider.getDepartures(params[0], DepartureList.this.arrival); |
|
357 |
return null; |
return null; |
358 |
} |
} |
359 |
|
|