diff options
author | Christopher Baines <cbaines8@gmail.com> | 2012-03-16 11:38:33 +0000 |
---|---|---|
committer | Christopher Baines <cbaines8@gmail.com> | 2012-03-16 11:38:33 +0000 |
commit | 915d0b3a72c5b6ed298b3984ca0224ad473b9899 (patch) | |
tree | b37a8feb8897142a9ff7552f0790c56cfee438ce /src/net/cbaines/suma/BusActivity.java | |
parent | a7a29da3b13d83952b65e6d97ec3588e2c023051 (diff) | |
download | southamptonuniversitymap-915d0b3a72c5b6ed298b3984ca0224ad473b9899.tar southamptonuniversitymap-915d0b3a72c5b6ed298b3984ca0224ad473b9899.tar.gz |
More changes.
Diffstat (limited to 'src/net/cbaines/suma/BusActivity.java')
-rw-r--r-- | src/net/cbaines/suma/BusActivity.java | 49 |
1 files changed, 20 insertions, 29 deletions
diff --git a/src/net/cbaines/suma/BusActivity.java b/src/net/cbaines/suma/BusActivity.java index 368d514..1659c88 100644 --- a/src/net/cbaines/suma/BusActivity.java +++ b/src/net/cbaines/suma/BusActivity.java @@ -131,12 +131,19 @@ public class BusActivity extends ToastHelperActivity implements Preferences { for (int num = timetableView.getFirstVisiblePosition(); num <= timetableView.getLastVisiblePosition(); num++) { final Stop stop = timetable.get(num); - if (System.currentTimeMillis() - stop.timeOfFetch.getTime() > 20000) { + GetTimetableStopTask task = tasks.get(num); + + if (task != null) { // If there is a task + if (task.getStatus() == AsyncTask.Status.FINISHED) { + task = null; // Delete it + } + } + + if (System.currentTimeMillis() - stop.timeOfFetch.getTime() > 20000 && task == null) { refreshBusStop(num); } else { // Log.v(TAG, "Not updating " + busStops.get(num)); } - } handler.postDelayed(refreshData, 50000); } @@ -147,30 +154,20 @@ public class BusActivity extends ToastHelperActivity implements Preferences { } private void refreshBusStop(int index) { - GetTimetableStopTask task = tasks.get(index); - if (task != null) { // If there is a taks - if (task.getStatus() == AsyncTask.Status.FINISHED) { // If - // its - // finished - task = null; // Delete it - } + // Remove the old time from the timetable + synchronized (timetable) { + timetable.set(index, new StopLoading(timetable.get(index).bus, busStops.get(index), timetable.get(index).arivalTime, + new Date(System.currentTimeMillis() - 21000), false)); + displayTimetable(); } - if (task == null) { // If there is now no task - // Log.v(TAG, "Updating " + busStops.get(num)); - - // Remove the old time from the timetable - synchronized (timetable) { - timetable.set(index, new StopLoading(timetable.get(index).bus, busStops.get(index), - timetable.get(index).arivalTime, new Date(System.currentTimeMillis() - 21000), false)); - displayTimetable(); - } - - task = new GetTimetableStopTask(); - task.execute(index); + GetTimetableStopTask task = new GetTimetableStopTask(); + task.execute(index); + synchronized (tasks) { tasks.put(index, task); } + } @Override @@ -262,16 +259,10 @@ public class BusActivity extends ToastHelperActivity implements Preferences { private class GetTimetableStopTask extends AsyncTask<Integer, Integer, Stop> { // private String errorMessage; - private BusStop busStop; - private int busStopIndex; - protected void onPreExecute() { - // progBar.setVisibility(View.VISIBLE); - } - protected Stop doInBackground(Integer... busStopIndexs) { - busStop = busStops.get(busStopIndexs[0]); + BusStop busStop = busStops.get(busStopIndexs[0]); busStopIndex = busStopIndexs[0]; Stop stop = null; @@ -300,7 +291,7 @@ public class BusActivity extends ToastHelperActivity implements Preferences { } protected void onPostExecute(Stop stop) { - // Log.i(TAG, "Got timetable"); + if (isCancelled()) return; synchronized (timetable) { timetable.set(busStopIndex, stop); |